Skip to Content

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

BAPI_PO

Hi Gurus,

I am woking on an interface where I need to use BAPI for PO creation for multiple line items and for this I have written the following code:

&----


*& Report Z_TEST1 *

*& *

&----


*& *

*& *

&----


REPORT Z_TEST1 .

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

  • internal table to store the data

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

data: poheader LIKE bapimepoheader,

poheaderx LIKE bapimepoheaderx,

poitem LIKE bapimepoitem OCCURS 0 WITH HEADER LINE,

poitemx LIKE bapimepoitemx OCCURS 0 WITH HEADER LINE,

return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,

return2 LIKE bapiret2 OCCURS 0 WITH HEADER LINE,

exppurchaseorder LIKE bapimepoheader-po_number,

poschedule LIKE bapimeposchedule OCCURS 0 WITH HEADER LINE,

poschedulex LIKE bapimeposchedulx OCCURS 0 WITH HEADER LINE.

data: begin of it_input_file OCCURS 0,

item_no(3),

ref_no(2),

vend_no(10),

material(18),

Quantity(13),

Price(10),

ord_unit(7),

Plant(4),

Strg_loc(4),

purch_grp(4),

purch_org(4),

c_code(4),

doc_typ(4),

del_date(10),

end of it_input_file.

data: it_ref_no_old(2) type c,

it_record like line of it_input_file,

it_record_x like line of it_input_file.

data: ld_file LIKE rlgrap-filename.

data: begin of it_read_file occurs 0,

line(1000),

end of it_read_file.

data: it_file like it_input_file occurs 0 with header line.

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

    • Definition of Variables *

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

data: v_semfile like RLGRAP-FILENAME.

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

  • Selection Screen *

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

selection-screen begin of block b1 with frame title text-001.

parameters: p_ifname like rlgrap-filename obligatory.

selection-screen end of block b1.

*selection-screen begin of block b2 with frame title text-002.

*

*parameters: p_ifnam2 like rlgrap-filename obligatory DEFAULT '/usr/sap/'.

*

*selection-screen end of block b2.

**

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_ifname.

CALL FUNCTION 'F4_FILENAME' "allows user to select path/file

EXPORTING

program_name = 'Z_PO_Creation'

dynpro_number = syst-dynnr

field_name = 'p_ifname'

IMPORTING

file_name = p_ifname.

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

  • START-OF-SELECTION *

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

start-of-selection.

perform get_data.

perform data_process.

end-of-selection.

&----


*& 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 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.

  • updating header data.

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.

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

&----


*& Form data_process

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM data_process .

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.

ENDFORM. " data_process.

The program is not showing me any error but when I tried to run it in the debug mode, the return statement at Call Bapi returns the folloowing errors:

1. E |BAPI |001 |No instance of object type PurchaseOrder

2. E |MEPO |002 |PO header data still faulty

Can you please help me out how to get rid of it.

Thanks

Rajeev Gupta

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