Ir al contenido principal

Cómo crear un LOG SLG1 (SLG0 - SLG2)

 Cuando creamos un programa que realiza actualizaciones de la base de datos como por ejemplo una carga masiva, es interesante poder ver los mensajes y el estado de cada una de las actualizaciones en un Log que podremos consultar cuando sea necesario desde las transacciones que nos proporciona SAP.

Estas son:

  • SLG0 : Crear objeto y subobjeto del Log.
  • SLG1: Visualizar Logs.
  • SLG2: Borrar Logs.

ESTRUCTURA DEL LOG:

Antes de nada, veamos la información que nos proporciona un Log:  Contiene información de cabecera ( tipo , creador, nº de log, Fecha, Programa desde el que se ha creado el log…) y un listado de mensajes que pueden ser de 3 tipos: error, warning y correcto.






En el listado de mensajes podremos filtrar por tipo de mensaje simplemente pulsando en la barra el tipo que queramos ver.

CREAR UN LOG

1. SLG0-El primer paso es crear el objeto y sub-objeto log

Es una forma de clasificar los logs , deberemos dar un nombre al objeto y subobjeto con el que luego crearemos nuestro log.









2. Modulos de funciones Application Log

Podemos usar varias funciones para crear el log, todas ellas empiezan por BAL_LOG*, las más importantes y en el orden que debemos utilizarlas son:

DATA: ls_log_header TYPE bal_s_log,                        gv_log_handle TYPE balloghndl.    CALL FUNCTION ‘BAL_LOG_CREATE’   EXPORTING     i_s_log                 = ls_log_header   IMPORTING     e_log_handle            = gv_log_handle   EXCEPTIONS     log_header_inconsistent = 1     OTHERS                  = 2.  IF sy-subrc <> 0. ENDIF.  
  • Iniciar el Log -> BAL_LOG_CREATE

En primer lugar, debemos abrir el log con este módulo de funciones, pasándole la estructura de la cabecera del log (ls_log_header) que contendrá entre otras cosas el nombre del objeto y subobjeto que hemos creado previamente.

  • Añadir mensajes al Log:

BAL_LOG_MSG_ADD  , BAL_LOG_MSG_ADD_FREE_TEXT  , BAL_LOG_MSG_CUMULATE

CALL FUNCTION ‘BAL_LOG_MSG_ADD_FREE_TEXT’
    EXPORTING
      i_log_handle     = gv_log_handle
      i_msgty          = lv_tipo     *Puede ser ‘E’,’W’,’A’,’S’
      i_probclass      = lv_probclass
      i_text           = lv_texto
    EXCEPTIONS
      log_not_found    = 1
      msg_inconsistent = 2
      log_is_full      = 3
      OTHERS           = 4.
  IF sy-subrc <> 0.
  ENDIF.  

Ejemplo: Con texto libre: En lv_texto podemos añadir el texto que nosotros queramos:

Lv_probclass puede tomar 4 valores:

Si queremos por ejemplo mostrar los mensajes que nos ha devuelto una llamada CALL TRANSACTION (l_s_msg) podremos utilizar:

CALL FUNCTION ‘BAL_LOG_MSG_ADD’    EXPORTING   
i_log_handle             = gv_log_handle      
i_s_msg                  = l_s_msg    
EXCEPTIONS      
log_not_found      = 1     
msg_inconsistent = 2      
log_is_full              = 3      
OTHERS             = 4    




  • Grabar el Log:

Para poder consultar el log que hemos creado desde la transacción SLG1 tenemos que guardarlo. Si no lo hacemos el log solamente estará disponible durante la ejecución del programa, puede ser útil si solo queremos ver el resultado cuando termine de ejecutarse el programa y si este se ejecuta en modo online. Al guardar el log, se le asigna un número, durante la ejecución del programa este número es temporal.

    CALL FUNCTION ‘BAL_DB_SAVE’
      EXPORTING
        i_save_all       = ‘X’
      EXCEPTIONS
        log_not_found    = 1
        save_not_allowed = 2
        numbering_error  = 3
        OTHERS           = 4.  
  • Mostrar el resultado del Log:
call function ‘BAL_DSP_LOG_DISPLAY’     
exceptions        
others                 = 1.

Transaccion SLG1

Desde esta transacción podemos ver todos los logs guardados en el sistema:




Fuente:
https://orekait.com/blog/como-crear-un-log-slg1/

Comentarios

Entradas más populares de este blog

A to Z of OLE Excel in ABAP 7.4

  SAP users, both business and end users always need to download the output of a report to spreadsheet and do their analytics.   The standard excel output from a report is very simple process but it is old fashioned and the spreadsheet looks quite boring.  There is no default formatting and the users have to do all the hard work of changing the fonts, coloring the texts, marking the borders etc. Updated 16th Aug 2019  –  If you are working in non-ABAP 7.4 (below), there is complete reference program for you too. Go to the end of this article.  Thank you  Legxis  ( LeonievonK ) for the share. I acknowledge, whatever I mentioned above can be achieved in many ways programmatically. We can do it in the old traditional ABAP way but  providing multiple tabs in the spreadsheet and formatting is quite tricky with non  OLE  method. OLE = Object Linking and Embedding The high level agenda of this article is to be the  G.O.A.T.  (please google it if you do not know the full form)  of OLE Excel Gu
How to add custom field in Additional B Tab for SAP Sales Order In this article we want to explain step by step how to add custom field in SAP Sales Order transaction VA01/VA02/VA03. This time Mr ABAPGurus will give the tutorial of enhancement to add custom field in SAP Sales order. In this sample we will add new custom field for comments and customer satisfaction, this data will save into separate table from SAP Standard table ( VBAK / VBAP ). SAP provided us with ADDITIONAL TAB in the sales order transaction ( VA01/VA02/VA03 ) which allow customer to add custom fields.  T he different between ADDITIONAL A and ADDITIONAL B is the ADDITIONAL A for field which already predefine in Sales Order Header ( VBAK ) fields and ADDITIONAL B is for field that freely define. This sample we will use ADDITIONAL B because we will store data from customer satisfaction into Z database table. 1. Create one Z table using SE11 SAP Transaction code. 2.Using SE38 Transaction code and ope

VOFM

Creating VOFM custom routine, functionality same as SAP standard routine 103 with Additional Functionality 1.    Introduction 1.1   Document Purpose 1.2    This is the document helps you to create custom routine for sales order for below specific requirement: Functional description: In case of sale order with the SD document category ‘K’ or ‘L’ or ‘H’ related to an invoice, we need to fill the fixed value date (VBKD_VALDT) with the billing reference date (VBRK_FKDAT). For example: Invoice 90001111, the billing date is 22.07.2013 If we create a sale order related to this invoice, we want the fixed value date equal to the billing reference date. As per the requirement: Sap standard routine ‘103’ triggers whenever sales order is being created with reference. Sap standard routine is configured in VOFM transaction as: Sap standard routine ‘103’ has the functionality of copying the billing document header data and billing document line item data into the