domingo, 4 de fevereiro de 2018

Approval Workflow for Pricing Condition

Business Scenario:

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.
/wp-content/uploads/2013/10/1_311556.png
  • Enter Condition type ‘K007’ and hit ‘Enter’ on the subsequent Pop up screen.
/wp-content/uploads/2013/10/2_311557.png /wp-content/uploads/2013/10/3_311561.png
  • Enter any Customer number, Amount and Set Processing status as ‘Blocked’
/wp-content/uploads/2013/10/3_311561.png
  • Set ‘Processing status’ field as ‘Output Only’ and ‘With Content’ on the subsequent popup screen. (screen variant)
/wp-content/uploads/2013/10/5_311563.png
  • Hit Save and then ‘Enter’ on the next pop up screen.
/wp-content/uploads/2013/10/6_311564.png
  • 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.
/wp-content/uploads/2013/10/7_311565.png
         Transaction VK11 now has the Processing Status as a non-editable column with Default value as 1 (Blocked)
/wp-content/uploads/2013/10/8_311567.png
  • Call Transaction SHD0 and activate the same Transaction variant ’ZVAR_VK’ for Condition Change transaction – VK12.
/wp-content/uploads/2013/10/9_311568.png
  • Similarly, screen variants can be created for other condition types and assigned to this transaction variant.
/wp-content/uploads/2013/10/10_311569.png
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
/wp-content/uploads/2013/10/11_311570.png
Extend Business Object BUS3005 (Condition)

  • Call transaction SWO1 (Business Object Builder) and create object type ZZBUS3005
/wp-content/uploads/2013/10/12_311571.png
  • Provide Object name, Description and underlying program name. Supertype indicates that this object type is inherited from standard SAP business object type BUS3005.
/wp-content/uploads/2013/10/13_311572.png
  • Change Object Release status to ‘Implemented’
/wp-content/uploads/2013/10/14_311573.png
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.
/wp-content/uploads/2013/10/15_311574.png
  • Place cursor on event and change its release status to implemented
/wp-content/uploads/2013/10/16_311575.png
  • Create Event Parameters
Place cursor on event and choose ‘Parameters’.
/wp-content/uploads/2013/10/17_311576.png/wp-content/uploads/2013/10/18_311577.png
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)
/wp-content/uploads/2013/10/19_311578.png
  • Create another Event ‘Changed’ with the same event parameter ‘ChangeDoc_Pos’ of structure type CDPOS.
/wp-content/uploads/2013/10/20_311579.png
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’
/wp-content/uploads/2013/10/21_311580.png
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 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
  swc_set_table event_container ‘ChangeDoc_Pos’  changedocument_position.
ENDFUNCTION.
  • Also add a new entry for ‘Changed’ Event.
/wp-content/uploads/2013/10/22_311581.png
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.
/wp-content/uploads/2013/10/23_311582.png/wp-content/uploads/2013/10/24_311583.png

  • Provide table name as ‘KONH’ and select the fields as shown. (More fields can be chosen if required within Workflow.)
/wp-content/uploads/2013/10/25_311584.png

  • Click ‘Create’ on all subsequent popup screens to create all selected attributes
/wp-content/uploads/2013/10/26_311585.png
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.
Sample Screen
/wp-content/uploads/2013/10/27_311586.png
  • 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 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’.
/wp-content/uploads/2013/10/28_311587.png /wp-content/uploads/2013/10/29_311588.png
Set method as Dialog and create method parameters using function parameters.            
/wp-content/uploads/2013/10/30_311589.png/wp-content/uploads/2013/10/31_311590.png
    
Click ‘Yes’ on the following pop up to auto-generate the method code.
/wp-content/uploads/2013/10/32_311591.png
Auto-generated Code:
begin_method reviewcond changing container.

DATA:
      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.
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.
/wp-content/uploads/2013/10/33_311592.png/wp-content/uploads/2013/10/34_311593.png
  • Place cursor on method ‘ReleaseCond’ and click ‘Program’ to write method code.
