07-09-2018 6:21 AM
Hello Users,
While I am transferring data into XML file then we are getting <ITEM> tag by default in XML file. We didn't done any code for this tag. How we can remove this tag form the file?.
find attached Image and code. I have checked so many SCN threads for the same but i didn't get any proper solution. Please help me.
REPORT ztest_s8.
* PANTALLA SELECCION *
PARAMETERS: gk_ruta TYPE rlgrap-filename DEFAULT 'D:\file2.xml'.
* PANTALLA SELECCION *
data :it_xml_final TYPE TABLE OF blob.
TYPES :begin of analysiscatid,
AnlCat_SHead TYPE char20,
END OF analysiscatid.
TYPES : BEGIN OF analysiscode,
accountcode TYPE char15,
analysisdimensionid TYPE numc2,
name TYPE char50,
status TYPE numc1,
AnalysisCatid TYPE analysiscatid,
END OF analysiscode.
TYPES : BEGIN OF payload,
analysiscode TYPE analysiscode,
END OF payload.
TYPES : BEGIN OF sunsystemscontext,
businessunit TYPE char3,
END OF sunsystemscontext.
TYPES: BEGIN OF user ,
name TYPE char3,
END OF user.
TYPES: BEGIN OF ssc,
user TYPE user,
sunsystemscontext TYPE sunsystemscontext,
payload TYPE payload,
END OF ssc.
data : it_file type TABLE OF ssc.
Data : wa_file type ssc.
* START OF SELECTION *
START-OF-SELECTION.
PERFORM llena_accesos.
PERFORM descarga_xml.
END-OF-SELECTION.
* END OF SELECTION *
* FORM LLENA_ACCESOS *
FORM llena_accesos.
CLEAR it_file.
MOVE: 'PK1' TO wa_file-user-name,
'KEV' TO wa_file-sunsystemscontext-businessunit,
'99320042' TO wa_file-payload-analysiscode-accountcode,
'05' TO wa_file-payload-analysiscode-analysisdimensionid,
'SUNIL' TO wa_file-payload-analysiscode-name,
'1' TO wa_file-payload-analysiscode-status,
'T5_STAFFID/CRED' TO wa_file-payload-analysiscode-AnalysisCatid-AnlCat_SHead.
APPEND wa_file to it_file.
CLEAR : wa_file.
ENDFORM. "LLENA_ACCESOS
* FORM LLENA_ACCESOS *
* FORM DESCARGA_XML *
FORM descarga_xml.
DATA: l_dom TYPE REF TO if_ixml_element,
m_document TYPE REF TO if_ixml_document,
g_ixml TYPE REF TO if_ixml,
w_string TYPE xstring,
w_size TYPE i,
w_result TYPE i,
w_line TYPE string,
it_xml TYPE dcxmllines,
s_xml LIKE LINE OF it_xml,
w_rc LIKE sy-subrc.
DATA: xml TYPE dcxmllines.
DATA: rc TYPE sy-subrc,
BEGIN OF xml_tab OCCURS 0,
d LIKE LINE OF xml,
END OF xml_tab.
* 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 TRANSFORMATION ('ID')
SOURCE ssc = 'abc' "extractiondate = sy-datum
obs = it_file
RESULT XML it_xml_final.
* CALL FUNCTION 'SDIXML_DATA_TO_DOM'
* EXPORTING
* name = 'SSC'
* dataobject = it_file
* IMPORTING
* data_as_dom = l_dom
* CHANGING
* document = m_document
* EXCEPTIONS
* illegal_name = 1
* OTHERS = 2.
* IF sy-subrc = 0.
* WRITE 'Ok'.
* ELSE.
* 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 INITIAL.
* WRITE 'Ok'.
* ELSE.
* 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 'Ok'.
* ELSE.
* WRITE: 'Err =',
* sy-subrc.
* ENDIF.
* LOOP AT it_xml INTO xml_tab-d.
* APPEND xml_tab.
* ENDLOOP.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
bin_filesize = w_size
filename = gk_ruta
filetype = 'BIN'
TABLES
* data_tab = xml_tab
data_tab = it_xml_final
EXCEPTIONS
OTHERS = 10.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. "DESCARGA_XML
* FORM DESCARGA_XML *
07-09-2018 6:29 AM
When you post code, could you please take the time to remove unnecessary blank lines and certainly commented out code. As it is, it is hard to understand what you've written. Only post code that is relevant. So far as I can see, for example, m_document is totally irrelevant to your question.
Furthermore, not only are forms obsolete since 7.4, but you shouldn't be using function module WS_DOWNLOAD - it is also obsolete. Please use the appropriate method of CL_GUI_FRONTEND_SERVICES.
Finally, don't touch global variables in forms (if you must use them). Instead use parameters to pass the data around. Global variables are bad.
07-09-2018 8:27 AM
Hello Matthew,
Thanks for your reply.
We are getting <ITEM> using Transaction ID method or using above commented code.Hence, I have created above code for testing purpose only.
I have added below code to replace-function module WS_DOWNLOAD but we are getting still same results.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = file_path
filetype = 'BIN'
CHANGING
data_tab = it_xml_final
07-09-2018 8:37 AM
<item> is tag of each table line that you pass to xml and auto generated. like OBS become root node and OBS table line items become <item> node. If you dont want that tag, you have to design your own transformation template.
07-10-2018 7:06 AM
Edit: Idk what layout you want to export but I have an workaround using transformation ID to manage xml node as you want. the ideal is like this:
SELECT CARRID, CARRNAME FROM SCARR UP TO 20 ROWS INTO TABLE @DATA(IT_FILE).
LOOP AT IT_FILE INTO DATA(LS_FILE).
R_DESCR ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( LS_FILE ).
DATA(LV_NAME) = R_DESCR->COMPONENTS[ 1 ]-NAME.
DATA(OBS) = VALUE ABAP_TRANS_SRCBIND_TAB( ( NAME = 'SSC' VALUE = REF #( 'abc' ) )
( NAME = LV_NAME VALUE = REF #( LS_FILE-CARRID ) )
).
ENDLOOP.
CALL TRANSFORMATION ('ID')
SOURCE (OBS)
RESULT XML IT_XML_FINAL.
07-09-2018 10:32 AM
I wasn't giving an answer to your question - I was stating general principles of ABAP. Don't use obsolete techniques. Switching from WS_DOWNLOAD to CL_GUI_FRONTEND_SERVICES makes your code better, but it will not fix your problem. Did you really think it would?
07-10-2018 10:17 AM
Hello Matthew,
Thanks a lot.Yes, it will help in my future.