Skip to Content
author's profile photo Former Member
Former Member

Generating abap source...fast or even on-the-fly?

Hallo,

In our project we massively generate abap source code using the functions in group SEOP. Unfortunately, it takes

quite a long time to generate all those classes for

our app.

Does anybody know of a fast way to generate and activate

abap, maybe even on the fly, i.e. in a running app?

Thanks in advance for any pointers,

thomas

Add comment
10|10000 characters needed characters exceeded

5 Answers

  • Posted on Jul 26, 2004 at 11:41 AM

    Hi Thomas,

    I don't know whether this is fast, but you can create subroutines on the fly with "create subroutine pool <itab> name <prog>". Have a look at the documentation. With "insert report <prog> from <itab>" you can create a report, which you can start with "submit <prog>". Have a look at the docu about performance requirements; I'm not sure here.

    Hope this helps

    Joerg

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 26, 2004 at 02:37 PM

    Hallo Thomas,

    here's an example of dynamically creating and calling an ABAP routine. I hope it makes some sense. Just a couple of words of warning. Firstly, there is a considerable performance overhead with such code. Secondly, SAP specifies in their documentation that GENERATE is only for internal use (although they use it for external programs too).

    I hope this helps.

    Gerard.

    FORM FILL_KEYS.

    DATA: BEGIN OF L_T_KEYS OCCURS 0,

    FIELDNAME TYPE FIELDNAME,

    VALUE TYPE FIELDVALUE,

    END OF L_T_KEYS.

    *

    DATA: BEGIN OF L_T_CODE OCCURS 0,

    LINE(80),

    END OF L_T_CODE.

    *

    DATA: L_TESTTAB TYPE ZTESTTAB,

    L_PROGRAM TYPE PROGRAM,

    L_VALUE TYPE FIELDVALUE,

    L_SUBRC LIKE SY-SUBRC,

    L_INDEX TYPE I,

    L_MESSAGE(132),

    L_EXIT.

    *

    FIELD-SYMBOLS: <F2> TYPE ANY.

    *

    L_TESTTAB = <F1>.

    *

    REFRESH: L_T_KEYS,

    L_T_CODE.

    *

    DO.

    ASSIGN COMPONENT SY-INDEX OF STRUCTURE L_TESTTAB TO <F2>.

    IF SY-SUBRC = 0.

    IF NOT <F2> IS INITIAL.

    L_T_KEYS-VALUE = <F2>.

    READ TABLE X_NAMTAB INDEX SY-INDEX.

    L_T_KEYS-FIELDNAME = X_NAMTAB-VIEWFIELD.

    APPEND L_T_KEYS.

    ENDIF.

    ELSE.

    EXIT.

    ENDIF.

    *

    ENDDO.

    DESCRIBE TABLE L_T_KEYS LINES L_INDEX.

    CHECK L_INDEX GT 0.

    APPEND: 'REPORT GERONIMO.'

    TO L_T_CODE,

    '*' TO L_T_CODE,

    'FORM POSITION_KEY_STRING TABLES P_EXTRACT'

    TO L_T_CODE,

    'CHANGING P_KEY_STRING P_SUBRC.'

    TO L_T_CODE,

    '*' TO L_T_CODE,

    'DATA: L_T_TESTTAB TYPE TABLE OF ZTESTTAB'

    TO L_T_CODE,

    'WITH HEADER LINE.' TO L_T_CODE,

    '*' TO L_T_CODE,

    'L_T_TESTTAB[] = P_EXTRACT[].'

    TO L_T_CODE,

    '*' TO L_T_CODE,

    'READ TABLE L_T_TESTTAB INTO P_KEY_STRING WITH KEY'

    TO L_T_CODE.

    *

    LOOP AT L_T_KEYS.

    CONCATENATE ''''

    L_T_KEYS-VALUE

    ''''

    INTO L_VALUE.

    IF SY-TABIX = L_INDEX.

    CONCATENATE L_VALUE

    '.' INTO L_VALUE.

    *

    ENDIF.

    *

    CONCATENATE L_T_KEYS-FIELDNAME

    '='

    L_VALUE

    INTO L_T_CODE

    SEPARATED BY SPACE.

    *

    APPEND L_T_CODE.

    *

    ENDLOOP.

    *

    APPEND: '*' TO L_T_CODE,

    'IF SY-SUBRC NE 0.' TO L_T_CODE,

    'CLEAR P_KEY_STRING.' TO L_T_CODE,

    'ENDIF.' TO L_T_CODE,

    'P_SUBRC = SY-SUBRC.' TO L_T_CODE.

    *

    APPEND 'ENDFORM.' TO L_T_CODE.

    GENERATE SUBROUTINE POOL L_T_CODE NAME L_PROGRAM

    MESSAGE L_MESSAGE.

    *

    IF L_MESSAGE IS INITIAL.

    PERFORM POSITION_KEY_STRING IN PROGRAM (L_PROGRAM)

    TABLES EXTRACT_M

    USING <F1>

    L_SUBRC.

    *

    IF NOT L_SUBRC IS INITIAL.

    CLEAR L_SUBRC.

    ENDIF.

    *

    ENDIF.

    *

    ENDFORM. "FILL_KEYS

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 26, 2004 at 08:27 PM

    Hi!

    I am curious about why you are using those function modules? They seem to be for internal use of program generation for class usage in programs.

    If you simply aim to generate ABAP programs, "INSERT REPORT...FROM..." , "GENERATE REPORT..." and/or "GENERATE SUBROUTINE POOL..." statements will do the work and provide dynamic programs. I guess, these are the lowest level statements we can use for this purpose. However, SAP warns about these statements.

    *--Serdar

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 27, 2004 at 05:55 AM

    Hallo Serdar,

    actually, I wasn't using function modules but generating a <b>transient</b> program. The suggestion you made would result in a <b>persistent</b> program. Both methods could be equally used but it depends on the goal. I suggested the transient method because I had the impression that different code had to be generated very often. Briefly here are the characteristics of the two methods.

    Transient Programs (with GENERATE SUBROUTINE):

    they are help in memory which means they can only be used internally by the program that created them,

    they are suited to very frequent changes in the requirements.

    Persistent Programs (with INSERT REPORT & SUBMIT REPORT):

    they are actually created meaning they can be called by any program,

    they are suitable when the code doesn't have to alter frequently,

    they can be generated by a different report than that which call it (performance consideration).

    As usual with SAP there is "more than one way to skin a cat".

    Gerard.

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 27, 2004 at 05:16 PM

    Hi Gerard

    I exactly agree with you. I think, I made you misunderstand since I didn't denote the name I was answering. But in my reply I was considering Thomas's request because he told that he was using FMs of the function group "SEOP". That's why, I wondered why he uses them and as I didn't know his choice for persistency/transiency, I suggested both "GENERATE REPORT..." and "GENERATE SUBROUTINE POOL..." .

    Still wondering how and why he uses "SEOP" functions 😊

    *--Serdar

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      If your Classes are not used outside your project you may create them as local classes within a report or function group, e.g. with insert report. This should be much faster than the generation of global classes.