/wp-content/uploads/2013/10/35_311594.png
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
    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
/wp-content/uploads/2013/10/36_311595.png
  • Save and Generate object type ‘ZZBUS3005’
/wp-content/uploads/2013/10/37_311596.png
Setup Business Object Delegation

  • Call transaction SWO1 and click on Setting -> Delegate
/wp-content/uploads/2013/10/38_311598.png
Add ‘New Entry’
/wp-content/uploads/2013/10/39_311599.png
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
/wp-content/uploads/2013/10/40_311600.png

  • Click on ‘Basic Data’ tab to setup triggering events
/wp-content/uploads/2013/10/41_311601.png
  • Go to ‘Start Events’ tab and setup ‘Created’ and ‘Changed’ events of Business Object BUS3005 as the triggering events for this workflow template.
/wp-content/uploads/2013/10/42_311602.png
  • Activate the event linkages.
This setting will trigger a workflow instance every time a Condition record is created or changed.
/wp-content/uploads/2013/10/43_311603.png
  • For each event, setup start condition -> (Condition type = ‘K007’)
This ‘Start Condition’ will be evaluated before triggering new workflow instance.
/wp-content/uploads/2013/10/44_311604.png
  • Create Workflow Container variable ‘ChangeDoc_Pos’
/wp-content/uploads/2013/10/45_311605.png

  • 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
/wp-content/uploads/2013/10/46_311606.png

  • Similarly create Workflow Container variable ‘BUS3005’ of object type ‘BUS3005’ and set its property as ‘Import’ Parameter.
/wp-content/uploads/2013/10/47_311607.png
  • 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
/wp-content/uploads/2013/10/48_311608.png

  • Add a new ‘Activity’ step for generating a Review task.
Double Click on ‘Undefined Step’ and choose step type as ‘Activity’
/wp-content/uploads/2013/10/49_311609.png

Choose Create task
/wp-content/uploads/2013/10/50_311610.png /wp-content/uploads/2013/10/51_311611.png


Click ‘Yes’ on the subsequent pop up to auto-create Task Container variables.
/wp-content/uploads/2013/10/52_311612.png

Make sure that Change Document table is passed to the task and Review Result is retrieved back to Workflow.
/wp-content/uploads/2013/10/53_311613.png /wp-content/uploads/2013/10/54_311614.png
Set the task as General Task
Use Rule ‘00000168’ to determine ‘Approver’ as the manager of the User (who creates/changes a condition record)
/wp-content/uploads/2013/10/55_311615.png
  • Add a condition step todetermine the Result of Approval.
/wp-content/uploads/2013/10/56_311616.png /wp-content/uploads/2013/10/57_311617.png
  • Add new Activity step for Releasing Condition Record in background.
Right click on the outcome branch ‘Approved’ and select ‘Create’ – Activity Step
/wp-content/uploads/2013/10/58_311618.png

Choose Create task
/wp-content/uploads/2013/10/59_311619.png /wp-content/uploads/2013/10/60_311660.png

Pass the Business Object instance to this task
/wp-content/uploads/2013/10/61_311621.png
  • Save and activate Workflow Template
               
Working DEMO

  • User creates a Condition record for Condition type ‘K007. Initially – the processing status is BLOCKED
/wp-content/uploads/2013/10/62_311622.png
  • On SAVE, the Workflow gets triggered and Approval item is routed to the Manager of the User who created the Condition record.
/wp-content/uploads/2013/10/63_311623.png
At this time, the customer discount is not reflected in the Order
/wp-content/uploads/2013/10/64_311624.png
/wp-content/uploads/2013/10/65_311625.png
  • 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)
/wp-content/uploads/2013/10/66_311627.png
  • On Approval, the Condition Record is released and customer discount is now applied on to the Gross Price of the Order.
/wp-content/uploads/2013/10/67_311628.png
/wp-content/uploads/2013/10/68_311629.png

Fonte: https://blogs.sap.com/2013/10/30/approval-workflow-for-pricing-condition/

Nenhum comentário:

Postar um comentário