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

Download XML structure to Application server

Former Member
0 Likes
1,817

Hi all.

I am generating an XML structure based on some data that I select from HR e-Recruiting, and I need to save the generated XML file on the application server, not the presentation server (local computer). Most of the code I have found on SDN (contributed by Robert Eijpe) and I must admit that I do not understand everything the code does.

I have attached the source code and the resulting XML structure:

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-uzeit+2(2) TO time+2(2).
  WRITE sy-uzeit+0(2) TO time+0(2).
  WRITE sy-datum+4(2) TO date+0(2).
  WRITE sy-datum+6(2) TO date+2(2).
  WRITE sy-datum+0(4) TO date+4(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.

<b>XML result:</b>

<?xml version="1.0" ?>

<position>

<job_title>Test Process Template</job_title>

<job_title>jjjj</job_title>

<job_title>Test Job Req. 20092005</job_title>

<job_title>Created 22.09</job_title>

<job_title>title 07.12</job_title>

<job_title>Test fra portal</job_title>

<job_title>Test med 100328</job_title>

<job_title>Test restricted recruiter</job_title>

<job_title>Test restricted recruiter</job_title>

<job_title>Workshop requisition job title</job_title>

</position>

Any help is greatly appreciated.

Best Regards,

Thomas Kjelsrud

1 ACCEPTED SOLUTION
Read only

guillaume-hrc
Active Contributor
0 Likes
1,109

Hi Thomas,

I do not quite see the problem here...

I have only 2 hints :

1) Are you sure your filepath is referring to a directory of the application server ?

=> see transaction AL11 to view the tree

=> see transaction FILE if you want to use logical file

2) Have you the required authorizations to write on the application server ? (what does the return code - sy-subrc - tell you in Debug ?)

Best regards,

Guillaume

Hi Thomas,

If possible can you please paste your final code here.

Thanks in Advance.

Murali Krishna K

6 REPLIES 6
Read only

guillaume-hrc
Active Contributor
0 Likes
1,110

Hi Thomas,

I do not quite see the problem here...

I have only 2 hints :

1) Are you sure your filepath is referring to a directory of the application server ?

=> see transaction AL11 to view the tree

=> see transaction FILE if you want to use logical file

2) Have you the required authorizations to write on the application server ? (what does the return code - sy-subrc - tell you in Debug ?)

Best regards,

Guillaume

Read only

0 Likes
1,109

Hi Guillaume,

The thing is that the code I presented to you is incorrect. I am asking the question of how to download / save an XML (not an internal table) to the application server. Using the gui_download will not satisfy me need, as it only downloads to the presentation server (local machine that I run my SAP session on), when I need it to download to the application server. The Open Dataset and Transfer statements are (as far as I know) only used for downloading internal tables to the application server.

So I guess my question should be like this instead:

"How can I save the XML structure that is created in the above program to the file system in the application server?"

It is a bit hard to explain this, so please ask me more questions if required.

Thank you for helping.

Best regards,

Thomas

Read only

0 Likes
1,109

Does this help ?

DATA rec(80). "Adjust as per requirement/OS limits

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.

Regards,

Viren.

Read only

0 Likes
1,109

As a matter of fact, it did! I just needed to make rec of type xml_line, and it seems to work.

Thanks!

Points rewarded

Read only

0 Likes
1,109

Hi Thomas,

If possible can you please paste your final code here.

Thanks in Advance.

Murali Krishna K

Read only

Former Member
0 Likes
1,109

Hi all,

i am having a problem when creating an XML file on the server. Once the file is created, and the file is opened in the DME engine, the xml files is created as one single line instead of a normal indented XML node. anyone can help me please. Thanks in advance