Sei sulla pagina 1di 5

BAPI- What is it and how its used [Part 1]

BAPI's are basically function modules only. ALL BAPI's are remote enabled function modules
which enables to access via non SAP systems.
A remote function enabled FM(Function Module) will be attached to BOR(Business Object
Repository) , then only it is termed as BAPI. Using BAPIs you can develop applications without
detailed knowledge of the underlying R/3 System.
Each BAPI is having its own business application and area. The integration between R/3 and
third-party software, legacy systems, and custom-developed software can be achieved via BAPI.
BAPI explorer with TCODE 'BAPI'.

BAPI explorer
All BAPI's are arraigned according to the business area. Details documentation is also available
for some BAPI's to show the usage of the BAPI

Documentation of each BAPI


BAPI since its RFC enabled FM, has no exceptions. There are BAPI return tables which can be
used to analyze the success/failure of the process.
Since BAPI's are basically FM only , we call BAPI the same way we call a normal FM.
Its very important to select appropriate BAPI and also to pass the data in a way required by
BAPI. Go through all I/O structures for the BAPI selected to understand this better. We can also
call BAPI of other SAP systems. Just mention destination and you are good to go.
Ex:
call function 'BAPI_SALESORDER_GETSTATUS'
destination 'PW2'
exporting
salesdocument = order
importing
return
= return
tables
statusinfo = statusinfo.
We need to call BAPI_TRANSACTION_COMMIT after each BAPI call to finalize or commit
the change or if some error occurs and we have identified the errors we need to use
BAPI_TRANSACTION_ROLLBACK to rollback the changes made if any.

Steps in using BAPI :


1) Find out which BAPI to be used.
Example: To create material found out that BAPI_MATERIAL_SAVEDATA can be used
2) Go to function builder SE37 and see the BAPI. See import and export parameters. Double
click on the structure or table type to know whether the fields involved in your program/report
are present or not.
3) find out which are fields you require and accordingly create variables of that type only.
Avoid 'like' and use 'type' and' type table of' in case of tables.
4) Pass the values to the BAPI function. Tables parameters requires variables with Header
line. All others are just work area.
5) Always after calling BAPI call , BAPI_TRANSACTION_COMMIT to commit the changes

(After each BAPI call this has to be done )


6) Keep a breakpoint and look at BAPI return. IF success it shows success message also if
problem it lists the problem clearly.

BAPI RETURN TABLE


7) In case of long text . See the function documentation of BAPI. Use accordingly. Just append
each text_line and there you go it will pass long text.
Example program to create/update a material along with long text
description of the material.
123
456
789
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

*&--------------------------------------------------------------*& Report ZAU_BAPITEST


*&
*&--------------------------------------------------------------*&
*&
*&--------------------------------------------------------------REPORT zau_bapitest.
DATA: lwa_bapihead TYPE bapimathead,
lwa_mara
TYPE bapi_mara,
lwa_marax
TYPE bapi_marax,
lit_return
TYPE bapiret2,
lit_makt
TYPE TABLE OF bapi_makt WITH HEADER LINE,
lit_mltx
TYPE TABLE OF bapi_mltx WITH HEADER LINE.
lwa_bapihead-material = '14842132B'.

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

lwa_bapihead-ind_sector = 'T'.
lwa_bapihead-matl_type = 'TROH'.
lwa_bapihead-basic_view = 'X'.
lwa_mara-base_uom = 'KGS'.
lwa_mara-matl_group = '00104'.
lwa_marax-matl_group = 'X'.
lwa_marax-base_uom = 'X'.
lit_makt-langu = '001'.
lit_makt-langu_iso = 'EN'.
lit_makt-matl_desc = ' This is created by using BAPI yeah !! '.
APPEND lit_makt.
lit_mltx-applobject = 'MATERIAL'.
lit_mltx-text_name = lwa_bapihead-material.
lit_mltx-text_id = 'GRUN'.
lit_mltx-langu ='001'.
lit_mltx-langu_iso = 'EN'.
lit_mltx-text_line =' This is 1st line'.
APPEND lit_mltx.
lit_mltx-applobject = 'MATERIAL'.
lit_mltx-text_name = lwa_bapihead-material.
lit_mltx-text_id = 'GRUN'.
lit_mltx-langu ='001'.
lit_mltx-langu_iso = 'EN'.
lit_mltx-text_line =' This is 2st line'.
APPEND lit_mltx.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata
= lwa_bapihead
clientdata
= lwa_mara
clientdatax
= lwa_marax
* PLANTDATA
=
* PLANTDATAX
=
* FORECASTPARAMETERS
=
* FORECASTPARAMETERSX
=
* PLANNINGDATA
=
* PLANNINGDATAX
=
* STORAGELOCATIONDATA
=
* STORAGELOCATIONDATAX
=
* VALUATIONDATA
=

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

* VALUATIONDATAX
=
* WAREHOUSENUMBERDATA
=
* WAREHOUSENUMBERDATAX
=
* SALESDATA
=
* SALESDATAX
=
* STORAGETYPEDATA
=
* STORAGETYPEDATAX
=
* FLAG_ONLINE
=''
* FLAG_CAD_CALL
=''
* NO_DEQUEUE
=''
* NO_ROLLBACK_WORK
=''
IMPORTING
return
= lit_return
TABLES
materialdescription
= lit_makt
materiallongtext
= lit_mltx
.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT
=
* IMPORTING
* RETURN
=
.
WRITE:/ lit_return-type.

Potrebbero piacerti anche