Tuesday, January 3, 2012

BAPI Return Parameter- BAPIRETURN/BAPIRET1/BAPIRET2



One of the distinguishing characteristics of a BAPI from the remote enabled function module is the return parameter which is either BAPIRETURN/BAPIRET1/BAPIRET2.RFCs can use the return parameter but it need not be BAPIRETURN/BAPIRET1/BAPIRET2. One of the fundamental  rules for BAPI is :it should be able to record and classify all possible errors that may occur.The Parameter named Return serves this purpose.It returns exception messages or success messages to the calling program
BAPIs themselves must not trigger any messages in the coding. In particular they must not generate terminations or display dialog boxes. Instead, all messages must be intercepted internally and reported back to the calling program in the Return parameter. Otherwise the BAPI will not be processed correctly and control may not be given back to the calling program. You must not use exceptions in BAPI interfaces.

Again,many of you would have the confusion whether to use BAPIRETURN or BAPIRET1 or BAPIRet2 when developing new BAPIs.Before we answer that question, we shall explore all the BAPI structures .

When the return parameter was first introduced in BAPI, its was BAPIRETURN and structure still remains the same.So the earliest BAPIs which have still not undergone drastic changes still has this Return type. It is a general structure for a BAPI return parameter. It is filled by function module BALW_BAPIRETURN_GET.
As of release 4.0A use BAPIRETURN1 and function module BALW_BAPIRETURN_GET1



Now, there is a hugh demerit for BAPIRETURN.As you see in the structure, Message handling or the error handling techniques are less.The number of parameters needed to capture the error or success has not been elaborate.This was the reason the next generation BAPIs were introduced with return type BAPIRET1.The structure of BAPIRET1 is as shown below. This structure is filled via the function module BALW_BAPIRETURN_GET1.


To Make more elaborate and strong on the error handling , BAPIRET2 was introduced.This has been the latest Return parameter for BAPI.

SAP also recommends to use BAPIRET2 as the return parameter for the new BAPIS being developed.The only exceptional case of using BAPIRETURN /BAPIRET1 is when you creating a custom BAPI based on old BAPIs and do not want the elaborate BAPIRET2.


The export parameter Return of BAPI can be implemented as follows:
  • As a structure, whereby it must be defined in the function module as an export parameter, as well as in the method in the BOR.
  • As a table, whereby it must be defined in the function module as a table parameter, as well as in the method in the BOR as an export parameter.
Before filling the Return parameter you should either initialize the structure with CLEAR or the table with REFRESH and CLEAR.If this is not done, proper detection of errors can not be possible.Hence its very important.
If the return parameter is not set or is set to an initial value this means that no error has occurred.
The Return parameter may be based on the following reference structures:
  • BAPIRET2
You must use this reference structure when developing new BAPIS.
  • BAPIRET1, BAPIRETURN
These reference structures are still partly used in old BAPIs.
Both structures must be filled in the logon language.


No comments:

Post a Comment