OData is Rest-based protocol, used to retrieve and update the data. It acts as a medium between front-end and back-end.

Purchase order: It means is a commercial document and first official offer issued by a buyer to a seller, indicating types, quantities, and agreed prices for products or services.

In this blog i will explain how do we create purchase order using bapi in a odata service .

Coming to the creation of Purchase order based on RFC  we are using the function module


Step 1: Go to Segw transaction and create a project

Step 2:Create a Project, Provide the project name, description and package. Click on continue.

The components are like

1. Data Model

2. Service Implementation

3. Runtime Artifacts

4. Service Maintenance.

And it Displays automatically when the project create.

Step 3: Our project looks as below.


Step 4: Go to the data model and Right click on that Import RFC Interface.

Step 5:When we click on RFC function module a screen should appear as below

Step 6:when we give an Entity type and RFC name and press Next.

Step 7: Follow the above step 6 to select the item, material, partner and conditions required fields to select as our requirement.

Step 8: N ow we need to generate runtime artifacts.for that, you need to select Runtime Artifacts and click on

Click OK and save it.

Step 9: Right click on get entity ->go to ABAP workbench and redefine the methods.

Step 10: Then we need to right click on the methods and redefine required methods in the following process.

To Get the Purchase Order .Write the code as Follows.



TYPES:BEGIN OF ty_bapiekko,

ponumber TYPE ebeln,

END OF ty_bapiekko.

DATA:it_num TYPE TABLE OF ty_bapiekko,

wa_num TYPE ty_bapiekko,

wa_keytab TYPE /iwbep/s_mgw_name_value_pair,

lv_tab TYPE string.

DATA:lv_ebeln TYPE ebeln.

READ TABLE it_key_tab INTO wa_keytab INDEX 1.

IF it_key_tab IS NOT INITIAL.

select single ebeln FROM ekko INTO lv_ebeln where ebeln = wa_keytab-value.

er_entity-po_number = lv_ebeln.


DATA :In the Same way Redefine the method and create the entries in Create set.


wa_header TYPE bapimepoheader,

wa_headerx TYPE bapimepoheaderx.

DATA: it_return TYPE TABLE OF bapiret2 ,

it_poitem TYPE TABLE OF bapimepoitem ,

wa_poitem TYPE bapimepoitem,

it_poitemx TYPE TABLE OF bapimepoitemx ,

wa_poitemx TYPE bapimepoitemx,

it_poschedule TYPE TABLE OF bapimeposchedule ,

it_poschedulex TYPE TABLE OF bapimeposchedulx ,

it_poaccount TYPE TABLE OF bapimepoaccount ,

it_poaccountx TYPE TABLE OF bapimepoaccountx ,

it_polimits TYPE TABLE OF bapiesuhc ,

it_povalues TYPE TABLE OF bapiesklc ,

po_number TYPE bapimepoheader-po_number,

it_poservices TYPE TABLE OF bapiesllc,

ls_expheader TYPE TABLE OF bapimepoheader,

ls_exppoexpimpheader TYPE TABLE OF bapieikp,

it_popartner TYPE TABLE OF bapiekkop ,”OPTIONAL,

wa_popartner TYPE bapiekkop,

it_pocondheader TYPE TABLE OF bapimepocondheader ,

wa_pocondheader TYPE bapimepocondheader,

it_pocondheaderx TYPE TABLE OF bapimepocondheaderx ,

wa_pocondheaderx TYPE bapimepocondheaderx,

it_partner TYPE TABLE OF bapimepopartner ,


g_potextitem TYPE TABLE OF bapimepotext ,

w_potextitem TYPE bapimepotext,

g_potextheader TYPE TABLE OF bapimepotextheader ,

w_potextheader TYPE bapimepotextheader,

it_bapi TYPE TABLE OF lfa1 .

* er_entity-MATERIAL = lv_ebeln.

DATA: et_table TYPE zcl_zcreate_bapi_pocre_mpc=>ts_purchaseorder.

io_data_provider->read_entry_data( IMPORTING es_data = et_table ).

wa_header-comp_code = et_table-comp_code.

wa_header-doc_type = et_table-doc_type.

wa_header-vendor = et_table-vendor.

wa_header-purch_org = et_table-purch_org.

wa_header-pur_group = et_table-pur_group.

wa_headerx-comp_code = ‘X’.

wa_headerx-doc_type = ‘X’ .

wa_headerx-vendor = ‘X’ .

wa_headerx-purch_org = ‘X’.

wa_headerx-pur_group = ‘X’.

wa_poitem-po_item = et_table-PO_ITEM. “wa_poitem-po_item.

wa_poitem-material = et_table-material.

wa_poitem-plant = et_table-plant.

wa_poitem-quantity = et_table-quantity.

*wa_poitem-net_price = et_table-net_price.

APPEND wa_poitem TO it_poitem.

wa_poitemx-po_item = et_table-PO_ITEM. “‘00010’.

wa_poitemx-po_itemx = ‘X’.

wa_poitemx-material = ‘X’.

wa_poitemx-plant = ‘X’.

wa_poitemx-quantity = ‘X’.

*wa_poitemx-net_price = ‘X’.

APPEND wa_poitemx TO it_poitemx.

*wa_popartner-buspartno = et_table-buspartno.

*APPEND wa_popartner TO it_popartner .

wa_POCONDHEADER-itm_number = et_table-PO_ITEM.

wa_pocondheader-cond_type = et_table-cond_type.

wa_pocondheader-conbaseval = et_table-conbaseval.

wa_pocondheader-change_id = et_table-change_id.

APPEND wa_pocondheader TO it_pocondheader.

wa_pocondheaderx-itm_number = et_table-PO_ITEM. “‘000010’.

wa_pocondheaderx-itm_numberx = ‘X’.

wa_pocondheaderx-cond_type = ‘X’.

wa_pocondheaderx-conbaseval = ‘X’.

wa_pocondheaderx-change_id = ‘X’.

APPEND wa_pocondheaderx TO it_pocondheaderx.

*w_potextitem-po_item = et_table-po_item .

* APPEND w_potextitem TO g_potextitem.

w_potextheader-text_line = et_table-text_line.

APPEND w_potextheader TO g_potextheader.

*it_return = et_table.



poheader = wa_header

poheaderx = wa_headerx


exppurchaseorder = po_number

* expheader = ls_expheader

* exppoexpimpheader = ls_exppoexpimpheader


return = it_return

poitem = it_poitem

poitemx = it_poitemx

* popartner = it_popartner

pocondheader = it_pocondheader

pocondheaderx = it_pocondheaderx

* potextitem = g_potextitem

potextheader = g_potextheader.

er_entity = et_table.


IF po_number IS NOT INITIAL.






*WRITE:/ PO number.


Step 11: Save and activate the set .

Step 12:Go to transaction /IWFND/MAINT_SERVICE and add service Press enter

Step 13: After adding that service gives system alias as a ‘LOCAL’ and click on get services select your service name.

Step 14: After adding your service and go back and select your service in sap gateway client.

Step 15:Start the Gateway Client (Transaction /IWFND/GW_CLIENT) in a separate window to run the service. Provide the following URI to get the metadata for the service:


Step 16:When We click on use as request and it displays in the HTTP request to change the entries

Step 17:After creation of an entries to HTTP request request data it should be displayed in it.when we click on post method then Purchase order it should be generated

Step 18: Either we will see purchase order entries it will be created in Go tcode ME21N(create) and check the entries are displayed .



To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply