Sunteți pe pagina 1din 23

3/8/2019 Purchase Requisition Workflow – copycodesap

COPYCODESAP

programming in sap abap

Purchase Requisition Workflow

A SAP system based approval which notifies business users to login to SAP and approve a particular
document or a part of it.

Purchase Requisition Release and Approval Workflow – 2 Level.

Standard Workflow Name PR Release – WS00000038

Customised PO Workflow Name – WS99400005

Object Type – BUS2009

Delegated Object Type – ZBUS2009

Custom Method Created for Delegated Object – ZPR_MTHD_BUS2009

Activity Created – Task to fetch Agent Mail ID

TCode Involved – ME51b to create / ME54b To release.

Step by step process to create workflow:-

1. Copy standard workflow – T Code to copy workflow PFTC

Name the copied workflow.

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 1/23
3/8/2019 Purchase Requisition Workflow – copycodesap

2. Once Copied Open the workflow in workflow Builder – T Code SWDD

Remove the unwanted activity and keep which ever you want.

3. Make Sure the start event is active (green).

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 2/23
3/8/2019 Purchase Requisition Workflow – copycodesap

When you click the binding you find the below screen.

4. Create a activity to fetch the agent mail ID.

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 3/23
3/8/2019 Purchase Requisition Workflow – copycodesap

Now if you double click the task it goes to the screen “Basic data” and you give the Object type and
the method.

Lets see how to find the object type and create linkage first then shall comeback to the activity.

How to find the Object type. I.e in this case BUS2012

First method – Go to tcode SWO2

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 4/23
3/8/2019 Purchase Requisition Workflow – copycodesap

You can find the Object type BUS2012.

The other method to find the object type.

Go to Tcode BAPI

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 5/23
3/8/2019 Purchase Requisition Workflow – copycodesap

Click the business object builder.

You can find the Object type BUS2012.

The third option would be to run SWELS/SWEL TCode. Execute the purchase order Tcode and find
in the SWEL about which Object type is triggered.

Since we have got the object type through the above mentioned approach now we are now going to
create the linkage by replacing the standard linkage. Go to TCode SWE2 and find the Object type
BUS2012.

Copy the standard BUS2012 and place the newly created workflow (WS99400002) in the receiver type
and mark the linkage. Now the linkage is created.

Event Name is RELEASESTEPCREATED

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 6/23
3/8/2019 Purchase Requisition Workflow – copycodesap

Now delegate the Object Type so that you can change/add methods in the standard Object type.

Choose Purchase Order.

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 7/23
3/8/2019 Purchase Requisition Workflow – copycodesap

After delegation, you can create/add a new method for your requirement in the object type
ZBUS2012.

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 8/23
3/8/2019 Purchase Requisition Workflow – copycodesap

The created method here is ZPO_MTHD_BUS2012.

How to create method –

Click create method and fill the below details.

Once the method name is created, release the method.

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 9/23
3/8/2019 Purchase Requisition Workflow – copycodesap

Next, click on the parameters. On the list shown on top.

Below screenshots show how the parameter is created.

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 10/23
3/8/2019 Purchase Requisition Workflow – copycodesap

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 11/23
3/8/2019 Purchase Requisition Workflow – copycodesap

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 12/23
3/8/2019 Purchase Requisition Workflow – copycodesap

Go back to the previous page and click program. Below is the program.

***** Implementation of object type ZBUS2012 *****


INCLUDE <object>.
BEGIN_DATA OBJECT. ” Do not change.. DATA is generated
* only private members may be inserted into structure private
DATA:
” begin of private,
” to declare private a ributes remove comments and
” insert private a ributes here …
” end of private,
BEGIN OF KEY,
PURCHASEORDER LIKE EKKO-EBELN,
END OF KEY.
END_DATA OBJECT. ” Do not change.. DATA is generated

begin_method zpo_mthd_bus2012 changing container.


DATA: l_data TYPE string,
lv_ebeln TYPE ebeln,
lv_frggr TYPE frggr,
lv_objid TYPE actorid,
lv_objid1 TYPE actorid,
lv_prnum TYPE ad_persnum,
lv_adrnr TYPE ad_addrnum,
lv_email TYPE ad_smtpadr.

DATA :wa_text TYPE tline,


it_text TYPE STANDARD TABLE OF tline.

DATA: purchaseorder TYPE ekko-ebeln,


releasecode TYPE rm06b-frgab,
agentid TYPE t16fw-objid,
mailid TYPE adr6-smtp_addr,
subject TYPE bapitgb-line,
mailtext TYPE bapitgb OCCURS 0.
https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 13/23
3/8/2019 Purchase Requisition Workflow – copycodesap

swc_get_element container ‘purchaseorder’ purchaseorder.


swc_get_element container ‘Releasecode’ releasecode.

*Read mail content.


CALL FUNCTION ‘READ_TEXT’
EXPORTING
client = sy-mandt
id = ‘ZTXT’
language = ‘E’
name = ‘ZGO_PO_MAIL’
object = ‘TEXT’
* ARCHIVE_HANDLE =0
* LOCAL_CAT =‘‘
* IMPORTING
* HEADER =
* OLD_LINE_COUNTER =
TABLES
lines = it_text.

