Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos
Purpose of creating a Rule:-
We are creating rule to determine the agents to whom we are going to send the mails/notification. Inside this we are going to see how we can determine the 
agents through a custom made FM with the help of Organization. We are also going to see that how we can filter the position based on certain attributes
which can be maintained in Org model. Over here we are going to consider the Billing Block. We are also showing the place in the Org Model to maintain
this type of attributes.
Step1:
Go to TCODE – PFAC and click on Create button.
Step2:
Give a name to the Rule under Field Abbr.
Select the Category as “F”.  This will determine all the agents with the help of a Function Module. We have created a custom FM “YWORKFLOW_AGENT_DETERMINATION” to get our Agents.
Step3:
Go to container tab and create 1 Element with name ITEM_GUID. Make the Property as Import.
Once you click on Create button you will get a pop-up fill all the required filled. Select “ABAP Dict. Reference” and give the data base table name and the field name. As shown in the below Screen shot.
Now go to property tab of the Element and check the Import box and press enter. Then Save the Rule and come out.
  1. FM YWORKFLOW_AGENT_DETERMINATION
       Build the Function module first before using it in Rule.
       Import Parameters   : - N/A
       Export Parameters  : - N/A
      Tables:-
      
Parameter NameTypingAssociated Type
AC_CONTAINERTYPESWCONT
ACTOR_TABTYPESWHACTOR
Logic:-  
  1. Declare the standard Include <CNTN01> for workflow container.
  2. Read the item GUID from Workflow container with the help of micro SWC_GET_ELEMENT. With the help of this micro you can get all the values
    which you will be passing from your workflow to Rule through Binding. We will discuss about this Rule Binding under Workflow creation section.
     swc_get_element ac_container 'ITEM_GUID'      w_itm_guid. 

   3.  Get the Header GUID from Item GUID with help of FM CRM_ORDER_GET_HEADER_GUID.

   4.  Get the Organization Details and Billing Details based on the Header GUID.

   5.  Get all the users based on the organization with help of FM RH_STRUC_GET. Keep only those users whose Object type (OTYPE) is equal to “S” delete

        the rests.

    6. Over here we are also considering Billing Block to filter the Positions. We are using Class CL_CRM_MIWF_TOOLS and Method

        APPLY_ATTRIBUTE_TO_POSITIONS to get filter the positions for those the billing Block is not maintained in org. model.

*Filter the positions by attributes

   
CALL METHOD cl_crm_miwf_tools=>apply_attribute_to_positions
     
EXPORTING
        iv_attrib_name  = c_attr_name
        iv_attrib_value = w_billing_block
        iv_scenario     = c_scenario
     
CHANGING
        ct_positions    = i_positions_1
     
EXCEPTIONS
        error_occurred  =
1
        parameter_error =
2
       
OTHERS          = 3.
In order to check the Billing Block is maintained for a position go to tcode PPOMA_CRM.  Select the Position and click on GOTO->Detail Object->Enhanced Object Description. As shown in the below Screen shot. Also you can use TCODE PP01 to check the position details.
Now select the Infotype “General Attribute Maint.” and click on display button. You can see all the Attributes and the values which are maintained for that
position. The Subtype is the Scenario value which we need to pass while calling the method.
Get all the users linked to this position with the help of CL_CRM_MIWF_TOOLS and method CONVERT_POSITIONS_INTO_USERS. Over here pass Position you got from above step and get the users and pass the value to ACTOR_TAB.
ACTOR_TAB holds all the agents to whom we are going to send the notifications/mails through our workflow.
Program( Sample Code for Agent Determination):-

FUNCTION yworkflow_agent_determination.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  TABLES
*"      AC_CONTAINER STRUCTURE  SWCONT
*"      ACTOR_TAB STRUCTURE  SWHACTOR
*"----------------------------------------------------------------------

*----------------------------------------------------------------------*
*                     DATA DECLARATIONS                                *
*----------------------------------------------------------------------*

*Include declarations
  INCLUDE:
*Standard Include for data declarations
         crm_object_names_con,
**Standard Include for workflow container
         <cntn01>.

