You are on page 1of 33

1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

GetStarted

Solutions Support Training Community Developer

Partner About

Community / Blogs

ApprovalWorkflowforPricing
Condition
October30,2013 | 678Views |
TanmayVyas
morebythisauthor

SAPBusinessWorkflow

abapdevlopment | pricingconditionpricing | pricingsalesorder | sapsalesand


distribution | sapsd | sapsdpricing | sapworkflow | sapworkflowdesign | workflow
approval

share
0 share
0 tweet share
0

Follow

BusinessScenario:

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/approvalworkflowforpricingcondition/ 1/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

change the net price of an order, the discount/surcharge must be


approvedbyamanager.Creatingorupdatingadiscount/surcharge
recordshouldtriggeraworkflowapprovalevent.Oncetheworkflow
object is approved by the appropriate manager, the condition
record is released and the discount/surcharge is applied to the
order.

Forthepurposeofdemo,considertheconditiontypeforCustomer
Discount (K007). This document provides a custom solution for
developingApprovalWorkflowforConditionRecords.

Create Transaction Variant to make Processing Status non


editableandassignadefaultvalue

Aprocessor(salesclerk)cancreateandchangeconditionrecords
viaVK11/VK12transactions.Itisnecessarytodisablethe
processingstatusfieldinordertopreventthesalesclerkfrom
accidentlysettingthestatusasReleased.

CalltransactionSHD0.EntertransactioncodeasVK11and
ZtransactionvariantZVAR_VK.ClickonCreatebutton.

EnterConditiontypeK007andhitEnteronthesubsequent
Popupscreen.

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 2/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

EnteranyCustomernumber,AmountandSetProcessing
statusasBlocked

SetProcessingstatusfieldasOutputOnlyandWith
Contentonthesubsequentpopupscreen.(screenvariant)

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 3/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

HitSaveandthenEnteronthenextpopupscreen.

SavetheTransactionVariantZVAR_VKandScreenvariant
ZVAR_VK_1307.GotoStandardVariantstabandactivate
TransactionVariantZVAR_VK.ThissetsZVAR_VKas
defaulttransactionvariantforVK11transaction.

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 4/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

TransactionVK11nowhastheProcessingStatusasanon
editablecolumnwithDefaultvalueas1(Blocked)

CallTransactionSHD0andactivatethesameTransaction
variantZVAR_VKforConditionChangetransactionVK12.

Similarly,screenvariantscanbecreatedforothercondition
typesandassignedtothistransactionvariant.

Fore.g.TransactionVK12nowhastheProcessingStatusasa
noneditable column with Default value as 1 (Blocked) for
conditiontypePR01

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 5/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

ExtendBusinessObjectBUS3005(Condition)

CalltransactionSWO1(BusinessObjectBuilder)andcreate
objecttypeZZBUS3005

ProvideObjectname,Descriptionandunderlyingprogram
name.Supertypeindicatesthatthisobjecttypeisinherited
fromstandardSAPbusinessobjecttypeBUS3005.

ChangeObjectReleasestatustoImplemented

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 6/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

CreateCustomEvents

PlacecursoronEventsandclickCreate.Onthe
subsequentpopupscreenprovideeventnameCreated.
ThiseventwillserveasTriggeringeventfortheCondition
RecordApprovalWorkflow.

Placecursoroneventandchangeitsreleasestatusto
implemented

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 7/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

CreateEventParameters

PlacecursoroneventandchooseParameters.

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.
(Whilecreation,theoldvalueswillbeblank)

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 8/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

Create another Event Changed with the same event


parameterChangeDoc_PosofstructuretypeCDPOS.

ConfigureWorkflowTriggeringeventsonChangeDocument

When a change to a Condition Record is logged by the system using


Change Document object COND_A the following event linkages will
triggerthecorrespondingBusinessobjectEvents.

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 9/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

CalltransactionSWEC(EventLinkageforChange
Documents)andclickonNewEntries

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
ContainerwithtableofChangeDocumentItemsi.e.Detailsof
thechangemadetotheConditionrecord.

Samplecode:

FUNCTION z_fill_event_cont.

*-

**Local Interface:

* IMPORTING

* 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

* TABLES

* EVENT_CONTAINER STRUCTURE SWCONT OPTIONAL

* CHANGEDOCUMENT_POSITION STRUCTURE CDPOS

OPTIONAL

*-

* Fill Event Container from Change-document

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 10/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

swc_set_table event_container

ChangeDoc_Pos changedocument_position.

ENDFUNCTION.

AlsoaddanewentryforChangedEvent.

This entry will trigger BUS3005.Changed event every time a


Conditionrecordischanged.

CreateCustomAttributes

PlacecursoronAttributesandclickCreate.HitYesonthe
subsequentpopup.

ProvidetablenameasKONHandselectthefieldsas
shown.(Morefieldscanbechosenifrequiredwithin

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 11/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

Workflow.)

ClickCreateonallsubsequentpopupscreenstocreateall
selectedattributes

CreateCustomMethods

ReviewPricingConditionThismethodisusedtopresenta
customapprovalscreentotheReviewer(Salesmanager)

CreateanewfunctionZ_REVIEW_CONDanddesigna
customApprovalscreenthatlistsOld/Newvaluesofthe
PricingConditionrecordandApprove/RejectButtons.

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 12/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

SampleScreen

FunctionmoduleZ_REVIEW_CONDcanbedevelopedwith
the assumption that Change Document table is passed to it
fromworkflow.
For each relevant field in the Change Document table
capture the old and new values and display on custom
screen.
FetchCustomernumberfromConditiontable.(A307inthis
example)
Capture the Review Result as A for Approved and R for
RejectedandpassitasExportingparameter.

Samplecode:

* 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/approvalworkflowforpricingcondition/ 13/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

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
nameZ_REVIEW_COND.

Set method as Dialog and create method parameters using

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 14/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

functionparameters.

Click Yes on the following pop up to autogenerate the


methodcode.

AutogeneratedCode:

begin_method reviewcond changing container.

DATA:

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 15/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

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/approvalworkflowforpricingcondition/ 16/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

swc_set_table container

ChangeDocumentTable

changedocumenttable.

end_method.

ReleasePricingConditionThismethodisusedtoRelease
theblockontheConditionrecordafterApproval.

PlacecursoronMethodandclickCreate.Onthe
subsequentpopupscreenprovidemethodname
ReleaseCond.ThismethodisaBackgroundmethod.

PlacecursoronmethodReleaseCondandclickProgramto
writemethodcode.

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 17/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

SampleCode:

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/approvalworkflowforpricingcondition/ 18/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

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.

PlacecursoronmethodReleaseCondandchangeits
releasestatustoimplemented

SaveandGenerateobjecttypeZZBUS3005

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 19/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

SetupBusinessObjectDelegation

CalltransactionSWO1andclickonSetting>Delegate

AddNewEntry

Thissettingcausesallthenewmethods,attributesandevents
fromZZBUS3005(subtype)willbeavailablewithinobjecttype
BUS3005(supertype)whenitisusedinanyWorkflow.

BuildtemplateforPricingConditionWorkflow

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 20/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

CalltransactionSWDDWorkflowBuilder.ClickSaveand
providenamefortheWorkflowtemplate

ClickonBasicDatatabtosetuptriggeringevents

GotoStartEventstabandsetupCreatedandChanged
eventsofBusinessObjectBUS3005asthetriggeringevents
forthisworkflowtemplate.

Activatetheeventlinkages.

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 21/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

This setting will trigger a workflow instance every time a


Conditionrecordiscreatedorchanged.

Foreachevent,setupstartcondition>(Conditiontype=
K007)

This Start Condition will be evaluated before triggering new


workflowinstance.

CreateWorkflowContainervariableChangeDoc_Pos

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 22/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

SetvariableChangeDoc_PospropertyasImportand
Multiline.ThisindicatesthattheChangeDocumenttablewill
bepassedtotheWorkflowfromtheTriggeringEvent

SimilarlycreateWorkflowContainervariableBUS3005of
objecttypeBUS3005andsetitspropertyasImport
Parameter.

