Monday, August 20, 2012

How to use Substitution Method in SAP FI

Substitution method used in SAP FI

Substitution method is used in SAP just like VOFM routine used in SAP SD. This helps us to validate or pass some values to SAP at the time of data entry in SAP system.

It's very simple to create a substitution method in SAP system. We just need to follow following steps.

1.Execute tcode 'OBBH' to setup substitution settings. This will ask  to maintain following entries in as shown in screen shot.

Maintain 'Company code' for which it's going to be used. Then maintain 'Validation/Substitution callup point' as per requirement.

After this  enter ths substitution and double click on it to create a new one.


After this create a step for Exit or field assignment as per requirement.

 We can select a single or multiple fields for substitution.
After this pass the Exit Name.


Note: Before we pass the Exit Name, we need to create the Exit in RGGBS000 program. This is given in later part of this blog.

Now we need to make sure that our exit should work for a specific condition only. For this 'Prerequisite' section is provided. pass your fields name from the 'Table fields' tab and it's value as shown below.


Now maintain the routine U903 in program RGGBS000.
Open the program RGGBS000 in ABAP Editor. Go Inside routine 'GET_EXIT_TITLES'.  create and enhancement and add the following code.

    exits-name  'U903'.
  exits-param c_exit_param_field"c_exit_param_none . "
  exits-title 'Shipment Cost Material Derivation'.
  APPEND exits.
* end of insertion
 
  REFRESH etab.
  LOOP AT exits.
    etab exits.
    APPEND etab.
  ENDLOOP.


this will add your exit name in Exit internal table 'ETAB'. After this call your subroutine as shown below.  Here I am using my exit to pass material and profit center at run time.
FORM U903 USING bseg-matnr.
DATAl_matnr TYPE matnr,
      l_werks TYPE werks_d,
      l_vbeln TYPE vbeln,
      l_PRCTR TYPE PRCTR.
CLEARl_PRCTR,l_matnr,l_vbeln,l_werks.
*Get Delivery
  SELECT SINGLE vbeln FROM vttp INTO l_vbeln
    WHERE tknum BKPF-XBLNR.
  IF sy-subrc eq 0.
*Get the Material from LIPS
    SELECT SINGLE matnr werks
      INTO (l_matnrl_werks )
      FROM lips
      WHERE vbeln l_vbeln.
    IF sy-subrc eq 0.
      BSEG-matnr l_matnr.
*Get Profit Centre
      SELECT SINGLE PRCTR INTO l_prctr
        FROM marc
        WHERE matnr l_matnr
          AND werks l_werks.
      IF sy-subrc eq 0.
        BSEG-PRCTR l_PRCTR.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM.

Now Save and activate your program. Now your exit U903 is ready to use.
before executing your program just check whether your Exit program is configured in your config or not.
Execute the Tcode 'GCX2'. it will display yourexit program for the respective application area.



Now we can test and our exit will work at run time and pass the material and profit centre value using substitution method U903.