BAPI in ABAP
BAPI in ABAP
BAPI
1. Introduction
BAPI stands for Business Application Programming Interface
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.
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.
BAPI_MATERIAL_SAVEDATA
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 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.
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.
BAPI 8
Mob No :- +916261538504
LS_RETURN TYPE BAPIRET2.
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.
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.
BAPI 11
Mob No :- +916261538504
* RETURNMESSAGES =
* PRTDATA =
* PRTDATAX =
* EXTENSIONIN =
* EXTENSIONINX =
.
ENDLOOP.
CL_DEMO_OUTPUT=>DISPLAY( LT_RETURN ).
7. Output
BAPI 12
Mob No :- +916261538504