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.
Dig Deeper on SAP ABAP
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.
Meet all of our SAP administration / development experts
View all SAP administration / development questions and answers
Start the conversation
0 comments