Ansicht
Dokumentation

BAL_CH_COLLECT -

BAL_CH_COLLECT -

SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up   CL_GUI_FRONTEND_SERVICES - Frontend Services  
This documentation is copyright by SAP AG.
SAP E-Book

|---------------------------------------------------------------------|
| Message Sets | |
|---------------------------------------------------------------------|

Overview
======================================================================

Sets of logs can be created with the following methods.

Function modules:
BAL_LOG_CREATE Create log with header data
BAL_LOG_MSG_ADD Log a message
BAL_LOG_EXCEPTION_ADD Add an exception to the log
BAL_LOG_MSG_CUMULATE Add a message cumulatively to the log
BAL_LOG_ADD_LOG_ITEMS Add all messages and exceptions of a log to another log
BAL_LOG_MSG_REPLACE Replaces the last message
BAL_GLB_MSG_CURRENT_HANDLE_GET Get the current message handle
BAL_LOG_MSG_DELETE Delete message
BAL_LOG_EXCEPTION_DELETE Delete exception
BAL_LOG_MSG_CHANGE Change message
BAL_LOG_EXCEPTION_CHANGE Change exception
BAL_GLB_MSG_DEFAULTS_GET Get message data defaults
BAL_GLB_MSG_DEFAULTS_SET Set message data defaults

Types
BAL_S_MDEF Message defaults

Example Program
The report SBAL_DEMO_02 simulates a flight check. Its output is the results of the check.
==>Run SBAL_DEMO_02 ==>SBAL_DEMO_02 code

Add message to log
=======================================================================

This is the "classic" method of including messages in a log. A message is appended to the log simply by using BAL_LOG_MSG_ADD.

==>Note
The log handle is optional for function modules such as BAL_LOG_MSG_ADD, BAL_LOG_MSG_CUMULATE, BAL_LOG_MSG_ADD_FREE_TEXT, etc.
If it is not specified, the default log, which can be set, with other default data, with BAL_GLB_MSG_DEFAULTS_SET is used. If no default log is defined, it is set automatically by BAL_LOG_CREATE (see here).

Add message cumulatively
=======================================================================

Functionality

A message is added to the log with (log handle) I_LOG_HANDLE cumulatively.

The message data is in the IMPORTING parameter I_S_MSG (structure BAL_S_MSG).

A message handle E_S_MSG_HANDLE, which uniquely identifies this message, is returned.

'Cumulative'

Some messages are sent several times by a program, without providing new information each time. Such messages can be cumulated with BAL_LOG_MSG_CUMULATE to save memory. When the same message is repeated, no new message is added, the counter MSG_COUNT for the old message is incremented.
You can specify when messages are the same in the function module interface. The T100 data must be identical, and you can specify that other data must also be the same:

  • I_COMPARE_ATTRIBUTES = 'X'
    Message attributes (problem class PROBCLASS, level of detail DETLEVEL and sort field ALSORT) must be identical
  • I_COMPARE_CONTEXT = 'X'
    The context must be the same
  • I_COMPARE_PARAMETERS = 'X'
    The message parameters must be the same.

To find identical messages quickly for cumulation, the Application Log constructs a small index table containing as unambiguous a signature of a message as possible, at runtime. This index is only constructed if cumulation is used.

Replace last message
=======================================================================

Functionality

The most recent Application Log message is deleted and replaced by a new message.

The new message data is in the IMPORTING parameter I_S_MSG (structure BAL_S_MSG). A message handle E_S_MSG_HANDLE, which uniquely identifies the message, is returned.

In which log is the new message put?

  • If a log handle is passed in I_LOG_HANDLE, the message is put in that log.
  • Otherwise it is put in the same log as the deleted message.
  • If there is no old message and no log is specified in I_LOG_HANDLE, the message is put in the default log (see here).

Why replace the last message?

The function module BAL_LOG_MSG_REPLACE can overwrite a message sent to the Application Log by an external program, with your own message.

Example
A generic scheduling module is called to calculate a flight schedule. If scheduling fails, the function module may send a relatively technical message: "Scheduling of procedure 0006 unsuccessful". As messages should always be logged where they occur, this module sends a message to the Application Log. The message "The flight from Hamburg to New York could not be scheduled" would be much more meaningful to the user.

