Usage:
* Used when the number of columns / fields are not known at the design time / compile time.
* Performance will not as good as in the Static internal table creation.
The code was written in R/3 Release 4.6C.
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.
is_fieldcat-fieldname = 'FIELD1'.
is_fieldcat-ref_field = 'MATNR'.
is_fieldcat-ref_table = 'MARA'.
APPEND is_fieldcat TO it_fieldcat.
is_fieldcat-fieldname = 'FIELD2'.
is_fieldcat-ref_field = 'SPRPS'.
is_fieldcat-ref_table = 'PA0001'.
APPEND is_fieldcat TO it_fieldcat.
is_fieldcat-fieldname = 'FIELD3'.
is_fieldcat-ref_field = 'BEGDA'.
is_fieldcat-ref_table = 'PA0002'.
APPEND is_fieldcat TO it_fieldcat.
* 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
Requires Free Membership to View
When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.
Hannah Smalltree, Editorial Directornew_line->* TO <l_line>. * Test it... DO 30 TIMES. ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <l_line> TO <l_field>. <l_field> = '12345'. ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <l_line> TO <l_field>. <l_field> = 'X'. ASSIGN COMPONENT 'FIELD3' OF STRUCTURE <l_line> TO <l_field>. <l_field> = '20030101'. INSERT <l_line> INTO TABLE <l_table>. ENDDO. LOOP AT <l_table> ASSIGNING <l_line>. * ASSIGN COMPONENT 'field1' OF STRUCTURE <l_line> TO <l_field>. WRITE / <l_line>. ENDLOOP.
This was first published in June 2003
Join the conversationComment
Share
Comments
Results
Contribute to the conversation