Ask the Expert

How to dynamically pass an internal table name thru a subroutine

I need to dynamically pass an internal table name thru a subroutine. And I must be able to process the internal table, which I accepted as a parameter. How do I go about accomplishing this? Here is my program for reference:

DATA : BEGIN OF LINE OCCURS 0,
       LINE1 TYPE I,
       LINE2 TYPE I,
       LINE3 TYPE I,
       END OF LINE.
DATA : INT_NAME(10) TYPE C,
       FUN_NAME(10) TYPE C,
       SORT1(10) TYPE C,
       SORT2(10) TYPE C.


LINE-LINE1 =  1.
LINE-LINE2 =  10.
LINE-LINE3 =  100.
APPEND LINE.
LINE-LINE1 = 2.
LINE-LINE2 = 20.
LINE-LINE3 = 200.
APPEND LINE.
LINE-LINE1 = 3.
LINE-LINE2 = 30.
LINE-LINE3 = 300.
APPEND LINE.
LINE-LINE1 = 4.
LINE-LINE2 = 40.
LINE-LINE3 = 400.
APPEND LINE.
* This is the internal table name passing as a parameter.
INT_NAME = 'line'.

PERFORM COMPUTE_IT USING (INT_NAME) FUN_NAME SORT1 SORT2.


*---------------------------------------------------------------------*
*       FORM compute_it                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  PINT_NAME                                                     *
*  -->  PFUN_NAME                                                     *
*  -->  PSORT1                                                        *
*  -->  PSORT2                                                        *
*---------------------------------------------------------------------*
FORM COMPUTE_IT USING (PINT_NAME) LIKE INT_NAME PFUN_NAME  PSORT1
PSORT2  .
  WRITE : PINT_NAME.
  LOOP AT PINT_NAME.
    WRITE: LINE-LINE1.
    WRITE: LINE-LINE2.
    WRITE: LINE-LINE3.
  ENDLOOP.

ENDFORM.

    Requires Free Membership to View

One way is to use GENERATE SUBROUTINE POOL to dynamically create the form. This statement takes an internal table containing ABAP source code, and puts it into a temporary subroutine pool, which only exists for the duration of your program. By constructing the internal table according to the value of INT_NAME, you will be able to achieve what you want. Forms in the temporary subroutine pool can be called using PERFORM (formname) IN PROGRAM (progname), where progname is set by the GENERATE SUBROUTINE POOL command.


This was first published in May 2002

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: