Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

BAPI_PO_CREATE!

I am working on PO creation and for this I have written the following code, PO is meant for multiple line items, and each PO should be differentiate from the other on the basis of the refrence field. The code is as follows:

&----


*& Form get_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_data .

v_semfile = p_ifname.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

filename = v_semfile

filetype = 'DAT'

TABLES

data_tab = it_input_file

EXCEPTIONS

conversion_error = 1

file_open_error = 2

file_read_error = 3

invalid_table_width = 4

invalid_type = 5

no_batch = 6

unknown_error = 7

gui_refuse_filetransfer = 8

OTHERS = 9.

ENDFORM. " get_data

&----


*& Form data_process

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM data_process .

if it_input_file[] is initial.

message E319 with 'There is no data to process!!'.

else.

sort it_input_file by ref_no.

clear: it_ref_no_old.

loop at it_input_file into it_record.

if it_record-ref_no ne it_ref_no_old .

loop AT it_input_file into it_record_x

where ref_no = it_record-ref_no .

endloop.

if syst-subrc = 0 .

PERFORM call_bapi.

endif.

endif.

it_ref_no_old = it_record-ref_no.

endloop.

endif.

ENDFORM.

*

&----


*& Form call_bapi

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM call_bapi .

LOOP AT it_input_file.

  • moving header data.

MOVE: it_input_file-vend_no TO poheader-vendor,

it_input_file-doc_typ TO poheader-doc_type,

it_input_file-purch_org TO poheader-purch_org,

it_input_file-purch_grp TO poheader-pur_group,

it_input_file-c_code TO poheader-comp_code,

it_input_file-doc_date TO poheader-doc_date.

  • updating header data.

if poheader-vendor <> ' '.

poheaderx-vendor = 'X'.

endif.

if poheader-doc_type <> ' '.

poheaderx-doc_type = 'X'.

endif.

if poheader-doc_date <> ' '.

poheaderx-doc_date = 'X'.

endif.

if poheader-purch_org <> ' '.

poheaderx-purch_org = 'X'.

endif.

if poheader-pur_group <> ' '.

poheaderx-pur_group = 'X'.

endif.

if poheader-comp_code <> ' '.

poheaderx-comp_code = 'X'.

endif.

  • poheaderx-vendor = 'X'.

  • poheaderx-doc_type = 'X'.

  • poheaderx-doc_date = 'X'.

  • poheaderx-purch_org = 'X'.

  • poheaderx-pur_group = 'X'.

  • poheaderx-comp_code = 'X'.

  • moving item data.

MOVE: it_input_file-item_no TO poitem-po_item,

it_input_file-plant TO poitem-plant,

it_input_file-Strg_loc TO poitem-stge_loc,

it_input_file-material TO poitem-material,

it_input_file-quantity TO poitem-quantity,

it_input_file-price TO poitem-price_unit,

it_input_file-ref_no TO poitem-ref_doc,

it_input_file-ord_unit TO poitem-po_unit.

  • updating Item data.

if poitem-plant <> ' '.

poitemx-plant = 'X'.

endif.

if poitem-material <> ' '.

poitemx-material = 'X'.

endif.

if poitem-stge_loc <> ' '.

poitemx-stge_loc = 'X'.

endif.

if poitem-quantity <> ' '.

poitemx-quantity = 'X'.

endif.

  • if poitem-price_unit <> ' '.

  • poitemx-price_unit = 'X'.

  • endif.

*

  • if poitem-ref_doc <> ' '.

  • poitemx-ref_doc = 'X'.

  • endif.

*

  • if poitem-po_unit <> ' '.

  • poitemx-po_unit = 'X'.

  • endif.

poitemx-po_item = it_input_file-item_no.

  • poitemx-plant = 'X'.

  • poitemx-stge_loc = 'X'.

  • poitemx-material = 'X'.

  • poitemx-quantity = 'X'.

move: it_input_file-del_date TO poschedule-delivery_date.

move: 'X' TO poschedulex-delivery_date.

APPEND: poitem, poitemx.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = poheader

poheaderx = poheaderx

IMPORTING

exppurchaseorder = exppurchaseorder

TABLES

poitem = poitem

poitemx = poitemx

poschedule = poschedule

poschedulex = poschedulex

return = return.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

IMPORTING

return = return2.

WRITE:/ exppurchaseorder.

ENDLOOP.

ENDFORM. " call_bapi

and my input file looks like this:

1 1000 NB 20071210 V1 AE01 501 USD 10 M5 1003 100 1000 EA 20071110

1 1000 NB 20071210 V1 AE01 507 USD 10 P10 1003 100 2000 EA 20071110

2 1000 NB 20071210 V1 AE01 501 USD 10 M5 1003 50 1000 EA 20071110

the name of the fields in order are : <b>refno., compnaycode,doc-typ,doc_date,vendor,purch_org,purch_grp,currency

tem no, material, plant, quantity, price, order unit, del_date</b>.

So basically my Program should create 2 PO's but to my surprise it created 5 or 6 po's with only first record.

Can you please help to get out of this issue.

Thanks

Rajeev Gupta

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question