cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (5)

Answers (5)

ssimsekler
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Serdar Simsekler wrote:

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

Well, because we are using ABAP objects, i.e. the object-oriented part of ABAP, classes, to be more specific.

We have quite some experience in that here.

The problem just is that we are using it on such a large

scale that it creates performance and manageability problems at times.

While our Framework developers can cope with it, the average application programmer is somewhat overwhelmed.

So I wondererd if there may not be a different, more

straightforward way to generate ABAP classes and methods.

thomas

ssimsekler
Active Contributor
0 Kudos

Hi Thomas

So, you are coding dynamic classes to be generated at runtime? I also use ABAP Objects, but my usage has two kinds:

1. Just implementing classes as repository objects which are then saved and generated in the system and instantiated in programs.

2. Implementing classes directly in an application program by hardcoding and then instantiating them within the visible area.

Your task (coding dynamic classes) is in fact really beyond my vision and now I wonder why you require dynamic classes (never ends, it started with my question to mum "From where did I come?"). And still I think there is no more convenient way to generate your dynamic classes other then these FMs. Sorry about my curiosity...

*--Serdar

Former Member
0 Kudos

>Hi Thomas

>So, you are coding dynamic classes to be generated at >runtime?

No. We are generating classes at design time from template

desctiptions.

thomas

former_member183804
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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.

ssimsekler
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

joerg_wegener
Explorer
0 Kudos

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