Dynamic Internal Table

Posted by Krishh Webworld | 11:14 AM | | 1 comments »

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.


Previously, we have seen:
  • Dynamic Internal Table Creation using RTTS
  • Dynamic Internal Table with Deep structure using RTTS
  • Dynamic Internal Table creation using class CL_ALV_TABLE_CREATE


  • 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:
    Code Snippet to Generate Dynamic ITAB
     
    *&---------------------------------------------------------------------*
    *& 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: TYPE STANDARD TABLE,
    .
    *
    FIELD-SYMBOLS: 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 .
    * Call the subroutine
    PERFORM (l_form) IN PROGRAM (l_name) USING .
    * Get the reference of the data and assign to field symbol
    ASSIGN dy_table->* TO .
    *
    * Create dynamic work area and assign to FS
    CREATE DATA dy_line LIKE LINE OF .
    ASSIGN dy_line->* TO .
    *
    *

    1 comments

    1. Mohammed Bohra // June 24, 2011 at 10:32 AM  

      barkwFor a Excellent Online Resource for SAP EP and SAP Web Dynpro ABAP, Visit Learn SAP Online

    Archives

    Subscribe Now: Feed Icon