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

Internal table to XML data in Application Server

Former Member
0 Likes
2,206

Dear Experts,

I have converted the internal table data into XML format using CL_XML_DOCUMENT class and CREATE_WITH_DATA - method. Here I have to upload this XML converted file in the given application server path. Kindly suggest me some methods or class, other options to do this.

I need to upload the XML file in to specified application server path. Kindly give some ideas.

Regards,

Sakthi

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
1,024

I guess you want to transfer XML document type ref to IF_IXML_DOCUMENT (which is instantiated with this method and stored in attribute M_DOCUMENT ) to a file on application server. Is that right?

If so please refer below program you should get the idea


DATA: gr_ixml TYPE REF TO if_ixml,
      gr_ixml_doc TYPE REF TO if_ixml_document.

gr_ixml = cl_ixml=>create( ).
"here you have the same kind of XML document
"as the one created with method CREATE_WITH_DATA
gr_ixml_doc = gr_ixml->create_document( ).  

DATA  gr_ixml_element TYPE REF TO if_ixml_element.

CALL METHOD gr_ixml_doc->create_element
  EXPORTING
    name = 'JOBS'
  RECEIVING
    rval = gr_ixml_element.

CALL METHOD gr_ixml_doc->append_child
  EXPORTING
    new_child = gr_ixml_element.

CALL METHOD gr_ixml_element->set_attribute
  EXPORTING
    name  = 'OBJID'
    value = '566677890'.

"serialization
DATA g_encoding_type TYPE string.
DATA g_stream_factory TYPE REF TO if_ixml_stream_factory.
DATA gr_encoding TYPE REF TO if_ixml_encoding.

g_stream_factory = gr_ixml->create_stream_factory( ).
gr_encoding = gr_ixml->create_encoding( byte_order = 0
                                       character_set = 'UTF-8' ).

DATA b_xml TYPE xstring.
DATA gr_ostream TYPE REF TO if_ixml_ostream.
gr_ostream = g_stream_factory->create_ostream_xstring( b_xml ).

CALL METHOD gr_ostream->set_encoding
  EXPORTING
    encoding = gr_encoding.

CALL METHOD gr_ixml_doc->render
  EXPORTING
    ostream = gr_ostream
    recursive = 'X'.

DATA g_resize TYPE i.
g_resize = gr_ostream->get_num_written_raw( ).

data ex_tab type table of x255.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
  EXPORTING
    buffer                = b_xml
  tables
    binary_tab            = ex_tab.

"now open file on application server
OPEN DATASET dset FOR OUTPUT IN BINARY MODE.
 
"and transfer ex_tab to dset

Regards

Marcin

4 REPLIES 4
Read only

Former Member
0 Likes
1,024

Hi,

have a look at the link below : [;

Regards,

Ravi Aswani

Read only

MarcinPciak
Active Contributor
0 Likes
1,025

I guess you want to transfer XML document type ref to IF_IXML_DOCUMENT (which is instantiated with this method and stored in attribute M_DOCUMENT ) to a file on application server. Is that right?

If so please refer below program you should get the idea


DATA: gr_ixml TYPE REF TO if_ixml,
      gr_ixml_doc TYPE REF TO if_ixml_document.

gr_ixml = cl_ixml=>create( ).
"here you have the same kind of XML document
"as the one created with method CREATE_WITH_DATA
gr_ixml_doc = gr_ixml->create_document( ).  

DATA  gr_ixml_element TYPE REF TO if_ixml_element.

CALL METHOD gr_ixml_doc->create_element
  EXPORTING
    name = 'JOBS'
  RECEIVING
    rval = gr_ixml_element.

CALL METHOD gr_ixml_doc->append_child
  EXPORTING
    new_child = gr_ixml_element.

CALL METHOD gr_ixml_element->set_attribute
  EXPORTING
    name  = 'OBJID'
    value = '566677890'.

"serialization
DATA g_encoding_type TYPE string.
DATA g_stream_factory TYPE REF TO if_ixml_stream_factory.
DATA gr_encoding TYPE REF TO if_ixml_encoding.

g_stream_factory = gr_ixml->create_stream_factory( ).
gr_encoding = gr_ixml->create_encoding( byte_order = 0
                                       character_set = 'UTF-8' ).

DATA b_xml TYPE xstring.
DATA gr_ostream TYPE REF TO if_ixml_ostream.
gr_ostream = g_stream_factory->create_ostream_xstring( b_xml ).

CALL METHOD gr_ostream->set_encoding
  EXPORTING
    encoding = gr_encoding.

CALL METHOD gr_ixml_doc->render
  EXPORTING
    ostream = gr_ostream
    recursive = 'X'.

DATA g_resize TYPE i.
g_resize = gr_ostream->get_num_written_raw( ).

data ex_tab type table of x255.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
  EXPORTING
    buffer                = b_xml
  tables
    binary_tab            = ex_tab.

"now open file on application server
OPEN DATASET dset FOR OUTPUT IN BINARY MODE.
 
"and transfer ex_tab to dset

Regards

Marcin

Read only

anesh_kumar
Active Participant
0 Likes
1,024

Hi

We had a similar requirement,You can use the below code

CALL FUNCTION 'SAP_CONVERT_TO_XML_FORMAT'

EXPORTING

I_XML_DOC_NAME = 'xmldocument'

IMPORTING

PE_BIN_FILESIZE = BIN_SIZE

TABLES

I_TAB_SAP_DATA = T_EXTRACT " your table name

CHANGING

I_TAB_CONVERTED_DATA = XMLTAB

EXCEPTIONS

CONVERSION_FAILED = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL METHOD CL_RSZ_WWW_DB_INTERFACE=>CONVERT_RAW_TO_CHAR

EXPORTING

I_T_IN = XMLTAB

IMPORTING

E_T_OUT = GT_ITAB[].

OPEN DATASET OUT_FILE FOR OUTPUT IN BINARY MODE.

LOOP AT GT_ITAB.

TRANSFER GT_ITAB-DATA TO OUT_FILE.

ENDLOOP.

Regards

Read only

Former Member
0 Likes
1,024

Thank you all. The problem got solved. Here is the way I have solved this problem.

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

DATA : XML_OUT TYPE STRING.

DATA : BEGIN OF ITAB1 OCCURS 0,

A(256) TYPE C,

END OF ITAB1.

CALL TRANSFORMATION ('ID')

SOURCE TAB = LT_FINAL[] "Internal table records from your requirement

RESULT XML XML_OUT. "Here in XML_OUT you will get all the converted recors

*&-- FM to change the XML data into Internal table --&*

CALL FUNCTION 'SCMS_STRING_TO_FTEXT'

EXPORTING

TEXT = XML_OUT "XML_OUT table as Input

  • IMPORTING

  • LENGTH =

TABLES

FTEXT_TAB = ITAB1. "In this internal table you will get all XML converted records

*&-- OPEN DATASET --&*

OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

LOOP AT itab1.

TRANSFER itab1-A into P_FILE.

ENDLOOP.

CLOSE DATASET P_FILE.

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

Thank you.