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

Test a Bapi

Former Member
0 Likes
7,034

Hi Gurus,

I need to figure out a Bapi for Puchase order create, which I assume is Bapi_Po_create.

I would like to figure out how I can test the Bapi and how can I find out the mandatory fields for this.

Any help would be appreciated with points

Regards,

DJ

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,362

goto SE37 and specify the BAPI...

Try specfying the values in various parameters... Now try to execute and if the mandatory fields need to be specified it doesnot run but asks for the fields...

5 REPLIES 5
Read only

Former Member
0 Likes
3,363

goto SE37 and specify the BAPI...

Try specfying the values in various parameters... Now try to execute and if the mandatory fields need to be specified it doesnot run but asks for the fields...

Read only

Former Member
0 Likes
3,362

hiii

simple way is go to SE37-->enter FM name ->press display->select import...here can see a column called OPTIONAL.if it is marked then fields are not mendatory or else compulsary fields.

best way to test BAPI is debug mode.and check return parameters.it will take time but you will get to know whole data transfering process.

regards

twinkal

Read only

Former Member
0 Likes
3,362

Hi,

Please use BAPI_PO_CREATE1 instead of BAPI_PO_CREATE. the latter one is obsolete.

This code will help you to know which fields can be used to create PO. To find the mandatory fields, you can check SE37 -> pass on the BAPI name and check the export, import and tables parameters. If optional is not selected, then you have to pass value to them.

gs_poheader-ref_1 = delivery.

gs_poheader-creat_date = sy-datum.

gs_poheader-created_by = sy-uname.

gs_poheader-langu = sy-langu.

gs_poheader-doc_date = sy-datum.

CLEAR gs_poheaderx.

gs_poheaderx-doc_type = 'X'.

gs_poheaderx-purch_org = 'X'.

gs_poheaderx-vendor = 'X'.

gs_poheaderx-pur_group = 'X'.

gs_poheaderx-ref_1 = 'X'.

gs_poheaderx-creat_date = 'X'.

gs_poheaderx-created_by = 'X'.

gs_poheaderx-langu = 'X'.

gs_poheaderx-doc_date = 'X'.

IF gt_delitem[] IS NOT INITIAL.

LOOP AT gt_delitem INTO gs_delitem.

CLEAR: gs_poitem, gs_poitemx.

gs_poitem-po_item = gs_delitem-posnr.

gs_poitem-material = gs_delitem-matnr.

gs_poitem-plant = gv_plant.

gs_poitem-quantity = gs_delitem-lfimg.

gs_poitem-shipping = space.

gs_poitem-tax_code = gv_taxid.

gs_poitem-po_unit = gs_delitem-meins.

APPEND gs_poitem TO gt_poitem.

gs_poitemx-po_item = gs_delitem-posnr.

gs_poitemx-po_itemx = 'X'.

gs_poitemx-material = 'X'.

gs_poitemx-plant = 'X'.

gs_poitemx-quantity = 'X'.

gs_poitemx-shipping = 'X'.

gs_poitemx-tax_code = 'X'.

gs_poitemx-po_unit = 'X'.

APPEND gs_poitemx TO gt_poitemx.

CLEAR: gs_poschedule, gs_poschedulex.

gs_poschedule-po_item = gs_delitem-posnr.

gs_poschedule-delivery_date = lv_date.

APPEND gs_poschedule TO gt_poschedule.

gs_poschedulex-po_item = gs_delitem-posnr.

gs_poschedulex-po_itemx = 'X'.

gs_poschedulex-delivery_date = 'X'.

APPEND gs_poschedulex TO gt_poschedulex.

ENDLOOP.

ENDIF.

    • Create Purchase Order.

IF gs_poheader IS NOT INITIAL.

CLEAR: gv_ponum.

REFRESH gt_return.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = gs_poheader

poheaderx = gs_poheaderx

testrun = testrun

IMPORTING

exppurchaseorder = gv_ponum

TABLES

return = gt_return

poitem = gt_poitem

poitemx = gt_poitemx

poschedule = gt_poschedule

poschedulex = gt_poschedulex.

    • Check for error messages

LOOP AT gt_return INTO gs_return WHERE type = 'E'

OR type = 'A'.

EXIT.

ENDLOOP.

IF sy-subrc <> 0 AND gv_ponum IS NOT INITIAL.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

ENDIF.

    • Return the values to Calling Program

IF gv_ponum IS NOT INITIAL.

purchaseorder = gv_ponum.

IF gt_poitem IS NOT INITIAL.

LOOP AT gt_poitem INTO gs_poitem.

CLEAR gs_item.

MOVE-CORRESPONDING gs_poitem TO gs_item.

gs_item-po_number = gv_ponum.

APPEND gs_item TO po_items.

ENDLOOP.

ENDIF.

ENDIF.

ENDIF.

Thanks,

Kartavya

Read only

uwe_schieferstein
Active Contributor
0 Likes
3,362

Hello

All the inputs which are required for the corresponding dialog transaction (ME21N) are mandatory for the BAPI, too.

While it is possible to test the BAPI_PO_CREATE1 using transaction SE37 (Function Builder) I can highly recommend to write a simple eCATT script (transaction SECATT ) which just calls the BAPI (FUN pattern) because you can evaluate the returned messages much easier and faster.

Regards

Uwe

Read only

3,362

Also check out how to test BAPI in SE37 and write the results to the data base (perform commit work) without any additional developement [Easy BAPI testing in SE37|http://dominiktylczynskien.wordpress.com/2011/07/06/easy-bapi-testing-in-se37/]

Dominik Tylczynski