Application Development 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: 

How to upload XML file using abap?

Former Member
0 Kudos

Hello,

I was trying to upload xml file via abap code ...but I am getting lot of errors.

I need a sample ABAP code along with Xml file format.

Regards,

Rachel

2 REPLIES 2

RKBhaskara
Active Contributor
0 Kudos

Hi,

Check FM : GUI_UPLOAD,

with filetype = 'BIN'.

Cheers,

Remi

Former Member
0 Kudos

hi,

i came across the similar requirement, the sample code is furnished here, i am taking xml file data into internal table and calling bapi to change the sales order.

data:

salesdocument like bapivbeln occurs 0 with header line,

order_header_in like bapisdh1 occurs 0 with header line,

order_header_inx like bapisdh1x occurs 0 with header line,

order_item_in like bapisditm occurs 0 with header line,

order_item_inx like bapisditmx occurs 0 with header line,

partners like bapiparnr occurs 0 with header line,

schedule_lines like bapischdl occurs 0 with header line,

schedule_linesx like bapischdlx occurs 0 with header line,

return like bapiret2 occurs 0 with header line.

data: result_xml type standard table of smum_xmltb.

data: result_tab like smum_xmltb.

constants: line_size type i value 255.

parameters doc_no like bapivbeln-vbeln.

salesdocument-vbeln = doc_no.

append salesdocument.

data: filename type string,xmldata type xstring .

data: begin of xml_tab occurs 0,

raw(line_size) type x,

end of xml_tab,

file type string,

size type i.

order_header_inx-updateflag = 'U'.

order_header_inx-sales_org = 'X'.

order_header_inx-distr_chan = 'X'.

order_header_inx-division = 'X'.

order_header_inx-sales_off = 'X'.

order_header_inx-purch_no_c = 'X'.

order_header_inx-req_date_h = 'X'.

order_header_inx-purch_date = 'X'.

append order_header_inx.

order_item_inx-updateflag = 'U'.

order_item_inx-material = 'X'.

order_item_inx-plant = 'X'.

order_item_inx-target_qty = 'X'.

order_item_inx-itm_number = 'X'.

append order_item_inx.

schedule_linesx-updateflag = 'U'.

schedule_linesx-req_qty = 'X'.

schedule_linesx-itm_number = 'X'.

append schedule_linesx.

  • upload the xml file

filename = 'C:\slcreaorder2.xml'.

call function 'GUI_UPLOAD'

exporting

filename = filename

filetype = 'BIN'

  • has_field_separator = ' '

  • header_length = 0

importing

filelength = size

tables

data_tab = xml_tab

exceptions

others = 1.

call function 'SCMS_BINARY_TO_XSTRING'

exporting

input_length = size

  • FIRST_LINE = 0

  • LAST_LINE = 0

importing

buffer = xmldata

tables

binary_tab = xml_tab

exceptions

failed = 1

others = 2

.

if sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

call function 'SMUM_XML_PARSE'

EXPORTING

xml_input = xmldata

TABLES

xml_table = result_xml

return = return.

loop at result_xml into result_tab.

case result_tab-cname.

when 'sales_org'.

order_header_in-sales_org = result_tab-cvalue.

when 'distr_chan'.

order_header_in-distr_chan = result_tab-cvalue.

when 'division'.

order_header_in-division = result_tab-cvalue.

when 'sales_off'.

order_header_in-sales_off = result_tab-cvalue.

when 'purch_no_c'.

order_header_in-purch_no_c = result_tab-cvalue.

when 'purch_date'.

order_header_in-purch_date = result_tab-cvalue.

when 'req_date_h'.

order_header_in-req_date_h = result_tab-cvalue.

  • Appending the Order_Header_in table

append order_header_in.

when 'material'.

order_item_in-material = result_tab-cvalue.

when 'plant'.

order_item_in-plant = result_tab-cvalue.

when 'target_qu'.

order_item_in-target_qty = result_tab-cvalue.

when 'itm_number1'.

order_item_in-itm_number = result_tab-cvalue.

  • Appending the Order_Items_In table.

append order_item_in.

  • item_cnt = item_cnt + 1.

when 'partn_role'.

partners-partn_role = result_tab-cvalue.

when 'partn_numb'.

partners-partn_numb = result_tab-cvalue.

append partners.

  • patnr_flag = 1.

when 'req_qty'.

schedule_lines-req_qty = result_tab-cvalue.

when 'itm_number'.

schedule_lines-itm_number = result_tab-cvalue.

  • Appending the Order_Schedules_in table.

append schedule_lines.

  • sch_cnt = sch_cnt + 1.

endcase.

endloop.

call function 'BAPI_SALESORDER_CHANGE'

exporting

salesdocument = salesdocument

order_header_in = order_header_in

order_header_inx = order_header_inx

  • SIMULATION =

  • BEHAVE_WHEN_ERROR = ' '

  • INT_NUMBER_ASSIGNMENT = ' '

  • LOGIC_SWITCH =

tables

return = return

order_item_in = order_item_in

order_item_inx = order_item_inx

  • PARTNERS =

  • PARTNERCHANGES =

  • PARTNERADDRESSES =

  • ORDER_CFGS_REF =

  • ORDER_CFGS_INST =

  • ORDER_CFGS_PART_OF =

  • ORDER_CFGS_VALUE =

  • ORDER_CFGS_BLOB =

  • ORDER_CFGS_VK =

  • ORDER_CFGS_REFINST =

SCHEDULE_LINES = schedule_lines

SCHEDULE_LINESX = schedule_linesx

  • ORDER_TEXT =

  • ORDER_KEYS =

  • CONDITIONS_IN =

  • CONDITIONS_INX =

  • EXTENSIONIN =

.

if sy-subrc ne 0.

write: return-message,return-number,return-type.

else.

write: return-message,return-number,return-type.

call function 'BAPI_TRANSACTION_COMMIT'

  • EXPORTING

  • WAIT =

  • IMPORTING

  • RETURN =

.

endif.

  • item_cnt = 0.

  • sch_cnt = 0.

  • patnr_flag = 0.

thanks

Pavan