You are on page 1of 73

A BAPI can interact and integrate with the software components of other vendors.

A BAPI is a Function Module in SAP that can be integrated with the legacy system to access the SAP business objects or it can be called inside the SAP itself depending the business re uirement. !sing a BAPI" we can fetch data from SAP or create#update the SAP master#transaction data. $here are BAPIs available for each transactions that are performed in SAP. %b&Answer for 'us(%#b& For e)ample" there is a BAPI available to *reate the *ustomer Master in SAP. $hat BAPI can be integrated with the legacy system using +emote Function *all ,+F*to create a *ustomer Master in SAP. By this way it interacts with a legacy system. %b&Answer for 'us.%#b& A BAPI is also used in the interface of . SAP systems. For e)ample" the data from a SAP system( need to be updated in another SAP system.. For that purpose" call the BAPI of the SAP system( from the SAP system. as a +emote Function *all ,+F*-. $he connection between the . systems are maintained using a +F* destination / the data are transferred between the . systems using I0ocs.

Custom BAPI creation - Step-by-step Procedure


Scenario1 Step2by2step creation of a BAPI to retrieve fields from table $33(. Procedure1 4o to transaction S5(( and create a structure as shown or as per your re uirement. 4ive the name in the 0ata type field and clic6 create.

In the pop2up that comes up" select the radio button 7 structure8.

In the components tab of the structure" give the different fields and their corresponding field types and press enter to chec6 the compatibility and corrective ness.

0o not forget to save it in a pac6age. 9ou can even save it as a local object. For my e)ample" I save it in a pac6age.

*hec6 the structure ,ctrl : F.- and activate ,ctrl : F;- the structure. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: <ow we are done with the creation of a Structure. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

4o to transaction S5;= where you create function modules. *lic6 on create after you enter the name of the Function module.

A screen as shown above would pop2up where you mention the function group to save the function module and also provide some short te)t describing your function module.

In the ne)t pop2up that follows" clic6 on continue as shown above.

$he function module screen would loo6 li6e the one above.

4o to the Attributes tab and select the radio button reading 7remote2enabled module8. *ome bac6 to the imports tab and provide the import parameters as shown or as per your re uirement.

<ow in the 5)port tab" provide the e)port parameters as shown or as per your re uirement.

In the tables tab" provide the information as shown or as per your re uirement.

$he ne)t screen you visit is the source code. It would loo6 li6e this.

In the source code tab" write the following code in order to pic6 the data based on the input you provide.

<ow" save and chec6 the code and activate the function module.

After successful activation" 4o to the attributes tab. 4o to Function module +elease+elease.

