Quantcast
Channel: SCN : Document List - SAP Business Workflow
Viewing all 38 articles
Browse latest View live

Sending reminder mail continously in workflow

$
0
0

Requirement : An agent is getting the work item , but he/she is not approving / rejecting the same, in this case system is keep on sending the reminder mail in every 12 hours until he / she act on the workitem. Once the workitem is approved / rejected  then only the control pass to the next step. Please find the template below followed by the step description

 

wf.jpg

Before the release step , I added a fork having two parallel branch with one necessary branch. In one of the branch I put the release step and rest of the operation and in another branch created an infinite loop step within this loop created a dummy method and two mail step ( one to SAP inbox and the second one to External mail ). In dummy method , I selected the Requested Start tab and put the work item creation and time after 12 hrs. ( please see the below screen shot ).

So whenever the Agent approve / reject the work item the fork will end OR every 12 hours the mail is keep on sending mail to the agent ( to sap inbox as well as external mail ) as a reminder until he approved/rejected the work item

t.jpeg


Table Driven Dynamic Parallel processing

$
0
0

Hello,

 

In this blog I would try to showcase a simple scenario which I have resolved with table driven dynamic parallel processing approach.

Definitely this scenario can't be a production scenario. But I would expect going through the blog, would help to build some basic idea about this dynamic processing approach for Workflow beginners.

 

Scenario:Trigger workflow with multiple Sales Orders. Depending on the Sales Org, agent will be determined dynamically and work item will be sent to the concerned agent. After receiving the work item, agent can display the sales order. Part - 1

 

A Z program which will be executed with multiple Sales Orders and based on the Sales Org , work item will be distributed to different agent as determined dynamically.

 

Therefore three things I will address here:

 

1. Design a Work flow template using  a 'Block' step (Tcode -: SWDD)

2. Create dynamic agent determination rule to determine agent to whom Work Item should be sent for. (Tcode: PFAC)

3. ABAP program to trigger the workflow created in step 1 (SE38 , Z Program)


Step 1: Design a Workflow Template using a block step as shown below


Workflow Template -1.PNG

In this Scenario, as I said, I will be running the workflow with two Sales Orders. Used the BOR Object as BUS2032.

The template contains the basic items as below:

1. Block Step

2. User Decision Step

3. Task to perform some activities (In this case , display the sales order)

 

Assumption: Though , target audience here are workflow beginners, still I assume reader should have some basic knowledge about workflow building.

So no point to display all the steps as that would make the information bit clumsy.

 

A) Creating container element

     I have a workflow container as below with Import and Multiple Check box as checked. The purpose of this workflow container is to contain

the given multiple sales order information.

 

Workflow Template -4.PNG

B) Use a Block step as below:

 

Create a new block step with below settings:

Workflow Template -2.PNG

I have taken block type as P (ParForEach), also in Parallel Processing tab I have Selected BUS2032 as Multiline Element.

 

Workflow Template -3.PNG

C) Creating a user Decision step as below:

 

Workflow Template -4.PNG

Here I have created the Title as 'Do you want to display Sales Order &1', and at the same time selected the Parameter 1 as &_BUS2032_LINE.SALESDOCUMENT&. You may noticed , I have used the Agent determination rule 95000010, which I will describe later.

 

 

As workflow container element "BUS02032" (Check Step 'A' ), will behave like an internal table , so line value is nothing but the work area is being passed to Rule determination procedure. Based on the line value (Sales Order Number ) , we will determine the Sales Org value of the document, and as per predefined rule I will determine the agent to whom the work item needs to be sent.

 

D. Create agent determination rule in transaction code "PFAC" as below:

 

Workflow Template -4.PNG

I have created a custom function module to determine the agent as shown in the above screen shot. The underlined coding in the function module is attached here.

 

Now the important part is the binding. Means binding workflow container with task as well the rule. I have shown below:

Workflow Template -4.PNG

Workflow Template -4.PNG

E. Now I have used the "display" method of the business object BUS2032 to display the sales order content as below.

Workflow Template -4.PNG

F. The workflow development is complete and now it is to be tested through SWUS. In my continuation blog I would execute this WF through SE38 program.

 

Workflow Template -4.PNG

Executing the workflow with given data will generate two different work items and based on the Sales Org , the work item will be assigned to the concerned agent.

Workflow Template -4.PNG

That's All. I would appreciate if you can provide your feedback and suggestion if any better option / solution is possible to this scenario.

 

- Thanks , Somnath


Canceling or changing decision options dynamically

$
0
0

This is an example of how to implement note 1648822 - Dynamic user decision which allows for the decision options to be changed. This example was used in a workflow which was basically a loop on a table of approvers, where the workflow goes up and down the list according to the user's decision, to set the decision option text and to remove the rejection option from the first approver (he/she has no one reject to…).

In this example 'level' is used as the current workflow level in the workflow container, 'LevelNeeded' is the number of approvers needed, it and the approvers list was calculated before the workitem started.

 

The use of this note enabled the approvers to be set dynamically, and to simplicity the workflow actually replacing more then a dozen workflow templates with a single one.

 

For example, the same workflow template was used for:

  • Requester->manager.
  • Requester->manager->CFO.
  • Requester->manager->Legal department->CFO.

 

The manager approval option can show:

  • Approve
  • approve and send request to CFO
  • approve and send request to legal department

according to the next step description.

 

In the implementation of method if_swf_ifs_workitem_exit~event_raised

 

IF im_event_name = 'BEF_DECI'.

 

Get the defined decision alternatives

CALL METHOD im_workitem_context->get_decision_alts

  IMPORTING

     et_decialts = lt_dec_alts

 

Get the workitem container

CALL METHOD im_workitem_context->get_wf_contianer

   RECEIVING re_container = lo_wf_container

 

Get data from the workitem contianer

CALL METHOD lo_wf_container->get

  EXPORTING

     name = 'Level'

  IMPORTING

     value = lv_level

 

CALL METHOD lo_wf_container->get

  EXPORTING

      name = 'LevelNeeded'

  IMPORTING

     value = lv_level_needed

 

Call method lo_wf_container->get

  EXPORTING

     name = 'Approvers'

  IMPORTING

     value = lt_approvers

 

Delete the reject option for the first approver

IF lv_level = 1.

  DELETE lt_dec_alts WHERE altkey = '0002'.

ENDIF.

 

Change the approval text

IF lv_level < lv_level_needed.

   lv_next_level = lv_level + 1.

   READ TABLE lt_approvers INDEX  lv_next_level INTO ls_approver.

   CONCATENATE text-001 "Approve and send to

                            ls_approver-decsription

                    INTO ls_dec_alt-alttext separated by space.

   MODIFY TABLE lt_dec_alts  FROM ls_dec_alt INDEX 1 TRANSPORTING alttext .

ENDIF.

 

Set the changed decision options 

CALL METHOD im_workitem_context->set_decision_alts

  EXPORTING

      et_decialts = lt_dec_alts

Mail attachment from PDF Spool request in SAP Workflow

$
0
0

Requirement : Once the release of the  PO is completed ( after released all level ) the PDF output of the particular PO has to send the PR creator and department head  as attachment.

 

spool.PNG

The code for getting the spool request is as follows

*fetching the spool request.

select single rqident

from TSP01

into l_rqident

where rqtitle = object-key-purchaseorder.

if sy-subrc = 0.

spool_generate = 'X'.

endif.

SWC_SET_ELEMENT CONTAINER 'spool_generate' SPOOL_GENERATE.

 

Step 2 : As the spool request generation will take some time , put the wait step with condition that until spool is getting generated ( &spool_generate& = 'X'. )

 

Step 3 : Create step ( activity ) for attaching the PO.

 

The code is as below.

begin_method pomail_attach changing container.

DATA:

   po_number TYPE ekko-ebeln,

   mail_id   TYPE TABLE OF adr6-smtp_addr.

swc_get_element container 'PO_NUMBER' po_number.

swc_get_table container 'MAIL_ID' mail_id.

 

CALL FUNCTION 'ZMM_PO_EMAIL_ATTACHMENT'

   EXPORTING

     i_ebeln = po_number

   TABLES

     i_email = mail_id. " mail id  of PR creator and dept. head.


   end_method.

 

Find the detailed code of above FM.


