Difference between revisions of "SAP ABAP DICTIONARY"

From SapWiki
(Created page with "==Tablas== ===Eventos en Utilidades-->Generador Actualiz.Tab.=== * Ejemplo Evento 01 <nowiki> FORM check_resolucion_ini. TYPES: BEGIN OF ty_data, perca TYPE zs...")
 
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
==Tablas==
 
==Tablas==
===Eventos en Utilidades-->Generador Actualiz.Tab.===
+
===Eventos en SE11-->Utilidades-->Generador actualiz.tab.===
* Ejemplo Evento 01
+
Ver tabla TVIMF
 +
==== Ejemplo Evento 01 - Antes de grabar los datos en la base de datos====
 
  <nowiki>
 
  <nowiki>
 
FORM check_resolucion_ini.
 
FORM check_resolucion_ini.
   TYPES: BEGIN OF ty_data,
+
   TYPES: BEGIN OF ty_data,   "campos de Mi tabla
 
           perca  TYPE zseg_ds67_1000-perca,
 
           perca  TYPE zseg_ds67_1000-perca,
 
           nresini TYPE zseg_ds67_1000-nresini,
 
           nresini TYPE zseg_ds67_1000-nresini,
Line 74: Line 75:
 
</nowiki>
 
</nowiki>
  
* Ejemplo evento 05
+
==== Ejemplo evento 05 - Al crear una entrada nueva====
  <mowiki>
+
  <nowiki>
 
FORM check_resolucion_ini_new.
 
FORM check_resolucion_ini_new.
  
 
   TYPES:  BEGIN OF ty_total.
 
   TYPES:  BEGIN OF ty_total.
       INCLUDE STRUCTURE zseg_ds67_1000.
+
       INCLUDE STRUCTURE zseg_ds67_1000. "Mi tabla
 
       INCLUDE STRUCTURE vimtbflags.
 
       INCLUDE STRUCTURE vimtbflags.
 
   TYPES:  END OF ty_total.
 
   TYPES:  END OF ty_total.
Line 127: Line 128:
 
ENDFORM.
 
ENDFORM.
 
</nowiki>
 
</nowiki>
 +
 +
<nowiki>
 +
FORM check_new_entry.
 +
 +
  TYPES:  BEGIN OF ty_total_c_oc_prcdef.
 +
      INCLUDE STRUCTURE z_my_table.
 +
      INCLUDE STRUCTURE vimtbflags.
 +
  TYPES:  END OF ty_total_c_oc_prcdef.
 +
 +
  DATA l_f TYPE abap_bool.
 +
 +
  FIELD-SYMBOLS: <ls_data>  TYPE z_my_table,
 +
                <ls_total> TYPE ty_total_c_oc_prcdef.
 +
 +
  ASSIGN <table1> TO <ls_data>.
 +
  IF sy-subrc IS INITIAL AND <ls_data> IS ASSIGNED.
 +
    LOOP AT total ASSIGNING <ls_total> CASTING.
 +
* verificar si registro ya fue borrado
 +
      IF <ls_total>-vim_action = geloescht
 +
        AND <ls_total>-usernw = <ls_data>-usernw
 +
        AND <ls_total>-rut = <ls_data>-rut.
 +
        l_f = abap_true.
 +
        EXIT.
 +
      ENDIF.
 +
    ENDLOOP.
 +
 +
    IF l_f = abap_false.
 +
      SELECT  COUNT(*) FROM  z_my_table
 +
            WHERE  usernw  = <ls_data>-usernw
 +
            AND    rut    = <ls_data>-rut.
 +
      IF sy-subrc = 0.
 +
        MESSAGE e000(0k) WITH 'Entrada ya existe'.
 +
      ENDIF.
 +
    ENDIF.
 +
 +
    LOOP AT total ASSIGNING <ls_total> CASTING.
 +
      IF <ls_total>-vim_action NE geloescht.
 +
        IF <ls_total>-usernw = <ls_data>-usernw
 +
          AND <ls_total>-rut = <ls_data>-rut.
 +
          MESSAGE e000(0k) WITH 'Entrada ya existe'.
 +
        ENDIF.
 +
      ENDIF.
 +
    ENDLOOP.
 +
 +
  ENDIF.
 +
 +
ENDFORM.</nowiki>
 +
 +
====ejemplo evento AA - en lugar de la rutina estándar para cargar datos====
 +
<nowiki>
 +
