Monday, April 14, 2008

SAP ABAP Calling Executable Programs

SAP ABAP Calling Executable Programs

If you wish to call an executable  ABAP progra from another ABAP program/report you can do so by using the SUBMIT statement.  For example your wish to call program <CALLEDPROGARM> from the current program <CURRENTPROGRAM> then the control can either be passed to the called program or once the called program has finished its job the control cab be RETURNED to the calling program. Please find the Syntax below.

SUBMIT prog|(variable) [AND RETURN] [options].

The called program name can be directly mentioned in the code or you can dynamically pass the called program using a variable. As mentioned above once the called program finishes its job, the program can be either returned to the calling program using the RETURN option. In case RETURN is omitted then all data and list levels of the calling program (the entire internal session) are deleted. After the called executable program has finished, control returns to the level from which you started the calling program. Whereas if the RETURN option is used then the control is returned to the statement after SUBMIT and the calling program continues its operation.

In case the called program has a selection screen then the SUBMIT statement can be used with the various options as shown below.


SUBMIT             [VIA SELECTION-SCREEN]
                        [USING SELECTION-SET var]


The following code will make things clearer.

The following is the called program

REPORT ZEXERCISE_1 MESSAGE-ID ZEXERCISE1.
 .
************************************************************************
*                                                                                                                          *
*            This Report Displays Sales Order Header Data                                      *
*                                                                                                                          *
*                                                                                                                          *
************************************************************************

* Tables Declaration----------------------------------------------------
Tables: VBAK,   " Sales Document: Header Data
        VBPA,   " Sales Document: Partner
        VBKD.   " Sales Document: Business Data

* Data Declaration------------------------------------------------------
data:   d_soldto(10), " Sold to party
        d_shipto(10), " Shipt to Party
        d_buyer(10),  " Buyer
        d_billto(10). " Bill to Party

* Select Options--------------------------------------------------------
Select-options: S_VBELN for vbak-vbeln. " Sales Order Number

* Start of Selection----------------------------------------------------
Start-Of-Selection.
Select vbeln
       netwr
       waerk into (vbak-vbeln, vbak-netwr, vbak-waerk) from vbak where
                                                      vbeln in s_VBELN.

       endselect.
* Select Buyer---------------------------------------------------------
  select single kunnr
          into d_buyer from vbpa where parvw = 'BU' or parvw = 'RE' and
                                                    vbeln = S_VBELN-LOW.
* Select Bill to Party-------------------------------------------------
  select single kunnr
          into d_billto from vbpa where parvw = 'BP' or parvw = 'WE' and
                                                    vbeln = S_VBELN-low.
* Select Sold to Party--------------------------------------------------
  select single kunnr
          into d_soldto from vbpa where parvw = 'SP' or parvw = 'AG' and
                                            vbeln = S_VBELN-low .
* Select Shipt to Party-------------------------------------------------
  select single kunnr
               into d_shipto from vbpa where parvw = 'SH' and
                                            vbeln = S_VBELN-low .
* Output the data-------------------------------------------------------



write:/ vbak-vbeln, d_buyer, vbak-netwr, d_billto, d_soldto, d_shipto,
vbak-waerk.

The following the the calling program.

REPORT ZEXERCISE_SUBMIT .


Data: d_value1(10).

d_value1 = 'Test1'.

SUBMIT ZEXERCISE_1 via selection-screen and RETURN.

write: d_value1.



EXERCISE

Please try the following options.

1) From the calling program's SUBMIT statement remove the and RETURN Option and see the result. If and RETURN is removed the the value of d_value1 is not written on the screen. Where as if and RETURN is not omitted then the control is given back to the called program at the next statement after SUBMIT and the value of d_value1 ie Test1 is written on the screen.

2) Create a variant for the program (see creating variants for ABAP Programs). And use the statement given below. And see the result. Note that SORD is the variant name and you need to replace it with the name given by you.

SUBMIT ZEXERCISE_1 using selection-set 'SORD'.

No comments:

Post a Comment