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

Former Member
0 Kudos

where do we use subroutine pool program?

I

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi,

Subroutine pool programs are the programs which have many subroutines defined.

These subroutines can be called in different programs or in same program.

This u can say is an external subroutine.

Hope this information helps u.

Regards,

Aleem.

7 REPLIES 7

Former Member
0 Kudos

hi,

Subroutine pool programs are the programs which have many subroutines defined.

These subroutines can be called in different programs or in same program.

This u can say is an external subroutine.

Hope this information helps u.

Regards,

Aleem.

Former Member
0 Kudos

Creating and Starting Temporary Subroutines Locate the document in its SAP Library structure

The dynamic programs discussed in the other topics of this section are created in the R/3 Repository. This topic describes how you can create and call dynamic subroutines in the main memory.

You write the source code of the subroutines as explained in Creating a New Program Dynamically into an internal table. To generate the program, you use the following statement:

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.

Note

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.

Example

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. The output is as follows:

This graphic is explained in the accompanying text

A generation error occurred since the WRITE statement has been misspelled in the second subroutine, DYN2. After that line has been revised:

APPEND

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

TO CODE.

the output looks as follows:

This graphic is explained in the accompanying text

Generation was successful. The internal program name is displayed. Then, the subroutines of the subroutine pool are called. Note that you do not need to know the program name to call the subroutines.

Former Member
0 Kudos

Subroutine Pool Programs contains all the declaration of Subroutines.

In standard SAP Programs, they keep all the Subrotine declaration at one place and call it as Subroutine Pool.

Former Member

Former Member
0 Kudos

Hi,

Type S programs are not executable. They are container programs for subroutines that should only be called externally. When you call a subroutine from an ABAP program, the entire main program is loaded into the internal session of the current program. Since type S programs contain mainly subroutines, they are known as subroutine pools.

Regards,

Jagadeesh.

Former Member
0 Kudos

Hi

The subroutine program is the definition of subroutines. It can not be executed. But you can include it in

your executable program and then can call the subroutine defined in the subroutine program.