‎2007 Feb 21 10:54 AM
I am using the below code to produce an XML output, but the actaul XML file drops tags that are empty. My table definition contains all the required fields, but for some reason the empty fields are dropped.
Can anyone tell me how to keep the empty fields in the xml file or suggest another approach.
build itab in format requried for XML output
SORT itab_output by sapno.
LOOP AT itab_output INTO wa_output.
lv_output = wa_output.
sapfeed-sapno = wa_output-sapno.
AT NEW sapno.
MOVE-CORRESPONDING lv_output TO lv_staff.
INSERT lv_staff INTO TABLE it_staff.
INSERT LINES OF it_staff INTO TABLE sapfeed-personal.
CLEAR it_staff[].
ENDAT.
Dont collect work record when emp only is selected
IF r_empl <> 'X'.
MOVE-CORRESPONDING wa_output TO lv_work.
INSERT lv_work INTO TABLE it_work.
INSERT LINES OF it_work INTO TABLE sapfeed-workdetail.
CLEAR: it_work[].
ENDIF.
AT END OF sapno.
APPEND sapfeed.
CLEAR: sapfeed.
ENDAT.
ENDLOOP.
CLASS CL_IXML DEFINITION LOAD.
G_IXML = CL_IXML=>CREATE( ).
CHECK NOT G_IXML IS INITIAL.
M_DOCUMENT = G_IXML->CREATE_DOCUMENT( ).
CHECK NOT M_DOCUMENT IS INITIAL.
WRITE: / 'Converting DATA TO DOM 1:'.
CALL FUNCTION 'SDIXML_DATA_TO_DOM'
EXPORTING
NAME = 'SAPFEED'
DATAOBJECT = SAPFEED[]
IMPORTING
DATA_AS_DOM = L_DOM
CHANGING
DOCUMENT = M_DOCUMENT
EXCEPTIONS
ILLEGAL_NAME = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
WRITE: 'Err =', SY-SUBRC.
ENDIF.
CHECK NOT L_DOM IS INITIAL.
W_RC = M_DOCUMENT->APPEND_CHILD( NEW_CHILD = L_DOM ).
IF W_RC IS NOT INITIAL.
WRITE: 'Err =', W_RC.
ENDIF.
CALL FUNCTION 'SDIXML_DOM_TO_XML'
EXPORTING
DOCUMENT = M_DOCUMENT
IMPORTING
XML_AS_STRING = W_STRING
SIZE = W_SIZE
TABLES
XML_AS_TABLE = IT_XML
EXCEPTIONS
NO_DOCUMENT = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
WRITE: 'Err =', SY-SUBRC.
ENDIF.
LOOP AT IT_XML INTO XML_TAB-D.
APPEND XML_TAB.
ENDLOOP.
Download file
IF r_srvr = 'X'.
NEED TO ADD XML_TAB TO server download
PERFORM SERVER_DOWNLOAD.
ELSE.
PERFORM GUI_DOWNLOAD using gv_resize
XML_TAB.
ENDIF.
‎2007 Feb 21 11:01 AM
Hi,
Check the following link:
http://sap-img.com/abap/sample-xml-source-code-for-sap.htm
it contains sample XML Source Code For SAP .
Hope this helps.
Reward if helpful.
Regards,
Sipra
‎2007 Feb 21 11:29 AM
Have you tried SAP JCO ? it is a conveninet method to convert into XML file and once the settings are done, it is very simpler and easy method. If intrested, please check the following link to convert the files into XML using Jco
http://help.sap.com/saphelp_nw04/helpdata/en/6f/1bd5c6a85b11d6b28500508b5d5211/content.htm
http://www.erpgenie.com/faq/jco.htm
https://media.sdn.sap.com/javadocs/NW04/SPS15/jc/com/sap/mw/jco/JCO.html
/people/anilkumar.vippagunta2/blog/2007/02/06/dynamic-jco-creation