SAP ABAP DICTIONARY

From SapWiki

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 S000(0k) WITH l_string 'Nr.Res.Ini' ls_data-nresini display like 'E'.
      vim_abort_saving = 'X'.
      exit.
    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.

actualizar tabla vía rango

* Objetivo    : Actualizar vista V_T508A
*               Copiado de RPTDSH20
REPORT ZT508A.

* 3.1G
* XAYP30K127599 290197 SQL Fehler im dynamischen Select in Form
*                      GET_V_T550A_DATA innerhalb VIEW_MAINTENANCE_CALL
*                      durch neuen Funktionsbaustein behoben
* 3.0D
* XWIP30K051797 220296 Datumsaufberietung gemäß Benutzerfestwerte
*                      beim View_Maintenance_Call
* 3.0C
* XBSP30K036111 110196  Report neu erstellt

TABLES: T508A.

* entries  to be selected by view-m-call
DATA: BEGIN OF DBA_SELLIST OCCURS 1.
        INCLUDE STRUCTURE VIMSELLIST.

* functions to be excluded during view_maintenance
DATA: END OF DBA_SELLIST.
DATA: BEGIN OF EXCL_CUAFUNCT OCCURS 1.
        INCLUDE STRUCTURE VIMEXCLFUN.
DATA: END OF EXCL_CUAFUNCT.

*data: datum_vmc(10). "date for view_maintenance_call "XAYP30K127599

* selection-criteria
SELECTION-SCREEN BEGIN OF BLOCK SEL WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: SCHKZ FOR T508A-SCHKZ,
                mofid FOR T508A-mofid,
                mosid FOR T508A-mosid.
SELECTION-SCREEN END OF BLOCK SEL.

START-OF-SELECTION.
  EXCL_CUAFUNCT-FUNCTION = 'AEND'.
  APPEND EXCL_CUAFUNCT.
  PERFORM FILL_DBA_SELLIST.
  CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
       EXPORTING
            ACTION         = 'U'
            VIEW_NAME      = 'V_T508A'
            COMPLEX_SELCONDS_USED = 'X'                   "XAYP30K127599
       TABLES
            DBA_SELLIST    = DBA_SELLIST
            EXCL_CUA_FUNCT = EXCL_CUAFUNCT.
  CHECK SY-SUBRC EQ 0.

*---------------------------------------------------------------------*
*       FORM FILL_ARG_T550A                                           *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM FILL_DBA_SELLIST.
  CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST'                "XAYP30K127599
       EXPORTING                                          "XAYP30K127599
            FIELDNAME          = 'SCHKZ'                  "XAYP30K127599
       TABLES                                             "XAYP30K127599
            SELLIST            = dba_sellist              "XAYP30K127599
            RANGETAB           = SCHKZ                    "XAYP30K127599
       EXCEPTIONS                                         "XAYP30K127599
            OTHERS             = 1.                       "XAYP30K127599
  CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST'                "XAYP30K127599
       EXPORTING                                          "XAYP30K127599
            FIELDNAME          = 'MOFID'                  "XAYP30K127599
            APPEND_CONJUNCTION = 'AND'                    "XAYP30K127599
       TABLES                                             "XAYP30K127599
            SELLIST            = dba_sellist              "XAYP30K127599
            RANGETAB           = MOFID                    "XAYP30K127599
       EXCEPTIONS                                         "XAYP30K127599
            OTHERS             = 1.                       "XAYP30K127599

  CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST'                "XAYP30K127599
       EXPORTING                                          "XAYP30K127599
            FIELDNAME          = 'MOSID'                  "XAYP30K127599
            APPEND_CONJUNCTION = 'AND'                    "XAYP30K127599
       TABLES                                             "XAYP30K127599
            SELLIST            = dba_sellist              "XAYP30K127599
            RANGETAB           = MOSID                    "XAYP30K127599
       EXCEPTIONS                                         "XAYP30K127599
            OTHERS             = 1.                       "XAYP30K127599
ENDFORM.

*---------------------------------------------------------------------*
*       FORM SHOW_VALUES                                              *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  TPROG                                                         *
*---------------------------------------------------------------------*
FORM SHOW_VALUES USING TPROG.

  DATA: INDEX LIKE SY-INDEX.
  CALL FUNCTION 'HELP_VALUES_GET'
       EXPORTING
            FIELDNAME    = 'TPROG'
            TABNAME      = 'T550A'
       IMPORTING
            SELECT_VALUE = TPROG
            SELECT_INDEX = INDEX
       EXCEPTIONS
            OTHERS       = 1.

ENDFORM.


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