Q

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.

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

Dig deeper on SAP ABAP

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

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:

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close