‎2007 Oct 03 3:18 AM
Hi gurus,
I am working on a BAPI 'BAPI_PO_CREATE1', and I have written the following code:
&----
*& Report Z_BAPI_PURCHASEORDER *
*& *
&----
*& *
*& *
&----
REPORT z_bapi_purchaseorder .
************************************************************************
Definition of Structures *
************************************************************************
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.
expheader LIKE bapimepoheader OCCURS 0 WITH HEADER LINE,
exppoexpimpheader LIKE bapieikp OCCURS 0 WITH HEADER LINE.
poschedule LIKE bapimeposchedule OCCURS 0 WITH HEADER LINE,
poschedulex LIKE bapimeposchedulx OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF itab OCCURS 0,
vend_no(10),
ord_typ(4),
po_date(8),
purch_org(4),
purch_grp(3),
plant(4),
sloc(4),
mat_grp(9),
mat_no(18),
quant(13),
del_date(8),
END OF itab.
************************************************************************
START-OF-SELECTION *
************************************************************************
START-OF-SELECTION.
PERFORM get_data.
PERFORM call_bapi.
END-OF-SELECTION.
&----
*& Form get_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM get_data .
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = 'C:\DocumentsSettings\Desktop\Purc_order_bapi.txt'
filetype = 'DAT'
TABLES
data_tab = itab
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 itab.
moving header data.
MOVE: '0000000111' TO poheader-vendor,
itab-ord_typ TO poheader-doc_type,
itab-po_date TO poheader-doc_date,
itab-purch_org TO poheader-purch_org,
itab-purch_grp TO poheader-pur_group,
'1000' TO poheader-comp_code,
'US' TO poheader-currency,
10 TO poheader-item_intvl,
'ZB03' TO poheader-pmnttrms.
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'.
poheaderx-item_intvl = 'X'.
poheaderx-pmnttrms = 'X'.
moving item data.
MOVE: 00001 TO poitem-po_item,
itab-plant TO poitem-plant,
itab-sloc TO poitem-stge_loc,
itab-mat_grp TO poitem-matl_group,
itab-mat_no TO poitem-material,
itab-quant TO poitem-quantity,
'V0' TO poitem-tax_code,
'0' TO poitem-item_cat .
'PC' TO poitem-po_unit.
updating Item data.
poitemx-po_item = 00001.
poitemx-plant = 'X'.
poitemx-stge_loc = 'X'.
poitemx-matl_group = 'X'.
poitemx-material = 'X'.
poitemx-quantity = 'X'.
poitemx-tax_code = 'X'.
poitemx-item_cat = 'X'.
poitemx-po_unit = 'X'.
moving delievery date.
MOVE: 00001 TO poschedule-po_item,
0001 TO poschedule-sched_line,
itab-del_date TO poschedule-delivery_date,
itab-quant TO poschedule-quantity.
MOVE: 00001 TO poschedulex-po_item,
0001 TO poschedulex-sched_line,
'X' TO poschedulex-delivery_date,
'X' TO poschedulex-po_itemx ,
'X' TO poschedulex-sched_linex ,
'X' TO poschedulex-quantity.
*
APPEND: poitem, poitemx.
poschedule.
poschedulex.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = poheader
poheaderx = poheaderx
IMPORTING
exppurchaseorder = exppurchaseorder
expheader = expheader
exppoexpimpheader = exppoexpimpheader
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
this particular code is taking care of a purchase order with one item, but if I need to make it work for multiple header with multiple item level, so can you please modify my code.
Thanks
Rajeev Gupta
‎2007 Oct 03 3:39 AM
Hi Rajeev, if you see you code for filling the item you have always been passing 00001 to the item number. so it always creates only one item with the data which you have filled in.
moving item data.
MOVE: 00001 TO poitem-po_item,
itab-plant TO poitem-plant,
itab-sloc TO poitem-stge_loc,
itab-mat_grp TO poitem-matl_group,
itab-mat_no TO poitem-material,
itab-quant TO poitem-quantity,
'V0' TO poitem-tax_code,
'0' TO poitem-item_cat .
'PC' TO poitem-po_unit.
In case you want to create multiple headers for this, make sure you increment the item number with in the loop to get multiple items for the PO's you create.
Regards
Gopi
‎2007 Oct 03 3:39 AM
Hi Rajeev, if you see you code for filling the item you have always been passing 00001 to the item number. so it always creates only one item with the data which you have filled in.
moving item data.
MOVE: 00001 TO poitem-po_item,
itab-plant TO poitem-plant,
itab-sloc TO poitem-stge_loc,
itab-mat_grp TO poitem-matl_group,
itab-mat_no TO poitem-material,
itab-quant TO poitem-quantity,
'V0' TO poitem-tax_code,
'0' TO poitem-item_cat .
'PC' TO poitem-po_unit.
In case you want to create multiple headers for this, make sure you increment the item number with in the loop to get multiple items for the PO's you create.
Regards
Gopi
‎2007 Oct 03 12:46 PM
hi Rajeev
what is the format/content of the file 'C:\DocumentsSettings\Desktop\Purc_order_bapi.txt'
Regards
Sumant