Friday, March 11, 2011

Converting internal table to XML

This demo program talks about how to convert internal table into XML and download to PC and upload the same to SAP.

*&---------------------------------------------------------------------*
*& Report  ZTOXML
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZTOXML.


*-------------- DATA
DATA : t001 type 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:\vino\WD\first.xml'
TABLES
data_tab = itab.


******************************* SECOND PHASE
******************************* SECOND PHASE
******************************* SECOND PHASE

BREAK-POINT.
REFRESH t001.
CLEAR t001.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'D:\vino\WD\first.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.


1 comment: