1/23/2017
Appr oval W or kfl ow for Pr i ci ng Condi ti on | SAP Bl ogs
Get Started
Solutions
Partner
Support
Community
Training
Community
Developer
About
/
Blogs Blog s
Approval Workflow for Pricing Condition October 30, 2013 30, 2013
|
678 Views Vi ews
|
Tanmay Vyas more by this author
SAP Business Workflow abap devlopment | pricing condition;pr condition;pricing icing | pricing sales order | sap sales and distribution | sap sd | sap sd pricing | sap workflow | sap workflow design | workflow approval
share 0
share 0
tweet
share 0
Follow
Business Scenario:
It is required that Sales manager must approve all order pricing changes. Since discounts and surcharges applied at order level, https://blogs.sap.com/2013/10/30/appr oval - wor kfl ow- for - pr i cing- condi ti on/
1/33
1/23/2017
Appr oval W or kfl ow for Pr i ci ng Condi ti on | SAP Bl ogs
change the net price of an order, the discount/surcharge must be approved by a manager. Creating or updating a discount/surcharge record should trigger a workflow approval event. Once the workflow object is approved by the appropriate manager, the condition record is released and the discount/surcharge is applied to the order. For the purpose of demo, consider the condition type for Customer Discount (K007). This document provides a custom solution for developing Approval Workflow for Condition Records. Create Transaction Variant to make Processing Status ‘noneditable’ and assign a default value
A processor (sales clerk) can create and change condition record records s via VK11/VK12 transactions. It is necessary to disable the processing status field in order to prevent the sales clerk from accidently setting the status as Released. Call transaction SHD0. Enter transaction code as VK11 and Z transaction variant ‘ZVAR_VK’. Click on ‘Create’ button.
Enter Condition type ‘K007’ and hit ‘Enter’ on the subsequent Pop up screen.
https://blogs.sap.com/2013/10/30/appr oval - wor kfl ow- for - pr i cing- condi ti on/
2/33
1/23/2017
Appr oval W or kfl ow for Pr i ci ng Condi ti on | SAP Bl ogs
change the net price of an order, the discount/surcharge must be approved by a manager. Creating or updating a discount/surcharge record should trigger a workflow approval event. Once the workflow object is approved by the appropriate manager, the condition record is released and the discount/surcharge is applied to the order. For the purpose of demo, consider the condition type for Customer Discount (K007). This document provides a custom solution for developing Approval Workflow for Condition Records. Create Transaction Variant to make Processing Status ‘noneditable’ and assign a default value
A processor (sales clerk) can create and change condition record records s via VK11/VK12 transactions. It is necessary to disable the processing status field in order to prevent the sales clerk from accidently setting the status as Released. Call transaction SHD0. Enter transaction code as VK11 and Z transaction variant ‘ZVAR_VK’. Click on ‘Create’ button.
Enter Condition type ‘K007’ and hit ‘Enter’ on the subsequent Pop up screen.
https://blogs.sap.com/2013/10/30/appr oval - wor kfl ow- for - pr i cing- condi ti on/
2/33
1/23/2017
Appr oval W or kfl ow for Pr i ci ng Condi ti on | SAP Bl ogs
Enter any Customer number, Amount and Set Processing status as ‘Blocked’
Set ‘Processing status’ field as ‘Output Only’ and ‘With Content’ on the subsequent popup screen. (screen variant)
https://blogs.sap.com/2013/10/30/appr oval - wor kfl ow- for - pr i cing- condi ti on/
3/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
Hit Save and then ‘Enter’ on the next pop up screen.
Save the Transaction Variant ‘ZVAR_VK’ and Screen variant ‘ZVAR_VK_1307’. Go to ‘Standard Variants’ tab and activate Transaction Variant ‘ZVAR_VK’. This sets ‘ZVAR_VK’ as default transaction variant for VK11 transaction.
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
4/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
Transaction VK11 now has the Processing Status as a noneditable column with Default value as 1 (Blocked)
Call Transaction SHD0 and activate the same Transaction variant ’ZVAR_VK’ for Condition Change transaction – VK12.
Similarly, screen variants can be created for other condition types and assigned to this transaction variant.
For e.g. Transaction VK12 now has the Processing Status as a non-editable column with Default value as 1 (Blocked) for condition type PR01 https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
5/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
Extend Business Object BUS3005 (Condition)
Call transaction SWO1 (Business Object Builder) and create object type ZZBUS3005
Provide Object name, Description and underlying program name. Supertype indicates that this object type is inherited from standard SAP business object type BUS3005.
Change Object Release status to ‘Implemented’
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
6/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
Create Custom Events
Place cursor on ‘Events’ and click ‘Create’. On the subsequent popup screen – provide event name ‘Created’. This event will serve as Triggering event for the Condition Record Approval Workflow.
Place cursor on event and change its release status to implemented
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
7/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
Create Event Parameters
Place cursor on event and choose ‘Parameters’.
Next
click
‘Create’
and
specify
parameter
name
as
‘ChangeDoc_Pos’ of structure type CDPOS. This event parameter will contain old and new values of the condition. (While creation, the old values will be blank)
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
8/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
Create another Event ‘Changed’ with the same event parameter ‘ChangeDoc_Pos’ of structure type CDPOS.
Configure Workflow Triggering events on Change Document When a change to a Condition Record is logged by the system using Change Document object ‘COND_A’ – the following event linkages will trigger the corresponding Business object Events.
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
9/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
Call transaction SWEC (Event Linkage for Change Documents) and click on ‘New Entries’
This entry will trigger ‘BUS3005.Created’ event every time a new Condition record is created. Create new Function ‘Z_FILL_EVENT_CONT’ that can be used to fill the Event Container with table of Change Document Items i.e. Details of the change made to the Condition record. Sample code:
FUNCTION z_fill_event_cont. *”———————————————————————*”*”Local Interface: *” IMPORTING *” VALUE(CHANGE_DOC_OBJECT) TYPE SWECDOBJCDOBJECTCL OPTIONAL *” VALUE(OBJTYPE) TYPE SWECDOBJ-OBJTYPE OPTIONAL *” VALUE(OBJKEY) TYPE SWEINSTCOU-OBJKEY OPTIONAL *” VALUE(EVENT) TYPE
SWOTRE-EVENT OPTIONAL
*” TABLES *” EVENT_CONTAINER STRUCTURE
SWCONT OPTIONAL
*” CHANGEDOCUMENT_POSITION STRUCTURE CDPOS OPTIONAL *”———————————————————————* Fill Event Container from Change-document https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
10/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
swc_set_table event_container ‘ChangeDoc_Pos’ changedocument_position. ENDFUNCTION.
Also add a new entry for ‘Changed’ Event.
This entry will trigger ‘BUS3005.Changed’ event every time a Condition record is changed. Create Custom Attributes
Place cursor on ‘Attributes’ and click ‘Create’. Hit ‘Yes’ on the subsequent pop up.
Provide table name as ‘KONH’ and select the fields as shown. (More fields can be chosen if required within
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
11/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
Workflow.)
Click ‘Create’ on all subsequent popup screens to create all selected attributes
Create Custom Methods
Review Pricing Condition – This method is used to present a custom approval screen to the Reviewer (Sales manager) Create a new function – ‘Z_REVIEW_COND’ and design a custom Approval screen that lists Old /New values of the Pricing Condition record and Approve/Reject Buttons.
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
12/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
Sample Screen
Function module ‘Z_REVIEW_COND’ can be developed with the assumption that Change Document table is passed to it from workflow. For each relevant field in the Change Document table – capture the old and new values and display on custom screen. Fetch Customer number from Condition table. (‘A307’ in this example) Capture the Review Result as ‘A’ for Approved and ‘R’ for Rejected and pass it as Exporting parameter.
Sample code:
* Populate Modified Fields LOOP AT it_changedoc_items. CASE it_changedoc_items-fname. *
Discount changed WHEN ‘KBETR’. MOVE it_changedoc_items-value_old TO
v_old_discount. v_old_discount = v_old_discount / 10. MOVE it_changedoc_items-value_new TO
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
13/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
v_new_discount. v_new_discount = v_new_discount / 10. *
Valid-from Date changed WHEN ‘DATAB’.
WRITE: it_changedoc_items-value_old TO
wa_old-valid_from, it_changedoc_items-value_new TO wa_new-valid_from. *
Valid-to Date changed WHEN ‘DATBI’.
WRITE: it_changedoc_items-value_old TO
wa_old-valid_to, it_changedoc_items-value_new TO wa_new-valid_to. WHEN OTHERS.
ENDCASE.
ENDLOOP.
In SWO1 transaction – Place cursor on ‘Method and click ‘Create’. On the subsequent popup screen – provide function name ‘Z_REVIEW_COND’.
Set method as Dialog and create method parameters using https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
14/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
function parameters.
Click ‘Yes’ on the following pop up to auto-generate the method code.
Auto-generated Code: begin_method reviewcond changing container.
DATA: https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
15/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
createdby TYPE konh-ernam, condtype TYPE t685t-vtext, reviewresult TYPE syst-input, changedocumenttable LIKE cdpos OCCURS 0.
swc_get_element container ‘Createdby’ createdby. swc_get_element container ‘CondType’ condtype. swc_get_table container ‘ChangeDocumentTable’ changedocumenttable.
CALL FUNCTION ‘Z_REVIEW_COND’ EXPORTING
im_createdby
= createdby
im_cond_type_name
= condtype
IMPORTING ex_review_result
=
reviewresult TABLES changedocument_position = changedocumenttable EXCEPTIONS OTHERS
= 01.
CASE sy-subrc. WHEN 0.
” OK
WHEN OTHERS.
” to be
implemented
ENDCASE.
swc_set_element container ‘ReviewResult’ reviewresult.
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
16/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
swc_set_table container ‘ChangeDocumentTable’ changedocumenttable.
end_method.
Release Pricing Condition – This method is used to Release the block on the Condition record after Approval. Place cursor on Method and click ‘Create’. On the subsequent popup screen – provide method name ‘ReleaseCond’. This method is a Background method.
Place cursor on method ‘ReleaseCond’ and click ‘Program’ to write method code.
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
17/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
Sample Code: begin_method releasecond changing container. DATA : l_usage
TYPE kvewe,
l_cond_tab
TYPE kotabnr,
l_appl
TYPE kappl,
l_cond_type
TYPE kscha,
l_cond_tab_name
TYPE t681-
kotab, v_sel_tab_name
type string.
* Fetch Condition Header data swc_get_property self ‘Application’
l_appl.
swc_get_property self ‘Usage’
l_usage.
swc_get_property self ‘Table’
l_cond_tab.
swc_get_property self ‘ConditionType’
l_cond_type.
* Determine condition tablename CLEAR l_cond_tab_name. CALL FUNCTION ‘RV_TABLE_NAME_SET’
EXPORTING rt_kotabnr = l_cond_tab rt_kvewe
= l_usage
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
18/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
IMPORTING rt_kotab
= l_cond_tab_name.
MOVE l_cond_tab_name
TO
v_sel_tab_name. * Update table to set Condition Record as RELEASED UPDATE (v_sel_tab_name) SET kbstat = ‘2’ kfrst = ” WHERE kappl
= l_appl
AND kschl
= l_cond_type
AND knumh
= object-key-
conditionrecordno. IF sy-subrc EQ 0. COMMIT WORK AND WAIT. ENDIF.
end_method.
Place cursor on method ‘ReleaseCond’ and change its release status to implemented
Save and Generate object type ‘ZZBUS3005’
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
19/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
Setup Business Object Delegation
Call transaction SWO1 and click on Setting -> Delegate
Add ‘New Entry’
This setting causes all the new methods, attributes and events from ZZBUS3005 (subtype) will be available within object type BUS3005 (supertype) – when it is used in any Workflow. Build template for Pricing Condition Workflow
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
20/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
Call transaction SWDD – Workflow Builder. Click Save and provide name for the Workflow template
Click on ‘Basic Data’ tab to setup triggering events
Go to ‘Start Events’ tab and setup ‘Created’ and ‘Changed’ events of Business Object BUS3005 as the triggering events for this workflow template.
Activate the event linkages.
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
21/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
This setting will trigger a workflow instance every time a Condition record is created or changed.
For each event, setup start condition -> (Condition type = ‘K007’)
This ‘Start Condition’ will be evaluated before triggering new workflow instance.
Create Workflow Container variable ‘ChangeDoc_Pos’
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
22/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
Set variable ‘ChangeDoc_Pos’ property as ‘Import’ and ‘Multiline’. This indicates that the Change Document table will be passed to the Workflow from the Triggering Event
Similarly create Workflow Container variable ‘BUS3005’ of object type ‘BUS3005’ and set its property as ‘Import’ Parameter.
Go to ‘Start Events’ under ‘Basic Data’ and setup the Data binding as shown – for both events. This setting passes data from Event container to Workflow container – during the triggering of the Workflow
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
23/33
1/23/2017
Approval Workfl ow f or Pricing Condition | SAP Blogs
Add a new ‘Activity’ step for generating a Review task.
Double Click on ‘Undefined Step’ and choose step type as ‘Activity’
Choose Create task
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
24/33
1/23/2017
Approval Workfl ow for Prici ng Condition | SAP Blogs
Click ‘Yes’ on the subsequent pop up to auto-create Task Container variables.
Make sure that Change Document table is passed to the task and Review Result is retrieved back to Workflow.
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
25/33
1/23/2017
Approval Workfl ow for Pricing Condition | SAP Blogs
Set the task as General Task Use Rule ‘00000168’ to determine ‘Approver’ as the manager of the User (who creates/changes a condition record)
Add a condition step todetermine the Result of Approval.
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
26/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
Add new Activity step for Releasing Condition Record in background.
Right click on the outcome branch ‘Approved’ and select ‘Create’ – Activity Step
Choose Create task
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
27/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
Pass the Business Object instance to this task
Save and activate Workflow Template
Working DEMO
User creates a Condition record for Condition type ‘K007. Initially – the processing status is BLOCKED https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
28/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
On SAVE, the Workflow gets triggered and Approval item is routed to the Manager of the User who created the Condition record.
At this time, the customer discount is not reflected in the Order
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
29/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
The Sales Manager can view the following Review Screen by executing the Approval Work item. (Old values are blank since this is a new condition)
On Approval, the Condition Record is released and customer discount is now applied on to the Gross Price of the Order.
Alert Mod erator
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
30/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
8 Comments You must be Logged on to comment or reply to a post.
OD Manikandan October 31, 2013 at 7:10 am
Very Nice material Regards, OD
Ronen Weisz January 29, 2014 at 7:24 pm
I have been looking for a way to do this for a long time, and seeing the whole process as you showed it was very helpful. One question, do you know of any way to do the condition update with a function module and not with a direct update? Ronen
Jyoti Prakash May 2, 2014 at 11:52 am
Tanmay Nice & elaborated documentation. Keep the good work & word moving. Thanks. Best Wishes, JP
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
31/33
1/23/2017
Approval Workflow for Pricing Condition | SAP Blogs
satish kumar pulijala May 2, 2014 at 5:27 pm
hi tanmay vyas Nice material thank u satish
anandkumar radhakrishnan May 3, 2014 at 7:08 am
Good Explanation!! Thanks a lot
Wallace Ferreira e Silva February 5, 2016 at 4:19 pm
Hi Tanmay, If approval user click cancel button in a review screen work item is completed. I think to move release code for review screen, because the method must be asynchronous and don´t accept export parameter. How do you implement cancel button in workflow ? Thanks in advance. Wallace
Tanmay Vyas
Post author
February 22, 2016 at 8:58 pm
https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/
32/33