Approval Workflow for Pricing Condition
It is required that Sales manager must approve all order pricing changes. Since discounts and surcharges applied at order level, 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 ‘non-editable’ and assign a default value
A processor (sales clerk) can create and change condition records 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.
- 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)
- 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.
Transaction VK11 now has the Processing Status as a non-editable 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
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’
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
- 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)
- 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.
- 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.
*” VALUE(CHANGE_DOC_OBJECT) TYPE SWECDOBJ-CDOBJECTCL OPTIONAL
*” VALUE(OBJTYPE) TYPE SWECDOBJ-OBJTYPE OPTIONAL
*” VALUE(OBJKEY) TYPE SWEINSTCOU-OBJKEY OPTIONAL
*” VALUE(EVENT) TYPE SWOTRE-EVENT OPTIONAL
*” EVENT_CONTAINER STRUCTURE SWCONT OPTIONAL
*” CHANGEDOCUMENT_POSITION STRUCTURE CDPOS OPTIONAL
* Fill Event Container from Change-document
swc_set_table event_container ‘ChangeDoc_Pos’ changedocument_position.
- 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 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.
- 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.
* Populate Modified Fields
LOOP AT it_changedoc_items.
* Discount changed
MOVE it_changedoc_items-value_old TO v_old_discount.
v_old_discount = v_old_discount / 10.
MOVE it_changedoc_items-value_new TO v_new_discount.
v_new_discount = v_new_discount / 10.
* Valid-from Date changed
it_changedoc_items-value_old TO wa_old-valid_from,
it_changedoc_items-value_new TO wa_new-valid_from.
* Valid-to Date changed
it_changedoc_items-value_old TO wa_old-valid_to,
it_changedoc_items-value_new TO wa_new-valid_to.
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 function parameters.
Click ‘Yes’ on the following pop up to auto-generate the method code.
begin_method reviewcond changing container.
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’
im_createdby = createdby
im_cond_type_name = condtype
ex_review_result = reviewresult
changedocument_position = changedocumenttable
OTHERS = 01.
WHEN 0. ” OK
WHEN OTHERS. ” to be implemented
swc_set_element container ‘ReviewResult’ reviewresult.
swc_set_table container ‘ChangeDocumentTable’ changedocumenttable.
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.
begin_method releasecond changing container.
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
CALL FUNCTION ‘RV_TABLE_NAME_SET’
rt_kotabnr = l_cond_tab
rt_kvewe = l_usage
rt_kotab = l_cond_tab_name.
MOVE l_cond_tab_name TO v_sel_tab_name.
* Update table to set Condition Record as RELEASED
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.
- Place cursor on method ‘ReleaseCond’ and change its release status to implemented
- Save and Generate object type ‘ZZBUS3005’
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
- 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.
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’
- 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
- Add a new ‘Activity’ step for generating a Review task.
Double Click on ‘Undefined Step’ and choose step type as ‘Activity’
Choose Create task
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.
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.
- 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
Pass the Business Object instance to this task
- Save and activate Workflow Template
- User creates a Condition record for Condition type ‘K007. Initially – the processing status is BLOCKED
- 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
- 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.