Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

creating zbapi

Former Member
0 Likes
839

Hi All,

Pls can you help me

how to create zbapi for material list

based on parameters like fromdate to todate

if i enter fromdate to todate all the materials should display

thanks

mars

5 REPLIES 5
Read only

Former Member
0 Likes
748

Hi Dude,

Hope this link helps you,

http://www.saptechnical.com/Tutorials/BAPI/BAPIMainPage.htm

Regards,

Lakshmanan

Read only

Former Member
0 Likes
748

hi,

this the step by step procedure..

There are 5 different steps in BAPI.

Create BAPI Structure

Create BAPI Function Module or API Method.

Create BAPI object

Release BAPI Function Module.

Release BAPI object.

Step1. Creating BAPI Structure:

Go to <SE11>.

Select Data Type & Enter a name.

Click on Create.

Note: Always BAPI should be in a development class with request number (Not Local Object).

Select Structure & hit ENTER.

Enter the fields from your database. Make sure that the first field is the Primary Key Field.

Then SAVE & ACTIVATE.

Step 2. Creating BAPI module:

Enter TR.CODE <SE37>.

Before entering any thing, from the present screen that you are in, select the menu

Goto -> Function Groups -> Create Group.

Enter a name (Note: This name Must start with ZBAPI)

Let this screen be as it is and open another window and there, enter TR.CODE <SE80).

Click on the Third ICON that says Inactive Objects.

Select the group that you just created and click on Activate.

Notice that the group you created will disappear from the list of inactive objects.

Go back to <SE37> screen and enter a name and hit <ENTER>. Then enter the group name that you just created and activated.

NOTE: When you release a function module the respective group will be attached to that particular application.

It cannot be used for any other application. NEVER include an already existing group that is attached to another module.

Now click on the first Tab that says ATTRIBUTES and select the radio button that says remote-enabled module since

we will be accessing this from any external system.

Then click on the second tab that says IMPORT.

Enter a PARAMETER NAME( here from date and to date), TYPE and the structure you created in the first step. Also select the check box ‘Pa’.

All remotely enabled functional modules MUST be Pa enabled, where Pa means ‘Passed by Value’ and if you don’t select ‘Pa’,

then that means it will be passed by reference..

Then click on tab that says EXPORT.

Enter the following as is in the first three fields

RETURN TYPE BAPIRETURN (These 3 field values are always same)

Here also select ‘Pa’ meaning Pass by value.

Note: BAPIRETURN contains structure with message fields.

Then SAVE and ACTIVATE.

Step 3. Creating BAPI object:

Enter Tr.Code <SWO1> (Note. It is letter ‘O’ and not Zero).

Enter a name and then click on create. Enter details.

NOTE: Make sure that that Object Type and Program name are SAME.

Enter Application ‘M’, if you are using standard table Mara. If you are using your own database then select ‘Z’ at the bottom.

Then hit <ENTER>.

Now we have to add ‘Methods’. High light METHODS and then select the following from the menu:

Goto Utilities -> API Methods -> Add Methods.

Enter function Module name and hit <ENTER>.

Select the second FORWARD ARROW button (>)to go to next step.

Check if every thing looks ok and again click on FORWARD ARROW button (>).

Then select ‘YES’ and click on <SAVE>.

Now on a different screen goto TR.CODE <SE37>. Enter Function Module name and select from the top menu Function Module -> Release -> Release.

Goback to TR.CODE <SWO1>.

Here select the menu combination shown below in the same order.

Edit -> Change Release Status -> Object Type Component -> To Implemented.

Edit -> Change Release Status -> Object Type Component -> To Released.

Edit -> Change Release Status -> Object Type -> To Implemented.

Edit -> Change Release Status -> Object Type -> To Released.

Then click on <SAVE>.

Then click on Generate Button (4th button from left hand side looks like spinning wheel).

Then Click on the button that says ‘PROGRAM’ to see the source code.

To check if this is present in work flow goto TR.CODE <BAPI>.

Here it shows business object repository.

First click on the middle button and then select “ALL” and hit ENTER.

Goto tab ALPHABETICAL and look for the object that you created. This shows that the BAPI object has been created successfully

Hope this helps u,

Regards,

Arunsri

Read only

Former Member
0 Likes
748

Hi,

Please remember that BAPI is a function module that you will have to create via SE37.

While creating it must be set as 'Remote Enabled', else it won't be a BAPI.

To pass parameters to a BAPI, structure is a must, even if its only one filed that you pass.

The BAPI return parameter is RETURN.

In your function module you have to design your logic accordingly.

Please don't forget to release the BAPI in appropriate steps.

Reward if Helpful.

Read only

Former Member
0 Likes
748

STEP 1 - Define a structures for the BAPI

