Quantcast
Channel: Sap & Microsoft Dynamics NAV (Navision) - sap
Viewing all articles
Browse latest Browse all 10

Substitution

$
0
0

Substitutions can be used for validating data at the time of entry in SAP system. It is possibile to create custom user exits so that one can set his validations & conditions. User exits are user defined FORM routines that are used to calculate/replace values with in a substitution.

What are substitutions?

Whenever a data is entered in a system, validations are invoked to check  its integrity .Once validations are done, one can substitute the entered value with some other value. This gives you the opportunity of having the system validate values that are to be substituted. A substitution value can be numeric or a string. The system first performs some validations and then substitutions.

Transactions used for substitutions are:                   

 GGB1:  Substitutions  maintenance.                                                                                                                                                                                                                                                           

 OBBH:  Activation of FI substitutions.

 Substitutions can be performed using three ways:

 1.Constant values.

 2.Field -Field assignment.

 3.User exits.

Steps for creating user exits for  substitutions.

The exits used for  substitutions are stored in a Include program. RGGBS000 is a standard include given by SAP for user exits for substitutions. So for creating custom user exits, one has to copy this include to a 'Z' (Custom namespace) program.

Step1 : Create a copy of include RGGBS000, let say ZTEST000.The length of the name you choose should not exceed 8 characters.

Step2 : Define your user exit in the FORM routine GET_EXIT_TITLES with the correct exit type (EXITS-PARAM).

exits-name  = 'U111'.
exits-param = c_exit_param_none.
exits-title = text-100.       "Give any suitable text for your exit
APPEND exits.

Include the EXIT NAME , PARAM and TITLE in the form GET_EXIT_TITLES .This form GET_EXIT_TITLES contains name and titles of all available standard exits. Every new exit need to be  added to this from. One has to specify a parameter type to enable the code generation program to determine correctly how to generate the user exit call ,i.e. How many and what kind of paramter(s) are used in the user exit. The following parameter types exist:

TYPE                                                    Description             
 -------------------------------------------------------------------------------------------------------
 C_EXIT_PARAM_NONE                     Use no parameter except B_RESULT . If you do not want to substitute a field, use this parameter in the substitution .
 C_EXIT_PARAM_FIELD                     Use one field as param. Exactly one field is substituted. 
 C_EXIT_PARAM_CLASS                    Use a type as parameter.

Step3: Create a FORM for your exit which will define itsfunctionality.

In form GET_EXIT_TITLES we have define our EXIT-NAME as  'U111'. So wee need to create a FORM with name U111 which will define the functionality of our user exit. Here I am taking a simple example of populating the Item Text (BSEG-SGTXT).

*---------------------------------------------------------------------*
*       FORM U111                                                               *
*---------------------------------------------------------------------*
*       Populate Item Text (BSEG-SGTXT)                                                              
*---------------------------------------------------------------------*
FORM U111.

  DATA: wl_awkey TYPE  bkpf-awkey.

  CONSTANTS: c_asterisk  TYPE c VALUE '*',
             c_hypen TYPE c VALUE '-'.

  CLEAR wl_awkey.

*-- Removing leading zeros
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
    EXPORTING
      input  = bkpf-awkey
    IMPORTING
      output = wl_awkey.

*-- Set the item text
  CONCATENATE c_asterisk bseg-zuonr c_hypen wl_awkey INTO bseg-sgtxt.

ENDFORM.                                                    "U111

You need to be cautious when writing code for your user exit. No dialog boxes, warning messages, information or error messages must be issued in an exit. Do not use any ABAP commands that cause you to leave the exit directly, for example LEAVE TO SCREEN. In the includes of the substitution exits, you must not use the commands MODIFY, INSERT or DELETE in the internally used structures such as BSEG or BKPF. These structures are interpreted internally as database tables because they are defined by a TABLES statement. As a result, the system writes, deletes or changes database records if you use the commands mentioned above. This can cause serious inconsistencies and problems in the document processing. If you want to change field contents in the exit type C_EXIT_PARAM_CLASS, you should make the changes in the internal table BOOL_DATA (for example BOLL_DATA-BSEG).

Step 4:Run transaction GCX2 to update IMG to use your new program instead of Standard SAP program for substitution exits.

Alternatively you can use   SPRO for  updating IMG. Run SPRO- Financial Accounting (New) - Special Purpose Ledger -Basic Settings - User Exits - Maintain Client Specific User Exits.

Update the program name RGGBR000 with your new program ZTEST000 for application area GBLS. Now you can use this user exit for substitutions.

substitution,sap

How to use custom user exit for a substitution?

Go to transaction GGB1. Here you can createchange a substitution. I am not going in detail for creating a  substitution. Specify the user exit (Highlighted area in red) for a field that is to be substituted buy your exit .

2.JPG

Also you can see the list of all the user exit on pressing F4 on the highlighted area in red. If your user exit is in active state, then it will be visible there. Once you have done the changes, Save it. Now your user exit will be invoked automatically for that field.


Viewing all articles
Browse latest Browse all 10