Message log ABAP

Often there is a need to display a list of messages to the user. In the message log you can display information about the progress of the program, as well as a list of errors that occurred as a result.

Throughout the work of the program, a globally defined variable that is filled with the necessary messages after which, for example, is called method for displaying the message log or saving this log in the system for further viewing in transaction SLG1.

Template for displaying a message log:

	DATA:
		ls_log   TYPE bal_s_log,
		ls_prof  TYPE bal_s_prof,
		lv_log_h TYPE balloghndl. 
						
	" Fill the log variable 
	CALL FUNCTION 'BAL_LOG_CREATE' 
		EXPORTING 
			i_s_log      = ls_log 
		IMPORTING 
			e_log_handle = lv_log_h
		EXCEPTIONS 
			OTHERS       = 0. 
							
	" In the loop we add messages to the log
	LOOP AT mt_msg REFERENCE INTO DATA(lr_msg).
	  CALL FUNCTION 'BAL_LOG_MSG_ADD'
		EXPORTING
		  i_log_handle = lv_log_h
		  i_s_msg      = lr_msg->*.
	ENDLOOP.
					
	" Fill the log window variable
	CALL FUNCTION 'BAL_DSP_PROFILE_STANDARD_GET'
	  IMPORTING
		e_s_display_profile = ls_prof.
				
	" Set the window size      
	ls_prof-start_row = 5.
	ls_prof-end_row   = 25.
	ls_prof-start_col = 10.
	ls_prof-end_col   = 150.
	ls_prof-show_all  = abap_true.
					
	" We pass the window data to the log	
	CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
	  EXPORTING
		i_s_display_profile = ls_prof.
							
	" Display the message log on the screen
	CALL FUNCTION 'BAL_LOG_REFRESH'
	  EXPORTING
		i_log_handle = lv_log_h.
								
	" Clean the global message variable
	CLEAR mt_msg. 

Done. As a result, we get a message log on the screen with indicators depending on the type of message with text and the ability to view the details of each message. The need for a global variable in which messages are stored may not be, if, for example, there is a need, before exiting the program, to have access to all messages during its working time.

Also, many interesting examples can be found in SBAL_DEMO*.