*&--------------------------------------------------------------------*
*&      FORM LOESCHEN                                                 *
*&--------------------------------------------------------------------*
* Behandeln der Funktion 'DELE'                                       *
*---------------------------------------------------------------------*
FORM LOESCHEN.
  DATA: NUMBER_OF_IGN_ENTR TYPE I, KEY_SAFE type VIM_tabKEY,
        L_IGN_ENTR_EX(1) TYPE C.
  IF STATUS-ACTION NE AENDERN AND STATUS-ACTION NE HINZUFUEGEN.
    MESSAGE I001(SV).
    EXIT.
  ENDIF.
  IF STATUS-MODE EQ DETAIL_BILD.
*   IF STATUS-ACTION EQ HINZUFUEGEN AND <XACT> NE NEUER_EINTRAG.
    IF STATUS-ACTION EQ HINZUFUEGEN AND NEUER EQ 'J'.
      MOVE <INITIAL> TO <TABLE1>.
      IF X_HEADER-BASTAB NE SPACE AND X_HEADER-TEXTTBEXST NE SPACE.
        MOVE <TEXT_INITIAL> TO <TABLE1_TEXT>.
      ENDIF.
      MESSAGE S013(SV).
      CLEAR <STATUS>-UPD_FLAG.
      EXIT.
    ENDIF.
    MOVE <XMARK> TO DETA_MARK_SAFE.
    IF X_HEADER-DELMDTFLAG NE SPACE.
      PERFORM CHECK_IF_ENTRY_IS_TO_DISPLAY USING 'L' <VIM_xEXTRACT_KEY>
                                                 SPACE <VIM_BEGDATE>.
      NUMBER_OF_IGN_ENTR = SY-SUBRC.
      KEY_SAFE = <VIM_xEXTRACT_KEY>.
    ENDIF.
    IF X_HEADER-DELMDTFLAG EQ SPACE OR NUMBER_OF_IGN_ENTR LT 8.
      READ TABLE EXTRACT INDEX NEXTLINE.
    ELSE.
      MOVE KEY_SAFE TO <VIM_xEXTRACT_KEY>.
      READ TABLE TOTAL WITH KEY <VIM_xEXTRACT_KEY> BINARY SEARCH.
      EXTRACT = TOTAL.
    ENDIF.
  ENDIF.
  IF X_HEADER-FRM_BF_DEL NE SPACE.
    PERFORM (X_HEADER-FRM_BF_DEL) IN PROGRAM (SY-REPID).
  ENDIF.
  IF VIM_CALLED_BY_CLUSTER NE SPACE.
    PERFORM VIM_STORE_STATE_INFO.
    CALL FUNCTION 'VIEWCLUSTER_DELETE_DEPENDENT'
         EXPORTING
              VIEW_NAME         = X_HEADER-VIEWNAME
              STATUS_MODE       = STATUS-MODE
              WORKAREA          = EXTRACT
              NO_DIALOG         = VIM_EXTERNAL_MODE
         IMPORTING
              IGN_ENTRIES_EXIST = L_IGN_ENTR_EX.
    IF L_IGN_ENTR_EX NE SPACE.
      IGNORED_ENTRIES_EXIST = L_IGN_ENTR_EX.
    ENDIF.
  ENDIF.
  IF STATUS-MODE EQ LIST_BILD.
    PERFORM LISTE_LOESCHE.
  ELSE.
*   IF <STATUS>-DISPL_MODE EQ EXPANDED.
*     READ TABLE EXTRACT INDEX NEXTLINE.
*   ELSE.
*     READ TABLE TOTAL WITH KEY <F1> BINARY SEARCH.
*     EXTRACT = TOTAL.
*   ENDIF.
    IF <XMARK> NE UEBERGEHEN.
      PERFORM DELETE_CHECK_KEYRANGE.
      IF SY-SUBRC EQ 0.
        PERFORM DETAIL_LOESCHE.
      ELSE.
        COUNTER = 0.
      ENDIF.
    ELSE.
      COUNTER = 0.
    ENDIF.
  ENDIF.
  IF VIM_SPECIAL_MODE EQ VIM_UPGRADE AND COUNTER EQ 0.
    FUNCTION = OK_CODE = 'IGN '.
  ENDIF.
  IF X_HEADER-FRM_AF_DEL NE SPACE.
    PERFORM (X_HEADER-FRM_AF_DEL) IN PROGRAM (SY-REPID).
  ELSE.
    IF IGNORED_ENTRIES_EXIST NE SPACE.
      PERFORM MARK_IGNORED_ENTRIES CHANGING NUMBER_OF_IGN_ENTR.
      CHECK VIM_SPECIAL_MODE NE VIM_UPGRADE.
      IF NUMBER_OF_IGN_ENTR EQ 1.
        MESSAGE S115(SV). "Eintrag konnte nicht gelöscht werden
      ELSEIF NUMBER_OF_IGN_ENTR GT 1.
        MESSAGE S116(SV) WITH NUMBER_OF_IGN_ENTR.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM.                               " LOESCHEN
