cancel
Showing results for 
Search instead for 
Did you mean: 

Function Module to calculate the pending Hours in Workflow

0 Kudos

Hi All,

I have the Scenario, that i want to calculated the Pending Hours in workflow still the PO created is approved. I want the Standared Function Module

For Calculating the Pending Hours in Workflow. Can you help me in finding the right Fn. Module.

Accepted Solutions (1)

Accepted Solutions (1)

I042439
Employee
Employee
0 Kudos

Hi Gokul

I would definitely go by Karri's response above!! SWI2_DURA is a good tcode to be utilized!

But if you want to still get the hands into your 'own' ABAP code, you can follow the following approach

1) Use FM SAP_WAPI_WORKITEMS_TO_OBJECT to get the latest workitem related to your PO (search SCN on how to use this FM - you will get a lot of posts). The table WORKLIST will hold the workitems. Pick the latest one based on WI_CD and WI_CT (creation date and time)

You will get the latest workflow related to your PO (whether completed or not) - the record above is the main workflow record and WORKLIST-WI_ID is the work item ID of the Main WF

2) Use FM SAP_WAPI_GET_DEPENDENT_WIS to get the sub work items of your main workflow (pass WORKITEM_ID = WORKLIST-WI_ID from above , DIRECT_DEPENDANTS_ONLY ='X' considering that the emails are not part of any sub-workflow)

You will get the workitems in table ITEMS. Sort them by WI_RH_TASK (keep only the TSxxxxxxxx of your mail steps).

First Look for your TSxxxxxxxx of your "to be approved email" - WI_CD and WI_CT will give the creation date and time of the Work item of this email

Second look for TSxxxxxxxx of your "Approved Email" if found - WI_CD and WI_CT will give the creation date and time of the Work item of this email.If not found AND the Main WF Status WORKLIST-WI_STAT <> COMPLETED, this means that it is pending - so use SY-DATUM to get the time difference

Now, this can cost you performance if the PO's are too large in number. Calling the above will cost multiple DB hits for every PO in your Report. Alternatively, you can use DB tabs behind these FMs:

1) Get PO workflows using table SWW_WI2OBJ - PO Number to Workitem ID

2) Get the Child Workitems of the Main WF WI ID from SWWWIHEAD where WI_CHCKWI = Main WF ID (also filter on Task ... where WI_RH_TASK = your mail Step tasks). you can use WI Creation Date and Times or Completion Date and times for calculations, all are available in SWWWIHEAD

Regards,

Modak


0 Kudos

Hi All,

I have written the Code like This, The Workflow is Triggering Correctly when i create or change PO in ME22n i am not getting the workitem value in it_worklist[].

Can you Check the Code and let me know the Correct Format.

SELECTION-SCREEN BEGIN OF BLOCK b1.

PARAMETERS p_inst TYPE sibflporb-instid OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b1.

CLEAR: it_worklist.

CLEAR o_obtype.
o_obtype-catid = 'BO'.
o_obtype-typeid = 'BUS2012'.
o_obtype-instid = p_inst.


IF o_obtype IS INITIAL.
   CALL FUNCTION 'SAP_WAPI_WORKITEMS_TO_OBJECT'
     EXPORTING
       object_por               = o_obtype
       top_level_items          = 'X'
       selection_status_variant = '0001'
       time                     = ls_time
       output_only_top_level    = 'X'
       determine_task_filter    = space
     TABLES
       task_filter              = lt_task_filter
       worklist                 = it_worklist[].
ELSE.
   CALL FUNCTION 'SAP_WAPI_WORKITEMS_TO_OBJECT'
     EXPORTING
       object_por               = o_obtype
       top_level_items          = space
       selection_status_variant = '0001'
       time                     = ls_time
       output_only_top_level    = 'X'
     TABLES
       task_filter              = lt_task_filter
       worklist                 = it_worklist[].
ENDIF.


*lt_worklist-wi_id = '495105'.
LOOP AT it_worklist INTO wa_worklist.

   CALL FUNCTION 'SAP_WAPI_READ_CONTAINER'
     EXPORTING
       workitem_id                    = wa_worklist-wi_id
*   LANGUAGE                       = SY-LANGU
*   USER                           = SY-UNAME
* IMPORTING
*   RETURN_CODE                    =
     TABLES
       simple_container               = lt_container.
*   message_lines                   = lt_message_lines
*   message_struct                  = lt_message_struct
*   subcontainer_bor_objects        = lt_subcontainer_bor_objects
*   subcontainer_all_objects        = lt_subcontainer_all_objects.
   APPEND LINES OF it_worklist TO it_final.

ENDLOOP.

former_member186746
Active Contributor
0 Kudos

Hi,

Why don't you use Object type and object key to retrieve workitems.

Kind regards, Rob Dielemans

I042439
Employee
Employee
0 Kudos

use selection_status_variant as 0000 - all instances (this will also pickup completed ones)

Answers (4)

Answers (4)

Former Member
0 Kudos

There are some really good hints for you about how to get the things done. In addition of others' instructions I would also recommend that you stop for a while and think what you really want to achieve. What information do you really need and from where can you get it? Sometimes you do not even need to get the information from the workflow / container / step history or whatever.

Sometimes you can read the necessary data directly from the application tables. For example check when the PO was created, and then find the time stamp when it was approved (status was changed or whatever). There is your duration. Or if it is a really simple workflow: email is sent then then approval work item is created to the approver. Why not read the work item creation and completion times directly from work item header table SWWWIHEAD. Of course you will get few milliseconds different results in this way compared to checking the email sending steps...

You could also take a look to SWI2_DURA transaction. It gives nice statistics of work item completion times etc.

Regards,

Karri

Former Member
0 Kudos

Hi Gokul,

I don't think so any standard FM for your requirement if i am not wrong.

But you can go for custom FM .

You can get the workflow details from below 3 tables.

SWW_CONT - Container Contents for Work Item Data Container

SWW_CONTOB - Container Cont. for Work Item Data Container (Only Objects

SWWWIHEAD - Header Table for all Work Item Types

you can write logic on your own based on workitem created time and approved time

if you know the workitem id.

Thanks,

Marimuthu.K

anjan_paul
Active Contributor
0 Kudos


Hi,

  you can create a custom fm , where you can read PO creation date from PO table.

After  that check in EREV table for    Released  On    field. And difference is pendin hours

0 Kudos

Hi Anjan,

Thanks for your Reply, But I want to calculate the pending hours Between the mail to be Approved and the mail had been Approved for the created PO. The time Delay in between the Approval of Created Po Mail.

Message was edited by: Gokul K

former_member185167
Active Contributor
0 Kudos

Hello,

Avoid accessing SAP tables directly. Try it with SAP_WAPI_READ_CONTAINER.

What is it that you want, the length of time it took for an approval of a workitem?

regards

Rick Bakker

0 Kudos

Hi All,

My workflow is correct. but i need to display the workitem PO, Date, Approver, Status nd Pending Hours in report format. Before using SAP_WAPI_READ_CONTAINER i need to use one satandard Function module.. I need that Function Module name and also how to display the Workitem Value in Report Format.

former_member185167
Active Contributor
0 Kudos

Hello,

It's unlikely that a standard function module will do exactly what you want.

Create your own fm or method that calls SAP_WAPI_READ_CONTAINER and/or DURATION_DETERMINE.

regards

Rick

former_member186746
Active Contributor
0 Kudos

hi

There is a tool for workload analysis SWI5

Does this conform to your requirement?

Kind regards, Rob Dielemans

0 Kudos

Hi Rob,

I am New to Workflow, so kindly tell me in breif.

What is the Standard Function Module for Calculating the Pending Hours..

I need the Function Module Name..

Jocelyn_Dart
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Gokul,

Function module DURATION_DETERMINE should be sufficient for your needs to calculate the difference between a start and end date/time and will work with or without a factory calendar.  It's from the same function group as END_TIME_DETERMINE which we usually use to calculate deadlines. 

Oldies but goodies!