Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Create an XML File in Application server

Hello,

I have a requirement to create an XML File as Local File and as server File. For the local File it works fine and i got a Local XML File.

My problem is for the Server File.I found a solution in internet to convert in binary.But i don't get in the server File created the XML structure.

Here is My code for the unix server File

DATA ex_tab TYPE TABLE OF x255.

  data: wa_tab type x255.

  data: lv_line(255) type c.

**-- carica tabella gt_file

   PERFORM CARICA_TAB_FILE.

   LOOP AT GT_FILE.

     MOVE-CORRESPONDING GT_FILE TO WA_SOURCE.

     APPEND WA_SOURCE TO GT_SOURCE.

     CLEAR WA_SOURCE.

   ENDLOOP.

* Perform the XSLT stylesheet

   TRY.

       CALL TRANSFORMATION ZMESMO052_XML

          SOURCE MATERIAL_DATA = GT_SOURCE[]

          RESULT XML XML_RESULT .

     CATCH CX_ROOT INTO GS_RIF_EX.

       GS_VAR_TEXT = GS_RIF_EX->GET_TEXT( ).

       MESSAGE GS_VAR_TEXT TYPE 'E'.

   ENDTRY.

  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

     EXPORTING

         buffer     = XML_RESULT

       TABLES

         binary_tab = ex_tab.

   CONCATENATE P_FILE '.xml' INTO P_FILE.

   CONDENSE P_FILE.

   TRANSLATE P_FILE TO LOWER CASE.

   OPEN DATASET P_FILE FOR OUTPUT IN BINARY MODE.

   IF SY-SUBRC NE 0.

     MESSAGE E000(ZF) WITH ' Error opening File' P_FILE.

   ENDIF.

   loop at ex_tab  into wa_tab.

     move wa_tab to lv_line.

     transfer lv_line to p_file.

   endloop.

   close dataset p_file.

And i Got a file like this

Any solution please

Tags:
Former Member
Former Member replied

I Found the solution,

DATA EX_TAB TYPE TABLE OF X255.

   DATA: WA_TAB TYPE X255.

   DATA: LV_LINE(255) TYPE C.

   DATA: L_CONVIN TYPE REF TO CL_ABAP_CONV_IN_CE.

   DATA: L_HTML TYPE STRING.

   DATA: L_VALUE TYPE STRING.

   DATA: L_MSGSTR TYPE STRING.

   DATA: FILENAME TYPE STRING.

**-- carica tabella gt_file

   PERFORM CARICA_TAB_FILE.

   LOOP AT GT_FILE.

     MOVE-CORRESPONDING GT_FILE TO WA_SOURCE.

     APPEND WA_SOURCE TO GT_SOURCE.

     CLEAR WA_SOURCE.

   ENDLOOP.

* Perform the XSLT stylesheet

   TRY.

       CALL TRANSFORMATION ZMESMO052_XML

          SOURCE MATERIAL_DATA = GT_SOURCE[]

          RESULT XML XML_RESULT .

     CATCH CX_ROOT INTO GS_RIF_EX.

       GS_VAR_TEXT = GS_RIF_EX->GET_TEXT( ).

       MESSAGE GS_VAR_TEXT TYPE 'E'.

   ENDTRY.

   TRY.

       CALL METHOD CL_ABAP_CONV_IN_CE=>CREATE

         EXPORTING

           ENCODING = 'UTF-8'

           INPUT    = XML_RESULT

         RECEIVING

           CONV     = L_CONVIN.

       CALL METHOD L_CONVIN->READ

         IMPORTING

           DATA = L_HTML.

     CATCH CX_ROOT.

       L_MSGSTR = 'Conversion error'.

   ENDTRY.

   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.

   CONCATENATE P_FILE '.xml' INTO P_FILE.

   CONDENSE P_FILE.

   TRANSLATE P_FILE TO LOWER CASE.

   FILENAME = P_FILE.

   OPEN DATASET FILENAME FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE

WITH UNIX LINEFEED.

   TRANSFER L_HTML TO FILENAME.

   CLOSE DATASET FILENAME.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question