2013 Apr 03 8:10 AM
This code creates a dynamic table for each table name in the loop, since there are so many tables and i won't know the table names i want to pass it ti <f1> etc and call it later on.
DATA : ref_tab TYPE tabname,
tbc_count TYPE string VALUE 1.
FIELD-SYMBOLS :
<f1> TYPE any table,
<f2> TYPE any table,
<f3> TYPE any table,
<f4> TYPE any table,
<f5> TYPE any table,
<dynamic> TYPE any table.
LOOP AT checktab.
CREATE DATA dataref TYPE TABLE OF (checktab-tabname).
ASSIGN dataref->* TO <dynamic>.
CONCATENATE '<f' tbc_count '>' INTO ref_tab.
ASSIGN <dynamic> TO <ref_tab).
tbc_count = tbc_count + 1.
ENDLOOP.
But i can't assign the dynamic table to ref_tab which contains the field symbol table name.
How to do it ?
This code creates a dynamic table for each table name in the loop, since there are so many tables and i won't know the table names i want to pass it ti <f1> etc and call it later on.
DATA : ref_tab TYPE tabname,
tbc_count TYPE string VALUE 1.
FIELD-SYMBOLS :
<f1> TYPE any table,
<f2> TYPE any table,
<f3> TYPE any table,
<f4> TYPE any table,
<f5> TYPE any table,
<dynamic> TYPE any table.
LOOP AT checktab.
CREATE DATA dataref TYPE TABLE OF (checktab-tabname).
ASSIGN dataref->* TO <dynamic>.
CONCATENATE '<f' tbc_count '>' INTO ref_tab.
ASSIGN <dynamic> TO <ref_tab).
tbc_count = tbc_count + 1.
ENDLOOP.
But i can't assign the dynamic table to ref_tab which contains the field symbol table name.
How to do it ?
2013 Apr 03 9:33 AM
Hello,
I just do some modification. Hope it will works. Please do the type reference correctly .
TYPES: BEGIN OF ty_checktab,
srl_no TYPE char1,
tab_name TYPE tabname,
END OF ty_checktab.
DATA : lv_tabname TYPE tabname,
lt_checktab TYPE STANDARD TABLE OF ty_checktab,
tbc_count TYPE string VALUE 1,
ls_chktab TYPE ty_checktab,
dataref TYPE REF TO data.
FIELD-SYMBOLS :
<f1> TYPE ANY TABLE,
<f2> TYPE ANY TABLE,
<f3> TYPE ANY TABLE,
<f4> TYPE ANY TABLE,
<f5> TYPE ANY TABLE,
<ref_tab> TYPE any,
<dynamic> TYPE ANY TABLE.
CLEAR lv_tabname.
LOOP AT lt_checktab INTO ls_chktab.
CREATE DATA dataref TYPE (ls_chktab-tab_name).
ASSIGN dataref->* TO <dynamic>.
CONCATENATE '<f' tbc_count '>' INTO lv_tabname..
ASSIGN lv_tabname TO <ref_tab>.
ASSIGN <dynamic> TO <ref_tab>.
tbc_count = tbc_count + 1.
ENDLOOP.
Please check below code . It is executing correctly.
PARAMETERS:
TAB_NAME LIKE SY-TNAME, "Table name
TAB_COMP LIKE X031L-FIELDNAME, "Field name
ANZAHL TYPE I DEFAULT 10. Number of lines
FIELD-SYMBOLS: <WA> TYPE ANY,
<COMP> TYPE ANY.
DATA: WA_REF TYPE REF TO DATA.
CREATE DATA WA_REF TYPE (TAB_NAME). "Suitable work area
ASSIGN WA_REF->* TO <WA>.
SELECT * FROM (TAB_NAME) INTO <WA>
UP TO anzahl ROWS.
WRITE: / TAB_COMP, <COMP>.
ENDSELECT.
Thanks,
Abhijit
2013 Oct 10 2:38 PM
This will work, but only if the table name that is constructed dynamically exists in the dictionary.
I used HR tables for this example
DATA: dyn_name TYPE tabname,
part_name TYPE tabname,
counter TYPE numc2.
part_name = 'HRP10'.
CONCATENATE part_name counter INTO dyn_name.
PERFORM dosomething CHANGING dyn_name
part_name
counter.
FORM dosomething CHANGING p_dyn_name TYPE tabname
p_part_name TYPE tabname
p_counter TYPE numc2.
FIELD-SYMBOLS: <wa> TYPE ANY,
<table> TYPE ANY TABLE.
DATA: wa_ref TYPE REF TO data,
tab_ref TYPE REF TO data.
p_counter = p_counter + 1.
WHILE p_counter < 10.
CREATE DATA wa_ref TYPE (p_dyn_name).
CREATE DATA tab_ref TYPE TABLE OF (p_dyn_name).
ASSIGN wa_ref->* TO <wa>.
ASSIGN tab_ref->* TO <table>.
SELECT * FROM (p_dyn_name) INTO TABLE <table>.
LOOP AT <table> ASSIGNING <wa>.
ENDLOOP.
CONCATENATE p_part_name p_counter INTO p_dyn_name.
PERFORM dosomething CHANGING p_dyn_name
p_part_name
p_counter.
ENDWHILE.
ENDFORM. " DOSOMETHING
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |