*&--------------------------------------------------------------------*
*&      Form  AFTER_TEMPORAL_DELIMITATION                             *
*&--------------------------------------------------------------------*
* fill EXTRACT with new due to temporal delimitation entries          *
*---------------------------------------------------------------------*
*                                                                     *
*&--------------------------------------------------------------------*
FORM after_temporal_delimitation.
  LOCAL: extract, <table1>.
  DATA: index_safe TYPE i, rec TYPE i.
  LOOP AT vim_delim_entries WHERE index3 NE space.
    DELETE extract INDEX vim_delim_entries-index3.
    MOVE vim_delim_entries-index3 TO index_safe.
    IF vim_special_mode EQ vim_reset.
      SUBTRACT 1 FROM <status>-maxlines.
      IF <status>-st_mode EQ detail_bild AND
         <status>-cur_line GE vim_delim_entries-index3.
        SUBTRACT 1 FROM <status>-cur_line.
      ENDIF.
    ELSE.
      SUBTRACT 1 FROM maxlines.
    ENDIF.
    IF vim_delim_entries-index1 NE 0.
      CLEAR vim_delim_entries-index3.
      MODIFY vim_delim_entries.
    ENDIF.
    LOOP AT vim_delim_entries WHERE index2 GT index_safe
                                OR  index3 GT index_safe.
      IF vim_delim_entries-index2 GT index_safe.
        SUBTRACT 1 FROM vim_delim_entries-index2.
      ENDIF.
      IF vim_delim_entries-index3 GT index_safe.
        SUBTRACT 1 FROM vim_delim_entries-index3.
      ENDIF.
      MODIFY vim_delim_entries.
    ENDLOOP.
  ENDLOOP.
  CLEAR extract.
  LOOP AT vim_delim_entries WHERE index3 EQ space.
    READ TABLE total INDEX vim_delim_entries-index1.
    MOVE total TO extract.
    IF x_header-delmdtflag EQ 'E' AND <vim_begdate> LE sy-datum AND
       <vim_enddate> GE sy-datum OR x_header-delmdtflag EQ 'B' AND
       <vim_begdate> GE sy-datum AND <vim_enddate> LE sy-datum.
      rec = 8.
      LOOP AT vim_collapsed_mainkeys.
        check <vim_collapsed_mkey_bfx> EQ <vim_tot_mkey_beforex>.
*                WHERE mkey_bf EQ <vim_tot_mkey_before>.
        IF vim_mkey_after_exists NE space.
          CHECK <vim_collapsed_key_afx> EQ <vim_tot_mkey_afterx>.
*          CHECK <vim_collapsed_key_af> EQ <vim_tot_mkey_after>.
        ENDIF.
        READ TABLE extract WITH KEY <vim_collapsed_keyx>
*        READ TABLE extract WITH KEY <vim_collapsed_key>
                           TRANSPORTING NO FIELDS.
        IF sy-subrc EQ 0.
          MODIFY extract INDEX sy-tabix. CLEAR rec.
        ENDIF.
        IF <vim_collapsed_keyx> NE <vim_xtotal_key>.
*        IF vim_collapsed_mainkeys-mainkey NE <vim_total_key>.
          <vim_collapsed_keyx> = <vim_xtotal_key>.
*          vim_collapsed_mainkeys-mainkey = <vim_total_key>.
          <vim_collapsed_mkey_bfx> = <vim_tot_mkey_beforex>.
*          vim_collapsed_mainkeys-mkey_bf = <vim_tot_mkey_before>.
          MODIFY vim_collapsed_mainkeys.
        ENDIF.
        EXIT.
      ENDLOOP.
      CHECK rec NE 0.
    ELSE.
      PERFORM check_if_entry_is_to_display USING 'L' <vim_xtotal_key>
                                                 space <vim_begdate>.
      CHECK sy-subrc LT 8.
    ENDIF.
    INSERT extract INDEX vim_delim_entries-index2.
    ADD 1 TO maxlines.
    MOVE vim_delim_entries-index2 TO index_safe.
    LOOP AT vim_delim_entries WHERE index2 GE index_safe.
      IF vim_delim_entries-index2 EQ index_safe.
        CHECK vim_delim_entries-index_corr NE space.
      ENDIF.
      ADD 1 TO vim_delim_entries-index2.
      MODIFY vim_delim_entries.
    ENDLOOP.
  ENDLOOP.
  REFRESH vim_delim_entries.
ENDFORM.                               "after_temporal_delimitation.
