Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BAPI help urgent

Former Member
0 Likes
620

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.

4 REPLIES 4
Read only

Former Member
0 Likes
575

Hi,

Check out the sample code for the same BAPI.

This error may come because of incorrect Package no value.

DATA: i_poitem TYPE STANDARD TABLE OF bapimepoitem,

i_poitemx TYPE STANDARD TABLE OF bapimepoitemx,

i_poitem_sch TYPE STANDARD TABLE OF bapimeposchedule,

i_poitem_schx TYPE STANDARD TABLE OF bapimeposchedulx,

i_acct_ass TYPE STANDARD TABLE OF bapimepoaccount,

i_acct_assx TYPE STANDARD TABLE OF bapimepoaccountx,

i_services TYPE STANDARD TABLE OF bapiesllc ,

i_srvacc TYPE STANDARD TABLE OF bapiesklc,

i_return TYPE STANDARD TABLE OF bapiret2,

wa_header TYPE bapimepoheader,

wa_headerx TYPE bapimepoheaderx,

wa_poitem TYPE bapimepoitem,

wa_poitemx TYPE bapimepoitemx,

wa_poitem_sch TYPE bapimeposchedule,

wa_poitem_schx TYPE bapimeposchedulx,

wa_acct_ass TYPE bapimepoaccount,

wa_acct_assx TYPE bapimepoaccountx,

wa_services TYPE bapiesllc,

wa_srvacc TYPE bapiesklc,

wa_return TYPE bapiret2,

ws_po TYPE bapimepoheader-po_number,

ws_wait TYPE bapita-wait.

CONSTANTS: c_x TYPE char01 VALUE 'X'.

break gbpra8.

wa_header-doc_type = 'ZDET'.

wa_header-vendor = '0002000000'.

PERFORM conversion_output USING wa_header-vendor

CHANGING wa_header-vendor.

wa_header-comp_code = 'DE03'.

wa_header-purch_org = 'DE03'.

wa_header-pur_group = 'DE1'.

wa_header-vper_start = '20060730'.

wa_header-vper_end = '20070621'.

wa_headerx-comp_code = c_x.

wa_headerx-doc_type = c_x.

wa_headerx-creat_date = c_x.

wa_headerx-created_by = c_x.

wa_headerx-vendor = c_x.

wa_headerx-purch_org = c_x.

wa_headerx-pur_group = c_x.

wa_headerx-vper_start = c_x.

wa_headerx-vper_end = c_x.

wa_poitem-po_item = 100.

wa_poitem-short_text = 'Sample'.

wa_poitem-plant = 'DE03'.

wa_poitem-quantity = 1.

wa_poitem-tax_code = 'V1'.

wa_poitem-item_cat = 'D'.

wa_poitem-acctasscat = 'K'.

wa_poitem-matl_group = 'ZDESS'.

wa_poitem-pckg_no = 10.

wa_poitem-gr_ind = space.

wa_poitem-gr_basediv = space.

APPEND wa_poitem TO i_poitem .

wa_poitemx-po_item = 100.

wa_poitemx-po_itemx = c_x.

wa_poitemx-short_text = c_x.

wa_poitemx-plant = c_x.

wa_poitemx-quantity = c_x.

wa_poitemx-tax_code = c_x.

wa_poitemx-item_cat = c_x.

wa_poitemx-acctasscat = c_x.

wa_poitemx-matl_group = c_x.

wa_poitemx-pckg_no = c_x.

wa_poitemx-gr_ind = c_x.

wa_poitemx-gr_basediv = space.

APPEND wa_poitemx TO i_poitemx.

wa_poitem-po_item = 200.

wa_poitem-short_text = 'Sample'.

wa_poitem-plant = 'DE03'.

wa_poitem-quantity = 1.

wa_poitem-tax_code = 'V1'.

wa_poitem-item_cat = 'D'.

wa_poitem-acctasscat = 'K'.

wa_poitem-matl_group = 'ZDESS'.

wa_poitem-pckg_no = 40.

wa_poitem-gr_ind = space.

wa_poitem-gr_basediv = space.

APPEND wa_poitem TO i_poitem .

wa_poitemx-po_item = 200.

wa_poitemx-po_itemx = c_x.

wa_poitemx-short_text = c_x.

wa_poitemx-plant = c_x.

wa_poitemx-quantity = c_x.

wa_poitemx-tax_code = c_x.

wa_poitemx-item_cat = c_x.

wa_poitemx-acctasscat = c_x.

wa_poitemx-matl_group = c_x.

wa_poitemx-pckg_no = c_x.

wa_poitemx-gr_ind = c_x.

wa_poitemx-gr_basediv = space.

APPEND wa_poitemx TO i_poitemx.

wa_acct_ass-po_item = 100.

wa_acct_ass-serial_no = 01.

wa_acct_ass-gl_account = '0006360100'.

wa_acct_ass-co_area = '1000'.

wa_acct_ass-costcenter = 'KC010000'.

APPEND wa_acct_ass TO i_acct_ass.

wa_acct_assx-po_item = 100.

wa_acct_assx-serial_no = 01.

wa_acct_assx-po_itemx = c_x.

wa_acct_assx-serial_nox = c_x.

wa_acct_assx-gl_account = c_x.

wa_acct_assx-co_area = c_x.

wa_acct_assx-costcenter = c_x.

APPEND wa_acct_assx TO i_acct_assx.

wa_acct_ass-po_item = 100.

