Skip to Content
Technical Articles
Author's profile photo Yogananda Muthaiah

SAP Commissions – Under the hood of Stage-hooks

Adding Pipeline Stage Hooks

If custom pipeline processing is required before a pipeline stage is run, after a stage
completes, or in the event of any stage exits due to an application exception, stage hooks can
be added to perform the required processing.

so below are the types of pipeline stage hooks, how to create and install them, and provides you a samples of each type of stage hook.

Types of Pipeline Stage Hooks

Pipeline stage hooks can support java class, script file, or stored procedure.

Type Description
Java class A java class. This class must implement an interface, StageHook.
To use a java class stage hook, you must install the java class first.
For a sample java class, including a sample xml descriptor, installation
instructions, and a definition of the StageHook interface,
Script file A batch file or shell script
Stored procedure A stored procedure, compiled into the TCMP/EXT schema

Note: All stage hook messages are logged to the controller.log. For a stage failure
hook, the pipeline exits after the stage failure hook returns

Pipeline stage hooks have three possible run times, as described

Pipeline Stage Hook Run Times

Type Description
pre-stage Pre-stage hooks are executed prior to the specified stage.
For example, a prestage hook for the Allocate stage will execute before the Allocate stage begins.
post-stage Post-stage hooks are executed after the specified stage has completed.
For example, a post-stage hook for the Allocate stage will execute when the
Allocate stage completes
stage failure A stage failure hook is called if any stage exits because there is an exception
during the pipeline run. You can only specify one stage failure hook for the
whole pipeline. If any stage exits due to an exception, the stage failure hook is
called. A common use of the stage failure hook is to call a program to send email to an administrator if there is a pipeline failure

Defining Pipeline Stage Hooks

Stage hooks are defined in a file called StageHookDescriptor.xml. This file needs to be provided to Technical Support team through ticket which will be placed on Pipeline Grid Server in the following location: /pipeline/classpath/properties

Note: Any time that you add stage hooks, support team must restart the application server. A file called StageHookDescriptorTemplate.xml is included in directory. file can be used as a reference to create a StageHookDescriptor.xml file. The tags and attributes of the StageHookDescriptor.xml file


sample StageHookDescriptor.xml

<?xml version="1.0" encoding="UTF-8"?>
<stagehooks version="1.0">
   <script />
   <script />
   <stagehook stagename="AllocateAggregation">
      <poststage type="storedproc">
         <command>EXT.Yoga_Stagehook.PostAllocateAggregation</command>
         <pipelineArgs>
            <name>period</name>
            <name>calendar</name>
            <name>processingUnitSeq</name>
         </pipelineArgs>
      </poststage>
   </stagehook>
   <stagehook stagename="Reward">
      <poststage type="storedproc">
         <command>EXT.Yoga_Stagehook.Stamp_PostReward</command>
         <pipelineArgs>
            <name>period</name>
            <name>calendar</name>
            <name>processingUnitSeq</name>
         </pipelineArgs>
      </poststage>
   </stagehook>
   <stagehook stagename="Classify">
      <prestage type="storedproc">
         <command>EXT.Yoga_Stagehook.PreClassify</command>
         <pipelineArgs>
            <name>period</name>
            <name>calendar</name>
            <name>processingUnitSeq</name>
         </pipelineArgs>
      </prestage>
   </stagehook>
</stagehooks>

Stored Proc Package

CREATE OR REPLACE PACKAGE EXT.Yoga_Stagehook
as
PROCEDURE PostAllocateAggregation (
P_PERIODNAME IN CS_PERIOD.NAME%TYPE ,
P_CALENDARNAME IN CS_CALENDAR.NAME%TYPE,
P_PROCESSINUNITSEQ IN CS_PROCESSINGUNIT.PROCESSINGUNITSEQ %TYPE 
 ) ;
 
 PROCEDURE PostReward (
P_PERIODNAME         IN CS_PERIOD.NAME%TYPE,
P_CALENDARNAME       IN CS_CALENDAR.NAME%TYPE,
P_PROCESSINUNITSEQ   IN CS_PROCESSINGUNIT.PROCESSINGUNITSEQ%TYPE
);

Procedure PreClassify(
      P_PERIODNAME         IN CS_PERIOD.NAME%TYPE,
      P_CALENDARNAME       IN CS_CALENDAR.NAME%TYPE,
      P_PROCESSINUNITSEQ   IN CS_PROCESSINGUNIT.PROCESSINGUNITSEQ%TYPE);
 
end Yoga_Stagehook;
/

Stored Proc Package body

CREATE OR REPLACE PACKAGE BODY EXT.Yoga_Stagehook 
AS g_periodname cs_period.name%TYPE;

