Professional Documents
Culture Documents
BAPI Extension
BAPI Extension
Standard tables might not have all the fields that customer required. So, customer will be adding his
own set of fields to meet his requirement. These fields are technically called Customer-defined fields.
Standard BAPI’s hold only standard fields at compile time and we can only supply data for standard
fields. To fill the customer-defined fields using standard BAPI’s we go for Extension BAPI’s.
Every BAPI which is having EXTENSIONIN, EXTENSIONINX parameters is eligible for extension BAPI
category. We will work with these EXTENSIONIN structures to fill the data for custom fields &
EXTENSIONINX for update flags. Before proceeding further, we must ensure the below important steps
are implemented to achieve the appropriate result.
Consider ZDOC_FIELD1, ZDOC_FIELD2, ZDOC_FIELD3 are three custom fields which are appended to
standard table MARA.
(The field names must be same as the custom field names in standard table MARA and the type of these
fields should be of type character in the structure)
(Again, the field names must be same as the custom field names in standard table MARA and the type of
these fields should be of type BAPIUPDATE in the structure)
An Extension structures only holds structure name and valueparts. In our scenario, the structure names
will be BAPI_TE_MARA, BAPI_TE_MARAX for EXTENSIONIN & EXTENSIONINX respectively. While coming
to valueparts, we need to populate our custom field values into valueparts based on the field length of
the fields which we are going to update based on offset.
So here, there will be four valueparts each having 240 characters of length. Once we fill the valuepart1
completely, we need to move on to valuepart2 and so on like that.
If we consider the structure BAPI_TE_MARA, it has a total of 6 fields including custom fields and key
field.
MATNR 18
COBJID 8
COTYPE2
ZDOC_FIELD1 10
ZDOC_FIELD2 5
ZDOC_FIELD3 8
So, as we are assigning our structure BAPI_TE_MARA to Extensionin Structure, the value part of the
extensionin structure should be filled with values of BAPI_TE_MARA structure. Since valuepart contains
240 characters’ length, the data is filled in the form of offset based on length of each field in
BAPI_TE_MARA.
With respect to our structure BAPI_TE_MARA, the field MATNR has 18 character’s length. So the first 18
characters of valuepart1 is reserved for MATNR. Starting from 0 to 18 places is reserved for MATNR.
gs_extensionin-valuepart1+0(18) = gs_bapi_te_mara-material.
Since we need to fill data for ZDOC_FIELD1, I won’t consider passing data for the next two fields (COBJID,
COTYPE) but their places are reserved in valuepart1 (We shouldn’t fill anything in their respective places
if we don’t want to update, they should be left blank). From 18th character in valuepart1, next 10 (8+2)
characters places are reserved for those two fields (COBJID, COTYPE).
So, 18 + 10 = 28
We are now at 28th position and as our next field is ZZFIELD1 & its length is 10 characters.
gs_extensionin-valuepart1+28(10) = gs_bapi_te_mara-zzfield1.
Like these we need to fill data for all the custom fields which need to updated in data base table.
We need to fill the EXTENSIONINX structure in the same manner as explained above.
Source Code:
REPORT ZJP_BAPI_EXT.
* Data declarations
gs_materialdescription-matl_desc ='000000000000001592'.
CLEAR : gs_materialdescription.
gs_bapi_te_mara-material = '000000000000001592'.
gs_bapi_te_mara-ZDOC_FIELD1 = 'Field1'.
gs_bapi_te_mara-ZDOC_FIELD2 = 'F2'.
gs_bapi_te_mara-ZDOC_FIELD3 = 'F3'.
gs_extensionin-STRUCTURE = 'BAPI_TE_MARA'.
gs_extensionin-valuepart1+0(18) = gs_bapi_te_mara-material.
gs_extensionin-valuepart1+28(10) = gs_bapi_te_mara-ZDOC_FIELD1.
gs_extensionin-valuepart1+38(5) = gs_bapi_te_mara-ZDOC_FIELD2.
gs_extensionin-valuepart1+43(8) = gs_bapi_te_mara-ZDOC_FIELD3.
gs_bapi_te_marax-material = '000000000000001592'.
gs_bapi_te_marax-ZDOC_FIELD1 = 'X'.
gs_bapi_te_marax-ZDOC_FIELD2 = 'X'.
gs_bapi_te_marax-ZDOC_FIELD3 = 'X'.
gs_extensioninx-STRUCTURE = 'BAPI_TE_MARAX'.
gs_extensioninx-valuepart1+0(18) = gs_bapi_te_marax-material.
gs_extensioninx-valuepart1+20(1) = gs_bapi_te_marax-ZDOC_FIELD1.
gs_extensioninx-valuepart1+21(1) = gs_bapi_te_marax-ZDOC_FIELD2.
gs_extensioninx-valuepart1+22(1) = gs_bapi_te_marax-ZDOC_FIELD3.
* Call BAPI
EXPORTING
headdata = gs_headdata
clientdata = gs_clientdata
clientdatax = gs_clientdatax
IMPORTING
RETURN = gs_return
TABLES
materialdescription = gt_materialdescription
extensionin = gt_extensionin
extensioninx = gt_extensioninx.
IF gs_return-TYPE EQ 'S'.
EXPORTING
WAIT = 'X'.
ELSE.
ENDIF.