Abap Calling Subroutine From Another Program

Posted on -

Hi Experts, I want to call abap program (program2) from another abap program(program1). The called program 2 has its own selection screen ( or variant) and calculate multiple colums and generate output file. I would like to pass values to this second program 2 and return one of the columns from this to first program ( program 1) Could you please let me know how to pass values from first program to second program and then return column values to first program so that it can be used further. SUBMIT ZSDSDEMAND1 using selection-set 'DEMAND1' and return.

  1. Give More Feedback
  2. See More On Tutorialspoint

Subroutines in ABAP programs: Subroutines are the program modules which can be called from ABAP/4 programs. They execute a logical task within a program.

We can call subroutines by using PERFORM command. We can use it to call the subroutine of another program. Subroutine f_compute_tax of the ABAP program.

Perform statement in ABAP is used to call an ABAP subroutine from any program. These calls to the subroutine are used for carrying out calculations, for fetching the data from the database that is to be displayed at the output. Subroutines are normally called internally, that is, they contain sections of code that are used frequently. External Subroutines can be grouped into Subroutine Pools. The source code of the external subroutines will be in an ABAP/4 program other than the calling procedure. The syntax for calling an external subroutine in ABAP program is:.Call to Subroutine:.Perform TABLES USING CHANGING Subroutine Code: Form TABLES USING CHANGING Subroutines have a formal interface (USING, CHANGING, and TABLES parameters). The interface parameters can be passed BY VALUE or BY REFERENCE.

Data that is defined within a subroutine (FROM. ENDFORM.) is local: lifetime and visibility is limited to the moment the subroutine is called.

Subroutines in SAP Script: While passing internal tables to the SAP Script form the procedure that is followed is to first define the internal table in the driver program and then fetch the data into the internal table. Then call the Function Module writeform inside the loop of the internal table. But if you have to use a SAP Standard driver program then you can neither define an internal table nor call the function module writeform inside the loop. The solution to this would be using an external subroutine and then fetching all the values in the external subroutine and then pass these values to the SAP Script form using perform statement. Now since an internal table can not be passed directly to the sap script, the fetched values are passed to the sap script one by one as mentioned in the CHANGING statement.

The syntax for calling an external subroutine from SAP Script is different from normal subroutine call. In the sap script you can call the perform as shown below /: perform in program /: using /: using. /: changing /: changing /: endperform Var1 and var2 are variable symbols and may of any of the four SAP Script symbol types. Return1 and return2 are local text symbols and must be therefore character strings.

In the ABAP subroutine the form for the above subroutine is defined as shown below. FORM TABLES fpitintab STRUCTURE itcsy fpitouttab STRUCTURE itcsy. The values of the SAPscript symbols (var1 and var2) passed with /: USING. Are now stored in the internal table FPITINTAB. Note that the system passes the values as character string to the subroutine, since the field VALUE in structure ITCSY has the domain TDSYMVALUE (CHAR 255).

FPITINTAB is a structure of type ITCSY, which has 2 components, NAME and VALUE. So in the program, var1 and var2 (which are sent from SAPScript), will be stored as FPITINTAB-NAME and its value will be in FPITINTAB -VALUE. You can utilize the FPITINTAB -VALUE and after performing the required operations, the return value should be assigned to table FPITOUTAB. This value can thus be obtained in var1 and var2 specified in SAPScript. See the example below on how to access the variables. The internal table FPITOUTAB contains names and values of the CHANGING parameters in the PERFORM statement. These parameters are local text symbols, that is, character fields.

Abap Calling Subroutine From Another Program

Give More Feedback

FPITOUTAB is again a structure of type ITCSY, which has 2 components, NAME and VALUE. So in the program, return1 and return2 (which are to be returned to SAPScript), will be stored as FPITOUTAB-NAME and its value will be in FPITOUTAB-VALUE. Example: In the example below, we are fetching the address and the input is the document number. Subroutine Call in the SAP Script form In the using parameter the document number is given and in the output parameter, all the address parameters which are required to be fetched are given. PERFORM GETADRNR IN PROGRAM /FIR/RUO2CB025001 USING &VVBELN& CHANGING &VSTREET2& CHANGING &VSTREET3& CHANGING &VSTREET& CHANGING &VCITY& ENDPERFORM Subroutine Code: FORM getadrnr TABLES fpitintab STRUCTURE itcsy fpitouttab STRUCTURE itcsy. DATA DECLARATIONS. Read internal input table to get document number SORT fpitintab BY name.

READ TABLE fpitintab INTO waintab WITH KEY name = 'VVBELN' BINARY SEARCH. Cartoon tigers. IF sy-subrc = 0. Vdocnum = waintab-value. SELECT SINGLE vkorg bukrs ernam fkdat kunrg FROM vbrk INTO itvbrk WHERE vbeln = vdocnum.

SELECT SINGLE adrnr FROM tvko INTO lvadrnr WHERE bukrs = itvbrk-bukrs AND vkorg = itvbrk-vkorg. IF lvadrnr IS NOT INITIAL. Fetch address details of for the address number SELECT city1 street strsuppl1 strsuppl2 FROM adrc UP TO 1 ROWS INTO itadrc WHERE addrnumber = lvadrnr. Read internal output table to send street2 SORT fpitouttab BY name. READ TABLE fpitouttab INTO waouttab WITH KEY name = 'VSTREET2' BINARY SEARCH. IF sy-subrc EQ 0. Waouttab-value = itadrc-street2.

MODIFY fpitouttab FROM waouttab INDEX sy-tabix. Read internal output table to send street3 READ TABLE fpitouttab INTO waouttab WITH KEY name = 'VSTREET3' BINARY SEARCH. IF sy-subrc EQ 0. Waouttab-value = itadrc-street3. MODIFY fpitouttab FROM waouttab INDEX sy-tabix. Read internal output table to send street READ TABLE fpitouttab INTO waouttab WITH KEY name = 'VSTREET' BINARY SEARCH. IF sy-subrc EQ 0.

See more on tutorialspoint

See More On Tutorialspoint

Waouttab-value = itadrc-street. MODIFY fpitouttab FROM waouttab INDEX sy-tabix. Read internal output table to send city READ TABLE fpitouttab INTO waouttab WITH KEY name = 'VCITY' BINARY SEARCH. IF sy-subrc EQ 0. Waouttab-value = itadrc-city. MODIFY fpitouttab FROM waouttab INDEX sy-tabix.