In this, the sixth blog in a 73-part series (‘The Overworked Workflow Administrator’), I hope to definitively answer the commonly-asked question: ‘How do you archive SAP workflows?’.
As a workflow administrator, I always knew I had to eventually archive some workflows, but it never reached the top of my ‘To Do’ list. Until now: we are preparing to migrate to a new system, and need to reduce our SAP table sizes. It’s also nice to do a spring clean after 7 years of operation.
Note that when I say ‘workflows’, I mean workflow instances – for example, an approval workflow for an $11,000 tax refund. A ‘workitem’ is a step in that workflow instance, which may appear in an inbox.
What does it mean to ‘archive’ a workflow?
Simply put, when you ‘archive’ a workflow, it is removed from the SAP instance and placed offline (i.e., in a file on your application server).
The workflow (and all its workitems, attachments, log history etc) is still available for read-only access, but its data disappear out of many large SAP database tables. This makes the Basis people very happy 🙂 .
You archive in two separate steps: writing a workflow to an archive file, and then deleting the workflow from the SAP system.
Note that you can only archive workflows that have status COMPLETED (or CANCELLED).
Why would you want to?
You may wish to archive workflows if:
- Your Production system has been running for a few years
- Your critical SAP workflow tables (like SWWWIHEAD, SWNCNTP0) are growing fast, impacting performance and slowing down Basis tasks
(like system backups)
- You are migrating to a new system and want to reduce the amount of database table data
The business users are nervous about this ‘archiving’. What are the impacts?
I’ve been told that many archiving projects never get off the ground, because of the ‘D’ word (deletion). Business users fear that the deleted workflows – and the legal audit trails they contain – will disappear forever.
As far as I can tell, the risks are small. This procedure has been around for years, and is (presumably) used routinely by thousands of large SAP customers. You don’t ‘delete’ the workflows until after the ‘write’ process’ has completed successfully. And yes, the workflows are physically deleted from the Production system, but they live on in the archive files.
Of course, you do need to be very careful with those archive files; it now becomes the responsibility of the Basis team to keep them safe and properly backed up.
How to archive workflows
Let’s assume that general archiving has already been set up in your system, and that the necessary configuration has been done for archive object ‘WORKITEM’. (If this is not true, please follow the instructions in SAP Note 2157048. This note contains a beautifully clear document by Eddie Morris called ‘Work Item Archiving for SAP Business Workflow’).
In the example below, I am archiving all eligible (COMPLETED / CANCELLED) workflows in our Test system, which were created between 2009 and
2012. There are about 450,000 workflows to be archived.
Step 1: Write the Workflows to Archive
- Transaction SWW_SARA
- Click on the ‘Write’ button
- Create a new variant: enter a variant name (e.g., 2009_2012) and click ‘Maintain’
- Choose the workflows that you want to archive; for example, all those with creation dates between 2009 and 2012. Choose ‘Production Mode’ (to actually write the archive file)
- Save and return to the previous screen
- Set up the archiving job: set the ‘Start Date’ (Immediate) and the ‘Spool Parameters’ (Send to SAP Spooler Only for now)
Once all the lights are green, you can hit ‘Execute (F8)’.
- Then click the green ‘Job’ button to view the progress of the archiving job in SM37.
Step 2: Confirm that archiving was successful
- Check the SM37 job logs to make sure they completed without errors
Step 3: Delete the archived workflows from SAP
- Transaction SWW_SARA
- Click the ‘Delete’ button (yes, it’s safe – nothing is deleted yet!)
- Click the ‘Archive Selection’ button, and choose all the archive files written in the previous step
- Set up the deletion jobs: set the ‘Start Date’ (Immediate) and the ‘Spool Parameters’ (Send to SAP Spooler Only for now)
- Once all the lights are green, you can hit ‘Execute (F8)’.
- Then click the green ‘Job’ button to view the progress of the deletion jobs (one for each archive file) in SM37.
How to view the archived workflows
The archived workflows can be browsed via the ‘Read’ button in SWW_SARA. The ‘Archive Explorer’ (via the ‘Information System’) allows you to search by date, task id, and so on. You can even search by BOR object, or class instance.
You can also locate the archived workflow for an individual business object via the GOS (Generic Object Services) tool. For example, if you want to view the approval workflow for a FICA refund document, just select ‘Archived Workflows’ from the GOS menu in the FPE3 (Display Document) transaction.
Top Tip: Clean up your old workflows first
My very first attempt at archiving did not pick up as many workflows as I had hoped. Thousands of old items still remained in the system. This is because – as mentioned above – archiving is restricted to workflows with status CANCELLED or COMPLETED.
We found a few hundred workflows in status ERROR, as well as many thousands in status STARTED.
The ERROR workflows were old instances that ran into errors and – for whatever reason – were not restarted. It would be dangerous to revive them now(!), so we decided to logically delete them. This sets them to status CANCELLED.
The STARTED workflows were, in most cases, workflows that had completed successfully, but were waiting for the user to acknowledge the outcome (e.g., ‘Your leave has been approved’). The workflows that fit this pattern were also logically deleted.
We decided, however, that if a user had reserved a workitem, then we would not archive the parent workflow.
For more information on logical deletion, please see this blog: How to ‘logically delete’ workflows.
Q: Are the complete workflows really written to the archive? Attachments, comments, objects, logs, everything?
A: Yes they are. I successfully tested the retrieval of different attachments from the archive: RAW notes, Word documents, and JPEG images. Business objects (such as refund documents) are a little different: they just have their key (e.g., document number) stored in the archive, so that they can be reinstantiated on demand – the same as in any workflow instance. Works seamlessly!
Q: Can I still browse the archived workflows through SWIA and SWI2_FREQ?
A: No of course not – they’ve been deleted from the SAP tables. But you can browse them through the SWW_SARA transaction (see above).
Q: Which tables are SAP workflows actually stored in?
A: Lots of them, but especially these large ones:
- SWWIHEAD (Headers)
- SWWCNTP0 (XML Container)
- SWWLOGHIST (Work Item History)
- SWW_CONT (Work Item Container)
Archiving can remove millions of rows from these tables.
Q: Is it possible to reinstate workflows after they have been archived?
A: No it is not. But why would you want to? The archived versions are just a click away.
Also, you can’t actually do anything with a COMPLETED workflow, except view the log.
Q: I have some Production workflows that I just want to delete. Should I bother archiving them?
A: Definitely archive them. The archiving process gives you a safe and fool-proof way of removing workflows – and all their child workitems – from your system. In general you should never directly delete workflows from Production – see Jocelyn’s heart-stopping blog for the many reasons why.
Q: So are there any disadvantages to workflow archiving?
A: I suppose there’s a risk that something could happen to the physical archive files, if the Basis team is not careful (for example, they could inadvertently delete them when transitioning to a new system). But even then, there should be a backup available.
Access to the archived workflows is of course a little slower, because they have to be extracted from a file. But how many users regularly need to look at old workflows?
Another drawback (for business users, perhaps) is that you can only view the logs of archived workflows in technical mode, not in the colourful ‘Active X’ or ‘Graphical Log’ formats.