==>Note
You can also get the handle of the last message sent with BAL_GLB_MSG_CURRENT_HANDLE_GET. This can be useful if you want to delete or change the last message, not replace it (with BAL_LOG_MSG_DELETE) or ( BAL_LOG_MSG_CHANGE) respectively.

Message as free text
=======================================================================

Functionality

A free text message is added to the log with (log handle) I_LOG_HANDLE.

The message text is passed to the function module BAL_LOG_MSG_ADD_FREE_TEXT in the IMPORTING parameter I_TEXT (maximum length 200 characters).

The error severity (I_MSGTY) and (optionally) the problem class (I_PROBCLASS) can also be specified.

A message handle E_S_MSG_HANDLE, which uniquely identifies this message, is returned.

Set message defaults
=======================================================================

Some information which is required to make a message meaningful is only available at a higher program level, not where the message is sent.

Example
The destination of a road transport is checked in a low-level routine, which knows neither the transport number nor the route involved.

The context information can be set as defaults using BAL_GLB_MSG_DEFAULTS_SET, before this routine is called, and put in the messages which it sends.
The data type BAL_S_MDEF, which contains other data (such as message attributes, parameters, the default log, etc.) as well as the context, is passed to this function module.
You can also get the current defaults with BAL_GLB_MSG_DEFAULTS_GET. This is useful when you want to change some, but not all, defaults (for example, the item number but not the order number).

  • ==>Note
    You should use the function modules BAL_GLB_MSG_DEFAULTS_GET and BAL_GLB_MSG_DEFAULTS_SET together, to be sure of the current defaults.

The defaults affect the following function modules:
BAL_LOG_MSG_ADD Put a message in a log
BAL_LOG_EXCEPTION_ADD Add exception to a log
BAL_LOG_MSG_CUMULATE Add message cumulatively
BAL_LOG_MSG_REPLACE Replace last message
BAL_LOG_MSG_ADD_FREE_TEXT Add message as free text

Message with complex context
=======================================================================


You may want to put more complex information in a message (or log header) than you can put in the context or parameter described above.
You can use the Application Log INDX table with the ABAP commands
EXPORT TO DATABASE and IMPORT FROM DATABASE
Program SBAL_DEMO_06 shows how you can save and read complex contexts, as follows:

  • Collect messages:
    Define a CALLBACK routine (...-PARAMS-CALLBACK-...) for a log header or message.
    Collect the complex context information in internal user tables.
  • Save logs:
    Write internal tables at this event with
          EXPORT my_data TO DATABASE bal_indx(al) ID lognumber.
    The internal log number LOGNUMBER is returned by the function module BAL_DB_SAVE.
  • Display log:
    If message or log header detail is selected in the log display, the CALLBACK routine setup when collecting, is called
    You can read and display the data here using
         EXPORT my_data FROM DATABASE bal_indx(al) ID lognumber.
    The internal log number LOGNUMBER is in the internal table passed to this callback routine (under PARAM = "%LOGNUMBER").
  • Delete logs
    The application does nothing. The data is deleted automatically.

==>Note
Use complex context information with care. Problems may arise, e.g. if the structure of the complex context MY_DATA has changed in a Release change. You may not be able to read the data. There is currently no guarantee that the complex context can be archived automatically when the archiving function is realized (it does not yet exist).

Add exception to the log
=======================================================================

Functionality

An exception text is added to the log identified with I_LOG_HANDLE (log handle).

The exception class, error severity, problem class, and level of detail are given to the function module BAL_LOG_EXCEPTION_ADD using the IMPORTING parameter I_S_EXC (structure BAL_S_EXC).

Context information for exceptions and cumulated addition of exceptions are not supported.

A message handle that uniquely identifies this message is returned with E_S_MSG_HANDLE.

=> Note: This function module replaces the function module BAL_LOG_EXC_ADD.






BAL_S_LOG - Application Log: Log header data   Vendor Master (General Section)  
This documentation is copyright by SAP AG.

Length: 13072 Date: 20240510 Time: 083126     sap01-206 ( 155 ms )