Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ZCL_ZGW_CUST_360_AB_DPC_EXT definition
- public
- inheriting from ZCL_ZGW_CUST_360_AB_DPC
- create public .
- public section.
- methods /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITY REDEFINITION.
- methods /iwbep/if_mgw_appl_srv_runtime~create_deep_entity REDEFINITION.
- protected section.
- methods MATERIALSET_GET_ENTITY REDEFINITION.
- methods MATERIALSET_GET_ENTITYSET REDEFINITION.
- private section.
- TYPES:BEGIN OF gy_expand_order.
- INCLUDE TYPE zcl_zgw_cust_360_ab_mpc=>ts_order.
- TYPES: navorderitems TYPE STANDARD TABLE OF zcl_zgw_cust_360_ab_mpc=>ts_orderitem WITH DEFAULT KEY.
- TYPES: navorderpartners TYPE STANDARD TABLE OF zcl_zgw_cust_360_ab_mpc=>ts_orderpartner WITH DEFAULT KEY.
- TYPES:END OF gy_expand_order.
- ENDCLASS.
- CLASS ZCL_ZGW_CUST_360_AB_DPC_EXT IMPLEMENTATION.
- METHOD MATERIALSET_GET_ENTITY.
- * METHODS materialset_get_entity
- * IMPORTING
- * !iv_entity_name TYPE string
- * !iv_entity_set_name TYPE string
- * !iv_source_name TYPE string
- * !it_key_tab TYPE /iwbep/t_mgw_name_value_pair
- * !io_request_object TYPE REF TO /iwbep/if_mgw_req_entity OPTIONAL
- * !io_tech_request_context TYPE REF TO /iwbep/if_mgw_req_entity OPTIONAL
- * !it_navigation_path TYPE /iwbep/t_mgw_navigation_path
- * EXPORTING
- * !er_entity TYPE zcl_zgw_cust_360_ab_mpc=>ts_material
- * !es_response_context TYPE /iwbep/if_mgw_appl_srv_runtime=>ty_s_mgw_response_entity_cntxt
- * RAISING
- * /iwbep/cx_mgw_busi_exception
- * /iwbep/cx_mgw_tech_exception .
- "define the error class
- DATA:lo_busi_exc TYPE REF TO /iwbep/cx_mgw_busi_exception.
- CREATE OBJECT lo_busi_exc.
- "Retrieve material key
- DATA(lv_matnr) = VALUE matnr( it_key_tab[ name = 'matnr' ]-value DEFAULT '').
- "Get your material - USE YOUR OWN METHOD!!!!
- CALL METHOD zcl_t18_ab_customer360=>get_material_info
- EXPORTING
- iv_matnr = lv_matnr
- IMPORTING
- et_material_info = DATA(lt_material_descr).
- IF sy-subrc EQ 0.
- "Read first line of table
- DATA(ls_material_descr) = lt_material_descr[ 1 ] .
- "Move data from first line to exporting
- MOVE-CORRESPONDING ls_material_descr TO er_entity.
- ELSE.
- "Trow message to gateway --> front-end.
- lo_busi_exc->get_msg_container( )->add_message_text_only( EXPORTING iv_msg_type = 'E' iv_msg_text = 'Material not Found' ).
- RAISE EXCEPTION lo_busi_exc.
- ENDIF.
- ENDMETHOD.
- METHOD MATERIALSET_GET_ENTITYSET.
- "define the error class
- DATA:lo_busi_exc TYPE REF TO /iwbep/cx_mgw_busi_exception.
- CREATE OBJECT lo_busi_exc.
- DATA lv_matnr TYPE matnr.
- DATA ls_entityset LIKE LINE OF et_entityset.
- "Get All material - USE YOUR OWN METHOD!!!!
- call method zcl_t18_AB_customer360=>get_material_info
- IMPORTING
- et_material_info = data(lt_material).
- IF sy-subrc = 0.
- "Filter Materials
- READ TABLE it_filter_select_options INTO DATA(ls_filter_materialnumber) WITH KEY property = 'matnr'.
- READ TABLE it_filter_select_options INTO DATA(ls_filter_materialdescr) WITH KEY property = 'maktx'.
- IF ls_filter_materialnumber IS NOT INITIAL AND ls_filter_materialdescr IS NOT INITIAL.
- LOOP AT lt_material INTO DATA(ls_material) WHERE matnr IN ls_filter_materialnumber-select_options OR maktx IN ls_filter_materialdescr-select_options.
- MOVE-CORRESPONDING ls_material TO ls_entityset.
- APPEND ls_entityset TO et_entityset.
- ENDLOOP.
- ELSEIF ls_filter_materialnumber IS NOT INITIAL.
- LOOP AT lt_material INTO ls_material WHERE matnr IN ls_filter_materialnumber-select_options.
- MOVE-CORRESPONDING ls_material TO ls_entityset.
- APPEND ls_entityset TO et_entityset.
- ENDLOOP.
- ELSEIF ls_filter_materialdescr IS NOT INITIAL.
- LOOP AT lt_material INTO ls_material WHERE maktx IN ls_filter_materialdescr-select_options.
- MOVE-CORRESPONDING ls_material TO ls_entityset.
- APPEND ls_entityset TO et_entityset.
- ENDLOOP.
- ELSE.
- MOVE-CORRESPONDING lt_material[] TO et_entityset[].
- ENDIF.
- SORT et_entityset.
- else.
- "Trow message to gateway --> front-end.
- lo_busi_exc->get_msg_container( )->add_message_text_only( EXPORTING iv_msg_type = 'E' iv_msg_text = 'Materials not Found' ).
- RAISE EXCEPTION lo_busi_exc.
- ENDIF.
- ENDMETHOD.
- METHOD /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITY.
- **TRY.
- *CALL METHOD SUPER->/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITY
- ** EXPORTING
- ** iv_entity_name =
- ** iv_entity_set_name =
- ** iv_source_name =
- ** it_key_tab =
- ** it_navigation_path =
- ** io_expand =
- ** io_tech_request_context =
- ** IMPORTING
- ** er_entity =
- ** es_response_context =
- ** et_expanded_clauses =
- ** et_expanded_tech_clauses =
- * .
- ** CATCH /iwbep/cx_mgw_busi_exception .
- ** CATCH /iwbep/cx_mgw_tech_exception .
- **ENDTRY.
- DATA: ls_order_expand TYPE gy_expand_order. "Structure that is the build the same way as our navigation
- DATA:lo_busi_exc TYPE REF TO /iwbep/cx_mgw_busi_exception. "exception class
- DATA:lv_msg TYPE bapi_msg. "Error message
- "Get all the expands
- DATA(lt_expand_clauses) = io_expand->get_children( ).
- "This method is called for every expand that is executed.
- "To split the logic for every entity we expand, we write a case statement.
- CASE iv_source_name.
- WHEN 'Order'.
- "Read the key parameter from the url
- "We only read the Sales order ID because this is the only one we defined as key in the order entity
- DATA(lv_order) = VALUE vbeln( it_key_tab[ name = 'Vbeln' ]-value ).
- CALL METHOD zcl_t18_af_customer360=>get_sales_order_data
- EXPORTING
- iv_vbeln = |{ lv_order ALPHA = IN }|
- IMPORTING
- es_salesorder_header = DATA(ls_sales_order_info)
- et_item = DATA(ls_sales_order_items)
- et_partner = DATA(ls_sales_order_partners)
- EXCEPTIONS
- no_sales_order_id_provided = 1.
- IF sy-subrc <> 0.
- "Build error message
- CALL FUNCTION 'MESSAGE_TEXT_BUILD'
- EXPORTING
- msgid = sy-msgid
- msgnr = sy-msgno
- msgv1 = sy-msgv1
- msgv2 = sy-msgv2
- msgv3 = sy-msgv3
- msgv4 = sy-msgv4
- IMPORTING
- message_text_output = lv_msg.
- "Trow message to gateway --> front-end.
- CREATE OBJECT lo_busi_exc.
- lo_busi_exc->get_msg_container( )->add_message_text_only( EXPORTING iv_msg_type = 'E' iv_msg_text = lv_msg ).
- RAISE EXCEPTION lo_busi_exc.
- ELSE.
- "Move all the data from the method to our temporary structure that looks linke our navigation path.
- MOVE-CORRESPONDING ls_sales_order_info TO ls_order_expand.
- "Return Items when asked
- IF line_exists( lt_expand_clauses[ tech_nav_prop_name = 'NAVORDERITEMS' ] ).
- MOVE-CORRESPONDING ls_sales_order_items[] TO ls_order_expand-navorderitems[].
- ENDIF.
- "Return partners when asked
- IF line_exists( lt_expand_clauses[ tech_nav_prop_name = 'NAVORDERPARTNERS' ] ).
- MOVE-CORRESPONDING ls_sales_order_partners[] TO ls_order_expand-navorderpartners[].
- ENDIF.
- ENDIF.
- WHEN OTHERS.
- "Do nothing
- ENDCASE.
- "Export the result data to the exporting
- "Because our temporary structure follow the structure of our navigation path, we can just use copy_data_to_ref.
- copy_data_to_ref(
- EXPORTING
- is_data = ls_order_expand
- CHANGING
- cr_data = er_entity
- ).
- "Indicate that following expands are resolved.
- IF line_exists( lt_expand_clauses[ tech_nav_prop_name = 'NAVORDERITEMS' ] ).
- APPEND 'NAVORDERITEMS' TO et_expanded_tech_clauses.
- ENDIF.
- IF line_exists( lt_expand_clauses[ tech_nav_prop_name = 'NAVORDERPARTNERS' ] ).
- APPEND 'NAVORDERPARTNERS' TO et_expanded_tech_clauses.
- ENDIF.
- ENDMETHOD.
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- METHOD /iwbep/if_mgw_appl_srv_runtime~create_deep_entity.
- DATA ls_deep TYPE gy_expand_order. "Reuse the deep order structure
- DATA: lo_message TYPE REF TO /iwbep/if_message_container.
- DATA: lx_bus_ex TYPE REF TO /iwbep/cx_mgw_busi_exception.
- DATA ls_sales_order_info TYPE ZT18_S_AB_SALESORDER_HEADER.
- DATA lt_sales_order_items TYPE zt18tt_sales_order_items.
- DATA lt_sales_order_partners TYPE zt18tt_sales_order_partners.
- DATA lt_return TYPE bapiret2_t.
- DATA lv_status TYPE char1.
- DATA lv_salesdoc TYPE vbeln.
- "Copy everything of the post into our deep entity
- io_data_provider->read_entry_data(
- IMPORTING
- es_data = ls_deep
- ).
- MOVE-CORRESPONDING ls_deep TO ls_sales_order_info.
- MOVE-CORRESPONDING ls_deep-navorderitems TO lt_sales_order_items.
- MOVE-CORRESPONDING ls_deep-navorderpartners TO lt_sales_order_partners.
- CALL FUNCTION 'ZFM_T18_AB_CREATE_SALES_ORDER'
- EXPORTING
- is_sales_order_info = ls_sales_order_info
- is_sales_order_items = lt_sales_order_items
- is_sales_order_partners = lt_sales_order_partners
- IMPORTING
- et_return = lt_return " Return table
- ev_status = lv_status " Single-Character Flag
- ev_salesdoc = lv_salesdoc. " Sales and Distribution Document Number
- LOOP AT lt_return TRANSPORTING NO FIELDS WHERE type CA 'EAX'.
- ENDLOOP.
- IF sy-subrc EQ 0.
- "When errors are returned --> show in front-end
- lo_message = mo_context->get_message_container( ).
- lo_message->add_messages_from_bapi( it_bapi_messages = lt_return ).
- CREATE OBJECT lx_bus_ex
- EXPORTING
- message_container = lo_message.
- RAISE EXCEPTION lx_bus_ex.
- ENDIF.
- ls_deep-Vbeln = lv_salesdoc.
- LOOP AT ls_deep-navorderitems ASSIGNING FIELD-SYMBOL(<fs_item>).
- <fs_item>-vbeln = lv_salesdoc.
- ENDLOOP.
- LOOP AT ls_deep-navorderpartners ASSIGNING FIELD-SYMBOL(<fs_partner>).
- <fs_partner>-vbeln = lv_salesdoc.
- ENDLOOP.
- copy_data_to_ref(
- EXPORTING
- is_data = ls_deep
- CHANGING
- cr_data = er_deep_entity
- ).
- ENDMETHOD.
- ENDCLASS.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement