Dear All,
cud any spot the error the error..it throws an exception FAILURE
&----
*& Report Y1MM_PODRG *
*& *
&----
*& *
*& *
&----
report y1mm_podrg .
tables: mara,
lfa1,
eina,
eine,
eban,
zdrgsah, zdrgsap,
t100.
*Internal Table to get the input Data
data: begin of i_input occurs 0,
matnr like ekpo-matnr,
asqty like ekpo-menge,
ebeln like ekpo-ebeln,
posnr like zdrgsap-posnr,
invno like zdrgsap-invno,
invdt like zdrgsah-invdt,
netpr like zdrgsap-netpr,
cntno like zdrgsap-cntno,
shcnm like zdrgsah-shcnm,
werks like ekpo-werks,
lgort like ekpo-lgort,
matkl like ekpo-matkl,
end of i_input.
data: begin of i_error occurs 0,
matnr like mara-matnr,
remark(255) type c,
end of i_error.
data: i_mara type mara occurs 0 with header line,
i_eina like eina occurs 0 with header line,
i_eine like eine occurs 0 with header line.
*Data declaration.
data: v_file type string, " Variable for uploading file
v_item(5) type c, " Line item number
v_itno(2) type c,
p_wkurs like zdrgkurs-wkurs,
v_matnr(20) type c,
v_menge(20) type c,
v_banfn(20) type c,
v_bnfpo(20) type c,
v_bednr(20) type c,
p_lifnr like lfa1-lifnr,
v_flag,
p_lifnrtxt(10),
p_wkurstxt(9),
p_bsartxt(4).
.
data: begin of i_inputxt occurs 0,
matnr(18) ,
asqty(13) ,
ebeln(10) ,
posnr(6) ,
invno(10) ,
invdt(8) ,
netpr(11) ,
cntno(11) ,
shcnm(10) ,
werks(4) ,
lgort(4) ,
matkl(9) ,
end of i_inputxt.
Constants
constants : c_pd01 like eine-werks value 'PD01',
c_x value 'X'.
*Structures to hold PO header data
data : header like bapimepoheader ,
headerx like bapimepoheaderx .
data : begin of cheader occurs 0,
cond_type like bapimepocondheader-cond_type,
end of cheader.
*data : cheaderx like bapimepocondheaderx.
data : begin of cheaderx occurs 0,
cond_type like bapimepocondheaderx-cond_type,
end of cheaderx.
*Internal Tables to hold PO ITEM DATA
data : item like bapimepoitem occurs 0 with header line,
itemx like bapimepoitemx occurs 0 with header line,
*Internal table to hold messages from BAPI call
return like bapiret2 occurs 0 with header line.
data : w_header(40) value 'PO Header'.
data : ws_langu like sy-langu.
*text-001 = 'PO Header' - define as text element
data : v_company like header-comp_code value 'SBA' ,
v_doctyp like header-doc_type value 'NB' ,
v_cdate like header-creat_date value 'sy-datum' ,
v_vendor like header-vendor ,
v_pur_org like header-purch_org value 'sbap' ,
v_pur_grp like header-pur_group value 'PG1' .
*Selection Screen Declarations
selection-screen begin of block b1 with frame title text-010.
parameters: p_invno like zdrgsah-invno obligatory,
p_bsart like ekko-bsart.
selection-screen end of block b1.
*selection-screen begin of block b2 with frame title text-002.
*parameters : item_num like item-po_item default '00010',
material like mara-matnr default '0011442062' ,
plant like item-plant default 'PD01' ,
quantity like item-quantity default 100.
*selection-screen end of block b2.
&----
start-of-selection.
&----
*DATA POPULATION
&----
ws_langu = sy-langu. "Language variable
To Upload the data into Internal table.
perform f_upload_data.
To Validate the input data.
perform f_check_data.
if i_error[] is initial.
To process the data file
perform f_process_session.
elseif not i_error[] is initial.
To display the error message
perform f_display_error.
perform bapi_call_data.
endif.
end-of-selection.
&----
*Output the messages returned from BAPI call
&----
loop at return.
write / return-message.
endloop.
&----
*& Form f_upload_data
&----
form f_upload_data .
select matwa as matnr asqty ebeln posnr b~invno invdt netpr cntno
shcnm into table i_input
from zdrgsah as a join zdrgsap as b on
a~invno = b~invno
where b~invno eq p_invno.
loop at i_input.
select single * from eban
where banfn eq i_input-ebeln
and bnfpo eq i_input-posnr.
if sy-subrc eq 0.
move eban-werks to i_input-werks.
move eban-lgort to i_input-lgort.
move eban-matkl to i_input-matkl.
modify i_input.
clear i_input.
endif.
endloop.
endform. " f_upload_data
&----
*& Form f_check_data
&----
form f_check_data .
if not i_input[] is initial.
select * from mara
into table i_mara
for all entries in i_input
where matnr eq i_input-matnr.
endif.
if i_mara[] is initial.
message e000(zcnc) with text-001.
endif.
read table i_input index 1.
if sy-subrc eq 0.
select single lifnr into p_lifnr from zdrgsup
where shcnm = i_input-shcnm.
if sy-subrc <> 0.
message e000(zcnc) with text-002.
endif.
endif.
select single wkurs into p_wkurs from zdrgkurs
where invno = p_invno.
if sy-subrc ne 0.
message e000(zcnc) with text-s11.
endif.
call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
exporting
input = p_lifnr
importing
output = p_lifnr.
p_lifnrtxt = p_lifnr.
p_wkurstxt = p_wkurs.
p_bsartxt = p_bsart.
loop at i_input.
move-corresponding i_input to i_inputxt.
append i_inputxt.
endloop.
endform. "f_check_data
&----
*& Form bapi_call_data
&----
text
----
form bapi_call_data.
*POPULATE HEADER DATA FOR PO
header-comp_code = v_company .
header-doc_type = v_doctyp .
header-creat_date = v_cdate .
header-vendor = p_lifnr .
header-langu = ws_langu .
header-quotation = p_invno.
header-exch_rate = p_wkurs.
header-ex_rate_fx = 'X'.
header-purch_org = v_pur_org .
header-pur_group = v_pur_grp .
header-doc_date = sy-datum.
&----
*POPULATE HEADER FLAG.
&----
headerx-comp_code = c_x.
headerx-doc_type = c_x.
headerx-creat_date = c_x.
headerx-vendor = c_x.
headerx-langu = c_x.
headerx-quotation = c_x.
headerx-exch_rate = c_x.
headerx-ex_rate_fx = c_x.
headerx-purch_org = c_x.
headerx-pur_group = c_x.
headerx-doc_date = c_x.
&----
*POPULATE HEADER DATA.CONDITIONS
&----
cheader-cond_type = 'ZCA1'.
append cheader.
cheader-cond_type = 'ZFA1'.
append cheader.
cheader-cond_type = 'ZINC'.
append cheader.
cheader-cond_type = 'ZIV1'.
append cheader.
cheader-cond_type = 'ZOT1'.
append cheader.
&----
*POPULATE HEADER CONDITION FLAG.
&----
cheader-cond_type = c_x.
&----
*POPULATE ITEM DATA.
&----
perform bdc_field using v_bednr i_input-cntno.
item-price_unit = '100'.
loop at i_inputxt.
item-plant = i_inputxt-werks.
item-stge_loc = i_inputxt-lgort.
item-material = i_inputxt-matnr.
item-matl_group = i_inputxt-matkl.
item-quantity = i_inputxt-asqty.
item-preq_no = i_inputxt-ebeln.
item-preq_item = i_inputxt-posnr.
item-trackingno = i_inputxt-cntno.
item-preq_item = i_input-posnr.
item-net_price = item-price_unit * item-quantity.
append item.
clear item.
endloop.
&----
*POPULATE ITEM FLAG TABLE
&----
itemx-po_item = item_num.
itemx-material = c_x.
itemx-plant = c_x .
itemx-stge_loc = c_x .
itemx-quantity = c_x .
itemx-stge_loc = c_x .
itemx-tax_code = c_x .
itemx-item_cat = c_x .
itemx-acctasscat = c_x .
itemx-net_price = c_x.
append itemx.
&----
*BAPI CALL
&----
call function 'BAPI_PO_CREATE1'
exporting
poheader = header
poheaderx = headerx
POADDRVENDOR =
TESTRUN =
IMPORTING
EXPPURCHASEORDER =
EXPHEADER =
EXPPOEXPIMPHEADER =
tables
pocondheader = cheader
pocondheaderx = cheaderx
return = return
poitem = item
poitemx = itemx.
&----
*Confirm the document creation by calling database COMMIT
&----
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'
IMPORTING
RETURN =
.
endform. "bapi_call_data
Thanks a lot ,
santosh Kotra.