Skip to Content

In this blog I would like to talk about using subroutine pools for doing dynamic programming in ABAP.The subroutine pools can be generated by using the following syntax :

GENERATE SUBROUTINE POOL itab NAME prog .

0.

    WRITE : / ‘Syntax error,message’,syntax_check_message,

              ‘in line no’,line_no.

    EXIT.

  ENDIF.

  PERFORM display_table IN PROGRAM (program_name).

&—-


*&      Form  build_table

&—-


FORM build_table USING  l_tabname.

  DATA: lwa_source_table LIKE source_table.

  APPEND

   ‘REPORT test.                               ‘     TO source_table.

  APPEND

  ‘TABLES :’                                         TO source_table.

  APPEND l_tabname                                   TO source_table.

  APPEND

  ‘.’                                                TO source_table.

  APPEND

  ‘ DATA : gt_itab like   ‘                          TO source_table.

  APPEND l_tabname                                   TO source_table.

  APPEND ‘  occurs 0 with header line.  ‘            TO source_table.

  APPEND ‘form display_table.’                       TO source_table.

  APPEND

  ‘SELECT * FROM   ‘                                 TO  source_table.

  APPEND l_tabname                                   TO source_table.

  APPEND

  ‘  into corresponding fields of table gt_itab.  ‘  TO source_table.

  APPEND

  ‘CALL FUNCTION ”REUSE_ALV_LIST_DISPLAY”       ‘  TO  source_table.

  APPEND

  ‘EXPORTING   ‘                                     TO  source_table.

  APPEND

  ‘I_STRUCTURE_NAME =    ‘                           TO  source_table.

  CONCATENATE ”” l_tabname ”” INTO lwa_source_table.

  APPEND lwa_source_table                            TO source_table.

  APPEND

    ‘TABLES                       ‘                  TO  source_table.

  APPEND

  ‘T_OUTTAB         =     gt_itab.     ‘             TO  source_table.

  APPEND ‘endform.’                                  TO source_table.

ENDFORM.                    ” build_table

Note :

A maximum of only 36 subroutine pools can be created in a program.

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

  1. Alvaro Tejada Galindo
    Hey Ravi:

    I just copy and excute you code…Woaw! You blow my mind -:D Really nice blog…But…FORM build_table USING l_tabname have to be that messy??? I mean…Why you need that some many white spaces…It makes it kinda hard to read.

    You code is the most dynamic code I ever seen -:P Hope to see more about that…Or about other ABAP secrets -;)

    Greetings,

    Blag.

    (0) 
    1. Ravi Shankar Rajan Post author
      Hi Alvaro
      Thanks for your comments.You are right about the white spaces as they can be avoided.But then in ECC 5.0 you can do the same thing using the “dynamic table” concept( create data object).
      (0) 
  2. Horst Keller
    Hi,

    Although program generation is very powerful, for performance reasons it should always be the latest means of dynamic programming.

    Other important means of dynamic programming that should always be considered before using program generation are dynamic token specification and RTTC (Run Time Type Creation).

    Especially for the example shown here, dynamic token specification together with RTTC would be sufficient. As of Release 6.40, RTTC allows you to create data objects of appropriate types and program generation is not necessary any more for such a purpose.

    In chapter 11 of the book “ABAP Objects, ABAP Programming in SAP NetWeaver” you get a step by step introduction into these techniques and hints when to use what. There, a small data browser is implemented using different techniques.

    Kind regards

    Horst

    (0) 

Leave a Reply