::::::::::::::::::::::::::::::::::::::::::::::: <ow we are done with the creation of a Function Module. ::::::::::::::::::::::::::::::::::::::::::::::: 4o to transaction S>?( and enter the name of the BAPI you would li6e to create or as shown in the screen and clic6 the create button.

4ive the name of the BAPI as above and clic6 on create.

4ive the above2mentioned details and clic6 on the continue icon.

Save in a pac6age. $he resulting screen is as follows.

<ow clic6 on the methods to drop down and see what methods are provided by default. $here would be two methods" showing in red color which come by default while creating the BAPI.

*lic6 or select the method as shown above and go to the path 7!tilities API methodsAdd methods8. ?n the screen that follows" provide the function module name and clic6 on the continue icon.

In the ultimate pop2up" clic6 the ne)t step icon. >e observe that the information is predefined in the fields. $his is the ne)t screen where you would just clic6 on the 7ne)t8 icon.

*lic6 on 9es. 9ou can see an information message reading 7 @BAPIFM$33(8 inserted.

<ow save after you add the method. Select / 0ouble clic6 on the API method. 4o to $ab1 ABAP *hec6 AAPI FunctionA.

$he above screen is displayed. 4o to the ABAP tab as shown below.

Select the +adio button reading 7API Function8 as already said above.

clic6 on the continue icon to proceed further.

<ow select the ?bject 7@BAPIB$33(8 as shown below.

4o to 1 5dit*hange +elease Status?bject type $o Modeled.

$he above shown screen will be displayed. *lic6 on yes. $he message shows" $he object type status set to modeled. ,or already modeled4o to 1 5dit*hange +elease Status?bject type $o Implemented.

9ou can see a message reading 7?bject type status set to implemented8 <ow" go to1 5dit*hange +elease Status?bject$o +eleased.

$here would be two pop ups coming up. *lic6 continue on the Pop !ps. Ceep the cursor on the AMethodA. 4o to1 5dit*hange +elease Status?bject type component$? Modeled.

9ou can see the message reading 7 status for method DEbapifmt33(F set to modeled8. <ow" go to1 5dit*hange +elease Status?bject type component $? Implemented

9ou can see the message reading 7 status for method DEbapifmt33(F set to implemented8. <ow go to1 5dit*hange +eleasse Status ?bject type component $o +eleased

9ou can see the message reading 7 status for method DEbapifmt33(F set to +eleased8. *lic6 on 4enerate Button. ,the red ball 6ind of button is the 4enerate button-

After clic6ing on the generate button" you can see the message reading 7?bject type A@BAPIB$33(A generated successfully8. <ow go to BAPI $code ,B?+- there we can find the BAPI ,our BAPI$he BAPI browser would loo6 li6e the screen below.

9ou can clic6 on the Alphabetical tab so that you can browse the BAPIFs in an alphabetical order. Find your BAPI as shown.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

<ow we are done with the creation of a BAPI. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: $est 9our BAPI.

5nter the name of your BAPI in the transaction S>?( and clic6 on D$estF.

$he above screen is displayed. *lic6 on the 5)ecute icon against the BAPI as shown.

$he above screen is displayed where you would re uire entering the data against the empty input fields.

>e have entered some data in the Field.

After entering the data" clic6 on the e)ecute icon as shown below.

$he following screen is displayed which has some values as is indicated by the I$5M$AB.

*lic6 on the 5dit table icon as shown below.

$he results as per our input are as shown below.

By this" we would get it confirmed that our BAPI is wor6ing properly. >e can even chec6 it by passing different values again. *ome bac6 to the input and e)ecution screen.

After e)ecuting the BAPI based on the input provided" we get the following screen.

Git on the e)ecute icon.

In the above shown screen" hit on the edit table icon.

$he above is the output we get from the input we provided. >e are now done with the creation and successful e)ecution of a BAPI.

Custom BAPI creation - Step-by-step Procedure


To create the custom BAPI, we need to follow this step-by-step procedure. The steps are (. *reate the BAPI structure. .. *reate +emote Function Module. ;. Place the +emote Function Module into B?+ ,Business ?bject +epository-. H. Implement" 4enerate and +elease the BAPI. Step 1: $o create BAPI structure" the structure name should start with the eyword !BAPI. Gere" $wo BAPI structures are created in this scenario .$he name of these BAPI structures are!BAPI"I#P$%T and !BAPI"TAB&'. Step (: !BAPI"I#P$%T structure contains the following fields.

Step )1 !BAPI"TAB&' structure contains the following fields.

Step *: <ow" define the +emote 5nabled Function Module using $2*ode S5;= starting with the@BAPI . Provide the name of the function module as !BAPI"+'#$"S+. >e must pass the Importand e,port parameters as -alue parameters.

Attribute Parameters:

Import Parameters:

',port Parameters:

%eturn parameter in the 5)port parameter contains the error messages. Gere" we must create a parameter of type structure BAPI%'T.%/ either in ',port Parameter or Table Parameter.

Table Parameters:

Source Parameter:

Step0: Place this Function Module in to B?+ using the $2code S1$1. Provide the name of the object and press create button.

Provide the following details.

Step 2: Add our *ustom BAPI using !tilities2&API Method2&Add Method

<ow" Provide the created *ustom Function Module name and clic6 enter.

Press the <e)t Step Button.

Press the <e)t Step Button.

*lic6 the 95S button.

<ow" Method is added in the B?+.

And Press Save button. Step 3: <ow Implement the BAPI.

<ow" 4enerate the BAPI by clic6ing symbol DballF.

Iastly" +elease the BAPI.

Step 4: <ow test the BAPI by clic6ing 5)ecute Button.

$he following screen appears and clic6 e)ecute button.

Provide the sales document number and press e)ecute button.

<ow chec6 the output as followsJ

Create Sales Order (BAPI_SALESORDER_CREA E!RO"DA #$ %it& BAPI E'tension


?ur client had a re uirement to create customer sales orders using BAPI function moduleBAPI"SA&'S$%+'%"5%'AT'6%$#+AT( with using custom fields ,@@K or 99K fieldswhich are appended on LBAP table with using append structure.

>e can easily create sales order with using standard fields via BAPI but as per re uirement we need to use e)tension of BAPI"SA&'S$%+'%"5%'AT'6%$#+AT( for (; customiEe fields. Steps for BAPI 5)tension1 Append @ALBAP structure in LBAP table with (; customiEe fields. Fields must begin with @@K or 99K naming .

In BAPI"SA&'S$%+'%"5%'AT'6%$#+AT( we need to use '7T'/SI$/I/ parameter for BAPI e)tension 9ou can use this parameter to transfer user2specific enhancements to a BAPI. $he customer has to complete the 5M$5<SI?< structure and the system automatically continues processing it. If you have not defined any user2specific fields" then you can transfer a blan6 5M$5<SI?<I< structure. 9ou can use also this e)tension LBAC" LBAP" LB5P tables.

Because the BAPIs wor6 with chec6bo)es" you must also define a customiEe structure ,@ABAP5BLBAPM- chec6bo) for the customer structure. It should be structured li6e this 0efine these customer structures in the structures LBAPC?@ and LBAPC?@M using I<*I!05 or APP5<0.

Add the customer structures to the BAP5BLBAP and BAP5BLBAPM BAPI structures using the APP5<0 techni ue.

Adjust the following structures for customer enhancements to table LBAP1 a- LBAPC?@ b- LBAPC?@M c- BAP5BLBAP d- BAP5BLBAPM If you need to use custom fields for LBAC you must adjust the following structures for customer enhancements to table LBAC1 a- LBACC?@ b- LBACC?@M c- BAP5BLBAC

