Code: Alles auswählen.
METHOD set_itab.
DATA: itab TYPE REF TO data.
CREATE DATA: itab LIKE im_itab.
FIELD-SYMBOLS: <itab> TYPE ANY TABLE.
ASSIGN: itab->* TO <itab>.
ENDMETHOD.
Code: Alles auswählen.
SELECT * FROM (im_ddic_tablename)
INTO CORRESPONDING FIELDS OF TABLE <itab>
Code: Alles auswählen.
data: itab TYPE REF TO data.
Code: Alles auswählen.
METHOD set_itab.
field-symbols: <fs> type table.
CREATE DATA: itab LIKE im_itab.
assign itab->* to <fs>.
<fs> = im_itab.
ENDMETHOD.
Code: Alles auswählen.
METHOD do_something.
DATA: h_itabtype TYPE REF TO data.
CREATE DATA h_itabtype TYPE TABLE OF (me->ddic_tablename).
FIELD-SYMBOLS: <itab> TYPE ANY TABLE.
ASSIGN: me->itab->* TO <itab> CASTING LIKE h_itabtype.
... do something with <itab>.
ENDMETHOD.
Code: Alles auswählen.
METHOD do_something.
FIELD-SYMBOLS: <itab> TYPE ANY TABLE.
ASSIGN: me->itab->* TO <itab>.
* ... do something with <itab>.
* z.B.
FIELD-SYMBOLS: <wa> TYPE ANY.
LOOP AT <itab> ASSIGNING <wa>.
ENDLOOP.
ENDMETHOD.
Damit sollte es zur Laufzeit möglich sein, die Feldliste zur Tabelle zu erhalten.Sometimes you may have only a table name and want to retrieve the name of each field of the corresponding table. For example, when you want to use ASSIGN COMPONENT fieldname OF TABLE table.
An ABAPer's first reaction is to read the standard ABAP basis tables DD02L, DD03L, etc
This way of reading fields is very slow. Use methods from the class CL_ABAP_TYPEDESCR instead.
Example:
data: descr_struc_ref TYPE REF TO cl_abap_structdescr.
descr_struc_ref ?= cl_abap_typedescr=>describe_by_name('SFLIGHT' ).
Here is the result of descr_struct_ref after the execution of this piece of code
ABSOLUTE_NAME C 200 \TYPE=SFLIGHT
TYPE_KIND C 1 u
LENGTH I 4 80
DECIMALS I 4 0
KIND C 1 S
STRUCT_KIND C 1 F
COMPONENTS h 8 Table[14x40]
HAS_INCLUDE C 1
The table COMPONENTS is filled with :
LENGTH DECIMALS TYPE_KIND NAME
3 | 0 |C |MANDT
3 | 0 |C |CARRID
4 | 0 |N |CONNID
8 | 0 |D |FLDATE
etc.
You have the fields name and a lot more information about the table. This class can also handle structure, table type, etc.
Note that this method is very fast because it uses the database layer directly thanks to SYSTEM CALLs.
To have a look at the class, use transaction SE24.
Code: Alles auswählen.
METHOD get_itab.
DATA: wa_itab TYPE REF TO data,
ret_itab TYPE REF TO data.
CREATE DATA: wa_itab TYPE (me->ddic_tablename),
ret_itab LIKE ch_itab.
FIELD-SYMBOLS: <itab> TYPE ANY TABLE,
<ret_itab> TYPE STANDARD TABLE,
<wa_itab> TYPE ANY.
ASSIGN: me->itab->* TO <itab>,
wa_itab->* TO <wa_itab>,
ch_itab TO <ret_itab>.
LOOP AT <itab> INTO <wa_itab>.
APPEND <wa_itab> TO <ret_itab>.
ENDLOOP.
ENDMETHOD.
Code: Alles auswählen.
...
DATA: BEGIN OF wa_itab,
irgendwas(30).
INCLUDE STRUCTURE t000.
DATA: END OF wa_itab.
DATA: itab LIKE STANDARD TABLE OF wa_itab.
...
CALL METHOD db->get_itab
EXPORTING
IM_RET_STRUCT = wa_itab.
CHANGING
ch_itab = itab.
...
Code: Alles auswählen.
METHOD get_itab.
DATA: wa_itab TYPE REF TO data,
wa_ret_itab TYPE REF TO data,
ret_itab TYPE REF TO data.
CREATE DATA: wa_itab TYPE (me->ddic_tablename),
wa_ret_itab LIKE im_ret_struct,
ret_itab LIKE ch_itab.
FIELD-SYMBOLS: <itab> TYPE ANY TABLE,
<ret_itab> TYPE STANDARD TABLE,
<wa_itab> TYPE ANY,
<wa_ret_itab> TYPE ANY.
ASSIGN: me->itab->* TO <itab>,
wa_itab->* TO <wa_itab>,
wa_ret_itab->* TO <wa_ret_itab>,
ch_itab TO <ret_itab>.
LOOP AT <itab> INTO <wa_itab>.
MOVE-CORRESPONDING <wa_itab> TO <wa_ret_itab>.
APPEND <wa_ret_itab> TO <ret_itab>.
ENDLOOP.
ENDMETHOD.