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

Regd: Converting Data in XML file

Former Member
0 Likes
727

Hi All,

We hav a requirement to convert the data from Internal table into a XML file.

The scenario is we hav developed a program to download the data in XML format,the problem is when the file is converted inot XML format its giving erreor that

<b>The XML page cannot be displayed

End tag 'KUN' does not match the start tag 'KUNNR'. Error processing resource 'file:///C:/TEST.xml'. Line 2, Position 1712

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

The code is specified below for understanding.

****************************************************************

  • TBALES DECLARATION

*

****************************************************************

TABLES: VBAK, "Sale Order Header

VBAP, "Sale Order Item Data

VBEP, "Schedule Line Data

KNA1, "General Data in Customer Master

VBRP. "Billing Document Item Data

****************************************************************

  • TYPES DECLARATION

*

****************************************************************

TYPES : BEGIN OF TY_SOSTATUS,

KUNNR LIKE VBAK-KUNNR, "Customer Number

NAME1 LIKE KNA1-NAME1, "Customer Name

BSTNK LIKE VBAK-BSTNK, "Customer P.O.

BSTDK LIKE VBAK-BSTDK, "Customer P.O. Date

VBELN LIKE VBAK-VBELN, "Sale Order Number

ERDAT LIKE VBAK-ERDAT, "Sale Order Date

POSNR LIKE VBAP-POSNR, "Sale Order Line Item

MATNR LIKE VBAP-MATNR, "Material Number

ARKTX LIKE VBAP-ARKTX, "Material Description

KWMENG LIKE VBAP-KWMENG, "Sale Order Quantity

VRKME LIKE VBAP-VRKME, "Unit of Measurement

EDATU LIKE VBEP-EDATU, "Sale Order Schedule Date

FKIMG LIKE VBRP-FKIMG, "Despatch Quantity

GBSTA LIKE VBUP-GBSTA, "Overall Sale Order Status

PNDQTY TYPE I,

END OF TY_SOSTATUS.

TYPES : BEGIN OF TEMP_DISP,

VBELN LIKE VBAK-VBELN,

AUART LIKE VBAK-AUART,

ERDAT LIKE VBAK-ERDAT,

KUNNR LIKE VBAK-KUNNR,

BSTNK LIKE VBAK-BSTNK,

BSTDK LIKE VBAK-BSTDK,

POSNR LIKE VBAP-POSNR,

MATNR LIKE VBAP-MATNR,

ARKTX LIKE VBAP-ARKTX,

KWMENG LIKE VBAP-KWMENG,

VRKME LIKE VBAP-VRKME,

END OF TEMP_DISP.

DATA: XML_OUT TYPE STRING.

****************************************************************

  • INTERNAL TABLE DECLARATION

*

****************************************************************

DATA : IT_SOSTATUS TYPE STANDARD TABLE OF TY_SOSTATUS

WITH HEADER LINE INITIAL SIZE 100 WITH DEFAULT KEY.

DATA : IT_TEMP TYPE STANDARD TABLE OF TEMP_DISP

WITH HEADER LINE INITIAL SIZE 100 WITH DEFAULT KEY.

DATA : BEGIN OF IT_XML_OUT OCCURS 0,

A(1500) TYPE C,

END OF IT_XML_OUT.

****************************************************************

  • SELECTION SCREEN DECLARATION

*

****************************************************************

SELECTION-SCREEN BEGIN OF BLOCK SOBLOCK WITH FRAME.

SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN,

S_ERDAT FOR VBAK-ERDAT,

S_AUART FOR VBAK-AUART,

S_WERKS FOR VBAP-WERKS.

SELECTION-SCREEN END OF BLOCK SOBLOCK.

****************************************************************

  • START OF SELECTION

*

****************************************************************

SELECT SVBELN SAUART SERDAT SKUNNR SBSTNK SBSTDK

LPOSNR LMATNR LARKTX LKWMENG L~VRKME FROM VBAK AS S

INNER JOIN VBAP AS L

ON SVBELN = LVBELN

INTO CORRESPONDING FIELDS OF TABLE IT_TEMP

WHERE S~AUART IN S_AUART AND

S~ERDAT IN S_ERDAT AND

L~WERKS IN S_WERKS .

CALL TRANSFORMATION (`ID`) SOURCE IT_XML_OUT = IT_TEMP[] RESULT XML XML_OUT.

CALL FUNCTION 'SOTR_SERV_STRING_TO_TABLE'

EXPORTING

TEXT = XML_OUT

  • FLAG_NO_LINE_BREAKS = 'X'

LINE_LENGTH = 65000

  • LANGU = SY-LANGU

TABLES

TEXT_TAB = IT_XML_OUT[].

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filetype = 'BIN'

filename = 'C:\TEST.xml'

TABLES

data_tab = IT_XML_OUT[].

Is there any other way to process this and download in XML format.

Help and Suggestions will be much Appreciated.

Thanks & Regds.

Ramesh.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
404

Hi ramesh,

1. itab --- > xml

xml ---> itab.

2. This program will do both.

(just copy paste in new program)

3.

REPORT abc.

*----


DATA

DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.

DATA : BEGIN OF itab OCCURS 0,

a(100) TYPE c,

END OF itab.

DATA: xml_out TYPE string .

DATA : BEGIN OF upl OCCURS 0,

f(255) TYPE c,

END OF upl.

DATA: xmlupl TYPE string .

                                                              • FIRST PHASE

                                                              • FIRST PHASE

                                                              • FIRST PHASE

*----


Fetch Data

SELECT * FROM t001 INTO TABLE t001.

*----


XML

CALL TRANSFORMATION ('ID')

SOURCE tab = t001[]

RESULT XML xml_out.

*----


Convert to TABLE

CALL FUNCTION 'HR_EFI_CONVERT_STRING_TO_TABLE'

EXPORTING

i_string = xml_out

i_tabline_length = 100

TABLES

et_table = itab.

*----


Download

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filetype = 'BIN'

filename = 'd:\xx.xml'

TABLES

data_tab = itab.

                                                              • SECOND PHASE

                                                              • SECOND PHASE

                                                              • SECOND PHASE

BREAK-POINT.

REFRESH t001.

CLEAR t001.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = 'D:\XX.XML'

filetype = 'BIN'

TABLES

data_tab = upl.

LOOP AT upl.

CONCATENATE xmlupl upl-f INTO xmlupl.

ENDLOOP.

*----


XML

CALL TRANSFORMATION ('ID')

SOURCE XML xmlupl

RESULT tab = t001[]

.

BREAK-POINT.

regards,

amit m.

2 REPLIES 2
Read only

Former Member
0 Likes
405

Hi ramesh,

1. itab --- > xml

xml ---> itab.

2. This program will do both.

(just copy paste in new program)

3.

REPORT abc.

*----


DATA

DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.

DATA : BEGIN OF itab OCCURS 0,

a(100) TYPE c,

END OF itab.

DATA: xml_out TYPE string .

DATA : BEGIN OF upl OCCURS 0,

f(255) TYPE c,

END OF upl.

DATA: xmlupl TYPE string .

                                                              • FIRST PHASE

                                                              • FIRST PHASE

                                                              • FIRST PHASE

*----


Fetch Data

SELECT * FROM t001 INTO TABLE t001.

*----


XML

CALL TRANSFORMATION ('ID')

SOURCE tab = t001[]

RESULT XML xml_out.

*----


Convert to TABLE

CALL FUNCTION 'HR_EFI_CONVERT_STRING_TO_TABLE'

EXPORTING

i_string = xml_out

i_tabline_length = 100

TABLES

et_table = itab.

*----


Download

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filetype = 'BIN'

filename = 'd:\xx.xml'

TABLES

data_tab = itab.

                                                              • SECOND PHASE

                                                              • SECOND PHASE

                                                              • SECOND PHASE

BREAK-POINT.

REFRESH t001.

CLEAR t001.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = 'D:\XX.XML'

filetype = 'BIN'

TABLES

data_tab = upl.

LOOP AT upl.

CONCATENATE xmlupl upl-f INTO xmlupl.

ENDLOOP.

*----


XML

CALL TRANSFORMATION ('ID')

SOURCE XML xmlupl

RESULT tab = t001[]

.

BREAK-POINT.

regards,

amit m.

Read only

athavanraja
Active Contributor
0 Likes
404

the error message is because the function to split the string into table has split the xml element <KUNNR> into two lines

<KUN

NR>

to make sure you dont get into this kind of problem either convert the string to xstring and then convert it to a table and download or

use the code sample explained in this thread

Regards

Raja

Reward points to helpful answers by choosing the appropriate radiobuttons