Logging, BAL
Logging is essential for developing end-user business processes. In ABAP systems, the standard tool for this purpose is the Business Application Log (BAL), which is supported in both on-premise systems and ABAP Cloud. With abap2UI5, you can use BAL functions just as you would in classic development. Logs can be displayed in tables or using the predefined popups provided by the framework.
BAL Variables
In ABAP classic, you can use the classic BAL function modules and display the BAL table with the popup z2ui5_cl_pop_messages
:
METHOD z2ui5_if_app~main.
DATA(lt_bal) = VALUE bal_t_msgr(
( msgid = 'Z001' msgno = '001' msgty = 'S' time_stmp = '21354' msgnumber = '01' )
( msgid = 'Z001' msgno = '001' msgty = 'S' time_stmp = '21354' msgnumber = '02' ) ).
client->nav_app_call( z2ui5_cl_pop_messages=>factory( lt_bal ) ).
ENDMETHOD.
ABAP Cloud
In ABAP Cloud, you can directly pass the logging object into the popup:
METHOD z2ui5_if_app~main.
DATA(lo_log) = cl_bali_log=>create( ).
DATA(lo_msg) = cl_bali_message_setter=>create(
severity = if_bali_constants=>c_severity_status
id = 'DEMO_LOG'
number = '002'
variable_1 = `username` ).
lo_log->add_item( lo_msg ).
DATA(lo_bapi) = cl_bali_message_setter=>create_from_bapiret2(
VALUE #(
type = 'E'
id = 'DEMO_LOG'
number = '002'
message_v1 = 'Dummy' ) ).
lo_log->add_item( lo_bapi ).
client->nav_app_call( z2ui5_cl_pop_messages=>factory( lo_log ) ).
ENDMETHOD.
abap-logger
You also have the option to use the fantastic open-source project abap-logger. This tool simplifies working with BAL logs and integrates seamlessly with abap2UI5. Here’s an example:
METHOD z2ui5_if_app~main.
DATA(log) = zcl_logger_factory=>create_log( desc = 'ABAP Logger' ).
log->e( 'This is an error...' ).
log->s( 'This is a success message...' ).
client->nav_app_call( z2ui5_cl_pop_messages=>factory( log ) ).
ENDMETHOD.
BAL Popup
Compared to message classes, BAL logs include more detailed information, such as timestamps. Use the specific BAL log popup to display this information. All the examples above can be used with the z2ui5_cl_pop_bal
popup for a more detailed output, here’s an example for the abap-logger:
METHOD z2ui5_if_app~main.
DATA(lo_log) = zcl_logger_factory=>create_log( desc = 'ABAP Logger' ).
log->e( 'This is an error...' ).
client->nav_app_call( z2ui5_cl_pop_bal=>factory( lo_log ) ).
ENDMETHOD.
TIP
The BAL popup is still in its early stages and offers basic functionality only. If you’ve implemented BAL features with abap2UI5, consider contributing to extend its capabilities.