Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Dynamic element specification in call transformation

0 Likes
2,809

Hello, I'm using call transformation to convert xml to abap structure.

call transformation demo_id_upper_lower "id 
parameters mode = 'UP' 
source xml asxml_str 
result paymentrequest = abap_out. 

This works as expected and the data is mapped to abap structure successfully. 'paymentrequest' being the root tag here. Is there a way to specify a variable containing the tag name instead of the tag directly in the result.

Eg. data(my_var) = 'paymentrequest'. 
call transformation demo_id_upper_lower "id 
parameters mode = 'UP' 
source xml asxml_str 
result my_var = abap_out. 

In this case there's no exception as such but then there's no conversion(I think it tries to find 'my_var'). I'm trying to encapsulate the conversion in a method/fm, hence the requirement.

Note: I have also tried assigning the element name to a field symbol. But that too didn't work.

1 ACCEPTED SOLUTION
Read only

DoanManhQuynh
Active Contributor
1,712

Lets try this:

DATA MAPP TYPE ABAP_TRANS_RESBIND_TAB.

MAPP = VALUE #( ( NAME = 'PAYMENTREQUEST' VALUE = REF #( abap_out ) ) ).

CALL TRANSFORMATION ID SOURCE XML l_xml
 RESULT (MAPP) .

Hello, I'm using call transformation to convert xml to abap structure.

call transformation demo_id_upper_lower "id 
parameters mode = 'UP' 
source xml asxml_str 
result paymentrequest = abap_out. 

This works as expected and the data is mapped to abap structure successfully. 'paymentrequest' being the root tag here. Is there a way to specify a variable containing the tag name instead of the tag directly in the result.

Eg. data(my_var) = 'paymentrequest'. 
call transformation demo_id_upper_lower "id 
parameters mode = 'UP' 
source xml asxml_str 
result my_var = abap_out. 

In this case there's no exception as such but then there's no conversion(I think it tries to find 'my_var'). I'm trying to encapsulate the conversion in a method/fm, hence the requirement.

Note: I have also tried assigning the element name to a field symbol. But that too didn't work.

2 REPLIES 2
Read only

DoanManhQuynh
Active Contributor
1,713

Lets try this:

DATA MAPP TYPE ABAP_TRANS_RESBIND_TAB.

MAPP = VALUE #( ( NAME = 'PAYMENTREQUEST' VALUE = REF #( abap_out ) ) ).

CALL TRANSFORMATION ID SOURCE XML l_xml
 RESULT (MAPP) .

Read only

0 Likes
1,712

Excellent. Thanks a lot. Exactly what I was looking for.

data(result_tab) = value abap_trans_resbind_tab( ( name = root value = ref #( abap_out ) ) ).

        call transformation demo_id_upper_lower "id
        parameters mode = 'UP'
        source xml asxml_str
        result (result_tab).

        if result_tab is not initial.
          read table result_tab into data(result_wa) index 1.
          if sy-subrc = 0.
            assign result_wa-value->* to field-symbol(<abap_out>).
            if <abap_out> is assigned.
              abap_out = <abap_out>.
            endif.
          endif.
        endif.