wa_acct_ass-serial_no = 02.

wa_acct_ass-gl_account = '0006360100'.

wa_acct_ass-co_area = '1000'.

wa_acct_ass-costcenter = 'KC010000'.

APPEND wa_acct_ass TO i_acct_ass.

wa_acct_assx-po_item = 100.

wa_acct_assx-serial_no = 02.

wa_acct_assx-po_itemx = c_x.

wa_acct_assx-serial_nox = c_x.

wa_acct_assx-gl_account = c_x.

wa_acct_assx-co_area = c_x.

wa_acct_assx-costcenter = c_x.

APPEND wa_acct_assx TO i_acct_assx.

wa_acct_ass-po_item = 200.

wa_acct_ass-serial_no = 01.

wa_acct_ass-gl_account = '0006360100'.

wa_acct_ass-co_area = '1000'.

wa_acct_ass-costcenter = 'KC010000'.

APPEND wa_acct_ass TO i_acct_ass.

wa_acct_assx-po_item = 200.

wa_acct_assx-serial_no = 01.

wa_acct_assx-po_itemx = c_x.

wa_acct_assx-serial_nox = c_x.

wa_acct_assx-gl_account = c_x.

wa_acct_assx-co_area = c_x.

wa_acct_assx-costcenter = c_x.

APPEND wa_acct_assx TO i_acct_assx.

wa_acct_ass-po_item = 200.

wa_acct_ass-serial_no = 02.

wa_acct_ass-gl_account = '0006360100'.

wa_acct_ass-co_area = '1000'.

wa_acct_ass-costcenter = 'KC010000'.

APPEND wa_acct_ass TO i_acct_ass.

wa_acct_assx-po_item = 200.

wa_acct_assx-serial_no = 02.

wa_acct_assx-po_itemx = c_x.

wa_acct_assx-serial_nox = c_x.

wa_acct_assx-gl_account = c_x.

wa_acct_assx-co_area = c_x.

wa_acct_assx-costcenter = c_x.

APPEND wa_acct_assx TO i_acct_assx.

wa_services-pckg_no = 10.

wa_services-line_no = 1.

wa_services-outl_no = '0'.

wa_services-outl_ind = c_x.

wa_services-subpckg_no = 20.

wa_services-from_line = 1.

wa_services-to_line = 2.

APPEND wa_services TO i_services.

wa_services-pckg_no = 20.

wa_services-line_no = 2.

wa_services-service = 'H007'.

wa_services-quantity = '12'.

wa_services-gr_price = '100'.

wa_services-userf1_txt = 'Firm'.

APPEND wa_services TO i_services.

wa_services-pckg_no = 40.

wa_services-line_no = 1.

wa_services-outl_no = '0'.

wa_services-outl_ind = c_x.

wa_services-subpckg_no = 50.

wa_services-from_line = 1.

wa_services-to_line = 2.

APPEND wa_services TO i_services.

wa_services-pckg_no = 50.

wa_services-line_no = 2.

wa_services-service = 'H008'.

wa_services-quantity = '12'.

wa_services-gr_price = '100'.

wa_services-userf1_txt = 'Firm'.

APPEND wa_services TO i_services.

wa_srvacc-pckg_no = 10.

wa_srvacc-line_no = 1.

wa_srvacc-serno_line = 01.

wa_srvacc-serial_no = 01.

wa_srvacc-percentage = 100.

APPEND wa_srvacc TO i_srvacc.

wa_srvacc-pckg_no = 20.

wa_srvacc-line_no = 2.

wa_srvacc-serno_line = 02.

wa_srvacc-serial_no = 02.

wa_srvacc-percentage = 100.

APPEND wa_srvacc TO i_srvacc.

wa_srvacc-pckg_no = 40.

wa_srvacc-line_no = 1.

wa_srvacc-serno_line = 01.

wa_srvacc-serial_no = 01.

wa_srvacc-percentage = 100.

APPEND wa_srvacc TO i_srvacc.

wa_srvacc-pckg_no = 50.

wa_srvacc-line_no = 2.

wa_srvacc-serno_line = 02.

wa_srvacc-serial_no = 02.

wa_srvacc-percentage = 100.

APPEND wa_srvacc TO i_srvacc.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = wa_header

poheaderx = wa_headerx

IMPORTING

exppurchaseorder = ws_po

TABLES

return = i_return

poitem = i_poitem

poitemx = i_poitemx

poschedule = i_poitem_sch

poschedulex = i_poitem_schx

poaccount = i_acct_ass

poaccountx = i_acct_assx

poservices = i_services

posrvaccessvalues = i_srvacc.

break gbpra8.

LOOP AT i_return INTO wa_return.

ENDLOOP.

ws_wait = 5.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = ws_wait.

&----


*& Form conversion_output

&----


  • Conversion exit input

----


FORM conversion_output USING p_ip

CHANGING p_op.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = p_ip

IMPORTING

output = p_op.

ENDFORM. " conversion_output

Reward points if it helps.

Manish

Read only

0 Likes
575

hi manish,

i have written this using an eg like this.

Thanks n Regards,

santosh.

Read only

former_member378318
Contributor
0 Likes
575

Hi,

Replace the following line as follows:

v_cdate like header-creat_date value 'sy-datum' ,

Replace with:

v_cdate like header-creat_date.

v_cdate = sy-datum.

I hope it gets further.

Read only

0 Likes
575

Hi dhillon,

Thanks for the attempt but its not working.

Regards,

santosh,