d- BAP5BLBACM If you need to use custom fields for LB5P you must adjust the following structures for customer enhancements to table LB5P1 a- LB5PC?@ b- LB5PC?@M c- BAP5BLB5P d- BAP5BLB5PM 4enerally" the data should be added to the BAPI interface in the internal communication structures ,LBACC?M" and so on-. $here" you can process the data in the S0 tables ,LBAC" and so on-. If the 5M$5<SI?<I< parameter contains customer data" you must complete at least the 6ey fields in the relevant standard parameters. $his is a simple ABAP code how to use e)tension table with BAPI data1 lvBsalesdocument li6e bapivbeln2vbeln" lsBorderBheaderBin type bapisdhd( " lsBorderBheaderBin) type bapisdhd()" ltBreturn type table of bapiret. with header line" ltBitemsBin type table of bapisditm with header line" ltBitemsBin) type table of bapisditm) with header line" ltBpartners type table of bapiparnr with header line" ltBschedulesBin type table of bapischdl with header line" ltBschedulesBin) type table of bapischdl) with header line" ltBorderBconditionsBin type table of bapicond with header line" ltBorderBconditionsBin) type table of bapicond) with header line" ltBe)tensionin type table of bapipare) with header line" lwaBe)tensionin type bapipare) " ltBbapeBvbap type table of bapeBvbap with header line" lwaBbapeBvbap type bapeBvbap" ltBbapeBvbap) type table of bapeBvbap) with header line" lwaBbapeBvbap) type bapeBvbap). lsBorderBheaderBin2docBtype N A@33(A. lsBorderBheaderBin2salesBorg N A(333A. lsBorderBheaderBin2distrBchan N A.3A. lsBorderBheaderBin2division N A3(A. lsBorderBheaderBin2salesBoff N A33(3A. lsBorderBheaderBin2purchBnoBc N A(333333(A. lsBorderBheaderBin)2updateflag N AIA. lsBorderBheaderBin)2docBtype N AMA. lsBorderBheaderBin)2salesBorg N AMA. lsBorderBheaderBin)2distrBchan N AMA. lsBorderBheaderBin)2division N AMA. lsBorderBheaderBin)2salesBoff N AMA. lsBorderBheaderBin)2purchBnoBc N AMA. ltBpartners2partnBrole N AA4A. ltBpartners2partnBnumb N A333333H333A. append ltBpartners.

ltBitemsBin2itmBnumber N A3333(3A. ltBitemsBin2material N A333333333;333333H3A. ltBitemsBin2salesBunit N AS$A. append ltBitemsBin. ltBitemsBin)2itmBnumber N A3333(3A. ltBitemsBin)2material N AMA. ltBitemsBin)2salesBunit N AMA. append ltBitemsBin). ltBschedulesBin2itmBnumber N A3333(3A. ltBschedulesBin2schedBline N A333(A. ltBschedulesBin2re B ty N (333. ltBschedulesBin2re Bdate N sy2datum. append ltBschedulesBin. ltBschedulesBin)2itmBnumber N A3333(3A. ltBschedulesBin)2schedBline N A333(A. ltBschedulesBin)2re B ty N AMA. ltBschedulesBin)2re Bdate N AMA. append ltBschedulesBin). lwaBbapeBvbap2vbeln N space. lwaBbapeBvbap2posnr N A3333(3A. lwaBbapeBvbap2EEtu6etf N 3. lwaBbapeBvbap2EEtu6ets N 3. lwaBbapeBvbap2EE6lt( N AHO4+AMA. lwaBbapeBvbap2EEsyf( N (P. lwaBbapeBvbap2EE6lt. N AHQ4+AMA. lwaBbapeBvbap2EEsyf. N 3. lwaBbapeBvbap2EE6lt; N AO.4+AMA. lwaBbapeBvbap2EEsyf; N 3. lwaBbapeBvbap2EEHOg N space. lwaBbapeBvbap2EEHQg N space. lwaBbapeBvbap2EEsbs N R. lwaBbapeBvbap2EEtss N R. lwaBbapeBvbap2EErss N (P. lwaBbapeBvbap)2vbeln N space. lwaBbapeBvbap)2posnr N waBouttab2posnr. lwaBbapeBvbap)2EEtu6etf N space. lwaBbapeBvbap)2EEtu6ets N space. lwaBbapeBvbap)2EE6lt( N AMA. lwaBbapeBvbap)2EEsyf( N AMA. lwaBbapeBvbap)2EE6lt. N AMA. lwaBbapeBvbap)2EEsyf. N AMA. lwaBbapeBvbap)2EE6lt; N AMA. lwaBbapeBvbap)2EEsyf; N AMA. lwaBbapeBvbap)2EEHOg N AMA. lwaBbapeBvbap)2EEHQg N AMA. lwaBbapeBvbap)2EEsbs N AMA. lwaBbapeBvbap)2EEtss N AMA. lwaBbapeBvbap)2EErss N AMA. move ABAP5BLBAPA to lwaBe)tensionin2structure. call method clBabapBcontainerButilitiesN&fillBcontainerBc e)porting imBvalue N lwaBbapeBvbap importing