In this step structures for the parameters and tables of the function module used for

the BAPI are defined.

Use Data type -> Structure

Define the following structures:

ZBAPI_ORDER_STATUS_IMPORT which contains the following fields:

ORDERID Order number (Keyfield)

SPRAS Language

ExcludeInactive - Checkbox - Exclude inactive status

ZBAPISTAT:

OBJNR like JEST-OBJNR

STAT like JEST-STAT

INACT like JEST-INACT

TXT04 like TJ02T-TXT04

TXT30 likeTJ02T-TXT30

Important note:

You will have to define a structure for every parameter in the BAPI. You cannot use

the same structures used in existing applications because BAPI structures are frozen

when BAPIs are released and then there are restrictions on changing them.

ZBAPI_ORDER_STATUS_IMPORT

ZBAPI_ORDER_S

TATUS_IMPORT

ZBAPISTAT

STEP 2 - Write Function Module

Important notes:

Each BAPI must have its own function group.

Under the attrbutes tab remember to select Processing Type Remote Enabled

module, otherwise the function module cannot be invoked via RFC and used as a

BAPI

Import/Export parameters can only be BY VALUE for an RFC enabled function

module

We are only creating one BAPI in this example, but you can create related BAPIs

in the same function pool, so they will be able to share global data.

attributes

Import Parameters

Export Parameters

Tables

Code

Notes:

The subroutine SET_RETURN_MESSAGE is a standard routine used for BAPIs that use the BAPIRETURN structure

In form Z_BAPI_GET_ORDER_SYSTEM_STATUS there is a test IF 1 = 2. If the test is true a mesage is displayed. The condition will obviously never be true, and we will never want to display a message in a BAPI. The reason why it

is included is, that it create a reference for the message, so that the WHERE USED funstionallity can be used for the message. This is the SAP standard way to handle it, copied from the Company Code GetList BAPI.

INCLUDE LZBAPISTATUSUXX

*****************************************************************

  • THIS FILE IS GENERATED BY THE FUNCTION LIBRARY. *

  • NEVER CHANGE IT MANUALLY, PLEASE! *

*****************************************************************

INCLUDE LZBAPISTATUSU02.

"Z_BAPI_GET_ORDER_SYSTEM_STATUS

INCLUDE LZBAPISTATUSTOP - Global data

FUNCTION-POOL ZBAPISTATUS. "MESSAGE-ID Z3

Types:

begin of Type_tj02t,

istat like tj02t-istat,

txt04 like tj02t-txt04,

txt30 like tj02t-txt30,

end of type_tj02t.

DATA:

  • Declarations for TABLE parameter

T_BAPISTAT like ZBAPISTAT occurs 0,

G_BAPISTAT like ZBAPISTAT,

  • Table for object texts

t_tj02t type type_tj02t occurs 0,

g_tj02t type type_tj02t.

  • Structure for return messages

DATA:

BEGIN OF MESSAGE,

MSGTY LIKE SY-MSGTY,

MSGID LIKE SY-MSGID,

MSGNO LIKE SY-MSGNO,

MSGV1 LIKE SY-MSGV1,

MSGV2 LIKE SY-MSGV2,

MSGV3 LIKE SY-MSGV3,

MSGV4 LIKE SY-MSGV4,

END OF MESSAGE.

INCLUDE LZBAPISTATUSF01 - Subroutines

***INCLUDE LZBAPISTATUSF01 .

----


&----


*& Form SET_RETURN_MESSAGE

&----


  • This routine is used for setting the BAPI return message.

*

  • The routine is a standard routine for BAPIs that handles the message

  • structure for the BAPIRETURN structure. It has been copied from the

  • BAPI Company Code Getlist

----


  • -->P_MESSAGE text

  • <--P_RETURN text

----


form SET_RETURN_MESSAGE USING VALUE(P_MESSAGE) LIKE MESSAGE

CHANGING P_RETURN LIKE BAPIRETURN.

CHECK NOT MESSAGE IS INITIAL.

CALL FUNCTION 'BALW_BAPIRETURN_GET'

EXPORTING

TYPE = P_MESSAGE-MSGTY

CL = P_MESSAGE-MSGID

NUMBER = P_MESSAGE-MSGNO

PAR1 = P_MESSAGE-MSGV1

PAR2 = P_MESSAGE-MSGV2

PAR3 = P_MESSAGE-MSGV3

PAR4 = P_MESSAGE-MSGV4

  • LOG_NO = ' '

  • LOG_MSG_NO = ' '

IMPORTING

BAPIRETURN = P_RETURN

EXCEPTIONS

OTHERS = 1.

endform. " SET_RETURN_MESSAGE

FUNCTION Z_BAPI_GET_ORDER_STATUS

