Wednesday 24 December 2014

               Enhancements

Enhancements: to add your own functionality to SAP's standard business applications without having to modify the original applications.

There are four ways of doing enhancements in SAP:
1. User exits
2. Customer exits
3. BADI's
4. Enhancement Frameworks

 1.      User exits:
   These are technically modifications. SAP provides many subroutine(s) with name USEREXIT_ * (i.e. ex: FORM USEREXIT_001)
these are saved in many includes which can be found via SE80 >> Search for Package VMOD. These are also called as Form exits.

Custom coding can be done in the subroutine. But the main disadvantage of these exits are : It requires Access key and only SD module supports this kind of enhancements.

2. Customer exits: 
Technically enhancements. Will not affect the source code of SAP program and hence no problem during upgrade.  There are 3 kinds of Customer exits


a) Function exits: 
Provided by means of FM’s (Function modules) .The code for the function module is written by the developer. You are not writing the code directly in the function module, but in the 'Z' include that is implemented in the function module.

Ex: open any Function module EXIT_* in se37

Ex: EXIT_SAPMF02K_001. But in the SAPMF02K program you will see this as
CALL CUSTOMER-FUNCTION '001'
it will have a Z include file, just edit the file directly. No Access key required.

b) Menu Exits: 
Enhances the menu available in standard SAP program. Developer can add his/her own text and logic for the menu. Function codes for menu exits all start with "+".
   Format:  +CUS (additional item in GUI status)

c) Screen exits:
Used to enhance the screen, add elements in screen etc
 Format:  CALL CUSTOMER-SUBSCREEN CUSTSCR2


d) Field exits:
Using field exits field label of data element can be changed.

3. BADI's: 
Business Add-Ins may be simply defined as an object-oriented extension of the SAP enhancement technique. Multiple implementation for same BADI can be done as BADI supports encapsulation of data. 

BADI's are classified into 3types.
a. Standard badi.
b. Custom badi.
c. Filter badi.
Filter badi is a part of custom badi. We know that in badi's one badi definations can be implemented n number of times. Such concept can be exploited using filter badi.



Note: In standard BADI, BADI definitions are predefined.


Find BADI & USER EXITS:


*&---------------------------------------------------------------------*

*& Report  Z_FIND_BADI

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*



REPORT Z_FIND_BADI.


TABLES : TSTC, TADIR, MODSAPT, MODACT, TRDIR, TFDIR, ENLFDIR, SXS_ATTRT, TSTCT.
DATA : JTAB LIKE TADIR OCCURS 0 WITH HEADER LINE.
DATA : FIELD1(30).
DATA : V_DEVCLASS LIKE TADIR-DEVCLASS.
DATA WA_TADIR TYPE TADIR.

PARAMETERS : P_TCODE LIKE TSTC-TCODE,
P_PGMNA LIKE TSTC-PGMNA .

START-OF-SELECTION.
IF NOT P_TCODE IS INITIAL.
  SELECT SINGLE * FROM TSTC WHERE TCODE EQ P_TCODE.
ELSEIF NOT P_PGMNA IS INITIAL.
  TSTC-PGMNA = P_PGMNA.
ENDIF.
IF SY-SUBRC EQ 0.
  SELECT SINGLE * FROM TADIR
        WHERE PGMID = 'R3TR'
          AND OBJECT = 'PROG'
          AND OBJ_NAME = TSTC-PGMNA.
  MOVE : TADIR-DEVCLASS TO V_DEVCLASS.
  IF SY-SUBRC NE 0.
    SELECT SINGLE * FROM TRDIR
          WHERE NAME = TSTC-PGMNA.
    IF TRDIR-SUBC EQ 'F'.
      SELECT SINGLE * FROM TFDIR
            WHERE PNAME = TSTC-PGMNA.
      SELECT SINGLE * FROM ENLFDIR
            WHERE FUNCNAME = TFDIR-FUNCNAME.
      SELECT SINGLE * FROM TADIR
            WHERE PGMID = 'R3TR'
              AND OBJECT = 'FUGR'
              AND OBJ_NAME EQ ENLFDIR-AREA.
      MOVE : TADIR-DEVCLASS TO V_DEVCLASS.
    ENDIF.
  ENDIF.
  SELECT * FROM TADIR INTO TABLE JTAB
        WHERE PGMID = 'R3TR'
          AND OBJECT IN ('SMOD', 'SXSD')
          AND DEVCLASS = V_DEVCLASS.
  SELECT SINGLE * FROM TSTCT
        WHERE SPRSL EQ SY-LANGU
          AND TCODE EQ P_TCODE.
  FORMAT COLOR COL_POSITIVE INTENSIFIED OFF.
  WRITE:/(19) 'Transaction Code - ',
        20(20) P_TCODE,
        45(50) TSTCT-TTEXT.
  SKIP.
  IF NOT JTAB[] IS INITIAL.
    WRITE:/(105) SY-ULINE.
    FORMAT COLOR COL_HEADING INTENSIFIED ON.
* Sorting the internal Table
    SORT JTAB BY OBJECT.
    DATA : WF_TXT(60) TYPE C,
          WF_SMOD TYPE I ,
          WF_BADI TYPE I ,
          WF_OBJECT2(30) TYPE C.
    CLEAR : WF_SMOD, WF_BADI , WF_OBJECT2.