*types declaration to fetch data from the table hrp1000
  TYPES:BEGIN OF ty_hrp1000,
        otype TYPE otype,        "Object Type
        objid TYPE hrobjid,      "Object ID
        otjid TYPE otjid,        "Concatenation of Object Type and Object ID
        short TYPE short_d,      "Object Abbreviation
        stext TYPE stext,        "Object Name
        END OF ty_hrp1000,

*types declaration for attributes data
        BEGIN OF ty_attributes,
        objid     TYPE hrobjid,       "Object ID
        position  TYPE hrobjid,       "Position ID
        attr_name TYPE om_attrib,     "Attribute name
        value_low TYPE om_attrval,    "Attribute value low
        value_h   TYPE om_attrvto,    "Attribute value high
        END OF ty_attributes.


*Internal table declarations
  DATA:
*internal table to read the Sales Order header guid
          i_header_guid           TYPE crmt_object_guid_tab,
*internal table for objects to be read
          i_requested_objects     TYPE crmt_object_name_tab,
*internal table for order header data
          i_orderadm_h            TYPE crmt_orderadm_h_wrkt,
*internal table for order item data
          i_orderadm_i            TYPE crmt_orderadm_i_wrkt,
*internal table for organizational data
          i_orgman                TYPE crmt_orgman_wrkt,
*internal table for Billing data
          i_billing               TYPE crmt_billing_wrkt,
*internal table for hrp1000 data
          i_hrp1000               TYPE TABLE OF ty_hrp1000,
*internal table for assigned objects
          i_assigned_objects      TYPE TABLE OF hrsettab,
*internal table for assigned objects
          i_assigned_objects01    TYPE TABLE OF hrsettab,
*internal table for root objects
          i_root_objects          TYPE TABLE OF hrrootob,
*internal table for position attributes data
          i_attrib                TYPE TABLE OF pt1222,
*internal table for position attributes data
          i_attrib_ext            TYPE TABLE OF omattvalrt,
*internal table for attributes data
          i_attributes            TYPE TABLE OF ty_attributes,
*internal table for message handle
          i_msg_handle            TYPE bal_t_msgh,
*internal table for messages
          i_msg_data              TYPE TABLE OF bal_s_msg,
*result structure for positions
          i_result_struc          TYPE TABLE OF struc,
*internal table for positions data
          i_positions_1           TYPE TABLE OF swhactor,
*internal table for receivers
          i_receiving_users       TYPE tswhactor.


*work area declarations
  DATA:

*work area for i_header_guid
       i_wa_header_guid        LIKE LINE OF i_header_guid,
*work area for i_requested_objects
       i_wa_requested_objects  LIKE LINE OF i_requested_objects,
*work area for i_orderadm_h
       i_wa_orderadm_h         LIKE LINE OF i_orderadm_h,
*work area for i_orderadm_i
       i_wa_orderadm_i         LIKE LINE OF i_orderadm_i,
*work area for i_orgman
       i_wa_orgman             LIKE LINE OF i_orgman,
*work area for i_billing
       i_wa_billing            LIKE LINE OF i_billing,
*work area for i_hrp1000
       i_wa_hrp1000            TYPE ty_hrp1000,
*work area for i_assigned_objects
       i_wa_assigned_objects   TYPE hrsettab,
*work area for i_assigned_objects01
       i_wa_assigned_objects01 TYPE hrsettab,
*work area for root objects
       i_wa_root_objects       TYPE hrrootob,
*work area for i_attrib
       i_wa_attrib             TYPE pt1222,
*work area for i_attrib_ext
       i_wa_attrib_ext         TYPE omattvalrt,
*work area for i_attributes
       i_wa_attributes         TYPE ty_attributes,
*work area for messages
       i_wa_msg_data           LIKE LINE OF i_msg_data,
*work area for message handle
       i_wa_msg_handle         TYPE balmsghndl,
*work area for message data
       i_wa_message            TYPE bal_s_msg,
*work area for message information
       i_wa_msg_info           TYPE crmt_msg_info,
*work area for i_result_struc
       i_wa_result_struc       TYPE struc,
*work area for i_positions_1
       i_wa_positions_01       TYPE swhactor,
**work area for i_positions_1
       i_wa_positions_02       TYPE swhactor.


*Varaible declarations
  DATA:
*Sales Org
       w_sales_org      TYPE crmt_sales_org,
*Billing Block
       w_billing_block TYPE crmt_bus_bill_block_reason,
