Ansicht
Dokumentation

BAL_CH_SAVE_LOAD -

BAL_CH_SAVE_LOAD -

General Material Data   ABAP Short Reference  
This documentation is copyright by SAP AG.
SAP E-Book

|---------------------------------------------------------------------|
| Save and load logs |
|---------------------------------------------------------------------|

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

Logs which have been collected in memory can be saved in the database. Saved logs can be reloaded into memory and changed or displayed.

Function modules
BAL_DB_SAVE Saves 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 Remove logs from memory
BAL_GLB_MEMORY_REFRESH (Partially) reset global memory

Example

Report SBAL_DEMO_05 (==>Run ==>Coding) simulates a settlement run for all flights on a specified date. You can choose:

  • Simulate settlement.
    The documents are only collected in memory with temporary numbers, which are logged.
  • Perform settlement.
    A log is saved in the database after the temporary document numbers have been replaced by permanent ones in the log.
  • Display logs.

Save logs
=======================================================================

Functionality

You can save logs in memory in the database with the function module BAL_DB_SAVE. You can save all data in memory (Importing parameter I_SAVE_ALL = 'X') or a subset specified by a set of log handles (Importing parameter I_T_LOG_HANDLE).

You can get the log handle table by calling the function module BAL_GLB_SEARCH_LOG which searches for logs in memory by specified filter criteria.

When logs are saved, an internal log number is issued (field LOGNUMBER). At runtime this field has a temporary value (e.g. $00001).

The function module BAL_DB_SAVE returns a table (Exporting parameter E_NEW_LOGNUMBERS) which relates LOG_HANDLE, external number EXTNUMBER, temporary LOGNUMBER and permanent LOGNUMBER, so you can find out which number was assigned to a log after saving.

You can also save IN UPDATE TASK (Importing parameter I_IN_UPDATE_TASK = 'X').

You can also save the logs in another client (parameter I_CLIENT). If you do not specify I_CLIENT, you save in the current client.

Notes

After logs have been saved they are still in memory in a state as though they had just been loaded from the database. To delete saved logs from memory, use either the function module BAL_LOG_REFRESH (for one log) or BAL_GLB_MEMORY_REFRESH (for several or all logs).

The field LOGNUMBER is still visible to the caller for reasons of compatibility, but it only has a temporary value at runtime and only becomes permanent after saving, so all application tables which point to a log with the LOGNUMBER must be updated when saving.
If you use the LOG_HANDLE field, this is not necessary. LOG_HANDLE has its permanent value as soon as a log is created (with BAL_LOG_CREATE).

Prepare save
=======================================================================

Functionality

Application Log message variables or contexts can sometimes still contain temporary data.

For example document numbers. When a document is created, it has a temporary number (e.g. ‘$0001’). A permanent number is only issued from a number range interval when the document is saved.

If messages are created for such a document, the message variables could contain temporary numbers. These temporary values should be replaced by permanent ones when you save (e.g. $0001 by 0000123456), otherwise the log is of no value.

The function module BAL_DB_SAVE_PREPARE performs this substitution.
You pass a replacement pattern (table type BAL_T_RPLV) which specifies, for example that message variables with old contents ‘$0001’ (field OLD_VALUE) are to be replaced by the new value ‘12345’ (field NEW_VALUE), ‘$0002’ by ‘67890’, etc.

You can also define replacements for context information (table type BAL_T_RPLC). For example, the data in the field ‘VBELN’ (FIELDNAME) is to be replaced in all contexts which have the DDIC structure ‘MY_STRUC’ (TABNAME); ‘$0001’ (OLD_VALUE) by ‘1234 (NEW_VALUE), etc.

I_REPLACE_IN_ALL_LOGS = 'X' specifies that the replacement be made in all logs in memory. If you only want to replace in certain logs, set I_REPLACE_IN_ALL_LOGS = ' ' and put the log handle in I_T_REPLACE_IN_THESE_LOGS.

  • Note
    When replacing message variables you cannot be completely sure that e.g. the message variable MSGV1 in a particular message really contains an order number. It could also be a (coincidentally identical) temporary number of a different document which was created in the background and for which messages were also created.
    You can avoid such ambiguities by specifying the source of a message variable when a message is sent, in the fields MSGV1_SRC, ..., MSGV4_SRC in the structure BAL_S_MSG. You can refer to these values (field MSGV_SRC) when you replace the message variables with BAL_DB_SAVE_PREPARE.

Find logs in the database
=======================================================================

Functionality

The function module BAL_DB_SEARCH finds logs in the database.

