2007 May 04 2:21 PM
Hi,
I have an requirement. if have 10 records then i have to create one internal table with those 10 as fields .... 10 records may vary dynamically how to .... create internal like that.
Please help with this.
Thanks,
Mathivanan.G
Hi,
I have an requirement. if have 10 records then i have to create one internal table with those 10 as fields .... 10 records may vary dynamically how to .... create internal like that.
Please help with this.
Thanks,
Mathivanan.G
2007 May 04 2:23 PM
Hi Mathivanan,
Refer this code :
REPORT ZDYNAMIC_INTERNAL_TABLE .
DATA: wa_fldcat TYPE LVC_S_FCAT.
DATA: it_fldcat TYPE LVC_T_FCAT.
DATA: it TYPE REF TO DATA.
FIELD-SYMBOLS: <fs_table> TYPE TABLE.
FIELD-SYMBOLS: <fs_temp> TYPE ANY.
START-OF-SELECTION.
*BUILDING FIELD CATALOG.
wa_fldcat-fieldname = 'matnr'.
wa_fldcat-tabname = 'it'.
wa_fldcat-datatype = 'matnr'.
append wa_fldcat to it_fldcat.
*CREATE THE DYNAMIC INTERNAL TABLE
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fldcat
IMPORTING
EP_TABLE = it.
Assign the pointer <fs_table> to the dynamically created internal table "it"
ASSIGN it->* TO <fs_table>.
populate the internal table (through field symbols)
select matnr
INTO TABLE <fs_table>
from mara
where mtart = 'ABF'.
write the data
loop at <fs_table> ASSIGNING <fs_temp>.
write:/ <fs_temp>.
endloop.
Reward points if Helpful.
Regards,
Hemant
2007 May 04 2:23 PM
Hi,
Check the blog below :
/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap
try your logic in this example....
=====================================
REPORT zmaschl_create_data_dynamic .
TYPE-POOLS: slis.
DATA: it_fcat TYPE slis_t_fieldcat_alv,
is_fcat LIKE LINE OF it_fcat.
DATA: it_fieldcat TYPE lvc_t_fcat,
is_fieldcat LIKE LINE OF it_fieldcat.
DATA: new_table TYPE REF TO data.
DATA: new_line TYPE REF TO data.
FIELD-SYMBOLS: <l_table> TYPE ANY TABLE,
<l_line> TYPE ANY,
<l_field> TYPE ANY.
Build fieldcat
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SYST'
CHANGING
ct_fieldcat = it_fcat[].
LOOP AT it_fcat INTO is_fcat WHERE NOT reptext_ddic IS initial.
MOVE-CORRESPONDING is_fcat TO is_fieldcat.
is_fieldcat-fieldname = is_fcat-fieldname.
is_fieldcat-ref_field = is_fcat-fieldname.
is_fieldcat-ref_table = is_fcat-ref_tabname.
APPEND is_fieldcat TO it_fieldcat.
ENDLOOP.
Create a new Table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = new_table.
Create a new Line with the same structure of the table.
ASSIGN new_table->* TO <l_table>.
CREATE DATA new_line LIKE LINE OF <l_table>.
ASSIGN new_line->* TO <l_line>.
Test it...
DO 30 TIMES.
ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.
<l_field> = sy-index.
INSERT <l_line> INTO TABLE <l_table>.
ENDDO.
LOOP AT <l_table> ASSIGNING <l_line>.
ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.
WRITE <l_field>.
ENDLOOP.
Reward points if useful..
Regards
Nilesh
2007 May 04 2:49 PM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |