0% found this document useful (0 votes)
3 views

BAPI in ABAP

BAPI (Business Application Programming Interface) is a preferred method for large-scale data migration in SAP systems, as it is faster and more reliable than BDC (Batch Data Communication). The document outlines the advantages of BAPI over BDC, including its ability to maintain compatibility during upgrades and direct database updates. It also provides a detailed implementation guide and code examples for using BAPI to upload material data.

Uploaded by

Ashrar Ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

BAPI in ABAP

BAPI (Business Application Programming Interface) is a preferred method for large-scale data migration in SAP systems, as it is faster and more reliable than BDC (Batch Data Communication). The document outlines the advantages of BAPI over BDC, including its ability to maintain compatibility during upgrades and direct database updates. It also provides a detailed implementation guide and code examples for using BAPI to upload material data.

Uploaded by

Ashrar Ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

4️⃣

BAPI
1. Introduction
BAPI stands for Business Application Programming Interface

BAPI is a technique which is used to conduct a large scale data migration

BAPIs in the SAP Systems are implemented as RFC enabled function modules.

When we create a business object for a RFC enabled function module and we merge it with
the function module then we call it a BAPI.

i.e. BAPI = RFC Function Module + Business Object

BAPI is always preferable as compared to BDC for data migration.

2. Why BAPI is more preferable as compared to


BDC ?
1. BDC
Upgradation :- When we go for upgradation, there might be possibility to change the screen
elements or numbers depending on the requirement. In that case, our existing BDC Program

BAPI 1
Mob No :- +916261538504
may or may not work. Unless and util we prepare new BDC recording, So, in that case we
can’t use the OLD BDC Program.

Faster :- BDC run through the screen flow to update the database. So, It is slower as
compared to BAPI.

2. BAPI
Upgradation :- In BAPI, SAP promises that they are going to keep the old BAPI and for new
functionality they will provide an upgraded BAPI. Until we write a new BAPI Program, we
can use the existing BAPI Program.

Faster :- BAPI directly updates the database, So it is faster as compared to BDC.

3. Some Important BAPIs for Data Migration


Create and Change Material Master Data :-

BAPI_MATERIAL_SAVEDATA

Creating a Purchase Order :-

BAPI_PO_CREATE1

4. Requirement
We will upload the below material data from notepad using BAPI.

BAPI 2
Mob No :- +916261538504
5. Implementation
Step 1 :- We will create a type structure and internal table for the same.

Step 2 :- We will use At Selection Screen on value request event and F4_Filenname method
to pick our file from local system.

BAPI 3
Mob No :- +916261538504
Step 3 :- Then In Start of Selection Event we will upload our File using GUI_UPLOAD
method.

Step 4 :- Then we will loop on our internal table.

Step 5 :- Inside the loop we will call the BAPI_MATERIAL_SAVEDATA function module.

BAPI 4
Mob No :- +916261538504
Step 6 :- For the HEADATA parameter, we will create a work area and in that work area we
will pass MATERIAL, IND_SECTOR, MATL_TYPE, BASIC_VIEW.

Step 7 :- We will create a work area for CLIENTDATA and we will pass unit of
measurement into it.

BAPI 5
Mob No :- +916261538504
Step 8 :- Whatever data you will pass in CLIENTATA, you will have to mark it as TRUE in
CLIENTDATAX parameter.

Step 9 :- Now we will create a internal table for MATERIALDESCRIPTION parameter and
we will pass our material description and language in this table.

BAPI 6
Mob No :- +916261538504
and we will pass this into MATERIALDESCRIPTION parameter.

Step 10 :- We will create a return work area for the RETURN parameter.

then we will pass the work area into RETURN parameter.

Step 10 :- Just before ending of loop we will append the RETURN work area into internal
table and we will clear the description internal table.

Step 11 :- After the ending of loop we will use DISPLAY our return table.

