INTRODUCTION


     Sometimes, when dealing with synchronous interfaces, you need your proxy implementation to return optional fields even if they are initial. It can be done activating XML Extended Handler feature and populating CONTROLLER tables of your output structure accordingly. I have created a pair of function modules to make this job easier:


FUNCTION MODULE – ZPI_UTIL_XML_EXTENDED_HANDLING

  • Description: It activates/deactivates the XML Extended Handling feature.
  • Parameters:
    • ACTIVATE: ‘X’ to activate and  ‘ ‘ to deactivate XML Extended Handling feature.


FUNCTION MODULE – ZPI_UTIL_BUILD_CONTROLLER


  • Description: It walks through the input structure looking for initial fields. Every time an initial field is found, it is inserted in the corresponding control table with the desired control flag.
  • Parameters:
    • CNTRL_FLAG: Field Control in XML Data Stream (=> Type Group SAI).
    • OUTPUT: Output structure.

THE CODE

ZPI_UTIL_XML_EXTENDED_HANDLING



 function zpi_util_xml_extended_handling. *"---------------------------------------------------------------------- *"*"Local Interface: *"  IMPORTING *"     REFERENCE(ACTIVATE) TYPE  ACT DEFAULT 'X' *"----------------------------------------------------------------------   data: lo_server_context   type ref to if_ws_server_context,         lo_payload_protocol type ref to if_wsprotocol_payload.   lo_server_context = cl_proxy_access=>get_server_context( ).   lo_payload_protocol ?= lo_server_context->get_protocol( if_wsprotocol=>payload ).   lo_payload_protocol->set_extended_xml_handling( extended_xml_handling = activate ). endfunction.


ZPI_UTIL_BUILD_CONTROLLER



 function zpi_util_build_controller. *"---------------------------------------------------------------------- *"*"Local Interface: *"  IMPORTING *"     REFERENCE(CNTRL_FLAG) TYPE  PRX_CONTR *"  CHANGING *"     REFERENCE(OUTPUT) *"----------------------------------------------------------------------   perform build_controller_table using output cntrl_flag. endfunction.
 *&---------------------------------------------------------------------* *&      Form  BUILD_CONTROLLER_TABLE *&---------------------------------------------------------------------* *       text *----------------------------------------------------------------------* *      -->P_OUTPUT  text *      -->P_CNTRL_FLAG  text *----------------------------------------------------------------------* form build_controller_table  using    p_output     type any                                       p_cntrl_flag type prx_contr.   data: descr_output  type ref to cl_abap_typedescr,         struc_output  type ref to cl_abap_structdescr,         ls_components type abap_compdescr,         ls_prxctrl    type prxctrl,         lv_initial    type act.   field-symbols:  type prxctrltab,                            type any,                            type any table,                      type any,                       type any table,                           type any.   descr_output = cl_abap_typedescr=>describe_by_data( p_output ).   case descr_output->type_kind. *   ------------------------------------------------- *   - P_OUTPUT is either a Flat or a Deep structure - *   -------------------------------------------------     when cl_abap_typedescr=>typekind_struct1 or "Internal type u (flat structure)          cl_abap_typedescr=>typekind_struct2.   "Internal type v (deep structure)       struc_output ?= descr_output.       assign p_output to .       if  is assigned.         loop at struc_output->components into ls_components.           assign component sy-tabix of structure  to . *         ------------------------------------------------------------------- *         -- Inside P_OUTPUT - Flat/Deep Strcuture: CONTROLLER table found -- *         -------------------------------------------------------------------           if ls_components-name eq 'CONTROLLER'.             if  is assigned.               assign  to .             endif. *         --------------------------------------------------------------- *         --  Inside P_OUTPUT - Flat/Deep Strcuture: Other field found -- *         ---------------------------------------------------------------           else.             case ls_components-type_kind. *             -------------------------------------------------------------------------------- *             --  Inside P_OUTPUT - Flat/Deep Strcuture: Flat and Deep Structures treatment -- *             --------------------------------------------------------------------------------               when cl_abap_typedescr=>typekind_struct1 or "Internal type u (flat structure)                    cl_abap_typedescr=>typekind_struct2.   "Internal type v (deep structure)                 if  is assigned.                   if ls_components-type_kind eq cl_abap_typedescr=>typekind_struct2.                     perform build_controller_table using  p_cntrl_flag.                   else.                     if  is not initial.                       perform build_controller_table using  p_cntrl_flag.                     endif.                   endif.                 endif. *            ---------------------------------------------------------------------- *            -- Inside P_OUTPUT - Flat/Deep Strcuture: Internal Tables treatment -- *            ----------------------------------------------------------------------               when cl_abap_typedescr=>typekind_table.     "Internal Type h (Internal Table)                 if  is assigned.                   assign  to .                   if  is assigned.                     if [] is not initial.                       perform build_controller_table using  p_cntrl_flag.                     endif.                   endif.                 endif. *            ------------------------------------------------------------------- *            --  Inside P_OUTPUT - Flat/Deep Strcuture: Other types treatment -- *            -------------------------------------------------------------------               when others.                 if  is assigned.                   assign component sy-tabix of structure  to .                   if  is assigned.                     if  is initial.                       ls_prxctrl-field = ls_components-name.                       ls_prxctrl-value = p_cntrl_flag.                       append ls_prxctrl to .                     endif.                   endif.                 endif.             endcase.           endif.         endloop.       endif. *   --------------------------------- *   - P_OUTPUT is an Internal Table - *   ---------------------------------     when cl_abap_typedescr=>typekind_table. "Internal Type h (Internal Table)       assign p_output to .       if  is assigned. *       ----------------------------------------------------------------- *       --  Inside P_OUTPUT - Internal Table: Treatment of each record -- *       -----------------------------------------------------------------         loop at  assigning .           perform build_controller_table using  p_cntrl_flag.         endloop.       endif.     when others.   endcase. endform.                    " BUILD_CONTROLLER_TABLE 


INVOCATION CODE


These two functions can be used in proxy implementations once the output structure is populated.

 call function 'ZPI_UTIL_XML_EXTENDED_HANDLING'    exporting       activate = 'X'. call function 'ZPI_UTIL_BUILD_CONTROLLER'    exporting       cntrl_flag = sai_ctrl_initial    changing       output     = output. 


New NetWeaver Information at SAP.com

Very Helpfull

User Rating: Be the first one !