"In ABAP it is very convenient to run a report using a Variant. Basically a report can have several Variants linked to it. If you use a variant then the data entry time is reduced considerably and this also reduces data entry errors. The load on the ABAP processing is also reduced. To create a Variant you may need the necessary authorizations. Most of the times while testing programs you will need to run a report using a variant and hence having the authorization to create a Variant is necessary. To create a Variant go to the main reporting screen, enter the name of the report for which you want to create the variant and select goto Variants option from the menu. The system displays the initial screen for the Variants. For creating a Variant you need to enter all the mandatory fields. Also you need to give a unique name for the Variant. Follow the naming convention rules. You may have to create several Variants for a particular report. Once a Variant is created you ca also schedule to run the report in the background using this Variant. For each variant that you create you need to give a brief description which will help to explain the purpose of the variant and help to distinguish the various Variants that you have created. You may want to protect your Variant by selecting the Protect Variant option. This option enables only the person who has created the Variant to change or delete it. While Running a report directly from the menu you can use the Run with Variant option and then select the desired variant from the dropdown list. Remember that Variants are report dependant. So to create a Variant you need to first create an ABAP report (Executable Program with selection screen). Once you successfully create all the variants for an ABAP report, you will save considerable amount of time which would otherwise have been spent in entering the same data again and again."
"SAP has provided two different types of methods for BDC to do its work. Among these the first one is called the classical method. This method is also called as the session method. Through this method the data can be read by the BDC program from a sequential dataset file. This sequential dataset file is stored in batch-input sessions. In order to run the transaction in this session, What you need is to execute the session. For this follow these few steps. YOu an start and subsequently monitor the sessions firstly from System----> Service---->Batch input or have the sessions run in the background."
Many a times it is required to pass data from one ABAP program to another. This can be done using the EXPORT and IMPORT statement in ABAP. Please find the examples given below.
REPORT ZEX_MEMORY .
Data: D_MEMORY(20) value 'BEFORE EXPORT', MEMID(5) value 'MEMID'.
write:/ D_MEMORY.
EXPORT D_MEMORY to MEMORY ID MEMID.
D_MEMORY = 'MOVED BEFORE IMPORT'.
write:/ '"Value before import"', D_MEMORY.
EXPORT D_MEMORY to MEMORY ID MEMID.
write:/ sy-subrc, ' "Value after import"', D_MEMORY.
FREE MEMORY ID MEMID.
IMPORT D_MEMORY from MEMORY ID MEMID.
write:/ sy-subrc, ' "Value after freeing memory"', D_MEMORY.
As you can see from the above example the field D_MEMORY can be exported to memory and then imported back. Once you are done with importing the value you need to FREE the memory ID. Please make sure that you free only the MEMORY ID exported by you. Here we are using the syntax given below.
EXPORT filed1 to MEMORY ID MEMID. IMPORT filed1 from MEMORY ID MEMID. FREE MEMORY ID MEMID.
You can also export field contents to memory from one program and import them in another program. Please see the code given below.
PROGRAM1Passing Values from one program to other in SAP ABAP
REPORT ZEX_MEMORYEXPORT .
Data: D_MEMORY1(100) value 'Exportfromprog1'.
EXPORT D_MEMORY1 D_MEMORY2 FROM 'EXPORTING THIS FROM PROGRAM1' TO MEMORY ID 'MEMID1'.
SUBMIT ZEX_MEMORY1 and RETURN.
write:/ sy-subrc, D_MEMORY1.
The above program will call the following program, since the value 'EXPORTING THIS FROM PROGRAM1' has already been exported to ABAP Memory it can be retrieved as shown in the program given below.
PROGRAM 2Passing Values from one program to other in SAP ABAP
REPORT ZEX_MEMORY1 .
Data: D_MEMORY1(100).
EXPORT D_MEMORY1 TO MEMORY ID 'MEMID1'.
IMPORT D_MEMORY2 TO D_MEMORY1 FROM MEMORY ID 'MEMID1'. WRITE: / SY-SUBRC, D_MEMORY1.
As shown in program 1 and 2 the value 'EXPORTING THIS FROM PROGRAM1' is passed from ABAP memory from one program to the other. See Also SET PARAMETER GET PARAMETERS SUBMIT PROGRAM
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.
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-------------------------------------------------------
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.
Always specify your conditions in the Where-clause instead of checking
them yourself with check statements. The database system can then use an index
(if possible) and the network load is considerably less.
Always use Pretty Printer and Extended Program Check before releasing the code.
Do not leave unused code in the program. Comment the code thoroughly. Align the comments and the Code. Follow the SAP Standards and SAP Best Practices guidelines. It’s a good practice to take a dump of the code on your local drive.