BAPI 7
Mob No :- +916261538504
6. Code
TYPES : BEGIN OF TY_MATERIAL,
MATNR TYPE MATNR,
MBRSH TYPE MBRSH,
MTART TYPE MTART,
MAKTX TYPE MAKTX,
MEINS TYPE MEINS,
END OF TY_MATERIAL.

DATA : LT_MATERIAL TYPE TABLE OF TY_MATERIAL,


LS_MATERIAL TYPE TY_MATERIAL.
DATA : LV_FILE TYPE STRING.

DATA : LS_HEADDATA TYPE BAPIMATHEAD.


DATA : LS_CLIENTDATA TYPE BAPI_MARA.
DATA : LS_CLIENTDATAX TYPE BAPI_MARAX.

DATA : LT_DESCRIPTION TYPE TABLE OF BAPI_MAKT,


LS_DESCRIPTION TYPE BAPI_MAKT.

DATA : LT_RETURN TYPE TABLE OF BAPIRET2,

BAPI 8
Mob No :- +916261538504
LS_RETURN TYPE BAPIRET2.

PARAMETERS : P_FILE TYPE LOCALFILE.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.


CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = P_FILE.

START-OF-SELECTION.
LV_FILE = P_FILE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = LV_FILE
* FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* FILENAME1 = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES

BAPI 9
Mob No :- +916261538504
DATA_TAB = LT_MATERIAL
* CHANGING
* ISSCANPERFORMED = ' '
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17.

LOOP AT LT_MATERIAL INTO LS_MATERIAL.

LS_HEADDATA-MATERIAL = LS_MATERIAL-MATNR.
LS_HEADDATA-IND_SECTOR = LS_MATERIAL-MBRSH.
LS_HEADDATA-MATL_TYPE = LS_MATERIAL-MTART.
LS_HEADDATA-BASIC_VIEW = 'X'.

LS_CLIENTDATA-BASE_UOM = LS_MATERIAL-MEINS.
LS_CLIENTDATAX-BASE_UOM = 'X'.

LS_DESCRIPTION-LANGU = SY-LANGU.
LS_DESCRIPTION-MATL_DESC = LS_MATERIAL-MAKTX.
APPEND LS_DESCRIPTION TO LT_DESCRIPTION.

BAPI 10
Mob No :- +916261538504
CLEAR LS_DESCRIPTION.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'


EXPORTING
HEADDATA = LS_HEADDATA
CLIENTDATA = LS_CLIENTDATA
CLIENTDATAX = LS_CLIENTDATAX
* PLANTDATA =
* PLANTDATAX =
* FORECASTPARAMETERS =
* FORECASTPARAMETERSX =
* PLANNINGDATA =
* PLANNINGDATAX =
* STORAGELOCATIONDATA =
* STORAGELOCATIONDATAX =
* VALUATIONDATA =
* VALUATIONDATAX =
* WAREHOUSENUMBERDATA =
* WAREHOUSENUMBERDATAX =
* SALESDATA =
* SALESDATAX =
* STORAGETYPEDATA =
* STORAGETYPEDATAX =
* FLAG_ONLINE = ' '
* FLAG_CAD_CALL = ' '
* NO_DEQUEUE = ' '
* NO_ROLLBACK_WORK = ' '
IMPORTING
RETURN = LS_RETURN
TABLES
MATERIALDESCRIPTION = LT_DESCRIPTION
* UNITSOFMEASURE =
* UNITSOFMEASUREX =
* INTERNATIONALARTNOS =
* MATERIALLONGTEXT =
* TAXCLASSIFICATIONS =

BAPI 11
Mob No :- +916261538504
* RETURNMESSAGES =
* PRTDATA =
* PRTDATAX =
* EXTENSIONIN =
* EXTENSIONINX =
.

APPEND LS_RETURN TO LT_RETURN.


CLEAR : LT_DESCRIPTION.

ENDLOOP.

CL_DEMO_OUTPUT=>DISPLAY( LT_RETURN ).

7. Output

8. Checking data in MARA TABLE

BAPI 12
Mob No :- +916261538504

You might also like