A Step by Step Guide For Beginners

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 66

A step by step guide for beginners on user defined BAPI creation in SAP S/4HANA

1 BAPIs

1.1 Use
A Business Application Programming Interface (BAPI) is a programming interface by means of which
you can access the business data and processes of the SAP system from a different application system.

2 Business Application Programming Interface (BAPI)

2.1 Use
The SAP business objects stored in the Business Object Repository (BOR) encapsulate their data and
processes. External access to the data and processes is only possible by means of specific methods
- BAPIs (Business Application Program Interfaces).

A BAPI is defined as a method of an SAP Business Object Type or of an SAP Interface Type.

Example
The functions that are implemented in the SAP business CostCenter object type include, for
example, listing all the available cost centers. The business object type CostCenter provides the
BAPI GetList() for this purpose.

The BAPIs in the SAP Systems are currently implemented as function modules, which are created
and managed in the Function Builder. Each function module underlying a BAPI:

▪ Supports the Remote Function Call (RFC) protocol

▪ Has been assigned as a method to a SAP business object type in the Business Object
Repository

▪ Is processed without returning any screen dialogs to the calling application Integration

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
1
2.2 Integration
The graphic below shows the relationship between an SAP business object type, its associated BAPIs
and its function modules.

Business Object Type with BAPIs and Associated Function Modules

This architecture enables SAP to change the implementation of a BAPI without affecting external
applications that are using the BAPI. For information on SAP policy for enhancing BAPIs, and SAP
release strategy for BAPIs, see SAP Enhancements to Released BAPIs (CA-BFA).

2.3 Prerequisites
To use a BAPI method to access data in SAP business objects, an application program only needs to
'know' how to call the method. The following information is required:

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
2
▪ The name of the BAPI

▪ Details of the BAPI interface:

▪ Import parameters, which contain data to be transferred from the calling program to the
BAPI

▪ Export parameters, which contain data to be transferred from the BAPI back to the calling
program

▪ Import/export (table) parameters for both importing and exporting data

Application programmers can work with SAP business objects and implement their BAPIs without
needing to know or consider the underlying implementation and coding details for the object.

3 A guide for beginners on user defined BAPI creation

3.1.1 Summary
A simple guide for beginners on creating a user defined BAPI and how to test it. The guide is prepared
in a step by step format with almost all possible screenshots. This guide contains 5 stages which are
explained in 30 simple steps. A basic knowledge in ABAP and Function module is preferred for the
reader.
Table of Contents

Stage1: Creating a structure in SE11

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
3
Stage2: Creating the function module in SE37

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
4
Stage 3: Creating the business object in SWO1

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
5
Stage 4: Viewing the created BAPI in BAPI Explorer

Stage 5: Test your BAPI

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
6
3.2 Introduction
A Business Application Programming Interface (BAPI) is a precisely defined interface providing access
to processes and data in business application systems such as SAP. BAPIs are defined as API methods
of SAP business object types. These business object types and their BAPIs are described and stored in
the Business Object Repository (BOR). A BAPI is implemented as a function module, that is stored and
described in the Function Builder.
BAPIs can be called within the SAP-System from external application systems and other programs.
BAPIs are the communication standard for business applications. BAPI interface technology forms the
basis for the following developments:
• Connecting:

• New SAP components, for example, Advanced Planner and Optimizer (APO) and Business
Information Warehouse (BW).

• Non-SAP software

• Legacy systems

• Isolating components within the SAPSystem in the context of Business Framework

• Distributed SAPscenarios with asynchronous connections using Application Link Enabling


(ALE)

• Connecting SAPSystems to the Internet using Internet Application Components (IACs)

• PC programs as frontends to the SAPSystem, for example, Visual Basic (Microsoft) or Visual
Age for Java (IBM).

• Workflow applications that extend beyond system boundaries

• Customers' and partners' own developments

BAPI is basically a RFC enabled function module. The difference between RFC enabled function module
and BAPI is business objects. You create business objects and those are then registered in your BOR
(Business Object Repository) which can be accessed outside the SAP system by using some other
applications (Non-SAP) such as VB or JAVA. In this case you only specify the business object and its
method from external system. In BAPI there is no direct system call, while RFC are direct system call.
Some BAPIs provide basic functions and can be used for most SAP business object types. These BAPIs
should be implemented the same for all business object types. In short BAPI is a RFC enabled function
module on the wrapper of Business object.
In this guide I have started with creating a structure in dictionary. Then I am creating a simple remote
enabled function module. The next step is creating a business object using SWO1 and we are adding
the above function module as a method of that business object. After completing the steps in SWO1
we will find our created BAPI in BAPI Explorer. Then we will do the testing of BAPI by inputting some
values.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
7
3.3 Stage1: Creating a structure in SE11
Step 1: Go to transaction SE11 and create a structure as shown or as per your requirement.

Do not forget to save it in a package. Check the structure (ctrl + F2) and activate (ctrl + F3) the
structure.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
8
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
9
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
10
3.4 Stage2: Creating the function module in SE37
Step 2: Go to transaction SE37 where you create function modules.
Click on create after you enter the name of the function module. Enter the function group and short
text. Now click on save button.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
11
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
12
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
13
Note: If function group is not already made, you could create it from Goto > Function group > Create
Group from the initial screen of SE37 or SE80:

SE80

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
14
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
15
SE37

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
16
Step 3: A message will be displayed ‘Function module name is reserved for SAP’. Just click continue.

Step 4: A screen will be displayed as below. In the attributes tab, make the processing type as ‘Remote-
Enabled Module’.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
17
Step 5: Now go to the Import tab and enter the details as follows or as per your requirement.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
18
PV_WERKS TYPE ZBAPITWLAD-WERKS Plant
PV_LGORT TYPE ZBAPITWLAD-LGORT Storage location
PV_LFDNR TYPE ZBAPITWLAD-LFDNR '10' Sequential address number
PV_TITLE TYPE ZBAPITWLAD-TITLE Form-of-Address Key
PV_NAME1 TYPE ZBAPITWLAD-NAME1 Name 1
PV_SORT1 TYPE ZBAPITWLAD-SORT1 Search Term 1
PV_SORT2 TYPE ZBAPITWLAD-SORT2 Search Term 2
PV_STREET TYPE ZBAPITWLAD-STREET Street
PV_HOUSE_NUM1 TYPE ZBAPITWLAD-HOUSE_NUM1 House Number
PV_POST_CODE1 TYPE ZBAPITWLAD-POST_CODE1 City postal code
PV_CITY1 TYPE ZBAPITWLAD-CITY1 City
PV_COUNTRY TYPE ZBAPITWLAD-COUNTRY Country/Region Key
PV_REGION TYPE ZBAPITWLAD-REGION Region (State, Province, County)
PV_TIME_ZONE TYPE ZBAPITWLAD-TIME_ZONE Address time zone
PV_LANGU_CREA TYPE ZBAPITWLAD-LANGU_CREA Address record
creation original language

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
19
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
20
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
21
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
22
Step 6: In the export tab enter the details as below.

*” EXPORT
*” RT_BAPIRET2
STRUCTURE BAPIRET2

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
23
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
24
In the changing tab, nothing to do.

Step 7: In the Tables tab enter the details as below.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
25
ZBAPITWLAD LIKE ZBAPITWLAD Structure BAPI update addresses of storage locations
ZRETURN LIKE BAPIRET2 Return Parameter

In the exception tab, nothing to do.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
26
Step 8: Now go to the source code tab and enter the code as shown below.

FUNCTION Z_BAPI_TWLAD_ADRC_UPDATE.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(PV_WERKS) TYPE ZBAPITWLAD-WERKS OPTIONAL
*" VALUE(PV_LGORT) TYPE ZBAPITWLAD-LGORT OPTIONAL
*" VALUE(PV_LFDNR) TYPE ZBAPITWLAD-LFDNR DEFAULT '10'
*" VALUE(PV_TITLE) TYPE ZBAPITWLAD-TITLE OPTIONAL
*" VALUE(PV_NAME1) TYPE ZBAPITWLAD-NAME1 OPTIONAL
*" VALUE(PV_SORT1) TYPE ZBAPITWLAD-SORT1 OPTIONAL
*" VALUE(PV_SORT2) TYPE ZBAPITWLAD-SORT2 OPTIONAL
*" VALUE(PV_STREET) TYPE ZBAPITWLAD-STREET OPTIONAL
*" VALUE(PV_HOUSE_NUM1) TYPE ZBAPITWLAD-HOUSE_NUM1 OPTIONAL
*" VALUE(PV_POST_CODE1) TYPE ZBAPITWLAD-POST_CODE1 OPTIONAL
*" VALUE(PV_CITY1) TYPE ZBAPITWLAD-CITY1 OPTIONAL
*" VALUE(PV_COUNTRY) TYPE ZBAPITWLAD-COUNTRY OPTIONAL
*" VALUE(PV_REGION) TYPE ZBAPITWLAD-REGION OPTIONAL
*" VALUE(PV_TIME_ZONE) TYPE ZBAPITWLAD-TIME_ZONE OPTIONAL
*" VALUE(PV_LANGU_CREA) TYPE ZBAPITWLAD-LANGU_CREA OPTIONAL
*" VALUE(PV_SIM) TYPE P06_FLOW_SIMULATION OPTIONAL

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
27
*" EXPORTING
*" VALUE(RETURN) TYPE BAPIRET2
*" TABLES
*" ZBAPITWLAD STRUCTURE ZBAPITWLAD
*" ZRETURN STRUCTURE BAPIRET2
*"----------------------------------------------------------------------

DATA GV_ADRNR TYPE TWLAD-ADRNR.


DATA GS_ADRC TYPE ADRC.

*Determination of Address from Plant and Storage Location

CLEAR GV_ADRNR.
CALL FUNCTION 'MM_DELIVERY_ADDRESS_PROPOSE'
EXPORTING
I_WERKS = PV_WERKS
I_LGORT = PV_LGORT
IMPORTING
E_ADRNR = GV_ADRNR.

IF NOT GV_ADRNR IS INITIAL.

*Reads from DB-table adrc


CALL FUNCTION 'RTP_US_DB_ADRC_READ'
EXPORTING
I_ADDRESS_NUMBER = GV_ADRNR
* I_NATION =''
* I_READ_DB=
IMPORTING
E_ADRC = GS_ADRC
EXCEPTIONS
NOT_FOUND =1
OTHERS = 2.

IF SY-SUBRC = 0.

IF NOT PV_TITLE IS INITIAL.


GS_ADRC-TITLE = PV_TITLE.
ENDIF.
IF NOT PV_NAME1 IS INITIAL.
GS_ADRC-NAME1 = PV_NAME1.
ENDIF.
IF NOT PV_SORT1 IS INITIAL.
GS_ADRC-SORT1 = PV_SORT1.
ENDIF.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
28
IF NOT PV_SORT2 IS INITIAL.
GS_ADRC-SORT2 = PV_SORT2.
ENDIF.
IF NOT PV_STREET IS INITIAL.
GS_ADRC-STREET = PV_STREET .
ENDIF.
IF NOT PV_HOUSE_NUM1 IS INITIAL.
GS_ADRC-HOUSE_NUM1 = PV_HOUSE_NUM1 .
ENDIF.
IF NOT PV_POST_CODE1 IS INITIAL.
GS_ADRC-POST_CODE1 = PV_POST_CODE1 .
ENDIF.
IF NOT PV_CITY1 IS INITIAL.
GS_ADRC-CITY1 = PV_CITY1.
ENDIF.
IF NOT PV_COUNTRY IS INITIAL.
GS_ADRC-COUNTRY = PV_COUNTRY.
ENDIF.
IF NOT PV_REGION IS INITIAL.
GS_ADRC-REGION = PV_REGION .
ENDIF.
IF NOT PV_TIME_ZONE IS INITIAL.
GS_ADRC-TIME_ZONE = PV_TIME_ZONE.
ENDIF.
IF NOT PV_LANGU_CREA IS INITIAL.
GS_ADRC-LANGU_CREA = PV_LANGU_CREA .
ENDIF.

*update ADRC
IF NOT GS_ADRC IS INITIAL.

CASE PV_SIM.

*simulation
WHEN ' '.

MESSAGE A031(KC) INTO ZRETURN-MESSAGE.


APPEND ZRETURN.
MESSAGE A031(KC) INTO RETURN-MESSAGE.

WHEN OTHERS.

