Fill Function Parameters From an XM..

download Fill Function Parameters From an XM..

of 4

Transcript of Fill Function Parameters From an XM..

  • 8/11/2019 Fill Function Parameters From an XM..

    1/4

    Getting Started Newsletters Store

    Products Services & Support About SCN Downloads

    Industries Training & Education Partnership Developer Center

    Lines of Business University Alliances Events & Webinars Innovation

    Log On Join UsHi, Guest Search the Community

    Activity Communications Actions

    Browse

    0 Tweet 1

    created by Edwin Vleeshouwerson Jun 17, 2013 4:51 PM, last modified by Edwin Vleeshouwerson Jun 18, 2013 7:57 AM

    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 youll then need to create a bit of code to transform th e input parameters to XML format.

    This can be done like:

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

    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:

    Dynamically fill Function parameters froman XML document

    Share 0Like

    01. call transformation id source para1 = para1

    02. para2_range = para2_range

    03. result xml xmlstring. XMLSTRING is of type STRING

    01. *--------------------------------------------------------------------*

    Version 2

    https://twitter.com/intent/tweet?hashtags=scn&original_referer=http%3A%2F%2Fscn.sap.com%2Fdocs%2FDOC-42984&text=Dynamically%20fill%20Function%20parameters%20from%20an%20XML%20document&tw_p=tweetbutton&url=http%3A%2F%2Fscn.sap.com%2Fdocs%2FDOC-42984&via=SAPCommNethttp://scn.sap.com/community/uachttp://scn.sap.com/community/downloadshttp://scn.sap.com/activityhttp://scn.sap.com/communicationshttp://scn.sap.com/welcomehttp://twitter.com/search?q=http%3A%2F%2Fscn.sap.com%2Fdocs%2FDOC-42984https://twitter.com/intent/tweet?hashtags=scn&original_referer=http%3A%2F%2Fscn.sap.com%2Fdocs%2FDOC-42984&text=Dynamically%20fill%20Function%20parameters%20from%20an%20XML%20document&tw_p=tweetbutton&url=http%3A%2F%2Fscn.sap.com%2Fdocs%2FDOC-42984&via=SAPCommNethttp://scn.sap.com/contenthttp://scn.sap.com/actionshttp://scn.sap.com/communicationshttp://scn.sap.com/activityhttp://scn.sap.com/login.jspahttp://scn.sap.com/docs/login.jspahttp://scn.sap.com/community/uachttp://scn.sap.com/community/developer-centerhttp://scn.sap.com/community/downloadshttp://scn.sap.com/welcomehttp://www.sapstore.com/http://scn.sap.com/community/newslettershttp://scn.sap.com/community/getting-started
  • 8/11/2019 Fill Function Parameters From an XM..

    2/4

    02. * Call the function again with parameters

    03. *--------------------------------------------------------------------*

    04. * To call the Function module again you'll need to:

    05. * 1. Get the import parameters of the function (read the interface)

    06. * 2. Build the internal table for the Import parameters + Values

    07. * 3. Read the XML and store the result in the internal table

    08. * 4. Map the parameters from the log to the parameters of the

    09. * function module that will be called again

    10. * 5. Call the function module

    11. *--------------------------------------------------------------------*

    12. TYPE-POOLS: abap.

    13. DATA: rf_root TYPE REF TO cx_root.

    14. DATA: st_interface TYPE rsfbintfv.

    15. DATA: st_import TYPE rsfbpara.

    16. DATA: ta_tab_logged TYPE abap_trans_resbind_tab.

    17. DATA: st_tab_logged TYPE abap_trans_resbind.

    18. DATA: ta_tab_call TYPE abap_func_parmbind_tab.

    19. DATA: ta_tab_unsorted TYPE STANDARD TABLE OF abap_func_parmbind.

    20. DATA: st_tab_call TYPE abap_func_parmbind.

    21. DATA: rf_data TYPE REF TO data.

    22. FIELD-SYMBOLS: TYPE REF TO data.

    23. FIELD-SYMBOLS: TYPE abap_trans_resbind.

    24. * 1. Get the import parameters of the function

    25. CALL METHOD cl_fb_function_utility=>meth_get_interface

    26. EXPORTING

    27. im_name = lp_function

    28. IMPORTING

    29. ex_interface = st_interface

    30. EXCEPTIONS

    31. error_occured = 1

    32. object_not_existing = 2

    33. OTHERS = 3.

    34. IF sy-subrc 0.35. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

    36. WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    37. EXIT.

    38. ENDIF.

    39. * 2. Build the internal table for the Import parameters + Values

    40. CLEAR: ta_tab_logged.

    41. LOOP AT st_interface-import INTO st_import.

    42. APPEND INITIAL LINE TO ta_tab_logged ASSIGNING .

    43. -name = st_import-parameter.

    44. TRY.

    45. CREATE DATA: rf_data TYPE (st_import-structure).

    46. ASSIGN: rf_data TO .47. CATCH cx_root INTO rf_root.

  • 8/11/2019 Fill Function Parameters From an XM..

    3/4

    Average User Rating

    (1 rating)

    0 Tweet 1

    That should work...

    562 Views Topics: abapTags: interface, xml, parameters, function

    48. lp_msg = rf_root->get_text( ).

    49. ENDTRY.

    50. -value ?= .

    51. ENDLOOP.

    52. * 3. Read the XML and store the result in the internal table

    53. CALL TRANSFORMATION id SOURCE XML ls_log-xml

    54. RESULT (ta_tab_logged).

    55. * 4. Now map the mapped parameters from the log to the export

    56. * parameters of the function module that will be called again

    57. CLEAR: ta_tab_call.

    58. LOOP AT ta_tab_logged INTO st_tab_logged.

    59. st_tab_call-name = st_tab_logged-name.

    60. st_tab_call-kind = abap_func_exporting.

    61. st_tab_call-value = st_tab_logged-value.

    62. APPEND st_tab_call TO ta_tab_unsorted.

    63. ENDLOOP.

    64. ta_tab_call[] = ta_tab_unsorted[].

    65. * 5. Call the function module

    66. TRY.

    67. CALL FUNCTION lp_function

    68. PARAMETER-TABLE

    69. ta_tab_call.

    70. CATCH cx_root INTO rf_root.

    71. lp_msg = rf_root->get_text( ).

    72. ENDTRY.

    Share 0Like

    1Comment

    http://twitter.com/search?q=http%3A%2F%2Fscn.sap.com%2Fdocs%2FDOC-42984https://twitter.com/intent/tweet?hashtags=scn&original_referer=http%3A%2F%2Fscn.sap.com%2Fdocs%2FDOC-42984&text=Dynamically%20fill%20Function%20parameters%20from%20an%20XML%20document&tw_p=tweetbutton&url=http%3A%2F%2Fscn.sap.com%2Fdocs%2FDOC-42984&via=SAPCommNet
  • 8/11/2019 Fill Function Parameters From an XM..

    4/4