FUNCTION z_bapi_get_order_system_status.

*"----


""Local interface:

*" IMPORTING

*" VALUE(I_AUFNR) TYPE AUFNR

*" VALUE(I_SPRAS) TYPE SPRAS DEFAULT SY-LANGU

*" VALUE(I_EXCLUDEINACTIVE) TYPE CHAR1 OPTIONAL

*" EXPORTING

*" VALUE(RETURN) TYPE BAPIRETURN

*" TABLES

*" T_BAPISTAT STRUCTURE ZBAPISTAT

*"----


**

*"Local interface:

*" IMPORTING

*" VALUE(I_AUFNR) TYPE AUFNR

*" VALUE(I_SPRAS) TYPE SPRAS DEFAULT SY-LANGU

*" VALUE(I_EXCLUDEINACTIVE) TYPE CHAR1 OPTIONAL

*" EXPORTING

*" VALUE(RETURN) TYPE BAPIRET2

*" TABLES

*" T_BAPISTAT STRUCTURE ZBAPISTAT

*"----


DATA:

l_aufnr LIKE afko-aufnr,

l_objnr LIKE jest-objnr.

********************************************

  • Check if order exists

********************************************

SELECT SINGLE aufnr

FROM afko

INTO l_aufnr

WHERE aufnr = BAPI_ORDER_STATUS_IMPORT-orderid.

IF sy-subrc NE 0.

CLEAR message.

message-msgty = 'E'.

message-msgid = 'Z3'.

message-msgno = '000'.

message-msgv1 = BAPI_ORDER_STATUS_IMPORT-orderid.

PERFORM set_return_message USING message

CHANGING return.

IF 1 = 2.

  • The only reason to include this statement, that will obviously

  • never execute, is that it will create a referecence so that you

  • can find out where a particular message is being used. This

  • functionality is used by the BAPIs programmed by SAP

MESSAGE e000(z3).

ENDIF.

ENDIF.

CHECK return IS INITIAL.

********************************************

  • Read order status

********************************************

CONCATENATE 'OR' BAPI_ORDER_STATUS_IMPORT-orderid INTO l_objnr.

IF BAPI_ORDER_STATUS_IMPORT-i_excludeinactive = 'X'.

SELECT objnr stat inact

FROM jest

INTO TABLE t_bapistat

WHERE objnr = l_objnr AND

inact <> 'X'.

ELSE.

SELECT objnr stat inact

FROM jest

INTO TABLE t_bapistat

WHERE objnr = l_objnr.

ENDIF.

IF sy-subrc <> 0.

  • No object status found

CLEAR message.

message-msgty = 'E'.

message-msgid = 'Z3'.

message-msgno = '001'.

message-msgv1 = BAPI_ORDER_STATUS_IMPORT-orderid.

PERFORM set_return_message USING message

CHANGING return.

IF 1 = 2.

MESSAGE e001(z3).

ENDIF.

ENDIF.

CHECK return IS INITIAL.

********************************************

  • Read order status texts

********************************************

SELECT istat txt04 txt30

FROM tj02t

INTO TABLE t_tj02t

FOR ALL ENTRIES IN t_bapistat

WHERE istat = t_bapistat-stat AND

spras = BAPI_ORDER_STATUS_IMPORT-i_spras.

SORT t_tj02t BY istat.

LOOP AT t_bapistat INTO g_bapistat.

READ TABLE t_tj02t

WITH KEY istat = g_bapistat-stat BINARY SEARCH

INTO g_tj02t.

IF sy-subrc = 0.

MOVE:

g_tj02t-txt04 TO g_bapistat-txt04,

g_tj02t-txt30 TO g_bapistat-txt30.

MODIFY t_bapistat FROM g_bapistat TRANSPORTING txt04 txt30.

ENDIF.

ENDLOOP.

ENDFUNCTION.

STEP 3 - Create the API Method Using the BAPI WIZARD

follow this link

http://www.sapmaterial.com/bapi_step3.html

STEP 4 - Final steps

When the Business object has been checked and the documentation created, the follwing steps must be carried out:

Release the BAPI function module (in the Function Builder).

Release the business object type (in the BOR ObjectType -> Change release status to -> Implemented ).

Release the BAPI as a method in the BOR (Release the methods you has created - Set the cursor on the method then

Edit -> Change release status -> Object type component -> To released )

For potential write BAPIs: Release the IDoc and its segments

You can now display the BAPI in the BAPI Explorer:

the link is

http://www.sapmaterial.com/bapi_step4.html

do reward if helpful

Read only

Former Member
0 Likes
748

Hi,

Please refer to the link below:

http://www.saptechnical.com/Tutorials/BAPI/CustomBAPICreation/page1.htm

Thanks,

Sriram Ponna.