Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
roger_alluivall
Participant
0 Kudos

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: <fs_controller_tab> type prxctrltab,
                 <fs_field>          type any,
                 <fs_table>          type any table,
                 <fs_output_line>    type any,
                 <fs_output_tab>     type any table,
                 <fs_output>         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 <fs_output>.
      if <fs_output> is assigned.
        loop at struc_output->components into ls_components.
          assign component sy-tabix of structure <fs_output> to <fs_field>.
*         -------------------------------------------------------------------
*         -- Inside P_OUTPUT - Flat/Deep Strcuture: CONTROLLER table found --
*         -------------------------------------------------------------------
          if ls_components-name eq 'CONTROLLER'.
            if <fs_field> is assigned.
              assign <fs_field> to <fs_controller_tab>.
            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 <fs_field> is assigned.
                  if ls_components-type_kind eq cl_abap_typedescr=>typekind_struct2.
                    perform build_controller_table using <fs_field> p_cntrl_flag.
                  else.
                    if <fs_field> is not initial.
                      perform build_controller_table using <fs_field> 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 <fs_field> is assigned.
                  assign <fs_field> to <fs_table>.
                  if <fs_table> is assigned.
                    if <fs_table>[] is not initial.
                      perform build_controller_table using <fs_table> p_cntrl_flag.
                    endif.
                  endif.
                endif.
*            -------------------------------------------------------------------
*            --  Inside P_OUTPUT - Flat/Deep Strcuture: Other types treatment --
*            -------------------------------------------------------------------
              when others.
                if <fs_controller_tab> is assigned.
                  assign component sy-tabix of structure <fs_output> to <fs_field>.
                  if <fs_field> is assigned.
                    if <fs_field> is initial.
                      ls_prxctrl-field = ls_components-name.
                      ls_prxctrl-value = p_cntrl_flag.
                      append ls_prxctrl to <fs_controller_tab>.
                    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 <fs_output_tab>.
      if <fs_output_tab> is assigned.
*       -----------------------------------------------------------------
*       --  Inside P_OUTPUT - Internal Table: Treatment of each record --
*       -----------------------------------------------------------------
        loop at <fs_output_tab> assigning <fs_output_line>.
          perform build_controller_table using <fs_output_line> 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.



Labels in this area