Sei sulla pagina 1di 6

Crear LOG para Batch Input o Call Transaction

27/05/2011Ing. Eduardo Miguel PuricelliDeja un comentarioGo to comments


Transacciones asociadas: SLG0, SLG1

Vamos a crear un LOG para ver el resultado de la ejecucin de, por ejemplo, un CALL
TRANSACTION (puede usarse para cualquier cosa que use una tabla de mensajes)

Para ello necesitamos meter mucho cdigo (recomiendo armarse un incluye) y crear un objeto
de log.

Empecemos creando el objeto de log: tenemos que ir a la transaccin SLG0, seleccionamos un


objeto (ejemplo ZFI) y hacemos click en Objetos inferiores.

All creamos un log para nuestro programa (con Entradas nuevas) y grabamos

Ahora vayamos al cdigo:

Las funciones que se usan son las funciones BAL_LOG* para la creacin y manipulacin del log y
BAL_* para visualizar y grabarlo en SAP.

La secuencia sera la siguiente:

1. Creo un objeto de log con la funcin BAL_LOG_CREATE


2. Hago un refresh de la tabla interna que contiene los datos de log con la funcin
BAL_LOG_REFRESH
3. loopeo la tabla de mensajes para agregar todos los mensajes al log (supongamos que los
mensajes son generados por la ejecucin de un call transaction), con la funcin
BAL_LOG_MSG_ADD
4. Muestro el resultado del log en pantalla con la funcin BAL_DSP_LOG_DISPLAY
5. Grabo en SAP el log, para luego poder acceder a verlo por la transaccin SLG1, con la funcin
BAL_DB_SAVE.
Hay varias funciones ms relacionadas, les recomiendo mirar las que existen. En este link hay
una explicacin de casi todas creo:

http://abap4.tripod.com/Using_Application_Logging.html
Bien, les paso ahora el cdigo y el include:

Ejemplo:

constants:
* Objeto y sub-objeto de log
co_object type balobj_d value ZFI,
co_subobject type balsubobj value ZFI_AR0001.
* Creo el LOG
perform log_create.

* Llamo al call transaction


call transaction VK11

using l_bdcdata_tab
mode co_mode
update co_updt
messages into p_messtab_tab. Lo que nos importa son los mensajes
* Proceso la tabla de mensajes p_messtab_tab
perform procesar_mess_tab changing p_messtab_tab[].

* Muestra el LOG de ejecucin


perform log_display.
perform log_save.
form procesar_mess_tab changing p_mess_tab type ty_bdcmsgcoll_tab.
data: l_mess_err type c.
perform log_process changing p_mess_tab
l_mess_err.
endform. PROCESAR_MESS_TAB
form log_create.
data: l_log_wa type bal_s_log.
if g_ctrllog_wa-crtlog is initial.

g_ctrllog_wa-crtlog = abap_true.

perform log_refresh using g_log_handle


g_log_handle_tab.
l_log_wa-object = co_object.
l_log_wa-subobject = co_subobject.
l_log_wa-aldate = sy-datum.
l_log_wa-altime = sy-uzeit.
l_log_wa-aluser = sy-uname.
l_log_wa-altcode = sy-tcode.
l_log_wa-alprog = sy-repid.
l_log_wa-almode = D.
l_log_wa-alchdate = sy-datum.
l_log_wa-alchtime = sy-uzeit.
l_log_wa-alchuser = sy-uname.
call function BAL_LOG_CREATE
exporting
i_s_log = l_log_wa
importing
e_log_handle = g_log_handle
exceptions
log_header_inconsistent = 1
others = 2.
if not sy-subrc is initial.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endif.

