2009 May 28 6:15 PM
Hi
Can anyone help me how to get the field text instead of the field names in the XML tags.
Ex: Instead of <MATNR> display the tag as <Material Number>
example : landk in t005 table is vehicle country key.
in xml file it shud show as <vehicle country key>table data</vehicle country key>.
land1 ---itz description is country key.
so we shud get <country key>table data</country key> in xml file.
thanks.
Hi
Can anyone help me how to get the field text instead of the field names in the XML tags.
Ex: Instead of <MATNR> display the tag as <Material Number>
example : landk in t005 table is vehicle country key.
in xml file it shud show as <vehicle country key>table data</vehicle country key>.
land1 ---itz description is country key.
so we shud get <country key>table data</country key> in xml file.
thanks.
2009 May 28 7:25 PM
Sample Code
REPORT ydw_rdprmt NO STANDARD PAGE HEADING.
PARAMETER: zfname TYPE rlgrap-filename.
TYPES: BEGIN OF lt_yrdprmt,
werks TYPE werks,
kunnr TYPE kunnr,
prmtcd TYPE zprmtcd,
END OF lt_yrdprmt.
DATA: wa_yrdprmt TYPE lt_yrdprmt.
DATA: it_yrdprmt TYPE TABLE OF lt_yrdprmt.
DATA : BEGIN OF itab OCCURS 0 ,
txt(800),
END OF itab.
DATA: filename LIKE zfname.
START-OF-SELECTION.
SELECT werks
kunnr
prmtcd
FROM yrdprmt
INTO TABLE it_yrdprmt
WHERE prmtcd <> ''.
DELETE ADJACENT DUPLICATES FROM it_yrdprmt.
PERFORM create_xml.
FORM create_xml .
itab-txt = '<YRDPRMT>' .
APPEND itab.
LOOP AT it_yrdprmt INTO wa_yrdprmt.
itab-txt = '<IT_YRDPRMT>'.
APPEND itab.
CONCATENATE '<' 'WERKS>' wa_yrdprmt-werks '</'
'WERKS>' INTO itab-txt.
APPEND itab .
CONCATENATE '<' 'KUNNR>' wa_yrdprmt-kunnr '</'
'KUNNR>' INTO itab-txt.
APPEND itab .
CONCATENATE '<' 'PRMTCD>' wa_yrdprmt-prmtcd '</'
'PRMTCD>' INTO itab-txt.
APPEND itab .
itab-txt = '</IT_YRDPRMT>'.
APPEND itab.
CLEAR wa_yrdprmt.
ENDLOOP.
itab-txt = '</YRDPRMT>' .
APPEND itab.
PERFORM write_to_file.
ENDFORM. " CREATE_XML
FORM write_to_file .
DATA : txt(800).
CONCATENATE zfname sy-datum sy-uzeit '.XML' INTO filename .
OPEN DATASET filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc EQ 0.
LOOP AT itab.
MOVE itab-txt TO txt.
CONDENSE txt.
TRANSFER txt TO filename.
ENDLOOP.
WRITE : / 'FILE CREATED' , filename.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
WRITE: 'No Path Found'.
ENDIF .
CLOSE DATASET filename.
ENDFORM. " WRITE_TO_FILE
Edited by: Santosh Reddy on May 28, 2009 11:55 PM
Edited by: Santosh Reddy on May 28, 2009 11:58 PM
2009 Jun 01 7:35 PM
Thanks Santhosh for the sample code.
Wht if we are getting all the fields from the table and if it is for many tables...
ex : need tht for all the fileds from mara, t005, etc...
can u give me the sample code...
So far i have coded..
1. getting all the fields from a table to an internal table
2. converting that to xml files using function modules
a. SDIXML_DATA_TO_DOM
b. SDIXML_DOM_TO_XML.
this i am doing for couple of tables...
output for the xml file is
eg material number in MARA table..
<matnr>tabledata</matnr>.
i need the output as
<Material Number>tabledata</Material Number>
We will be only giving the tags with the field text as it is on SAP. No underscore or hypens etc will be replaced for spaces in the tags.
2009 Jun 01 9:27 PM
some coding to understand:
DATA: l_ixml TYPE REF TO if_ixml,
l_streamfactory TYPE REF TO if_ixml_stream_factory,
l_ostream TYPE REF TO if_ixml_ostream,
l_renderer TYPE REF TO if_ixml_renderer,
l_document TYPE REF TO if_ixml_document,
l_encoding TYPE REF TO if_ixml_encoding.
DATA: l_element_root TYPE REF TO if_ixml_element,
l_element_job TYPE REF TO if_ixml_element,
l_element_name TYPE REF TO if_ixml_element,
l_element_rout TYPE REF TO if_ixml_element,
l_element_conf TYPE REF TO if_ixml_element,
l_element_cova TYPE REF TO if_ixml_element,
l_value TYPE string,
l_xml_table TYPE TABLE OF xml_line,
l_xml_size TYPE i,
l_rc TYPE i.
loop at itab.
at first.
l_ixml = cl_ixml=>create( ).
l_document = l_ixml->create_document( ).
l_encoding = l_ixml->create_encoding( byte_order = if_ixml_encoding=>co_little_endian character_set = 'utf-8' ).
l_document->set_encoding( l_encoding ).
l_element_root = l_document->create_simple_element( name = 'FusionJob' parent = l_document ).
l_element_job = l_document->create_simple_element( name = 'Job' parent = l_element_root ).
l_value = HEADER_TABLE-aufnr+5(7).
l_element_name = l_document->create_simple_element( name = 'Name' value = l_value parent = l_element_job ).
endat.
l_element_rout = l_document->create_simple_element( name = 'ERPRoutePoint' parent = l_element_job ).
l_value = itab-step.
l_element_conf = l_document->create_simple_element( name = 'ERPRoutPointName' value = l_value parent = l_element_rout ).
l_value = itab-conf.
l_element_cova = l_document->create_simple_element( name = 'ERPRoutPointValue' value = l_value parent = l_element_rout ).
endloop.
l_streamfactory = l_ixml->create_stream_factory( ).
l_ostream = l_streamfactory->create_ostream_itable( table = l_xml_table ).
l_renderer = l_ixml->create_renderer( ostream = l_ostream
document = l_document ).
l_rc = l_renderer->render( ).
l_xml_size = l_ostream->get_num_written_raw( ).
concatenate pfad 'SAP_' HEADER_TABLE-aufnr '.xml' into name.
CALL METHOD cl_gui_frontend_services=>gui_download
2009 Jun 01 9:54 PM
result after downloading:
<FusionJob>
<Job>
<Name>1006427</Name>
<ERPRoutePoint>
<ERPRoutPointName>1</ERPRoutPointName>
<ERPRoutPointValue>0000079890</ERPRoutPointValue>
</ERPRoutePoint>Greetz Tony
2009 Jun 10 9:39 AM
2009 Jun 10 1:49 PM
2009 Jul 31 9:54 AM
Hi
would it be possible for to send me sample code as my requirement is similar, i have an internal table with a list of customers and would like to create an xml output. what i am looking for isthe parameters that need to be be passed to the functionm modules
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |