Skip to Content
avatar image
Former Member

XML element attributes in program

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Apr 08, 2011 at 02:35 PM

    did you solve this?

    I need to do the same thing.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 09, 2011 at 09: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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 10, 2011 at 08: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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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