Generate XML from BSP

By Manasi S Balagere

STEP1: have a controller in the BSP application ending with .xml (for eg: export.xml)

STEP2: create a controller class for the controller(zcl_c_xml_export)

STEP3: In the do_request method of the of the controller class, pass the internal table to be converted to the xml file via a function module ZI057678_TEST_XML; which will return the xml string.

Now, call the “write” method of the cl_bsp_controller and pass the xml string 

STEP3.1: The function module will have the following code:

FUNCTION zi057678_test_xml.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     REFERENCE(IT_ITAB) TYPE  STANDARD TABLE
*"  EXPORTING
*"     REFERENCE(EV_OUTPUT) TYPE  STRING
*"----------------------------------------------------------------------

  
DATA: lt_column             TYPE TABLE OF   dfies,
        ls_column             
LIKE LINE  OF   lt_column,
        ls_js                 
TYPE            string,
        lr_export_table_ref   
TYPE REF TO     data,
        lr_ixml               
TYPE REF TO     if_ixml,
        lr_stream_factory     
TYPE REF TO     if_ixml_stream_factory,
        lr_encoding           
TYPE REF TO     if_ixml_encoding,
        lr_resstream          
TYPE REF TO     if_ixml_ostream,
        lr_doc                
TYPE REF TO     if_ixml_document,
        lr_root_node          
TYPE REF TO     if_ixml_element.


  
FIELD-SYMBOLS: <fs>   LIKE it_itab,
                 <tab>  
TYPE table.

  
CONSTANTS:   c_encoding     TYPE string VALUE 'UTF-8'.

  
"create new data object and copy it_itab into it
  
CREATE DATA lr_export_table_ref LIKE it_itab.

  
ASSIGN lr_export_table_ref->* TO <fs>.

  <fs> = it_itab.

  
"create an instance of the Ixml Processor
  lr_ixml = cl_ixml=>
create( ).

  
"create xml docu
  lr_doc = lr_ixml->create_document( ).

  
"create the Stream Factory
  lr_stream_factory = lr_ixml->create_stream_factory( ).

  
"create an Endcoding and Byte Order
  lr_encoding = lr_ixml->create_encoding( character_set = c_encoding
                                          byte_order    = 
0 ).

  
"set encoding for docu
  lr_doc->set_encoding( 
encoding = lr_encoding ).

  
"append root node
  lr_root_node = lr_doc->create_element( name = 
'table' ).
  lr_doc->append_child( new_child = lr_root_node ).

  
"create the output stream with a pointer to our binary string  

   lr_resstream = lr_stream_factory->create_ostream_cstring( ev_output ).

  
"get a pointer to our data table
  
ASSIGN lr_export_table_ref->* TO <tab>.

  
"set the Encoding into a stream
  lr_resstream->set_encoding( 
encoding = lr_encoding ).

  
"call Transformation using the simple XSLT id_indent
  
CALL TRANSFORMATION id_indent
    SOURCE     itab = <tab>
    RESULT XML lr_resstream.

ENDFUNCTION.

STEP4: Now test the controller to see the pop up of the XML.

 

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image