e)Bcontainer N lwaBe)tensionin2valuepart(. append lwaBe)tensionin to ltBe)tensionin. clear lwaBe)tensionin. clear ltBe)tensionin. move ABAP5BLBAPMA to lwaBe)tensionin2structure. move lwaBbapeBvbap) to lwaBe)tensionin2valuepart(. append lwaBe)tensionin to ltBe)tensionin. clear ltBe)tensionin. call function ABAPIBSAI5S?+05+B*+5A$5F+?M0A$.A e)porting K salesdocumentin N lvBsalesdocument orderBheaderBin N lsBorderBheaderBin orderBheaderBin) N lsBorderBheaderBin) K S5<05+ N K BI<A+9B+5IA$I?<SGIP$9P5 N K I<$B<!MB5+BASSI4<M5<$ N K B5GAL5B>G5<B5++?+ N K I?4I*BS>I$*G N K $5S$+!< N K *?<L5+$ NAA importing salesdocument N lvBsalesdocument tables return N ltBreturn orderBitemsBin N ltBitemsBin orderBitemsBin) N ltBitemsBin) orderBpartners N ltBpartners orderBschedulesBin N ltBschedulesBin orderBschedulesBin) N ltBschedulesBin) orderBconditionsBin N ltBorderBconditionsBin orderBconditionsBin) N ltBorderBconditionsBin) K ?+05+B*F4SB+5F N K ?+05+B*F4SBI<S$ N K ?+05+B*F4SBPA+$B?F N K ?+05+B*F4SBLAI!5 N K ?+05+B*F4SBBI?B N K ?+05+B*F4SBLC N K ?+05+B*F4SB+5FI<S$ N K ?+05+B**A+0 N K ?+05+B$5M$ N K ?+05+BC59S N e)tensionin N ltBe)tensionin K PA+$<5+A00+5SS5S N . call function ABAPIB$+A<SA*$I?<B*?MMI$A e)porting wait N AMA.

BAPI E'tension (or BAPI_ACC_)L_POS I*)_POS


Gad a re uirement to post 4I documents via BAP I function module1 BAPI"A55"8&"P$STI/8"P$ST" using the 0 custom fields which are added to BS54 table *ustom field in the $code FB3( are Project I0" *hannel" State" +einsurer *ode and Product as1

*ustom fields in BS54 table are highlighted below1

In BAPI SBAPIBA**B4IBP?S$I<4BP?S$S need to add 5M$5<SI?<( for BAPI e)tension.

Building structure BAPI5M$*" BAPI5M$" BAPI5M$A which will act as the container for the O custom fields

*an use the following code for filling the values in the 5M$5<SI?<( 1 0A$A 1 itBe)tension $9P5 $ABI5 ?F bapie)tc" waBe)tension $9P5 bapie)tc. Filling e)tension table waBe)tension2field(,3;N lwBitem2itemnoBacc:=,;-. waBe)tension2field(:3;,3H- N wBpost2EEproj. waBe)tension2field(:3=,3H- N wBpost2EEstate. waBe)tension2field(:((,3P- N wBpost2EErecode.

waBe)tension2field(:(=,3H- N wBpost2EEprod. waBe)tension2field(:.(,3H- N wBpost2EEchennel. waBe)tension2field(:.O,3H- N wBpost2ldgrp. APP5<0 waBe)tension $? itBe)tension. *I5A+1 lwBitem"waBe)tension. *alling the BAPI ABAPIBA**B4IBP?S$I<4BP?S$A and passing itBe)tension to e)tension(. *AII F!<*$I?< ABAPIBA**B4IBP?S$I<4BP?S$A 5MP?+$I<4 documentheader N waBhead IMP?+$I<4 objBtype N objBtype objB6ey objBsys N $ABI5S accountgl currencyamount N iBamnt return N iBreturn e,tension1 9 it"e,tension. *AII F!<*$I?< ABAPIB$+A<SA*$I?<B*?MMI$A.

N objB6ey objBsys N iBitem

1. About the Example 2. STEP 1 - Define a structures for the BAPI 3. STEP 2 rite !unction "o#ule I(A)D

$. STEP 3 - %reate the API "etho# &sin' the BAPI *. STEP $ - !inal steps

About the example


This BAPI reads system status for a production order from table JEST and system status text from table TJ02T
Name Function group ZGetOrderStatus ZBAPISTATUS

Function module: Z_BAPI_GET_ORDER_STATUS Import parameters: ORDER_STATUS_IMPORT t pe !"API_ORDER_STATUS_IMPORT:


A.6/% ?rder number ,CeyfieldSP%AS Ianguage ',cludeInacti-e 2 *hec6bo) 2 5)clude inactive status

Ta#les

T_"APISTAT t pe !"APISTAT:

O"$NR li6e T5S$2?BT<+ STAT like JEST-STAT INA%T like JEST-INACT T&T'( like TJ02T-T T0! T&T)' likeTJ02T-T T"0

E*port parameters

RETURN like BAPIRETURN

STEP 1 - Define a structures for the BAPI


In this step a structures for the parameters and tables of the function module used for the BAPI are defined. se Data type -> Structure

0efine the following structures1 @BAPIB?+05+BS$A$!SBIMP?+$ which contains the following fields1

?+05+I0 ?rder number ,CeyfieldSP+AS Ianguage 5)cludeInactive 2 *hec6bo) 2 5)clude inactive status

@BAPIS$A$1 ?BT<+ li6e T5S$2?BT<+


S$A$ li6e T5S$2S$A$ I<A*$ li6e T5S$2I<A*$ $M$3H li6e $T3.$2$M$3H $M$;3 li6e$T3.$2$M$;3

Important note: 9ou will have to define a structure for every parameter in the BAPI. 9ou cannot use the same structures used in e)isting applications because BAPI structures are froEen when BAPIs are released and then there are restrictions on changing them.

!BAPI"$%+'%"STAT.S"I#P$%T

!BAPISTAT

ST'P ( - 1rite 6unction #odule


Important notes1

5ach BAPI must have its own function group. !nder the attributes tab remember to select Processing $ype Remote Enabled module" otherwise the function module cannot be invo6ed via +F* and used as a BAPI Import#5)port parameters can only be B9 LAI!5 for an +F* enabled function module

>e are only creating one BAPI in this e)ample" but you can create related BAPIs in the same function pool" so they will be able to share global data.

Attributes

Import Parameters

',port Parameters

Tables

5ode

/otes:

$he subroutine S5$B+5$!+<BM5SSA45 is a standard routine used for BAPIs that use the BAPI+5$!+< structure In form @BBAPIB45$B?+05+BS9S$5MBS$A$!S there is a test IF 1 = 2. If the test is true a message is displayed. $he condition will obviously never be true" and we will never want to display a message in a BAPI. $he reason why it is included is" that it create a reference for the message" so that the >G5+5 !S50 functionality can be used

for the message. $his is the SAP standard way to handle it" copied from the *ompany *ode 4etIist BAPI.
I/5&.+' &!BAPISTAT.S.77 ***************************************************************** * THIS FILE IS GENERATED BY THE FUNCTION LIBRARY. * * NEVER CHANGE IT MANUALLY, PLEASE! * ***************************************************************** INCLUDE LZBAPISTATUSU02. "Z_BAPI_GET_ORDER_SYSTEM_STATUS INCLUDE LZBAPISTATUSTOP - Global a!a F!<*$I?<2P??I @BAPIS$A$!S. SM5SSA452I0 @; $ypes1 begin of $ypeBtj3.t" istat li6e tj3.t2istat" t)t3H li6e tj3.t2t)t3H" t)t;3 li6e tj3.t2t)t;3" end of typeBtj3.t. 0A$A1 : +eclarations for TAB&' parameter $BBAPIS$A$ li6e @BAPIS$A$ occurs 3" 4BBAPIS$A$ li6e @BAPIS$A$" : Table for ob;ect te,ts tBtj3.t type typeBtj3.t occurs 3" gBtj3.t type typeBtj3.t. : Structure for return messa<es 0A$A1 B54I< ?F M5SSA45" MS4$9 IIC5 S92MS4$9" MS4I0 IIC5 S92MS4I0" MS4<? IIC5 S92MS4<?" MS4L( IIC5 S92MS4L(" MS4L. IIC5 S92MS4L." MS4L; IIC5 S92MS4L;" MS4LH IIC5 S92MS4LH" 5<0 ?F M5SSA45. INCLUDE LZBAPISTATUSF"# - S$b%o$!&'() :::I/5&.+' &!BAPISTAT.S6=1 . :----------------------------------------------------------------------: :>---------------------------------------------------------------------: :> 6orm S'T"%'T.%/"#'SSA8' :>---------------------------------------------------------------------: : This routine is used for settin< the BAPI return messa<e. : The routine is a standard routine for BAPIs that handles the messa<e : structure for the BAPI%'T.%/ structure. It has been copied from the : BAPI 5ompany 5ode 8etlist :----------------------------------------------------------------------: : --?P"#'SSA8' te,t : @--P"%'T.%/ te,t :----------------------------------------------------------------------: form S5$B+5$!+<BM5SSA45 !SI<4 LAI!5,PBM5SSA45- IIC5 M5SSA45 *GA<4I<4 PB+5$!+< IIC5 BAPI+5$!+<. *G5*C <?$ M5SSA45 IS I<I$IAI. *AII F!<*$I?< ABAI>BBAPI+5$!+<B45$A 5MP?+$I<4 $9P5 N PBM5SSA452MS4$9 *I N PBM5SSA452MS4I0 <!MB5+ N PBM5SSA452MS4<?

PA+( N PBM5SSA452MS4L( PA+. N PBM5SSA452MS4L. PA+; N PBM5SSA452MS4L; PA+H N PBM5SSA452MS4LH K I?4B<? N A A K I?4BMS4B<? N A A IMP?+$I<4 BAPI+5$!+< N PB+5$!+< 5M*5P$I?<S ?$G5+S N (. endform. S S5$B+5$!+<BM5SSA45 FUNCTION Z*BAPI*GET*ORDER*STATUS F!<*$I?< EBbapiBgetBorderBsystemBstatus. :A---------------------------------------------------------------------:A:A&ocal interface: :A I#P$%TI/8 :A BA&.'CI"A.6/%D TEP' A.6/% :A BA&.'CI"SP%ASD TEP' SP%AS +'6A.&T SE-&A/8. :A BA&.'CI"'75&.+'I/A5TIB'D TEP' 5FA%1 $PTI$/A& :A '7P$%TI/8 :A BA&.'C%'T.%/D TEP' BAPI%'T.%/ :A TAB&'S :A T"BAPISTAT ST%.5T.%' !BAPISTAT :A---------------------------------------------------------------------0A$A1 lBaufnr IIC5 af6o2aufnr" lBobjnr IIC5 jest2objnr. ******************************************** * C+(,- &. o% (% (/&)!) ******************************************** SELECT SINGLE aufnr FROM afk INTO !_aufnr "#ERE aufnr $ BAPI_ORDER_STATUS_IMPORT% r&'r(&. IF )*%)u+r, NE 0. CLEAR -'))a.'. -'))a.'%-)./* $ 0E0. -'))a.'%-).(& $ 0Z10. -'))a.'%-).n $ 00000. -'))a.'%-).23 $ BAPI_ORDER_STATUS_IMPORT% r&'r(&. PERFORM )'/_r'/urn_-'))a.' USING -'))a.' C#ANGING r'/urn. IF 3 $ 2. * T+( o'l0 %(a)o' !o &',l$ ( !+&) )!a!(1('!, !+a! 2&ll ob3&o$)l0 * '(3(% (/(,$!(, &) !+a! &! 2&ll ,%(a!( a %(.(%(,(',( )o !+a! 0o$ * ,a' .&' o$! 2+(%( a 4a%!&,$la% 1())a5( &) b(&'5 $)( . T+&) * .$',!&o'al&!0 &) $)( b0 !+( BAPI) 4%o5%a11( b0 SAP MESSAGE '0004516. ENDIF. ENDIF. C#EC7 r'/urn IS INITIAL. :::::::::::::::::::::::::::::::::::::::::::: : %ead order status :::::::::::::::::::::::::::::::::::::::::::: *?<*A$5<A$5 A?+A BAPIB?+05+BS$A$!SBIMP?+$2orderid I<$? lBobjnr. IF BAPIB?+05+BS$A$!SBIMP?+$2iBe)cludeinactive N AMA. S5I5*$ objnr stat inact F+?M jest I<$? $ABI5 tBbapistat >G5+5 objnr N lBobjnr A<0 inact %& AMA.

5IS5. S5I5*$ objnr stat inact F+?M jest I<$? $ABI5 tBbapistat >G5+5 objnr N lBobjnr. 5<0IF. IF sy2subrc %& 3. : /o ob;ect status found *I5A+ message. message2msgty N A5A. message2msgid N A@;A. message2msgno N A33(A. message2msgv( N BAPIB?+05+BS$A$!SBIMP?+$2orderid. P5+F?+M setBreturnBmessage !SI<4 message *GA<4I<4 return. IF ( N .. M5SSA45 e33(,E;-. 5<0IF. 5<0IF. *G5*C return IS I<I$IAI. :::::::::::::::::::::::::::::::::::::::::::: : %ead order status te,ts :::::::::::::::::::::::::::::::::::::::::::: S5I5*$ istat t)t3H t)t;3 F+?M tj3.t I<$? $ABI5 tBtj3.t F?+ AII 5<$+I5S I< tBbapistat >G5+5 istat N tBbapistat2stat A<0 spras N BAPIB?+05+BS$A$!SBIMP?+$2iBspras. S?+$ tBtj3.t B9 istat. I??P A$ tBbapistat I<$? gBbapistat. +5A0 $ABI5 tBtj3.t >I$G C59 istat N gBbapistat2stat BI<A+9 S5A+*G I<$? gBtj3.t. IF sy2subrc N 3. M?L51 gBtj3.t2t)t3H $? gBbapistat2t)t3H" gBtj3.t2t)t;3 $? gBbapistat2t)t;3. M?0IF9 tBbapistat F+?M gBbapistat $+A<SP?+$I<4 t)t3H t)t;3. 5<0IF. 5<0I??P. 5<0F!<*$I?<.

ST'P ) - 5reate the API #ethod .sin< the BAPI 1I!A%+


$he BAPI wiEard is used to$o e)pose the remote function module as a BAPI. $he wiEard will generate some additional code" so the function module is a valid method of the B?+. $his allows the BAPi to be called as a wor6flow method in addition to be called by an outside program. No!(6 5ach function module corresponds to a method in the B?+ 4o to the Business ?bject Builder S>?(. 9ou can either create the new ?bject type as a subtype of an e)isting business object or create a new business object from scratch. In this e)ample it would be obvious to create the ?bject type as a

subtype of B!S.33O Production order. Gowever" to illustrate how to create a new ?bject type from scratch" we will do this. In the Object/Interface type field write the name of the new Business ?bject1 @?+05+S$A$. Press enter and fill in the additional fields necessary to create the object type. Supertype1 <ot relevant because we are creating our object from scratch Program. $his is the name of the program where the wiEard generates code for the ?bject type" <?$ the function module we created earlier. $he program name must not be the name of an e)isting program.

Press enter and create the new business object. <ote that when you create the business object a standard interface" an attribute ?bject$ype and the methods 5)istence*hec6 and 0isplay are automatically generated. $hese cannot be changed U

$he ne)t step is to add the @BBAPIB45$B?+05+BS$A$!S method to the business object. Select Ut l t e! -> "#I met$od! -> "dd met$od and write the name of the function module in the dialog bo). <e)t the dialog o) show below will be shown. $his is the start screen of the BAPI wiEard. Proceed with wiEard by pressing the button.

