Aug 23, 2011

The Events in Table Maintenance Generator SM30


The Events in Table Maintenance Generator SM30

There are 39 events for Table Maintenance Generator, follow this:
SE54 ->  Enter Table Name (Which table you want) -> Environment -> Events -> Enter -> New Entries -> Under ' T ' -> Press F4.
Then you will get this event:
01
Before saving the data in the database
02
After saving the data in the database
03
Before deleting the data displayed
04
After deleting the data displayed
05
Creating a new entry
06
After completely performing the function 'Get orig
07
Before correcting the contents of a selected field
08
After correcting the contents of a selected field
09
After getting the original of an entry
10
After creating the header entries for the change t
11
After changing a key entry for the change task (E0
12
After changing the key entries for the change task
13
Exit editing (exit main function module)
14
After lock/unlock in the main function module
15
Before retrieving deleted entries
16
After retrieving deleted entries
17
Do not use. Before print: Event 26
18
After checking whether the data has changed
19
After initializing global variables, field symbols
20
after input in date subscreen (time-dep. tab./view
21
Fill hidden fields
22
Go to long text maintenance for other languages
23
Before calling address maintenance screen
24
After restricting an entry (time-dep. tab./views)
25
Individual authorization checks
26
Before creating a list
27
After creation or copying a GUID (not a key field)
28
After entering a date restriction for time-dep. vi
AA
Instead of the standard data read routine
AB
Instead of the standard database change routine
AC
Instead of the standard 'Get original' routine
AD
Instead of the standard RO field read routine
AE
Instead of standard positioning coding
AF
Instead of reading texts in other languages
AG
Instead of 'Get original' for texts in other langu
AH
Instead of DB change for texts in other languages
ST
GUI menu main program name
AI
Internal use only


Aug 22, 2011

How to find BADI in ABAP


How to find BADI in ABAP

You can find BADI's in different ways...

1>First go to any transaction->iN THE menu bar SYSTEM->STATUS->Get the program name ->double click->u will go to the program attached to the tcode. Now search term will be CALL CL_EXITHANDLER. Now u will get list of BADI'S available..

2>Goto SE24->Give class name as CL_EXITHANDLER->Display->double click on GET_INSTANCE method->Now u will go inside the method->Now put break point on the CL_EXITHANDLER. Now go to any transaction code and pass dat..U will see that it will be stopped on the break point which u set on the CL_EXITHANDLER...In the exit name u can find list of badi's attached to the tcode..

There are multiple ways of searching for BADI.

• Finding BADI Using CL_EXITHANDLER=>GET_INSTANCE
• Finding BADI Using SQL Trace (TCODE-ST05).
• Finding BADI Using Repository Information System (TCODE- SE84).

1. Go to the Transaction, for which we want to find the BADI, take the example of Transaction VD02. Click on System->Status. Double click on the program name. Once inside the program search for ‘CL_EXITHANDLER=>GET_INSTANCE’.
Make sure the radio button “In main program” is checked. A list of all the programs with call to the BADI’s will be listed.
The export parameter ‘EXIT_NAME’ for the method GET_INSTANCE of class CL_EXITHANDLER will have the user exit assigned to it. The changing parameter ‘INSTANCE’ will have the interface assigned to it. Double click on the method to enter the source code.Definition of Instance would give you the Interface name.

2. Start transaction ST05 (Performance Analysis).
Set flag field "Buffer trace"
Remark: We need to trace also the buffer calls, because BADI database tables are buffered. (Especially view V_EXT_IMP and V_EXT_ACT)
Push the button "Activate Trace". Start transaction VA02 in a new GUI session. Go back to the Performance trace session.
Push the button "Deactivate Trace".
Push the button "Display Trace".
The popup screen "Set Restrictions for Displaying Trace" appears.
Now, filter the trace on Objects:
• V_EXT_IMP
• V_EXT_ACT

Push button "Multiple selections" button behind field Objects
Fill: V_EXT_IMP and V_EXT_ACT

All the interface class names of view V_EXT_IMP start with IF_EX_. This is the standard SAP prefix for BADI class interfaces. The BADI name is after the IF_EX_.
So the BADI name of IF_EX_CUSTOMER_ADD_DATA is CUSTOMER_ADD_DATA

3. Go to “Maintain Transaction” (TCODE- SE93).
Enter the Transaction VD02 for which you want to find BADI.
Click on the Display push buttons.
Get the Package Name. (Package VS in this case)

Go to TCode: SE84->Enhancements->Business Add-inns->Definition
Enter the Package Name and Execute.

Here you get a list of all the Enhancement BADI’s for the given package MB.
The simplese way for finding BADI is
1. Choose Tcode Program & package for that Tcode.
2. Go to Tcode se18
3. Press F4
4. Search by package or by program.

Ref: http://abapreports.blogspot.com/2008/06/badi-finding-in-abap.html


Generate Application Log


Generate Application Log
By Naimesh Patel

Application log is used to generate a log which can be accessed later by the users. Sometimes there would be a situation where we need to generate the log, especially for the Errorenous situation.

Application Log is the rich type log. It contains the information like User, Time, Expiry date of the log. It has also traffic icons for the messages based on the message type.

Log is also getting generated when we run the report in the Background. This is called as the Job Log. But it doesn't have the same formatting as the Application Log. It will also not get generated when you run the report online. So, if we have to generate the Log in the both scenario than we have to use the Application Log.

Important Tcodes:
SLG0 - Create a new Log Object and subobject
SLG1 - Display Application Log
SLG2 - Delete the Application Log

To start generating the custom Application Log than we need to create a new Log object and Subobject. Use the Tcode SLG0 and create a new custom Application Log object.
So, let's see the code snippet to generate the Application Log.
REPORT  zapplog.

*&---------------------------------------------------------------------*
*& This code snippet will show how to generate the Application log
*&   by using some function modules
*&
*&---------------------------------------------------------------------*
*
DATA: lf_obj        TYPE balobj_d,
      lf_subobj     
TYPE balsubobj,
      ls_header     
TYPE balhdri,
      lf_log_handle 
TYPE balloghndl,
      lf_log_number 
TYPE balognr,
      lt_msg        
TYPE balmi_tab,
      ls_msg        
TYPE balmi,
      lt_lognum     
TYPE TABLE OF balnri,
      ls_lognum     
TYPE balnri.
*
* Application Log object & Subobject
lf_obj     = 
'ZTEST_NP'.
lf_subobj  = 
'ZTEST_1'.
*
* Header information for the log
ls_header-object     = lf_obj.
ls_header-subobject  = lf_subobj.
ls_header-aldate     = sy-datum.
ls_header-altime     = sy-uzeit.
ls_header-aluser     = sy-uname.
ls_header-aldate_del = sy-datum + 
1.
*
* Get the Log handle using the header
CALL FUNCTION 'APPL_LOG_WRITE_HEADER'
  
EXPORTING
    
header              = ls_header
  
IMPORTING
    e_log_handle        = lf_log_handle
  
EXCEPTIONS
    object_not_found    = 
1
    subobject_not_found = 
2
    error               = 
3
    
OTHERS              = 4.
IF sy-subrc <> 0.
  
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*
* Get the next avaliable Log number
CALL FUNCTION 'BAL_DB_LOGNUMBER_GET'
  
EXPORTING
    i_client                 = sy-mandt
    i_log_handle             = lf_log_handle
  
IMPORTING
    e_lognumber              = lf_log_number
  
EXCEPTIONS
    log_not_found            = 
1
    lognumber_already_exists = 
2
    numbering_error          = 
3
    
OTHERS                   = 4.
*
* Fill the Application Log messages.
*   Here we can append our own messages as per our application
*   behaviour
*
* Information message will generate the Green Light
ls_msg-msgty = 
'I'.
ls_msg-msgid = 
'00'.
ls_msg-msgno = 
'398'.
ls_msg-msgv1 = 
'Testing 1234'.
APPEND ls_msg TO lt_msg.
*
* Warning message will generate the Yellow light
ls_msg-msgty = 
'W'.
ls_msg-msgid = 
'00'.
ls_msg-msgno = 
'398'.
ls_msg-msgv1 = 
'Warning Testing 1234'.
APPEND ls_msg TO lt_msg.
*
* Error message will generate the Red Light
ls_msg-msgty = 
'E'.
ls_msg-msgid = 
'00'.
ls_msg-msgno = 
'398'.
ls_msg-msgv1 = 
'Error Testing 1234'.
APPEND ls_msg TO lt_msg.
*
* Write the Log mesages to the memory
CALL FUNCTION 'APPL_LOG_WRITE_MESSAGES'
  
EXPORTING
    object              = lf_obj
    subobject           = lf_subobj
    log_handle          = lf_log_handle
  
TABLES
    messages            = lt_msg
  
EXCEPTIONS
    object_not_found    = 
1
    subobject_not_found = 
2
    
OTHERS              = 3.
IF sy-subrc <> 0.
  
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*
* write the log message to Database which can be later analyzed
*   from transaction SLG1
MOVE-CORRESPONDING ls_header TO ls_lognum.
ls_lognum-lognumber = lf_log_number.
APPEND ls_lognum TO lt_lognum.
*
CALL FUNCTION 'APPL_LOG_WRITE_DB'
  
EXPORTING
    object                = lf_obj
    subobject             = lf_subobj
    log_handle            = lf_log_handle
  
TABLES
    object_with_lognumber = lt_lognum
  
EXCEPTIONS
    object_not_found      = 
1
    subobject_not_found   = 
2
    internal_error        = 
3
    
OTHERS                = 4.
IF sy-subrc <> 0.
  
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*
* display the generate log from the memory.
CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'.


The generated application Log will look like this:




TIP

When we generate the some type of application log in the background job, we would like to set the appropriate job status based on the messages in the log table. For example, if the Application log has any error we want to set the status of the job as the "Cancelled". To achieve this, we have to add this type of code after we append our log to database using the FM APPL_LOG_WRITE_DB:
*&---------------------------------------------------------------------*
*& This code snippet will show how to set the status of the background
*&   job if the application log has been generated in the background.
*&---------------------------------------------------------------------*
READ TABLE lt_msg INTO la_msg WITH KEY msgty = 'E'.
IF sy-subrc = 0.
  
MESSAGE e398(00) WITH 'Some error occured. Application Log'
                        
'has generated. Check in tcode SLG1'.
ENDIF.

You can find more about the Application Log in SAP Library at: Application Log

One of the reader has asked this question: When to use Application Log?
1. When we want to save the List/Log for the long time: Generally, we have the spool retention preiod of 8 days. So, the list or log will be deleted automatically.
2. When we want more information compared to Log generated with WRITE: Application Log has more information like User, date of creation, Severarity of the message.
3. In ALE / EDI Processing: When we do the cross client processing (IDoc Processing), we can generate the Application log to keep track of the generated errors or the messages.