* Get the total SMOD.
    LOOP AT JTAB INTO WA_TADIR.
      AT FIRST.
        FORMAT COLOR COL_HEADING INTENSIFIED ON.
        WRITE:/1 SY-VLINE,
              2 'Enhancement/ Business Add-in',
              41 SY-VLINE ,
              42 'Description',
              105 SY-VLINE.
        WRITE:/(105) SY-ULINE.
      ENDAT.

      CLEAR WF_TXT.

      AT NEW OBJECT.
        IF WA_TADIR-OBJECT = 'SMOD'.
          WF_OBJECT2 = 'Enhancement' .
        ELSEIF WA_TADIR-OBJECT = 'SXSD'.
          WF_OBJECT2 = ' Business Add-in'.
        ENDIF.
        FORMAT COLOR COL_GROUP INTENSIFIED ON.
        WRITE:/1 SY-VLINE,
              2 WF_OBJECT2,
              105 SY-VLINE.
      ENDAT.

      CASE WA_TADIR-OBJECT.
      WHEN 'SMOD'.
        WF_SMOD = WF_SMOD + 1.
        SELECT SINGLE MODTEXT INTO WF_TXT
              FROM MODSAPT
              WHERE SPRSL = SY-LANGU
                AND NAME = WA_TADIR-OBJ_NAME.
        FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
      WHEN 'SXSD'.
* For BADis
        WF_BADI = WF_BADI + 1 .
        SELECT SINGLE TEXT INTO WF_TXT
              FROM SXS_ATTRT
              WHERE SPRSL = SY-LANGU
                AND EXIT_NAME = WA_TADIR-OBJ_NAME.
        FORMAT COLOR COL_NORMAL INTENSIFIED ON.
      ENDCASE.
      WRITE:/1 SY-VLINE,
            2 WA_TADIR-OBJ_NAME HOTSPOT ON,
            41 SY-VLINE ,
            42 WF_TXT,
            105 SY-VLINE.

      AT END OF OBJECT.
        WRITE : /(105) SY-ULINE.
      ENDAT.
    ENDLOOP.
    WRITE:/(105) SY-ULINE.
    SKIP.
    FORMAT COLOR COL_TOTAL INTENSIFIED ON.
    WRITE:/ 'No.of Exits:' , WF_SMOD.
    WRITE:/ 'No.of BADis:' , WF_BADI.
  ELSE.
    FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
    WRITE:/(105) 'No userexits or BADis exist'.
  ENDIF.
ELSE.
  FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
  WRITE:/(105) 'Transaction does not exist'.
ENDIF.

AT LINE-SELECTION.
  DATA : WF_OBJECT TYPE TADIR-OBJECT.
  CLEAR WF_OBJECT.
  GET CURSOR FIELD FIELD1.
  CHECK FIELD1(8) EQ 'WA_TADIR'.
  READ TABLE JTAB WITH KEY OBJ_NAME = SY-LISEL+1(20).
  MOVE JTAB-OBJECT TO WF_OBJECT.
  CASE WF_OBJECT.
    WHEN 'SMOD'.
      SET PARAMETER ID 'MON' FIELD SY-LISEL+1(10).
      CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.
    WHEN 'SXSD'.
      SET PARAMETER ID 'EXN' FIELD SY-LISEL+1(20).
      CALL TRANSACTION 'SE18' AND SKIP FIRST SCREEN.
  ENDCASE.
  INPUT:


OUTPUT: 







4. Enhancement Frameworks: 
In Enhancements are restricted to only certain applications. All the requirements of enhancements for sap applications. All the requirement of enhancements for sap application can't be satisfied using badi. In Such case we have to work with Enhancement frame work.

In enhancement frame work sap is providing enhancement spots where you can create enhancements based on your requirements.

Even if requirements is not satisfied through enhancement spots we have to break the access key with the help  of basis consultant.

 This is the new kind of enhancement technique provided by SAP. These provides some hooks or places where custom logic can be coded in the standard program. There are 2 kinds of Enhancement frameworks:
a) Implicit and
b) Explicit Enhancements

 1. Explicit enhancement points:These are basically hooks already coded into the program by SAP at various points of the code. See program RIAUFMVK for examples of these! These are very easy to implement simply go into enhancement mode of SE80 and right click on the enhancement point where you want to add your code and choose ‘Enhancement Implementation->Create’ Give it a name, description and assign it to a change request (should not be a Z package) and then simply add the code as normal.
2. Implicit enhancement points: These are basically points within ABAP code where an enhancement point is implied, and in which case can be created. Examples of implicit enhancement points are at the beginning and end of FORM’s, at the end of a program, include or function module etc. 


1. What is the difference between BAPI, BADI and User Exit?
BAPI - These are published programs which is used to upload data into SAP system.
BADI - This is a program enhancement technique. SAP provides BADI openings in the standard programs. You need to search for the suitable BADI as Ur requirement and then do the coding and plug in the program.
USEREXIT - It is also a program enhancement technique. Here also u
need to find suitable user exit and code in Ur program.

