‎2007 Oct 04 7:09 PM
Hi Gurus,
I am working on a BAPI to create purchase order and for this I have written the follwoing code:
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.
DATA: BEGIN OF itab OCCURS 0,
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),
END OF itab.
Data: it_ref_no_old(2) type c,
it_record like line of itab,
it_record_x like line of itab.
************************************************************************
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.
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 = 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: itab-vend_no TO poheader-vendor,
itab-doc_typ TO poheader-doc_type,
itab-purch_org TO poheader-purch_org,
itab-purch_grp TO poheader-pur_group,
itab-c_code TO poheader-comp_code.
updating header data.
poheaderx-vendor = 'X'.
poheaderx-doc_type = 'X'.
poheaderx-purch_org = 'X'.
poheaderx-pur_group = 'X'.
poheaderx-comp_code = 'X'.
moving item data.
MOVE: itab-plant TO poitem-plant,
itab-Strg_loc TO poitem-stge_loc,
itab-material TO poitem-material,
itab-quantity TO poitem-quantity,
itab-price TO poitem-price_unit,
itab-ref_no TO poitem-ref_doc,
itab-ord_unit TO poitem-po_unit.
updating Item data.
poitemx-plant = 'X'.
poitemx-stge_loc = 'X'.
poitemx-material = 'X'.
poitemx-quantity = 'X'.
poitem-price_unit = 'X'.
poitem-ref_doc = 'X'.
poitem-po_unit = 'X'.
APPEND: poitem, poitemx.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = poheader
poheaderx = poheaderx
IMPORTING
exppurchaseorder = exppurchaseorder
TABLES
poitem = poitem
poitemx = poitemx
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 itab by ref_no.
clear: it_ref_no_old.
loop at itab into it_record.
if it_record-ref_no ne it_ref_no_old .
loop AT itab 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
and my text file looks like this:
the sequence of the fileds are:
Ref no., Vendor, material,Quantity, Price, Ord_unit, Plant,
Strg_loc, purch_org, purch_grp,c_code, doc_typ
1 101 123 100 10 car 101 121 114 112 222 NB
1 101 234 100 10 buc 101 121 114 112 222 NB
1 101 567 100 10 car 101 121 114 112 222 NB
2 102 123 100 10 car 101 121 114 112 222 NB
2 102 567 100 10 car 101 121 114 112 222 NB
3 103 234 100 10 buc 101 121 114 112 222 NB
3 103 567 100 10 car 101 121 114 112 222 NB
3 103 123 100 10 car 101 121 114 112 222 NB
4 104 567 100 10 car 101 121 114 112 222 NB
To me code looks perfectly fine but somehow its not creating the purchse order, can you please help me to get out of this issue.
Thanks
Rajeev Gupta
Message was edited by:
Rajeev Gupta
‎2007 Oct 04 7:15 PM
Hi Rajeev,
Try these FM:
BAPI_PO_GETDETAIL
BAPI_PO_GETDETAIL1
call BAPI-function in this system *
CALL FUNCTION 'BAPI_PO_GETDETAIL1'
EXPORTING
PURCHASEORDER = PURCHASEORDER
ACCOUNT_ASSIGNMENT = ACCOUNT_ASSIGNMENT
ITEM_TEXT = ITEM_TEXT
HEADER_TEXT = HEADER_TEXT
DELIVERY_ADDRESS = DELIVERY_ADDRESS
VERSION = VERSION
SERVICES = SERVICES
IMPORTING
POHEADER = POHEADER
POEXPIMPHEADER = POEXPIMPHEADER
TABLES
RETURN = RETURN
POITEM = POITEM
POADDRDELIVERY = POADDRDELIVERY
POSCHEDULE = POSCHEDULE
POACCOUNT = POACCOUNT
POCONDHEADER = POCONDHEADER
POCOND = POCOND
POLIMITS = POLIMITS
POCONTRACTLIMITS = POCONTRACTLIMITS
POSERVICES = POSERVICES
POSRVACCESSVALUES = POSRVACCESSVALUES
POTEXTHEADER = POTEXTHEADER
POTEXTITEM = POTEXTITEM
POEXPIMPITEM = POEXPIMPITEM
POCOMPONENTS = POCOMPONENTS
POSHIPPINGEXP = POSHIPPINGEXP
POHISTORY = POHISTORY
POHISTORY_TOTALS = POHISTORY_TOTALS
POCONFIRMATION = POCONFIRMATION
ALLVERSIONS = ALLVERSIONS
POPARTNER = POPARTNER
EXTENSIONOUT = EXTENSIONOUT
EXCEPTIONS
OTHERS = 1.
(or)
Try this out...
Report ZBapi .
data: po_items type table of bapiekpo with header line.
parameters: p_ebeln type ekko-ebeln.
call function 'BAPI_PO_GETDETAIL'
exporting
purchaseorder = p_ebeln
ITEMS = 'X'
ACCOUNT_ASSIGNMENT = ' '
SCHEDULES = ' '
HISTORY = ' '
ITEM_TEXTS = ' '
HEADER_TEXTS = ' '
SERVICES = ' '
CONFIRMATIONS = ' '
SERVICE_TEXTS = ' '
EXTENSIONS = ' '
IMPORTING
PO_HEADER =
PO_ADDRESS =
tables
PO_HEADER_TEXTS =
po_items = po_items
PO_ITEM_ACCOUNT_ASSIGNMENT =
PO_ITEM_SCHEDULES =
PO_ITEM_CONFIRMATIONS =
PO_ITEM_TEXTS =
PO_ITEM_HISTORY =
PO_ITEM_HISTORY_TOTALS =
PO_ITEM_LIMITS =
PO_ITEM_CONTRACT_LIMITS =
PO_ITEM_SERVICES =
PO_ITEM_SRV_ACCASS_VALUES =
RETURN =
PO_SERVICES_TEXTS =
EXTENSIONOUT =
.
check sy-subrc = 0.
loop at po_items.
write:/ po_items.
endloop.
Reward if helpful.
Regards,
Harini.S
‎2007 Oct 04 7:19 PM
Thanks for the reply Harini, but I have already used this BAPI but somehow I got stuck somewhere, can you please help me out with my code only.
Thanks
Rajeev Gupta