FORM read_z_my_table.
 +
 +
  DATA lt_z_my_table TYPE TABLE OF z_my_table.
 +
  DATA ra_user TYPE TABLE OF zbptaxnum_rango.
 +
 +
  REFRESH total.
 +
 +
  IMPORT ra_user FROM MEMORY ID 'Z_MY_TABLE'.
 +
 +
  SELECT * INTO TABLE lt_z_my_table FROM z_my_table WHERE usernw IN ra_user.
 +
  IF sy-subrc = 0 AND lt_z_my_table[] IS NOT INITIAL.
 +
    LOOP AT lt_z_my_table INTO DATA(wa).
 +
*    append missing entry
 +
      <vim_total_struc> = wa.
 +
      APPEND total.
 +
    ENDLOOP.
 +
*  ensure correct sorting
 +
    SORT total BY <vim_xtotal_key>.
 +
  ENDIF.
 +
ENDFORM. </nowiki>
 +
 +
programa para actualizar tabla
 +
<nowiki>
 +
DATA wa TYPE z_my_table.
 +
 +
*--------------------------------------------------------------------*
 +
SELECT-OPTIONS: ra_user FOR wa-usernw.
 +
*--------------------------------------------------------------------*
 +
 +
*--------------------------------------------------------------------*
 +
START-OF-SELECTION.
 +
*--------------------------------------------------------------------*
 +
* ver eventos en mantenedor de tabla z_my_table (trn SE11)
 +
EXPORT ra_user TO MEMORY ID 'Z_MY_TABLE'.
 +
 +
CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
 +
  EXPORTING
 +
    action                    = 'U'
 +
    view_name                  = 'Z_MY_TABLE'
 +
    no_warning_for_clientindep = 'X'
 +
  EXCEPTIONS
 +
    OTHERS                    = 15.
 +
 +
IF sy-subrc <> 0.
 +
  MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
 +
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
 +
 +
ENDIF.</nowiki>
 +
 +
===Bloquear Tablas===
 +
<nowiki>
 +
data l_VARKEY TYPE  RSTABLE-VARKEY.
 +
 +
l_varkey = sy-mandt.
 +
 +
CALL FUNCTION 'ENQUEUE_E_TABLEE'
 +
EXPORTING
 +
*  MODE_RSTABLE        = 'E'
 +
  TABNAME              = 'T7RUSCHOOL'
 +
  VARKEY              = l_varkey
 +
*  X_TABNAME            = ' '
 +
*  X_VARKEY            = ' '
 +
*  _SCOPE              = '2'
 +
*  _WAIT                = ' '
 +
*  _COLLECT            = ' '
 +
EXCEPTIONS
 +
  FOREIGN_LOCK        = 1
 +
  SYSTEM_FAILURE      = 2
 +
  OTHERS              = 3
 +
          .
 +
IF sy-subrc <> 0.
 +
* Implement suitable error handling here
 +
ENDIF.
 +
 +
CALL FUNCTION 'DEQUEUE_E_TABLE'
 +
EXPORTING
 +
*  MODE_RSTABLE      = 'E'
 +
  TABNAME            = 'T7RUSCHOOL'
 +
  VARKEY            = l_varkey
 +
*  X_TABNAME          = ' '
 +
*  X_VARKEY          = ' '
 +
*  _SCOPE            = '3'
 +
*  _SYNCHRON          = ' '
 +
*  _COLLECT          = ' '
 +
          .
 +
</nowiki>
 +
 +
===Log de Modificaciones===
 +
Trn. SCU3 - Reporte RSTBHIST : Evaluación de objetos Customizing y tablas grabados en log

Latest revision as of 21:01, 18 October 2024

Tablas

Eventos en SE11-->Utilidades-->Generador actualiz.tab.

Ver tabla TVIMF

Ejemplo Evento 01 - Antes de grabar los datos en la base de datos

FORM check_resolucion_ini.
  TYPES: BEGIN OF ty_data,    "campos de Mi tabla
           perca   TYPE zseg_ds67_1000-perca,
           nresini TYPE zseg_ds67_1000-nresini,
           nresfin TYPE zseg_ds67_1000-nresfin,
         END OF ty_data.

  DATA lt_data TYPE TABLE OF ty_data.
  DATA lt_data2 TYPE TABLE OF ty_data.
  DATA ls_data LIKE LINE OF lt_data.
  DATA ls_data2 LIKE LINE OF lt_data.

  DATA: fieldname1 TYPE fieldname VALUE 'PERCA'.
  DATA: fieldname2 TYPE fieldname VALUE 'NRESINI'.
  DATA: fieldname3 TYPE fieldname VALUE 'NRESFIN'.

  FIELD-SYMBOLS: <fs1> TYPE any.
  FIELD-SYMBOLS: <fs2> TYPE any.
  FIELD-SYMBOLS: <fs3> TYPE any.

  LOOP AT total.
    ASSIGN COMPONENT fieldname1 OF STRUCTURE <vim_total_struc> TO <fs1>.
    ASSIGN COMPONENT fieldname2 OF STRUCTURE <vim_total_struc> TO <fs2>.
    ASSIGN COMPONENT fieldname3 OF STRUCTURE <vim_total_struc> TO <fs3>.

    ls_data-perca   = <fs1>.
    ls_data-nresini = <fs2>.
    ls_data-nresfin = <fs3>.

    APPEND ls_data TO lt_data.

  ENDLOOP.

  SORT lt_data BY perca.
  DATA: l_string  TYPE string,
        l_string2 TYPE string.

