09-02-2008 9:23 AM
I am using following FMs to create XML document from internal table
CALL FUNCTION 'SDIXML_DATA_TO_DOM'
CALL FUNCTION 'SDIXML_DOM_TO_XML'
My internal table has field 'AMT' and generated XML file has following line
<AMT>1000</AMT>
But I want this line to be generated as <AMT Ccy = 'USD'>1000</AMT>
I tried to use set_attribute method of element but not able to get this.I should be missing somethig as I am new to this XML.
Can anyone please advsie how I can get this?
Thanks for your help.
Srinivas
04-08-2011 3:35 PM
04-09-2011 10:42 AM
Hi
Try using normal ABAP on internal table.
Loop through the internal table and replace all occurrences of "<AMT>" with "<AMT Ccy = 'USD'>" in the work area and modify internal table from work area.
For more information check keyword REPLACE in F1 help.
Regards,
Rupesh
04-10-2011 9:39 PM
Hello Srinivas
Below you see sample coding that I use on SAP-PI to map attributes into the XML stream (INVOIC IDoc)::
NOTE: mo_document is of TYPE REF TO if_ixml_document (which is exported as DATA_AS_DOM by fm SDIXML_DATA_TO_DOM).
METHOD MAP_SD_DOC_CAT_AND_BILL_TYPE.
* define local data
DATA: ld_billingdoc TYPE bapivbrkout-billingdoc,
ld_billing_type type bapivbrkout-bill_type,
ld_sd_doc_category TYPE vbtyp,
ld_edi_qualifier TYPE string.
" Location code mapping only for outbound invoices, i.e.
" invoices sent by subsidiary to its customers
CHECK ( is_outbound_invoic( ) = abap_true ).
CALL METHOD zcl_edi_idoc_invoic_services=>get_billingdoc_detail
EXPORTING
param = mif_param
* id_idocnumber =
id_rfc_destination = md_rfcdest
IMPORTING
ed_billingdoc = ld_billingdoc
ed_billing_type = ld_billing_type
ed_sd_doc_category = ld_sd_doc_category
ed_edi_qualifier = ld_edi_qualifier.
* NOTE: We add the SD document category and the EDI qualifier
* as attributes to E1EDK01/BELNR.
** <E1EDK01 SEGMENT="1">
** <CURCY>EUR</CURCY>
** <HWAER>EUR</HWAER>
** <WKURS>1.00000</WKURS>
** <ZTERM>T60F</ZTERM>
** <EIGENUINR>nnn</EIGENUINR>
** <BSART>INVO</BSART>
** <BELNR SD_DOC_CATEGORY="O" EDI_QUALIFIER="381" BILL_TYPE="ZOII">
** 1010010911
** </BELNR>
** <NTGEW>97.662</NTGEW>
** <BRGEW>127.239</BRGEW>
** <GEWEI>KGM</GEWEI>
** <FKART_RL>LR</FKART_RL>
** <RECIPNT_NO>0000823305</RECIPNT_NO>
** <FKTYP>L</FKTYP>
** </E1EDK01>
DATA: ld_name TYPE string,
ld_value TYPE string,
ld_rc TYPE i,
lo_node TYPE REF TO if_ixml_node,
lo_node_child TYPE REF TO if_ixml_node,
lo_clone TYPE REF TO if_ixml_node,
lo_children TYPE REF TO if_ixml_node_list,
lo_element TYPE REF TO if_ixml_element,
lo_attribute TYPE REF TO if_ixml_attribute,
lo_filter TYPE REF TO if_ixml_node_filter,
lo_iter TYPE REF TO if_ixml_node_iterator,
lo_doc TYPE REF TO if_ixml_document.
* Filter for nodes of segment E1EDK01
lo_filter = mo_document->create_filter_name( name = 'E1EDK01' ).
CALL METHOD mo_document->create_iterator_filtered
EXPORTING
* depth = 0
filter = lo_filter
RECEIVING
rval = lo_iter.
DO.
lo_node = lo_iter->get_next( ).
EXIT.
ENDDO.
* NODE: First (and single) parent node is the entire E1EDK01 segment
lo_children = lo_node->get_children( ).
lo_filter = mo_document->create_filter_name( name = 'BELNR' ).
lo_iter = lo_children->create_iterator_filtered( lo_filter ).
* NOTE: We should have a single child node => BELNR
DO.
lo_node = lo_iter->get_next( ).
EXIT.
ENDDO.
CHECK ( lo_node IS BOUND ).
ld_name = lo_node->get_name( ).
ld_value = lo_node->get_value( ).
LOG-POINT ID zedi
SUBKEY mc_subkey_runtime
FIELDS syst-index ld_name ld_value.
* Add attribute SD_DOC_CATEGORY and EDI_QUALIFIER to element BELNR
lo_element ?= lo_node.
ld_name = 'SD_DOC_CATEGORY'.
ld_value = ld_sd_doc_category.
CALL METHOD lo_element->set_attribute
EXPORTING
name = ld_name
value = ld_value
RECEIVING
rval = ld_rc.
ld_name = 'EDI_QUALIFIER'.
ld_value = ld_edi_qualifier.
CALL METHOD lo_element->set_attribute
EXPORTING
name = ld_name
value = ld_value
RECEIVING
rval = ld_rc.
ld_name = 'BILL_TYPE'.
ld_value = ld_billing_type.
CALL METHOD lo_element->set_attribute
EXPORTING
name = ld_name
value = ld_value
RECEIVING
rval = ld_rc.
ENDMETHOD.
Regards
Uwe
08-03-2011 7:26 AM
Hi,
I need to do the same thing.
I am using Call transformation ID.
But ID XSLT can take only element.
Please suggest an xslt which can take attribute.
Thank you.
Sanchari