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 internal tabel to xml

Former Member
0 Kudos

Hi All,

I have generated xml file from internal table and need to display in excel as a report..but i need to add the custom column names and other formating options..could any one help me how to generate the xml with those column headings or attributes.

<?xml version="1.0" encoding="iso-8859-1" ?>

- <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">

- <asx:values>

- <OUTPUT>

- <item>

<MANDT>040</MANDT>

<ZPRDBRN>HCPTOOLSUS</ZPRDBRN>

<DESCRP>Current Open Deliveries</DESCRP>

<ZPTDAT>2008-12-19</ZPTDAT>

<ZHTUSOR>527</ZHTUSOR>

<ZHTUSIT>3753</ZHTUSIT>

<ZHTUSQT>43973</ZHTUSQT>

<ZHTUSNT>1623976.22</ZHTUSNT>

<ZHPRTOR />

<ZHPRTITM />

<ZHPRTQT />

</item>

appreciate your help..

thanks,

Suresh.

5 REPLIES 5

former_member181995
Active Contributor
0 Kudos

check the link posted by Monalisa in below thread.

0 Kudos

Hi Amit,

Thanks for u r response, i have that xml programatically generated and i wanted the xml tags to be generated in the same way and not sure how to do that.i got the tags from monalisa's wiki...are there any examples or any help that i can generate the code with the tags or to do my customization?

Thank you,

Suresh.

SuhaSaha
Advisor
Advisor
0 Kudos

Hello Suresh,

May be you can try this piece of code:


*&---------------------------------------------------------------------*
*& Report  Z_SPLIT_TABLE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  Z_SPLIT_TABLE.

TYPES:
  BEGIN OF TY_VBAK,
    VBELN TYPE VBELN_VA,
    VBTYP TYPE VBTYP,
    ERDAT TYPE ERDAT,
  END OF TY_VBAK,

  BEGIN OF TY_XML,
    DATA TYPE REF TO DATA,
    XML  TYPE STRING,
  END OF TY_XML.

DATA:
  V_ROWS      TYPE I,
  IT_VBAK     TYPE STANDARD TABLE OF TY_VBAK,
  V_FILENAM   TYPE STRING,
  V_FILEPATH  TYPE STRING,
  V_SIZE      TYPE I,
  IT_DATA     TYPE REF TO DATA,
  IT_XML      TYPE STANDARD TABLE OF TY_XML,
  WA_XML      TYPE TY_XML,
  CL_ZIP      TYPE REF TO CL_ABAP_ZIP.

DATA:
  V_DATA     TYPE REF TO DATA,
  V_XML      TYPE XSTRING,
  V_ZIPFILE  TYPE XSTRING,
  IT_BINFILE TYPE STANDARD TABLE OF X255.

FIELD-SYMBOLS:
  <FS_TAB> TYPE TABLE,
  <FS>     TYPE ANY.

PARAMETERS:
  P_DATA TYPE NUMC2 DEFAULT '25',
  P_FILE TYPE LOCALFILE DEFAULT
              'C:\Documents and Settings\ssaha\Desktop\'.

START-OF-SELECTION.

  V_ROWS = P_DATA.

  SELECT VBELN VBTYP ERDAT UP TO V_ROWS ROWS
  INTO TABLE IT_VBAK
  FROM VBAK
  WHERE ERDAT <= '20081231'
  OR    ERDAT >  '20080901'.

  IF SY-SUBRC = 0.
*   Create DATA reference of the internal table
    GET REFERENCE OF IT_VBAK INTO IT_DATA.

*   Transfer the contents of this to the data table
    WA_XML-DATA = IT_DATA.

    CONCATENATE SY-DATUM SY-UZEIT '.txt' INTO WA_XML-XML.

    APPEND WA_XML TO IT_XML.
    CLEAR WA_XML.
  ENDIF.

END-OF-SELECTION.


  CREATE OBJECT CL_ZIP.

  LOOP AT IT_XML INTO WA_XML.
    UNASSIGN: <FS_TAB>, <FS>.

    ASSIGN WA_XML-DATA->* TO <FS_TAB>.
    CREATE DATA V_DATA LIKE LINE OF <FS_TAB>.
    ASSIGN V_DATA->* TO <FS>.

*   Create the XML Transformation
    CALL TRANSFORMATION ID
    SOURCE <FS> = <FS_TAB>
    RESULT XML V_XML.

*   Add the XML file to ZIP folder
    CALL METHOD CL_ZIP->ADD( NAME    = WA_XML-XML
        CONTENT = V_XML )
*      EXPORTING
        .

  ENDLOOP.

  V_ZIPFILE = CL_ZIP->SAVE( ).
*    RECEIVING
*      ZIP = V_ZIPFILE.

  CLEAR V_SIZE.

  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      BUFFER        = V_ZIPFILE
    IMPORTING
      OUTPUT_LENGTH = V_SIZE
    TABLES
      BINARY_TAB    = IT_BINFILE.

  V_FILEPATH = P_FILE.

  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      BIN_FILESIZE            = V_SIZE
      FILENAME                = V_FILEPATH
      FILETYPE                = 'BIN'
    TABLES
      DATA_TAB                = IT_BINFILE
    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.
  ENDIF.

I written this code to generate a ZIP file instead it generated an XML file ) I am still working on it.

But since you need an XML file i hope this helps.

BR,

Suhas

Former Member
0 Kudos

Hi Suhas,

Thank you for u r response, I have already generated the xml file but need to format the xml file with customized headings and fonts. i have the tags available but not sure how to do them programatically..

plz help or any ideas would really help..

my xml is like this.

<?xml version="1.0" encoding="iso-8859-1"?>

<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0"><asx:values>

<item><output>

<MANDT>040</MANDT>

<DESCRP>Current Open Deliveries</DESCRP>

<ZPTDAT>2008-12-19</ZPTDAT>

<ZHTUSOR> 527</ZHTUSOR>

<ZHTUSIT> 3753</ZHTUSIT>

<ZHTUSQT> 43973</ZHTUSQT>

<ZHTUSNT>1623976.22</ZHTUSNT>

</item></OUTPUT></Workbook></asx:values></asx:abap>

thank you.

suresh.

Former Member
0 Kudos

Dear,

Define one internal table with a string.

Fill the above file into an internal table itab.

Now loop on that internal table.

do the formatting depends on the Intial tags of the XML message.

Example:

LOOP AT itab.
     IF itab-line+1( 6 ) = ZPTDAT.
             do some thing.....
     ENDIF.
ENDLOOP.

Thanks and Regards,