g_periodseq cs_period.periodseq%TYPE;
g_period_startdate cs_period.startdate%TYPE;
g_period_enddate cs_period.enddate%TYPE;
g_processingunitseq cs_processingunit.processingunitseq%TYPE;
g_processingunitname CS_PROCESSINGUNIT.NAME%TYPE;
g_calendarname cs_calendar.name%TYPE;
g_calendarseq cs_calendar.calendarseq%TYPE;
g_eot cs_period.removedate%TYPE := TO_DATE ('1-JAN-2200',
                                            'DD-MON-YYYY');
g_unittypeseq CS_UNITTYPE.UNITTYPESEQ%TYPE;

PROCEDURE setGlobals (p_period cs_period.name%TYPE, p_calendar cs_calendar.name%TYPE, 
p_processingunit cs_processingunit.name%TYPE) 
AS 
BEGIN 
g_calendarname := p_calendar;

g_periodname := p_period;
g_processingunitname := p_processingunit;


SELECT processingunitseq INTO g_processingunitseq
FROM cs_processingunit
WHERE name = g_processingunitname;

DBMS_OUTPUT.put_line ('g_calendarname=' || g_calendarname);


SELECT calendarseq INTO g_calendarseq
FROM cs_calendar
WHERE name = g_calendarname
  AND removedate = g_eot;


SELECT periodseq,
       startdate,
       enddate INTO g_periodseq,
                    g_period_startdate,
                    g_period_enddate
FROM cs_period
WHERE calendarseq = g_calendarseq
  AND removedate = g_eot
  AND name = g_periodname;


SELECT UNITTYPESEQ INTO g_unittypeseq
FROM cs_unittype
WHERE name='USD'
  AND removedate >sysdate;

END setGlobals;

----         Start your Procedure      -----------------


----         End your Procedure      -----------------
END Yoga_Stagehook;
/

Run the pipeline to check if stagehook is getting Triggered,

Go to Pipeline Logs – Select the Stage where stagehook is placed and download

Understanding through Logs

Assigned Tags

      14 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Krishnan Ramany
      Krishnan Ramany

      This is a good article. One of the Key aspects is to ensure that the Developers write Stagehooks keeping in mind the overall expected pipeline performance. Poorly designed queries can increase Pipeline Run times.

      Author's profile photo Yogananda Muthaiah
      Yogananda Muthaiah
      Blog Post Author

      that's absolutely right Krishnan Ramany !!

      Author's profile photo Lara Golden
      Lara Golden

      Really useful article, Yoga! Thank you for writing this.

      Author's profile photo Yogananda Muthaiah
      Yogananda Muthaiah
      Blog Post Author

      Thank you Lara Golden !!

      Author's profile photo Olivier Franco
      Olivier Franco

      Very useful article. Thank you for share it. I have a question about stage hook, Do you know if it is possible to update core tables (e.g CS_CREDIT) from a stored procedure?.

      Author's profile photo Yogananda Muthaiah
      Yogananda Muthaiah
      Blog Post Author

      yes Its possible Olivier Franco

      you need to have grants to do UPDATE statement on TCMP schema.

      Author's profile photo Olivier Franco
      Olivier Franco

      Thanks for your answer. We'll try it using your advice.

      Author's profile photo Yogananda Muthaiah
      Yogananda Muthaiah
      Blog Post Author

      Sure Olivier Franco

      Keep sharing all the blogs to your friends as well to make more larger group.

      Author's profile photo Tas Cullen
      Tas Cullen

      Hi Yoga,

      Under stage failure, you state that a common usage is to trigger emails to be sent. Do you have an example of how that might be done in the EXT schema?

      Thanks

      Author's profile photo Yogananda Muthaiah
      Yogananda Muthaiah
      Blog Post Author

      Tas Cullen

      yes, you can configure the Business Process Management from SPM home page and have Calculation Failure enabled which will send notification to users.      Its pipeline process and nothing related to EXT Schema.

      Author's profile photo Daniele Antonioli
      Daniele Antonioli

      Good morning.

      Support shared me StageHookDescriptorTemplate.xml but it's different than what's above; it also says inside "Please read the "TrueCompManager Plug-in Developers Guide" for an
      explanation of how to use stage hooks."

      is it possible to get the guide somehow?

       

      Thank you.

      Regards,

      Daniele

      Author's profile photo Yogananda Muthaiah
      Yogananda Muthaiah
      Blog Post Author

      Daniele Antonioli

      Kindly setup a meeting with support and ask some to copy me, I will join and discuss.

      Author's profile photo Daniel Harsojo
      Daniel Harsojo

      Hi Yoga,

      Do you know if we can apply a stagehook on the 'Update Analytics" stage?

      Author's profile photo Yogananda Muthaiah
      Yogananda Muthaiah
      Blog Post Author

      aniel Harsojo

      Yes you can use it .