The main diff
bet BADI and USEREXIT is that in USEREXIT u code in the standard SAP progra
m, hence any updation in the version of the standard program will lead to t
he loss of Ur coding. But same is not the case of BADI. Here the code remai
ns outside the standard program.

2. A data conversion needs to be done for Sales Order and the legacy data
is
 
available in a flat file. Which technique should we follow and why - BDC or
BAPI. - what the ???
 Lets see .. an order has a header and items and schedules
... and most probably text at the header and item .. as well as partner
functions etc .. etc ... how is "A" flat file going to accomodate that ??
If you have to answer this question, then the answer is use a BDC if you can
for a 1 time conversion. BAPI's are good for interfaces as they run faster.
But BAPI's are more difficult to figure out than writing a BDC. Also, BDC's
cant be used for transactions that use "enjoy controls", so if any part of
the screen flow uses "enjoy controls", the BDC will not work. So, you may
have no choice but to use a BAPI ... So, it’s dependent on what screen you
need to hit to "build" the order. If the text screen uses an "enjoy
control" (which I think it does (in 4.6), then the BDC wont work on this
screen. But since you're using ABAP to build the BDC screen, you can always
write the text directly to the tables.

3. A program is generating an outbound IDOC and ther is some error in the
data (say an outbound IDOC for Sales Order has been generated and the
Material Number has not been properly formatted so that it can be accepted
by the receiving system). How shall we handle this error from the program
who is generating the outbound IDOC?
 

- im not sure what this question is actually asking. Errors on inbound
IDOC's are usually handled by workflow. 

4. What is the difference between User Exit and Function Exit?
User Exit
Customer Exit
User exit is implemented in the form of a Subroutine i.e. PERFORM xxx.
Example: INCLUDE MVF5AFZZ 
à
PERFORM userexit_save_document_prepare.  
A customer exit can be implemented as:
·         Function exit
·         Screen Exit
·         Menu Exit
·         Field Exit
Example: CALL Customer function ‘xxx’
INCLUDE xxx.
You modify this include.
In case of a PERFORM, you have access to almost all the data. So you have better control, but more risk of making the system unstable.
You have access only to the importing, exporting, changing and tables parameter of the Function Module. So you have limited access to data.
User exit is considered a modification and not an enhancement.
A customer exit is considered an enhancement.
You need Access Key for User Exit.
You do not need access key.
Changes are lost in case of an upgrade.
Changes are upgrade compatible.
User exit is the earliest form of change option offered by SAP.
Customer exits came later and they overcome the shortcomings of User Exit.
No such thing is required here.
To activate a function exit, you need to create a project in SMOD and activate the project.
5. What is the difference between RFC and BAPI? 
BAPI
RFC
Just as Google offers Image/Chart/Map APIs OR Facebook offers APIs for Comment/Like, SAP offers APIs in the form of BAPIs. BAPI is a library of function modules released by SAP to the public so that they can interface with SAP.
RFC is nothing but a remote enabled function module. So if there is a Function Module in SAP system 1 on server X , it can be called from a SAP system 2 residing on server Y.
There is a Business Object Associated with a BAPI. So a BAPI has an Interface, Key Field, Attributes, Methods, and Events.
No Business Object is associated with a RFC.
Outside world (JAVA, VB, .Net or any Non SAP system) can connect to SAP using a BAPI.
Non–SAP world cannot connect to SAP using RFC.
Error or Success messages are returned in a RETURN table.

6.  What is the difference between  BDCandBAPI?
RFC does not have a return table.
BAPI
BDC
BAPI is faster than BDC.
BDC is relatively slower than BAPI.
BAPI directly updates database.
BDC goes through all the screens as a normal user would do and hence it is slower.
No such processing options are available in BAPI.
Background and Foreground processing options are available for BDC.
BAPI would generally used for small data uploads.
BDCs would be preferred for large volumes of data upload since background processing option is available.
For processing errors, the Return Parameters for BAPI should be used.This parameter returns exception messages or success messages to the calling program.
Errors can be processed in SM35 for session method and in the batch input program for Call Transaction method.

7.  What is the difference between SAP memory and ABAP memory?
SAP Memory
ABAP Memory
When you are using the SET/GET Parameter ID command, you are using the SAP Memory.
When you are using the EXPORT IMPORT Statements, you are using the ABAP Memory.
SAP Memory is User Specific.
What does this mean?
àThe data stored in SAP memory can be accesses via any session from a terminal. 
ABAP Memory is User and Transaction Specific.What does this mean?à The data stored in ABAP memory can be accessed only in one session. If you are creating another session, you cannot use ABAP memory.

8.  A system has two clients 100 and 500 on the same application server. If you make changes to a SAPSCRIPT on client 100, will the changes be available in client 500?
No. SAPSCRIPT is client dependent. You will have to transport changes from client 100 to client 500. However, for SMARTFORMS, Changes will be made both for client 100 and client 500.

9.  There are 1000’s of IDOCs in your system and say you no longer need some of them? How will you get rid of those IDOCs?
One way is to archive the IDOCs using transaction SARA.
But what the interviewer was expecting was ‘How do you change IDoc Status’?
There are different ways of doing this:
A) Use FM IDOC_STATUS_WRITE_TO_DATABASE
B) USE FMs:
     EDI_DOCUMENT_OPEN_FOR_PROCESS and
     EDI_DOCUMENT_CLOSE_PROCESS

