Dynamic actions trigger automatic processing when infotypes are maintained.
This document will guide us as how to write the code to perform additional checks and triggering the dynamic action.
Dynamic action can be triggered from the SPRO tcode following the path Personnel Management->Personnel Administration->Customizing Procedures->Dynamic Actions. This path will open the dynamic action table which can be maintained directly using table T588Z using SM30 tcode.
The dictionary definition of the table is as below.
Most of the field are self explanatory, small description is as below:
INFTY: This field specifies infotype on which certain operation causes dynamic action to trigger.
SUBTY: This field specifies corresponding subtype of the infotype on which certain operation causes dynamic action to trigger. This field is optional.
FNAME: Name of the field in the above mentioned infotype. This is again optional field.
OPERA: This specifies the operation performed in the infotype. This field will tell as when to trigger dynamic action (while create/change/delete operation).
Possible values of this field is as listed below.
|00||Independent of the current function carried out|
|06||Change and create|
|10||Change and delete|
|12||Create and delete|
SEQNO: This field specifies sequence number
KENNZ: This field specifies about the nature of the operation to be performed. Various values of this field is as specified in table below.
|P||Check conditions(behaves like IF condition)|
|I||Maintain infotype record. The possible actions are INS, COP, MOD, DEL [‘/D’ is used to run action in background]|
|W||Set default values when creating a new record|
|V||Reference to another step|
|F||Call routine (SAP program routine)|
|Any other entries refer to “comment line”.|
VINFO: This is very important field wherein the conditions and operations as specified in the ‘KENNZ‘ field is specified in brief.
There are some known fields which are automatically known while dynamic action is triggered. From SAP note Note 386027 – Dynamic actions.
Known fields: The fields of the infotype that triggers the dynamic action are known. Also, the table contents of the tables T001P (Personnel Area/Subarea) and T503 (Employee Group/Subgroup) and the structures PSPAR and PSAVE are known . T001P, T503 and PSPAR contain the values that are valid at the start date of the current record. PSAVE contains the old values of the infotype record.
As of Release 4.5, you can use the fields of structure RP50D, for example, by calculating or filling them in a FORM (‘F’) routine and then using them for checking or for the value specification when you maintain an infotype record.
Since this document is mainly intended for technical HR consultant, therefore we will work mainly with KENNZ (Indicator for step) field value ‘F’ of the dynamic action table and will write a routine which will do all the defaulting work for us.
Scenario: We will write a code so as to default the telephone number in the User Id field of communication infotype (IT0105), subtype ‘MPHN’ as well as begin date which should be defaulted to the last date of the IT0006 begin date. This action should take place when IT0006, subty ‘1’, field ‘TELNR’ is changed.
Also, if the country grouping of an employee is 10 (i.e USA), then ‘+1-‘ should be added before telephone number.
*Please note this scenario is a pure hypothetical one just for learning purpose.
Code: First thing before start writing the code is to maintain the dynamic action table T588Z, indicator for step field (KENNZ) should be maintained as ‘F’ so that the program routine is called.
Below is the T588Z entries maintained in our case.
As can be seen, just one Plausibility check (IF condition) is applied and then routine ‘CREATE_0105’ is called, whose definition is stored in custom program ZHR_INS.
All the further coding is done inside program ZHR_INS inside routine ‘CREATE_0105’. Program type can be either Executable (1) or Subroutine pool (S).
I have created a Subroutine pool as below:
Now, finally we will start with coding…
1. In the first screen shot below v_begda and v_phnno are the variables used to default the begin date and the User ID field in the IT0105, subtype ‘MPHN’ and the code is written as per our scenario.
INCLUDE MPPDAT00 is a very important include and should be used as it contains all the necessary data declarations used in Dynamic Actions.
2. The next screen-shot is very important and will default the values in the IT0105, subty ‘MPHN’ screen.
a. Internal table initial_values is used to store the field values which needs to be defaulted.Its definition is stored in include MPPDAT00. We just need to append the relevant field and its corresponding values along with the SEQNR to default the various fields in the targeted infotype.
b. Other internal table is used for triggering of the targeted infotype and should be populated with the field like ACTIO, INFTY, SUBTY,..,SEQNR as below.
That finishes the coding part, now we will test our dynamic action by changing TELNR field in IT0006 for an US employee.
Please note that the start date of IT0006 record is 01-jan-1996 so start date of IT0105 should be 31-jan-1996 and also TELNR here is 1234789041 so our USER ID field should be +1-1234789041.
On pressing save, our IT0105 is triggered with all the desired values.
The complete code is attached in the .txt file format.