GotoStartEventsunderBasicDataandsetuptheData
bindingasshownforbothevents.Thissettingpassesdata
fromEventcontainertoWorkflowcontainerduringthe
triggeringoftheWorkflow

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 23/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

AddanewActivitystepforgeneratingaReviewtask.

Double Click on Undefined Step and choose step type as


Activity

ChooseCreatetask

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 24/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

Click Yes on the subsequent pop up to autocreate Task


Containervariables.

MakesurethatChangeDocumenttableispassedtothetask
andReviewResultisretrievedbacktoWorkflow.

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 25/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

SetthetaskasGeneralTask

UseRule00000168todetermineApproverasthemanager
oftheUser(whocreates/changesaconditionrecord)

AddaconditionsteptodeterminetheResultofApproval.

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 26/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

AddnewActivitystepforReleasingConditionRecordin
background.

Right click on the outcome branch Approved and select


CreateActivityStep

ChooseCreatetask

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 27/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

PasstheBusinessObjectinstancetothistask

SaveandactivateWorkflowTemplate

WorkingDEMO

UsercreatesaConditionrecordforConditiontypeK007.
InitiallytheprocessingstatusisBLOCKED

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 28/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

OnSAVE,theWorkflowgetstriggeredandApprovalitemis
routedtotheManageroftheUserwhocreatedtheCondition
record.

Atthistime,thecustomerdiscountisnotreflectedintheOrder

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 29/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

TheSalesManagercanviewthefollowingReviewScreenby
executingtheApprovalWorkitem.(Oldvaluesareblank
sincethisisanewcondition)

OnApproval,theConditionRecordisreleasedandcustomer
discountisnowappliedontotheGrossPriceoftheOrder.

AlertModerator

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 30/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

8Comments
YoumustbeLoggedontocommentorreplytoapost.

ODManikandan

October31,2013at7:10am

VeryNicematerial
Regards,
OD

RonenWeisz

January29,2014at7:24pm

Ihavebeenlookingforawaytodothisforalongtime,
andseeingthewholeprocessasyoushoweditwasveryhelpful.
Onequestion,doyouknowofanywaytodotheconditionupdatewitha
functionmoduleandnotwithadirectupdate?
Ronen

JyotiPrakash

May2,2014at11:52am

Tanmay
Nice&elaborateddocumentation.Keepthegoodwork&wordmoving.
Thanks.
BestWishes,
JP

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 31/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

satishkumarpulijala

May2,2014at5:27pm

hitanmayvyas
Nicematerial
thanku
satish

anandkumarradhakrishnan

May3,2014at7:08am

GoodExplanation!!Thanksalot

WallaceFerreiraeSilva

February5,2016at4:19pm

HiTanmay,
Ifapprovaluserclickcancelbuttoninareviewscreenworkitemis
completed.
Ithinktomovereleasecodeforreviewscreen,becausethemethod
mustbeasynchronousanddontacceptexportparameter.
Howdoyouimplementcancelbuttoninworkflow?
Thanksinadvance.
Wallace

TanmayVyas Postauthor

February22,2016at8:58pm

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 32/33
1/23/2017 ApprovalWorkflowforPricingCondition|SAPBlogs

HiWallace,
InthegivenscenarioIhaveusedaSynchronousmethod
fortheReviewtask.OnclickofCancelbuttonYoucan
usemacroexit_cancelledtoCANCELtheprocessingofthe
workitembutstillkeeptheworkitemwithintheApprovers
inbox.
Tanmay

WallaceFerreiraeSilva

February23,2016at12:41pm

ThanksTanmay,
Iusedassychronousmethodwithsucesss.But
inVK11andVK12whenuserentermoreone
lineintabelcontrolkbstatnotfilledwithscreen
variant.
Howdosolvedthisissue?
Thanksinadvanceandcongratsgreatjob!

Share & Follow


Privacy TermsofUse LegalDisclosure Copyright Trademark Sitemap Newsletter

https://blogs.sap.com/2013/10/30/approvalworkflowforpricingcondition/ 33/33

You might also like