on 03-13-2007 3:21 PM
Hi :{),
I am trying to get the list of agents who approved an item in a shopping cart.
( Item based workflow)
I know how to get the agent list for the SC itself, using the FM SAP_WAPI_WORKITEMS_TO_OBJECT, OBJTYPE = 'BUS2121',OBJKEY ='10000001319'
, but I don't know how to get the approvers for specific items inside the SC.
can anyone help??
thanks
Ofer
Hi
Please try the following function modules ->
<b>SAP_WAPI_OBJECTS_IN_WORKITEM
SAP_WAPI_GET_OBJECTS
SAP_WAPI_WORKITEMS_BY_TASK
SAP_WAPI_GET_DEPENDENT_WIS
SAP_WAPI_WORKITEMS_BY_FREQUENC
SAP_WAPI_WORKITEMS_BY_DEADLINE
SAP_WAPI_WORKITEMS_BY_ERROR
SAP_WAPI_WORKITEM_RECIPIENTS
SAP_WAPI_END_RESUBMISSION
SAP_WAPI_GET_WORKITEM_DETAIL
SAP_WAPI_SET_WORKITEM_COMPLETD
SAP_WAPI_SET_WORKITEM_STATUS
SAP_WAPI_COUNT_WORKITEMS
SAP_WAPI_EXECUTE_WORKITEM</b>
Hope this will help.
Please reward suitable points, incase it suits your requirements.
Regards
- Atul
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Try this out. I am sure it will help.
<u>You can use FM <b>BBP_PDH_WFL_WI_FROM_OBJECT_GET</b> to get a WF item.
Example:</u>
call function 'BBP_PDH_WFL_WI_FROM_OBJECT_GET'
exporting
iv_object_id = g_crmd_orderadm_h-object_id
iv_object_type = g_crmd_orderadm_h-object_type
importing
ev_workitem_id = gv_workitem
ev_workitem_header = lv_workflow.
<u>
Where:
g_crmd_orderadm_h-object_id is number of SC
g_crmd_orderadm_h-object_type is 'BUS2121'
in table EV_WORKITEM_HEADER you can find:
- who approve this WF (field WI_AGENT)
- when this is happend (field WI_CD, WI_CT)
- status of workflow (field STATUSTEXT or WI_STAT)
- type of workflow (field WI_RH_TASK)
If you want to know the date of SC creation please refer to table CRMD_ORDERADM_H for document header or use FM BBP_PD_SC_GETDETAIL.
In E_HEADER check CREATED_BY and CREATED_AT fields</u>
Hope this will help.
Please reward suitable points, incase it suits your requirements.
Regards
- Atul
Thank you all,
What finally did the job was the FM
'BBP_PDH_WFL_PARAM_APPLET_FILL2'
in which you can specify both an SC GUID and an ITEM GUID,
and get the approvers for the specific item,
e.g:
call function 'BBP_PDH_WFL_PARAM_APPLET_FILL2'
exporting
IV_START_TASK = 'WS14500015'
IV_START_WI_ID = wa_worklist-WI_ID
IV_DB_WORKITEM_ID = wa_worklist-WI_ID
IV_OBJECT_TYPE = 'BUS2121'
IV_OBJECT_ID = wa_objkey2
IV_GUID = wa_guid32
IV_ITEM_GUID = wa_item_guid32
IV_IS_VIEW_ITEM_LEVEL = 'X'
iv_adhoc_extension_mode = ''
tables
ET_WF_APPROVER = IT_ITEM_WORKFLOW
ET_NODES = ET_NODES
ET_LINES = ET_LINES
ET_AGNTS = ET_AGNTS
ET_TASKS = ET_TASKS.
regards
Ofer
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Use SWI6 for getting the item line agents.
Regards
Vinod
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Atul,
This FM gives the complete workflow for the shopping cart,
but what about the items Inside?
In our system, the following situation is possible:
A shopping cart of 2 items (say, a desk and a laptop)
is approved by persons A,B and C,
item 1 (desk) is approved by person D,
Item 2 (laptop) by person E,
and so forth..
Is it possible to get the workitems of the SC items?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
<u>Please refer to this Sample code for Line-item Approval - SRM workflow.</u>
<b>* This code gives idea about of how line item approval should work</b>
INCLUDE <swfcntn01>. "Workflow
DATA:
ls_header TYPE bbp_pds_sc_header_d,
* approval object related structures
ls_approver TYPE bbp_wfl_approval_table_badi,
ls_approver_a TYPE bbp_wfl_approval_table_badi,
ls_approver_b TYPE bbp_wfl_approval_table_badi,
lt_approver TYPE TABLE OF bbp_wfl_approval_table_badi,
ls_item_app_obj TYPE bbps_wfl_item_approval_obj,
ls_approval_def TYPE bbpt_wfl_lia_def,
* tables for different approval criteria
lt_appr_def TYPE TABLE OF bbpt_wfl_lia_def,
lv_call_crit1 TYPE bbp_wfl_app_criterion,
lv_call_value1 TYPE bbp_wfl_app_property,
* approval item fields and structures
ls_approval_item TYPE bbps_wfl_item_approval,
lt_approval_items TYPE TABLE OF bbps_wfl_item_approval,
lv_approval_index TYPE bbp_wfl_approval_table_badi-approval_index,
lv_guid TYPE crmt_object_guid,
ev_app_obj_guid TYPE bbp_guid_32,
lv_object_value TYPE bbp_wfl_lia_value,
lv_def_value TYPE bbp_wfl_lia_value,
lv_object_found LIKE syst-subrc,
lv_ob_tbx LIKE syst-tabix,
* item fields and structures
ls_item TYPE bbp_pds_sc_item_d,
lt_item TYPE TABLE OF bbp_pds_sc_item_d,
ls_account TYPE bbp_pds_acc,
lt_account TYPE TABLE OF bbp_pds_acc.
* purchase order special...
DATA:
lt_approval_agent_obj TYPE TABLE OF swf_bor_object,
lt_approval_init_agents TYPE TABLE OF bbp_wfl_approval_table,
ls_wa_agent_obj TYPE swf_bor_object,
ls_approval_agent TYPE bbp_wfl_approval_table,
ls_wa_approval_init_agents TYPE bbp_wfl_approval_table,
ls_wa_approval_history TYPE bbps_wfl_history_line_badi,
lv_index TYPE syindex,
lv_usr01_name TYPE ad_namtext,
lo_new_instance TYPE swf_bor_object,
lo_user TYPE swf_bor_object.
* Business objects (local)
CONSTANTS:
c_po TYPE crmt_subobject_category_db VALUE 'BUS2201',
c_biddingdoc TYPE crmt_subobject_category_db VALUE 'BUS2200',
c_quotation TYPE crmt_subobject_category_db VALUE 'BUS2202',
c_grse TYPE crmt_subobject_category_db VALUE 'BUS2203',
c_invoice TYPE crmt_subobject_category_db VALUE 'BUS2205',
c_shop TYPE crmt_subobject_category_db VALUE 'BUS2121',
c_contract TYPE crmt_subobject_category_db VALUE 'BUS2000113',
c_salescontract TYPE crmt_subobject_category_db VALUE 'BUS2000114',
c_avl TYPE crmt_subobject_category_db VALUE 'BUS2206',
c_invoicegrp TYPE crmt_subobject_category_db VALUE 'BUS2207',
c_vendor_obj TYPE crmt_subobject_category_db VALUE 'BUS1006200'.
* Approval Criteria and properties used (local)
CONSTANTS:
c_3_step_limit TYPE i VALUE 510000000,
c_no_approval TYPE i VALUE 501000000,
c_item_value TYPE bbp_wfl_app_criterion VALUE 'ITEM_VALUE',
c_item_value_desc TYPE bbp_step_description
VALUE 'Item Vaue Approval',
c_cost_centre TYPE bbp_wfl_app_criterion VALUE 'COST_CTR',
c_cost_centre_desc TYPE bbp_step_description
VALUE 'Cost Centre Approval',
c_prod_categ TYPE bbp_wfl_app_criterion VALUE 'PROD_CAT',
c_prod_categ_desc TYPE bbp_step_description
VALUE 'Product Category'.
CONSTANTS:
c_agent_is_user TYPE otype VALUE 'US'.
*** workflow approval states
CONSTANTS:
c_wf_approved TYPE bbp_wfl_approvalstate VALUE '0',
c_wf_rejected TYPE bbp_wfl_approvalstate VALUE '1',
c_wf_not_instanced TYPE bbp_wfl_approvalstate VALUE '2',
c_wf_changed TYPE bbp_wfl_approvalstate VALUE '3',
c_wf_partialapproved TYPE bbp_wfl_approvalstate VALUE '4',
c_wf_step_in_process TYPE bbp_wfl_approvalstate VALUE '5'.
* map char32 to raw16
MOVE guid TO lv_guid.
CASE object_type.
WHEN c_shop.
* ----------- shopping cart ---------------------------------- *
*** get the nevessary field entries from the shopping cart
CALL FUNCTION 'BBP_PD_SC_GETDETAIL'
EXPORTING
i_guid = lv_guid
i_object_id = object_id
IMPORTING
e_header = ls_header
TABLES
e_item = lt_item
e_account = lt_account.
IF ls_header-total_value LT c_no_approval.
*** we define a threshold value of 501 000 000 that means, if the
*** shopping cart value is below that, ther's no approval required
no_further_approval_needed = 'X'.
ELSE.
* read definition table
CLEAR lt_appr_def.
SELECT * FROM bbpt_wfl_lia_def
INTO CORRESPONDING FIELDS OF ls_approval_def.
APPEND ls_approval_def TO lt_appr_def.
ENDSELECT.
*** We build up the item_approval_table and coplete approval object.
*** For that we loop over the items, investigate if it belongs to
*** one of the approval definitions we have made in the data base
*** table " BBPT_WFL_IA_DEF ". I.e. if we have defined an approver
*** for cost centre '1000' and the line item is assigned to cost
*** centre '1000' the approver can be set - also, if there is no
*** specific definition for the costcentre, but there is a definition
*** for cost centre 'OTHERS'. However, if there is no entry with
*** value 'OTHERS' in the cost centre table, there is no approval
*** for that item
LOOP AT lt_item INTO ls_item WHERE del_ind IS INITIAL.
*** the item guid is set to all 'approval item' entries - this table
*** provides a link between the approval object (defined by its GUID)
*** and the line item in the shopping cart
ls_approval_item-approval_item_guid = ls_item-guid.
* 1st approval step executed for indices 1 and 0
IF actual_approval_index LE 1.
CLEAR ls_item_app_obj.
ls_item_app_obj-sc_guid = ls_header-guid.
*** 1st level: distinguish according to item value:
*** for items with price less than 1000 we have a different approver
*** - or none if none is defined - than for items costing more than 1000
IF ls_item-value LT 1000.
lv_call_value1 = 'LOW'.
ELSE.
lv_call_value1 = 'HIGH'.
ENDIF.
*** the following function now creates a GUID and an entry in the item
*** approval object table if the criterion/value pair does not yet have
*** a definition in that table - otherwise it returns the GUID already
*** defined. The table lt_item_app_obj is updated in that function and
*** there is no other modification to this table necessary in the BADI.
*** The only important thing is, that the function has to be called with
*** exactely the same key in order to identify the correct entry.
CALL FUNCTION 'BBP_WFL_DIN_APP_OBJ_GET'
EXPORTING
sc_guid = ls_header-guid
criterion1 = c_item_value
value1 = lv_call_value1
IMPORTING
approval_obj_guid = ev_app_obj_guid
TABLES
item_app_obj = item_approval_obj.
*** now we can also complete the approval item table with the approval
*** object number and append it. The approver(s) for that object will be
*** completed in a second step after this loop over the items.
ls_approval_item-approval_object_guid = ev_app_obj_guid.
APPEND ls_approval_item TO lt_approval_items.
ENDIF. " 1st approval step
* 2nd approval step executed for indices 1 and 0
IF actual_approval_index LE 2.
CLEAR ls_item_app_obj.
ls_item_app_obj-sc_guid = ls_header-guid.
* 2nd level: cost centre approval
*** read cost centre in the account table (filled in the getdetail)
READ TABLE lt_account INTO ls_account
WITH KEY p_guid = ls_item-guid.
*** try to find an approver definition for the cost centre found
READ TABLE lt_appr_def INTO ls_approval_def
WITH KEY app_crit_name1 = c_cost_centre
app_crit_value1 = ls_account-cost_ctr.
IF sy-subrc = 4.
*** if no cost centre found, check if there's an aprover for others
lv_call_value1 = 'OTHERS'.
READ TABLE lt_appr_def INTO ls_approval_def
WITH KEY app_crit_name1 = c_cost_centre
app_crit_value1 = lv_call_value1.
ELSE.
MOVE ls_account-cost_ctr TO lv_call_value1.
ENDIF.
IF sy-subrc = 0.
*** as in the 1st step, we call the function that filles the approval
*** object table. Now we would also like this function fo add the values
*** of the items belonging to a specific approval object to be
*** summarised in the field APP_CRIT_VALUE3. For that we provide the
*** item value and fill the flag 'iv_add_value'
*** the item table is filled in the interface in order to check if an
*** item exists for the approver before inserted
CALL FUNCTION 'BBP_WFL_DIN_APP_OBJ_GET'
EXPORTING
sc_guid = ls_header-guid
criterion1 = c_cost_centre
value1 = lv_call_value1
iv_item_value = ls_item-value
iv_add_value = 'X'
IMPORTING
approval_obj_guid = ev_app_obj_guid
TABLES
item_app_obj = item_approval_obj.
ls_approval_item-approval_object_guid = ev_app_obj_guid.
APPEND ls_approval_item TO lt_approval_items.
ENDIF.
ENDIF. "2nd approval step
*** 3 step approval - 3rd step executed
*** we want to execute the 3rd step only for shopping carts with a
*** value exceeding a certain limit
IF actual_approval_index LE 3
AND ls_header-total_value GE c_3_step_limit.
* 3rd level: item category is evaluated
CLEAR ls_item_app_obj.
ls_item_app_obj-sc_guid = ls_header-guid.
* find out if there's a specific definition for that product category
READ TABLE lt_appr_def INTO ls_approval_def
WITH KEY app_crit_name1 = c_prod_categ
app_crit_value1 = ls_item-category_id.
IF sy-subrc = 4.
*** ceck if there is a default entry (similar to 2nd step)...
lv_call_value1 = 'OTHERS'.
READ TABLE lt_appr_def INTO ls_approval_def
WITH KEY app_crit_name1 = c_prod_categ
app_crit_value1 = lv_call_value1.
ELSE.
MOVE ls_item-category_id TO lv_call_value1.
ENDIF.
IF sy-subrc = 0.
*** if a definition (either specific or not) is found and we can fill a
*** new entry in the approval object table or find the corresponding one
CALL FUNCTION 'BBP_WFL_DIN_APP_OBJ_GET'
EXPORTING
sc_guid = ls_header-guid
criterion1 = c_prod_categ
value1 = lv_call_value1
iv_item_value = ls_item-value
iv_add_value = 'X'
IMPORTING
approval_obj_guid = ev_app_obj_guid
TABLES
item_app_obj = item_approval_obj.
ls_approval_item-approval_object_guid = ev_app_obj_guid.
APPEND ls_approval_item TO lt_approval_items.
ENDIF.
ENDIF. " 3rd approval step
ENDLOOP.
* now fill the approver for the different approval definitions
* 1st approval step executed for indices 1 and 0
IF actual_approval_index LE 1.
*** fill the approver table lt_approver using the guid/key combination
*** from the item approval object table to assign the approval object
*** guid to the approvers specified for the key in the definition table
*** the hide items flag specifies, that for those steps where it is set
*** the approver can only see the items of their responsibility
CALL FUNCTION 'BBP_WFL_DIN_FILL_APPROVER'
EXPORTING
iv_approval_index = 1
ic_step_description = c_item_value_desc
iv_criterion1 = c_item_value
iv_hide_items_flag = 'X'
TABLES
it_approval_def = lt_appr_def
it_approval_object = item_approval_obj
et_approver = lt_approver
it_approval_items = lt_approval_items.
ENDIF.
* 2nd aproval step executed for actual indices 1, 2 and 0
IF actual_approval_index LE 2.
*** fill approvers for 2nd step
CALL FUNCTION 'BBP_WFL_DIN_FILL_APPROVER'
EXPORTING
iv_approval_index = 2
ic_step_description = c_cost_centre_desc
iv_criterion1 = c_cost_centre
TABLES
it_approval_def = lt_appr_def
it_approval_object = item_approval_obj
et_approver = lt_approver
it_approval_items = lt_approval_items.
ENDIF.
IF actual_approval_index GT 2 AND
ls_header-total_value LT c_3_step_limit.
*** 2 step approval if value is less than c_3_step_limit
no_further_approval_needed = 'X'.
ELSEIF actual_approval_index LE 3
AND ls_header-total_value GE c_3_step_limit.
*** 3 step approval - 3rd step executed
CALL FUNCTION 'BBP_WFL_DIN_FILL_APPROVER'
EXPORTING
iv_approval_index = 3
ic_step_description = c_prod_categ_desc
iv_criterion1 = c_prod_categ
TABLES
it_approval_def = lt_appr_def
it_approval_object = item_approval_obj
et_approver = lt_approver
it_approval_items = lt_approval_items.
ELSEIF actual_approval_index GT 3.
*** we don't define more than 3 steps
no_further_approval_needed = 'X'.
ENDIF.
item_approval_table[] = lt_approval_items[].
approval_table[] = lt_approver[].
ENDIF. " value less than "c_no_approval"
WHEN c_po.
* --------------------- purchase order ---------------------------- *
** 08/15 implementation - well at least this shows it's not the
** auto-approval work flow ruinning
*
* IF actual_approval_index LE 1.
* ls_approval_agent-approval_branch = 1.
* ls_approval_agent-initial_index = 1. " Index = 1
* ls_approval_agent-initial_agent = 'MANAGER2'.
* ls_approval_agent-approval_state = c_wf_not_instanced.
* APPEND ls_approval_agent TO lt_approval_init_agents.
* ENDIF.
*
* IF actual_approval_index LE 2.
* ls_approval_agent-approval_branch = 1.
* ls_approval_agent-initial_index = 2. " Index = 2
* ls_approval_agent-initial_agent = 'MANAGER10'.
* ls_approval_agent-approval_state = c_wf_not_instanced.
* APPEND ls_approval_agent TO lt_approval_init_agents.
* ls_approval_agent-approval_branch = 1.
* ls_approval_agent-initial_index = 2. " Index = 2
* ls_approval_agent-initial_agent = 'MANAGER5'.
* ls_approval_agent-approval_state = c_wf_not_instanced.
* APPEND ls_approval_agent TO lt_approval_init_agents.
* ENDIF.
*
* IF actual_approval_index LE 3.
* ls_approval_agent-approval_branch = 1.
* ls_approval_agent-initial_index = 2. " Index = 3
* ls_approval_agent-initial_agent = 'MANAGER44'.
* ls_approval_agent-approval_state = c_wf_not_instanced.
* APPEND ls_approval_agent TO lt_approval_init_agents.
* ENDIF.
** 1) Evaluate the list of spending limit approvers from BOR
** attributes
swf_create_object lo_new_instance object_type guid.
swf_get_property lo_new_instance 'SLManagerUserList'
lt_approval_agent_obj[].
lv_index = 1.
LOOP AT lt_approval_agent_obj INTO ls_wa_agent_obj.
swf_get_property ls_wa_agent_obj 'User' lo_user.
swf_get_property lo_user 'NameWithLeadingUS'
ls_approval_agent-approval_agent.
swf_get_property lo_user 'Name' lv_usr01_name.
MOVE lv_usr01_name TO ls_approval_agent-name.
ls_approval_agent-approval_index = lv_index.
ls_approval_agent-approval_branch = 1.
ls_approval_agent-initial_index = lv_index.
ls_approval_agent-initial_agent =
ls_approval_agent-approval_agent.
ls_approval_agent-approval_state = c_wf_not_instanced.
APPEND ls_approval_agent TO lt_approval_init_agents.
lv_index = lv_index + 1.
ENDLOOP.
*** 2) Evaluate the list of remaining approvers. The actual approver
*** belongs to the list as well.
LOOP AT approval_history_table INTO
ls_wa_approval_history WHERE type <> 'I'.
LOOP AT lt_approval_init_agents INTO
ls_wa_approval_init_agents.
IF ls_wa_approval_init_agents-approval_index LT
ls_wa_approval_history-approval_index.
DELETE lt_approval_init_agents.
ENDIF.
ENDLOOP.
ENDLOOP.
* fill the import table
CLEAR ls_wa_approval_init_agents.
LOOP AT lt_approval_init_agents INTO
ls_wa_approval_init_agents.
CLEAR ls_wa_approval_history.
MOVE-CORRESPONDING ls_wa_approval_init_agents TO
ls_wa_approval_history.
APPEND ls_wa_approval_history TO approval_table.
ENDLOOP.
IF approval_table[] IS INITIAL.
no_further_approval_needed = 'X'.
ENDIF.
* fill administrators for WIs with missing approver assignment:
CLEAR ls_approver.
ls_approver-approval_agent = 'USADMIN1'.
APPEND ls_approver TO approval_administrators.
ls_approver-approval_agent = 'USADMIN2'.
APPEND ls_approver TO approval_administrators.
* approval_table[] = lt_approver[].
* ----------------------- contract -------------------------------- *
WHEN c_contract.
* to be implemented
CALL FUNCTION 'BBP_WFL_DIN_EXAMPLE_APPROVAL'
IMPORTING
et_approval_agents = approval_table[].
* --------------------- quotation ---------------------------------- *
WHEN c_quotation.
ls_approver-approval_description = '1st Approval'.
ls_approver-approval_index = 1.
ls_approver-approval_branch = 1.
* ls_approval_agent-initial_index = 1.
ls_approver-approval_agent = 'USMANAGER11'.
ls_approver-name = 'Karina Manager11'.
* ls_approval_agent-approval_state = c_wf_not_instanced.
APPEND ls_approver TO lt_approver.
ls_approver-approval_index = 1.
ls_approver-approval_branch = 1.
* ls_approval_agent-initial_index = 1.
ls_approver-approval_agent = 'USMANAGER10'.
ls_approver-name = 'Armin Manager10'.
* ls_approval_agent-approval_state = c_wf_not_instanced.
APPEND ls_approver TO lt_approver.
ls_approver-approval_description = '2nd Approval'.
ls_approver-approval_index = 2.
ls_approver-approval_branch = 1.
* ls_approval_agent-initial_index = 2.
ls_approver-approval_agent = 'USMANAGER44'.
ls_approver-name = 'Paola Manager44'.
* ls_approval_agent-approval_state = c_wf_not_instanced.
APPEND ls_approver TO lt_approver.
ls_approver-approval_description = '3rd Approval'.
ls_approver-approval_index = 3.
ls_approver-approval_branch = 1.
* ls_approval_agent-initial_index = 2.
ls_approver-approval_agent = 'USMANAGER2'.
ls_approver-name = 'Arnold Manager2'.
* ls_approval_agent-approval_state = c_wf_not_instanced.
APPEND ls_approver TO lt_approver.
approval_table[] = lt_approver[].
ENDCASE.
Hope this will help.
Please reward suitable points, incase it suits your requirements.
Regards
- Atul
Hi
<u>Refer to this OSS Consulting Note.</u>
<b>Note 731637 - Consulting: How can the item-based approval be used?</b>
<u>Some function modules of interest here are -></u>
<b>SWW_WI_HEADER_READ
SWP_TOP_LEVEL_WORKFLOW_GET
SWP_WORKFLOW_HEADER_READ
SWD_GET_WFD_ID
SWW_WIS_HEADER_READ
SWD_WF_DEFINITION_NODE_GET
SAP_WAPI_WORKITEMS_TO_OBJECT</b>
Hope this will help.
Please reward suitable points, incase it suits your requirements.
Regards
- Atul
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.