Creating Data for Customer defined fields using Extension BAPI

In this post, we will be learning how to create or update data for Customer-defined fields in standard table using Extension BAPI. In my previous post, I had explained how to create data using standard BAPI’s. In case if you missed it, Click here to view it.

Note: Please follow up the previous post as same example will be extended for this scenario also.

How this Extension BAPI works? 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 ZZFIELD1, ZZFIELD2, ZZFIELD3 are three custom fields which are appended to standard table MARA. Now our requirement is to update these customer defined fields using standard BAPI. For this to happen, there are mainly 3 steps to be performed.

Step 1: Append these 3 custom fields to BAPI_TE_MARA structure.

(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)

Step 2: Append these 3 custom fields to BAPI_TE_MARAX 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)

Wonder why am I adding custom fields to BAPI_TE_MARA, BAPI_TE_MARAX structures? These structures are specified under EXTENSIONIN parameter of the BAPI_MATERIAL_SAVEDATA documentation. As like we discussed earlier, in case of extension BAPI also the structures will be mentioned in the standard documentation.

Step 3: Implement logic to populate values into these custom fields or BAPI_TE_MARA, BAPI_TE_MARAX with the key field value. Finally append these structures BAPI_TE_MARA, BAPI_TE_MARAX to EXTENSIONIN, EXTENSIONINX internal table respectively and pass them to BAPI.

Now we shall implement the above steps.

Before that we will have a look at Customer-defined fields in MARA table which need to be supplied with data.

Image_16

Here we will supply data to custom fields ZZFIELD1, ZZFIELD2, ZZFIELD3.

Step 1: Append these 3 custom fields to BAPI_TE_MARA structure

Image_17

Step 2: Append these 3 custom fields to BAPI_TE_MARAX structure

Image_18

Note: Make sure you appended the fields to respective structures with same field names as in standard table MARA and their types as in above.

Step 3: Implement logic to populate these fields and send it to BAPI

Image_19

Image_20

Here we should be very careful while populating the extension structures, because these 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.

So how to fill data into this valuepart?

If we consider the structure BAPI_TE_MARA, it has a total of 6 fields including my custom fields and key field.

Field name Field length
MATNR 18
COBJID 8
COTYPE 2
ZZFIELD1 10
ZZFIELD2 5
ZZFIELD3 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.

Since we need to fill data for ZZFIELD1, 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.

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.

And finally pass it to BAPI.

Note: If the data is not updated into custom fields, then we need to do some configurations in T-code OMSR by creating new entries for custom fields, assigning maintenance status & selection group number.

Click here to do the configurations

Leave a Reply