10.  What is the difference between CHAIN … ENDCHAIN and FIELD commands in Module Pool?
If you want to validate a single field in Module Pool, you use the FIELD Command.
On error, this single filed is kept open for input.

If you however want to validate multiple fields, you can use the CHAIN … ENDCHAIN command. You specify multiple fields between CHAIN and ENDCHAIN.
On error, all fields between CHAIN …… ENDCHAIN are kept open for input.

11.  What are the types of Function Modules? What is an UPDATE function module?
There are three types of Function Modules: Normal, RFC, and UPDATE.

The aim of the Update function module is either to COMMIT all changes to database at once or to ROLLBACK all the changes. By definition, an update function module is used to bundle all the updates in your system in one LUW (logical unit of work).

This FM is called whenever COMMIT WORK statement is encountered in the calling program and the way you call it isCALL FUNCTION XXX IN UPDATE TASK.

Have a look at FM EDI_DOCUMENT_CLOSE_PROCESS_UPD and do a where used.
This FM is used as Update FM in case you make changes to IDoc contents/status via your program.

  11. How is the table sorted when you do not specify field name and Ascending or Descending? On what criteria will the table be sorted? Do internal table have keys?

Yes, internal table have keys.
The default key is made up of the non-numeric fields of the table line in the order in which they occur.

12. How do you find BAPI?
You can go to Transaction BAPI and then search for your desired object.
Say you want to find a BAPI for creating users in the system, in such case you can search for the ‘User’ and find the relevant BAPIs.

Approach2:
Another way is to find a Business Object. Say you want to find a BAPI for creating Material in SAP and you know the BO for Material is BUS1001006. You can go to Transaction SWO1 and enter the BO BUS1001006 in the BOR. Then have a look at the methods for this BO.

13.  How do you find BADI?
Approach1:
Go to Class CL_EXITHANDLER in SE24 ---> Put a breakpoint in method GET_INSTANCE.Now go and execute your transaction code for which you want to find BADI.
You will find the BADI in the changing parameter exit_name:


Approach 2:
Go to Tcode SE84 à Enhancements àBADIs à Definitions.
Find the package for the Tcode for which you are finding the BADI.
Enter it as shown and hit execute:


14. What are the different ways in which you can make changes to SAP standard software?
Customizing 
Enhancements to the SAP Standard
Modifications to the SAP Standard
Customer Development

15. What is customizing?
Customizing is the setting of system parameters via SAP's own interface.

16. Why do you need enhancements?
The standard applications do not offer some of the functionality you need. The R/3 enhancement concept allows you to add your own functionality to SAP's standard business applications.


17. What are the different types of enhancements?
Enhancements using customer exits

Customers' potential requirements which are not included in the standard software are incorporated in the standard

as empty modification 'shells'. Customers can then fill these with their own coding. Enhancements can relate to

programs, menus and screens. Upward compatibility is assured. In other words, SAP guarantees that the jump from the

standard software to the exit and the interface which call the exit will remain valid in future releases.

Enhancements to ABAP/4 Dictionary elements
these are ABAP/4 Dictionary enhancements (creation of table appends), text enhancements (customer-specific key
words and documentation for data elements) and field exits (creation of additional coding for data elements).

18. What is customer development?
Creating customer-specific objects within the customer name range.

19. What is SSCR?
SSCR (SAP Software Change Registration) is a procedure, for registering all manual changes to SAP source coding and SAP Dictionary objects.

20. What is the difference between modifications and enhancements?
Modifications mean making changes to the SAP standard functionality.
Enhancements mean adding some functionality to SAP standard functionality.

21. What are the disadvantages of modification?
Modifying standard code can lead to errors
Modifications mean more work during software upgrades

22. What are the advantages of enhancements?
Do not affect standard SAP source code
Do not affect software upgrades

23. When do you opt for modification?
Customer exits are not available for all programs and screens within the R/3 standard applications. You can only
use exits if they already exist within the SAP R/3 System. Otherwise you have to opt for modifications.

24. What are the various types of customer exits?
Menu exits
Screen exits
function module exits
Keyword exits

25. What is a menu exit?
Adding items to the pull-down menus in standard R/3 applications.

26. What is a screen exit?
Adding fields to the screens within R/3 applications. SAP creates screen exits by placing special sub screen areas

within a standard R/3 screen and calling a customer sub screen from within the standard dynpro's flow logic.

27. What is a function module exit?
Adding functionality to R/3 applications. Function module exits play a role in both menu and screen exits.

28. What is a keyword exit?
Add documentation to the data elements of key words defined in the ABAP/4 Dictionary. The system displays this documentation whenever a user presses F1 to get online help for a screen field.

29. How does SAP organize its exits?
SAP organizes its exits in packages that are called SAP enhancements. Each SAP enhancement can contain many individual exits.

30. What is an add-on project?
To take advantage of the exits available within standard R/3 applications, you need to create an add-on project.
This project lets you organize the enhancement packages and exits you want to use. The add-on project also allows
you to hang add-on functionality onto the exit hooks contained with SAP enhancements.

