SAP MDG · UTILITIES

How do I read SLG1 application log messages for a change request and filter them for email notifications in SAP MDG?

Use APPL_LOG_READ_DB with the change-request external number pattern 'CRequest Activation-<CR_ID>', keep only the requested message type, compare timestamps against the newest entry with SCOV_TIME_DIFF, and convert the selected BAL messages to readable text using MESSAGE_TEXT_BUILD before adding them to the email output.

Use APPL_LOG_READ_DB with the change-request external number pattern 'CRequest Activation-<CR_ID>', keep only the requested message type, compare timestamps against the newest entry with SCOV_TIME_DIFF, and convert the selected BAL messages to readable text using MESSAGE_TEXT_BUILD before adding them to the email output.

To build email-ready SLG1 output for an MDG change request, the pattern is to derive the application-log external number from the request ID, read BAL messages with APPL_LOG_READ_DB, sort by timestamp, filter by message type, and keep only the log entries that are close to the latest event. The retrieved messages are then converted to readable text with MESSAGE_TEXT_BUILD and appended to the email message table.

Process flow

  1. Build the application-log external number from the change request ID.
  2. Read BAL messages from the log repository.
  3. Sort the messages by timestamp descending.
  4. Filter to the required message type.
  5. Identify the latest timestamp.
  6. Convert timestamps to date/time.
  7. Compute the time difference in seconds.
  8. Keep only messages within the 120-second window.

Referenced tables

ObjectPurpose
BALMApplication log message table used as the source message list
BAPIRET2Output structure for readable message text in email processing
BALNREXTExternal number for the application log object
USMD1210Change request note table shown in related MDG utility logic

ILLUSTRATIVE ABAP SAMPLE

Source ABAP example

Exact relevant implementation excerpt from the knowledge document.

1METHOD fetch_slg1_logs. 2 3**Data Declarations 4 DATA:ld_extnum TYPE balnrext, 5 ld_pattern TYPE string, 6 ld_cr_activation_pattern TYPE string, 7 lt_messages TYPE STANDARD TABLE OF balm, 8 ls_msg_output TYPE bapiret2, 9 ld_recent_date TYPE cva_date, 10 ld_date TYPE cva_date, 11 ld_recent_time TYPE cva_time, 12 ld_time TYPE cva_time, 13 ld_date_diff TYPE i, 14 ld_time_diff TYPE cva_time, 15 ld_sec TYPE i. 16 17**Fetch Pattern 18 CONCATENATE 'CRequest Activation-' iv_crequest_id INTO ld_cr_activation_pattern. 19 20**Fetch External Number 21 ld_extnum = ld_cr_activation_pattern. 22 23**Fetch SLG1 Logs 24 CALL FUNCTION 'APPL_LOG_READ_DB' 25 EXPORTING 26 external_number = ld_extnum 27 TABLES 28 messages = lt_messages. 29 30**Sort messages based on Time Stamp Descending 31 SORT lt_messages BY time_stmp DESCENDING. 32 33**Delete messages that do not belong to the input message type 34 DELETE lt_messages WHERE msgty NE iv_message_type. 35 36**Fetch Latest Message Entry, Date and Time 37 READ TABLE lt_messages ASSIGNING FIELD-SYMBOL(<ls_latest_record>) INDEX 1. 38 IF <ls_latest_record> IS ASSIGNED. 39 CONVERT TIME STAMP <ls_latest_record>-time_stmp TIME ZONE sy-zonlo 40 INTO DATE ld_recent_date TIME ld_recent_time. 41 ENDIF. 42 43**Latest messages are being formatted 44 LOOP AT lt_messages ASSIGNING FIELD-SYMBOL(<ls_messages>). 45 46**Fetch Date and Time of the Message Entry 47 CONVERT TIME STAMP <ls_messages>-time_stmp TIME ZONE sy-zonlo 48 INTO DATE ld_date TIME ld_time. 49 50**Fetch Date and Time difference 51 CALL FUNCTION 'SCOV_TIME_DIFF' 52 EXPORTING 53 im_date1 = ld_date 54 im_date2 = ld_recent_date 55 im_time1 = ld_time 56 im_time2 = ld_recent_time 57 IMPORTING 58 ex_days = ld_date_diff 59 ex_time = ld_time_diff 60 EXCEPTIONS 61 start_larger_than_end = 1 62 OTHERS = 2. 63 IF sy-subrc <> 0. 64* Implement suitable error handling here 65 ENDIF. 66 67**Fetch Time Difference in seconds 68 ld_sec = ( ( ld_time_diff+0(2) * 3600 ) + ( ld_time_diff+2(2) * 60 ) + ld_time_diff+4(2) ). 69 70**When Time Difference is less than or equal to 2 minutes 71 IF ld_date_diff LE 0 AND ld_sec LE 120. 72 73 CALL FUNCTION 'MESSAGE_TEXT_BUILD' 74 EXPORTING 75 msgid = <ls_messages>-msgid 76 msgnr = <ls_messages>-msgno 77 msgv1 = <ls_messages>-msgv1 78 msgv2 = <ls_messages>-msgv2 79 msgv3 = <ls_messages>-msgv3 80 msgv4 = <ls_messages>-msgv4 81 IMPORTING 82 message_text_output = ls_msg_output-message. 83 84**Push messages to output messages structure 85 APPEND ls_msg_output TO et_messages. 86 CLEAR ls_msg_output. 87 88 ENDIF. 89 90 ENDLOOP. 91 92 ENDMETHOD.

The remaining configuration, implementation details, and testing guidance continue from this answer more…

Related questions and keywords

Alternative questions

  • How can I fetch SLG1 logs for an MDG change request in ABAP?
  • How do I build an email-friendly list of application log messages for a change request?
  • What is the ABAP pattern to read and filter MDG activation logs from SLG1?

Possible questions

  • How can I fetch SLG1 logs for an MDG change request in ABAP?
  • How do I build an email-friendly list of application log messages for a change request?
  • What is the ABAP pattern to read and filter MDG activation logs from SLG1?
  • Which function module reads application log entries from SLG1?
  • How do I convert BAL messages into readable text in ABAP?

Keywords

SAP MDGSLG1application logchange requestemail notificationAPPL_LOG_READ_DBMESSAGE_TEXT_BUILDSCOV_TIME_DIFFBALMBAPIRET2