* verificar Nr.Res.Fin >= Nr.Res.Ini
  LOOP AT lt_data INTO ls_data.
    IF ls_data-nresfin < ls_data-nresini and ls_data-nresfin is NOT INITIAL.
      l_string = |Para Período { ls_data-perca } Nr.Res.Fin { ls_data-nresfin } menor a|.
      MESSAGE e000(0k) WITH l_string 'Nr.Res.Ini' ls_data-nresini.
      vim_abort_saving = 'X'.
    ENDIF.
  ENDLOOP.
  CLEAR sy-subrc.

  lt_data2[] = lt_data[].

  SORT lt_data2 BY perca DESCENDING.
  SORT lt_data BY perca ASCENDING.

* verificar Nr.Res.Ini > Nr.Res.Fin de períodos anteriores
  LOOP AT lt_data INTO ls_data.
    LOOP AT lt_data2 INTO ls_data2 WHERE perca < ls_data-perca.
      if ls_data2-nresfin is INITIAL.
        ls_data2-nresfin = ls_data2-nresini.
      endif.

      IF ls_data-nresini <= ls_data2-nresfin.
        l_string = |Para Período { ls_data-perca } Nr.Res.Ini { ls_data-nresini } menor/igual a|.
        l_string2 = |Nr.Res.Fin { ls_data2-nresfin } de Período { ls_data2-perca }|.
        MESSAGE e000(0k) WITH l_string l_string2.
      ENDIF.
    ENDLOOP.
  ENDLOOP.


ENDFORM.

Ejemplo evento 05 - Al crear una entrada nueva

FORM check_resolucion_ini_new.

  TYPES:  BEGIN OF ty_total.
      INCLUDE STRUCTURE zseg_ds67_1000.  "Mi tabla
      INCLUDE STRUCTURE vimtbflags.
  TYPES:  END OF ty_total.

  TYPES: BEGIN OF ty_data,
           perca   TYPE zseg_ds67_1000-perca,
           nresini TYPE zseg_ds67_1000-nresini,
           nresfin TYPE zseg_ds67_1000-nresfin,
         END OF ty_data.

  DATA lt_data TYPE TABLE OF ty_data.
  DATA ls_data LIKE LINE OF lt_data.

  DATA: l_string TYPE string.
  DATA: l_string2 TYPE string.
  FIELD-SYMBOLS: <ls_data>  TYPE zseg_ds67_1000,
                 <ls_total> TYPE ty_total.

  ASSIGN <table1> TO <ls_data>.

  IF <ls_data>-nresfin < <ls_data>-nresini and <ls_data>-nresfin is NOT INITIAL.
    l_string = |Para Período { <ls_data>-perca } Nr.Res.Fin { <ls_data>-nresfin } menor a|.
    MESSAGE e000(0k) WITH l_string 'Nr.Res.Ini' <ls_data>-nresini.
  ENDIF.

  LOOP AT total ASSIGNING <ls_total> CASTING.
    MOVE-CORRESPONDING <ls_total> TO ls_data.
    APPEND ls_data TO lt_data.
  ENDLOOP.

  SORT lt_data BY perca DESCENDING.

  data l_res type ZSEG_DS67_1000-nresfin.

  LOOP AT lt_data INTO ls_data WHERE perca < <ls_data>-perca.
    if ls_data-nresfin is INITIAL.
      ls_data-nresfin = ls_data-nresini.
    endif.

    IF <ls_data>-nresini <= ls_data-nresfin.
      l_string = |Para Período { <ls_data>-perca } Nr.Res.Ini { <ls_data>-nresini } menor/igual a|.
      l_string2 = |Nr.Res.Fin { ls_data-nresfin } de Período { ls_data-perca }|.
      MESSAGE e000(0k) WITH l_string l_string2.
    ENDIF.
  ENDLOOP.

