Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

subroutine pool

Former Member
0 Kudos
1,266

Hi all,

how to run the subroutine pool program .

regards.

Krishna

2 REPLIES 2

Former Member
0 Kudos
381

Hi Krishna

You cannot run a Subroutine pool program.

~ Ranganath

Former Member
0 Kudos
381

Hi,

Subroutine Pools

Subroutine pools are created using the ABAP Editor and are introduced with the PROGRAM statement. They may not contain any screens of their own, and with the exception of the LOAD-OF-PROGRAM event block they may only use subroutines as processing blocks. Subroutine pools are loaded by externally calling their subroutines from within other ABAP programs.

How to Use

Syntax

GENERATE SUBROUTINE POOL <itab> NAME <prog> [<options>].

This statement creates a subroutine pool in the main memory area of the running program. You pass the source code of the subroutine pool in internal table <itab>. The statement returns the name of the generated subroutine pool in field <prog> that should have type C of length 8. You use the name in <prog> to call the external subroutines defined in table <itab> through dynamic subroutine calls as explained in Specifying the Subroutine Name at Runtime.

The subroutine pool only exists during the runtime of the generating program and can only be called from within this program. You can create up to 36 subroutine pools for one program.

If an error occurs during generation, SY-SUBRC is set to 8. Otherwise, it is set to 0.

You can use the following options <options> in the GENERATE SUBROUTINE POOL statement:

MESSAGE <mess>

In the case of a syntax error, field <mess> contains the error message.

INCLUDE <incl>

In the case of a syntax error, field <incl> contains the name of the include program in which the error possibly occurred.

LINE <line>

In the case of a syntax error, field <line> contains the number of the wrong line.

WORD <word>

In the case of a syntax error, field <word> contains the wrong word.

OFFSET <offs>

In the case of a syntax error, field <offs> contains the offset of the wrong word in the line.

TRACE-FILE <trac>

If you use this option, you switch on the trace mode and field <trac> contains the trace output.

Compared to INSERT REPORT, the GENERATE SUBROUTINE POOL statement has a better performance. Furthermore, you do not have to care about naming conventions or restrictions of the correction and transport system when you use statement GENERATE SUBROUTINE POOL.

REPORT SAPMZTST.

DATA: CODE(72) OCCURS 10,

PROG(8), MSG(120), LIN(3), WRD(10), OFF(3).

APPEND 'PROGRAM SUBPOOL.'

TO CODE.

APPEND 'FORM DYN1.'

TO CODE.

APPEND

'WRITE / ''Hello, I am the temporary subroutine DYN1!''.'

TO CODE.

APPEND 'ENDFORM.'

TO CODE.

APPEND 'FORM DYN2.'

TO CODE.

APPEND

'WRIT / ''Hello, I am the temporary subroutine DYN2!''.'

TO CODE.

APPEND 'ENDFORM.'

TO CODE.

GENERATE SUBROUTINE POOL CODE NAME PROG

MESSAGE MSG

LINE LIN

WORD WRD

OFFSET OFF.

IF SY-SUBRC <> 0.

WRITE: / 'Error during generation in line', LIN,

/ MSG,

/ 'Word:', WRD, 'at offset', OFF.

ELSE.

WRITE: / 'The name of the subroutine pool is', PROG.

SKIP 2.

PERFORM DYN1 IN PROGRAM (PROG).

SKIP 2.

PERFORM DYN2 IN PROGRAM (PROG).

ENDIF.

In this program, a subroutine pool containing two subroutines is placed into table CODE. Note that the temporary program must contain a REPORT or PROGRAM statement. Statement GENERATE SUBROUTINE POOL generates the temporary program.

Regards,

Renjith Michael.