Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

how to create dynamic internal table

hi all,

how to create dynamic internal table

if possible i need even the sample code

Thanks in advance

Points will be rewarded

Tags:
replied
REPORT zpwtest .

*** Tables
DATA: lt_data TYPE REF TO data.
DATA: lt_fieldcatalog TYPE lvc_t_fcat.

*** Structure
DATA: ls_fieldcatalog TYPE lvc_s_fcat.

*** Data References
DATA: new_line TYPE REF TO data.

*** Field Symbols
FIELD-SYMBOLS: <fs_data> TYPE REF TO data,
               <fs_1> TYPE ANY TABLE,
               <fs_2>,
               <fs_3>.



ls_fieldcatalog-fieldname = 'MANDT'.
APPEND ls_fieldcatalog TO lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'CARRID'. "Fieldname
ls_fieldcatalog-inttype = 'C'. "Internal Type C-> Character
APPEND ls_fieldcatalog TO lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'CONNID'.
ls_fieldcatalog-inttype = 'N'.
APPEND ls_fieldcatalog TO lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'FLDATE'.
ls_fieldcatalog-inttype = 'D'.
APPEND ls_fieldcatalog TO lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'PRICE'.
ls_fieldcatalog-inttype = 'P'.
APPEND ls_fieldcatalog TO lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'CURRENCY'.
ls_fieldcatalog-inttype = 'C'.
APPEND ls_fieldcatalog TO lt_fieldcatalog.


ASSIGN lt_data TO <fs_data>.


CALL METHOD cl_alv_table_create=create_dynamic_table
     EXPORTING
       it_fieldcatalog = lt_fieldcatalog
     IMPORTING
       ep_table = fs_data
     EXCEPTIONS
       generate_subpool_dir_full = 1
       OTHERS = 2
		.
IF sy-subrc <> 0.
ENDIF.



*** So <FS_1> now points to our dynamic internal table.

ASSIGN <fs_data>->* TO <fs_1>.

*** Next step is to create a work area for our dynamic internal table.

CREATE DATA new_line LIKE LINE OF <fs_1>.

*** A field-symbol to access that work area
ASSIGN new_line->*  TO <fs_2>.

*** And to put the data in the internal table
SELECT mandt carrid connid fldate price currency
  FROM sflight
  INTO CORRESPONDING FIELDS OF TABLE <fs_1>.

*** Access contents of internal table
LOOP AT <fs_1> ASSIGNING <fs_2>.

  ASSIGN COMPONENT 1 OF STRUCTURE <fs_2> TO <fs_3>.
  WRITE: / <fs_3>.
ENDLOOP.



2 View this answer in context
Not what you were looking for? View more on this topic or Ask a question