Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3132

Re: Triggering two workflows using a single CR

$
0
0

Hi Arihant,

 

For example i told a method READ_MARCFRGTR. This is not existing in standard example implementation. You have to create this method and code it similar to READ_MATERIAL.

Please follow below steps in the BADI:

 

  • Create a custom implementation for this BADI.
  • Inside this custom implementation class, create a new static private method called READ_MARCFRGTR.
  • Create below parameters for this new method,
    • Exporting parameter ES_MARCFRGTR  TYPE /MDGMM/_S_MM_PP_MARCFRGTR
    • Importing paramter IV_CR_NUMBER TYPE USMD_CREQUEST
  • Put below code inside this new method.

METHOD read_marcfrgtr.
   DATA: lr_model    TYPE REF TO if_usmd_model_ext.
   DATA: lt_sel      TYPE usmd_ts_sel.
   DATA: ls_sel      TYPE usmd_s_sel.
   DATA: lt_objlist  TYPE usmd_t_crequest_entity.
   DATA: ls_objlist  TYPE usmd_s_crequest_entity.
   DATA: lv_matnr    TYPE matnr.
   DATA: lr_data     TYPE REF TO data.
   FIELD-SYMBOLS: <lt_data> TYPE SORTED TABLE.
   FIELD-SYMBOLS: <ls_data> TYPE any.
   CONSTANTS: lc_incl  TYPE ddsign   VALUE 'I'.
   CONSTANTS: lc_equal TYPE ddoption VALUE 'EQ'.

   CLEAR: es_marcfrgtr.
* Get read-only access to USMD model data
   CALL METHOD cl_usmd_model_ext=>get_instance
     EXPORTING
       i_usmd_model = if_mdg_bs_mat_gen_c=>gc_model_mm
     IMPORTING
       eo_instance  = lr_model.
* Read object list of CR and get the one and only material:
* Get the key of the (type 1) entity MATERIAL
* from the object list of this CR
   ls_sel-sign      = lc_incl.
   ls_sel-option    = lc_equal.
   ls_sel-fieldname = usmd0_cs_fld-crequest.
   ls_sel-low       = iv_cr_number.
   INSERT ls_sel INTO TABLE lt_sel.
   CALL METHOD lr_model->read_char_value
     EXPORTING
       i_fieldname       = usmd0_cs_fld-crequest
       it_sel            = lt_sel
       if_use_edtn_slice = abap_false
     IMPORTING
       et_data           = lt_objlist.
   READ TABLE lt_objlist INTO ls_objlist INDEX 1.
   ASSERT sy-subrc = 0. " CR not found or contains no material
   lv_matnr = ls_objlist-usmd_value.
* Prepare result table for MATERIAL read
   CALL METHOD lr_model->create_data_reference
     EXPORTING
       i_fieldname = if_mdg_bs_mat_gen_c=>gc_fieldname_marcfrgtr
       i_struct    = lr_model->gc_struct_key_attr
       if_table    = abap_true
       i_tabtype   = lr_model->gc_tabtype_sorted
     IMPORTING
       er_data     = lr_data.
   ASSIGN lr_data->* TO <lt_data>.
* Read MATERIAL via material number and Change Request ID
   CLEAR lt_sel.
   ls_sel-fieldname = if_mdg_bs_mat_gen_c=>gc_fieldname_material.
   ls_sel-sign   = lc_incl.
   ls_sel-option = lc_equal.
   ls_sel-low    = lv_matnr.
   INSERT ls_sel INTO TABLE lt_sel.
   ls_sel-fieldname = usmd0_cs_fld-crequest.
   ls_sel-low       = iv_cr_number.
   INSERT ls_sel INTO TABLE lt_sel.
   CALL METHOD lr_model->read_char_value
     EXPORTING
       i_fieldname       = if_mdg_bs_mat_gen_c=>gc_fieldname_marcfrgtr 
       it_sel            = lt_sel
       i_readmode        = if_usmd_model_ext=>gc_readmode_default
       if_use_edtn_slice = abap_false
     IMPORTING
       et_data           = <lt_data>.
* Return the one and only result
   READ TABLE <lt_data> ASSIGNING <ls_data> INDEX 1.
   ASSERT sy-subrc = 0. " CR not found or contains no material
   MOVE-CORRESPONDING <ls_data> TO es_marcfrgtr.
ENDMETHOD.


  • Create also GET_ELEMENT_ID and READ_CREQUEST methods and copy same code from the example implementation class CL_MDG_BS_MAT_BRF_CONTEXT_LABO to your custom implementation class.
  • Now inside the method PREPARE_RULE_CONTEXT use below code

 

METHOD if_usmd_ssw_rule_cntx_prepare~prepare_rule_context.
* Add one decision table parameter "Labor" (MARC-CASMARCFT)
* to the user agent decision table
   DATA: lv_brf_expr_id TYPE if_fdt_types=>id.
   DATA: ls_context     TYPE usmd_s_fdt_context_value.
   DATA: lv_crequest    TYPE usmd_s_crequest.
   DATA: ls_marcfrgtr    TYPE /MDGMM/_S_MM_PP_MARCFRGTR.
   FIELD-SYMBOLS: <value> TYPE any.
* Prepare export parameters
   CLEAR et_message.
   CLEAR et_rule_context_value.
* Read the one and only material of the CR
   CALL METHOD read_marcfrgtr
     EXPORTING
       iv_cr_number = iv_cr_number
     IMPORTING
       es_material  = ls_marcfrgtr.
* Read the CR itself (to get the CR type
   CALL METHOD read_crequest
     EXPORTING
       iv_cr_number = iv_cr_number
     IMPORTING
       es_crequest  = lv_crequest.
* fill out the return table
   get_element_id(
     EXPORTING
       iv_cr_type = lv_crequest-usmd_creq_type
       iv_name    = 'CASMARCFT'
     IMPORTING
       ev_brf_expr_id = lv_brf_expr_id ).
   ls_context-id = lv_brf_expr_id.
   CREATE DATA ls_context-value TYPE labor.
   ASSIGN  ls_context-value->* TO <value>.
   <value> = ls_material-labor.
   APPEND ls_context TO et_rule_context_value.
ENDMETHOD.


Viewing all articles
Browse latest Browse all 3132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>