Skip to Content
avatar image
Former Member

Function Module to calculate the pending Hours in Workflow

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Jan 08, 2015 at 04:37 AM

    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


    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 07, 2015 at 09:50 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 06, 2015 at 10:48 AM


    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

  • Jan 06, 2015 at 10:36 AM

    hi

    There is a tool for workload analysis SWI5

    Does this conform to your requirement?

    Kind regards, Rob Dielemans

    Add comment
    10|10000 characters needed characters exceeded

    • 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!

  • avatar image
    Former Member
    Jan 06, 2015 at 10:59 AM

    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

    Add comment
    10|10000 characters needed characters exceeded