31. What are user-exits?
32. What is badi?
33. What is the difference between user-exit & BADIs?
34. What is the difference between user-exit & customer-exit?
35. How do you get functional specs when you are assigned some object? (Specs through email...?)
36. How do you write technical specs?
37. How do you write UTP? (Unit test plan)

38. What is the difference between Implicit Enhancements and Explicit Enhancements?
39. What is the difference between Enhancement point and Enhancement Section?
40. How do you find Function Exit?
41. How do you activate a Function Exit?

Example

The SAP enhancement RSAP0001 is used to fill the fields which are added to the extraction structure of the datasource, From Release 6.0, the Business Add-In (BAdi) RSU5_SAPI_BADI is available for datasource enhancements. So you will have several advantages while using BAdi instead of User exits.
Note: In User exit, only one enhancement will be used for all the datasources, using BAdi, we can use multiple enhancements. Each enhancement will be implemented in a separate method of the class.
Data source 0FI_AR_4 is appended with fields ZZSPART– Division, ZZVKORG- Sales organization, ZZVTWEG-Distribution channel. The data for these fields should be filled from VBRK table.

Go to T code SE19.  Choose Classic BAdi, Give the BAdi name as RSU5_SAPI_BADI (standard). Click on Create Implementation.

Give the Implementation name and Click on Ok.  An Implementation ZC_RSU5_SAPI_BADI will be created with the definition of standard BAdi RSU5_SAPI_BADI. 
Maintain the Description for the implementation and activate it.

Implementation of the BAdi is created.
When you create the Implementation, a class will be created with the naming convention ZCL_IM_(implementation name with out Z) in our case, ZCL_IM_C_RSU5_SAPI_BADI.

To display the class and its methods, go to Interface tab and double click on the class name. To display the documentation for the BAdi click on Def. documentation tab.
You will enter into the screen of Class builder 



In the class builder, methods tab – we will see 2 standard methods.

This method allows you to fill your added fields that you have attached as an append structure to the extract structure of transaction and master data in the SAP BW. 

To see the parameters passed to this method, select the DATA_TRANSFORM method and click on parameters tab.


Note: Since our current requirement is to fill the data for enhanced transaction datasource, so we will concentrate more on DATA_TRANSFORM method only. To know more about HIER_TRANSFORM method and it’s parameters you can refer the SAP note 691154.
To go back to the methods screen just  click on the methods tab. 

After coming back to methods, double click on the method DATA_TRANSFORM or select the method and click on the source code button, you will go to the source code editor for this method.


How to Implement BAdI for Enhancing the Datasource in ECC
Just copy and paste the below code. This is a common code for any project. You need to change only the class name while reading the SEOCOMPO table.  Give the class name you created.  Rests of all steps are same as they are. 

Note: We wrote this code to use it for any kind of datasource enhancements including CRM or APO. Every line of code, comments are provided to understand the code better.
METHOD IF_EX_RSU5_SAPI_BADI~DATA_TRANSFORM.


*Declare the variable which holds method (datasource enhancement)   DATA : L_METHOD TYPE SEOCMPNAME.


*Add some letter to prefix, because method can't be started with number   CONCATENATE 'M_' I_DATASOURCE INTO L_METHOD.


*checks the internal table, if it has no data then it exits the method.  CHECK C_T_DATA[] IS NOT INITIAL.

*Read the component(method) from SEOCOMPO table: this table will get an entry wh en  
*        a customized method is created in the class. this customized method will conta in the source code logic to fill the enhanced field of the datasource   
  SELECT SINGLE CMPNAME FROM SEOCOMPO INTO L_METHOD WHERE         CLSNAME = 'ZCL_IM_C_RSU5_SAPI_BADI' AND         CMPNAME = L_METHOD.

*        Check the sy-subrc, if it is not equal to 0, then exits the method   CHECK SY-SUBRC EQ 0.


*        if method is found in the SEOCOMPO table, that particular method will be call ed
so automatically enhancement logic written in that method will get executed and 
Modified to C_T_DATA
  
  CALL METHOD (L_METHOD)
    EXPORTING
      I_UPDMODE    = I_UPDMODE       I_T_SELECT   = I_T_SELECT
      I_T_FIELDS   = I_T_FIELDS
    CHANGING
      C_T_DATA     = C_T_DATA       C_T_MESSAGES = C_T_MESSAGES.

ENDMETHOD.

Activate this method and come back to the class builder screen.
In our case the datasource is 0FI_AR_4.


A new customized method M_0FI_AR_4 is entered in the method’s column. Declare this method with level as ‘Static’ and visibility as ‘Provate’.
As already discussed, method can’t be started with a number,   so it was prefixed with M_.  The method name we give here should have the same name which is called in DATA_TRANSFORM method.
Note: while declaring this method, we have the two options to choose level, either Static or Instance.
If I choose Static - then we can call that method using class name, that method is independent of that object.
If it is instance - then we can call that method using object name, that method is dependent of that object.

Similarly the visibility, we have 3 options to choose, Public, private and protected. If it is Public – then visible to all classes. If it protected – then visible to only with in the class and with in the sub class. If you choose Private – only with in the class, not even from subclass also.

