1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
FORM bapi_write_to_application_log USING iv_object TYPE balobj_d iv_subobject TYPE balsubobj it_error_log TYPE bapirettab. DATA: lv_extno TYPE timestamp, ls_s_log TYPE bal_s_log, ls_s_msg TYPE bal_s_msg, lv_log_handle TYPE balloghndl, lt_log_handle TYPE bal_t_logh. IF NOT it_error_log IS INITIAL. CONVERT DATE sy-datum TIME sy-uzeit INTO TIME STAMP lv_extno TIME ZONE sy-zonlo. ls_s_log-extnumber = lv_extno. ls_s_log-object = iv_object. ls_s_log-subobject = iv_subobject. ls_s_log-aldate = sy-datum. ls_s_log-altime = sy-uzeit. ls_s_log-aluser = sy-uname. * Create application log CALL FUNCTION 'BAL_LOG_CREATE' EXPORTING i_s_log = ls_s_log IMPORTING e_log_handle = lv_log_handle EXCEPTIONS log_header_inconsistent = 1 OTHERS = 2. IF sy-subrc = 0. APPEND lv_log_handle TO lt_log_handle. * Add messages to application log LOOP AT it_error_log ASSIGNING FIELD-SYMBOL(<fs_error_log>). CLEAR ls_s_msg. ls_s_msg-msgty = <fs_error_log>-type. ls_s_msg-msgid = <fs_error_log>-id. ls_s_msg-msgno = <fs_error_log>-number. ls_s_msg-msgv1 = <fs_error_log>-message_v1. ls_s_msg-msgv2 = <fs_error_log>-message_v2. ls_s_msg-msgv3 = <fs_error_log>-message_v3. ls_s_msg-msgv4 = <fs_error_log>-message_v4. CALL FUNCTION 'BAL_LOG_MSG_ADD' "#EC CI_SUBRC EXPORTING i_log_handle = lv_log_handle i_s_msg = ls_s_msg EXCEPTIONS log_not_found = 1 msg_inconsistent = 2 log_is_full = 3 OTHERS = 4. ENDLOOP. * Save application log CALL FUNCTION 'BAL_DB_SAVE' "#EC CI_SUBRC EXPORTING i_t_log_handle = lt_log_handle EXCEPTIONS log_not_found = 1 save_not_allowed = 2 numbering_error = 3 OTHERS = 4. IF sy-subrc <> 0. * do nothing ENDIF. ENDIF. ENDIF. ENDFORM. |
Пример вызова
1 2 3 |
PERFORM bapi_write_to_application_log USING 'ZOBJECT' 'ZSUBOBJECT' lt_messages. |
Не забываем завести объект и подобъект для журнала в таблицах
BALOBJ и BALSUB (V_BALSUB).