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: 

ABAP store XML data as file in AL11

vsubbakrishna
Participant
0 Kudos

Hi All,

I would like to know how i can store XML file on AL11..when i tried it generated a the file contents looked like  þÿ#<#?#x#m#l# #v#e#r#s#i#o#n#=#"#1#.#0#"# ???where as GUI_DOWNLOAD looks fine...Appreciate kind help..

Tahnks,

Subba

REPORT zsub_test_xml_.
DATA:l_send TYPE zar_send,
         w_xml TYPE string,
         fname(200) VALUE '/usr/sap/trans/Test.xml'.


FIELD-SYMBOLS:<l_line> TYPE zar_cdttrftxinf.

PERFORM f_send CHANGING l_send.

CALL TRANSFORMATION ZTRANS

SOURCE indata = l_send-indata RESULT
XML w_xml.


DATA : BEGIN OF itab OCCURS 0,
        a(100) TYPE c,
END OF itab.
data:wa_itab like LINE OF itab.

CALL FUNCTION 'HR_EFI_CONVERT_STRING_TO_TABLE'
  EXPORTING
    i_string         = w_xml
    i_tabline_length = 100
  TABLES
    et_table         = itab.

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    filetype = 'BIN'
    filename = 'C:\Users\Subba.Krishna\Desktop\file_name.xml'   " works fine
  TABLES
    data_tab = itab.

OPEN DATASET fname FOR OUTPUT IN binary mode.
*LOOP AT itab INTO wa_itab.
   TRANSFER  w_xml TO  filename.
*ENDLOOP.
CLOSE DATASET filename.



3 REPLIES 3

former_member219762
Contributor
0 Kudos

Hi Subba,

Use ARCHIVFILE_CLIENT_TO_SERVER function module to upload to application server and ARCHIVFILE_SERVER_TO_CLIENT to down load.

Regards,

Sreenivas.

bernat_loscos
Explorer
0 Kudos

Hi Subba,

You can use this function to upload .xml to sap:

DATA: l_appl_file TYPE eseftappl,

          l_upload    TYPE localfile.

l_upload   = 'your pc file'.

l_appl_file = 'Sap path'.

CALL FUNCTION 'C13Z_FILE_UPLOAD_ASCII' "

        EXPORTING  i_file_front_end   = l_appl_file

                   i_file_appl        =  l_upload

                   i_file_overwrite   = 'X'

        EXCEPTIONS fe_file_not_exists = 1

                   fe_file_read_error = 2

                   ap_no_authority    = 3

                   ap_file_open_error = 4

                   ap_file_exists     = 5.

and use cl_gui_frontend_services=>file_open_dialog, for open file...

Regards,

former_member221372
Participant
0 Kudos

Hope this help,

REPORT zex4.

DATA :
        lt_source TYPE TABLE OF zmdeljiitm,
        lt_send TYPE TABLE OF zmdeljiitm,
        lt_edifact TYPE TABLE OF zmxmlexport,
        wa_source LIKE LINE OF lt_source,
        wa_zmdeljihdr TYPE zmdeljihdr,
        xml_result TYPE xstring"xstring ensures UTF-8 encoding

SELECT SINGLE *
   FROM zmdeljihdr
   INTO wa_zmdeljihdr.

SELECT *
   FROM zmdeljiitm
   INTO TABLE lt_source.

SELECT *
   FROM zmxmlexport
   INTO TABLE lt_edifact
   WHERE filetype  = 'TEST'
   AND   zkey      = 'D'.

DATA : obj1 TYPE REF TO cl_xml_document.
DATA : lv_subrc TYPE sysubrc.
DATA : f_name TYPE localfile.

CREATE OBJECT obj1.

wa_zmdeljihdr-ddate_tmp = wa_zmdeljihdr-ddate+2.
wa_zmdeljihdr-cdate_tmp = wa_zmdeljihdr-cdate.
wa_zmdeljihdr-dtime_tmp = wa_zmdeljihdr-dtime+0(4).

*&------------------------------------------------------------------------------------------------------------------------

*&--> TO SAVE IN PRESENTATION SERVER

*&------------------------------------------------------------------------------------------------------------------------

LOOP AT lt_source INTO wa_source.

   CALL FUNCTION 'BKK_GET_MONTH_LASTDAY'
     EXPORTING
       i_date = wa_source-del_date_from
     IMPORTING
       e_date = wa_source-del_date_to.

   wa_source-ddate_tmp = wa_source-ddate.
   wa_source-erdat_tmp = wa_source-erdat.
   wa_source-del_date_fro_tmp = wa_source-del_date_from.
   wa_source-del_date_to_tmp = wa_source-del_date_to.

   APPEND wa_source TO lt_send.

   AT END OF vendor.
     CALL TRANSFORMATION zdeljit
       SOURCE zheader = wa_zmdeljihdr
              zitem = lt_send[]
              edifact = lt_edifact[]
       RESULT XML xml_result.

     CALL METHOD obj1->parse_xstring
       EXPORTING
         stream  = xml_result
       RECEIVING
         retcode = lv_subrc.

     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
       EXPORTING
         input  = wa_source-vendor
       IMPORTING
         output = wa_source-vendor.

**    PATH

     CALL METHOD obj1->export_to_file
       EXPORTING
         filename = f_name
       RECEIVING
         retcode  = lv_subrc.

     REFRESH : lt_send[].
   ENDAT.
   CLEAR : wa_source.
ENDLOOP.

*&------------------------------------------------------------------------------------------------------------------------

*&--> TO SAVE IN APPLICATION SERVER

*&------------------------------------------------------------------------------------------------------------------------


*LOOP AT lt_source INTO wa_source.
*
*  CALL FUNCTION 'BKK_GET_MONTH_LASTDAY'
*    EXPORTING
*      i_date = wa_source-del_date_from
*    IMPORTING
*      e_date = wa_source-del_date_to.
*
*  wa_source-ddate_tmp = wa_source-ddate.
*  wa_source-erdat_tmp = wa_source-erdat.
*  wa_source-del_date_fro_tmp = wa_source-del_date_from.
*  wa_source-del_date_to_tmp = wa_source-del_date_to.
*
*  APPEND wa_source TO lt_send.
*
*  AT END OF vendor.
*
*    CALL TRANSFORMATION zdeljit
*      SOURCE zheader = wa_zmdeljihdr
*             zitem = lt_send[]
*             edifact = lt_edifact[]
*      RESULT XML xml_result.
*
*    CALL METHOD obj1->parse_xstring
*      EXPORTING
*        stream  = xml_result
*      RECEIVING
*        retcode = lv_subrc.
*
*    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
*      EXPORTING
*        input  = wa_source-vendor
*      IMPORTING
*        output = wa_source-vendor.
*
*    CONCATENATE '/siam_sftp/from_hero_local/' wa_source-vendor '.xml' INTO f_name.
*
*    DATA :
*           l_convin TYPE REF TO cl_abap_conv_in_ce,
*           l_html TYPE string.
*
*
*    TRY.
*        CALL METHOD cl_abap_conv_in_ce=>create
*          EXPORTING
*            encoding = 'UTF-8'
*            input    = xml_result " xstring content received from portal
*          RECEIVING
*            conv     = l_convin.
*
*        CALL METHOD l_convin->read
*          IMPORTING
*            data = l_html.
*
*      CATCH cx_root.
**        l_msgstr = 'Conversion error'.
*    ENDTRY.
*
*    DATA : l_value TYPE char3.
*
*    SEARCH l_html FOR '><'.
*    CLEAR l_value.
*
*    l_value = cl_abap_char_utilities=>newline.
*    CONCATENATE '>' l_value '<' INTO l_value.
*    IF sy-subrc = 0.
*      REPLACE ALL OCCURRENCES OF '><' IN l_html WITH l_value IN CHARACTER MODE.
*    ENDIF.
*
*    OPEN DATASET f_name
*         FOR OUTPUT IN TEXT MODE
*         ENCODING DEFAULT.
*
*    TRANSFER l_html TO f_name.
*
*    CLOSE DATASET f_name.
*
*    REFRESH : lt_send[].
*  ENDAT.
*  CLEAR : wa_source.
*ENDLOOP.

Regards

Bharath