UPDATE ADRC FROM GS_ADRC.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
29
IF SY-SUBRC NE 0.
* abort: error during update
MESSAGE A017(KC) WITH 'UPDATE ADRC' SY-SUBRC INTO ZRETURN-MESSAGE.
APPEND ZRETURN.
MESSAGE A017(KC) WITH 'UPDATE ADRC' SY-SUBRC INTO RETURN-MESSAGE.

ENDIF.

ENDCASE.

ENDIF.

ENDIF.

ENDIF.

ENDFUNCTION.

Step 9: Next we have to release the function module by Function Module>Release>Release.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
30
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
31
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
32
3.5 Stage 3: Creating the business object in SWO1
Step 10: Go to transaction SWO1 and enter the name of the BAPI you would like to create and click
create. Here I have given the name ZBAPIADRC (Z_API_TWLAD_ADRC_UPDATE. In the coming screen
Enter the details as below or as per requirement and click continue. That will ask you to save the
object. Save it in a package.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
33
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
34
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
35
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
36
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
37
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
38
Step 11: In the resulting screen click on the methods to drop down and see what methods are
provided by default. There would be two methods, showing in red color which comes by default while
creating the BAPI. Now select ‘Add Method’ from Utilities > API Methods > Add Method.
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
39
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
40
Step 12: On the screen that follows, provide the function module name that we just created in the
previous stage and click on the continue icon. In the coming pop-up, click the next step icon. We
observe that the information is predefined in the fields.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
41
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
42
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
43
Step 13: This is the next screen where you would just click on the “next” icon.

Step 14: A popup will be displayed as below.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
44
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
45
Click on Yes. You can see an information message reading “ ZZZZ” inserted.

Step 15: Now save after you add the method. Select & Double click on the API method.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
46
Go to Tab: ABAP Check 'API Function' as shown below.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
47
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
48
Select the Radio button reading “API Function” as already said above.

Step 16: Now select the Object “ZBAPI_TWLAD_ADRC_UPDATE” as shown below.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
49
Step 17: Now Go to : Edit > Change Release Status > Object type > To Modeled.

Step 18: The below shown screen will be displayed. Click on yes.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
50
The message shows, The object type status set to modeled. ( or already modeled )

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
51
Step 19: Now go to: Edit > Change Release Status > Object type >To Implemented. You can see a
message reading “Object type status set to implemented” .

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
52
Step 20: Now, go to: Edit > Change Release Status > Object > To Released. There would be two pop
ups coming up. Click continue on the Pop Ups.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
53
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
54
Step 21: Keep the cursor on the 'Method'. Now go to: Edit > Change Release Status > Object type
component > To Modeled. (Shown as below).

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
55
Step 22: Now, go to: Edit > Change Release Status > Object type component > To Implemented. You
can see the message reading “ status for method ‘ZZ’ set to implemented”.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
56
Step 23: Now go to: Edit > Change Releasse Status > Object type component > To Released. You can
see the message reading “ status for method ‘zz’ set to Released”.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
57
Step 24: Click on ‘Generate’ from Object Type as shown below.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
58
After clicking on the generate button, you can see the message reading “Object type
'ZBAPI_TWLAD_ADRC_UPDATE' generated successfully”. Now we are done with the creation of a
BAPI.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
59
3.6 Stage 4: Viewing the created BAPI in BAPI Explorer

Step 25: Go to BAPI Explorer (Transaction code is ‘BAPI’) there we can find the BAPI (our BAPI). You
can click on the Alphabetical tab so that you can browse the BAPI’s in an alphabetical order. Find your
BAPI as shown.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
60
3.7 Stage 5: Test your BAPI
Step 26: Enter the name of your BAPI in the transaction SWO1 and click on ‘Test’.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
61
Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
62
Step 27: The below screen is displayed. Click on the Execute icon (circled in red) against the BAPI as
shown

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
63
Step 28: The below screen will be displayed where you would require entering the data against the
empty input fields.

Step 29: You could use the input help as shown below; here I have selected ‘0001’. And click the
execute button.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
64
Step 30: The resulting screen is displayed below, where you can see ‘N Entries’ against ZZ. Double click
on ‘ Entries’.

The results as per our input are as shown below.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
65
By this, we would get it confirmed that our BAPI is working properly. We can even check it by passing
different values again. Come back to the input and execution screen.
We are now done with the creation and successful execution of a BAPI.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
66

You might also like