Write your logic to fill the appended fields in the datasource.
Before writing the logic, in the method screen click on private section to declare the parameters like C_T_DATA, I_T_SELECT and I_T_FIELDS.
 Copy and paste the below code in the private section of the method. Just replace your method name.
private section.
   type-pools SBIWA.
 class-methods M_0FI_AR_4   importing
      value(I_UPDMODE) type SBIWA_S_INTERFACE-UPDMODE       value(I_T_SELECT) type SBIWA_T_SELECT       value(I_T_FIELDS) type SBIWA_T_FIELDS     changing
      !C_T_DATA type ANY TABLE
      !C_T_MESSAGES type RSU5_T_MESSAGES optional

After writing this code in private section, activate this section and click on back button. You will come back to the source code screen of method.
Here you write your logic to fill the field just like as you write in CMOD enhancements.

Below is the code for my requirement. Comments are provided to understand better. You can write your own logic in the space.
METHOD M_0FI_AR_4.

*       declaring a field symbol with type of extract structure of 0FI_AR_4   FIELD-SYMBOLS: TYPE DTFIAR_3.

*       declare a structure with field required from VBRK table
  TYPES: BEGIN OF IT_VBRK,
             V_VBELN TYPE VBELN_VF,
             V_VKORG TYPE VKORG,
             V_VTWEG TYPE VTWEG,
             V_SPART TYPE SPART,          END OF IT_VBRK.

*       Declare an internal table and work area with above type
  DATA: ZBW_VBRK TYPE STANDARD TABLE OF IT_VBRK,
        L_T_DATA TYPE STANDARD TABLE OF DTFIAR_3,  " internal table same as C_T_ DATA
         WA_VBRK TYPE IT_VBRK.

*       move the entire content into another internal table   L_T_DATA[] = C_T_DATA[].

  IF NOT L_T_DATA IS INITIAL.

*       read the  fields from VBRK table for all entries of L_T_DATA and put them in to IT_VBRK
    SELECT VBELN VKORG VTWEG SPART
       FROM VBRK INTO TABLE ZBW_VBRK
       FOR ALL ENTRIES IN L_T_DATA      WHERE VBELN = L_T_DATA-BELNR.     
      SORT ZBW_VBRK BY V_VBELN.
      CLEAR WA_VBRK.

    LOOP AT L_T_DATA ASSIGNING .

    READ TABLE ZBW_VBRK INTO WA_VBRK WITH KEY V_VBELN = BELNR BINARY SEARCH.

    IF SY-SUBRC = 0.

*update the Sales organization, distribution channel and division  field after reading the Billing document  number from IT_VBRK table
      -ZZVKORG = WA_VBRK-V_VKORG.
        -ZZVTWEG = WA_VBRK-V_VTWEG.         -ZZSPART = WA_VBRK-V_SPART .
      ENDIF.

    ENDLOOP.   ENDIF.
  C_T_DATA[] = L_T_DATA[].

REFRESH: L_T_DATA,          ZBW_VBRK.

ENDMETHOD.

Save and Activate the method.
So when you extract data in RSA3, datasource parameter is passed to the Class and then respective method will be called from the DATA_TRANSFORM method. That particular method will execute the code and data will be populated for the enhanced fields i.e. ZZSPART– Division, ZZVKORG- Sales organization, ZZVTWEG-Distribution channel in the 0FI_AR_4.

Note: To create another enhancement for the datasource 2lis_11_vahdr, give the method name in the class builder and follow the same steps as above.

Like this we can write all our enhancements in separate methods in the same class. By this we improve performance and flexibility to work on respective enhancements without disturbing other enhancements.



Business Add-Ins (BADIs): An Overview
Business Add-Ins may be simply defined as an object-oriented extension of the SAP enhancement technique.
The method name is specified via a BADI interface. The name of the interface is of the form IF_EX_BADI, where BADI is the name of the Business Add-In in question. For example, in the case of the HR Add-In HR_INDVAL, the involved interface is IF_EX_HR_INDVAL. 
There are two main attributes of Business Add-Ins, namely Multiple-Use and/or Filter Dependent. If you want to allow more than one implementation for a given BADI, the attribute of the corresponding BADI is set as Multiple-use. Likewise, Business Add-ins may also be defined as filter-dependent. This allows you to define subtypes for a given Business Add-In. In this case, a different method code is created and executed for each filter specified in the BADI definition.

BADIs provide a number of advantages to developers and consultants:

They let you quickly and easily adapt SAP according to your users’ requirements, without the need for modifying standard code.
Since the enhancement is not fixed for all scenarios, BADIs allow you to implement a different application logic for a variety of country versions and company requirements. 

For developers having an affinity for object-oriented concepts, this functionality provides a means of effective SAP program enhancement. 

Transaction SE18
You may use the transaction SE18 to display a list of existing BADIs as well as to view the attributes and structure of a given BADI. In order to search for an appropriate BADI in your functional area, call transaction SE18.

BADI Initial Definition Screen
You also may create new (or display existing) BADI definitions via this transaction.

Displaying Definition of BADI HRPAYCA_RP_ROE

The Attributes tab shows the General Data and the Type of the BADI in question.

BADI Interface and Method Name

Double-click on the Method name in order to view the details about the importing, exporting, and changing parameters of the BADI method in question.

Parameters of a Given BADI Method 

In case of Filter-Dependent BADIs, one important parameter that is passed on to the method is the filter value. The name of this parameter, in most cases, is FLT_VAL. 

Structure of Programs that Employ the BADI Functionality
It is a good idea for you to familiarize yourself with the structure of programs that employ Business Add-Ins. The programs (whether standard or custom-built) that incorporate the BADI functionality include a somewhat common block of code.

The block of code first declares the class CL_EXITHANDLER, and then declares a reference variable (in this case, MYEXIT) to the interface of the BADI in question. Then, the program calls the static method GET_INSTANCE  of the CL_EXITHANDLER class. This method is used to access an active instance of the Business Add-In class, which is placed in the declared variable MYEXIT.


Steps Required in Implementing a BADI
Step 1:  Creating an Implementation

The first step involves creating a BADI implementation. Call transaction SE19.

Enter a suitable name for your implementation in the field provided, and click the Create button. 

A pop-up screen appears, as shown in Figure 7. Enter the name of the BADI involved and press the Enter button. 

Enter an appropriate short text in the field provided. Then, click on the Interface tab. This shows the name of the class that will be generated as a result of the implementation. You may change the class if you like. The Interface tab also contains the name of the BADI method.

Note:  In case you are implementing a Filter-Dependent BADI, you need to enter a suitable filter value in the table control provided in the Type portion of the Attributes tab. The Filter Value(s) field (in this case) is available for input

Then, double-click on the name of the method (in our case SAP_SCRIPT_TABLES). This takes you to the Class Builder’s method editor screen.



Step 2:  Writing the Code for the BADI Method

The next step is to write the appropriate coding for the BADI method.
. For example, the following form for internal table declaration will give an error:
 
 DATA: BEGIN OF ITAB2 OCCURS 0,
        MYFIELD1,
        MYFIELD2,
       END OF ITAB2.
Activate your BADI implementation. 
The Business Add-In applicable in this case is HR_INDVAL, and the interface involved is IF_EX_HR_INDVAL. As already mentioned, the first step is to create the implementation. An implementation by the name Z_FIRST_IMP1 was created.

Creating an Implementation for Business Add-In HR_INDVAL

I have assumed that the indirect valuation module Z123 has already been created. Next, the method on the Interface tab is accessed. In this case, the name of the method is DO_INDIRECT_VALUATION.

The important parameters in this case are the VALUATION_INPUT and VALUATION_OUTPUT variables. The appropriate code is written for the method DO_INDIRECT_VALUATION. When the user creates entries for allowances that have been assigned the given module, the formula specified in BADI method DO_INDIRECT_VALUATION is executed, and the resulting allowance value is displayed on the screen. 


One of the advantages of SAP software is the possibility to adapt the software to own requirements and the possibility of keeping the adaptations during upgrade.
Ways of adaptation:
Customizing
Enhancement

Modification
The roadmap of enhancement techniques

Enhancement Framework is the new paradigm to bring all enhancement techniques under one roof.  It can also be switched using Switch Framework.  The following are different enhancement technologies available under this framework.
Source Code Enhancement
Function Group Enhancement
Class Enhancement 
Kernel-BADI Enhancement

Semantically related enhancement options are grouped under a ‘Simple Enhancement Spot’.  ‘Composite Enhancement Spot’ contains one or more of Simple and other Composite Enhancement Spots.  On the other hand (implementation side), various related implementation elements are grouped under a ‘Simple Enhancement Implementation’.  A ‘Composite Enhancement Implementation’ can contain one or more of Simple and other Complex Enhancement Implementations. The important point to note here is these four entities form the basis of transportable objects in the Enhancement Framework.


Enhancements – Relations


Whenever enhancement needs to be incorporated directly into the ABAP source code, this technology shall be provided.  Implementing this technology is also called as Source Code Plug-In.  There are two types of Source Code enhancements possible.

Note that, in order to implement any of these Source code enhancements, you need to be in the ‘Change
Enhancement mode’ (the spiral icon  available in the editor).  Technically the source code plug-in implementations are stored in a separate include program and not as part of the original source program. 

Implicit enhancement option
Throughout the ABAP system, enhancement options are automatically available at certain pre-defined places.  Some of the implicit options are:
At the end of all the programs (Includes, Reports, Function pool, Module pool, etc.), after the last statement
At the beginning and end of all FORM subroutines
At the end of all Function Modules
At the end of all visibility areas (public, protected and private) of local class
To view all the implicit options available in a source code, choose ‘Edit -> Enhancement Operations -> Show Implicit Enhancement Options’ from the editor. 
You don’t need to have an explicitly defined enhancement spot in order to implement these enhancements.  Just position the cursor on any of these implicit points and choose ‘Create Enhancement’ from the menu to implement it. 

Implicit Enhancement Option
At common enhancement places, implicit Enhancement options are available.
Example:
End of Executable Program, Include, Function group, Dialog module 

Begin/End of Form routine / Function module / Method
End of a structure
End of Private/Protected/Public Section of a local class.