*Distribution Channel
       w_dis_channel    TYPE crmt_distribution_channel,
*Division
       w_division       TYPE crmt_division,
*first level org unit
       w_firstlevel_ou  TYPE hrobjid,
*second level org unit
       w_secondlevel_ou TYPE hrobjid,
*org unit position
       w_position       TYPE hrobjid,
*order header guid
       w_hdr_guid       TYPE crmt_object_guid,
*order ITEM guid
       w_itm_guid       TYPE crmt_object_guid,
*message number
       w_msgno          TYPE msgnr,
*message id
       w_msgid          TYPE symsgid,
*object type
       w_otype          TYPE otype,
*Agent ID in Organizational Management
       w_objid          TYPE actorid.

*Constants declarations
  CONSTANTS:
*Evaluation Path - 'ORGEH'
    c_wegid1    TYPE wegid VALUE  'ORGEH',
*Evaluation Path - 'OO-S-BP'
    c_wegid2    TYPE wegid VALUE  'OO-S-BP',
*Evaluation Path - 'PLSTE'
    c_wegid3    TYPE wegid VALUE  'PLSTE',
*Object Type - 'O' - Organizational unit
    c_otype_o   TYPE otype VALUE 'O',
*Object Type - 'S' - Position
    c_otype_s   TYPE otype VALUE 'S',
*Object Type - '*' - All
    c_otype_*   TYPE otype VALUE '*',
*Status Vector - '00001'
    c_svect     TYPE svect VALUE '00001',
*Status - 'X' - Active
    c_active    TYPE sactiv VALUE 'X',
*Technical Depth of Structure - 2
    c_tdepth_2  TYPE tdepth VALUE '2',
*Technical Depth of Structure - 3
    c_tdepth_3  TYPE tdepth VALUE '3',
*Scenario - 'SALE' - Sales
    c_scenario  TYPE om_attrscn VALUE 'SALE',
*the product does not exists in the system - Unknown part
    c_msgno_501 TYPE symsgno VALUE '501',
*mandatory pricing condition xx is missing  - Price missing
    c_msgno_801 TYPE symsgno VALUE '801',
*It is forbidden to create sales document for product xx - Blocked part
    c_msgno_420 TYPE symsgno VALUE '420',
*product xx in sales organization yy distribution channel zz not scheduled
* - unnumbered part
    c_msgno_419 TYPE symsgno VALUE '419',
*error message
    c_msgty     TYPE symsgty VALUE 'E',
*Unknown part
    c_msgid1    TYPE symsgid VALUE 'CRM_ORDERADM_I',
*Price missing
    c_msgid2    TYPE symsgid VALUE 'PRC_PRI',
*Blocked part and unnumbered part
    c_msgid3    TYPE symsgid VALUE 'CRM_PRODUCT_I',
*supress output - 'X' - True
    c_true      TYPE crmt_boolean VALUE 'X',
*null value
    c_null      TYPE c VALUE ' ',
*attribute name - YMI_SALERR
    c_attr_name TYPE om_attrib VALUE 'YMI_BILBK'. "'YMI_BBLOCK'.


*----------------------------------------------------------------------*
*                                                                      *
*----------------------------------------------------------------------*

* clear the work area's
  CLEAR: i_wa_requested_objects,i_wa_header_guid,i_wa_orgman,i_wa_msg_data,
         i_wa_result_struc,i_wa_positions_01,i_wa_positions_02,i_wa_msg_handle.

*-- Container operations
* read elements out of container
  swc_get_element ac_container 'ITEM_GUID'      w_itm_guid.

  CALL FUNCTION 'CRM_ORDER_GET_HEADER_GUID'
    EXPORTING
      iv_ref_guid     = w_itm_guid
      iv_ref_kind     = 'B'
    IMPORTING
      ev_header_guid  = w_hdr_guid
    EXCEPTIONS
      not_found       = 1
      parameter_error = 2
      OTHERS          = 3.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

*populate order header
  i_wa_requested_objects = gc_object_name-orderadm_h.
  INSERT i_wa_requested_objects INTO TABLE i_requested_objects.
*populate order item
  i_wa_requested_objects = gc_object_name-orderadm_i.
  INSERT i_wa_requested_objects INTO TABLE i_requested_objects.
*populate org
  i_wa_requested_objects = gc_object_name-orgman.
  INSERT i_wa_requested_objects INTO TABLE i_requested_objects.

*populate billing
  i_wa_requested_objects = gc_object_name-billing.
  INSERT i_wa_requested_objects INTO TABLE i_requested_objects.

*move the order header guid to i_header_guid
  i_wa_header_guid = w_hdr_guid.
  INSERT i_wa_header_guid INTO TABLE i_header_guid.


*get the sales org and Billing data
  CALL FUNCTION 'CRM_ORDER_READ'
    EXPORTING
      it_header_guid       = i_header_guid
      it_requested_objects = i_requested_objects
    IMPORTING
      et_orderadm_h        = i_orderadm_h
      et_orderadm_i        = i_orderadm_i
      et_orgman            = i_orgman
      et_billing           = i_billing
    EXCEPTIONS
      document_not_found   = 1
      error_occurred       = 2
      document_locked      = 3
      no_change_authority  = 4
      no_display_authority = 5
      no_change_allowed    = 6
      OTHERS               = 7.

  IF sy-subrc EQ 0.

*     get the sales org data
    READ TABLE i_orgman INTO i_wa_orgman WITH KEY
                             ref_guid = w_hdr_guid.
    IF sy-subrc EQ 0.
*     move object type
      w_otype   = i_wa_orgman-sales_org(2).
*     move object id
      w_objid   = i_wa_orgman-sales_org+2.

    ENDIF.

    READ TABLE i_billing INTO i_wa_billing
      WITH KEY ref_guid = w_itm_guid.
    IF sy-subrc IS INITIAL.
      w_billing_block  = i_wa_billing-billing_block.
    ENDIF.


  ENDIF.

*get the org units belonging to the resp.sales org
  CALL FUNCTION 'RH_STRUC_GET'
    EXPORTING
      act_otype      = w_otype
      act_objid      = w_objid
      act_wegid      = c_wegid3
      act_begda      = sy-datum
      act_endda      = sy-datum
      act_int_flag   = c_null
      act_tflag      = c_null
      act_vflag      = c_null
    TABLES
      result_struc   = i_result_struc
    EXCEPTIONS
      no_plvar_found = 0
      no_entry_found = 0
      OTHERS         = 0.

  IF sy-subrc EQ 0.

*delete entries that are not positions (type 'S')
*and prepare objects tab for the next function call
    LOOP AT i_result_struc INTO i_wa_result_struc
                              WHERE otype = c_otype_s.
*read the table i_positions
      READ TABLE i_positions_1 INTO i_wa_positions_01
                 WITH KEY otype = i_wa_result_struc-otype
                          objid = i_wa_result_struc-objid.  "#EC *
      IF sy-subrc NE 0.

*move object type
        i_wa_positions_02-otype = i_wa_result_struc-otype.
*move object id
        i_wa_positions_02-objid = i_wa_result_struc-objid.

        APPEND i_wa_positions_02 TO i_positions_1.

      ENDIF.

    ENDLOOP.

*sort i_positions by otype and objid
    SORT i_positions_1 BY otype objid.

  ENDIF.

*if i_positions_1 is not initial
  IF i_positions_1[] IS NOT INITIAL.

*get the Billing attribute (Billing Block) through which the Billing Block can be filtered

*Filter the positions by attributes
    CALL METHOD cl_crm_miwf_tools=>apply_attribute_to_positions
      EXPORTING
        iv_attrib_name  = c_attr_name                       "#EC NOTEXT
        iv_attrib_value = w_billing_block
        iv_scenario     = c_scenario                        "#EC NOTEXT
      CHANGING
        ct_positions    = i_positions_1
      EXCEPTIONS
        error_occurred  = 1
        parameter_error = 2
        OTHERS          = 3.

    IF sy-subrc EQ 0.

*Convert the positions into users
      CALL METHOD cl_crm_miwf_tools=>convert_positions_into_users
        EXPORTING
          it_positions   = i_positions_1
        IMPORTING
          et_users       = i_receiving_users
        EXCEPTIONS
          error_occurred = 1
          OTHERS         = 2.

      IF sy-subrc EQ 0.

*move the receiving users to actor_tab
        actor_tab[] = i_receiving_users.

      ENDIF.

    ENDIF.

  ENDIF.

ENDFUNCTION.