FUNCTION zmm_po_email_attachment.

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  IMPORTING

*"     VALUE(I_EBELN) TYPE  EKKO-EBELN OPTIONAL

*"  TABLES

*"      I_EMAIL STRUCTURE  ZMM_MAILID

*"----------------------------------------------------------------------

   TABLES: tsp01.

   "------------------------------------------------------------

   " Constants Declarations

   "------------------------------------------------------------

   CONSTANTS: lc_pdf        TYPE char3      VALUE 'PDF',

              lc_obj_name   TYPE so_obj_nam VALUE 'PDF', "'SCRIPT',

              lc_express    TYPE char1      VALUE 'X',

              lc_rec_type   TYPE char1      VALUE 'U',

              lc_sensitivty TYPE so_obj_sns VALUE 'F',

              lc_doc_type   TYPE so_obj_tp  VALUE 'RAW',

              lc_in_out     TYPE sonv-flag  VALUE 'X',

              lc_no(1)      TYPE c          VALUE ' ',

              lc_device(4TYPE c          VALUE 'LOCL'.

   "------------------------------------------------------------

   " Internal Tables Declarations

   "------------------------------------------------------------

   DATA : lint_objpack    TYPE TABLE OF sopcklsti1,

          lint_objbin     TYPE TABLE OF solisti1,

          lint_objtxt     TYPE TABLE OF solisti1,

          lint_reclist    TYPE TABLE OF somlreci1,

          lint_pdf_output TYPE TABLE OF tline.

*         lint_mess_att   TYPE TABLE OF solisti1.

   "------------------------------------------------------------

   " Work Area Declarations

   "------------------------------------------------------------

   DATA : lfs_objpack    TYPE sopcklsti1,

          lfs_objbin     TYPE solisti1,

          lfs_objtxt     TYPE solisti1,

          lfs_reclist    TYPE somlreci1,

          lfs_doc_chng   TYPE sodocchgi1,

          lfs_tsp01      TYPE tsp01,

          lfs_pdf_output TYPE tline,

          lfs_mess_att   TYPE solisti1.

 

   "------------------------------------------------------------

   " Local Varaibles Declarations

   "------------------------------------------------------------

   DATA : lwf_lines_txt TYPE i,

          lwf_lines_bin TYPE i,

          lwf_buffer    TYPE string,

          p_spoolid     TYPE rspoid,

          p_partnum     TYPE adsnum VALUE '1',

          p_pdf         TYPE fpcontent,

          p_pages       TYPE i,

          so_solixtab   TYPE solix_tab,

          p_pdf_file    TYPE string.

   "------------------------------------------------------------

   " Logic started..

   "------------------------------------------------------------

   IF i_ebeln IS NOT INITIAL

   AND i_email[] IS NOT INITIAL.

** To get the spool no from the purchase document number..

     SELECT SINGLE *

       FROM tsp01

       INTO lfs_tsp01

       WHERE rqtitle = i_ebeln.

     IF sy-subrc = 0.

       p_spoolid = lfs_tsp01-rqident.

       PERFORM create_pdf_from_spool  IN PROGRAM saplfpcomp  USING p_spoolid

                                           p_partnum

                                  CHANGING p_pdf

                                           p_pages

                                           p_pdf_file.

       IF sy-subrc = 0.

*--->Convert xstrin to solix

         so_solixtab = cl_bcs_convert=>xstring_to_solix( p_pdf ).

       ENDIF.

 

       "--------------------------------------------------------

       "  To add the recipients email address

       "---------------------------------------------------------

       LOOP AT i_email .

         lfs_reclist-receiver = i_email.

         lfs_reclist-express  = lc_express.

         lfs_reclist-rec_type = lc_rec_type.

         APPEND lfs_reclist TO lint_reclist.

         CLEAR  lfs_reclist.

       ENDLOOP.

       "--------------------------------------------------------

       " Mail Content

       "--------------------------------------------------------

** for Header

       lfs_objtxt = 'Dear User,'.

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

** For space

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

** For content

       CONCATENATE 'Purchase order : ' i_ebeln ', has been approved.' INTO lfs_objtxt.

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

** For space

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

** For footer

       lfs_objtxt = 'This is an auto generated email, please do not reply.'.

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

       "------------------------------------------------------------

       " Mail Header

       "------------------------------------------------------------

       DESCRIBE TABLE lint_objtxt LINES lwf_lines_txt.

       lfs_doc_chng-obj_name   = lc_obj_name.

       lfs_doc_chng-obj_langu  = sy-langu.

       CONCATENATE 'Purchase order: ' i_ebeln ', has been approved' INTO lfs_doc_chng-obj_descr.

       lfs_doc_chng-sensitivty = lc_sensitivty.

       lfs_doc_chng-doc_size   = 1.

       "------------------------------------------------------------

       " Pack to main body as RAW.

       "------------------------------------------------------------

       CLEAR lfs_objpack-transf_bin.

       lfs_objpack-head_start = 1.

       lfs_objpack-head_num   = 0.

       lfs_objpack-body_start = 1.

       lfs_objpack-body_num   = lwf_lines_txt.

       lfs_objpack-doc_type   = lc_doc_type.

       APPEND lfs_objpack TO lint_objpack.

       "------------------------------------------------------------

       " Packing as PDF.

       "------------------------------------------------------------

       CLEAR lwf_lines_bin.

**      DESCRIBE TABLE lint_mess_att LINES lwf_lines_bin.

       DESCRIBE TABLE so_solixtab LINES lwf_lines_bin.

       lfs_objpack-transf_bin = abap_true.

       lfs_objpack-head_start = 1.

       lfs_objpack-head_num   = 1.

       lfs_objpack-body_start = 1.

       lfs_objpack-body_num   = lwf_lines_bin.

       lfs_objpack-doc_type   = lc_pdf.

       CONCATENATE 'Purchase order: ' i_ebeln ', has been approved' INTO lfs_objpack-obj_name.

       CONCATENATE 'Purchase order' ':' i_ebeln INTO lfs_objpack-obj_descr.

**

       lfs_objpack-doc_size = lwf_lines_bin * 255.

       APPEND lfs_objpack TO lint_objpack.

       "------------------------------------------------------------

       " To send the smartform as attachment in Mail to the above receipent

       "------------------------------------------------------------

       CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

         EXPORTING

           document_data              = lfs_doc_chng

           put_in_outbox              = lc_in_out

         TABLES

           packing_list               = lint_objpack

           contents_hex               = so_solixtab

           contents_txt               = lint_objtxt

           receivers                  = lint_reclist

         EXCEPTIONS

           too_many_receivers         = 1

           document_not_sent          = 2

           document_type_not_exist    = 3

           operation_no_authorization = 4

           parameter_error            = 5

           x_error                    = 6

           enqueue_error              = 7

           OTHERS                     = 8.

       IF sy-subrc = 0.

         COMMIT WORK.

       ENDIF.

     ENDIF.

   ENDIF.

 

ENDFUNCTION.

Workflow problems? Read this first!

$
0
0

Attention SAP Business Workflow fans!

 

If you are having a SAP Workflow problem, please take a few minutes to do these simple checks.

 

It could save you (and us) a lot of time. Almost every day we at the SAP Business Workflow forum

get a lengthy thread describing bizarre errors which leave us scratching our heads until it's revealed on page 3

that, oh, WF-BATCH only has the SAP_NOOB role or that, oops, the Deadline job isn't running in SWU3.

 

After you have checked and tried all of these suggestions, please feel free to post your question

- we're always keen to see interesting new problems that we may well encounter ourselves next week.

Please indicate that you have made these basic checks. Let me know with a Like or a Comment if

this document did indeed solve your problem.

 

I'll keep updating this document with more checks as time goes on. Suggestions are very welcome!

I will try to put the checks in order of usefulness.

 

This is not a FAQ (Frequently Asked Questions), more like an FPS (Frequently Provided Solutions).

I'll keep it brief because you have a problem to solve.

 

 

1. SWU_OBUF

This solves the most problems of all, especially after a change or a transport. Try it, it can't hurt.

swu_obuf.jpg

Now try again.

 

2. General Task

Many people set Decision Tasks to General Task but this may not get transported with the task, depending

on your system settings. Result: nobody is receiving that workitem. Compare the source and target system.

One way to check for General Task: transaction PFTC_DIS, enter TS number

pftc_dis.jpg

Click on the spectacles then Additional data > Agent assignment > Display

gen_task.jpg

 

3. ST22 - short dumps

Always worth checking for shortdumps in transaction ST22 if you're having strange problems, especially a background workflow step staying in status "In Process". Look for user WF-BATCH.

 

4. WF-BATCH settings

It's amazing the variety of problems you can get if WF-BATCH doesn't have full privileges. Do everyone a favour and check that it has SAP_ALL and SAP_NEW. One way to do this is by looking in transaction SU01D for user WF-BATCH and check the Profiles tab:

batch.jpg

If you don't have access to SU01D then have cheeky look in SE16 at table UST04 where BNAME = 'WF-BATCH' .

 

While you're looking at WF-BATCH, check if it has an Output Device set (SU01D, tab Defaults, or table USR01 field SPLD). No need to panic if it's not set but worth trying if you're stumped. Here's a blog Sue K wrote about how that setting can really ruin your day:

Master Data will always bite you

 

 

5. SU53 - authorization problems

This is a general SAP tip that also applies to workflow. If you're having problems, check transaction SU53 to see if your userid is missing some necessary authorizations. It shows the most recently failed authorization checks so you can cut & paste it and send it to your friendly SAP Security gal or guy.

 

6. SWI1 - workflow log

If your workflow isn't doing what you want it to do then you should, of course, check the workflow log (transaction SWI1). How many times have I had to say that... The amount of information is amazing, you can (almost) see everything that  happened. For the best results, make sure you go to the Chronological Log in the View With Technical Details :

swi1.jpg

Be wary of the Graphical Log, it can't be trusted to be entirely accurate - and it gives very little information. If there's an error message in the Chronological Log and it's a bit vague then always try Extras > All Errors

(see top of picture, above).

 

7. SWU3 - the background jobs

 

At transaction SWU3, make sure the necessary workflow background jobs are running.

Under "Maintain Runtime Environment"  you should see at the very least:

swu3.jpg

If you don't have access to SWU3, you can also look in transaction SM37 for SWWERRE and SWWDHEX (deadlines).

If these jobs are not running then your workflow deadlines are useless and a temporary error could bring your workflows to a halt.

 

8. Don't forget US

A very frequent solution to posted problems is a suggestion to check if the "US" prefix was forgotten when specifying a userid as a (dynamic) workitem recipient.

 

9. The bindings, always check the bindings.

Many problems are caused by incorrect bindings, especially between the starting event and the workflow. Look at each of your bindings carefully, to make sure they are doing what you want and none have been missed.  Also check that each container element has been correctly specified as Import, Export and/or Multiline. Make sure the dataypes match as well, on each side of the binding. You are given a lot of freedom to get it wrong.

 

bind.jpg

 

To be continued...

How to (not) debug workflow background tasks

$
0
0

This is a very common question in the discussion threads and I think I read more than 5 blogs suggesting different ways to debug the workflows. However, and this is an Update following the SAP customer connection Workflow Focus topic, there should now be an easy way to debug the background tasks - see note 2197117 - Debugging of background workitems - https://service.sap.com/sap/support/notes/2197117.

If you can't implement the note, or want to try another way of solving the problem, there are a few steps you can use:

 

The first option is using the workflow log, one advantage of the workflow system is that it logs almost everything so in contrast to a regular program which you don't know exactly what has happen to the user, in the workflow you can see in importing and exporting parameters in the log. When you build your workflows remember to also add the return messages of the function modules to the log so you can have the complete picture.

Sometime you use a parameter of the business object in a rule or an internal part of the task, add it as an attribute of the object so you can see it too in the log.

 

Second step you can do is to use the test option in SWO1 and debug the method, since the background task is actually a call to an object method, debugging the method in most cases is the same as debugging the task.

 

Another option before starting to debug tasks which is useful for all background process, not just the workflows (I actually use it mainly for the SRM workflow BADIs) is using log points, it's very simple to add to your program:

Log point ID zlog_point_name SUBKEY im_object_num FIELDS field1 field2 etc.

And you will have the ability to log the data even in productions systems without using debugger. See for more detail:

Checkgroups - ABAP Development - SCN Wiki

http://help.sap.com/abapdocu_702/en/abaplog-point.htm

 

Now only if all this failed go to solutions like changing the workflow RFC destination, adding endless loops in the program etc.

SAP Workflow Transactions

$
0
0

After a number of implemented SAP Workflow projects, I build my own list of common SAP Workflow transactions (aka «tcodes»). Now it's a time to share the assets, feel free to print and use. Due to some reason, probably the security one, SAP SCN doesn't allow to upload files in PDF, thus I uploaded a PNG-version, feel free to ask a PDF-version in the comments.

 

Workflow Troubleshooting

SWU_OBUF

manual buffer refresh

SWPC

continue WF after a system crash

SWI6

show all WF instances, work item IDs by BOR/CL name & Object Key (optional)

SM12

lock, unlock the object

SWIA

work item administration (WI)

SWI2_DIAG

error diagnosis

SWWL

delete work item

SWI2_DEAD

deadline monitor

SWWL_
TOPLEVEL

delete a parent workflow with all of its child work items

SWI2_DURA

process duration

SWUD

WF diagnosis

SWI2_ADM1

find orphaned work item

SWELS

event trace

SWI5

work item per work center, job, organizational unit, position, user

SWEL

display event trace

SARA

archiving

 


 

Workflow Development

SWDD

WF builder

SWNADMIN

notification management

PFTC

template, task management (WS, TS)

SM37

view scheduled and processed jobs

PFTC_DIS

assigning possible agent

SBWP

WF inbox

PFAC

rule creation, editing, testing

SWU0

simulate the event linkage

SWO1

business object builder (BOR)

SWEQADM

event queue, preventing RFC-problem

SWUS

test, execute WF

SWB_COND

all start conditions

SWEINST

all terminating events linkage

SWU9

WF trace for the session

SWUI_
VERIFY

WF verification

SWEQBROWSER

event waiting in the event queue

SOST

SAPconnect transmission request

SWPA

customizing WF runtime system

SWNCONFIG

notification configuration

PPOM

organization & staffing

SWI1

selection report for work item

PPOME

organizational management, structure & staff assignment, user mapping

SM52

view tRFC

SWI2_FREQ

opened task statistic

 


 

ABAP Development

SE24

classes

SE11

data types, domains, tables

SE37

function modules, functions

SE09

list of change requests per SAP user

SE38

programs

SE03

change requests management

ST22

runtime error logs, dumps

STMS

change requests transferring

 

P.S. Yet another list of Useful Transactions in SAP Workflow.

Condition to start a workitem

$
0
0

Friends….

  We can put conditions to create the workitem, after creation of the workitem and after execution of the workitem.

(We can use Condition step type to validate the technical functions). (If you are not familiar with Standard task creation, check the below link

  http://scn.sap.com/blogs/anomitroguha/2012/04/11/part-3-creation-of-a-workflow-standard-task-and-binding-of-rule ).

‘Conditions’ tab in ‘Activity’ step type will perform the different types of conditions on workitems, like before starting of a workitem.

img 1.png

We have 3 types of conditions.

  1. Create workitem: When a workitem was generated, it will check the respective condition was satisfied or not? At that time the workitem status is “IN PREPARATION”, the workitem is not accessible anywhere.
  2. Complete Workitem: In this case, workitem will be generated, but it will not complete until the condition is true. The workitem will not complete until the condition evaluates to true.
  3. Complete Execution: After execution of the workitem, the condition will be evaluated and if it is true then only the workitem will complete.

Step 1:

Create a workflow container element and make it as import as mentioned below.

img 2.png

Step 2:

I have created a Task with the following details.

img 3.png

Save the task.

  1. Maintain the task as ‘General Task’ as mentioned below. Menu options --> Additional data--> Agent assignment--> Maintain.

Select the task and click on ‘Attributes’ button. Select ‘General Task’ radio button and click on ‘Transfer’.

img 4.png

Come back from the screen. Enter some text in the Task Description

img 5.png

  1. Save task & come back. Maintain possible Binding from Workflow to Task and vice versa.

In the ‘Agents’ tab of activity step, select ‘User’ and any user name as mentioned below.

img 6.png

Go to ‘condition’ tab in the activity step. We can observe three types of conditions in the screen.

  1. Create workitem
  2. Complete workitem
  3. Complete execution

img 7.png

Open ‘create work item’ tab to create a condition, if this condition is true then only workitem will create.

Click on ‘click here to create a new condition’ sentence to create the condition.

Enter the following condition

img 8.png

Note: We know the condition is false, for this step workitem will not create until the condition is true.

We can find a symbol in the 'conditions' tab as mentioned below.

img 9.png

Save, activate and execute the workflow. Provide element WI_Elem value as ‘5’ and execute.

img 10.png

It will show the agent name in the ActiveX version log but unfortunately the workitem will not be available in agent inbox. Scroll down to check user inbox.

img 11.png

In the technical details of log, we can observe a different symbol at the step and in ‘Message’ tab message text as ‘Execution Interrupted’.

img 12.png

Go and check in the agent inbox. There is no workitem from our workflow.

img 13.png

In the execution time of our workflow, if I provide the element WI_Elem value as 10, it will works fine.

img 14.png

img 15.png

After workitem execution the workflow log appears as usual.

ENJOY WORKFLOWS…..

 

Regards,

Murali Krishna.


Sending outlook mail with workitem as attachment

$
0
0

Scenario : Workflow to send notifications to outlook email id's of the approvers and send the SAP Short cut as an attachment. If the approver  clicks the attachment it will directly open the work item, the user can take appropriate action on the same.

 

Actually it is a standard functionality , we can customize the standard report RSWUWFML2 and apply the same for our custom development .

 

  • Copy the standard program RSWUWFML2
  • customize the same as below ( only the content of the attachment and body of the mail is changed ).

mail1.PNG

mail2.PNG

mail3.PNG

mail4.PNG

mail5.PNG

Output

op.PNG


Regards,

Shamsudheen.

SAP Workflow improvements - at last!

$
0
0

Good news for all Workflowers out there.

 

workflower.jpg

 

Because of the massive support for the SAP Customer Influence program by our group (thanks to Sue Keohan), I got a flurry of emails today about Workflow improvements that have been delivered. There are probably more - I didn't sign up for all of them - but I thought I'd share these. Let us know if you received notification of any others.

 

 

"Admin: Debugging-mode for background tasks", submitted by Florin Wach

Status: Delivered  https://service.sap.com/sap/support/notes/2197117

 

 

"Allow WF Administrators?Developer to forward workitems to themselves", submitted by Susan Keohan

Status: Delivered   https://service.sap.com/sap/support/notes/2188631

 

 

"Chronological View in Technical Log as a User Setting", submitted by Mark Pyc

Status: Delivered  https://service.sap.com/sap/support/notes/2188655

 

 

"Increase the number of lines in the condition editor", submitted by ?

Status: Delivered  https://service.sap.com/sap/support/notes/2185487

 

***Edited to add some more (thanks to Ronen Weisz ) :

 

Adding additional functions for _WFSYST - for example 'concatenate',  this is still a workaround but a nice effort.

https://service.sap.com/sap/support/notes/2188696

 

GOS improvements - the log will now auto-refresh and will be sorted by creation date and time!

https://service.sap.com/sap/support/notes/2184630

 

You can now navigate to the FM directly from the event linkage (SWE2)

https://service.sap.com/sap/support/notes/2185723

 

You can now enter the technical workitem display in one click.

https://service.sap.com/sap/support/notes/2186821

 

Support for agent rule in SWDC

https://service.sap.com/sap/support/notes/2191614

 

August 2015, I received some more in the mail:

 

Add workflow version to the Where-Used list

https://service.sap.com/sap/support/notes/2201971

 

Automatic alignment of the workflow model

https://service.sap.com/sap/support/notes/2201454

 

Thanks to everyone who contributed, especially those who submitted the requests in the first place.

Workflow Agent Determination Customization

$
0
0

Objective

The object of this document is to detail the process of customizing the Agent determination of a standard workflow.

 

Pre-requisite

The reader must the aware of the basic workflow design terminologies.

 

Scenario

Customer has requested for a change in the agent determination of a standard workflow such as Purchase Order Workflow or Purchase Request Workflow or leave workflow.

When the request is only specific to the customization of agent determination, it is not advisable to design a copy of the standard workflow. As this would require us to completely re-configure the workflow settings of the new workflow.

 

Illustration

 

There are two possible approach to customize agent determination of a standard workflow, which are as follows,

·        Customizing an Existing Agent Rule

·        Making a copy of the existing rule

 

Customizing an Existing Agent Rule:

For explanation purpose let us consider the standard Purchase Order workflow (WS20000075). The below steps details the process of customizing the existing rule.

  • To identify the Rule linked to the Workflow click on the task which determines the rule as shown below.

P1.jpg

  • In the Task Display screen which pops up, select the default rules tab. A line Item with “Type of Rule” as “Agent (Default Rule)” refers the default rule associated with this workflow. In this case the PO Workflow standard rule is 20000027 as shown below.

P1.jpg

  • The rule is computed based on the Function Module linked to it. To check on the function module linked with this rule, double click on the rule number. For the PO workflows FM: ME_REL_GET_RESPONSIBLE is responsible for rule determination.

P1.jpg

  • SAP follows a standard enhancement routines in case of Rule’s Function Modules and places a User Exit in each of the Function Module. In this case User exit “EXIT_SAPLEBNF_005” is provided by SAP to implement the customer requirements.

P1.jpg

  • Implementing them will enable the Customer required design to be implemented.
  • In this case SAP has configured this customer exit to be triggered only when the “Role resolution for workflow” is set to ‘9’. Which has to be maintained for Release Group/ Release Code Combination in the release code table T16FC(Also maintainable through SPRO)

Making a copy of an existing Rule:

When rule customization is not sufficient to achieve the requirement. Then a copy of the existing rule can be made and required design can be implemented. The process is as follows.

  • To create a copy or a new rule the path Tools –> Business Workflow –> Development –> Definition tools –>Rules for Agent Assignment –>Create/Change/Display is used as shown below

P1.jpg

·        Create a copy or design your own function module and link the same to newly created Rule as shown below.

        

P1.jpg

·        Once the new rule is designed and tested the same can be linked to the Agent Determination Task as shown below.

 

P1.jpg

References: 

 

http://help.sap.com

                   

How to send mail with attachment of SAP Script in Workflow

$
0
0

Scenario : Once the release of the  PO is completed ( after released all level ) the script output of the particular PO has to send the initiator as attachment.

 

Step 1 :  Create step ( activity ) in workflow for getting the spool request of the release PO .

 

spool.PNG

 

The code for getting the spool request is as follows

*fetching the spool request.

select single rqident

from TSP01

into l_rqident

where rqtitle = object-key-purchaseorder.

if sy-subrc = 0.

spool_generate = 'X'.

endif.

SWC_SET_ELEMENT CONTAINER 'spool_generate' SPOOL_GENERATE.

 

Step 2 : As the spool request generation will take some time , put the wait step with condition that until spool is getting generated ( &spool_generate& = 'X'. )

 

Step 3 : Create step ( activity ) for attaching the PO.

 

The code is as below

 

BEGIN_METHOD POMAIL_ATTCHMNT CHANGING CONTAINER.

DATA:

      MAIL_ID TYPE ADR6-SMTP_ADDR,

      PO_NUMBER TYPE EKKO-EBELN.

  SWC_GET_ELEMENT CONTAINER 'mail_id' MAIL_ID.

  SWC_GET_ELEMENT CONTAINER 'PO_Number' PO_NUMBER.

" calling FM for Mail attachment .

CALL FUNCTION 'ZMM_PO_EMAIL_ATTACHMENT'

EXPORTING

   I_EBELN       = PO_NUMBER " passing the PO

   I_EMAIL       = MAIL_ID. " passing the mail id of initiator.

END_METHOD.

 

In the above function module , I am writing the code for getting PDF output from the spool number and make the bin file and passing the same to the SO_NEW_DOCUMENT_ATT_SEND_API1. and sending the attachment with the notification. Find the detailed code below.

"------------------------------------------------------------

   " Constants Declarations

   "------------------------------------------------------------

   CONSTANTS: lc_pdf        TYPE char3      VALUE 'PDF',

              lc_obj_name   TYPE so_obj_nam VALUE 'SCRIPT',

              lc_express    TYPE char1      VALUE 'X',

              lc_rec_type   TYPE char1      VALUE 'U',

              lc_sensitivty TYPE so_obj_sns VALUE 'F',

              lc_doc_type   TYPE so_obj_tp  VALUE 'RAW',

              lc_in_out     TYPE sonv-flag  VALUE 'X',

              lc_no(1)      TYPE c          VALUE ' ',

              lc_device(4TYPE c          VALUE 'LOCL'.

   "------------------------------------------------------------

   " Internal Tables Declarations

   "------------------------------------------------------------

   DATA : lint_objpack      TYPE TABLE OF sopcklsti1,

          lint_objbin       TYPE TABLE OF solisti1,

          lint_objtxt       TYPE TABLE OF solisti1,

          lint_reclist      TYPE TABLE OF somlreci1,

          lint_pdf_output   TYPE TABLE OF tline,

          lint_mess_att     TYPE TABLE OF solisti1.

   "------------------------------------------------------------

   " Work Area Declarations

   "------------------------------------------------------------

   DATA : lfs_objpack       TYPE sopcklsti1,

          lfs_objbin        TYPE solisti1,

          lfs_objtxt        TYPE solisti1,

          lfs_reclist       TYPE somlreci1,

          lfs_doc_chng      TYPE sodocchgi1,

          lfs_tsp01         TYPE tsp01,

          lfs_pdf_output    TYPE tline,

          lfs_mess_att      TYPE solisti1.

   "------------------------------------------------------------

   " Local Varaibles Declarations

   "------------------------------------------------------------

   DATA : lwf_lines_txt     TYPE i,

          lwf_lines_bin     TYPE i,

          lwf_buffer        TYPE string.

   "------------------------------------------------------------

   " Logic started..

   "------------------------------------------------------------

   IF i_ebeln IS NOT INITIAL

  AND i_email IS NOT INITIAL.

** To get the spool no from the purchase document number..

     SELECT SINGLE *

       FROM tsp01

       INTO lfs_tsp01

      WHERE rqtitle = i_ebeln.

     IF sy-subrc = 0.

** To set the local language..

       SET LOCALE LANGUAGE sy-langu.

** To get the PDF output from the spool no..

       CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

         EXPORTING

           src_spoolid              = lfs_tsp01-rqident

           no_dialog                = lc_no

           dst_device               = lc_device

         TABLES

           pdf                      = lint_pdf_output

         EXCEPTIONS

           err_no_otf_spooljob      = 1

           err_no_spooljob          = 2

           err_no_permission        = 3

           err_conv_not_possible    = 4

           err_bad_dstdevice        = 5

           user_cancelled           = 6

           err_spoolerror           = 7

           err_temseerror           = 8

           err_btcjob_open_failed   = 9

           err_btcjob_submit_failed = 10

           err_btcjob_close_failed  = 11

           OTHERS                   = 12.

       IF sy-subrc = 0.

         "------------------------------------------------------------

         " Transfer the 132-long strings to 255-long strings

         "------------------------------------------------------------

         LOOP AT lint_pdf_output INTO lfs_pdf_output.

           TRANSLATE lfs_pdf_output USING ' ~'.

           CONCATENATE lwf_buffer lfs_pdf_output INTO lwf_buffer.

         ENDLOOP.

**

         TRANSLATE lwf_buffer USING '~ '.

         DO.

           lfs_mess_att = lwf_buffer.

           APPEND lfs_mess_att TO lint_mess_att.

           SHIFT lwf_buffer LEFT BY 255 PLACES.

           IF lwf_buffer IS INITIAL.

             EXIT.

           ENDIF.

         ENDDO.

       ENDIF.

       "------------------------------------------------------------

       " To add the recipients email address

       "------------------------------------------------------------

       lfs_reclist-receiver = i_email.

       lfs_reclist-express  = lc_express.

       lfs_reclist-rec_type = lc_rec_type.

       APPEND lfs_reclist TO lint_reclist.

       CLEAR  lfs_reclist.

       "------------------------------------------------------------

       " Mail Content

       "------------------------------------------------------------

** for Header

       lfs_objtxt = 'Dear User,'.

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

** For space

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

** For content

       CONCATENATE 'Purchase order : ' i_ebeln ', has been approved.' INTO lfs_objtxt.

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

** For space

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

** For footer

       lfs_objtxt = 'This is an auto generated email, please do not reply.'.

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

       "------------------------------------------------------------

       " Mail Header

       "------------------------------------------------------------

       DESCRIBE TABLE lint_objtxt LINES lwf_lines_txt.

       lfs_doc_chng-obj_name   = lc_obj_name.

       lfs_doc_chng-obj_langu  = sy-langu.

       CONCATENATE 'Purchase order: ' i_ebeln ', has been approved' INTO lfs_doc_chng-obj_descr.

       lfs_doc_chng-sensitivty = lc_sensitivty.

       lfs_doc_chng-doc_size   = 1.

       "------------------------------------------------------------

       " Pack to main body as RAW.

       "------------------------------------------------------------

       CLEAR lfs_objpack-transf_bin.

       lfs_objpack-head_start = 1.

       lfs_objpack-head_num   = 0.

       lfs_objpack-body_start = 1.

       lfs_objpack-body_num   = lwf_lines_txt.

       lfs_objpack-doc_type   = lc_doc_type.

       APPEND lfs_objpack TO lint_objpack.

       "------------------------------------------------------------

       " Packing as PDF.

       "------------------------------------------------------------

       CLEAR lwf_lines_bin.

       DESCRIBE TABLE lint_mess_att LINES lwf_lines_bin.

       lfs_objpack-transf_bin = abap_true.

       lfs_objpack-head_start = 1.

       lfs_objpack-head_num   = 1.

       lfs_objpack-body_start = 1.

       lfs_objpack-body_num   = lwf_lines_bin.

       lfs_objpack-doc_type   = lc_pdf.

       CONCATENATE 'Purchase order: ' i_ebeln ', has been approved' INTO lfs_objpack-obj_name.

       CONCATENATE 'Purchase order' ':' i_ebeln INTO lfs_objpack-obj_descr.

**

       lfs_objpack-doc_size = lwf_lines_bin * 255.

       APPEND lfs_objpack TO lint_objpack.

       "------------------------------------------------------------

       " To send the smartform as attachment in Mail to the above receipent

       "------------------------------------------------------------

       CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

         EXPORTING

           document_data              = lfs_doc_chng

           put_in_outbox              = lc_in_out

         TABLES

           packing_list               = lint_objpack

           contents_bin               = lint_mess_att

           contents_txt               = lint_objtxt

           receivers                  = lint_reclist

         EXCEPTIONS

           too_many_receivers         = 1

           document_not_sent          = 2

           document_type_not_exist    = 3

           operation_no_authorization = 4

           parameter_error            = 5

           x_error                    = 6

           enqueue_error              = 7

           OTHERS                     = 8.

       IF sy-subrc = 0.

         COMMIT WORK.

       ENDIF.

     ENDIF.

   ENDIF.

ENDFUNCTION.


PO on HOLD? – HOLD Workflow Triggering

$
0
0

This document explains the scenario of triggering the workflow on creation of Purchase Order (Only if the PO is having the release strategy).

The business was facing the below obstacles as mentioned

Problem Description:

  • The workflow was not working properly when the user puts the PO on Hold (with missing cost center for example).
  • Then when the user completes the PO by saving (after entering the cost center details), the workflow is not triggered.

  Assumptions: 

  • The workflow is already built and it working fine in normal scenarios as per the client requirement.
  • The problem occurred when the PO is put on hold and the saved after making necessary changes to PO.
  • The triggering event used for the workflow is BUS2012.RELEASESTEPCREATED (as it needs to be triggered only when the release strategy is there for a PO)

Observations:

As I was searching for the possible solution in the internet, programmers in most of the blogs suggested to use the BUS2012.CREATED event (will be triggered when the PO is created). But in my case I do not want to trigger my workflow each time a PO is created, the workflow has to be triggered only when the PO created and it is having a release strategy.

Let us create a PO and put it in hold status to understand the problem in better way

Transaction: ME21N (Create PO).

PO on Hold.png


 

Now the PO is in hold status, we now make some changes (not mandatory), and save the PO (as shown in screen below).

PO Saved.png

NOTE : As we can see that the PO which was kept on hold has been saved. While performing this the event BUS2012.CHANGED has been triggered and not BUS2012.CREATED. So the answer I found in the blogs to use BUS2012.CREATED as a triggering event will not work in this scenario.

 

Possible Solutions:

  1. The workflow needs to be triggered even when the PO is kept on hold with the proper data (Ex:-Findind the approver, Triggerring mail to appropriate approver, Sending work item to approver’s inbox etc..) but all these processing should begin only when the PO changed to status unhold (Changed).
  2. The workflow should not be triggered when the PO is kept on hold, it needs to be triggered only when the PO is in unhold status and the functionalities of the workflow should be unaltered.

Let us choose the second solution because it sounds simple and logical enough to implement.

As per choosen option, the first thing will be finding whether the PO is in hold status or not in table level. The EKKO (Purchasing Document Header) table is having a field MEMORY(Purchase order not yet complete), it will be having a value ‘X’ if the PO is not complete (hold).

Please find the screen below

EKKO.png

This field will be blank once the PO is changed to unhold (created successfully) status.

Ex :-

EKKO.png

Now, we are already using the triggerring event BUS2012.RELEASESTEPCREATED along with that we also need to use the event BUS2012.CHANGED.

PFTC.png

Now every time the PO is changed, the workflow will be triggered we need to control this because our intention is to triggered the PO only when the PO is not in HOLD status.

  We can use a start condition for the workflow using the field ‘Purchase Order.Release Status’ this flag will be ‘X’ if the PO is saved perfectly, otherwise it will be blank (if the PO is kept on hold status). The start condition used as follows

PFTC.png

From the change we incorporated above the workflow will not be triggered when PO is kept on hold.

In general there will be scenario the PO might required to changed after it has been created, for example updating the net amount, changing the purchase group etc..

Currently in our case workflow will be triggered everytime there is a change PO. We need to restrict this because PO change scenarios will be handled in later stages of the workflow (if we do not restrict, all these scenarios needs to handled immediately after triggering the workflow. Will be complicated).

 

To achieve this an attribute needs to be created in the delegated BOR where the flag will be set based on the changes happened to the PO.

The changes to the PO can be found on the table CDHDR (Change document header) and CDPOS (Change document items).

CDHDR.png

CDHDR.png

The workflow triggering can be stopped each time the PO is getting changed once it is saved. So will trigger the workflow based on the follwing logic.

 

Retrieving the latest change done to the PO from CDHDR

SELECT MAX( changenr )
FROM cdhdr
INTO lv_changenr
WHERE objectid = object-key “ PO number
AND   username NE ‘WF-BATCH’. “ Olny if not triggered by the system

IF sy-subrc = 0.
** Checking if the PO was on hold from CDPOS
SELECT fname
value_new
FROM cdpos
INTO TABLE lt_cdpos
WHERE objectid = object-key
AND   fname    = ‘MEMORY’ “ Field name
AND   changenr = lv_changenr  “ Value from CDHDR
AND   chngind  = ‘U’.                         “ Updated
IF sy-subrc = 0.

FLAG = abap_true.

     ELSE

FLAG = abap_false.

ENDIF.

ENDIF.

Now we will use this flag value in the workflow start condition in the CHANGE triggering event of the workflow. The WF should be triggered only when the FLAG is set to ‘X’ it means that the MEMORY field value has been changed while updating the PO.

Conclustion:

We tracked the latest changes done to the PO and in that latest change we are checking wether the PO is crated form its previous hold status. If so we are settign the flag and we are using this as a start condition. If MEMORY field is not present in the latest change we are not triggering the workflow.

NOTE : The remaining conditions can be handles based on the business requirement.

 

============================== THANK YOU =====================================

How to (not) debug workflow background tasks

$
0
0

This is a very common question in the discussion threads and I think I read more than 5 blogs suggesting different ways to debug the workflows. However, and this is an Update following the SAP customer connection Workflow Focus topic, there should now be an easy way to debug the background tasks - see note 2197117 - Debugging of background workitems - https://service.sap.com/sap/support/notes/2197117.

If you can't implement the note, or want to try another way of solving the problem, there are a few steps you can use:

 

The first option is using the workflow log, one advantage of the workflow system is that it logs almost everything so in contrast to a regular program which you don't know exactly what has happen to the user, in the workflow you can see in importing and exporting parameters in the log. When you build your workflows remember to also add the return messages of the function modules to the log so you can have the complete picture.

Sometime you use a parameter of the business object in a rule or an internal part of the task, add it as an attribute of the object so you can see it too in the log.

 

Second step you can do is to use the test option in SWO1 and debug the method, since the background task is actually a call to an object method, debugging the method in most cases is the same as debugging the task.

 

Another option before starting to debug tasks which is useful for all background process, not just the workflows (I actually use it mainly for the SRM workflow BADIs) is using log points, it's very simple to add to your program:

Log point ID zlog_point_name SUBKEY im_object_num FIELDS field1 field2 etc.

And you will have the ability to log the data even in productions systems without using debugger. See for more detail:

Checkgroups - ABAP Development - SCN Wiki

http://help.sap.com/abapdocu_702/en/abaplog-point.htm

 

Now only if all this failed go to solutions like changing the workflow RFC destination, adding endless loops in the program etc.

SAP Workflow Transactions

$
0
0

After a number of implemented SAP Workflow projects, I build my own list of common SAP Workflow transactions (aka «tcodes»). Now it's a time to share the assets, feel free to print and use. Due to some reason, probably the security one, SAP SCN doesn't allow to upload files in PDF, thus I uploaded a PNG-version, feel free to ask a PDF-version in the comments.

 

Workflow Troubleshooting

SWU_OBUF

manual buffer refresh

SWPC

continue WF after a system crash

SWI6

show all WF instances, work item IDs by BOR/CL name & Object Key (optional)

SM12

lock, unlock the object

SWIA

work item administration (WI)

SWI2_DIAG

error diagnosis

SWWL

delete work item

SWI2_DEAD

deadline monitor

SWWL_
TOPLEVEL

delete a parent workflow with all of its child work items

SWI2_DURA

process duration

SWUD

WF diagnosis

SWI2_ADM1

find orphaned work item

SWELS

event trace

SWI5

work item per work center, job, organizational unit, position, user

SWEL

display event trace

SARA

archiving

 


 

Workflow Development

SWDD

WF builder

SWNADMIN

notification management

PFTC

template, task management (WS, TS)

SM37

view scheduled and processed jobs

PFTC_DIS

assigning possible agent

SBWP

WF inbox

PFAC

rule creation, editing, testing

SWU0

simulate the event linkage

SWO1

business object builder (BOR)

SWEQADM

event queue, preventing RFC-problem

SWUS

test, execute WF

SWB_COND

all start conditions

SWEINST

all terminating events linkage

SWU9

WF trace for the session

SWUI_
VERIFY

WF verification

SWEQBROWSER

event waiting in the event queue

SOST

SAPconnect transmission request

SWPA

customizing WF runtime system

SWNCONFIG

notification configuration

PPOM

organization & staffing

SWI1

selection report for work item

PPOME

organizational management, structure & staff assignment, user mapping

SM52

view tRFC

SWI2_FREQ

opened task statistic

 


 

ABAP Development

SE24

classes

SE11

data types, domains, tables

SE37

function modules, functions

SE09

list of change requests per SAP user

SE38

programs

SE03

change requests management

ST22

runtime error logs, dumps

STMS

change requests transferring

 

P.S. Yet another list of Useful Transactions in SAP Workflow.


Condition to start a workitem

$
0
0

Friends….

  We can put conditions to create the workitem, after creation of the workitem and after execution of the workitem.

(We can use Condition step type to validate the technical functions). (If you are not familiar with Standard task creation, check the below link

  http://scn.sap.com/blogs/anomitroguha/2012/04/11/part-3-creation-of-a-workflow-standard-task-and-binding-of-rule ).

‘Conditions’ tab in ‘Activity’ step type will perform the different types of conditions on workitems, like before starting of a workitem.

img 1.png

We have 3 types of conditions.

  1. Create workitem: When a workitem was generated, it will check the respective condition was satisfied or not? At that time the workitem status is “IN PREPARATION”, the workitem is not accessible anywhere.
  2. Complete Workitem: In this case, workitem will be generated, but it will not complete until the condition is true. The workitem will not complete until the condition evaluates to true.
  3. Complete Execution: After execution of the workitem, the condition will be evaluated and if it is true then only the workitem will complete.

Step 1:

Create a workflow container element and make it as import as mentioned below.

img 2.png

Step 2:

I have created a Task with the following details.

img 3.png

Save the task.

  1. Maintain the task as ‘General Task’ as mentioned below. Menu options --> Additional data--> Agent assignment--> Maintain.

Select the task and click on ‘Attributes’ button. Select ‘General Task’ radio button and click on ‘Transfer’.

img 4.png

Come back from the screen. Enter some text in the Task Description

img 5.png

  1. Save task & come back. Maintain possible Binding from Workflow to Task and vice versa.

In the ‘Agents’ tab of activity step, select ‘User’ and any user name as mentioned below.

img 6.png

Go to ‘condition’ tab in the activity step. We can observe three types of conditions in the screen.

  1. Create workitem
  2. Complete workitem
  3. Complete execution

img 7.png

Open ‘create work item’ tab to create a condition, if this condition is true then only workitem will create.

Click on ‘click here to create a new condition’ sentence to create the condition.

Enter the following condition

img 8.png

Note: We know the condition is false, for this step workitem will not create until the condition is true.

We can find a symbol in the 'conditions' tab as mentioned below.

img 9.png

Save, activate and execute the workflow. Provide element WI_Elem value as ‘5’ and execute.

img 10.png

It will show the agent name in the ActiveX version log but unfortunately the workitem will not be available in agent inbox. Scroll down to check user inbox.

img 11.png

In the technical details of log, we can observe a different symbol at the step and in ‘Message’ tab message text as ‘Execution Interrupted’.

img 12.png

Go and check in the agent inbox. There is no workitem from our workflow.

img 13.png

In the execution time of our workflow, if I provide the element WI_Elem value as 10, it will works fine.

img 14.png

img 15.png

After workitem execution the workflow log appears as usual.

ENJOY WORKFLOWS…..

 

Regards,

Murali Krishna.

Workflow Agent Determination Customization

$
0
0

Objective

The object of this document is to detail the process of customizing the Agent determination of a standard workflow.

 

Pre-requisite

The reader must the aware of the basic workflow design terminologies.

 

Scenario

Customer has requested for a change in the agent determination of a standard workflow such as Purchase Order Workflow or Purchase Request Workflow or leave workflow.

When the request is only specific to the customization of agent determination, it is not advisable to design a copy of the standard workflow. As this would require us to completely re-configure the workflow settings of the new workflow.

 

Illustration

 

There are two possible approach to customize agent determination of a standard workflow, which are as follows,

·        Customizing an Existing Agent Rule

·        Making a copy of the existing rule

 

Customizing an Existing Agent Rule:

For explanation purpose let us consider the standard Purchase Order workflow (WS20000075). The below steps details the process of customizing the existing rule.

  • To identify the Rule linked to the Workflow click on the task which determines the rule as shown below.

P1.jpg

  • In the Task Display screen which pops up, select the default rules tab. A line Item with “Type of Rule” as “Agent (Default Rule)” refers the default rule associated with this workflow. In this case the PO Workflow standard rule is 20000027 as shown below.

P1.jpg

  • The rule is computed based on the Function Module linked to it. To check on the function module linked with this rule, double click on the rule number. For the PO workflows FM: ME_REL_GET_RESPONSIBLE is responsible for rule determination.

P1.jpg

  • SAP follows a standard enhancement routines in case of Rule’s Function Modules and places a User Exit in each of the Function Module. In this case User exit “EXIT_SAPLEBNF_005” is provided by SAP to implement the customer requirements.

P1.jpg

  • Implementing them will enable the Customer required design to be implemented.
  • In this case SAP has configured this customer exit to be triggered only when the “Role resolution for workflow” is set to ‘9’. Which has to be maintained for Release Group/ Release Code Combination in the release code table T16FC(Also maintainable through SPRO)

Making a copy of an existing Rule:

When rule customization is not sufficient to achieve the requirement. Then a copy of the existing rule can be made and required design can be implemented. The process is as follows.

  • To create a copy or a new rule the path Tools –> Business Workflow –> Development –> Definition tools –>Rules for Agent Assignment –>Create/Change/Display is used as shown below

P1.jpg

·        Create a copy or design your own function module and link the same to newly created Rule as shown below.

        

P1.jpg

·        Once the new rule is designed and tested the same can be linked to the Agent Determination Task as shown below.

 

P1.jpg

References: 

 

http://help.sap.com

                   

How to send mail with attachment of SAP Script in Workflow

$
0
0

Scenario : Once the release of the  PO is completed ( after released all level ) the script output of the particular PO has to send the initiator as attachment.

 

Step 1 :  Create step ( activity ) in workflow for getting the spool request of the release PO .

 

spool.PNG

 

The code for getting the spool request is as follows

*fetching the spool request.

select single rqident

from TSP01

into l_rqident

where rqtitle = object-key-purchaseorder.

if sy-subrc = 0.

spool_generate = 'X'.

endif.

SWC_SET_ELEMENT CONTAINER 'spool_generate' SPOOL_GENERATE.

 

Step 2 : As the spool request generation will take some time , put the wait step with condition that until spool is getting generated ( &spool_generate& = 'X'. )

 

Step 3 : Create step ( activity ) for attaching the PO.

 

The code is as below

 

BEGIN_METHOD POMAIL_ATTCHMNT CHANGING CONTAINER.

DATA:

      MAIL_ID TYPE ADR6-SMTP_ADDR,

      PO_NUMBER TYPE EKKO-EBELN.

  SWC_GET_ELEMENT CONTAINER 'mail_id' MAIL_ID.

  SWC_GET_ELEMENT CONTAINER 'PO_Number' PO_NUMBER.

" calling FM for Mail attachment .

CALL FUNCTION 'ZMM_PO_EMAIL_ATTACHMENT'

EXPORTING

   I_EBELN       = PO_NUMBER " passing the PO

   I_EMAIL       = MAIL_ID. " passing the mail id of initiator.

END_METHOD.

 

In the above function module , I am writing the code for getting PDF output from the spool number and make the bin file and passing the same to the SO_NEW_DOCUMENT_ATT_SEND_API1. and sending the attachment with the notification. Find the detailed code below.

"------------------------------------------------------------

   " Constants Declarations

   "------------------------------------------------------------

   CONSTANTS: lc_pdf        TYPE char3      VALUE 'PDF',

              lc_obj_name   TYPE so_obj_nam VALUE 'SCRIPT',

              lc_express    TYPE char1      VALUE 'X',

              lc_rec_type   TYPE char1      VALUE 'U',

              lc_sensitivty TYPE so_obj_sns VALUE 'F',

              lc_doc_type   TYPE so_obj_tp  VALUE 'RAW',

              lc_in_out     TYPE sonv-flag  VALUE 'X',

              lc_no(1)      TYPE c          VALUE ' ',

              lc_device(4TYPE c          VALUE 'LOCL'.

   "------------------------------------------------------------

   " Internal Tables Declarations

   "------------------------------------------------------------

   DATA : lint_objpack      TYPE TABLE OF sopcklsti1,

          lint_objbin       TYPE TABLE OF solisti1,

          lint_objtxt       TYPE TABLE OF solisti1,

          lint_reclist      TYPE TABLE OF somlreci1,

          lint_pdf_output   TYPE TABLE OF tline,

          lint_mess_att     TYPE TABLE OF solisti1.

   "------------------------------------------------------------

   " Work Area Declarations

   "------------------------------------------------------------

   DATA : lfs_objpack       TYPE sopcklsti1,

          lfs_objbin        TYPE solisti1,

          lfs_objtxt        TYPE solisti1,

          lfs_reclist       TYPE somlreci1,

          lfs_doc_chng      TYPE sodocchgi1,

          lfs_tsp01         TYPE tsp01,

          lfs_pdf_output    TYPE tline,

          lfs_mess_att      TYPE solisti1.

   "------------------------------------------------------------

   " Local Varaibles Declarations

   "------------------------------------------------------------

   DATA : lwf_lines_txt     TYPE i,

          lwf_lines_bin     TYPE i,

          lwf_buffer        TYPE string.

   "------------------------------------------------------------

   " Logic started..

   "------------------------------------------------------------

   IF i_ebeln IS NOT INITIAL

  AND i_email IS NOT INITIAL.

** To get the spool no from the purchase document number..

     SELECT SINGLE *

       FROM tsp01

       INTO lfs_tsp01

      WHERE rqtitle = i_ebeln.

     IF sy-subrc = 0.

** To set the local language..

       SET LOCALE LANGUAGE sy-langu.

** To get the PDF output from the spool no..

       CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

         EXPORTING

           src_spoolid              = lfs_tsp01-rqident

           no_dialog                = lc_no

           dst_device               = lc_device

         TABLES

           pdf                      = lint_pdf_output

         EXCEPTIONS

           err_no_otf_spooljob      = 1

           err_no_spooljob          = 2

           err_no_permission        = 3

           err_conv_not_possible    = 4

           err_bad_dstdevice        = 5

           user_cancelled           = 6

           err_spoolerror           = 7

           err_temseerror           = 8

           err_btcjob_open_failed   = 9

           err_btcjob_submit_failed = 10

           err_btcjob_close_failed  = 11

           OTHERS                   = 12.

       IF sy-subrc = 0.

         "------------------------------------------------------------

         " Transfer the 132-long strings to 255-long strings

         "------------------------------------------------------------

         LOOP AT lint_pdf_output INTO lfs_pdf_output.

           TRANSLATE lfs_pdf_output USING ' ~'.

           CONCATENATE lwf_buffer lfs_pdf_output INTO lwf_buffer.

         ENDLOOP.

**

         TRANSLATE lwf_buffer USING '~ '.

         DO.

           lfs_mess_att = lwf_buffer.

           APPEND lfs_mess_att TO lint_mess_att.

           SHIFT lwf_buffer LEFT BY 255 PLACES.

           IF lwf_buffer IS INITIAL.

             EXIT.

           ENDIF.

         ENDDO.

       ENDIF.

       "------------------------------------------------------------

       " To add the recipients email address

       "------------------------------------------------------------

       lfs_reclist-receiver = i_email.

       lfs_reclist-express  = lc_express.

       lfs_reclist-rec_type = lc_rec_type.

       APPEND lfs_reclist TO lint_reclist.

       CLEAR  lfs_reclist.

       "------------------------------------------------------------

       " Mail Content

       "------------------------------------------------------------

** for Header

       lfs_objtxt = 'Dear User,'.

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

** For space

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

** For content

       CONCATENATE 'Purchase order : ' i_ebeln ', has been approved.' INTO lfs_objtxt.

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

** For space

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

** For footer

       lfs_objtxt = 'This is an auto generated email, please do not reply.'.

       APPEND lfs_objtxt TO lint_objtxt.

       CLEAR lfs_objtxt.

       "------------------------------------------------------------

       " Mail Header

       "------------------------------------------------------------

       DESCRIBE TABLE lint_objtxt LINES lwf_lines_txt.

       lfs_doc_chng-obj_name   = lc_obj_name.

       lfs_doc_chng-obj_langu  = sy-langu.

       CONCATENATE 'Purchase order: ' i_ebeln ', has been approved' INTO lfs_doc_chng-obj_descr.

       lfs_doc_chng-sensitivty = lc_sensitivty.

       lfs_doc_chng-doc_size   = 1.

       "------------------------------------------------------------

       " Pack to main body as RAW.

       "------------------------------------------------------------

       CLEAR lfs_objpack-transf_bin.

       lfs_objpack-head_start = 1.

       lfs_objpack-head_num   = 0.

       lfs_objpack-body_start = 1.

       lfs_objpack-body_num   = lwf_lines_txt.

       lfs_objpack-doc_type   = lc_doc_type.

       APPEND lfs_objpack TO lint_objpack.

       "------------------------------------------------------------

       " Packing as PDF.

       "------------------------------------------------------------

       CLEAR lwf_lines_bin.

       DESCRIBE TABLE lint_mess_att LINES lwf_lines_bin.

       lfs_objpack-transf_bin = abap_true.

       lfs_objpack-head_start = 1.

       lfs_objpack-head_num   = 1.

       lfs_objpack-body_start = 1.

       lfs_objpack-body_num   = lwf_lines_bin.

       lfs_objpack-doc_type   = lc_pdf.

       CONCATENATE 'Purchase order: ' i_ebeln ', has been approved' INTO lfs_objpack-obj_name.

       CONCATENATE 'Purchase order' ':' i_ebeln INTO lfs_objpack-obj_descr.

**

       lfs_objpack-doc_size = lwf_lines_bin * 255.

       APPEND lfs_objpack TO lint_objpack.

       "------------------------------------------------------------

       " To send the smartform as attachment in Mail to the above receipent

       "------------------------------------------------------------

       CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

         EXPORTING

           document_data              = lfs_doc_chng

           put_in_outbox              = lc_in_out

         TABLES

           packing_list               = lint_objpack

           contents_bin               = lint_mess_att

           contents_txt               = lint_objtxt

           receivers                  = lint_reclist

         EXCEPTIONS

           too_many_receivers         = 1

           document_not_sent          = 2

           document_type_not_exist    = 3

           operation_no_authorization = 4

           parameter_error            = 5

           x_error                    = 6

           enqueue_error              = 7

           OTHERS                     = 8.

       IF sy-subrc = 0.

         COMMIT WORK.

       ENDIF.

     ENDIF.

   ENDIF.

ENDFUNCTION.


Sending reminder mail continously in workflow

$
0
0

Requirement : An agent is getting the work item , but he/she is not approving / rejecting the same, in this case system is keep on sending the reminder mail in every 12 hours until he / she act on the workitem. Once the workitem is approved / rejected  then only the control pass to the next step. Please find the template below followed by the step description

 

wf.jpg

Before the release step , I added a fork having two parallel branch with one necessary branch. In one of the branch I put the release step and rest of the operation and in another branch created an infinite loop step within this loop created a dummy method and two mail step ( one to SAP inbox and the second one to External mail ). In dummy method , I selected the Requested Start tab and put the work item creation and time after 12 hrs. ( please see the below screen shot ).

So whenever the Agent approve / reject the work item the fork will end OR every 12 hours the mail is keep on sending mail to the agent ( to sap inbox as well as external mail ) as a reminder until he approved/rejected the work item

t.jpeg

How to (not) debug workflow background tasks

$
0
0

This is a very common question in the discussion threads and I think I read more than 5 blogs suggesting different ways to debug the workflows. However, and this is an Update following the SAP customer connection Workflow Focus topic, there should now be an easy way to debug the background tasks - see note 2197117 - Debugging of background workitems - https://service.sap.com/sap/support/notes/2197117.

If you can't implement the note, or want to try another way of solving the problem, there are a few steps you can use:

 

The first option is using the workflow log, one advantage of the workflow system is that it logs almost everything so in contrast to a regular program which you don't know exactly what has happen to the user, in the workflow you can see in importing and exporting parameters in the log. When you build your workflows remember to also add the return messages of the function modules to the log so you can have the complete picture.

Sometime you use a parameter of the business object in a rule or an internal part of the task, add it as an attribute of the object so you can see it too in the log.

 

Second step you can do is to use the test option in SWO1 and debug the method, since the background task is actually a call to an object method, debugging the method in most cases is the same as debugging the task.

 

Another option before starting to debug tasks which is useful for all background process, not just the workflows (I actually use it mainly for the SRM workflow BADIs) is using log points, it's very simple to add to your program:

Log point ID zlog_point_name SUBKEY im_object_num FIELDS field1 field2 etc.

And you will have the ability to log the data even in productions systems without using debugger. See for more detail:

Checkgroups - ABAP Development - SCN Wiki

http://help.sap.com/abapdocu_702/en/abaplog-point.htm

 

Now only if all this failed go to solutions like changing the workflow RFC destination, adding endless loops in the program etc.

Viewing all 38 articles
Browse latest View live


Latest Images

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