After you have finished the wiEard" you will notice that the @4et?rderStatus has been added to the business object1

9ou can double2clic6 on the method to see its properties. $o use the business object you must change the ?bject type status to Implemented. !se menu 5dit2&*hange releases status2&?bject type2&$o implemented. <o you can test the object ,Press FR-. <ote that the BAPI wiEard has added a wrapper class for the function module so it can be sued as method in the business object. *hoose menu %oto->#ro&ram to display the program1 ::::: Implementation of ob;ect type !$%+'%STAT ::::: I<*I!05 %?BT5*$&. B54I<B0A$A ?BT5*$. A +o not chan<e.. +ATA is <enerated : only pri-ate members may be inserted into structure pri-ate 0A$A1 A be<in of pri-ate, A to declare pri-ate attributes remo-e comments and A insert pri-ate attributes here ... A end of pri-ate, C59 IIC5 S>?$?BTI02?BTC59. 5<0B0A$A ?BT5*$. S 0o not change.. 0A$A is generated B54I<BM5$G?0 @45$?+05+S$A$!S *GA<4I<4 *?<$AI<5+. 0A$A1 BAPI?+05+S$A$!SIMP?+$ IIC5 @BAPIB?+05+BS$A$!SBIMP?+$" +5$!+< IIC5 BAPI+5$!+<" $BAPIS$A$ IIC5 @BAPIS$A$ ?**!+S 3. S>*B45$B5I5M5<$ *?<$AI<5+ ABapi?rderStatusImportA BAPI?+05+S$A$!SIMP?+$. S>*B45$B$ABI5 *?<$AI<5+ A$BapistatA $BAPIS$A$. 5A&& 6./5TI$/ G!"BAPI"8'T"$%+'%"STAT.SG 5MP?+$I<4 BAPIB?+05+BS$A$!SBIMP?+$ N BAPI?+05+S$A$!SIMP?+$ IMP?+$I<4 +5$!+< N +5$!+< $ABI5S $BBAPIS$A$ N $BAPIS$A$ 5M*5P$I?<S ?$G5+S N 3(. *AS5 S92S!B+*. >G5< 3. S ?C >G5< ?$G5+S. S to be implemented 5<0*AS5. S>*BS5$B5I5M5<$ *?<$AI<5+ A+eturnA +5$!+<. S>*BS5$B$ABI5 *?<$AI<5+ A$BapistatA $BAPIS$A$. 5<0BM5$G?0.

STEP 7 - F&'al )!(4)


>hen the Business object has been chec6ed and the documentation created" the following steps must be carried out1 R'!'a)' /8' BAPI fun,/( n - &u!' 4(n /8' Fun,/( n Bu(!&'r6. +elease the business object type ,in the B?+ Object'ype -> ($an&e relea!e !tatu! to -> Implemented -. R'!'a)' /8' BAPI a) a -'/8 & (n /8' BOR 4R'!'a)' /8' -'/8 &) * u 8a) ,r'a/'& % S'/ /8' ,ur) r n /8' -'/8 & /8'n

Edit -> Change release status -> Object type component -> To released 6 For potential write BAPIs1 +elease the I0oc and its segments

Y u ,an n 9 &():!a* /8' BAPI (n /8' BAPI E;:! r'r<

BAPI Step by step Guidance


BAPI stands for Business Application Pro!rammin! Interface. There are " different steps in BAPI. # $reate BAPI Structure # $reate BAPI %unction &odule or API &ethod. # $reate BAPI ob'ect # (elease BAPI %unction &odule. # (elease BAPI ob'ect. Step). $reatin! BAPI Structure* # +o to ,SE))-. # Select .ata Type / Enter a name. # $lic0 on $reate. # 1ote* Al2ays BAPI should be in a de3elopment class 2ith re4uest number 51ot 6ocal 7b'ect8. # Select Structure / hit E1TE(. # Enter the fields from your database. &a0e sure that the first field is the Primary 9ey %ield. # Then SA:E / A$TI:ATE. Step 2. $reatin! BAPI module* # Enter T(.$7.E ,SE;<-. # Before enterin! any thin!= from the present screen that you are in= select the menu +oto #- %unction +roups #- $reate +roup. Enter a name 51ote* This name &ust start 2ith >BAPI8 6et this screen be as it is and open another 2indo2 and there= enter T(.$7.E ,SE?08. $lic0 on the Third I$71 that says Inacti3e 7b'ects. Select the !roup that you 'ust created and clic0 on Acti3ate. 1otice that the !roup you created 2ill disappear from the list of inacti3e ob'ects. # +o bac0 to ,SE;<- screen and enter a name and hit ,E1TE(-. Then enter the !roup name that you 'ust created and acti3ated. 17TE* @hen you release a function module the respecti3e !roup 2ill be attached to that particular application. It cannot be used for any other application. 1E:E( include an already existin! !roup that is attached to another module. 1o2 clic0 on the first Tab that says AATT(IB TESB and select the radio button that says remote#enabled module since 2e 2ill be accessin! this from any external