LOOP AT it_text INTO wa_text.


l_data = wa_text-tdline.
APPEND l_data TO mailtext.
CLEAR : wa_text, l_data.
ENDLOOP.

*Get approver ID.


*Get release group from ekko
SELECT SINGLE ebeln
frggr FROM ekko INTO (lv_ebeln, lv_frggr) WHERE ebeln = purchaseorder.

*Get approver id by passing release group & code from T16FW


SELECT SINGLE objid FROM t16fw INTO lv_objid WHERE frggr = lv_frggr AND frgco = releasecode
.

*Assign the agent id to external parameter


CONCATENATE ‘US’ lv_objid INTO lv_objid1.
agentid = lv_objid1.

*Get Email ID.


*Fetch address & Person number from USR21
SELECT SINGLE persnumber
addrnumber FROM usr21 INTO (lv_prnum, lv_adrnr) WHERE bname = lv_objid.

SELECT SINGLE smtp_addr FROM adr6 INTO lv_email WHERE addrnumber = lv_adrnr AND pers
number = lv_prnum.

IF lv_email IS NOT INITIAL.


mailid = lv_email.
ENDIF.

*Get Subject from SO10.


REFRESH it_text[].
CALL FUNCTION ‘READ_TEXT’
EXPORTING
https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 14/23
3/8/2019 Purchase Requisition Workflow – copycodesap

client = sy-mandt
id = ‘ZTXT’
language = ‘E’
name = ‘ZGO_PO_SUBJ’
object = ‘TEXT’
* ARCHIVE_HANDLE =0
* LOCAL_CAT =‘‘
* IMPORTING
* HEADER =
* OLD_LINE_COUNTER =
TABLES
lines = it_text.

LOOP AT it_text INTO wa_text.


l_data = wa_text-tdline.
IF l_data IS NOT INITIAL.
WRITE l_data TO subject.
CLEAR : wa_text, l_data.
ENDIF.
ENDLOOP.

swc_set_element container ‘agentid’ agentid.


swc_set_element container ‘mailid’ mailid.
swc_set_element container ‘subject’ subject.
swc_set_table container ‘mailtext’ mailtext.

REFRESH :it_text[].
CLEAR : lv_ebeln, lv_frggr, lv_objid, lv_prnum, lv_adrnr, lv_email.
end_method.

Now the method is created. Assign it to the activity.

Check in the Tab Container if all the parameters are there.

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 15/23
3/8/2019 Purchase Requisition Workflow – copycodesap

Now go back to the previous screen and do the agent assignment.

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 16/23
3/8/2019 Purchase Requisition Workflow – copycodesap

Once the agent assignment is done do the binding.

Activity for fetching agent ID is done now lets go to the send activity on sending mail for approval.

How to maintain the release strategy:

SPRO and follow the below the screenshot.


https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 17/23
3/8/2019 Purchase Requisition Workflow – copycodesap

Click workflow and define the user/Agent ID.

The Final look of Completed workflow Builder:

Important T Code to watch out.

SU03 – Basis Configuration

SOST : To check if the mail is transferred which is triggered from Workflow.

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 18/23
3/8/2019 Purchase Requisition Workflow – copycodesap

Advertisements

REPORT THIS AD

REPORT THIS AD
JUNE 27, 2016JUNE 27, 2016
(HTTPS://COPYCODESAP.WORDPRESS.COM/2016/06/27/PURCHASE-REQUISITION-
WORKFLOW/) BY PRAVEEN ATHIKKAL
(HTTPS://COPYCODESAP.WORDPRESS.COM/AUTHOR/PRAVEENATHICKAL/) 2 COMMENTS
(HTTPS://COPYCODESAP.WORDPRESS.COM/2016/06/27/PURCHASE-REQUISITION-
WORKFLOW/#COMMENTS)

2 thoughts on “Purchase Requisition Workflow”

Karina says:
Dec 28, 2017 at 7:26 pm
Really useful guide, thank you!
I’m doing something similar to this, for release of contract (BUS2014), everything works fine for 1
level release but for releases with more than 1 level the WF is only triggered for the first level, I
executed a trace and I can see that the event RELEASESTEPCREATED is trigger just once, is there
any customization or something I can check that could be causing the problem? any suggestion?

REPLY
Praveen Athikkal says:
Jan 19, 2018 at 1:42 pm
https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 19/23
3/8/2019 Purchase Requisition Workflow – copycodesap

Hi Karina,
Sorry, Been a long time since i checked my blog.
Not sure if you have fixed the issue or not. If not then would you mind to elaborate the issue
for my understanding.

Thanks & Regards,


Praveen.

REPLY

Create a free website or blog at WordPress.com.

REPORT THIS AD

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 20/23
3/8/2019 Purchase Requisition Workflow – copycodesap

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 21/23
3/8/2019 Purchase Requisition Workflow – copycodesap

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 22/23
3/8/2019 Purchase Requisition Workflow – copycodesap

https://copycodesap.wordpress.com/2016/06/27/purchase-requisition-workflow/ 23/23