Explicit enhancement option
The Implicit enhancement options are provided at specific source code places explicitly by SAP (Note that these enhancement definitions can also be created by partners and customers in their code).
There are two types of Explicit Enhancement options available.  One which can be provided at a specific place - called Enhancement Point, and another which can be used to replace a set of statements – called Enhancement Section.  For this, we now have two new ABAP statements, viz.
ENHANCEMENT-POINT
ENHANCEMENT-SECTION 

         When the Enhancement-Section is implemented, only the implementation gets executed and the original code doesn’t get executed.  This is a new technique, which didn’t exist previously in any of the old ways of enhancing, to exclude any standard SAP code from execution.  Because of this, there can be only one active implementation of an Enhancement-Section. On the other hand, there can be multiple active implementations of an Enhancement-Point, in which case all the implementations will be executed with no guarantee in the order of execution. 



Explicit Enhancement Option
Predefined enhancement options can be defined in source code.
They are additionally stored inside Enhancement Spots. 

Implicit Enhancement Options




Explicit Enhancement Options

All application function modules can be enhanced by adding parameters to the standard function module interface.  These parameters must be ‘optional’ in nature, since adding a mandatory parameter will require all calls to be changed.  Additionally any function module that is part of the Central Basis can not be enhanced (for example: function module ‘POPUP_TO_CONFIRM’).  From the menu, choose ‘Function module -> Enhance interface’ to add optional parameters to a function module. 


Think about all the steps that customers currently go through for adding new parameters to a BAPI.  Cloning of BAPI is an option but maintaining and syncing up during upgrade could be a nightmare.  Now with a combination of Function Group enhancement and Source code plug-in, BAPI’s can easily be enhanced to add new parameters and add custom logic to process those parameters. 

Function Group Enhancements allow:
Adding new optional parameters to existing function modules



The global Classes and Interfaces can be enhanced as follows:
Adding optional parameters to existing Methods
Adding new Methods to the global Class / Interface
Adding Pre-exit, Post-exit or Overwrite-exit to an existing Method
The Pre and Post exits get executed before and after invoking the respective method.  These are achieved by an automatically generated local class.  All methods are stored as part of this local class. (Point to ponder: Are private and protected attributes accessible from the Pre and Post exits?).
Choose menu option ‘Class -> Enhance’ to add new methods or parameters.  Choose menu option ‘Edit -> Enhancement operations’ to add or delete the Pre/Post/Overwrite exit methods. 

Class/Interface Enhancements allow addition of:
Optional parameters to existing methods methods events and event handlers references to interfaces

Exits to existing methods
Pre-Exit – Called at the beginning of a method Post-Exit – Called at the End of a method
Overwrite-Exit – Replaces the original method.

Adding new methods

Adding optional parameters to existing methods



SE18 -> utilities -> Migrate





The old classic-BADI’s are implemented purely at the ABAP Workbench level; that is, both the definition and implementation are realized as workbench repository objects (global classes and interfaces).  The new Kernel-BADI takes it to the ABAP language level.  Because of this, the new Kernel-BADI’s are much faster compared to the old classic-BADI’s.
There are two new ABAP statements available now to support the Kernel-BADI’s, namely GET BADI and CALL BADI.
Example:  data bd_hdl type ref to badi_name. GET BADI bd_hdl filters filt_1 = ‘VALUE’. CALL BADI bd_hdl->method       exporting param_1 = 10.
The old classic-BADI used to mix both implementation selection and method call in the same CALL METHOD statement.  The implementations could only be chosen at run-time because of the above reason and due to the fact that the BADI handle could only be gotten from another method call by passing the BADI name.  
Whereas in the new Kernel-BADI, the active BADI implementations are included into the load of BADI handle at compile time and the filter criterion are expanded as IF statements.  This is the reason the new KernelBADI’s are much faster than classic-BADI’s.
Some of the other new features of Kernel-BADI’s are,
Improved Filters with complex filter condition editor
Stateful BADI support and Context based lifetime control
Possibility to inherit the implementations
Switchable using Switch Framework


Since Kernel-BADI is yet another enhancement technology under Enhancement Framework, we need to create Enhancement Spot in order to hold the BADI definitions.  Similarly, the BADI implementations must also be assigned to Enhancement Implementations.  The BADI definition and implementation editors are integrated into SE80.


By now you would have understood and appreciated the benefits this new technology brings to the table.  Here is the summary.
All enhancement technologies are now under a single roof of Enhancement Framework, and integrated into the ABAP workbench.  Result: Enhancement is easily manageable.
The Enhancement Framework can be switched using Switch Framework through package assignment.
With new enhancement technologies (like Source Code, Function & Class enhancements), the options to enhance standard SAP code have increased tremendously.  This cuts down on the need to do Core-mod, which requires more effort than enhancement
Kernel-BADI’s are much faster compared to the old classic-BADI’s
Implementing classes of Kernel-BADI’s are re-usable through inheritance
The lifecycle of BADI implementation instances are better managed through advanced options
(Stateful BADI’s through Context based and reusable instantiation)
During the upgrade, SPAU_ENH transaction lets you create enhancement implementations to hold the BADI implementations, which guarantees the Return On Investment (ROI) for the old classicBADI implementations.


























No comments:

Post a Comment