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

subroutine

Hi,

If a subroutine is dynamically called from other programs,how can we know from where it is being called?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 06:24 AM

    Hi

    Hope it will help you,.

    Pls reward if help.

    Subroutine Pools

    Subroutine pools, as the name implies, were created to contain selections of subroutines that can be called externally from other programs. Before release 6.10, this was the only way subroutine pools could be used. But besides subroutines, subroutine pools can also contain local classes and interfaces. As of release 6.10, you can connect transaction codes to methods. Therefore, you can now also call subroutine pools via transaction codes. This is the closest to a Java program you can get in ABAP: a subroutine pool with a class containing a method – say – main connected to a transaction code.

    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.

    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.

    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.

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 07:16 AM

    Hi,

    Catch the value of sy-cprog in one variable,it will throw the program which called the subroutine.

    Regards,

    Renjith Michael.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 07:34 AM

    hi,

    SY-CPROG gives the program name of external procedure call.

    reward if helpful..

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.