You can find all Dynamic ITAB discussions at Tutorials > Dynamic Internal Table.
Recently, one of my friends asked me for the solution to create Internal Table. The problem was his system was not able to support the RTTS nor it has the class CL_ALV_TABLE_CREATE. Actually, I had developed this solution in early days when I was working on system 4.6B where I haven’t RTTS nor the ALV class.
Here is the solution:
*&---------------------------------------------------------------------*
*& Report ZDYN_ITAB_OLD
*&---------------------------------------------------------------------*
*& Fill the Subroutine Pool source
*& Generate Subroutine Pool
*& Call the Sobroutine to create ITAB
*&---------------------------------------------------------------------*
*
REPORT zdyn_itab_old.
*
DATA: dy_table TYPE REF TO data,
dy_line TYPE REF TO data.
*
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
<dyn_wa>.
*
FIELD-SYMBOLS: <fs> TYPE ANY.
*
* To generate the Dyanmic table with the COLOR
DATA: ls_source TYPE string.
DATA: lt_source LIKE STANDARD TABLE OF ls_source WITH HEADER LINE.
*
DATA: l_name LIKE sy-repid.
DATA: l_message(240) TYPE c,
l_line TYPE i,
l_word(72) TYPE c.
*
DATA: l_form(30) TYPE c VALUE 'TABLE_CREATE'.
*
*.....................................................................
START-OF-SELECTION.
* Subroutine definition
lt_source = 'REPORT ZTEST_SUBROUTINE_POOL.'.
APPEND lt_source.
* From Begin
lt_source = 'FORM TABLE_CREATE USING I_FS TYPE ANY.'.
APPEND lt_source.
* Table definition begin
lt_source = 'DATA: BEGIN OF LT_GENTAB OCCURS 0.'.
APPEND lt_source.
lt_source = 'DATA: BUKRS TYPE BUKRS. '.
APPEND lt_source.
lt_source = 'DATA: BKTXT TYPE BKTXT. '.
APPEND lt_source.
lt_source = 'DATA: END OF LT_GENTAB.'.
APPEND lt_source.
lt_source = 'DATA: POINTER TYPE REF TO DATA.'.
APPEND lt_source.
lt_source = 'CREATE DATA POINTER LIKE STANDARD TABLE OF LT_GENTAB.'.
APPEND lt_source.
lt_source = 'I_FS = POINTER.'.
APPEND lt_source.
* Form End
lt_source = 'ENDFORM. '.
APPEND lt_source.
*
* Subroutine Pool name
l_name = 'ZTEST_SUBROUTINE_POOL'.
*
* Generate Subroutine
CATCH SYSTEM-EXCEPTIONS generate_subpool_dir_full = 9.
GENERATE SUBROUTINE POOL lt_source NAME l_name
MESSAGE l_message LINE l_line WORD l_word. "#EC CI_GENERATE
ENDCATCH.
* Error handling
IF NOT l_message IS INITIAL.
MESSAGE e000(0k) WITH l_message l_line l_word.
ENDIF.
*
* data reference
ASSIGN dy_table TO <fs>.
* Call the subroutine
PERFORM (l_form) IN PROGRAM (l_name) USING <fs>.
* Get the reference of the data and assign to field symbol
ASSIGN dy_table->* TO <dyn_table>.
*
* Create dynamic work area and assign to FS
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
*
*