endform. LOG_CREATE
form log_process
changing p_mess_tab type ty_bdcmsgcoll_tab
p_mess_err type c.
data: l_dummy type c, #EC NEEDED
l_mess_wa type bdcmsgcoll.
loop at p_mess_tab into l_mess_wa.
message id l_mess_wa-msgid
type l_mess_wa-msgtyp
number l_mess_wa-msgnr
with l_mess_wa-msgv1
l_mess_wa-msgv2
l_mess_wa-msgv3
l_mess_wa-msgv4
into l_dummy.
Aadimos los mensajes a nuestro log.
perform log_msg_add changing p_mess_err.
endloop.
clear: p_mess_tab.
refresh: p_mess_tab.
free: p_mess_tab.
endform. LOG_PROCESS
form log_refresh
using p_log_handle type balloghndl
p_log_handle_tab type bal_t_logh.
call function BAL_LOG_REFRESH
exporting
i_log_handle = p_log_handle
exceptions
log_not_found = 1
others = 2.
if not sy-subrc is initial.
exit.
endif.
refresh p_log_handle_tab.
endform. LOG_REFRESH
form log_msg_add
changing p_mess_err type c.
data: l_msg_wa type bal_s_msg.

l_msg_wa-msgty = sy-msgty.
l_msg_wa-msgid = sy-msgid.
l_msg_wa-msgno = sy-msgno.
l_msg_wa-msgv1 = sy-msgv1.
l_msg_wa-msgv2 = sy-msgv2.
l_msg_wa-msgv3 = sy-msgv3.
l_msg_wa-msgv4 = sy-msgv4.
case sy-msgty.
when co_msgty_x.
l_msg_wa-probclass = co_probclass_very_high.
p_mess_err = X.
when co_msgty_a.
l_msg_wa-probclass = co_probclass_very_high.
p_mess_err = X.
when co_msgty_e.
l_msg_wa-probclass = co_probclass_high.
p_mess_err = X.
when co_msgty_w.
l_msg_wa-probclass = co_probclass_medium.
when co_msgty_i.
l_msg_wa-probclass = co_probclass_low.
when co_msgty_s.
l_msg_wa-probclass = co_probclass_low.
when co_msgty_none.
l_msg_wa-probclass = co_probclass_none.
endcase.
call function BAL_LOG_MSG_ADD
exporting
i_log_handle = g_log_handle
i_s_msg = l_msg_wa
exceptions
log_not_found = 1
msg_inconsistent = 2
log_is_full = 3
others = 4.
if not sy-subrc is initial.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
append g_log_handle to g_log_handle_tab.

endform. LOG_MSG_ADD
form log_display .
call function BAL_DSP_LOG_DISPLAY
* EXPORTING
* I_S_DISPLAY_PROFILE =
* I_T_LOG_HANDLE =
* I_T_MSG_HANDLE =
* I_S_LOG_FILTER =
* I_S_MSG_FILTER =
* I_T_LOG_CONTEXT_FILTER =
* I_T_MSG_CONTEXT_FILTER =
* I_AMODAL =
* IMPORTING
* E_S_EXIT_COMMAND =
exceptions
profile_inconsistent = 1
internal_error = 2
no_data_available = 3
no_authority = 4
others = 5.
if not sy-subrc is initial.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform. LOG_DISPLAY
form log_save.
data: l_bal_t_lgnm type bal_t_lgnm.
call function BAL_DB_SAVE Application Log: Database: Save logs
exporting
i_client = sy-mandt sy-mandt Client in which the new log is to be saved
i_in_update_task = space boolean Save in UPDATE TASK
i_save_all = space boolean Save all logs in memory
i_t_log_handle = g_log_handle_tab bal_t_logh Table of log handles
importing
e_new_lognumbers = l_bal_t_lgnm #EC NEEDED bal_t_lgnm Table of new log numbers
exceptions
log_not_found = 1 Log not found
save_not_allowed = 2 Cannot save
numbering_error = 3 Number assignment error
.
if not sy-subrc is initial.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform. log_save
Ejecutamos el programa y luego accedemos a la transaccin SLG1 para ver los resultados de la
ejecucin del LOG.
Ac vemos los resultados que se generaron al usar el call transaction

Potrebbero piacerti anche