ENDFORM.

FORM check_new_entry.

  TYPES:  BEGIN OF ty_total_c_oc_prcdef.
      INCLUDE STRUCTURE z_my_table.
      INCLUDE STRUCTURE vimtbflags.
  TYPES:  END OF ty_total_c_oc_prcdef.

  DATA l_f TYPE abap_bool.

  FIELD-SYMBOLS: <ls_data>  TYPE z_my_table,
                 <ls_total> TYPE ty_total_c_oc_prcdef.

  ASSIGN <table1> TO <ls_data>.
  IF sy-subrc IS INITIAL AND <ls_data> IS ASSIGNED.
    LOOP AT total ASSIGNING <ls_total> CASTING.
* verificar si registro ya fue borrado
      IF <ls_total>-vim_action = geloescht
         AND <ls_total>-usernw = <ls_data>-usernw
         AND <ls_total>-rut = <ls_data>-rut.
        l_f = abap_true.
        EXIT.
      ENDIF.
    ENDLOOP.

    IF l_f = abap_false.
      SELECT  COUNT(*) FROM  z_my_table
             WHERE  usernw  = <ls_data>-usernw
             AND    rut     = <ls_data>-rut.
      IF sy-subrc = 0.
        MESSAGE e000(0k) WITH 'Entrada ya existe'.
      ENDIF.
    ENDIF.

    LOOP AT total ASSIGNING <ls_total> CASTING.
      IF <ls_total>-vim_action NE geloescht.
        IF <ls_total>-usernw = <ls_data>-usernw
          AND <ls_total>-rut = <ls_data>-rut.
          MESSAGE e000(0k) WITH 'Entrada ya existe'.
        ENDIF.
      ENDIF.
    ENDLOOP.

  ENDIF.

ENDFORM.

ejemplo evento AA - en lugar de la rutina estándar para cargar datos

FORM read_z_my_table.

  DATA lt_z_my_table TYPE TABLE OF z_my_table.
  DATA ra_user TYPE TABLE OF zbptaxnum_rango.

  REFRESH total.

  IMPORT ra_user FROM MEMORY ID 'Z_MY_TABLE'.

  SELECT * INTO TABLE lt_z_my_table FROM z_my_table WHERE usernw IN ra_user.
  IF sy-subrc = 0 AND lt_z_my_table[] IS NOT INITIAL.
    LOOP AT lt_z_my_table INTO DATA(wa).
*     append missing entry
      <vim_total_struc> = wa.
      APPEND total.
    ENDLOOP.
*   ensure correct sorting
    SORT total BY <vim_xtotal_key>.
  ENDIF.
ENDFORM. 

programa para actualizar tabla

DATA wa TYPE z_my_table.

*--------------------------------------------------------------------*
SELECT-OPTIONS: ra_user FOR wa-usernw.
*--------------------------------------------------------------------*

*--------------------------------------------------------------------*
START-OF-SELECTION.
*--------------------------------------------------------------------*
* ver eventos en mantenedor de tabla z_my_table (trn SE11)
EXPORT ra_user TO MEMORY ID 'Z_MY_TABLE'.

CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
  EXPORTING
    action                     = 'U'
    view_name                  = 'Z_MY_TABLE'
    no_warning_for_clientindep = 'X'
  EXCEPTIONS
    OTHERS                     = 15.

IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
         WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

Bloquear Tablas

data l_VARKEY TYPE  RSTABLE-VARKEY.

l_varkey = sy-mandt.

CALL FUNCTION 'ENQUEUE_E_TABLEE'
 EXPORTING
*   MODE_RSTABLE         = 'E'
   TABNAME              = 'T7RUSCHOOL'
   VARKEY               = l_varkey
*   X_TABNAME            = ' '
*   X_VARKEY             = ' '
*   _SCOPE               = '2'
*   _WAIT                = ' '
*   _COLLECT             = ' '
 EXCEPTIONS
   FOREIGN_LOCK         = 1
   SYSTEM_FAILURE       = 2
   OTHERS               = 3
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

CALL FUNCTION 'DEQUEUE_E_TABLE'
 EXPORTING
*   MODE_RSTABLE       = 'E'
   TABNAME            = 'T7RUSCHOOL'
   VARKEY             = l_varkey
*   X_TABNAME          = ' '
*   X_VARKEY           = ' '
*   _SCOPE             = '3'
*   _SYNCHRON          = ' '
*   _COLLECT           = ' '
          .

Log de Modificaciones

Trn. SCU3 - Reporte RSTBHIST : Evaluación de objetos Customizing y tablas grabados en log