Вы находитесь на странице: 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 Us Hi, Guest Search the Community
Activity Communications Actions
Browse
0 Tweet 1
created by Edwin Vleeshouwers on Jun 17, 2013 4:51 PM, last modified by Edwin Vleeshouwers on 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 the 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 from
an XML document
Share
0 Like
01. call transformation id source para1 = para1
02. para2_range = para2_range
03. result xml xmlstring. XMLSTRING is of type STRING
01. *--------------------------------------------------------------------*
Version 2
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: <data_ref> TYPE REF TO data.
23. FIELD-SYMBOLS: <tab_logged> 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 <tab_logged>.
43. <tab_logged>-name = st_import-parameter.
44. TRY.
45. CREATE DATA: rf_data TYPE (st_import-structure).
46. ASSIGN: rf_data TO <data_ref>.
47. CATCH cx_root INTO rf_root.
Average User Rating
(1 rating)
0 Tweet 1

That should work...
562 Views Topics: abap Tags: interface, xml, parameters, function
48. lp_msg = rf_root->get_text( ).
49. ENDTRY.
50. <tab_logged>-value ?= <data_ref>.
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 0 Like
1 Comment
Follow SCN
Site Index Contact Us SAP Help Portal
Privacy Terms of Use Legal Disclosure Copyright
Like (0)
Alejandro Bindi Jun 19, 2013 3:34 PM
Very good idea!
I suppose the parameters serialization to XML using ID transformation could also be made generic /
dynamic. CL_FB_PARAMETER_DB class could also be useful for this.

Regards, thanks for sharing.

Вам также может понравиться