Dynamic Internal Table

By | December 23, 2008 | Dynamic ITAB | 15,283 | 0

Describes a way to create a dynamic internal table from coding. This is also can be used when RTTS is not supported or class CL_ALV_TABLE_CREATE is not available.

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.
*
DATAdy_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
DATAls_source TYPE string.
DATAlt_source LIKE STANDARD TABLE OF ls_source WITH HEADER LINE.
*
DATAl_name LIKE sy-repid.
DATAl_message(240TYPE c,
      l_line TYPE i,
      l_word(72TYPE c.
*
DATAl_form(30TYPE 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(0kWITH l_message l_line l_word.
  ENDIF.
*
* data reference
  ASSIGN dy_table TO <fs>.
* Call the subroutine
  PERFORM (l_formIN PROGRAM (l_nameUSING <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>.
*
*

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 274 articles.

Load comments

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.