SAP ABAP DICTIONARY

From SapWiki
Revision as of 22:07, 31 August 2022 by WikiSysop (talk | contribs)

Tablas

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

Ver tabla TVIMF

Ejemplo Evento 01

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

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.

ejemplo evento AA

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.