You pass log header filter criteria (structure BAL_S_LFIL), and a sorted table of log headers (structure BALHDR) which satisfy the criteria is returned.
You can pass this to the module BAL_DB_LOAD BAL_DB_LOAD, which loads these logs into memory.

  • Notes
    Avoid a FULL TABLE SCAN when you create the filter structure BAL_S_LFIL by specifying the following fields or field combinations:
    - LOGNUMBER (primary index of the log header table)
    - LOG_HANDLE (has an index)
    - OBJECT/SUBOBJECT/EXTNUMBER (has an index)
    For an application object to efficiently access a log, it must have either LOGNUMBER or LOG_HANDLE in its structures, or the field EXTNUMBER should contain a unique key derived from the application object data (e.g. document number). Together with the OBJECT/SUBOBJECT (the application which wrote the log), the access should be unique.
    Other criteria such as time restrictions or transaction which created the log, can also be specified in the filter structure.
    You can also search in another client. The client in E_T_LOG_HEADER is taken into account automatically. If I_CLIENT is not specified, the current client is used.

Load logs from the database
=======================================================================

Functionality

The function module BAL_DB_LOAD loads logs from the database.
Which logs are to be loaded into memory can be specified in one of several ways:

  • I_T_LOG_HANDLE
    A table of log handles
  • I_T_LOGNUMBER
    A table of internal log numbers
  • I_T_LOG_HEADER
    A table of log headers (returned by function module BAL_DB_SEARCH)

The result of loading can be a table of log handles (Exporting parameter E_T_LOG_HANDLE) or message handles (Exporting parameter E_T_MSG_HANDLE).

This function module is cross-client:

  • If you specify I_T_LOG_HANDLE it searches in all clients (this is not critical because the log handle is globally unique)
  • If you specify I_T_LOGNUMBER the client in the parameter I_CLIENT is taken into account. If it is not specified, the current client is used.
  • If you specify I_T_LOG_HEADER the client in the table field MANDANT is taken into account (it is filled automatically by the function module BAL_DB_SEARCH).

Other parameters:

You can specify that only the log headers are to be loaded in memory with the Importing parameter I_DO_NOT_LOAD_MESSAGES. See Read log messages as required.

You can specify that the exception LOG_ALREADY_LOADED be raised if one of the logs to be loaded is already in memory, with the Importing parameter I_EXCEPTION_IF_ALREADY_LOADED = 'X'. In this case no logs are loaded.
I_EXCEPTION_IF_ALREADY_LOADED = ' ' (default) ignores a log to be loaded if it is already in memory. All other logs are loaded correctly.

  • Note
    To load the database status, use the function module BAL_DB_RELOAD, which first deletes a log from memory if necessary before loading it.

Read log messages as required
=======================================================================

The parameter I_DO_NOT_LOAD_MESSAGES = "X" tells the function module BAL_DB_LOAD to read only the log headers into memory.
The messages in a log are only read into memory at certain events:

  • read access to the messages (e.g. to display the log, or by the function module BAL_LOG_MSG_READ)
  • change access to the log (e.g. when changing the header data with function module BAL_LOG_HDER_CHANGE, or when adding messages with BAL_LOG_MSG_ADD)
  • when the function module BAL_DB_RELOAD is called for this log.

when the messages in a log are all reloaded once. Messages are not reloaded individually, so either only the header, or all of a log is in memory.

I_DO_NOT_LOAD_MESSAGES = "X" has no effect if you have defined statistics with the function module BAL_STATISTICS_GLB_SET or BAL_STATISTICS_LOG_SET (Application Log statistics tell you how many errors, warnings, etc. there were at a particular time for a specified criterion, e.g. "3 errors for material ABC").
These statistics are based on message data, so the messages must always be read.

I_DO_NOT_LOAD_MESSAGES = "X" is useful if you want to see the log header data first.

It can also be used to display logs:

if the display profile only uses log header data in the tree, you only need to read the log headers into memory. When a log is selected in the tree, the log messages are read for display.

The function module BAL_DSP_LOG_DISPLAY does not automatically know whether the tree only contains log header data, because it can also contain context information, which can be in a message or the header, so the display profile I_S_DISPLAY_PROFILE (structure BAL_S_PROF) must explicitly state that the tree contains no message data, with I_S_DISPLAY_PROFILE-TREE_NOMSG = ‘X‘.

  • Note
    I_DO_NOT_LOAD_MESSAGES ,,,,= ‘X‘
    and the display profile option
    I_S_DISPLAY_PROFILE-TREE_NOMSG ,,= ‘X‘
    are only meaningful when
    I_S_DISPLAY_PROFILE-SHOW_ALL ,,= ‘ ‘
    in the display profile, otherwise the messages are displayed immediately.





ROGBILLS - Synchronize billing plans   TXBHW - Original Tax Base Amount in Local Currency  
This documentation is copyright by SAP AG.

Length: 12970 Date: 20240510 Time: 050139     sap01-206 ( 191 ms )