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: 

Need Sample code to upload the data to Application Server

Former Member
0 Kudos
132

Hi ,

I need to upload the data to application server.

The output should be an XML file.

Can anybody send me sample code for this.

Reward points are assured.

Best Regards

Bhagat.

6 REPLIES 6

Bema
Active Participant
0 Kudos
101

To upload data to application server, you can use OPEN DATASET...TRANSFER...CLOSE DATASET statements.

Former Member
0 Kudos
101

may be this code wil help ,first to downjload the XML fine -

1)

REPORT zhr_test2_tk.

TYPE-POOLS: ixml.

TYPES: BEGIN OF xml_line,

data(256) TYPE x,

END OF xml_line.

DATA: l_ixml TYPE REF TO if_ixml,

l_streamfactory TYPE REF TO if_ixml_stream_factory,

l_ostream TYPE REF TO if_ixml_ostream,

l_renderer TYPE REF TO if_ixml_renderer,

l_document TYPE REF TO if_ixml_document.

DATA: l_element_position TYPE REF TO if_ixml_element,

l_element_title TYPE REF TO if_ixml_element,

  • l_element_flight TYPE REF TO if_ixml_element,

  • l_element_from TYPE REF TO if_ixml_element,

  • l_element_to TYPE REF TO if_ixml_element,

l_element_dummy TYPE REF TO if_ixml_element,

l_value TYPE string.

DATA: l_xml_table TYPE TABLE OF xml_line,

l_xml_size TYPE i,

l_rc TYPE i.

DATA: lt_erec TYPE TABLE OF hrp5126,

l_erec TYPE hrp5126.

DATA: date(10),

time(4),

filepath TYPE string.

CONSTANTS: filedir TYPE string VALUE 'C:\tmp\',

filename TYPE string VALUE 'ZHR_test'.

START-OF-SELECTION.

  • fill internal table

SELECT * FROM hrp5126 INTO TABLE lt_erec.

  • Start filling xml DOM object from internal table lt_erec.

LOOP AT lt_erec INTO l_erec.

*Create the root node 'position'

IF sy-tabix EQ 1.

  • create an ixml factory

l_ixml = cl_ixml=>create( ).

  • create Document Object Model

l_document = l_ixml->create_document( ).

  • Fill root node with value 'position'

l_element_position = l_document->create_simple_element(

name = 'position'

parent = l_document ).

ENDIF.

IF sy-tabix GT 1.

  • create element jobtitle as child of position

l_value = l_erec-jobtitle.

l_element_title = l_document->create_simple_element(

name = 'job_title'

parent = l_element_position

value = l_value ).

l_value = l_erec-empl_start_date.

l_element_dummy = l_document->create_simple_element(

name = 'StartDate'

parent = l_element_title

value = l_value ).

l_value = l_erec-empl_end_date.

l_element_dummy = l_document->create_simple_element(

name = 'EndDate'

parent = l_element_title

value = l_value ).

ENDIF.

ENDLOOP.

IF sy-subrc NE 0.

WRITE: 'No data in table hrp5125'.

ENDIF.

  • create a stream factory

l_streamfactory = l_ixml->create_stream_factory( ).

  • connect internal XML table to streamfactory

l_ostream = l_streamfactory->create_ostream_itable(

table = l_xml_table ).

  • render the document

l_renderer = l_ixml->create_renderer( ostream = l_ostream

document = l_document ).

l_rc = l_renderer->render( ).

  • Get time and date

WRITE sy-uzeit2(2) TO time2(2).

WRITE sy-uzeit0(2) TO time0(2).

WRITE sy-datum4(2) TO date0(2).

WRITE sy-datum6(2) TO date2(2).

WRITE sy-datum0(4) TO date4(4).

*Build filename with date and time reference

CONCATENATE filedir filename date time '.xml' INTO filepath.

<i>* This is the code I hope to modify in order to save the xml structure on the application server, with a specified filepath.</i>

<b> OPEN DATASET filepath FOR OUTPUT IN BINARY MODE.

LOOP AT lt_erec into l_erec.

TRANSFER l_erec TO filepath.

ENDLOOP.

CLOSE DATASET filepath.</b>

  • save XML document

l_xml_size = l_ostream->get_num_written_raw( ).

*This is the code for download to local computer

  • CALL METHOD cl_gui_frontend_services=>gui_download

  • EXPORTING

  • bin_filesize = l_xml_size

  • filename = filepath

  • filetype = 'BIN'

  • CHANGING

  • data_tab = l_xml_table

  • EXCEPTIONS

  • file_write_error = 1

  • no_batch = 2

  • gui_refuse_filetransfer = 3

  • invalid_type = 4

  • no_authority = 5

  • unknown_error = 6

  • header_not_allowed = 7

  • separator_not_allowed = 8

  • filesize_not_allowed = 9

  • header_too_long = 10

  • dp_error_create = 11

  • dp_error_send = 12

  • dp_error_write = 13

  • unknown_dp_error = 14

  • access_denied = 15

  • dp_out_of_memory = 16

  • disk_full = 17

  • dp_timeout = 18

  • file_not_found = 19

  • dataprovider_exception = 20

  • control_flush_error = 21

  • OTHERS = 22.

*

  • IF sy-subrc <> 0.

  • MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

  • WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

2) uploading tht PC XML file to APPliaction server -

DATA rec like QISRS_XML_LINE.

OPEN DATASET filepath FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

LOOP AT l_xml_table into rec.

TRANSFER rec TO filepath.

ENDLOOP.

CLOSE DATASET filepath.

Former Member
0 Kudos
101

data: str(255).

  • bring the file data into itab.

data: fname(30) value 'd:\xxx.xml'.

open dataset fname for output in text mode encoding default.

loop at itab.

concatenate itab-var1 itab-var2 .........itab-varn into str seperated by ','.

transfer str to fname.

endloop.

if sy-subrc = 0.

write: 'file downloaded'.

else.

write: 'unable to download'.

endif.

close dataset fname.

Cheers.

0 Kudos
101

Hi Giri,

I need to download the data as an XML file.

Best Regards

Bhagat.

0 Kudos
101

Hi Giri,

The requirement is I need to Upload the data to application server and that data should get resided on the application server as an XML file.

Can you send me sample code for this ?

Best Regards

Bhagat.

Bema
Active Participant