Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 10.80 KB | None | 0 0
  1. class ZCL_ZGW_CUST_360_AB_DPC_EXT definition
  2.   public
  3.   inheriting from ZCL_ZGW_CUST_360_AB_DPC
  4.   create public .
  5.  
  6. public section.
  7. methods /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITY REDEFINITION.
  8. methods /iwbep/if_mgw_appl_srv_runtime~create_deep_entity REDEFINITION.
  9. protected section.
  10. methods MATERIALSET_GET_ENTITY REDEFINITION.
  11. methods MATERIALSET_GET_ENTITYSET REDEFINITION.
  12. private section.
  13. TYPES:BEGIN OF gy_expand_order.
  14. INCLUDE TYPE zcl_zgw_cust_360_ab_mpc=>ts_order.
  15. TYPES: navorderitems TYPE STANDARD TABLE OF zcl_zgw_cust_360_ab_mpc=>ts_orderitem WITH DEFAULT KEY.
  16. TYPES: navorderpartners TYPE STANDARD TABLE OF zcl_zgw_cust_360_ab_mpc=>ts_orderpartner WITH DEFAULT KEY.
  17. TYPES:END OF gy_expand_order.
  18.  
  19. ENDCLASS.
  20.  
  21.  
  22.  
  23. CLASS ZCL_ZGW_CUST_360_AB_DPC_EXT IMPLEMENTATION.
  24.   METHOD MATERIALSET_GET_ENTITY.
  25. *    METHODS materialset_get_entity
  26. *      IMPORTING
  27. *        !iv_entity_name          TYPE string
  28. *        !iv_entity_set_name      TYPE string
  29. *        !iv_source_name          TYPE string
  30. *        !it_key_tab              TYPE /iwbep/t_mgw_name_value_pair
  31. *        !io_request_object       TYPE REF TO /iwbep/if_mgw_req_entity OPTIONAL
  32. *        !io_tech_request_context TYPE REF TO /iwbep/if_mgw_req_entity OPTIONAL
  33. *        !it_navigation_path      TYPE /iwbep/t_mgw_navigation_path
  34. *      EXPORTING
  35. *        !er_entity               TYPE zcl_zgw_cust_360_ab_mpc=>ts_material
  36. *        !es_response_context     TYPE /iwbep/if_mgw_appl_srv_runtime=>ty_s_mgw_response_entity_cntxt
  37. *      RAISING
  38. *        /iwbep/cx_mgw_busi_exception
  39. *        /iwbep/cx_mgw_tech_exception .
  40.  "define the error class
  41.     DATA:lo_busi_exc TYPE REF TO /iwbep/cx_mgw_busi_exception.
  42.     CREATE OBJECT lo_busi_exc.
  43.     "Retrieve material key
  44.     DATA(lv_matnr) = VALUE matnr( it_key_tab[ name = 'matnr' ]-value DEFAULT '').
  45.  
  46.     "Get your material - USE YOUR OWN METHOD!!!!
  47.     CALL METHOD zcl_t18_ab_customer360=>get_material_info
  48.       EXPORTING
  49.         iv_matnr   = lv_matnr
  50.       IMPORTING
  51.         et_material_info = DATA(lt_material_descr).
  52.  
  53.     IF sy-subrc EQ 0.
  54.       "Read first line of table
  55.       DATA(ls_material_descr) =  lt_material_descr[ 1 ] .
  56.       "Move data from first line to exporting
  57.       MOVE-CORRESPONDING ls_material_descr TO er_entity.
  58.     ELSE.
  59.       "Trow message to gateway --> front-end.
  60.       lo_busi_exc->get_msg_container( )->add_message_text_only( EXPORTING iv_msg_type = 'E' iv_msg_text = 'Material not Found' ).
  61.       RAISE EXCEPTION lo_busi_exc.
  62.     ENDIF.
  63.  
  64.  
  65.  
  66.   ENDMETHOD.
  67.  
  68.   METHOD MATERIALSET_GET_ENTITYSET.
  69. "define the error class
  70.     DATA:lo_busi_exc TYPE REF TO /iwbep/cx_mgw_busi_exception.
  71.     CREATE OBJECT lo_busi_exc.
  72.  
  73.     DATA lv_matnr TYPE matnr.
  74.     DATA ls_entityset LIKE LINE OF et_entityset.
  75.  
  76.     "Get All material - USE YOUR OWN METHOD!!!!
  77.     call method zcl_t18_AB_customer360=>get_material_info
  78.       IMPORTING
  79.         et_material_info = data(lt_material).
  80.     IF sy-subrc = 0.
  81.     "Filter Materials
  82.     READ TABLE it_filter_select_options INTO DATA(ls_filter_materialnumber) WITH KEY property  = 'matnr'.
  83.     READ TABLE it_filter_select_options INTO DATA(ls_filter_materialdescr) WITH KEY property  = 'maktx'.
  84.  
  85.     IF ls_filter_materialnumber IS NOT INITIAL AND ls_filter_materialdescr IS NOT INITIAL.
  86.       LOOP AT lt_material INTO DATA(ls_material) WHERE matnr IN ls_filter_materialnumber-select_options OR maktx IN ls_filter_materialdescr-select_options.
  87.         MOVE-CORRESPONDING ls_material TO ls_entityset.
  88.         APPEND ls_entityset TO et_entityset.
  89.       ENDLOOP.
  90.     ELSEIF ls_filter_materialnumber IS NOT INITIAL.
  91.       LOOP AT lt_material INTO ls_material WHERE matnr IN ls_filter_materialnumber-select_options.
  92.         MOVE-CORRESPONDING ls_material TO ls_entityset.
  93.         APPEND ls_entityset TO et_entityset.
  94.       ENDLOOP.
  95.     ELSEIF ls_filter_materialdescr IS NOT INITIAL.
  96.       LOOP AT lt_material INTO ls_material WHERE maktx IN ls_filter_materialdescr-select_options.
  97.         MOVE-CORRESPONDING ls_material TO ls_entityset.
  98.         APPEND ls_entityset TO et_entityset.
  99.       ENDLOOP.
  100.     ELSE.
  101.       MOVE-CORRESPONDING lt_material[] TO et_entityset[].
  102.     ENDIF.
  103.  
  104.  
  105.     SORT et_entityset.
  106.     else.
  107.           "Trow message to gateway --> front-end.
  108.       lo_busi_exc->get_msg_container( )->add_message_text_only( EXPORTING iv_msg_type = 'E' iv_msg_text = 'Materials not Found' ).
  109.       RAISE EXCEPTION lo_busi_exc.
  110.     ENDIF.
  111.  
  112.   ENDMETHOD.
  113.  
  114.   METHOD /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITY.
  115. **TRY.
  116. *CALL METHOD SUPER->/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITY
  117. **  EXPORTING
  118. **    iv_entity_name           =
  119. **    iv_entity_set_name       =
  120. **    iv_source_name           =
  121. **    it_key_tab               =
  122. **    it_navigation_path       =
  123. **    io_expand                =
  124. **    io_tech_request_context  =
  125. **  IMPORTING
  126. **    er_entity                =
  127. **    es_response_context      =
  128. **    et_expanded_clauses      =
  129. **    et_expanded_tech_clauses =
  130. *    .
  131. ** CATCH /iwbep/cx_mgw_busi_exception .
  132. ** CATCH /iwbep/cx_mgw_tech_exception .
  133. **ENDTRY.
  134.  
  135.     DATA: ls_order_expand TYPE gy_expand_order. "Structure that is the build the same way as our navigation
  136.     DATA:lo_busi_exc TYPE REF TO /iwbep/cx_mgw_busi_exception. "exception class
  137.     DATA:lv_msg TYPE bapi_msg. "Error message
  138.  
  139.     "Get all the expands
  140.     DATA(lt_expand_clauses) = io_expand->get_children( ).
  141.  
  142.     "This method is called for every expand that is executed.
  143.     "To split the logic for every entity we expand, we write a case statement.
  144.     CASE iv_source_name.
  145.       WHEN 'Order'.
  146.  
  147.         "Read the key parameter from the url
  148.         "We only read the Sales order ID because this is the only one we defined as key in the order entity
  149.         DATA(lv_order) = VALUE vbeln( it_key_tab[ name = 'Vbeln' ]-value ).
  150.  
  151.         CALL METHOD zcl_t18_af_customer360=>get_sales_order_data
  152.           EXPORTING
  153.             iv_vbeln      = |{ lv_order ALPHA = IN }|
  154.           IMPORTING
  155.             es_salesorder_header     = DATA(ls_sales_order_info)
  156.             et_item    = DATA(ls_sales_order_items)
  157.             et_partner = DATA(ls_sales_order_partners)
  158.           EXCEPTIONS
  159.         no_sales_order_id_provided = 1.
  160.         IF sy-subrc <> 0.
  161.           "Build error message
  162.           CALL FUNCTION 'MESSAGE_TEXT_BUILD'
  163.             EXPORTING
  164.               msgid               = sy-msgid
  165.               msgnr               = sy-msgno
  166.               msgv1               = sy-msgv1
  167.               msgv2               = sy-msgv2
  168.               msgv3               = sy-msgv3
  169.               msgv4               = sy-msgv4
  170.             IMPORTING
  171.               message_text_output = lv_msg.
  172.           "Trow message to gateway --> front-end.
  173.           CREATE OBJECT lo_busi_exc.
  174.           lo_busi_exc->get_msg_container( )->add_message_text_only( EXPORTING iv_msg_type = 'E' iv_msg_text = lv_msg ).
  175.           RAISE EXCEPTION lo_busi_exc.
  176.         ELSE.
  177.           "Move all the data from the method to our temporary structure that looks linke our navigation path.
  178.           MOVE-CORRESPONDING ls_sales_order_info TO ls_order_expand.
  179.  
  180.           "Return Items when asked
  181.           IF line_exists( lt_expand_clauses[ tech_nav_prop_name = 'NAVORDERITEMS' ] ).
  182.             MOVE-CORRESPONDING ls_sales_order_items[] TO ls_order_expand-navorderitems[].
  183.           ENDIF.
  184.  
  185.           "Return partners when asked
  186.           IF line_exists( lt_expand_clauses[ tech_nav_prop_name = 'NAVORDERPARTNERS' ] ).
  187.             MOVE-CORRESPONDING ls_sales_order_partners[] TO ls_order_expand-navorderpartners[].
  188.           ENDIF.
  189.         ENDIF.
  190.  
  191.       WHEN OTHERS.
  192.         "Do nothing
  193.     ENDCASE.
  194.  
  195.     "Export the result data to the exporting
  196.     "Because our temporary structure follow the structure of our navigation path, we can just use copy_data_to_ref.
  197.     copy_data_to_ref(
  198.       EXPORTING
  199.         is_data = ls_order_expand
  200.       CHANGING
  201.         cr_data = er_entity
  202.     ).
  203.  
  204.     "Indicate that following expands are resolved.
  205.     IF line_exists( lt_expand_clauses[ tech_nav_prop_name = 'NAVORDERITEMS' ] ).
  206.       APPEND 'NAVORDERITEMS' TO et_expanded_tech_clauses.
  207.     ENDIF.
  208.     IF line_exists( lt_expand_clauses[ tech_nav_prop_name = 'NAVORDERPARTNERS' ] ).
  209.       APPEND 'NAVORDERPARTNERS' TO et_expanded_tech_clauses.
  210.     ENDIF.
  211.   ENDMETHOD.
  212.  
  213. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  214. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  215.   METHOD /iwbep/if_mgw_appl_srv_runtime~create_deep_entity.
  216.  
  217.     DATA ls_deep                        TYPE gy_expand_order. "Reuse the deep order structure
  218.     DATA: lo_message                    TYPE REF TO /iwbep/if_message_container.
  219.     DATA: lx_bus_ex                     TYPE REF TO /iwbep/cx_mgw_busi_exception.
  220.     DATA ls_sales_order_info            TYPE ZT18_S_AB_SALESORDER_HEADER.
  221.     DATA lt_sales_order_items           TYPE zt18tt_sales_order_items.
  222.     DATA lt_sales_order_partners        TYPE zt18tt_sales_order_partners.
  223.     DATA lt_return                      TYPE  bapiret2_t.
  224.     DATA lv_status                      TYPE  char1.
  225.     DATA lv_salesdoc                    TYPE  vbeln.
  226.  
  227.     "Copy everything of the post into our deep entity
  228.     io_data_provider->read_entry_data(
  229.         IMPORTING
  230.         es_data = ls_deep
  231.         ).
  232.  
  233.     MOVE-CORRESPONDING ls_deep TO ls_sales_order_info.
  234.     MOVE-CORRESPONDING ls_deep-navorderitems TO lt_sales_order_items.
  235.     MOVE-CORRESPONDING ls_deep-navorderpartners TO lt_sales_order_partners.
  236.  
  237.     CALL FUNCTION 'ZFM_T18_AB_CREATE_SALES_ORDER'
  238.       EXPORTING
  239.         is_sales_order_info     = ls_sales_order_info
  240.         is_sales_order_items    = lt_sales_order_items
  241.         is_sales_order_partners = lt_sales_order_partners
  242.       IMPORTING
  243.         et_return               = lt_return     " Return table
  244.         ev_status               = lv_status    " Single-Character Flag
  245.         ev_salesdoc             = lv_salesdoc.  " Sales and Distribution Document Number
  246.     LOOP AT lt_return TRANSPORTING NO FIELDS WHERE type CA 'EAX'.
  247.     ENDLOOP.
  248.     IF sy-subrc EQ 0.
  249.       "When errors are returned --> show in front-end
  250.       lo_message = mo_context->get_message_container( ).
  251.       lo_message->add_messages_from_bapi( it_bapi_messages = lt_return ).
  252.       CREATE OBJECT lx_bus_ex
  253.         EXPORTING
  254.           message_container = lo_message.
  255.       RAISE EXCEPTION lx_bus_ex.
  256.     ENDIF.
  257.  
  258.     ls_deep-Vbeln = lv_salesdoc.
  259.     LOOP AT ls_deep-navorderitems ASSIGNING FIELD-SYMBOL(<fs_item>).
  260.       <fs_item>-vbeln = lv_salesdoc.
  261.     ENDLOOP.
  262.  
  263.     LOOP AT ls_deep-navorderpartners ASSIGNING FIELD-SYMBOL(<fs_partner>).
  264.       <fs_partner>-vbeln = lv_salesdoc.
  265.     ENDLOOP.
  266.  
  267.     copy_data_to_ref(
  268.       EXPORTING
  269.         is_data = ls_deep
  270.       CHANGING
  271.         cr_data = er_deep_entity
  272.     ).
  273.   ENDMETHOD.
  274.  
  275.  
  276. ENDCLASS.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement