воскресенье, 14 июля 2013 г.

Application Logging

SAP provides a method to use a standard logging facility for all of your custom ABAP programs. It consists of several transaction codes, tables, and function modules. By using the SAP functionality, it is possible to have a standard way to store error messages, making the handling of errors much simpler, and increasing the maintainablity of code.
Transaction Codes: SLG0 is used to configure categories for the error messages, and SLG1 is used to view the messages.
Tables: BALHDR is the main (header table), and BALM contains all of the detailed messages.
Function Modules: Much like the SAP function modules used to send email, these function modules would benefit from having a simpler interface wrapped around them. The function modules can be found in Function Group SLG0. Look for the INIT, HEADER, and MESSAGE function modules, as well as the WRITE_DB (I think that is the name...). If you want examples of how these function modules are used, please do a where used on them. I am unable to post the SAP examples here.
All APPL_LOG function modules are from 3.0. Starting at 4.6, see function groups that start with SBAL.



3.0 to 4.5 Function Modules


Create application log


Function group SLG0

You write the application log records with these function modules.
APPL_LOG_WRITE_HEADER With this function module, you write the log header data in local memory.

APPL_LOG_WRITE_LOG_PARAMETERS With this function module, you write the name of the log parameters and the associated values for the specified object or sub-object in local memory. If this function module is called repeatedly for the same object or sub-object, the existing parameters are updated accordingly. If you do not specify an object or sub-object with the call, the most recently used is assumed.

APPL_LOG_WRITE_MESSAGES With this function module you write one or more messages, without parameters, in local memory.

APPL_LOG_WRITE_SINGLE_MESSAGE With this function module you write a single message, without parameters, in local memory. If no header entry has yet been written for the object or sub-object, it is created. If you do not specify an object or sub-object with the call, the most recently used is assumed.

APPL_LOG_WRITE_MESSAGE_PARAMS With this function module you write a single message, with parameters, in local memory. Otherwise the function module works like APPL_LOG_WRITE_SINGLE_MESSAGE.

APPL_LOG_SET_OBJECT With this function module, you create a new object or sub-object for writing in local memory. With a flag you can control whether the APPL_LOG_WRITE_... messages are written in local memory or are output on the screen.

APPL_LOG_INIT This function module checks whether the specified object or sub-object exists and deletes all existing associated data in local memory.

APPL_LOG_WRITE_DB With this function module you write all data for the specified object or sub-object in local memory to the database. If the log for the object or sub-object in question is new, the log number is returned to the calling program.


Display application log


Function group SLG3

With these function modules you display logs for analysis.
APPL_LOG_DISPLAY With this function module you can analyze logs in the database.

APPL_LOG_DISPLAY_INTERN With this function module you can analyze logs in local memory, e.g. when you have only collected log records at runtime and do not want to write to the database.


Read application log


Function group SLG1

If you want to analyze the log yourself, you can read the logs with these function modules.
APPL_LOG_READ_DB With this function module you read the log data in the database for an object or sub-object according to specified selection conditions.

APPL_LOG_READ_INTERN With this function module you read all log data whose log class has at least the specified value, from local memory, for the specified object or sub-object.


Delete application log


Function group SLG2

With this function module you delete logs.
APPL_LOG_DELETE With this function module you delete logs in the database according to specified selection conditions


4.6 Function modules for writing application logs.

Much more flexible than old functions. Modules are relatively well documented. Read the documentation.
Run SBAL_DOCUMENTATION to see detailed documentation.

Simple call

BAL_LOG_CREATE Create log with header data

BAL_LOG_MSG_ADD Put message in log

BAL_DSP_LOG_DISPLAY Display messages in memory


Methods of collecting messages

BAL_LOG_CREATE Create log with header data

BAL_LOG_MSG_ADD Put message in log

BAL_LOG_MSG_CUMULATE Add message cumulated

BAL_LOG_MSG_REPLACE Replace last message

BAL_GLB_MSG_CURRENT_HANDLE_GET Get current message handle

BAL_LOG_MSG_DELETE Delete message

BAL_LOG_MSG_CHANGE Change message

BAL_GLB_MSG_DEFAULTS_GET Get message defaults

Program SBAL_DEMO_02

Find and read messages in memory

BAL_GLB_SEARCH_LOG Find logs in memory

BAL_GLB_SEARCH_MSG Find messages in memory

BAL_LOG_HDR_READ Read log header and other data

BAL_LOG_MSG_READ Read message and other data

Program SBAL_DEMO_03

Log display and display profiles

BAL_DSP_LOG_DISPLAY Display Log

BAL_DSP_PROFILE_STANDARD_GET Standard profile (SLG1) for a lot of logs

BAL_DSP_PROFILE_SINGLE_LOG_GET Standard profile (SLG1) for one log

BAL_DSP_PROFILE_NO_TREE_GET Display without tree (fullscreen)

BAL_DSP_PROFILE_POPUP_GET Display without tree (popup)

BAL_DSP_PROFILE_DETLEVEL_GET Message hierarchy in DETLEVEL

Program SBAL_DEMO_04

Display log in subscreen

BAL_DSP_OUTPUT_INIT Initialize output

BAL_DSP_OUTPUT_SET_DATA Set dataset to be displayed

BAL_DSP_OUTPUT_FREE End output

Program SBAL_DEMO_04_SUBSCREEN

Log display in Control Container

BAL_CNTL_CREATE Create Control for log display

BAL_CNTL_REFRESH Put new data in log display

BAL_CNTL_FREE Release Control

Program SBAL_DEMO_04_CONTROL

Save, load, find and delete logs in the database

BAL_DB_SAVE Save logs in the database

BAL_DB_SAVE_PREPARE Prepare save

BAL_DB_SEARCH Find logs in the database

BAL_DB_LOAD Load logs from the database

BAL_LOG_REFRESH Delete log from memory

BAL_GLB_MEMORY_REFRESH (Partially) reset global memory

BAL_DB_DELETE Delete logs from the database

Program SBAL_DEMO_05

Change logs

BAL_DB_ENQUEUE Lock log

BAL_DB_LOAD Load log(s)

BAL_DB_SAVE Save log(s)

BAL_DB_DEQUEUE Unlock log

BAL_LOG_MSG_CHANGE Change message

BAL_LOG_MSG_DELETE Delete message

BAL_LOG_HDR_CHANGE Change log header

BAL_LOG_DELETE Delete log (from database also at Save)

BAL_LOG_REFRESH Delete log from memory


Start transaction: Initializations

BAL_GLB_CONFIG_SET Set configuration

BAL_GLB_CONFIG_GET Read configuration

BAL_GLB_AUTHORIZATION_GET Assign authorization

BAL_GLB_AUTHORIZATION_RESET Reset authorization

BAL_GLB_MEMORY_REFRESH (Partially) initialize memory

BAL_MSG_DISPLAY_ABAP Output message as ABAP-MESSAGE


Working roll area-independently

BAL_GLB_MEMORY_EXPORT Put function group memory in ABAP-MEMORY

BAL_GLB_MEMORY_IMPORT Get function group memory from ABAP-MEMORY


Data and existence checks

BAL_LOG_HDR_CHECK Check log header data for consistency

BAL_LOG_MSG_CHECK Check message data for consistency

BAL_LOG_EXIST Check existence of a log in memory

BAL_LOG_MSG_EXIST Check existence of a message in memory


Read or check Application Log object and subobject

BAL_OBJECT_SELECT Read Application Log objects table record

BAL_SUBOBJECT_SELECT Read subobject table record

BAL_OBJECT_SUBOBJECT Check whether object and subobject exist and the combination is allowed


Log Display: Detail screens

BAL_DSP_MSG_LONGTEXT Display message long text

BAL_DSP_MSG_PARAMETERS Either output extended long text or call a callback routine (based on the data in BAL_S_MSG-PARAMS)

BAL_DSP_MSG_TECHNICAL_DATA Output technical data of a message such as work area, error number, etc.

BAL_DSP_LOG_PARAMETERS Either output extended long text or call a callback routine (based on the data in BAL_S_LOG-PARAMS)

BAL_DSP_LOG_TECHNICAL_DATA Output all log header data

Here is some documentation on SAP's logging:
PDF format -
HTML document -

Комментариев нет:

Отправить комментарий