SAP Blog

Wednesday, February 13, 2008

How to create ABAP reports with IS-U like logs.

Today I want to share you with a powerfull tool which is the IS-U like log system.
You can display an IS-U like log using transaction SLG1 or SLG_ISU.

How can you create ABAP reports with IS-U like logs?

This is a picture of how a IS-U like log looks like:



You need/can define your own log object in the system in the view BALOBJ. Using SM30 you can define your own log object. Let's define a ZTEST log in this view.






After that you can use the log object in your ABAP reports.
You can copy and paste the above text into SE38 ABAP Editor.

*You need to include the EMSG include program in your report.

INCLUDE EMSG.

*This include contains a lots of macros used to write log messages.
*Second you need the type pool EEMSG.

TYPE-POOLS: eemsg.

*Define a log parameter structure :

DATA: xy_parm TYPE eemsg_parm_open.

*And the log handle:
DATA: handle LIKE emsg_gen-handle.

*Define a parameter to hold the internal log number like this:

PARAMETERS extnr LIKE balhdr-extnumber NO-DISPLAY.

*Open the log using the above code.

CLEAR xy_parm.
xy_parm-extnumber = extnr.
xy_parm-appl_log = 'ZTEST'.

CALL FUNCTION 'MSG_OPEN'
EXPORTING
x_no_dialog = ' '
x_log = 'X'
x_next_msg = ' '
x_obj_twice = ' '
IMPORTING
y_msg_handle = handle
CHANGING
xy_parm = xy_parm.


*Now you can write to the log using the macro mac_msg_putx.

mac_msg_putx co_msg_information '398' '00'
'INFO' '123' space space space.

mac_msg_putx co_msg_error '398' '00' 'Error' '123' space space space.


*When the program is finished you should:

*Save the log like
CALL FUNCTION 'MSG_ACTION'
EXPORTING
x_msg_handle = handle
x_action = co_msg_save
EXCEPTIONS
OTHERS = 1.

IF sy-subrc <> 0.
mac_msg_repeat co_msg_error internal_error.
ENDIF.

*Display the log is not in background like this:
IF sy-batch IS INITIAL.
CALL FUNCTION 'MSG_ACTION'
EXPORTING
x_msg_handle = handle
x_action = co_msg_dspl
EXCEPTIONS
OTHERS = 1.
ENDIF.

*Close the log.

CALL FUNCTION 'MSG_CLOSE'
EXPORTING
x_msg_handle = handle.



*Now we're done. You should have a log which looks like the first picture.

4 comments:

abaper said...

Very nice tutorial. Not too short, not too long. Just what I need. Thanks!

Sij said...

Hey am using this macros for displaying log.
Can you tell how to pass messages with parameters into this.

oracle procurement said...

Thanks for posting this blog i in reality loved it and put up some particular blogs approximately sap........visit our internet site associated with sap fusion all modules education
Oracle Fusion procurement Coaching Center

ORACLE FUSION PROCUREMENT said...

Hi,
This is very informative post.Thanks for sharing such a wonderful post.
oracle fusion SCM online training