system. Then clic0 on the second tab that says AI&P7(TB. Enter a PA(A&ETE( 1A&E= TCPE and the structure you created in the first step. Also select the chec0 box DPaE. All remotely enabled functional modules & ST be Pa enabled= 2here Pa means DPassed by :alueE and if you donEt select DPaE= then that means it 2ill be passed by reference.. Then clic0 on tab that says AEFP7(TB. Enter the follo2in! as is in the first three fields (ET (1 TCPE BAPI(ET (1 5These ; field 3alues are al2ays same8 Gere also select DPaE meanin! Pass by 3alue. 1ote* BAPI(ET (1 contains structure 2ith messa!e fields. Then SA:E and A$TI:ATE. Step ;. $reatin! BAPI ob'ect* # Enter Tr.$ode ,S@7)- 51ote. It is letter D7E and not >ero8. # Enter a name and then clic0 on create. Enter details. 17TE* &a0e sure that that 7b'ect Type and Pro!ram name are SA&E. # Enter Application D&E= if you are usin! standard table &ara. If you are usin! your o2n database then select D>E at the bottom. # Then hit ,E1TE(-. # 1o2 2e ha3e to add D&ethodsE. Gi!h li!ht &ETG7.S and then select the follo2in! from the menu* +oto tilities #- API &ethods #- Add &ethods. # Enter function &odule name and hit ,E1TE(-. # Select the second %7(@A(. A((7@ button 5-8to !o to next step. # $hec0 if e3ery thin! loo0s o0 and a!ain clic0 on %7(@A(. A((7@ button 5-8. # Then select DCESE and clic0 on ,SA:E-. # 1o2 on a different screen !oto T(.$7.E ,SE;<-. Enter %unction &odule name and select from the top menu %unction &odule #- (elease #- (elease. # +obac0 to T(.$7.E ,S@7)-. Gere select the menu combination sho2n belo2 in the same order. # Edit #- $han!e (elease Status #- 7b'ect Type $omponent #- To Implemented. # Edit #- $han!e (elease Status #- 7b'ect Type $omponent #- To (eleased. # Edit #- $han!e (elease Status #- 7b'ect Type #- To Implemented. # Edit #- $han!e (elease Status #- 7b'ect Type #- To (eleased.

# Then clic0 on ,SA:E-. # Then clic0 on +enerate Button 5Hth button from left hand side loo0s li0e spinnin! 2heel8. # Then $lic0 on the button that says DP(7+(A&E to see the source code. To chec0 if this is present in 2or0 flo2 !oto T(.$7.E ,BAPI-. Gere it sho2s business ob'ect repository. # %irst clic0 on the middle button and then select IA66J and hit E1TE(. # +oto tab AA6PGABETI$A6B and loo0 for the ob'ect that you created. This sho2s that the BAPI ob'ect has been created successfully.

Creating Custom BAPI - step by step


Step +, Create Structure-Structures (or parameters. %&ic& %e need in SE++

/se Data elements %&ile creatin0 structure (ields

Step # , Create !unction "odule usin0 SE12

Select Radio Button 3Remote-Enabled "odule4

Pro5ide Import Parameters as belo% and select Pass by 6alue7

Pro5ide ables (or output and Return table to &andle Errors

8rite t&e code to retrie5e t&e data7

Sa5e C&ec9 and Acti5ate t&e (unction module7 And 0o bac9 In "enu. )o to !unction "odule -: Release -: Release

Step 1 , Create Ob;ect type (or !unction "odule Create Ob;ect type in S8O+

Pro5ide Ob;ect name.*ame.Description.Pro0ram and Application

Open *ode o( "et&od and Select "et&od7 *o% in "enu. )oto /tilities -: API "et&ods -: Add "et&od7

Pro5ide !unction "odule.8&ic& %as created in Step # and <it enter7

C&ec9 on *e't7

C&ec9 all t&e parameters and clic9 on *e't

Clic9 on Sa5e7

*o% Clic9 on Sa5e and Select Ob;ect ype7 In "enu. )oto Edit -: C&an0e Release Status -: Ob;ect ype -: o "odeled

Clic9 on Sa5e

In "enu. )oto Edit -: C&an0e Release Status -: Ob;ect ype -: o Implemented

In "enu. )oto Edit -: C&an0e Release Status -: Ob;ect ype -: o Released

*o% Select !unction "odule in "et&od7 In "enu. )oto Edit -: C&an0e Release Status -: Ob;ect ype Component -: o "odeled

In "enu. )oto Edit -: C&an0e Release Status -: Ob;ect ype Component -: o Implemented

In "enu. )oto Edit -: C&an0e Release Status -: Ob;ect ype Component -: o Released

!inally Clic9 On )enerate7

Step = , C&ec9 it in BAPI Repositor

You might also like