Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member206575
Participant

Okay, the title may be confusing. It is possible to create an XML string from (inside) a called function module.

Usually this is done to keep a log of function modules that are called through webservices (done with XML).

The assumption is then that the generated XML string is stored in a table, with the name of the function module (and perhaps more info like a timestamp).

The transformation of the Function to an XML string can be done as follows:

Assuming the function module has two parameters PARA1 and a table PARA2_RANGE.

Within the function you’ll then need to create a bit of code to transform the input parameters to XML format. This can be done like:

It is important that the parameters are copied with exactly the same name.

    call transformation id source  para1                = para1
                                                       para2_range      = para2_range
                                result xml      xmlstring.                                “XMLSTRING is of type STRING

If this XML string is then stored in a table (with the name of the Function), then it can be used to call the function module again.

That way you can check if the XML was correct and the values that were passed were okay.

It is possible to do this dynamically. How this can be done can be deducted from the example code below:

*--------------------------------------------------------------------*
* Call the function again with parameters
*--------------------------------------------------------------------*
* To call the Function module again you'll need to:
* 1. Get the import parameters of the function (read the interface)
* 2. Build the internal table for the Import parameters + Values
* 3. Read the XML and store the result in the internal table
* 4. Map the  parameters from the log to the parameters of the
*    function module that will be called again
* 5. Call the function module
*--------------------------------------------------------------------*
TYPE-POOLS: abap.
DATA: rf_root               TYPE REF TO cx_root.
DATA: st_interface          TYPE rsfbintfv.
DATA: st_import             TYPE rsfbpara.
DATA: ta_tab_logged         TYPE abap_trans_resbind_tab.
DATA: st_tab_logged         TYPE abap_trans_resbind.
DATA: ta_tab_call           TYPE abap_func_parmbind_tab.
DATA: ta_tab_unsorted       TYPE STANDARD TABLE OF abap_func_parmbind.
DATA: st_tab_call           TYPE abap_func_parmbind.
DATA: rf_data               TYPE REF TO data.
FIELD-SYMBOLS: <data_ref>   TYPE REF TO data.
FIELD-SYMBOLS: <tab_logged> TYPE abap_trans_resbind.
* 1. Get the import parameters of the function
CALL METHOD cl_fb_function_utility=>meth_get_interface
  EXPORTING
    im_name             = lp_function
  IMPORTING
    ex_interface        = st_interface
  EXCEPTIONS
    error_occured       = 1
    object_not_existing = 2
    OTHERS              = 3.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  EXIT.
ENDIF.
* 2. Build the internal table for the Import parameters + Values
CLEAR: ta_tab_logged.
LOOP AT st_interface-import INTO st_import.
  APPEND INITIAL LINE TO ta_tab_logged ASSIGNING <tab_logged>.
  <tab_logged>-name  = st_import-parameter.
  TRY.
      CREATE DATA: rf_data TYPE (st_import-structure).
      ASSIGN: rf_data TO <data_ref>.
    CATCH cx_root INTO rf_root.
      lp_msg = rf_root->get_text( ).
  ENDTRY.
  <tab_logged>-value ?= <data_ref>.
ENDLOOP.
* 3. Read the XML and store the result in the internal table
CALL TRANSFORMATION id SOURCE XML ls_log-xml
                           RESULT (ta_tab_logged).
* 4. Now map the mapped parameters from the log to the export
*    parameters of the function module that will be called again
CLEAR: ta_tab_call.
LOOP AT ta_tab_logged INTO st_tab_logged.
  st_tab_call-name  = st_tab_logged-name.
  st_tab_call-kind  = abap_func_exporting.
  st_tab_call-value = st_tab_logged-value.
  APPEND st_tab_call TO ta_tab_unsorted.
ENDLOOP.
ta_tab_call[] = ta_tab_unsorted[].
* 5. Call the function module
TRY.
    CALL FUNCTION lp_function
      PARAMETER-TABLE
        ta_tab_call.
  CATCH cx_root INTO rf_root.
    lp_msg = rf_root->get_text( ).
ENDTRY.

That should work...

1 Comment