Dynamic Internal Table

By | December 23, 2008 | Dynamic ITAB | 11,907 | 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.
* To generate the Dyanmic table with the COLOR
DATAls_source TYPE string.
DATAl_name LIKE sy-repid.
DATAl_message(240TYPE c,
      l_line TYPE i,
      l_word(72TYPE c.
* Subroutine definition
  APPEND lt_source.
* From Begin
  APPEND lt_source.
* Table definition begin
  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.
  APPEND lt_source.
  APPEND lt_source.
  lt_source 'I_FS = POINTER.'.
  APPEND lt_source.
* Form End
  lt_source 'ENDFORM. '.
  APPEND lt_source.
* Subroutine Pool name
* Generate Subroutine
  CATCH SYSTEM-EXCEPTIONS generate_subpool_dir_full 9.
             MESSAGE l_message LINE l_line WORD l_word"#EC CI_GENERATE
* Error handling
  IF NOT l_message IS INITIAL.
    MESSAGE e000(0kWITH l_message l_line l_word.
* 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{273 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 273 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.