*---------------------------------------------------------------------*
*    generated viewmaintenance function pool
*   generation date: 30.12.2012 at 22:57:55 by user CREYTZ
*   view maintenance generator version: #001407#
*---------------------------------------------------------------------*
*******************************************************************
*   System-defined Include-files.                                 *
*******************************************************************
*---------------------------------------------------------------------*
*    generated viewmaintenance function pool top
*   generation date: 30.12.2012 at 22:57:55 by user CREYTZ
*   view maintenance generator version: #001407#
*---------------------------------------------------------------------*
FUNCTION-POOL ZSOFTCOPY_DBM              MESSAGE-ID SV.

TABLES: e070, e071k, e071, tadir, dderr, tddat, objh.

TYPE-POOLS: cxtab, cmpwl, vimty, slctr, trwbo, scpr, slis, szadr.

CLASS: cl_abap_char_utilities DEFINITION LOAD.

* Adresspflege Übergangslösung anfang
TABLES: sadr, sadr2, sadr3, sadr4, sadr5.
DATA: sadr_keylen  TYPE i,             "key length of table SADR
      sadr_namtab_read TYPE c.                              "flag:

* Adresspflege Übergangslösung ende

DATA: maint_stat LIKE vimstatus.

FIELD-SYMBOLS: <vim_ctotal> TYPE ANY, <vim_cextract> TYPE ANY,
               <vim_xtotal> TYPE x, <vim_xextract> TYPE x,
               <vim_total_struc> TYPE ANY,
               <vim_extract_struc> TYPE ANY,
               <vim_tot_txt_struc> TYPE ANY,
               <vim_ext_txt_struc> TYPE ANY,
               <f1> TYPE ANY, <name> TYPE ANY, <table1> TYPE ANY,
               <table2> TYPE ANY, <orig_key> TYPE x,
               <client> TYPE ANY, <vim_total_key> TYPE ANY,
               <vim_extract_key> TYPE ANY,
               <vim_xtotal_key> TYPE x,
               <vim_xextract_key> TYPE x,
               <vim_client_initial> TYPE ANY.
* unicode
FIELD-SYMBOLS: <table1_x> TYPE x,
               <table2_x> TYPE x,
               <f1_x> TYPE x,
               <table1_wa> TYPE ANY,
               <table1_wax> TYPE x,
               <f1_wax> TYPE x,
               <vim_corr_keyx> TYPE x,
               <initial_x> TYPE x.
FIELD-SYMBOLS: <mark> TYPE ANY, <action> TYPE ANY,
               <xmark> TYPE ANY, <xact> TYPE ANY, <initial> TYPE ANY,
               <status> STRUCTURE vimstatus DEFAULT maint_stat,
               <address_number> TYPE ANY,
               <user_exit_field> TYPE ANY,
               <replace_field> TYPE ANY,
               <vim_begdate>     LIKE sy-datum,
               <vim_new_begdate> LIKE sy-datum,
               <vim_enddate>     LIKE sy-datum,
               <vim_enddate_mask> TYPE ANY,
               <vim_mainkey_mask> TYPE ANY,
               <vim_prtfky_wa> TYPE ANY, <vim_prtfky_extract> TYPE ANY,
               <vim_prtfky_total> TYPE ANY,
               <vim_begdate_mask> TYPE ANY,
               <vim_collapsed_keyx> TYPE x,
               <vim_collapsed_logkeyx> TYPE x,
               <vim_collapsed_key_afx> TYPE x,
               <vim_merged_keyx> TYPE x,
               <vim_total_address_number> TYPE ANY,
               <vim_addr_handle_x> TYPE x,
* Unicode
  <vim_h_mkey> TYPE x, <vim_h_old_mkey> TYPE x,
  <vim_h_coll_mkey> TYPE x, <vim_h_merged_key> TYPE x,
  <vim_h_coll_bfkey> TYPE x, <vim_h_coll_logkey> TYPE x,
  <vim_f1_beforex> TYPE x, <vim_f1_afterx> TYPE x,
  <vim_mkey_beforex> TYPE x, <vim_mkey_afterx> TYPE x,
  <vim_tot_mkey_beforex> TYPE x, <vim_tot_mkey_afterx> TYPE x,
  <vim_ext_mkey_beforex> TYPE x, <vim_ext_mkey_afterx> TYPE x,
  <vim_old_mkey_beforex> TYPE x, <vim_old_mkey_afterx> TYPE x,
  <vim_collapsed_mkey_bfx> TYPE x,
* for downward-compatibility only:
  <vim_f1_before>, <vim_f1_after>,
  <vim_mkey_before>, <vim_mkey_after>,
  <vim_tot_mkey_before>, <vim_tot_mkey_after>,
  <vim_ext_mkey_before>, <vim_ext_mkey_after>,
  <vim_old_mkey_before>, <vim_old_mkey_after>,
  <vim_collapsed_key_af>, <vim_collapsed_logkey>,
  <vim_merged_key>, <vim_collapsed_key>.
*
FIELD-SYMBOLS: <subsetfield> TYPE ANY, <rdonlyfield> TYPE ANY,
               <value> TYPE ANY,
               <state> STRUCTURE vimstatus DEFAULT maint_stat,
               <vim_tctrl> TYPE cxtab_control, <vim_sellist> TYPE table,
               <vim_ck_sellist> TYPE table, <vim_field_value> TYPE ANY,
               <vim_scrform_name> TYPE ANY,
               <vim_auth_sellist> TYPE table.
FIELD-SYMBOLS: <table1_text> TYPE ANY, <table1_xtext> TYPE x,
               <total_text> TYPE ANY, <extract_text> TYPE ANY,
               <vim_xtotal_text> TYPE x, <vim_xextract_text> TYPE x,
               <action_text> TYPE ANY,
               <xact_text> TYPE ANY,
               <extract_enti> TYPE ANY, <vim_xextract_enti> TYPE x,
               <textkey> TYPE ANY, <initial_textkey> TYPE ANY,
               <textkey_x> TYPE x, <initial_textkey_x> TYPE x,
               <text_initial> TYPE ANY, <text_initial_x> TYPE x,
               <vim_text_enddate> TYPE ANY.
FIELD-SYMBOLS: <vim_texttab> TYPE table,               "SW Texttransl ..
*                            Type VIM_TAB_US/ .. /VIM_TAB_UL
               <vim_read_langus> TYPE table. "SW Texttransl
*----------------------------------------------------------------------*
* Declaration of types                                                 *
*----------------------------------------------------------------------*
types: vim_ko200_tab_type type table of ko200.
TYPES: BEGIN OF state_vector,
         type(1)   TYPE c,             " E=Einstufig Z=Zweistufig
         action(1) TYPE c,             " S=Anz., U=Änd., A=Hinzuf., T=Tr
         mode(1)   TYPE c,             " L=Liste, D=Detail
         data(1)   TYPE c, " G=gesamt, X=Extract, D=Geloeschte
         mark(1)   TYPE c,             " M=Markiert,  =Nicht Markiert
         delete(1) TYPE c,             " D=Gelöscht,  =Nicht Gelöscht
         fill1(1)  TYPE c,             "filler, not used
         fill2(1)  TYPE c,                                  "     - " -
       END OF state_vector,
       vim_tabkey TYPE tabl4096,
       BEGIN OF vim_tabkey_c,
        line(255) TYPE c,
       END OF vim_tabkey_c,
       BEGIN OF vim_ck_selcond,
         field LIKE vimnamtab-bastabfld,
         operator(2) TYPE c,
         hk1(1) TYPE c,
         value LIKE vimsellist-value,
         hk2(1) TYPE c,
         and LIKE vimsellist-and_or,
       END OF vim_ck_selcond,
       vimexclfldtab TYPE STANDARD TABLE OF vimexclfld
                          WITH DEFAULT KEY  INITIAL SIZE 10,
       BEGIN OF vimexclfldtabsline,
         viewname LIKE tvdir-tabname,
         excl_pos_tab TYPE vimexclfldtab,
         excl_rpl_tab TYPE vimexclfldtab,
         excl_que_tab TYPE vimexclfldtab,
       END OF vimexclfldtabsline,
       vimexclfldtabs TYPE SORTED TABLE OF vimexclfldtabsline
                           WITH UNIQUE KEY viewname,
       BEGIN OF vim_delim_entr_tl, "indizes of delim. entries
         index1 TYPE i,            "entries with mainkey in total
         index2 TYPE i,
         index3 TYPE i,            "current entry in extract in
                                   "collapsed mode
         index_corr(1) TYPE c,
       END OF vim_delim_entr_tl,
       BEGIN OF vim_collapsed_mkeys_tl,"collapsed mainkeys
         mkey_bf TYPE vim_tabkey_c,
         mainkey TYPE vim_tabkey_c,
         log_key TYPE vim_tabkey_c,
       END OF vim_collapsed_mkeys_tl,
       BEGIN OF vim_merged_entr_tl,    "merged entries
         new_key TYPE vim_tabkey,
         merged_key TYPE vim_tabkey,
         new_begdate TYPE d,
         new_enddate TYPE d,
         merged_begdate TYPE d,
         merged_enddate TYPE d,
       END OF vim_merged_entr_tl,
       BEGIN OF vim_ale_keyspec_objs,
         oname LIKE objh-objectname,
         otype LIKE objh-objecttype,
       END OF vim_ale_keyspec_objs,
       vim_flds_tab_type TYPE TABLE OF fieldname,           "fieldlist
       vimnamtab_type type table of vimnamtab.

* Definitionen für Texterfassung in mehreren Sprachen  "SW Texttransl ..
CONSTANTS:
      ultra_short_tab TYPE i VALUE 32,
      very_short_tab TYPE i VALUE 48,
      short_tab TYPE i VALUE 64,
      middle_tab TYPE i VALUE 128,
      long_tab TYPE i VALUE 256,
      very_long_tab TYPE i VALUE 512,
      ultra_long_tab TYPE i VALUE 4096,
      vim_max_keylen_show TYPE i VALUE 120,
      vim_max_textfields TYPE i VALUE 8,   "Anzahl Textfelder auf D0100
      vim_max_keyfields TYPE i VALUE 10.   "  "    Keyfelder   "     "

TYPES: vim_line_ul(ultra_long_tab)  TYPE c,
       vim_line_vl(very_long_tab)   TYPE c,
       vim_line_l(long_tab)         TYPE c,
       vim_line_m(middle_tab)       TYPE c,
       vim_line_s(short_tab)        TYPE c,
       vim_line_vs(very_short_tab)  TYPE c,
       vim_line_us(ultra_short_tab) TYPE c,

       vim_tab_ul  TYPE vim_line_ul OCCURS 0,
       vim_tab_vl  TYPE vim_line_vl OCCURS 0,
       vim_tab_l   TYPE vim_line_l OCCURS 0,
       vim_tab_m   TYPE vim_line_m OCCURS 0,
       vim_tab_s   TYPE vim_line_s OCCURS 0,
       vim_tab_vs  TYPE vim_line_vs OCCURS 0,
       vim_tab_us  TYPE vim_line_us OCCURS 0.

TYPES: BEGIN OF vim_variable_tab,
         valid_idx LIKE sy-index,      " Index der gefüllten Tabelle
         tab_us TYPE vim_tab_us,       " falls benutzt -> valid_idx = 2
         tab_vs TYPE vim_tab_vs,       "     "                "     = 3
         tab_s  TYPE vim_tab_s,
         tab_m  TYPE vim_tab_m,
         tab_l  TYPE vim_tab_l,
         tab_vl TYPE vim_tab_vl,
         tab_ul TYPE vim_tab_ul,
        END OF vim_variable_tab.

TYPES: BEGIN OF vim_tabdata_record,
         viewname   LIKE tvdir-tabname,
         sel_langus LIKE t002-spras OCCURS 0,
         all_langus(1) TYPE c,
         tabdata    TYPE vim_variable_tab,
       END OF vim_tabdata_record.
* lok. Hilfsvariable für Absprung in Langtextpflege über User-Exit
DATA: vim_internal_ltext_call(1) TYPE c.              ".. SW Texttransl

*----------------------------------------------------------------------*
* Declaration of constants                                             *
*----------------------------------------------------------------------*
CONSTANTS:
      read(4) TYPE c VALUE 'READ',
      edit(4) TYPE c VALUE 'EDIT',
      read_and_edit(4) TYPE c VALUE 'RDED',
      vim_read_text(4) TYPE c VALUE 'RTXT',                 "SW Textimp
        " FCODE: Einlesen + zusätzl. Lesen der Texttab in allen Sprachen
      save(4) TYPE c VALUE 'SAVE',
      reset_list(4) TYPE c VALUE 'ORGL',
      reset_entry(4) TYPE c VALUE 'ORGD',
      switch_to_show_mode(4) TYPE c VALUE 'ANZG',
      switch_to_update_mode(4) TYPE c VALUE 'AEND',
      switch_transp_to_upd_mode(4) TYPE c VALUE 'TRAE',
      get_another_view(4) TYPE c VALUE 'ATAB',
      back(4) TYPE c VALUE 'BACK',
      end(4) TYPE c VALUE 'ENDE',
      canc(4) TYPE c VALUE 'ABR ',
      transport(4) VALUE 'TRSP',
      subset(1) TYPE c VALUE 'S',
      authority type sychar01 value 'A',
      ddic_marks(2)   TYPE c VALUE 'XB', "ddic marks for ddic-flag
      vim_subset_marks(2) TYPE c VALUE 'SB', "subset marks for ddic-flag
      vim_subset_marks_mult(4) TYPE c VALUE 'SBMA', "including authority
                                                            "and mult
      rdonly(1) TYPE c VALUE 'R',
      vim_hidden(1) TYPE c VALUE 'H',
      adrnbr(1) TYPE c VALUE 'A',
      usrexi(1) TYPE c VALUE 'X',
      client_length LIKE sy-fdpos VALUE '3', "in characters
      vim_datum_length LIKE sy-fdpos VALUE '8',
      vim_spras_length LIKE sy-fdpos VALUE '1',
      fname_length  TYPE i VALUE '30', "max. fieldname length
      compl_form_offs LIKE sy-fdpos VALUE '6',
      corr_form_offs LIKE sy-fdpos VALUE '11',
      transporter LIKE tadir-pgmid VALUE 'R3TR', "name of transport pgm
      transp_object LIKE tadir-object VALUE 'TABU', "object to transport
      vim_view_type LIKE e071k-mastertype VALUE 'VDAT',
      vim_clus_type LIKE e071k-mastertype VALUE 'CDAT',
      vim_tran_type LIKE e071k-mastertype VALUE 'TDAT',
      vim_deleted_key LIKE tadir-pgmid VALUE '(DL)',
      vim_unlockable_object LIKE e071k-mastertype VALUE '(UO)',
      vim_lockable_object LIKE e071k-mastertype VALUE '(LO)',
      vim_long_objname LIKE e071k-objname VALUE '(?TABKEY?)',
      vim_71k_name_length TYPE i VALUE '30',
      vim_transport_denied(1) TYPE c VALUE 'V',
      sortflag_with_existency LIKE e071k-sortflag VALUE '2',
      sortflag_without_existency LIKE e071k-sortflag VALUE '3',
      e071_objfunc LIKE e071-objfunc VALUE 'K',
      state_vect_prefix(7) TYPE c VALUE 'STATUS_',
      state_vect_prefix_length TYPE i VALUE '7',
      sap_cust_classes(2) TYPE c VALUE 'EG',    "tabclasses to check
      sap_only_classes(1) TYPE c VALUE 'S',                 "      -"-
      sap_cust_ctrl_classes(1) TYPE c VALUE 'E',            "      -"-
      no_transport_classes(1) TYPE c VALUE 'L',             "       -"-
      no_transport_log_classes(1) TYPE c VALUE 'W',"   -"-
      application_delivery_classes(1) TYPE c VALUE 'A',
      customizing_delivery_classes(3) TYPE c VALUE 'CEG',
      nbrd_texts_prefix(10) TYPE c VALUE 'SVIM_TEXT_',
      nbrd_texts_prefix_length TYPE i VALUE '10',
      master_fpool(8) TYPE c VALUE 'SAPLSVIM',
      vim_position_info_len TYPE i VALUE '30', "length of dynpro field
      vim_position_info_lg1 TYPE i VALUE '13', "length of 'Eintrag'
      vim_position_info_lg2 TYPE i VALUE '6',  "length of 'von'
      vim_position_info_lg3 TYPE i VALUE '10', "max length of entry nbr.
      vim_reset(1) TYPE c VALUE 'O',
      vim_replace(1) TYPE c VALUE 'R',
      vim_upgrade(1) TYPE c VALUE 'U',
      vim_direct_upgrade(1) TYPE c VALUE 'C',
      vim_undelete(1) TYPE c VALUE 'D',
      vim_delimit(1) TYPE c VALUE 'G',
      vim_delete(1) TYPE c VALUE 'L',
      vim_extedit(1) TYPE c VALUE 'E',
      vim_import(1) TYPE c VALUE 'I',
      vim_import_no_dialog TYPE c VALUE 'D',
      vim_import_with_dialog TYPE c VALUE 'H',
      vim_time_dep_dpl_modif_form(30) TYPE c
                                  VALUE 'TIME_DEPENDENT_DISPLAY_MODIF',
      vim_view(1) TYPE c VALUE 'V',    "OBJH-type for views
      vim_tabl(1) TYPE c VALUE 'S',    "OBJH-type for tables
      vim_clst(1) TYPE c VALUE 'C',    "OBJH-type for clusters
      vim_tran(1) TYPE c VALUE 'T',    "OBJH-type for transact.
      vim_logo(1) TYPE c VALUE 'L',    "OBJH-type for TLOGO-obj.
      vim_cust(4) TYPE c VALUE 'CUST', "OBJ-category CUST
      vim_syst(4) TYPE c VALUE 'SYST', "OBJ-category SYST
      vim_cust_syst(4) TYPE c VALUE 'CUSY',    "OBJ-category CUSY
      vim_appl(4) TYPE c VALUE 'APPL', "OBJ-category APPL
      vim_noact(1) TYPE c VALUE 'N',   "client state: no action
      vim_log(1)   TYPE c VALUE '1',   "client state: log chngs.
      vim_locked(1) TYPE c VALUE '2',  "client state: no chngs.
      vim_local_clnt(1) TYPE c VALUE '3',      "client state: no transp.
      vim_nocliindep_cust(1) TYPE c VALUE '1', "client state: ....
      vim_noreposichanges(1) TYPE c VALUE '2', "client state: ....
      vim_noreposiandcust(1) TYPE c VALUE '3', "client state: ....
      vim_frm_text_upd_flag(19) TYPE c VALUE 'SET_TXT_UPDATE_FLAG',
      vim_frm_fill_textkey(19) TYPE c VALUE 'FILL_TEXTTAB_KEY_UC',
*      vim_frm_fill_textkey(16) TYPE c VALUE 'FILL_TEXTTAB_KEY',
      vim_max_trsp_keylength TYPE i VALUE '120',
      vim_max_trsp_identical_key TYPE i VALUE '119',
      vim_char_inttypes(5) TYPE c VALUE 'CDNST', "char types for transp.
      vim_not_importable type objimp value '1'.

CONSTANTS:
* Type
  einstufig(1)       TYPE c VALUE 'E',
  zweistufig(1)      TYPE c VALUE 'Z',
* Action
  anzeigen(1)        TYPE c VALUE 'S',
  aendern(1)         TYPE c VALUE 'U',
  vim_ds_loeschen(1) TYPE c VALUE 'D',             "MF BCSet-DS loeschen
  hinzufuegen(1)     TYPE c VALUE 'A',
  kopieren(1)        TYPE c VALUE 'C',
  profil_hinzufuegen TYPE c VALUE 'R',                      "UFprofile
  transportieren(1)  TYPE c VALUE 'T',
  pruefen(1)         TYPE c VALUE 'P',
  zurueckholen(1)    TYPE c VALUE 'Z',
  task_add(1)        TYPE c VALUE 'E',
  task_del(1)        TYPE c VALUE 'F',
* Data
  gesamtdaten(1)     TYPE c VALUE 'G',
  auswahldaten(1)    TYPE c VALUE 'X',
* Mark
  markiert(1)        TYPE c VALUE 'M',
  nicht_markiert(1)  TYPE c VALUE ' ',
* Mode
  detail_bild(1)     TYPE c VALUE 'D',
  list_bild(1)       TYPE c VALUE 'L',
* Delete
  geloescht(1)       TYPE c VALUE 'D',
  nicht_geloescht(1) TYPE c VALUE ' ',
* selected
  by_field_contents(1) TYPE c VALUE 'I',
* time dependent objects: display mode
  expanded(1)          TYPE c VALUE ' ',
  collapsed(1)         TYPE c VALUE 'C',
  collapsed_displd(1)  TYPE c VALUE 'D',
* others
  update_geloescht(1) TYPE c VALUE 'Y',
  neuer_geloescht(1)  TYPE c VALUE 'X',
  dummy_geloescht(1)  TYPE c VALUE 'Z',
  neuer_eintrag(1)    TYPE c VALUE 'N',
  uebergehen(1)       TYPE c VALUE '*',
  leer(1)             TYPE c VALUE 'L',
  original(1)         TYPE c VALUE ' ',
  bcset_only(1)       TYPE c VALUE 'B'.      "Show only data from bcset

CONSTANTS: vim_scrform_domain LIKE dd03p-domname VALUE 'TDFORM',
           vim_delim_date_domain LIKE dd03p-domname VALUE 'DATUM',
           vim_begdate_dtel1 LIKE dd03p-rollname VALUE 'BEGDATUM',
           vim_begdate_dtel2 LIKE dd03p-rollname VALUE 'BEGDA',
           vim_begdate_dtel3 LIKE dd03p-rollname VALUE 'ISH_BEGDT',
           vim_begdate_dtel4 LIKE dd03p-rollname VALUE 'VIM_BEGDA',
           vim_enddate_dtel1 LIKE dd03p-rollname VALUE 'ENDDATUM',
           vim_enddate_dtel2 LIKE dd03p-rollname VALUE 'ENDDA',
           vim_enddate_dtel3 LIKE dd03p-rollname VALUE 'ISH_ENDDT',
           vim_enddate_dtel4 LIKE dd03p-rollname VALUE 'VIM_ENDDA',
           BEGIN OF vim_adrnbr_domains,
             dom1 LIKE dd03p-domname VALUE 'ADRNR',
             dom2 LIKE dd03p-domname VALUE 'CADRNR',
             dom3 LIKE dd03p-domname VALUE 'AD_ADDRNUM',
           END OF vim_adrnbr_domains,
           vim_addr_e071k_master TYPE sobj_name VALUE 'ADDRESS',
                                                "UF688403/2000
           vim_addr_e071k_master_46 TYPE sobj_name VALUE 'ADDRESS_4.6'.
"UF688403/2000


CONSTANTS: vim_sbscr_prog LIKE d020s-prog VALUE 'SAPLSVCM',
           vim_sbscr_dnum LIKE d020s-dnum VALUE '0101',
           vim_locked_in_corr LIKE vimstatus-corr_nbr VALUE 'LOCKED',
           vim_dummy_mainkey TYPE c VALUE 'K',
           vim_no_mkey_not_procsd(1) TYPE c VALUE 'X',
           vim_no_mkey_procsd_patt(2) TYPE c VALUE 'XY',
           vim_no_mkey_not_procsd_patt(2) TYPE c VALUE 'YX',
           vim_source_entry(1) TYPE c VALUE 'O',
           vim_clidep(1) TYPE x VALUE '02',
           vim_auth_initial_check(1) TYPE c VALUE 'I',
           vim_auth_switch_to_update_mode(1) TYPE c VALUE 'U',
           vim_auth_requested_check(1) TYPE c VALUE 'R'.

CONSTANTS: vim_tb_read_single_form(23) TYPE c
                                  VALUE 'TABLE_READ_SINGLE_ENTRY'.
DATA:      compl_formname(30) TYPE c VALUE 'COMPL_',
           corr_formname(30) TYPE c VALUE 'CORR_MAINT_',
           BEGIN OF vim_read_single_form,
            prefix(18) TYPE c VALUE 'READ_SINGLE_ENTRY_',
            viewname LIKE tvdir-tabname,
           END OF vim_read_single_form,
           BEGIN OF vim_read_single_form_40,
            prefix(12) TYPE c VALUE 'READ_SINGLE_',
            viewname LIKE tvdir-tabname,
           END OF vim_read_single_form_40.

* state fields
DATA: status TYPE state_vector,
* BEGIN OF STATUS,
*   TYPE(1)   TYPE C VALUE '2',        " E=Einstufig Z=Zweistufig
*   ACTION(1) TYPE C VALUE 'U',   " S=Anz., U=Änd., A=Hinzuf.,T=Tr
*   MODE(1)   TYPE C VALUE 'L',   " L=Liste, D=Detail
*   DATA(1)   TYPE C VALUE 'G',   " G=gesamt, X=Extract, D=Geloeschte
*   MARK(1)   TYPE C VALUE ' ',        " M=Markiert,  =Nicht Markiert
*   DELETE(1) TYPE C VALUE ' ',        " D=Gelöscht,  =Nicht Gelöscht
*   FILL1(1)  TYPE C VALUE ' ',        "filler, not used
*   FILL2(1)  TYPE C VALUE ' ',        "     - " -
* END OF STATUS,

  BEGIN OF title,
   action(1) TYPE c VALUE 'U',    " S=Anzeigen, U=Ändern, H=Hinzufügen
   mode(1)   TYPE c VALUE 'L',         " L=Liste, D=Detail
   data(1)   TYPE c VALUE 'G',    " G=Gesamt, X=Extrakt, D=Geloeschte
  END OF title.

* data containers and description
************************************************************************
DATA:  vim_for_alignment_only TYPE f,   "never remove!!!
       vim_view_wax TYPE tabl8000,
       vim_ctabkeylen TYPE sy-fleng.    "key length in characters

* other fields
DATA:
  vim_ale_keyspec_check(1) TYPE c,     "Flag: .......
  vim_ale_keyspec_objtab TYPE vim_ale_keyspec_objs OCCURS 1
                              WITH HEADER LINE,
  vim_delim_expa_excluded(1) TYPE c,   "Flag: .....
  vim_auth_event(1) TYPE c,
  vim_auth_action(1) TYPE c,
  vim_auth_rc LIKE sy-subrc, "0-ok, 4-show only, 8-no_authority->exit
  vim_auth_msgid LIKE sy-msgid,
  vim_auth_msgno LIKE sy-msgno,
  vim_auth_msgv1 LIKE sy-msgv1,
  vim_auth_msgv2 LIKE sy-msgv2,
  vim_auth_msgv3 LIKE sy-msgv3,
  vim_auth_msgv4 LIKE sy-msgv4,
  vim_no_warning_for_cliindep(1) TYPE c, "Flag: ......
  vim_begdate_is_ro(1) TYPE c, "Flag: nokey-datefield is readonly
  vim_addr_field_selection LIKE addr1_fsel-fisel, "for ADDR_DIALOG_PREPA
  vim_addr_keywords LIKE addr1_keyw,   "  - " -
  vim_addr_titlebar LIKE sy-title,     "  - " -
  vim_addr_chng_deflt_comm_types LIKE addr_comm,  "  - " -
  vim_addr_frame_text LIKE addr_frame, "  - " -
  vim_addr_excluded_functions LIKE vimexclfun     "  - " -
                              OCCURS 0 WITH HEADER LINE,
  vim_upgr_address_number LIKE addr1_sel-addrnumber,
  vim_skip_adr_maint TYPE xfeld,                            "UF120400
  vim_texttab_is_ro(1) TYPE c,
  vim_system_type(10) TYPE c,          "SAP/CUSTOMER
  vim_nbr_of_scrfrm_pointers TYPE i,
  vim_enq_s_u_rc LIKE sy-subrc,
  vim_addr_e071k_tab LIKE TABLE OF e071k INITIAL SIZE 0,
  vim_addr_e071_tab LIKE TABLE OF e071 INITIAL SIZE 0,
  vim_tsadrv LIKE tsadrv,              "Addresses: TSADRV-entry
  vim_addr_group LIKE tsadrv-addr_group,
  vim_addr_basetable LIKE dd03l-tabname,
  vim_addr_bastab_field LIKE dd03l-fieldname,
  vim_show_consistency_alert(1) TYPE c VALUE 'X',
  vim_import_testmode(1) TYPE c,
  vim_import_forcemode(1) TYPE c,
  vim_import_profile(1) TYPE c,        "Profilimport
  vim_profile_errorkey LIKE SCPRACPR-TABLEKEY,
  vim_abort_saving(1) TYPE c,          " 'X' -> Sichern abbrechen
  vim_import_no_message(1) TYPE c,
  vim_single_entry_function TYPE vimty_tcode,
  vim_single_entry_ins_key_input LIKE tvdir-flag,
  vim_import_mode_active(1) TYPE c,
  vim_last_logged_message TYPE vimty_message,
  vim_copy_call_level TYPE i,
  vim_nr_entries_to_copy TYPE i,       "SW 510129/1999
  vim_no_dialog(1) TYPE c,             "flag:......
  vim_modify_screen(1) TYPE c,         "Modul-lokales Flag
  vim_object LIKE vimdesc-viewname,
  vim_objfield LIKE vimnamtab-viewfield,
  vim_results_of_ext_mod LIKE vimmodres,
  vim_called_by_cluster(1) TYPE c,
  vim_calling_cluster TYPE vcl_name,
  vim_enqueue_range(1) TYPE c,
  vim_view_name LIKE vimdesc-viewname,
  replace_mode(1) TYPE c,
  vim_restore_mode(1) TYPE c,
  vim_external_mode(1) TYPE c,
  vim_extcopy_mode(1) TYPE c,
  vim_special_mode(1) TYPE c,          "O-reset,R-replace,U-upgrade
  vim_special_adjust_mode(1) TYPE c,
  vim_adjust_middle_level_mode(1) TYPE c,
  maint_mode TYPE c,
  update_flag(1) TYPE c VALUE ' ',
  adrnbr_roflag(1) TYPE c VALUE ' ',
  block_sw    TYPE c VALUE ' ',
  block_1     LIKE sy-tabix,
  block_2     LIKE sy-tabix,
  liste       LIKE d020s-dnum,
  detail      LIKE d020s-dnum,
  returncode  LIKE ocus-returncode,
  viewtitle   LIKE ocus-tabtitle,
  tablen      LIKE ocus-tablen,
  keylen      LIKE ocus-keylen,
  anzahl      TYPE i,
  answer(1)   TYPE c,
  neuer(1)    TYPE c VALUE 'N',
  ok_code     LIKE sy-ucomm,           "(4) type c,    SW, wg Controls
  function    LIKE sy-ucomm,           "(4) type c,
  relation(2) TYPE c VALUE 'EQ',
  counter LIKE sy-fdpos,
  mark_extract TYPE i,
  mark_total   TYPE i,
  l LIKE sy-tabix,
  o TYPE i,
  pos TYPE i,
  refcnt TYPE i,
  newcnt TYPE i,
  orgcnt TYPE i,
  last_view_info LIKE dd02v-tabname,
  vim_last_objh_view LIKE dd02v-tabname,
  vim_act_dynp_view LIKE dd02v-tabname,
  vim_ale_edit_lock(1) TYPE c,                              "flag:.....
  vim_ale_msgid LIKE sy-msgid,
  vim_ale_msgno LIKE sy-msgno,
  vim_ale_msgv1 LIKE sy-msgv1,
  vim_ale_msgv2 LIKE sy-msgv2,
  vim_ale_msgv3 LIKE sy-msgv3,
  vim_ale_msgv4 LIKE sy-msgv4,
  last_corr_number LIKE e070-trkorr,
  fill_extr_first_proc TYPE c,       "flag: Fill_extract first time proc
* F(30) TYPE C,  "4.0 name extension "max. Länge ABAP-Feldnamen: 30 Zchn
  f LIKE d021s-fnam,
* SUBSETID_RECEIVED TYPE C,          "flag: subset ID already received
  e071k_tab_modified TYPE c,                                "flag:
  sel_field_for_replace(30) TYPE c,    "field selected for replace
  sel_field_for_replace_l(30) TYPE c,  "field selected for replace long
* CORR_NBR LIKE TADIR-KORRNUM,       "current corr.nbr
  corr_nbr LIKE e070-trkorr,           "current corr.nbr
  master_type LIKE tadir-object VALUE 'TABU', "master object to transp.
  master_name LIKE tadir-obj_name,     "name of object to transport
  vim_client_state LIKE t000-cccoractiv, " state of client for transport
  get_corr_keytab(1) TYPE c,           "Flag: keytab is to read
  last_ext_modif_view LIKE tvdir-tabname,                   "flag:
  deta_mark_safe(1) TYPE c,
  ignored_entries_exist(1) TYPE c,                          "flag:
  corr_action(1) TYPE c,             "current action for UPDATE_CORR_KEY
  replace_texttable_field(1) TYPE c, "flag: replace function for textfld
  nbrd_texts_alr_read(1) TYPE c,     "flag: texts from SVIM already read
  svim_text_001(35) TYPE c,            "numbered text of SVIM
  svim_text_002(35) TYPE c,            "numbered text of SVIM
  svim_text_003(35) TYPE c,            "numbered text of SVIM
  svim_text_004(35) TYPE c,            "numbered text of SVIM
  svim_text_005(35) TYPE c,            "numbered text of SVIM
  svim_text_006(35) TYPE c,            "numbered text of SVIM
  svim_text_007(35) TYPE c,            "numbered text of SVIM
  svim_text_008(35) TYPE c,            "numbered text of SVIM
  svim_text_009(35) TYPE c,            "numbered text of SVIM
  svim_text_010(35) TYPE c,            "numbered text of SVIM
  svim_text_011(35) TYPE c,            "numbered text of SVIM
  svim_text_012(35) TYPE c,            "numbered text of SVIM
  svim_text_013(35) TYPE c,            "numbered text of SVIM
  svim_text_014(35) TYPE c,            "numbered text of SVIM
  svim_text_015(35) TYPE c,            "numbered text of SVIM
  svim_text_016(35) TYPE c,            "numbered text of SVIM
  svim_text_017(35) TYPE c,            "numbered text of SVIM
  svim_text_018(35) TYPE c,            "numbered text of SVIM
  svim_text_019(35) TYPE c,            "numbered text of SVIM
  svim_text_020(35) TYPE c,            "numbered text of SVIM
  svim_text_021(35) TYPE c,            "numbered text of SVIM
  svim_text_022(35) TYPE c,            "numbered text of SVIM
  svim_text_023(35) TYPE c,            "numbered text of SVIM
  svim_text_024(35) TYPE c,            "numbered text of SVIM
  svim_text_025(35) TYPE c,            "numbered text of SVIM
  svim_text_026(35) TYPE c,            "numbered text of SVIM
  svim_text_027(13) TYPE c,            "numbered text of SVIM
  svim_text_028(06) TYPE c,            "numbered text of SVIM
  svim_text_029(20) TYPE c,            "numbered text of SVIM
  svim_text_030(35) TYPE c,            "numbered text of SVIM
  svim_text_031(35) TYPE c,            "numbered text of SVIM
  svim_text_032(35) TYPE c,            "numbered text of SVIM
  svim_text_033(35) TYPE c,            "numbered text of SVIM
  svim_text_034(35) TYPE c,            "numbered text of SVIM
  svim_text_035(35) TYPE c,            "numbered text of SVIM
  svim_text_036(35) TYPE c,            "numbered text of SVIM
  svim_text_037(35) TYPE c,            "numbered text of SVIM
  svim_text_038(35) TYPE c,            "numbered text of SVIM
  svim_text_039(35) TYPE c,            "numbered text of SVIM
  svim_text_040(35) TYPE c,            "numbered text of SVIM
  svim_text_041(20) TYPE c,            "numbered text of SVIM
  svim_text_042(20) TYPE c,            "numbered text of SVIM
  svim_text_043(40) TYPE c,            "numbered text of SVIM
  svim_text_044(40) TYPE c,            "numbered text of SVIM
  svim_text_045(20) TYPE c,            "numbered text of SVIM
  svim_text_046(20) TYPE c,            "numbered text of SVIM
  svim_text_104(19) TYPE c,            "numbered text of SVIM
  svim_text_p01(20) TYPE c,            "numbered text of SVIM
  svim_text_p02(20) TYPE c,            "numbered text of SVIM
  svim_text_p03(20) TYPE c,            "numbered text of SVIM
  svim_text_prb(40) TYPE c,            "numbered text of SVIM
  svim_text_prc(40) TYPE c,            "numbered text of SVIM
  svim_text_pre(40) TYPE c,            "numbered text of SVIM
  svim_text_prf(70) TYPE c,            "numbered text of SVIM
  svim_text_prg(70) TYPE c,            "numbered text of SVIM
  svim_text_pri(40) TYPE c,            "numbered text of SVIM
  svim_text_prj(40) TYPE c,            "numbered text of SVIM
  vim_marked(1) TYPE c,                "mark-checkbox field
  vim_frame_field LIKE dd25v-ddtext, "name of frame (subset fields only)
  vim_position_info(42) TYPE c,        "field for 'entry x of y'
  vim_position_info_mask(42) TYPE c, "mask for field for 'entry x of y'
  vim_fpool_name LIKE trdir-name,
  vim_posi_push(25) TYPE c,          "push button to posit on list scrn
  temporal_delimitation_happened TYPE c,                    "flag: ....
  vim_mkey_after_exists(1) TYPE c,                          "flag: ....
  vim_no_mainkey_exists(1) TYPE c,                          "flag: ....
  nbr_of_added_dummy_entries TYPE i,   "for function NEWL: ...
  vim_next_screen LIKE tvdir-liste,    "next screen number
  vim_leave_screen(1) TYPE c,          "flag: leave screen necessary
  vim_prtfky_assigned(1) TYPE c,                            "flag...
* VIM_EXTRACT_MODIFIED(1) TYPE C,    "flag...
  vim_temp_delim_alr_checked(1) TYPE c,                     "flag...
  vim_ignore_collapsed_mainkeys(1) TYPE c,                  "flag...
  vim_corr_obj_viewname LIKE tvdir-tabname,
  vim_last_source_system LIKE tadir-srcsystem,
  vim_slct_functiontext(20) TYPE c,
  vim_comp_menue_text(20) TYPE c,
  vim_key_alr_checked(1) TYPE c,       "flag: .....
  vim_keyrange_alr_checked(1) TYPE c,  "flag: .....
  vim_prt_fky_flds_updated(1) TYPE c,  "flag: .....
  vim_exit_11_12_active(1) TYPE c,     "flag: .....
  BEGIN OF vim_default_rfc_dest,       "global vector for default
    viewname LIKE tvdir-tabname,       "RFC-destination
    rfcdest LIKE rfcdes-rfcdest,
  END OF vim_default_rfc_dest,
  BEGIN OF vim_default_upgr_clnt,      "global vector for default
    viewname LIKE tvdir-tabname,       "client for upgrade
    client LIKE sy-mandt,
  END OF vim_default_upgr_clnt,
  vim_title_name LIKE vimdesc-ddtext,
  vim_tabctrl_active(1) TYPE c,
  vim_tc_cols TYPE cxtab_column,
  vim_local_char1(1) TYPE c.           "Modul-lok. Hilfsvariable

* data for time-dependent routines (VCX)
FIELD-SYMBOLS: <key_date> TYPE ANY.
DATA: BEGIN OF d0001_field_tab OCCURS 10,
        begin TYPE d, end TYPE d, mark(1) TYPE c,
      END OF d0001_field_tab,
      d0001_cursor TYPE i,
      BEGIN OF d0001_status,
        type(1)   TYPE c,
        action(1) TYPE c,
        mode(1)   TYPE c,
        data(1)   TYPE c,
        mark(1)   TYPE c,
        delete(1) TYPE c,
        fill1(1)  TYPE c,              "filler, not used
        fill2(1)  TYPE c,                                   "     - " -
        spec_mode TYPE c,
      END OF d0001_status,
      d0001_input_flag(1) TYPE c,
      vim_mainkey TYPE vim_tabkey_c,   "field for mainkey (prt. forkey)
      current_date TYPE d,
      date_to_delimit TYPE d,
      date_to_posit TYPE d,
      vim_old_viewkey TYPE vim_tabkey_c,
      date_safe TYPE d,
      vim_old_st_selected(1) TYPE c,
      BEGIN OF vim_memory_id_1,  "memory-ID for vim_collapsed_entries
        viewname LIKE vimdesc-viewname,
        user     LIKE sy-uname,
      END OF vim_memory_id_1,
      BEGIN OF vim_memory_id_2,  "memory-ID for date subscreen data
        viewname LIKE vimdesc-viewname,
        user     LIKE sy-uname,
      END OF vim_memory_id_2,
      vim_date_mask(8) TYPE c VALUE '++++++++',
      vim_coll_mkeys_first(1) TYPE c,
      vim_merge_begin TYPE i,
      vim_merge_end TYPE i,
      vim_begdate_entered(1) TYPE c,
      BEGIN OF vim_begdate_name,
        tabname LIKE vimdesc-viewname,
        dash(1) TYPE c VALUE '-',
        fieldname LIKE vimnamtab-viewfield,
      END OF  vim_begdate_name,
      BEGIN OF vim_enddate_name,
        tabname LIKE vimdesc-viewname,
        dash(1) TYPE c VALUE '-',
        fieldname LIKE vimnamtab-viewfield,
      END OF  vim_enddate_name,
      vim_last_coll_mainkeys_ix TYPE i,
      vim_coll_mainkeys_beg_ix TYPE i VALUE 1,
      check_all_keyr_scnd_time(1) TYPE c, "Flag: .........
      vim_tdep_title(19) type c.
CONSTANTS: vim_init_date TYPE d VALUE '00000000'.


* data for navigation within internal tables
DATA:
  aktuell(10) TYPE n,
  maximal(10) TYPE n,
  index     LIKE sy-tabix,
  exind     LIKE sy-tabix,
  mandant   LIKE sy-mandt,
  curline   LIKE sy-tabix,             "Cursor-Position in Tab.
  curpage   LIKE sy-tabix VALUE 1,     "aktuelle Seite
  firstline LIKE sy-tabix VALUE 1,
  nextline  LIKE sy-tabix VALUE 1,
                            "Pos. erste Zeile der akt. Seite in Tab.
  anz_lines LIKE sy-tabix,             "Anzahl vorhandener Tab.-Zeilen
  anz_pages LIKE sy-tabix,             "Anzahl vorhandener Tab.-Seiten
  maxlines  LIKE sy-tabix,             "Anzahl vorhandener Tab.-Zeilen
  destpage  LIKE sy-tabix,  "Seite, auf die geblättert werden soll
  looplines LIKE sy-tabix.  "Anzahl Step-loop-Zeilen im Dynpro

* declarations for activating bc-sets                 "UF profile
TYPES: BEGIN OF vim_pr_tab_type,
                recnumber LIKE scprvals-recnumber,
                action TYPE char1,
                keys_fix,
                align TYPE f,
                keys(1024) TYPE x,
                txt_in_sy_langu_exsts TYPE xfeld,
                align2 TYPE f,
                textrecord TYPE vim_line_ul,
       END OF vim_pr_tab_type.
TYPES: BEGIN OF vim_pr_fields_type,
                recnumber LIKE scprvals-recnumber,
                keys_fix(1),
                fields TYPE vimty_fields_tab_type,
       END OF vim_pr_fields_type,
       vimsellist_type TYPE TABLE OF vimsellist,
       BEGIN OF  bc_key_type,   "HCG like e072k but tabkey 255
          trkorr like e071k-trkorr,
          pgmid like e071k-pgmid,
          object like e071k-object,
          objname like e071k-objname,
          as4pos like e071k-as4pos,
          mastertype like e071k-mastertype,
          mastername like e071k-mastername,
          viewname like e071k-viewname,
          objfunc like e071k-objfunc,
          bc_tabkey like scpractr-tabkey,
          sortflag like e071k-sortflag,
          flag like e071k-flag,
          lang like e071k-lang,
          activity like e071k-activity,
       END OF bc_key_type,
       bc_keytab_type type table of bc_key_type,
* For managing entries coming from bc-sets
       vim_bc_tab_logs TYPE TABLE OF scpractr,
       vim_bc_del_records TYPE TABLE OF scprreca,
       vim_bc_values_lang_type TYPE TABLE OF scpr_vall.
DATA:  vim_pr_fields TYPE TABLE OF vim_pr_fields_type INITIAL SIZE 15,
       vim_pr_fields_wa TYPE vim_pr_fields_type,
       vim_coming_from_img,            "'Y': coming from IMG, 'N': not
       vim_pr_tab TYPE TABLE OF vim_pr_tab_type,
       vim_profile_values TYPE TABLE OF scpr_vals INITIAL SIZE 50,
       vim_bc_entry_list TYPE vimty_bc_entry_list_ttype,
       vim_bc_entry_list_wa TYPE vimty_bc_entry_list_type,
       vim_pr_activating, vim_bc_keys_fix(3),
       vim_set_from_bc_pbo,
       vim_bc_chng_allowed TYPE xfeld, "fix bc-set values modifiable
       vim_pr_records TYPE i.    "number of activated profile records
DATA:  vim_actopts TYPE SCPRACTOPT, "Activation options at BC-SET import
       vim_bcset_id TYPE scpr_id.                        "Name of BC-SET
* field attributes in profiles
CONSTANTS: vim_profile_fix(3)    VALUE 'FIX',
           vim_profile_fixkey(3) VALUE 'FKY',
           vim_profile_use(3)    VALUE 'USE',
           vim_profile_key(3)    VALUE 'KEY',
           vim_profile_usekey(3) VALUE 'UKY',
* for flag KEYS_FIX
           vim_pr_error    VALUE 'E',                       "key error
           vim_pr_open     VALUE 'O',  "no key field fix
           vim_pr_some_fix VALUE 'S',                       "some fix
           vim_pr_all_fix  VALUE 'A',  "all key fields fix
* others
           vim_pr_into_view VALUE 'V',
           vim_profile_found VALUE 'X',
           vim_pr_imp_unchecked VALUE 'Y',
           vim_writing_bc_imp_log VALUE 'W'.
DATA:      vim_pr_stat_txt_me LIKE smp_dyntxt, "dynamic texts for dynpro
           vim_pr_stat_txt_ch LIKE smp_dyntxt,
           vim_pr_stat_txt_ta LIKE smp_dyntxt,
           vim_pr_stat_txt_or LIKE smp_dyntxt.
* internal tables
DATA: vim_adj_header LIKE vimdesc OCCURS 1,
      vim_adj_namtab LIKE vimnamtab OCCURS 0,
      vim_adj_dbasellist LIKE vimsellist OCCURS 0.
DATA: vim_locked_addresses LIKE SORTED TABLE OF adrc-addrnumber
                           WITH UNIQUE KEY table_line
                           INITIAL SIZE 10
                           WITH HEADER LINE.

DATA: BEGIN OF vim_addresses_to_save OCCURS 10,
        viewname LIKE tvdir-tabname,
        addrnumber LIKE adrc-addrnumber,
        handle LIKE addr1_dia-handle,
      END OF vim_addresses_to_save.

DATA: BEGIN OF textpool_tab OCCURS 30.                      "textpool
        INCLUDE STRUCTURE textpool.
DATA: END OF textpool_tab.

DATA: BEGIN OF exclude_tab OCCURS 10,  "fields to exclude from repl
        field LIKE d021s-fnam,         "functions (old version)
      END OF exclude_tab.

DATA: excl_rpl_tab TYPE vimexclfldtab  "fields to exclude from repl
        WITH HEADER LINE,
      excl_que_tab TYPE vimexclfldtab  "fields to exclude from query
        WITH HEADER LINE,
      excl_pos_tab TYPE vimexclfldtab  "fields to exclude from posit
        WITH HEADER LINE,
      vim_excl_xxx_tab_safe TYPE vimexclfldtabs "safe for all excl tabs
        WITH HEADER LINE.

DATA: BEGIN OF vim_corr_objtab OCCURS 10.      "transport objects on the
        INCLUDE STRUCTURE e071.        "vim-object level
DATA:   lockable(1) TYPE c,
      END OF vim_corr_objtab.

DATA: BEGIN OF vim_corr_entryobjtab OCCURS 10. "transport objects on the
        INCLUDE STRUCTURE ko200.       "vim-obj-entries level
DATA:   lockable(1) TYPE c,
      END OF vim_corr_entryobjtab.

DATA: BEGIN OF e071k_tab OCCURS 100.   "keys of changed entries
        INCLUDE STRUCTURE e071k.       "(used as parameter for VIEWPROC)
DATA: END OF e071k_tab.

DATA: vim_alv_fcat TYPE slis_t_fieldcat_alv, "ABAP List Viewer
*      vim_alv_excluding TYPE slis_t_extab,
*      vim_alv_special_groups TYPE slis_t_sp_group_alv,
*      vim_alv_sort TYPE slis_t_sortinfo_alv,
*      vim_alv_sel_hide TYPE slis_sel_hide_alv,
      vim_alv_events TYPE slis_t_event,
*      vim_alv_event_exit TYPE slis_t_event_exit,
      vim_alv_print TYPE slis_print_alv,
      vim_alv_layout TYPE slis_layout_alv,
      vim_alv_variant LIKE disvariant,
      vim_var_save, vim_var_default, vim_alv_value_length TYPE intlen,
      vim_alv_called_by TYPE char30,
      alv_value_tab TYPE TABLE OF tabl8000 initial size 500.
*DATA: BEGIN OF alv_value_tab OCCURS 1,
*      line(4096),
*      END OF alv_value_tab.

DATA: align_value_tab TYPE f,
      BEGIN OF value_tab OCCURS 1,     "Printing with ALV ==>
        line(4096),                                         "
      END OF value_tab.                                     "obsolete

DATA: BEGIN OF structure_table OCCURS 20.   "Printing with ALV ==>
        INCLUDE STRUCTURE dfies.                            "
DATA: END OF structure_table.                               "obsolete

DATA: vim_list_header TYPE slis_t_listheader. "List header for ALV-list

DATA: vim_delim_entries TYPE STANDARD TABLE  "indizes of delim. entries
        OF vim_delim_entr_tl WITH DEFAULT KEY INITIAL SIZE 10
        WITH HEADER LINE.

DATA: BEGIN OF vim_sval_tab OCCURS 1.  "fields for POPUP_GET_VALUES
        INCLUDE STRUCTURE sval.
DATA: END OF vim_sval_tab.

DATA: vim_collapsed_mainkeys TYPE STANDARD TABLE  "collapsed mainkeys
        OF vim_collapsed_mkeys_tl WITH DEFAULT KEY INITIAL SIZE 1
        WITH HEADER LINE.

DATA: vim_merged_entries TYPE STANDARD TABLE      "merged entries
        OF vim_merged_entr_tl WITH DEFAULT KEY INITIAL SIZE 1
        WITH HEADER LINE.

DATA: BEGIN OF vim_copied_indices OCCURS 10,
        ix LIKE sy-tabix, ex_ix LIKE sy-tabix, level TYPE i,
      END OF vim_copied_indices.

DATA: vim_wheretab LIKE vimwheretb OCCURS 10,
      imp_results TYPE slctr_tables_keys WITH HEADER LINE.

* Datencontainer für Texttabelle in mehreren Sprachen     "SW Texttransl
DATA: vim_texttab_container TYPE vim_tabdata_record OCCURS 0
      WITH HEADER LINE, "da 'read table .. assigning <fs>' nicht unterst
      vim_texttab_container_index LIKE sy-tabix,
      vim_d0100_fdescr_ini TYPE vimty_screen_fdescr_tab.

RANGES: mark_functions FOR sy-ucomm,   "fct. which need marked entries
        adrnbr_domain FOR sadr-adrnr,  "domains for address numbers
        exted_functions FOR sy-ucomm,  "fct. used by external edit
        vim_guid_domain FOR vimnamtab-domname, "domains for GUIDs
        vim_begda_types FOR dd03p-rollname,  "types for time-dependence
        vim_endda_types FOR dd03p-rollname.  "types for time-dependence

* constants for documentation 'User Instructions'
CONSTANTS: vim_docu_prog LIKE iwreferenc-programm VALUE 'SAPLSVIM',
           vim_docu_extension LIKE iwreferenc-spec_text
                   VALUE 'SM30 USER INTERFACE'.

* Konstanten für Dynpro
CONSTANTS: vim_template_dynpro TYPE x VALUE '20',  " Vorlagedynpro
           vim_standard_dynpro TYPE x VALUE 'C0'.  " Komprimierung ein

* Organisation criteria (linedependent authorisations)
DATA:  vim_oc_inst TYPE REF TO cl_viewfields_org_crit.

* Backup for DBA_SELLIST
DATA  vim_dba_sel_kept TYPE svorg_vimsellist_type.
*---------------------------------------------------------------------*
*    view related data declarations
*   generation date: 31.12.2012 at 00:06:34 by user CREYTZ
*   view maintenance generator version: #001407#
*---------------------------------------------------------------------*
*...processing: ZSOFTCOPY_STRIP.................................*
DATA:  BEGIN OF STATUS_ZSOFTCOPY_STRIP               .   "state vector
         INCLUDE STRUCTURE VIMSTATUS.
DATA:  END OF STATUS_ZSOFTCOPY_STRIP               .
CONTROLS: TCTRL_ZSOFTCOPY_STRIP
            TYPE TABLEVIEW USING SCREEN '0001'.
*...processing: ZSOFTCOPY_TABLE.................................*
DATA:  BEGIN OF STATUS_ZSOFTCOPY_TABLE               .   "state vector
         INCLUDE STRUCTURE VIMSTATUS.
DATA:  END OF STATUS_ZSOFTCOPY_TABLE               .
CONTROLS: TCTRL_ZSOFTCOPY_TABLE
            TYPE TABLEVIEW USING SCREEN '0002'.
*...processing: ZSOFTCOPY_TEXT..................................*
DATA:  BEGIN OF STATUS_ZSOFTCOPY_TEXT                .   "state vector
         INCLUDE STRUCTURE VIMSTATUS.
DATA:  END OF STATUS_ZSOFTCOPY_TEXT                .
CONTROLS: TCTRL_ZSOFTCOPY_TEXT
            TYPE TABLEVIEW USING SCREEN '0003'.
*...processing: ZSOFTCOPY_VARID.................................*
DATA:  BEGIN OF STATUS_ZSOFTCOPY_VARID               .   "state vector
         INCLUDE STRUCTURE VIMSTATUS.
DATA:  END OF STATUS_ZSOFTCOPY_VARID               .
CONTROLS: TCTRL_ZSOFTCOPY_VARID
            TYPE TABLEVIEW USING SCREEN '0004'.
*.........table declarations:.................................*
TABLES: *ZSOFTCOPY_STRIP               .
TABLES: *ZSOFTCOPY_TABLE               .
TABLES: *ZSOFTCOPY_TEXT                .
TABLES: *ZSOFTCOPY_TEXTT               .
TABLES: *ZSOFTCOPY_VARID               .
TABLES: ZSOFTCOPY_STRIP                .
TABLES: ZSOFTCOPY_TABLE                .
TABLES: ZSOFTCOPY_TEXT                 .
TABLES: ZSOFTCOPY_TEXTT                .
TABLES: ZSOFTCOPY_VARID                .

* general table data declarations..............
***INCLUDE LSVIMTDT .
DATA:
* Tabelle für die DB-Zeilen, Ultra Long
  BEGIN OF EXTRACT_UL OCCURS 0,
        LINE(4096),
      END OF EXTRACT_UL,
* Tabelle für die DB-Zeilen, Very Long
  BEGIN OF EXTRACT_VL OCCURS 0,
        LINE(512),
      END OF EXTRACT_VL,
* Tabelle für die DB-Zeilen, Long
  BEGIN OF EXTRACT_L OCCURS 0,
        LINE(256),
      END OF EXTRACT_L,
* Tabelle für die DB-Zeilen, Middle
  BEGIN OF EXTRACT_M OCCURS 0,
        LINE(128),
      END OF EXTRACT_M,
* Tabelle für die DB-Zeilen, Short
  BEGIN OF EXTRACT_S OCCURS 0,
        LINE(64),
      END OF EXTRACT_S,
* Tabelle für die DB-Zeilen, Very Short
  BEGIN OF EXTRACT_VS OCCURS 0,
        LINE(48),
      END OF EXTRACT_VS,
* Tabelle für die DB-Zeilen, Ultra Short
  BEGIN OF EXTRACT_US OCCURS 0,
        LINE(32),
      END OF EXTRACT_US.

* Table for all entries loaded from database
DATA:
* Tabelle für die DB-Zeilen, Ultra Long
  BEGIN OF TOTAL_UL OCCURS 0,
        LINE(4096),
      END OF TOTAL_UL,
* Tabelle für die DB-Zeilen, Very Long
  BEGIN OF TOTAL_VL OCCURS 0,
        LINE(512),
      END OF TOTAL_VL,
* Tabelle für die DB-Zeilen, Long
  BEGIN OF TOTAL_L OCCURS 0,
        LINE(256),
      END OF TOTAL_L,
* Tabelle für die DB-Zeilen, Middle
  BEGIN OF TOTAL_M OCCURS 0,
        LINE(128),
      END OF TOTAL_M,
* Tabelle für die DB-Zeilen, Short
  BEGIN OF TOTAL_S OCCURS 0,
        LINE(64),
      END OF TOTAL_S,
* Tabelle für die DB-Zeilen, Very Short
  BEGIN OF TOTAL_VS OCCURS 0,
        LINE(48),
      END OF TOTAL_VS,
* Tabelle für die DB-Zeilen, Ultra Short
  BEGIN OF TOTAL_US OCCURS 0,
        LINE(32),
      END OF TOTAL_US.

* Tabelle mit den modifizierten Elementen

DATA: BEGIN OF MOD_ELEM_TAB OCCURS 100,
        LINES(4096),
      END OF MOD_ELEM_TAB.

*ATA: FORBIDDEN_FUNC_NAME_CHARS(10) VALUE '/\$!§%&''##',   "#EC *
*     FORBIDDEN_AREA_NAME_CHARS(10) VALUE '/\$!§%&''##'.   "#EC *
DATA: FORBIDDEN_FUNC_NAME_CHARS(9) VALUE '\$!§%&''##',   "#EC *
      FORBIDDEN_AREA_NAME_CHARS(9) VALUE '\$!§%&''##'.   "#EC *
*****************************************************************
*   THIS FILE IS GENERATED BY THE FUNCTION LIBRARY.             *
*   NEVER CHANGE IT MANUALLY, PLEASE!                           *
*****************************************************************
*---------------------------------------------------------------------*
*    program for:   TABLEFRAME_ZSOFTCOPY_DBM
*   generation date: 30.12.2012 at 22:57:54 by user CREYTZ
*   view maintenance generator version: #001407#
*---------------------------------------------------------------------*
*******************************************************************
*   THIS FILE IS GENERATED BY THE FUNCTION LIBRARY.               *
*   NEVER CHANGE IT MANUALLY, PLEASE!                             *
*******************************************************************
FUNCTION $$UNIT$$ TABLEFRAME_ZSOFTCOPY_DBM

         IMPORTING
               VALUE(VIEW_ACTION) DEFAULT 'S'
               VALUE(VIEW_NAME) LIKE !DD02V-TABNAME
               VALUE(CORR_NUMBER) LIKE !E070-TRKORR DEFAULT ' '
         TABLES
               !DBA_SELLIST STRUCTURE !VIMSELLIST
               !DPL_SELLIST STRUCTURE !VIMSELLIST
               !EXCL_CUA_FUNCT STRUCTURE !VIMEXCLFUN
               !X_HEADER STRUCTURE !VIMDESC
               !X_NAMTAB STRUCTURE !VIMNAMTAB
         EXCEPTIONS
               !MISSING_CORR_NUMBER.

  PERFORM TABLEFRAME TABLES X_HEADER X_NAMTAB DBA_SELLIST DPL_SELLIST
                            EXCL_CUA_FUNCT
                     USING  CORR_NUMBER VIEW_ACTION VIEW_NAME.

ENDFUNCTION.
                    "TABLEFRAME_ZSOFTCOPY_DBM
*---------------------------------------------------------------------*
*    program for:   TABLEPROC_ZSOFTCOPY_DBM
*   generation date: 30.12.2012 at 22:57:55 by user CREYTZ
*   view maintenance generator version: #001407#
*---------------------------------------------------------------------*
*******************************************************************
*   THIS FILE IS GENERATED BY THE FUNCTION LIBRARY.               *
*   NEVER CHANGE IT MANUALLY, PLEASE!                             *
*******************************************************************
FUNCTION $$UNIT$$ TABLEPROC_ZSOFTCOPY_DBM

         IMPORTING
               VALUE(FCODE) DEFAULT 'RDED'
               VALUE(VIEW_ACTION) DEFAULT 'S'
               VALUE(VIEW_NAME) LIKE !DD02V-TABNAME
               VALUE(CORR_NUMBER) LIKE !E070-TRKORR DEFAULT ' '
         EXPORTING
               VALUE(LAST_ACT_ENTRY)
               VALUE(UCOMM)
               VALUE(UPDATE_REQUIRED)
         TABLES
               !CORR_KEYTAB STRUCTURE !E071K
               !DBA_SELLIST STRUCTURE !VIMSELLIST
               !DPL_SELLIST STRUCTURE !VIMSELLIST
               !EXCL_CUA_FUNCT STRUCTURE !VIMEXCLFUN
               !EXTRACT
               !TOTAL
               !X_HEADER STRUCTURE !VIMDESC
               !X_NAMTAB STRUCTURE !VIMNAMTAB
         EXCEPTIONS
               !MISSING_CORR_NUMBER
               !SAVING_CORRECTION_FAILED
         $$GLOBAL.

  PERFORM TABLEPROC.

ENDFUNCTION.
                    "TABLEPROC_ZSOFTCOPY_DBM

*******************************************************************
*   include-files generated by view maintenance tool              *
*******************************************************************

*      view related include-files   (never change, please)        *
*---------------------------------------------------------------------*
*    view related FORM routines
*   generation date: 30.12.2012 at 22:57:55 by user CREYTZ
*   view maintenance generator version: #001407#
*---------------------------------------------------------------------*

* base table related FORM-routines.............
*-------------------------------------------------------------------
***INCLUDE LSVIMFTX .
*-------------------------------------------------------------------
*&--------------------------------------------------------------------*
*&      Form  TABLE_CALL_FUNCTION                                     *
*---------------------------------------------------------------------*
* call function TABLEPROC with proper parameters
*---------------------------------------------------------------------*
* TCF_FCODE    ---> current function code                             *
* TCF_TABTYPE  ---> type of int. table: SHORT, MIDDLE, LONG, VERY_LONG*
* TCF_UPD_fLAG <--- flag: update required                             *
*---------------------------------------------------------------------*
FORM table_call_function TABLES dba_sellist dpl_sellist
                                x_header STRUCTURE vimdesc
                                x_namtab excl_cua_funct
                         USING value(tcf_fcode) value(tcf_tabtype)
                               tcf_upd_flag.

  DATA: function_name LIKE tfdir-funcname VALUE 'TABLEPROC_',
        prefix_len TYPE i VALUE '10'.

  READ TABLE x_header INDEX 1.
  MOVE x_header-area TO function_name+prefix_len.
  IF function_name CA forbidden_func_name_chars.
    PERFORM replace_forbidden_chars USING forbidden_func_name_chars
                                          function_name.
  ENDIF.
  CASE tcf_tabtype.
    WHEN 'ULTRA_SHORT'.
      CALL FUNCTION function_name
        EXPORTING
          fcode                    = tcf_fcode
          view_action              = maint_mode
          view_name                = x_header-viewname
          corr_number              = corr_nbr
        IMPORTING
          ucomm                    = function
          update_required          = tcf_upd_flag
        TABLES
          dba_sellist              = dba_sellist
          dpl_sellist              = dpl_sellist
          excl_cua_funct           = excl_cua_funct
          x_header                 = x_header
          x_namtab                 = x_namtab
          corr_keytab              = e071k_tab
          extract                  = extract_us
          total                    = total_us
        EXCEPTIONS
          missing_corr_number      = 01
          saving_correction_failed = 03.
    WHEN 'VERY_SHORT'.
      CALL FUNCTION function_name
        EXPORTING
          fcode                    = tcf_fcode
          view_action              = maint_mode
          view_name                = x_header-viewname
          corr_number              = corr_nbr
        IMPORTING
          ucomm                    = function
          update_required          = tcf_upd_flag
        TABLES
          dba_sellist              = dba_sellist
          dpl_sellist              = dpl_sellist
          excl_cua_funct           = excl_cua_funct
          x_header                 = x_header
          x_namtab                 = x_namtab
          corr_keytab              = e071k_tab
          extract                  = extract_vs
          total                    = total_vs
        EXCEPTIONS
          missing_corr_number      = 01
          saving_correction_failed = 03.
    WHEN 'SHORT'.
      CALL FUNCTION function_name
        EXPORTING
          fcode                    = tcf_fcode
          view_action              = maint_mode
          view_name                = x_header-viewname
          corr_number              = corr_nbr
        IMPORTING
          ucomm                    = function
          update_required          = tcf_upd_flag
        TABLES
          dba_sellist              = dba_sellist
          dpl_sellist              = dpl_sellist
          excl_cua_funct           = excl_cua_funct
          x_header                 = x_header
          x_namtab                 = x_namtab
          corr_keytab              = e071k_tab
          extract                  = extract_s
          total                    = total_s
        EXCEPTIONS
          missing_corr_number      = 01
          saving_correction_failed = 03.
    WHEN 'MIDDLE'.
      CALL FUNCTION function_name
        EXPORTING
          fcode                    = tcf_fcode
          view_action              = maint_mode
          view_name                = x_header-viewname
          corr_number              = corr_nbr
        IMPORTING
          ucomm                    = function
          update_required          = tcf_upd_flag
        TABLES
          dba_sellist              = dba_sellist
          dpl_sellist              = dpl_sellist
          excl_cua_funct           = excl_cua_funct
          x_header                 = x_header
          x_namtab                 = x_namtab
          corr_keytab              = e071k_tab
          extract                  = extract_m
          total                    = total_m
        EXCEPTIONS
          missing_corr_number      = 01
          saving_correction_failed = 03.
    WHEN 'LONG'.
      CALL FUNCTION function_name
        EXPORTING
          fcode                    = tcf_fcode
          view_action              = maint_mode
          view_name                = x_header-viewname
          corr_number              = corr_nbr
        IMPORTING
          ucomm                    = function
          update_required          = tcf_upd_flag
        TABLES
          dba_sellist              = dba_sellist
          dpl_sellist              = dpl_sellist
          excl_cua_funct           = excl_cua_funct
          x_header                 = x_header
          x_namtab                 = x_namtab
          corr_keytab              = e071k_tab
          extract                  = extract_l
          total                    = total_l
        EXCEPTIONS
          missing_corr_number      = 01
          saving_correction_failed = 03.
    WHEN 'VERY_LONG'.
      CALL FUNCTION function_name
        EXPORTING
          fcode                    = tcf_fcode
          view_action              = maint_mode
          view_name                = x_header-viewname
          corr_number              = corr_nbr
        IMPORTING
          ucomm                    = function
          update_required          = tcf_upd_flag
        TABLES
          dba_sellist              = dba_sellist
          dpl_sellist              = dpl_sellist
          excl_cua_funct           = excl_cua_funct
          x_header                 = x_header
          x_namtab                 = x_namtab
          corr_keytab              = e071k_tab
          extract                  = extract_vl
          total                    = total_vl
        EXCEPTIONS
          missing_corr_number      = 01
          saving_correction_failed = 03.
    WHEN 'ULTRA_LONG'.
      CALL FUNCTION function_name
        EXPORTING
          fcode                    = tcf_fcode
          view_action              = maint_mode
          view_name                = x_header-viewname
          corr_number              = corr_nbr
        IMPORTING
          ucomm                    = function
          update_required          = tcf_upd_flag
        TABLES
          dba_sellist              = dba_sellist
          dpl_sellist              = dpl_sellist
          excl_cua_funct           = excl_cua_funct
          x_header                 = x_header
          x_namtab                 = x_namtab
          corr_keytab              = e071k_tab
          extract                  = extract_ul
          total                    = total_ul
        EXCEPTIONS
          missing_corr_number      = 01
          saving_correction_failed = 03.
  ENDCASE.
ENDFORM.                               " TABLE_CALL_FUNCTION

*&--------------------------------------------------------------------*
*&      Form  TABLE_GET_DATA                                          *
*---------------------------------------------------------------------*
* get data from database
*---------------------------------------------------------------------*
FORM table_get_data.
  CONSTANTS maxsellines TYPE i VALUE 500.
  DATA: tgd_sellist LIKE vimsellist OCCURS 10, tgd_sel LIKE vimsellist,
        tgd_sellangu LIKE vimsellist,
        short_sellist LIKE vimsellist OCCURS 10,
        short_sel LIKE vimsellist,
        tgd_ind TYPE i, tgd_field LIKE vimnamtab-viewfield,
        selnumber TYPE i, selindex TYPE i, selcut TYPE i,
        selpieces TYPE i.
  FIELD-SYMBOLS: <text_key>.
  DATA: primtab TYPE REF TO data, texttab TYPE REF TO data,
        w_texttab_save TYPE REF TO data, w_texttab TYPE REF TO data,
        text_keyflds TYPE vim_flds_tab_type.

  FIELD-SYMBOLS: <primtab> TYPE STANDARD TABLE,
                 <texttab> TYPE SORTED TABLE, <w_texttab> TYPE ANY,
                 <w_texttab_save> TYPE ANY, <textline_x> TYPE x.

  REFRESH total. CLEAR total.
  IF x_header-selection NE space.
    DESCRIBE TABLE dba_sellist LINES selnumber.
    IF selnumber > maxsellines.  "fragmentation of too large sellists
      CLEAR selpieces.
      CLEAR selindex.
      CREATE DATA primtab TYPE STANDARD TABLE OF (x_header-maintview).
      ASSIGN primtab->* TO <primtab>.
      WHILE selindex < selnumber.
        selpieces = selpieces + maxsellines.
        REFRESH short_sellist.
        CLEAR selcut.
        WHILE selcut EQ 0 AND selindex < selnumber.
          selindex = selindex + 1.
          READ TABLE dba_sellist INTO short_sel INDEX selindex.
          APPEND short_sel TO short_sellist.
          IF selindex > selpieces AND short_sel-and_or NE 'AND'.
            selcut = 1.
          ENDIF.
        ENDWHILE.
        CLEAR short_sel-and_or.      "last line without logic operation
        MODIFY short_sellist FROM short_sel INDEX selindex.
        CALL FUNCTION 'VIEW_FILL_WHERETAB'
           EXPORTING
                tablename               = x_header-maintview
*             ONLY_CNDS_FOR_KEYFLDS   = 'X' "use default SPACE
           TABLES
                sellist                 = short_sellist
                wheretab                = vim_wheretab
                x_namtab                = x_namtab
           EXCEPTIONS
                no_conditions_for_table = 01.
*       read data from database with morer wheretabs...................*
        SELECT * FROM (x_header-maintview) APPENDING TABLE <primtab>
                                          WHERE (vim_wheretab).
        CLEAR selcut.
      ENDWHILE.
    ELSE.                                  "selnumber > maxsellines
      CALL FUNCTION 'VIEW_FILL_WHERETAB'
           EXPORTING
                tablename               = x_header-maintview
*             ONLY_CNDS_FOR_KEYFLDS   = 'X' "use default SPACE
           TABLES
                sellist                 = dba_sellist
                wheretab                = vim_wheretab
                x_namtab                = x_namtab
           EXCEPTIONS
                no_conditions_for_table = 01.
*   read data from database with one wheretab..........................*
    CREATE DATA primtab TYPE STANDARD TABLE OF (x_header-maintview)."UCb
    ASSIGN primtab->* TO <primtab>.
    SELECT * FROM (x_header-maintview) INTO TABLE <primtab>
                                        WHERE (vim_wheretab).
    ENDIF.                                   "if selnumber > maxsellines
  ELSE.                                  "if x_header-selection NE space
    REFRESH vim_wheretab.
*   read data from database without wheretab...........................*
    CREATE DATA primtab TYPE STANDARD TABLE OF (x_header-maintview)."UCb
    ASSIGN primtab->* TO <primtab>.
    SELECT * FROM (x_header-maintview) INTO TABLE <primtab>.
  ENDIF.                                "if x_header-selection NE space
  IF x_header-texttbexst EQ space.
* no texttable
    LOOP AT <primtab> INTO <vim_total_struc>.
      APPEND total.
    ENDLOOP.                                                "UCe
    SORT total BY <vim_xtotal_key>. <status>-alr_sorted = 'R'.
    IF x_header-selection EQ space AND x_header-delmdtflag NE space.
* time dependence
      PERFORM build_mainkey_tab_0.
    ENDIF.
    LOOP AT total.
      CLEAR: <action>, <mark>.
      MODIFY total.
      IF x_header-selection EQ space AND x_header-delmdtflag NE space.
        PERFORM build_mainkey_tab_1.
      ENDIF.
    ENDLOOP.
    IF x_header-selection EQ space AND x_header-delmdtflag NE space.
      PERFORM build_mainkey_tab_2.
    ENDIF.
  ELSE.
* texttable exists
    PERFORM vim_get_text_keyflds USING x_header-texttab
                                 CHANGING text_keyflds.
    CREATE DATA texttab TYPE SORTED TABLE OF (x_header-texttab)
     WITH UNIQUE KEY (text_keyflds).                        "UCb
    ASSIGN texttab->* TO <texttab>.
    IF x_header-selection NE space.
* get selection for texttable
*      READ TABLE dba_sellist INTO dpl_sellist INDEX 1.
      DESCRIBE TABLE dba_sellist LINES selnumber.
      selindex = 0.
      WHILE selindex < selnumber.
        selindex = selindex + 1.
        READ TABLE dba_sellist INTO tgd_sel INDEX selindex.
        READ TABLE x_namtab WITH KEY
          viewfield = tgd_sel-viewfield texttabfld = space.
      CHECK x_namtab-keyflag = 'X'.        " key fields for texttab only
        tgd_sel-viewfield = x_namtab-txttabfldn.
        READ TABLE x_namtab WITH KEY
          viewfield = tgd_sel-viewfield texttabfld = 'X'.
        tgd_sel-tabix = sy-tabix.
        IF tgd_sel-and_or NE 'AND' OR selindex = 1.          "Langufield
          READ TABLE x_namtab WITH KEY primtabkey = 0 keyflag = 'X'.
          tgd_sellangu-viewfield = x_namtab-viewfield.
          tgd_sellangu-tabix     = sy-tabix.
          tgd_sellangu-operator = 'EQ'.
          tgd_sellangu-value = sy-langu.
          tgd_sellangu-and_or = 'AND'.
          IF tgd_sellangu-value EQ space.
            tgd_sellangu-initial = 'X'.
          ENDIF.
          tgd_sellangu-cond_kind = dpl_sellist-cond_kind.
          CLEAR tgd_sellangu-converted.
          APPEND tgd_sellangu TO tgd_sellist.
        ENDIF.
        APPEND tgd_sel TO tgd_sellist.
*      Did not work for sellist to describe more than one dataset in
*      transport request                                          "HCG
*      LOOP AT x_namtab WHERE keyflag NE space    "fill sellist for
*                         AND texttabfld NE space. "texttab
*        tgd_field = x_namtab-viewfield.
*        tgd_ind   = sy-tabix.
*        IF x_namtab-primtabkey EQ 0.   "langufield
*          tgd_sel-viewfield = tgd_field.
*          tgd_sel-tabix     = tgd_ind.
*          tgd_sel-operator = 'EQ'.
*          tgd_sel-value = sy-langu.
*          tgd_sel-and_or = 'AND'.
*          IF tgd_sel-value EQ space.
*            tgd_sel-initial = 'X'.
*          ENDIF.
*          tgd_sel-cond_kind = dpl_sellist-cond_kind.
*          clear tgd_sel-converted.
*          APPEND tgd_sel TO tgd_sellist.
*        ELSE.
*          READ TABLE x_namtab INDEX x_namtab-primtabkey.
*          LOOP AT dba_sellist WHERE viewfield EQ x_namtab-viewfield.
*            tgd_sel = dba_sellist.
*            tgd_sel-viewfield = tgd_field.
*            tgd_sel-tabix     = tgd_ind.
*            IF tgd_sel-and_or EQ space.
*              tgd_sel-and_or = 'AND'.
*            ENDIF.
*            APPEND tgd_sel TO tgd_sellist.
*          ENDLOOP.
*        ENDIF.
*      ENDLOOP.
      ENDWHILE.
      DESCRIBE TABLE tgd_sellist.
      READ TABLE tgd_sellist INDEX sy-tfill INTO tgd_sel.
      IF tgd_sel-and_or NE space.
        CLEAR tgd_sel-and_or.
        MODIFY tgd_sellist INDEX sy-tfill FROM tgd_sel.
      ENDIF.
    ELSE.
* no selection for primary table: fill selection with langu-field only
      LOOP AT x_namtab WHERE keyflag NE space    "fill sellist with
                         AND texttabfld NE space  "language condition
                         AND primtabkey EQ 0.
        tgd_sel-viewfield = x_namtab-viewfield.
        tgd_sel-tabix     = sy-tabix.
        tgd_sel-operator = 'EQ'.
        tgd_sel-value = sy-langu.
        tgd_sel-and_or = space.
        IF tgd_sel-value EQ space.
          tgd_sel-initial = 'X'.
        ENDIF.
        APPEND tgd_sel TO tgd_sellist.
        EXIT.
      ENDLOOP.
    ENDIF.
*    CALL FUNCTION 'VIEW_FILL_WHERETAB'
*      EXPORTING
*        tablename               = x_header-texttab
*        only_cnds_for_keyflds   = 'X'
*      TABLES
*        sellist                 = tgd_sellist
*        wheretab                = vim_wheretab
*        x_namtab                = x_namtab
*      EXCEPTIONS
*        no_conditions_for_table = 01.
** read texttable from database
*    SELECT * FROM (x_header-texttab) INTO TABLE <texttab>
*                                      WHERE (vim_wheretab).
    DESCRIBE TABLE tgd_sellist LINES selnumber.
    IF selnumber > maxsellines.  "fragmentation of too large sellists
      CLEAR selpieces.
      CLEAR selindex.
      WHILE selindex < selnumber.
        selpieces = selpieces + maxsellines.
        REFRESH short_sellist.
        CLEAR selcut.
        WHILE selcut EQ 0 AND selindex < selnumber.
          selindex = selindex + 1.
          READ TABLE tgd_sellist INTO short_sel INDEX selindex.
          APPEND short_sel TO short_sellist.
          IF selindex > selpieces AND short_sel-and_or NE 'AND'.
            selcut = 1.
          ENDIF.
        ENDWHILE.
        CLEAR short_sel-and_or.      "last line without logic operation
        MODIFY short_sellist FROM short_sel INDEX selindex.
        CALL FUNCTION 'VIEW_FILL_WHERETAB'
          EXPORTING
            tablename               = x_header-texttab
            only_cnds_for_keyflds   = 'X'
          TABLES
            sellist                 = short_sellist
            wheretab                = vim_wheretab
            x_namtab                = x_namtab
          EXCEPTIONS
            no_conditions_for_table = 01.
*       read data from database with morer wheretabs...................*
        SELECT * FROM (x_header-texttab) APPENDING TABLE <texttab>
                                          WHERE (vim_wheretab).
        CLEAR selcut.
      ENDWHILE.
    ELSE.                                  "selnumber > maxsellines
      CALL FUNCTION 'VIEW_FILL_WHERETAB'
        EXPORTING
          tablename               = x_header-texttab
          only_cnds_for_keyflds   = 'X'
        TABLES
          sellist                 = tgd_sellist
          wheretab                = vim_wheretab
          x_namtab                = x_namtab
        EXCEPTIONS
          no_conditions_for_table = 01.
*   read data from database with one wheretab..........................*
      SELECT * FROM (x_header-texttab) INTO TABLE <texttab>
                                        WHERE (vim_wheretab).
    ENDIF.                                   "if selnumber > maxsellines
    IF x_header-selection EQ space AND x_header-delmdtflag NE space.
      PERFORM build_mainkey_tab_0.
    ENDIF.
    CREATE DATA w_texttab_save TYPE (x_header-texttab).
    CREATE DATA w_texttab TYPE (x_header-texttab).
    ASSIGN: w_texttab->* TO <w_texttab>,
            w_texttab_save->* TO <w_texttab_save>,
            <w_texttab_save> TO <textline_x> CASTING.
    LOOP AT <primtab> INTO <vim_total_struc>.
*       hier aufbauen schlüssel texttabelle in feld text_key
      CLEAR <w_texttab>.
      PERFORM fill_texttab_key_uc USING <vim_total_struc>
                                  CHANGING <w_texttab>.
      IF <w_texttab> NE <w_texttab_save>.
        READ TABLE <texttab> INTO <w_texttab_save>
         FROM <w_texttab>.
        IF sy-subrc = 0.
*          MOVE <w_texttab_save> TO <w_textline>.
*          MOVE textline(x_header-texttablen) TO <total_text>.
        ELSE.
          MOVE <text_initial> TO <w_texttab_save>.
        ENDIF.
*      ELSE.
*        MOVE <w_texttab_save> TO <w_textline>.
*        MOVE textline(x_header-texttablen) TO <total_text>.
      ENDIF.
      MOVE <textline_x> TO <vim_xtotal_text>.
      CLEAR: <action>, <mark>, <action_text>.
      APPEND total.
      IF x_header-selection EQ space AND x_header-delmdtflag NE space.
        PERFORM build_mainkey_tab_1.
      ENDIF.
    ENDLOOP.
    SORT total BY <vim_xtotal_key>. <status>-alr_sorted = 'R'.
    IF x_header-selection EQ space AND x_header-delmdtflag NE space.
      PERFORM build_mainkey_tab_2.
    ENDIF.
  ENDIF.
*.check dynamic selectoptions (not in DDIC)...........................*
  IF x_header-selection NE space.
    PERFORM check_dynamic_select_options.
  ENDIF.
ENDFORM.                               " TABLE_GET_DATA

*&--------------------------------------------------------------------*
*&      Form  TABLE_DB_UPD                                            *
*---------------------------------------------------------------------*
* process data base updates/inserts/deletes
*---------------------------------------------------------------------*
FORM table_db_upd.
  DATA: modified_entries TYPE i, prt_frky_entries TYPE i, rc TYPE i,
        h_ix TYPE i,
        primtab_mod TYPE REF TO data,
        primtab_mod_wa TYPE REF TO data,
        texttab_mod TYPE REF TO data,
        w_texttab_mod TYPE REF TO data,
        e071_loctab TYPE vim_ko200_tab_type.
  FIELD-SYMBOLS: <mod_elem_tab> TYPE STANDARD TABLE, <h_keyx> TYPE x,
                 <mod_elem_wa> TYPE ANY,
                 <texttab> TYPE STANDARD TABLE, <w_texttab> TYPE ANY,
                 <textline_x> TYPE x.

* first of all: delete requests
  CREATE DATA primtab_mod TYPE TABLE OF (x_header-maintview).
  CREATE DATA primtab_mod_wa TYPE (x_header-maintview).
  ASSIGN: primtab_mod->* TO <mod_elem_tab>,
          primtab_mod_wa->* TO <mod_elem_wa>.
  LOOP AT total.
    CHECK ( <action> EQ geloescht OR <action> EQ update_geloescht OR
            <action> EQ neuer_geloescht ).
    IF <action> EQ neuer_geloescht.
      IF status-delete EQ geloescht.
        READ TABLE extract WITH KEY <vim_xtotal_key>.
        IF sy-subrc EQ 0.
          DELETE extract INDEX sy-tabix.
        ENDIF.
      ENDIF.
      DELETE total.
    ELSE.
      APPEND <vim_total_struc> TO <mod_elem_tab>.
      ADD 1 TO modified_entries.
      IF x_header-texttbexst EQ space. "no texttab
        IF status-delete EQ geloescht.
          READ TABLE extract WITH KEY <vim_xtotal_key>.
          IF sy-subrc EQ 0.
            DELETE extract INDEX sy-tabix.
          ENDIF.
        ENDIF.
        DELETE total.
      ENDIF.
    ENDIF.
  ENDLOOP.
  IF modified_entries NE 0.
    DELETE (x_header-maintview) FROM TABLE <mod_elem_tab>.
  ENDIF.
  IF x_header-texttbexst NE space.
    CLEAR modified_entries.
    CREATE DATA texttab_mod TYPE STANDARD TABLE OF (x_header-texttab).
    CREATE DATA w_texttab_mod TYPE (x_header-texttab).
    ASSIGN: texttab_mod->* TO <texttab>,
            w_texttab_mod->* TO <w_texttab>,
            <w_texttab> TO <textline_x> CASTING.
* delete texts for all deleted entities
    LOOP AT <mod_elem_tab> INTO <table1_wa>.
      READ TABLE total WITH KEY <f1_wax> BINARY SEARCH.
      h_ix = sy-tabix.
      IF x_header-ptfrkyexst NE space.
* partial foreign key relation:
* Are there still any primary table entries?
        PERFORM create_wheretab_new USING x_namtab[]
                                          <vim_total_struc>
                                          <vim_tot_txt_struc>
                                          x_header-maintview
                                          'X' rc.
        IF rc NE 0.                    "something seems to be wrong
          prt_frky_entries = 1.        "don't delete
        ELSE.
          SELECT COUNT(*) FROM (x_header-maintview) UP TO 1 ROWS
                          WHERE (vim_wheretab).
          prt_frky_entries = sy-dbcnt.
        ENDIF.
      ELSE.
        CLEAR prt_frky_entries.
      ENDIF.
      IF prt_frky_entries EQ 0.
* No, there aren't.
*        MODIFY mod_elem_tab FROM <total_text>.
        MOVE <vim_xtotal_text> TO <textline_x>.
        APPEND <w_texttab> TO <texttab>.
        ADD 1 TO modified_entries.
      ENDIF.
      IF status-delete EQ geloescht.
        READ TABLE extract WITH KEY <vim_xtotal_key>
         TRANSPORTING NO FIELDS.
        IF sy-subrc EQ 0.
          DELETE extract INDEX sy-tabix.
        ENDIF.
      ENDIF.
      DELETE total INDEX h_ix.
    ENDLOOP.
    IF modified_entries NE 0.
* delete text entries in all languages
      DO modified_entries TIMES.
*        READ TABLE mod_elem_tab INDEX 1.
*        DELETE mod_elem_tab INDEX 1.
        READ TABLE <texttab> INTO <w_texttab> INDEX 1.
*        PERFORM create_wheretab TABLES x_namtab
*                                USING mod_elem_tab
*                                      x_header-texttab space rc.
        PERFORM create_wheretab_new USING x_namtab[]
                                          <vim_total_struc>
                                          <vim_tot_txt_struc>
                                          x_header-texttab
                                          space
                                          rc.
        SELECT * FROM (x_header-texttab) APPENDING TABLE <texttab>
                                         WHERE (vim_wheretab).
      ENDDO.
*      DELETE (x_header-texttab) FROM TABLE mod_elem_tab.
      DELETE (x_header-texttab) FROM TABLE <texttab>.
    ENDIF.
  ENDIF.
* now update requests
  REFRESH: <mod_elem_tab>.
  CLEAR modified_entries.
  LOOP AT total.
    CHECK <action> EQ aendern.
*    MOVE: total TO <table1>,
*          <table1> TO mod_elem_tab.
*    APPEND mod_elem_tab.
    APPEND <vim_total_struc> TO <mod_elem_tab>.
    ADD 1 TO modified_entries.
    IF x_header-texttbexst EQ space OR
       <action_text> EQ original.
      READ TABLE extract WITH KEY <vim_xtotal_key>.
      <action> = original.
      IF sy-subrc = 0.
        <xact> = original.
        MODIFY extract INDEX sy-tabix.
      ENDIF.
      MODIFY total.
    ENDIF.
  ENDLOOP.
  IF modified_entries NE 0.
    UPDATE (x_header-maintview) FROM TABLE <mod_elem_tab>.
  ENDIF.
  IF x_header-texttbexst NE space.
    REFRESH <texttab>.
    CLEAR modified_entries.
    LOOP AT total.
      CHECK <action_text> EQ aendern.
*      MOVE: <total_text> TO mod_elem_tab.
*      APPEND mod_elem_tab.
      MOVE <vim_xtotal_text> TO <textline_x>.
      APPEND <w_texttab> TO <texttab>.
      ADD 1 TO modified_entries.
      READ TABLE extract WITH KEY <vim_xtotal_key>.
      IF <action> EQ aendern.
        <action> = original. <xact> = original.
      ENDIF.
      <action_text> = original. <xact_text> = original.
      IF sy-subrc = 0.
        MODIFY extract INDEX sy-tabix.
      ENDIF.
      MODIFY total.
    ENDLOOP.
    IF modified_entries NE 0.
*      UPDATE (x_header-texttab) FROM TABLE mod_elem_tab.
      UPDATE (x_header-texttab) FROM TABLE <texttab>.
    ENDIF.
  ENDIF.
* last not least: insert requests
  REFRESH: <mod_elem_tab>. CLEAR modified_entries.
  LOOP AT total.
    CHECK <action> EQ neuer_eintrag.
*    MOVE: total TO <table1>,
*          <table1> TO mod_elem_tab.
*    APPEND mod_elem_tab.
    APPEND <vim_total_struc> TO <mod_elem_tab>.
    ADD 1 TO modified_entries.
    IF x_header-texttbexst EQ space OR
       <action_text> EQ original.
      READ TABLE extract WITH KEY <vim_xtotal_key>.
      <action> = original.
      IF sy-subrc = 0.
        <xact> = original.
        MODIFY extract INDEX sy-tabix.
      ENDIF.
      MODIFY total.
    ENDIF.
  ENDLOOP.
  IF modified_entries NE 0.
    INSERT (x_header-maintview) FROM TABLE <mod_elem_tab>.
  ENDIF.
  IF x_header-texttbexst NE space.
    REFRESH <texttab>.
    CLEAR modified_entries.
    LOOP AT total.
      CHECK <action_text> EQ neuer_eintrag.
*      MOVE: <total_text> TO mod_elem_tab.
*      APPEND mod_elem_tab.
      MOVE <vim_xtotal_text> TO <textline_x>.
      APPEND <w_texttab> TO <texttab>.
      ADD 1 TO modified_entries.
      READ TABLE extract WITH KEY <vim_xtotal_key>.
      IF <action> EQ neuer_eintrag.
        <action> = original. <xact> = original.
      ENDIF.
      <action_text> = original. <xact_text> = original.
      IF sy-subrc = 0.
        MODIFY extract INDEX sy-tabix.
      ENDIF.
      MODIFY total.
    ENDLOOP.
    IF modified_entries NE 0.
*      INSERT (x_header-texttab) FROM TABLE mod_elem_tab
*                                ACCEPTING DUPLICATE KEYS.
      INSERT (x_header-texttab) FROM TABLE <texttab>
                                ACCEPTING DUPLICATE KEYS.
      IF sy-subrc NE 0. "duplicate keys -> process additional update
*        UPDATE (x_header-texttab) FROM TABLE mod_elem_tab.
        UPDATE (x_header-texttab) FROM TABLE <texttab>.
      ENDIF.
    ENDIF.
  ENDIF.
*    Call synchronizer
*  REFRESH e071_loctab.
*  APPEND e071 TO e071_loctab.
*  PERFORM vim_synchronizer_call
*                USING e071_loctab[]
*                      corr_keytab[]
*                      'X'.

  CLEAR: <status>-upd_flag,
         <status>-upd_checkd.
  MESSAGE s018(sv).
ENDFORM.                               " TABLE_DB_UPD

*&--------------------------------------------------------------------*
*&      Form  TABLE_READ_SINGLE_ENTRY                                 *
*---------------------------------------------------------------------*
* read single entry from data base
*---------------------------------------------------------------------*
FORM table_read_single_entry.
  DATA: tab TYPE REF TO data, texttab TYPE REF TO data,
        textline TYPE REF TO data.

  FIELD-SYMBOLS: <tab> TYPE STANDARD TABLE,
                 <texttab> TYPE STANDARD TABLE,
                 <textline> TYPE ANY, <textline_x> TYPE x.

  CREATE DATA tab TYPE STANDARD TABLE OF (x_header-maintview).
  ASSIGN tab->* TO <tab>.
*  REFRESH mod_elem_tab.
*  MOVE <f1> TO gen_key.
  CALL FUNCTION 'DB_SELECT_GENERIC_TABLE'
       EXPORTING
            tablename   = x_header-maintview
*            genkey      = gen_key
            genkey      = <f1_x>
            genkey_ln   = x_header-keylen
       TABLES
*            inttab      = mod_elem_tab
            inttab      = <tab>
       EXCEPTIONS
            db_error    = 12
            not_found   = 04
            wrong_param = 08.
  IF sy-subrc > 4. RAISE get_table_error. ENDIF.
*  READ TABLE mod_elem_tab INDEX 1.
  READ TABLE <tab> INTO <table1> INDEX 1.
  IF sy-subrc <> 0.
    MOVE <initial> TO <table1>.
*  ELSE.
*    <table1> = mod_elem_tab.
  ENDIF.
  IF x_header-texttbexst NE space.
* read text table
    CREATE DATA texttab TYPE STANDARD TABLE OF (x_header-texttab).
    CREATE DATA textline TYPE (x_header-texttab).
    ASSIGN: texttab->* TO <texttab>,
            textline->* TO <textline>,
            <textline> TO <textline_x> CASTING.
*    REFRESH mod_elem_tab.
*    CLEAR gen_key.
*    WRITE <table1_text> TO gen_key(x_header-textkeylen).
    CALL FUNCTION 'DB_SELECT_GENERIC_TABLE'
         EXPORTING
              tablename   = x_header-texttab
*              genkey      = gen_key
              genkey      = <textkey_x>
              genkey_ln   = x_header-textkeylen
         TABLES
*              inttab      = mod_elem_tab
              inttab      = <texttab>
         EXCEPTIONS
              db_error    = 12
              not_found   = 04
              wrong_param = 08.
    IF sy-subrc > 4. RAISE get_table_error. ENDIF.
*    READ TABLE mod_elem_tab INDEX 1.
    READ TABLE <texttab> INTO <table1_text> INDEX 1.
    IF sy-subrc <> 0.
      MOVE <text_initial> TO <table1_text>.
      CLEAR sy-subrc.
*    ELSE.
*      <table1_text> = mod_elem_tab.
    ENDIF.
  ENDIF.
ENDFORM.                               " TABLE_READ_SINGLE_ENTRY

*&--------------------------------------------------------------------*
*&      Form  SET_TXT_UPDATE_FLAG                                     *
*---------------------------------------------------------------------*
* note, if texttab entry was modified on screen
*---------------------------------------------------------------------*
FORM set_txt_update_flag.

  IF <textkey_x> EQ <initial_textkey_x> OR "textkey not filled yet OR
     status-action EQ kopieren OR      "copy mode              OR
     neuer EQ 'J' OR <xact> EQ leer OR "real new entry         OR
     ( temporal_delimitation_happened EQ 'X' AND "temporal delimitation
        x_header-delmdtflag EQ 'B' ).
    PERFORM fill_texttab_key_uc USING <table1> <table1_text>.
  ENDIF.
  IF status-action EQ hinzufuegen.
    <status>-upd_flag = 'X'.           "always both tables must be added
  ELSE.
    TRANSLATE <status>-upd_flag USING ' TEX'.
  ENDIF.
ENDFORM.                               " SET_TXT_UPDATE_FLAG

*&--------------------------------------------------------------------*
*&      Form  FILL_TEXTTAB_KEY                                        *
*&--------------------------------------------------------------------*
*       Kept for downward compatibility only. Never use in unicode-
*       system. Use FILL_TEXTTAB_KEY instead                          *
*&--------------------------------------------------------------------*
FORM fill_texttab_key USING enti_wa text_wa.
  FIELD-SYMBOLS: <enti>, <text>.
  DATA: index TYPE i.
  LOOP AT x_namtab WHERE texttabfld NE space
                     AND keyflag NE space. "all keyfields of text table
    index = x_namtab-position - x_header-tablen.
    ASSIGN text_wa+index(x_namtab-flength) TO <text>.
    IF x_namtab-primtabkey EQ space.   "language key
      MOVE sy-langu TO <text>.
    ELSE.
      index = x_namtab-primtabkey.
      READ TABLE x_namtab INDEX index. "corresponding field of entity tb
      IF sy-subrc EQ 0.
        ASSIGN enti_wa+x_namtab-position(x_namtab-flength) TO <enti>.
        MOVE <enti> TO <text>.
      ENDIF.
    ENDIF.
  ENDLOOP.
ENDFORM.                               "FILL_TEXTTAB_KEY

*&--------------------------------------------------------------------*
*&      Form  FILL_TEXTTAB_KEY_UC                                     *
*&--------------------------------------------------------------------*
* ENTI_WA ---> WA of entity table                                     *
* TEXT_WA <--- WA of text table                                       *
*&--------------------------------------------------------------------*
FORM fill_texttab_key_uc USING enti_wa
                         CHANGING text_wa.
  FIELD-SYMBOLS: <namtab> TYPE vimnamtab, <namtab2> TYPE vimnamtab,
                 <enti> TYPE ANY, <text> TYPE ANY.
  DATA: index TYPE i.
  LOOP AT x_namtab ASSIGNING <namtab> WHERE texttabfld NE space
                     AND keyflag NE space.
* keyfield of text table
    ASSIGN COMPONENT <namtab>-viewfield OF STRUCTURE text_wa
     TO <text>.
    IF <namtab>-primtabkey EQ space.   "language key
      MOVE sy-langu TO <text>.
    ELSE.
      index = <namtab>-primtabkey.
      READ TABLE x_namtab ASSIGNING <namtab2> INDEX index.
* corresponding field of entity tb
      IF sy-subrc EQ 0.
        ASSIGN COMPONENT <namtab2>-viewfield OF STRUCTURE enti_wa
         TO <enti>.
        MOVE <enti> TO <text>.
      ENDIF.
    ENDIF.
  ENDLOOP.
ENDFORM.                               "FILL_TEXTTAB_KEY_UC

*&--------------------------------------------------------------------*
*&      Form CREATE_WHERETAB_NEW                                      *
*&--------------------------------------------------------------------*
* create where-tab for dynamic select                                 *
*&--------------------------------------------------------------------*
*        --> CW_TOTAL        table line
*            CW_TABLE        table the wheretab has to be filled for
*            CW_ENTI_KEY
*            CW_RC
*&--------------------------------------------------------------------*
FORM create_wheretab_new USING cw_namtab LIKE x_namtab[]
                               total_struc TYPE any
                               total_txt_struc TYPE any
                               value(cw_table) LIKE vimdesc-viewname
                               value(cw_enti_key) TYPE xfeld
                               cw_rc TYPE i.

  DATA: cw_sellist LIKE vimsellist OCCURS 10, cw_sel LIKE vimsellist,
        first(1) TYPE c VALUE 'X', w_namtab TYPE vimnamtab.
  FIELD-SYMBOLS: <cw_value> TYPE ANY,
                 <w_namtab2> TYPE vimnamtab.

  LOOP AT cw_namtab INTO w_namtab
                    WHERE keyflag NE space    "all textkeyfields
                      AND texttabfld NE space "with relations to
                      AND primtabkey NE 0.    "entity key fields
    CHECK w_namtab-datatype NE 'CLNT' OR first EQ space.
    TRANSLATE first USING 'X '.
*    IF cw_enti_key EQ space.
*      SUBTRACT x_header-tablen FROM w_namtab-position.
*    ENDIF.
*    ASSIGN cw_total+w_namtab-position(w_namtab-flength) "value of
*              TO <cw_value>.           "textkey
    IF cw_enti_key NE space.
      READ TABLE cw_namtab INDEX w_namtab-primtabkey
       ASSIGNING <w_namtab2>.           "corresp. enti key
      ASSIGN COMPONENT <w_namtab2>-viewfield OF
       STRUCTURE total_struc TO <cw_value>.
      cw_sel-viewfield = <w_namtab2>-viewfield.
    ELSE.
      ASSIGN COMPONENT w_namtab-viewfield OF
       STRUCTURE total_txt_struc TO <cw_value>.
      cw_sel-viewfield = w_namtab-viewfield.
    ENDIF.
    cw_sel-tabix     = sy-tabix.
    cw_sel-operator = 'EQ'.
    cw_sel-and_or = 'AND'.
    CALL FUNCTION 'VIEW_CONVERSION_OUTPUT'
         EXPORTING
              tabname      = cw_table
              fieldname    = cw_sel-viewfield
              value_intern = <cw_value>
*              inttype      = w_namtab-inttype
*              datatype     = w_namtab-datatype
*              decimals     = w_namtab-decimals
*              convexit     = w_namtab-convexit
*              sign         = w_namtab-sign
              outputlen    = w_namtab-outputlen
              intlen       = w_namtab-flength
         IMPORTING
              value_extern = cw_sel-value.
    IF cw_sel-value EQ space.
      cw_sel-initial = 'X'.
    ENDIF.
    CASE w_namtab-inttype.
      WHEN 'F'. cw_sel-fltp_value = <cw_value>.
      WHEN 'D'. cw_sel-date_value = <cw_value>.
      WHEN 'T'. cw_sel-time_value = <cw_value>.
      WHEN 'P'. cw_sel-pckd_value(w_namtab-flength) = <cw_value>.
      WHEN 'N'. cw_sel-numc_value(w_namtab-flength) = <cw_value>.
      WHEN 'C'. cw_sel-invd_value(w_namtab-flength) = <cw_value>.
      WHEN 'I'. cw_sel-int4_value = <cw_value>.
      WHEN 'X'.
        CASE w_namtab-datatype.
          WHEN 'INT1'. cw_sel-int1_value = <cw_value>.
          WHEN 'INT2'. cw_sel-int2_value = <cw_value>.
          WHEN 'INT4'. cw_sel-int4_value = <cw_value>.
          WHEN 'RAW'. cw_sel-raw_value(w_namtab-flength) = <cw_value>.
        ENDCASE.
    ENDCASE.
    cw_sel-converted = 'X'.
    APPEND cw_sel TO cw_sellist.
    CLEAR cw_sel.
  ENDLOOP.
  DESCRIBE TABLE cw_sellist.
  READ TABLE cw_sellist INTO cw_sel INDEX sy-tfill.
  IF cw_sel-and_or NE space.
    CLEAR cw_sel-and_or. MODIFY cw_sellist INDEX sy-tfill FROM cw_sel.
  ENDIF.
  CALL FUNCTION 'VIEW_FILL_WHERETAB'
    EXPORTING
      tablename               = cw_table
      only_cnds_for_keyflds   = 'X'
    TABLES
      sellist                 = cw_sellist
      wheretab                = vim_wheretab
      x_namtab                = cw_namtab
    EXCEPTIONS
      no_conditions_for_table = 01.
  cw_rc = sy-subrc.
ENDFORM.                               "create_wheretab_new
*&--------------------------------------------------------------------*
*&      Form CREATE_WHERETAB                                          *
*&--------------------------------------------------------------------*
*       Kept for downward compatibility only. Never use in unicode-
*       system. Use CREATE_WHERETAB_NEW instead.
*&--------------------------------------------------------------------*
*        --> CW_TOTAL        table line
*            CW_TABLE        table name
*            CW_ENTI_KEY
*            CW_RC
*&--------------------------------------------------------------------*
FORM create_wheretab TABLES cw_namtab STRUCTURE vimnamtab
                     USING value(cw_total)
                           value(cw_table) LIKE vimdesc-viewname
                           value(cw_enti_key) TYPE c
                           cw_rc TYPE i.
  DATA: cw_sellist LIKE vimsellist OCCURS 10, cw_sel LIKE vimsellist,
        first(1) TYPE c VALUE 'X'.
  FIELD-SYMBOLS: <cw_value>.

  LOOP AT cw_namtab WHERE keyflag NE space    "all textkeyfields
                      AND texttabfld NE space "with relations to
                      AND primtabkey NE 0.    "entity key fields
    CHECK cw_namtab-datatype NE 'CLNT' OR first EQ space.
    TRANSLATE first USING 'X '.
    IF cw_enti_key EQ space.
      SUBTRACT x_header-tablen FROM cw_namtab-position.
    ENDIF.
    ASSIGN cw_total+cw_namtab-position(cw_namtab-flength) "value of
              TO <cw_value>.           "textkey
    IF cw_enti_key NE space.
      READ TABLE cw_namtab INDEX cw_namtab-primtabkey."corresp. enti key
    ENDIF.
    cw_sel-viewfield = cw_namtab-viewfield.
    cw_sel-tabix     = sy-tabix.
    cw_sel-operator = 'EQ'.
    cw_sel-and_or = 'AND'.
    CALL FUNCTION 'VIEW_CONVERSION_OUTPUT'
      EXPORTING
        value_intern = <cw_value>
        inttype      = cw_namtab-inttype
        datatype     = cw_namtab-datatype
        decimals     = cw_namtab-decimals
        convexit     = cw_namtab-convexit
        sign         = cw_namtab-sign
        outputlen    = cw_namtab-outputlen
        intlen       = cw_namtab-flength
      IMPORTING
        value_extern = cw_sel-value.
    IF cw_sel-value EQ space.
      cw_sel-initial = 'X'.
    ENDIF.
* SW 5.8.98 ..
* folgende MOVE's führen zu unerwünschten impliziten Konvertierungen
* und damit zu Laufzeitfehler
    CLEAR cw_sel-converted.
*   case cw_namtab-inttype.
*     when 'F'. cw_sel-fltp_value = <cw_value>.
*     when 'D'. cw_sel-date_value = <cw_value>.
*     when 'T'. cw_sel-time_value = <cw_value>.
*     when 'P'. cw_sel-pckd_value(cw_namtab-flength) = <cw_value>.
*     when 'N'. cw_sel-numc_value(cw_namtab-flength) = <cw_value>.
*     when 'C'. cw_sel-invd_value(cw_namtab-flength) = <cw_value>.
*     when 'I'. cw_sel-int4_value = <cw_value>.
*     when 'X'.
*       case cw_namtab-datatype.
*         when 'INT1'. cw_sel-int1_value = <cw_value>.
*         when 'INT2'. cw_sel-int2_value = <cw_value>.
*         when 'INT4'. cw_sel-int4_value = <cw_value>.
*         when 'RAW'. cw_sel-raw_value(cw_namtab-flength) = <cw_value>.
*       endcase.
*   endcase.
*   cw_sel-converted = 'X'.                                ".. SW 5.8.98
    APPEND cw_sel TO cw_sellist.
  ENDLOOP.
  DESCRIBE TABLE cw_sellist.
  READ TABLE cw_sellist INTO cw_sel INDEX sy-tfill.
  IF cw_sel-and_or NE space.
    CLEAR cw_sel-and_or. MODIFY cw_sellist INDEX sy-tfill FROM cw_sel.
  ENDIF.
  CALL FUNCTION 'VIEW_FILL_WHERETAB'
    EXPORTING
      tablename               = cw_table
      only_cnds_for_keyflds   = 'X'
    TABLES
      sellist                 = cw_sellist
      wheretab                = vim_wheretab
      x_namtab                = cw_namtab
    EXCEPTIONS
      no_conditions_for_table = 01.
  cw_rc = sy-subrc.
ENDFORM.                               "create_wheretab

*&--------------------------------------------------------------------*
*&      Form  TABLEFRAME                                              *
*&--------------------------------------------------------------------*
* program for function TABLEFRAME_<area>                              *
*&--------------------------------------------------------------------*
FORM  tableframe TABLES header STRUCTURE vimdesc
                        namtab STRUCTURE vimnamtab
                        dbasellist STRUCTURE vimsellist
                        dplsellist STRUCTURE vimsellist
                        exclcuafunct STRUCTURE vimexclfun
                 USING  corrnumber
                        viewaction
                        viewname.

  DATA: enqueue_processed TYPE c, "flag: view enqueued by VIEWFRAME_..
        table_type(11) TYPE c,         "type of table to use
        table_length TYPE i.           "length of current table

*-<<<-------------------------------------------------------------->>>>*
* first of all: determine well-sized internal tables etc.              *
*-<<<-------------------------------------------------------------->>>>*
  READ TABLE header INDEX 1.
  table_length = header-tablen / cl_abap_char_utilities=>charsize + 2.
*  tab lg. + action + mark
  IF header-texttbexst NE space.
    table_length = table_length
     + header-texttablen / cl_abap_char_utilities=>charsize + 1.
* txtb+txtact
  ENDIF.
  IF table_length LE ultra_short_tab.
    MOVE 'ULTRA_SHORT'     TO table_type.
    FREE: extract_vs, total_vs,
          extract_s, total_s,
          extract_m, total_m,
          extract_l, total_l,
          extract_vl, total_vl,
          extract_ul, total_ul.
  ELSEIF table_length LE very_short_tab.
    MOVE 'VERY_SHORT'     TO table_type.
    FREE: extract_us, total_us,
          extract_s, total_s,
          extract_m, total_m,
          extract_l, total_l,
          extract_vl, total_vl,
          extract_ul, total_ul.
  ELSEIF table_length LE short_tab.
    MOVE 'SHORT'     TO table_type.
    FREE: extract_us, total_us,
          extract_vs, total_vs,
          extract_m, total_m,
          extract_l, total_l,
          extract_vl, total_vl,
          extract_ul, total_ul.
  ELSEIF table_length LE middle_tab.
    MOVE 'MIDDLE'    TO table_type.
    FREE: extract_us, total_us,
          extract_vs, total_vs,
          extract_s, total_s,
          extract_l, total_l,
          extract_vl, total_vl,
          extract_ul, total_ul.
  ELSEIF table_length LE long_tab.
    MOVE 'LONG'    TO table_type.
    FREE: extract_us, total_us,
          extract_vs, total_vs,
          extract_s, total_s,
          extract_m, total_m,
          extract_vl, total_vl,
          extract_ul, total_ul.
  ELSEIF table_length LE very_long_tab.
    MOVE 'VERY_LONG'    TO table_type.
    FREE: extract_us, total_us,
          extract_vs, total_vs,
          extract_s, total_s,
          extract_m, total_m,
          extract_l, total_l,
          extract_ul, total_ul.
  ELSEIF table_length LE ultra_long_tab.
    MOVE 'ULTRA_LONG'    TO table_type.
    FREE: extract_us, total_us,
          extract_vs, total_vs,
          extract_s, total_s,
          extract_m, total_m,
          extract_l, total_l,
          extract_vl, total_vl.
  ENDIF.
  maint_mode = viewaction.
  corr_nbr = corrnumber.
*-<<<-------------------------------------------------------------->>>>*
* Entrypoint after changing maintenance mode (show <--> update)        *
*-<<<-------------------------------------------------------------->>>>*
  DO.
*----------------------------------------------------------------------*
* Select data from database                                            *
*----------------------------------------------------------------------*
    PERFORM table_call_function TABLES dbasellist dplsellist
                                header namtab exclcuafunct
                                USING read table_type update_flag.
    CASE sy-subrc.
      WHEN 1.
        RAISE missing_corr_number.
    ENDCASE.
*-<<<-------------------------------------------------------------->>>>*
* Entrypoint after saving data into database                           *
* Entrypoint after refreshing selected entries from database           *
*-<<<-------------------------------------------------------------->>>>*
    DO.
*----------------------------------------------------------------------*
* Edit data                                                            *
*----------------------------------------------------------------------*
      DO.
        PERFORM table_call_function
                             TABLES dbasellist dplsellist
                                    header namtab exclcuafunct
                             USING edit table_type <status>-upd_flag.
        CASE sy-subrc.
          WHEN 1.
            IF maint_mode EQ transportieren AND viewaction EQ aendern.
              MOVE viewaction TO maint_mode.
            ELSE.
              RAISE missing_corr_number.
            ENDIF.
          WHEN OTHERS.
            EXIT.
        ENDCASE.
      ENDDO.
*----------------------------------------------------------------------*
*  Handle usercommands...                                              *
*  ...at first handle commands which could cause loss of data          *
*----------------------------------------------------------------------*
      IF function EQ back.
        function = end.
      ENDIF.
      IF ( function EQ switch_to_show_mode OR
           function EQ get_another_view    OR
           function EQ switch_transp_to_upd_mode OR
           function EQ end ) AND
         <status>-upd_flag NE space.
        PERFORM beenden.
        CASE sy-subrc.
          WHEN 0.
            PERFORM table_call_function
                         TABLES dbasellist dplsellist
                                header namtab exclcuafunct
                         USING save table_type <status>-upd_flag.
            CASE sy-subrc.
              WHEN 0.
                IF <status>-upd_flag EQ space. EXIT. ENDIF.
              WHEN 1.
                RAISE missing_corr_number.
              WHEN 3.
            ENDCASE.
          WHEN 8.
            EXIT.
          WHEN 12.
        ENDCASE.
*----------------------------------------------------------------------*
*  ...2nd: transport request                                           *
*----------------------------------------------------------------------*
      ELSEIF function EQ transport.
        IF <status>-upd_flag NE space.
          PERFORM transportieren.
          CASE sy-subrc.
            WHEN 0.
              PERFORM table_call_function
                              TABLES dbasellist dplsellist
                                     header namtab exclcuafunct
                              USING save table_type <status>-upd_flag.
              CASE sy-subrc.
                WHEN 0.
                  maint_mode = transportieren.
                WHEN 1.
                  RAISE missing_corr_number.
                WHEN 3.
              ENDCASE.
            WHEN 8.
              EXIT.
            WHEN 12.
          ENDCASE.
        ELSE.
          maint_mode = transportieren.
        ENDIF.
*----------------------------------------------------------------------*
*  ...now reset or save requests                                       *
*----------------------------------------------------------------------*
      ELSEIF function EQ reset_list  OR
             function EQ reset_entry OR
             function EQ save.
*----------------------------------------------------------------------*
*  Refresh selected entries from database or save data into database   *
*----------------------------------------------------------------------*
        PERFORM table_call_function
                          TABLES dbasellist dplsellist
                                 header namtab exclcuafunct
                          USING function table_type <status>-upd_flag.
        CASE sy-subrc.
          WHEN 1.
            RAISE missing_corr_number.
          WHEN 3.
        ENDCASE.
      ELSE.
        EXIT.
      ENDIF.
    ENDDO.
*----------------------------------------------------------------------*
*  ...now other commands...                                            *
*----------------------------------------------------------------------*
    CASE function.
      WHEN switch_to_show_mode.
*   change maintenance mode from update to show
        PERFORM enqueue USING 'D' header-frm_af_enq. "dequeue view
        CLEAR enqueue_processed.
        maint_mode = anzeigen.
      WHEN switch_to_update_mode.
*     change maintenance mode from show to update
        PERFORM enqueue USING 'E' header-frm_af_enq.  "enqueue view
        IF sy-subrc EQ 0.
          MOVE 'X' TO enqueue_processed.
          maint_mode = aendern.
        ENDIF.
      WHEN switch_transp_to_upd_mode.
*     change maintenance mode from transport to update
        maint_mode = aendern.
      WHEN transport.
*     change maintenance mode from update to transport
        maint_mode = transportieren.
      WHEN OTHERS.
        IF enqueue_processed NE space.
          PERFORM enqueue USING 'D' header-frm_af_enq."dequeue view
        ENDIF.
        PERFORM before_leaving_frame_function
                                      USING header-frm_bf_end.
        EXIT.
    ENDCASE.
  ENDDO.
ENDFORM.                                                    "

*&--------------------------------------------------------------------*
*&      Form TABLEPROC                                                *
*&--------------------------------------------------------------------*
* program for function TABLEPROC_<area>                               *
*&--------------------------------------------------------------------*
FORM  tableproc.
*----------------------------------------------------------------------*
* Initialization: set field-symbols etc.                               *
*----------------------------------------------------------------------*
  IF last_view_info NE view_name.
    PERFORM initialisieren.
  ENDIF.
  PERFORM justify_action_mode.
  MOVE: view_action TO maint_mode,
        corr_number TO corr_nbr.

*----------------------------------------------------------------------*
* Get data from database                                               *
*----------------------------------------------------------------------*
  IF fcode EQ read OR fcode EQ read_and_edit.
    PERFORM prepare_read_request.
    IF x_header-frm_rp_get NE space.
      PERFORM (x_header-frm_rp_get) IN PROGRAM (sy-repid).
    ELSE.
      PERFORM table_get_data.
    ENDIF.
    IF fcode EQ read_and_edit. fcode = edit. ENDIF.
  ENDIF.

  CASE fcode.
    WHEN  edit.                        " Edit read data
      PERFORM call_dynpro.
      PERFORM check_upd.
*....................................................................*

    WHEN save.                         " Write data into database
      PERFORM prepare_saving.
      IF <status>-upd_flag NE space.
        IF x_header-frm_rp_upd NE space.
          PERFORM (x_header-frm_rp_upd) IN PROGRAM.
        ELSE.
          IF sy-subrc EQ 0.
            PERFORM table_db_upd.
          ENDIF.
        ENDIF.
        PERFORM after_saving.
      ENDIF.
*....................................................................*

    WHEN reset_list.     " Refresh all marked entries of EXTRACT from db
      PERFORM reset_entries USING list_bild.
*....................................................................*

    WHEN reset_entry.               " Refresh single entry from database
      PERFORM reset_entries USING detail_bild.
*.......................................................................
  ENDCASE.
  MOVE: <status>-upd_flag TO update_required,
        function TO ucomm.
ENDFORM.                               "tableproc

*&--------------------------------------------------------------------*
*&      FORM  REPLACE_FORBIDDEN_CHARS                                 *
*&--------------------------------------------------------------------*
* replace forbidden characters with internal code into NAME           *
*---------------------------------------------------------------------*
* ---> NAME - name to correct                                         *
* ---> FORBIDDEN_CHARS - chars which must be replaced                 *
* <--- NAME - corrected name                                          *
*&--------------------------------------------------------------------*
FORM  replace_forbidden_chars USING value(forbidden_chars) name.
  FIELD-SYMBOLS: <code>.
  DATA: suspect_char(1) TYPE c, code(2) TYPE c.

  DO.
    IF name CA forbidden_chars.
      ASSIGN name+sy-fdpos(1)  TO <code>.
      MOVE <code> TO suspect_char.
      ASSIGN <code> TO <code> TYPE 'X'.
      MOVE <code> TO code.
      REPLACE suspect_char WITH code INTO name.
    ELSE.
      EXIT.
    ENDIF.
  ENDDO.
ENDFORM.                               "replace_forbidden_chars
*&---------------------------------------------------------------------*
*&      Form  vim_get_text_keyflds
*&---------------------------------------------------------------------*
*       inserts all key field names of a texttable into a table
*----------------------------------------------------------------------*
*      -->P_TEXTTABNAME   text table name
*      <--P_TEXT_KEYFLDS  table of keyfields
*----------------------------------------------------------------------*
FORM vim_get_text_keyflds USING p_texttabname TYPE tabname
                         CHANGING p_text_keyflds TYPE vim_flds_tab_type.

  STATICS: texttabname_save TYPE tabname,
           text_keyflds_save TYPE vim_flds_tab_type.

  FIELD-SYMBOLS: <namtab> TYPE vimnamtab.

  REFRESH p_text_keyflds.
  IF texttabname_save = p_texttabname.
    APPEND LINES OF text_keyflds_save TO p_text_keyflds.
  ELSE.
    texttabname_save = p_texttabname.
    REFRESH text_keyflds_save.
    LOOP AT x_namtab ASSIGNING <namtab> WHERE texttabfld NE space
                       AND keyflag NE space.
      APPEND <namtab>-viewfield TO p_text_keyflds.
    ENDLOOP.
    APPEND LINES OF p_text_keyflds TO text_keyflds_save.
  ENDIF.
ENDFORM.                               " vim_get_text_keyflds
*---------------------------------------------------------------------*
*    view related PAI modules
*   generation date: 30.12.2012 at 22:57:55 by user CREYTZ
*   view maintenance generator version: #001407#
*---------------------------------------------------------------------*

***INCLUDE LSVIMITX .
MODULE SET_TXT_UPDATE_FLAG.
  PERFORM SET_TXT_UPDATE_FLAG.
ENDMODULE.

*      general include-files        (never change, please)        *
***INCLUDE LSVIMFXL.
* SW 25.3.1997
*    Readonly-Felder in Texttabelle berücksichtigen

* SW 14.7.1998
*    Import für Texte in anderen Sprachen    "Textimp

* SW 17.9.1998
*    beim Kopieren Texte in anderen Sprachen berücksichtigen   "Textcopy
* UF 19.10.1998: DB-Zugriffe in Include LSVIMFL1 verlagert
*----------------------------------------------------------------------*
*   INCLUDE LSVIMFL1
**----------------------------------------------------------------------
*
*---------------------------------------------------------------------*
*       FORM VIM_GET_TEXTTAB_DATA                                     *
*---------------------------------------------------------------------*
* Texteinträge von der DB nachlesen für angeg. Sprachen               *
* UFProbl251070/1998: Falls X_NAMTAB-Reihenfolge nicht mit
*                     DBA-SELLIST-Reihenfolge übereinstimmt, werden
*                     ANDs oder ORs verschluckt.
*---------------------------------------------------------------------*
*  --> LANGUS         ausgewählte Sprachen
* <--> TEXTTAB
*---------------------------------------------------------------------*
FORM vim_get_texttab_data TABLES langus STRUCTURE h_t002
                          CHANGING texttab TYPE table.
*                                  Type VIM_LINE_US/../VIM_LINE_UL
  DATA: tgd_sellist LIKE vimsellist OCCURS 10, tgd_sel LIKE vimsellist,
        wheretab_line LIKE vimwheretb,
        spras_value(3) TYPE c,
*        curr_spras(1) TYPE c,
        keylen TYPE i,
        l TYPE i, sellist_l TYPE i, tbx TYPE i,
        and_or_str(6) TYPE c, left_par(1) TYPE c,
        tmp_texttab TYPE REF TO data,
        tmp_texttab_wa TYPE REF TO data,
*        tmp_texttab TYPE vim_tab_ul WITH HEADER LINE,
        texttab_tabix LIKE sy-tabix,
        align1 type f,
        texttab_wa TYPE vim_line_ul,
        align2 type f,
        view_wa TYPE tabl8000, map_error TYPE xfeld.
  FIELD-SYMBOLS: <tmp_texttab> TYPE STANDARD TABLE,
                 <tmp_texttab_wa> TYPE ANY, <tmp_texttab_wax> TYPE x,
                 <view_key> TYPE x, <next_spras> TYPE spras,
                 <curr_spras> TYPE spras,
                 <h_texttab> TYPE x, <h_texttab_wa> TYPE x,
                 <viewkey_in_texttab> TYPE x, <texttab_struc> TYPE ANY.

  CREATE DATA: tmp_texttab TYPE STANDARD TABLE OF (x_header-texttab),
               tmp_texttab_wa TYPE (x_header-texttab).
  ASSIGN: tmp_texttab->* TO <tmp_texttab>,
          tmp_texttab_wa->* TO <tmp_texttab_wa>,
          <tmp_texttab_wa> TO <tmp_texttab_wax> CASTING.

  IF x_header-selection NE space.
    LOOP AT dba_sellist INTO tgd_sel       "UFProbl251070/1998
     WHERE value <> space OR initial = 'X'.
      LOOP AT x_namtab WHERE viewfield EQ tgd_sel-viewfield
                       AND keyflag NE space AND txttabfldn NE space.
        tgd_sel-viewfield = x_namtab-txttabfldn.
        tgd_sel-tabix     = sy-tabix.
        APPEND tgd_sel TO tgd_sellist.
        EXIT.
      ENDLOOP.
    ENDLOOP.                                "UFProbl251070/1998
  ENDIF.                               "X_HEADER-SELECTION

  DESCRIBE TABLE tgd_sellist LINES sellist_l.
  IF sellist_l > 0.
    READ TABLE tgd_sellist INDEX sellist_l INTO tgd_sel.
    IF tgd_sel-and_or NE space.
      CLEAR tgd_sel-and_or.
      MODIFY tgd_sellist INDEX sellist_l FROM tgd_sel.
    ENDIF.
    CALL FUNCTION 'VIEW_FILL_WHERETAB'
         EXPORTING
              tablename               = x_header-texttab
              only_cnds_for_keyflds   = 'X'
              is_texttable            = 'X'
         TABLES
              sellist                 = tgd_sellist
              wheretab                = vim_wheretab
              x_namtab                = x_namtab
         EXCEPTIONS
              no_conditions_for_table = 01.
    IF sy-subrc = 1. sellist_l = 0. ENDIF.
  ELSE.
    REFRESH vim_wheretab.
  ENDIF.

* VIM_WHERETAB um Bedingungen für ausgew. Sprachen ergänzen
  DESCRIBE TABLE langus LINES l.
  IF l > 1.
    and_or_str = 'OR'.
    IF sellist_l > 0.
      left_par = '('.
    ENDIF.
  ENDIF.
  tbx = 1.
  spras_value = ''' '''.
  LOOP AT langus.
    spras_value+1(1) = langus-spras.
    IF tbx = l.      " letzte Zeile für Sprachselektion
      IF l > 1 AND sellist_l > 0.
        and_or_str = ' ) AND'.
      ELSEIF l = 1 AND sellist_l > 0.
        and_or_str = ' AND'.
      ELSE.
        CLEAR and_or_str.
      ENDIF.
    ENDIF.
   CONCATENATE left_par x_header-sprasfield 'EQ' spras_value and_or_str
                            INTO wheretab_line SEPARATED BY space.
    INSERT wheretab_line INTO vim_wheretab INDEX tbx.
    CLEAR left_par.
    tbx = tbx + 1.
  ENDLOOP.

  SELECT * FROM (x_header-texttab) INTO TABLE <tmp_texttab>
                                      WHERE (vim_wheretab).

* Texttabellen-Einträge sortiert in Texttabelle einfügen
  IF x_header-delmdtflag <> space AND  "zeitabh. & part. Fremdschl.
     x_header-ptfrkyexst  = 'X'.       "      -> zeitunabh. Texttab.
    keylen = x_header-after_keyc
              - vim_datum_length * cl_abap_char_utilities=>charsize.
  ELSE.
    keylen = x_header-after_keyc.
  ENDIF.
  ASSIGN: view_wa(keylen) TO <view_key>,
          texttab_wa TO <h_texttab_wa> CASTING,
          <h_texttab_wa>(keylen) TO <viewkey_in_texttab>,
          <h_texttab_wa>+keylen(x_header-texttablen) TO <h_texttab>,
          <h_texttab> TO <texttab_struc>
           CASTING TYPE (x_header-texttab),
          COMPONENT x_header-sprasfield OF STRUCTURE <texttab_struc>
           TO <next_spras>,
          COMPONENT x_header-sprasfield OF STRUCTURE <tmp_texttab_wa>
           TO <curr_spras>.
  LOOP AT <tmp_texttab> INTO <tmp_texttab_wa>.
    PERFORM map_texttabkey_to_viewkey TABLES x_namtab
                                      USING x_header
                                            <tmp_texttab_wax>
                                            x_header-textkeylen
                                            x_header-genertxtrp
                                      CHANGING <view_key>
                                               map_error.
    CHECK map_error = space.
*    PERFORM vim_fill_view_key USING tmp_texttab
*                           CHANGING <view_key> curr_spras.
    CLEAR texttab_wa.
    READ TABLE texttab WITH KEY <view_key> INTO texttab_wa
                                                        BINARY SEARCH.
    texttab_tabix = sy-tabix.
    IF sy-subrc = 0 AND
      <viewkey_in_texttab> = <view_key> AND  "Text ex. in weiteren Spr
      <next_spras> < <curr_spras>. "#EC PORTABLE
      LOOP AT texttab FROM texttab_tabix INTO texttab_wa.
        IF <viewkey_in_texttab> <> <view_key> OR
           <next_spras> >= <curr_spras>. "#EC PORTABLE
          texttab_tabix = sy-tabix.
          EXIT.
        ELSEIF <next_spras> < <curr_spras>. "#EC PORTABLE
          texttab_tabix = sy-tabix + 1.
        ENDIF.
      ENDLOOP.
    ENDIF.   " <next_spras> >= <curr_spras> oder ex. nicht
    IF <next_spras> <> <curr_spras> OR
       <viewkey_in_texttab> <> <view_key>.  "Text ex. nicht in Sprache
      CLEAR texttab_wa.
      <viewkey_in_texttab> = <view_key>.
      <texttab_struc> = <tmp_texttab_wa>.
      INSERT texttab_wa INTO texttab INDEX texttab_tabix.
    ELSE.
      <texttab_struc> = <tmp_texttab_wa>.
      MODIFY texttab FROM texttab_wa INDEX texttab_tabix.
    ENDIF.

  ENDLOOP.                             " tmp_texttab
ENDFORM.                               "VIM_GET_TEXTTAB_DATA

*---------------------------------------------------------------------*
*       FORM VIM_READ_TEXTTAB_ENTRY                                   *
*---------------------------------------------------------------------*
* einzelnen Texttabellen-Eintrag für alle bisher bearbeiteten         *
* Sprachen nachlesen
* Aktueller Eintrag steht in Kopfzeile von EXTRACT
*---------------------------------------------------------------------*
FORM vim_read_texttab_entry.
  DATA: texttab_wa TYPE vim_line_ul,
        texttab_tabix LIKE sy-tabix,
        keylen TYPE i,
        offset TYPE i,
        modify_texttab(1) TYPE c,
        tmp_texttab TYPE ref to data,
        w_tmp_texttab type ref to data.
  FIELD-SYMBOLS: <h_texttab_wa> type x,
                 <viewkey_in_texttab> type x,
                 <texttab_key> type x,
                 <texttab_fields>, <texttab_action> type c,
                 <extract_key> type x,
                 <tmp_texttab> type standard table,
                 <w_tmp_texttab> type any,
                 <w_tmp_texttab_x> type x.

  IF x_header-delmdtflag <> space AND  "zeitabh. & part. Fremdschl.
     x_header-ptfrkyexst  = 'X'.       "      -> zeitunabh. Texttab.
    ASSIGN <vim_ext_mkey_beforex> TO <extract_key>.
*    ASSIGN <vim_ext_mkey_before> TO <extract_key>.
    keylen = x_header-keylen
              - vim_datum_length * cl_abap_char_utilities=>charsize.
  ELSE.
    ASSIGN <vim_xextract_key> TO <extract_key>.
     keylen = x_header-after_keyc.
*    keylen = x_header-keylen.
  ENDIF.

  READ TABLE <vim_texttab> WITH KEY <extract_key>
                           BINARY SEARCH TRANSPORTING NO FIELDS.
  IF sy-subrc = 0.
    texttab_tabix = sy-tabix.
  ELSE.
    EXIT.     "keine Texte zum Key in anderen Sprachen erfaßt
  ENDIF.

  ASSIGN: texttab_wa TO <h_texttab_wa> casting,
          <h_texttab_wa>+keylen(x_header-textkeylen) TO <texttab_key>,
          <h_texttab_wa>+keylen(x_header-texttablen)
           TO <texttab_fields>.
*  ASSIGN texttab_wa(keylen) TO <viewkey_in_texttab>.
*  ASSIGN texttab_wa+keylen(x_header-textkeylen) TO <texttab_key>.
*  ASSIGN texttab_wa+keylen(x_header-texttablen) TO <texttab_fields>.
  offset = ( keylen + x_header-texttablen )
           / cl_abap_char_utilities=>charsize.
*  offset = keylen + x_header-texttablen.
  ASSIGN texttab_wa+offset(1) TO <texttab_action>.

  create data tmp_texttab type standard table of (x_header-texttab).
  create data w_tmp_texttab type (x_header-texttab).
  assign: tmp_texttab->* to <tmp_texttab>,
          w_tmp_texttab->* to <w_tmp_texttab>,
          <w_tmp_texttab> to <w_tmp_texttab_x> casting.
  LOOP AT <vim_texttab> FROM texttab_tabix INTO texttab_wa.
    IF <viewkey_in_texttab> <> <extract_key>. EXIT. ENDIF.
    IF <texttab_action> = neuer_eintrag.
      DELETE <vim_texttab>.
      modify_texttab = 'X'.
    ELSEIF <texttab_action> <> original.
      refresh <tmp_texttab>.
*      REFRESH tmp_texttab.
      CALL FUNCTION 'DB_SELECT_GENERIC_TABLE'
           EXPORTING
                genkey      = <texttab_key>
                genkey_ln   = x_header-textkeylen
                tablename   = x_header-texttab
           TABLES
                inttab      = <tmp_texttab>
*                inttab      = tmp_texttab
           EXCEPTIONS
                db_error    = 12
                not_found   = 04
                wrong_param = 08.
      IF sy-subrc > 4. RAISE get_table_error. ENDIF.

      READ TABLE <tmp_texttab> into <w_tmp_texttab> INDEX 1.
*      READ TABLE tmp_texttab INDEX 1.
      IF sy-subrc = 0.
        <texttab_fields> = <w_tmp_texttab_x>(x_header-texttablen).
*        <texttab_fields> = tmp_texttab(x_header-texttablen).
        <texttab_action> = original.
        MODIFY <vim_texttab> FROM texttab_wa.
        modify_texttab = 'X'.
      ELSE.                            "NOT_FOUND
        DELETE <vim_texttab>.
        modify_texttab = 'X'.
      ENDIF.
    ENDIF.
  ENDLOOP.
  IF modify_texttab = 'X'.
    MODIFY vim_texttab_container INDEX vim_texttab_container_index.
    CLEAR sy-subrc.
  ELSE.
    sy-subrc = 4.
  ENDIF.
ENDFORM.                               "VIM_READ_TEXTTAB_ENTRY

*---------------------------------------------------------------------*
*       FORM VIM_TEXTTAB_DB_UPD                                       *
*---------------------------------------------------------------------*
* Datenbank-Änderungen für Texttabelle (für spras <> SY-LANGU)        *
* Action_Flag in <VIM_TEXTTAB> für modif. Einträge zurücksetzen
* gelöschte Einträge aus interner Text-Tabelle löschen
*---------------------------------------------------------------------*
FORM vim_texttab_db_update.
  DATA: modified_entries TYPE i,
        texttab_modified(1) TYPE c,
        keylen TYPE i,
        offset TYPE i,
        align type f, texttab_wa TYPE vim_line_ul, "HCG never separate
        tmp_texttab TYPE REF TO data,
        w_tmp_texttab TYPE REF TO data.
*        tmp_texttab TYPE vim_tab_ul WITH HEADER LINE.
  FIELD-SYMBOLS: <tmp_texttab> TYPE STANDARD TABLE,
                 <w_tmp_texttab> TYPE ANY,
                 <h_texttab_wa> TYPE x, <h_texttab_fields> TYPE x,
                 <texttab_fields> TYPE ANY, <texttab_action>.

  CLEAR texttab_modified.
  CHECK x_header-texttbexst <> space.
  IF x_header-delmdtflag <> space AND  "zeitabh. & part. Fremdschl.
     x_header-ptfrkyexst  = 'X'.       "      -> zeitunabh. Texttab.
    keylen = x_header-after_keyc
             - vim_datum_length * cl_abap_char_utilities=>charsize.
  ELSE.
    keylen = x_header-after_keyc.
  ENDIF.

  CREATE DATA: tmp_texttab TYPE STANDARD TABLE OF (x_header-texttab),
               w_tmp_texttab TYPE (x_header-texttab).
  ASSIGN: tmp_texttab->* TO <tmp_texttab>,
          w_tmp_texttab->* TO <w_tmp_texttab>,
          texttab_wa TO <h_texttab_wa> CASTING,
          <h_texttab_wa>+keylen(x_header-texttablen)
           TO <h_texttab_fields>,
          <h_texttab_fields> TO <texttab_fields>
           CASTING TYPE (x_header-texttab).
  offset = ( keylen + x_header-aft_txttbc )
           / cl_abap_char_utilities=>charsize.
  ASSIGN texttab_wa+offset(1) TO <texttab_action>.

* DELETE: nur in interner Texttabelle, in DB schon bisher für alle Spr.
  LOOP AT <vim_texttab> INTO texttab_wa.
    CHECK <texttab_action> EQ geloescht OR
          <texttab_action> EQ neuer_geloescht OR
          <texttab_action> EQ update_geloescht.
    DELETE <vim_texttab>.
    texttab_modified = 'X'.
  ENDLOOP.                             "<VIM_TEXTTAB>

* UPDATE
  CLEAR modified_entries. REFRESH <tmp_texttab>.
  LOOP AT <vim_texttab> INTO texttab_wa.
    CHECK <texttab_action> EQ aendern.
    APPEND <texttab_fields> TO <tmp_texttab>.
*    tmp_texttab  = <texttab_fields>.
*    APPEND tmp_texttab.
    modified_entries = modified_entries + 1.
    <texttab_action> = original.
    MODIFY <vim_texttab> FROM texttab_wa.
  ENDLOOP.                             "<VIM_TEXTTAB>
  IF modified_entries > 0.
    UPDATE (x_header-texttab) FROM TABLE <tmp_texttab>.
    texttab_modified = 'X'.
  ENDIF.

* INSERT
  CLEAR modified_entries. REFRESH <tmp_texttab>.
  LOOP AT <vim_texttab> INTO texttab_wa.
    CHECK <texttab_action> EQ neuer_eintrag.
    APPEND <texttab_fields> TO <tmp_texttab>.
*    tmp_texttab = <texttab_fields>.
*    APPEND tmp_texttab.
    modified_entries = modified_entries + 1.
    <texttab_action> = original.
    MODIFY <vim_texttab> FROM texttab_wa.
  ENDLOOP.                             "<VIM_TEXTTAB>
  IF modified_entries > 0.
    INSERT (x_header-texttab) FROM TABLE <tmp_texttab>
           ACCEPTING DUPLICATE KEYS. "um RABAX bei unzulässigem
    "Texttab-Aufbau zu vermeiden
    texttab_modified = 'X'.
  ENDIF.

  IF texttab_modified = 'X'.
    MODIFY vim_texttab_container INDEX vim_texttab_container_index.
  ENDIF.
ENDFORM.                               "VIM_TEXTTAB_DB_UPDATE

* Import für Texte in anderen Sprachen                      "Textimp ...
*---------------------------------------------------------------------*
*       FORM VIM_READ_TEXTTAB_ALL_LANGUS                              *
*---------------------------------------------------------------------*
* Texteinträge von der DB für alle Sprachen einlesen.                 *
*---------------------------------------------------------------------*
FORM vim_read_texttab_all_langus.
  DATA: langus_selected(1) TYPE c,
        curr_sptxt LIKE t002t-sptxt,
        sel_langus LIKE h_t002 OCCURS 0 WITH HEADER LINE.

  CALL FUNCTION 'VIEW_GET_LANGUAGES'
       EXPORTING
            all_without_selection = 'X'
       IMPORTING
            languages_selected    = langus_selected
            curr_sptxt            = curr_sptxt
       TABLES
            languages             = sel_langus.
  IF x_header-frm_tl_get NE space.
    PERFORM (x_header-frm_tl_get) IN PROGRAM (x_header-fpoolname)
                                  TABLES sel_langus.
  ELSE.
    PERFORM vim_read_texttab_for_langus TABLES sel_langus USING ' '.
  ENDIF.
ENDFORM.                               "VIM_READ_TEXTTAB_ALL_LANGUS

************************************************************************
* SW Langtext
*    Absprung in Langtextpflege über Userexit vom Übersetzungsscreen aus
*    ermöglichen
*---------------------------------------------------------------------*
*       FORM VIM_CALL_LTEXT_EXIT                                      *
*---------------------------------------------------------------------*
* ->  MAINT_MODE      'U'/'R' (Update/Read)
* ->  EXITFORM        Name der Userexit-Routine für Langtextpflege
* <-> TEXTTABLE_ENTRY Zeile, für die Langtextpflege aufgerufen wurde
* <-  MODIFIED        'X' -> Zeile wurde modifiziert
*---------------------------------------------------------------------*
* Aufruf des Userexits für Langtextpflege                             *
*---------------------------------------------------------------------*
FORM vim_call_ltext_exit
             USING    maint_mode TYPE c
                      exitform TYPE vimfrmname
             CHANGING texttable_entry TYPE vimty_textmaint_record
                      modified TYPE c.
  DATA: text_wa TYPE vim_line_ul,
        textmaint_field TYPE vimty_textfield,
        pgm_name LIKE sy-repid,
        offset LIKE sy-fdpos.

  FIELD-SYMBOLS: <text_wa> TYPE x, <text_wa_struc> TYPE ANY,
                 <texttabkey> TYPE x, <txtfld> TYPE ANY.

  CLEAR modified.
  IF vim_internal_ltext_call = space.
    PERFORM (exitform) IN PROGRAM (sy-repid).
  ELSE.
    READ TABLE x_header INDEX 1.
    ASSIGN: text_wa TO <text_wa> CASTING,
            <text_wa> TO <text_wa_struc>
             CASTING TYPE (x_header-texttab),
            texttable_entry-keys TO <texttabkey> CASTING.

    PERFORM map_viewkey_to_texttabkey TABLES x_namtab
                                USING x_header
                                      texttable_entry-spras
                                      <texttabkey>
                             CHANGING <text_wa>.
*    PERFORM VIM_FILL_TEXTTAB_KEY USING TEXTTABLE_ENTRY-KEYS
*                                       TEXTTABLE_ENTRY-SPRAS
*                                       X_HEADER-SPRASFDPOS
*                              CHANGING TEXT_WA.
    LOOP AT texttable_entry-texttab INTO textmaint_field.
      READ TABLE x_namtab INDEX textmaint_field-namtab_idx.
*      offset = x_namtab-texttabpos.
      IF x_namtab-lowercase = space.
        TRANSLATE textmaint_field-text TO UPPER CASE.
      ENDIF.
      IF x_namtab-txttabfldn = space.
* tab + texttab
        ASSIGN COMPONENT x_namtab-bastabfld
         OF STRUCTURE <text_wa_struc> TO <txtfld>.
      ELSE.
* view
        ASSIGN COMPONENT x_namtab-txttabfldn
         OF STRUCTURE <text_wa_struc> TO <txtfld>.
      ENDIF.
      <txtfld> = textmaint_field-text.
*      text_wa+offset(x_namtab-flength) =
*         textmaint_field-text(x_namtab-flength).
    ENDLOOP.
    PERFORM (exitform) IN PROGRAM (x_header-fpoolname)
                          USING maint_mode
                          CHANGING text_wa modified.
    IF modified = 'X'.
      IF maint_mode = 'U'.
        LOOP AT texttable_entry-texttab INTO textmaint_field.
          READ TABLE x_namtab INDEX textmaint_field-namtab_idx.
          ASSIGN COMPONENT x_namtab-txttabfldn
           OF STRUCTURE <text_wa_struc> TO <txtfld>.
          textmaint_field-text = <txtfld>.
*          offset = x_namtab-texttabpos.
*          textmaint_field-text(x_namtab-flength) =
*            text_wa+offset(x_namtab-flength).
          MODIFY texttable_entry-texttab FROM textmaint_field.
        ENDLOOP.
        texttable_entry-action = 'X'.
      ELSE.
        CLEAR modified.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM.                               " VIM_CALL_LTEXT_EXIT
*---------------------------------------------------------------------*
*       FORM VIM_SET_LANGUAGES                                        *
*---------------------------------------------------------------------*
* Sprachauswahl expl. über Menue
*---------------------------------------------------------------------*
FORM vim_set_languages.
  DATA: dummy_langus LIKE h_t002 OCCURS 0.
  CALL FUNCTION 'VIEW_GET_LANGUAGES'
    EXPORTING
      new_selection         = 'X'
*      called_by_viewmaint   = 'X'
    TABLES
      languages             = dummy_langus
    EXCEPTIONS
      no_languages_possible = 1.
  IF sy-subrc = 1.
    MESSAGE s160(sv).
  ENDIF.
ENDFORM.                    "vim_set_languages

*---------------------------------------------------------------------*
*       FORM VIM_RESET_TEXTTAB                                        *
*---------------------------------------------------------------------*
* Rücksetzen der internen Texttabelle
*---------------------------------------------------------------------*
* --> VIEWNAME   Rücksetzen der Texttab für Tab/View VIEWNAME
*---------------------------------------------------------------------*
FORM vim_reset_texttab USING viewname LIKE tvdir-tabname.

  READ TABLE vim_texttab_container WITH KEY viewname = viewname
                         BINARY SEARCH.
  IF sy-subrc = 0.
    FREE vim_texttab_container-tabdata-tab_us.
    FREE vim_texttab_container-tabdata-tab_vs.
    FREE vim_texttab_container-tabdata-tab_s.
    FREE vim_texttab_container-tabdata-tab_m.
    FREE vim_texttab_container-tabdata-tab_l.
    FREE vim_texttab_container-tabdata-tab_vl.
    FREE vim_texttab_container-tabdata-tab_ul.
    FREE vim_texttab_container-sel_langus.
    CLEAR vim_texttab_container-all_langus.
    MODIFY vim_texttab_container INDEX sy-tabix.
*     DELETE VIM_TEXTTAB_CONTAINER INDEX SY-TABIX.
  ENDIF.
ENDFORM.                               "VIM_RESET_TEXTTAB

*---------------------------------------------------------------------*
*       FORM VIM_MULTI_LANGU_TEXT_MAINT                               *
*---------------------------------------------------------------------*
* Routine zur Behandlung der Funktion:                                *
*   "Texterfassung in weiteren Sprachen"                              *
*---------------------------------------------------------------------*
FORM vim_multi_langu_text_maint.
  DATA: langus_selected(1) TYPE c,
        curr_sptxt LIKE t002t-sptxt,
        sel_langus LIKE h_t002 OCCURS 0 WITH HEADER LINE,
        texttab_for_output TYPE vimty_multilangu_texttab,
        maint_mode(1) TYPE c,
        textmodif(1) TYPE c,
        f_called_by_viewmaint TYPE c.  "XB H611377 BCEK070683


  CALL FUNCTION 'VIEW_GET_LANGUAGES'
    IMPORTING
      languages_selected    = langus_selected
      curr_sptxt            = curr_sptxt
    TABLES
      languages             = sel_langus
    EXCEPTIONS
      no_languages_possible = 1.
  IF sy-subrc = 1.
    MESSAGE s160(sv).
    EXIT.
  ELSEIF langus_selected = ' '.
    MESSAGE s153(sv).
    EXIT.
  ENDIF.
  IF x_header-frm_tl_get NE space.
    PERFORM (x_header-frm_tl_get) IN PROGRAM (x_header-fpoolname)
                                  TABLES sel_langus.
  ELSE.
    PERFORM vim_read_texttab_for_langus TABLES sel_langus USING ' '.
  ENDIF.

* Falls mehr als 8 Textfelder (noch nicht realisiert)
*    -> Popup zur Feldselektion und Dynproattribute aktualisieren
* PERFORM VIM_ACTUALIZE_D0100.

  REFRESH texttab_for_output.
  PERFORM vim_fill_texttab_for_maint TABLES sel_langus
                                     USING curr_sptxt
                                     CHANGING texttab_for_output.
  IF status-action EQ anzeigen OR status-action EQ transportieren.
    maint_mode = 'R'.
  ELSE.
    maint_mode = 'U'.
  ENDIF.
* XB H611377B BCEK070683
* check if it is called by view maintenance.
  IF x_namtab IS NOT INITIAL AND x_header IS NOT INITIAL.
    f_called_by_viewmaint = 'X'.
  ENDIF.
  CALL FUNCTION 'VIEW_MULTI_LANGU_TEXT_MAINT'
    EXPORTING
      mode                   = maint_mode
      ltext_exit_form        = x_header-frm_tltext
      called_by_viewmaint   = f_called_by_viewmaint
    IMPORTING
      vim_texttable_modified = textmodif
    TABLES
      vim_d0100_fielddescr   = vim_d0100_fdescr_ini
      vim_texttable          = texttab_for_output
      x_header               = x_header
      x_namtab               = x_namtab.
* XB H611377E BCE070683
  IF maint_mode = 'U' AND textmodif = 'X'.
    PERFORM vim_update_texttab USING texttab_for_output.
    MODIFY vim_texttab_container INDEX vim_texttab_container_index.
  ENDIF.

  IF status-mode = list_bild.          "Entmarkieren
    LOOP AT extract.
      CHECK <xmark> = markiert.
      CLEAR <xmark>.
      MODIFY extract.
      mark_extract = mark_extract - 1.
      READ TABLE total WITH KEY <vim_xextract_key> BINARY SEARCH.
      IF sy-subrc = 0 AND <mark> = markiert.
        CLEAR <mark>.
        MODIFY total INDEX sy-tabix.
        mark_total = mark_total - 1.
      ENDIF.
    ENDLOOP.
  ENDIF.

ENDFORM.                               " VIM_MULTI_LANGU_TEXT_MAINT

*---------------------------------------------------------------------*
*       FORM VIM_SELECT_TEXTFIELDS                                    *
*---------------------------------------------------------------------*
* Falls mehr als 8 Textfelder existieren -> Benutzerauswahl
*---------------------------------------------------------------------*
FORM vim_select_textfields.
  DATA: nr_of_fields TYPE i.

  nr_of_fields = 0.
  LOOP AT x_namtab WHERE keyflag <> 'X' AND
                         ( texttabfld = 'X' OR txttabfldn <> space ) AND
                     ( readonly = space OR readonly = 'R' )."SW 25.3.97
    "   Textfeld in Tabelle or Textfeld in View
    x_namtab-textfldsel = 'X'.
    nr_of_fields = nr_of_fields + 1.
    MODIFY x_namtab.
    IF nr_of_fields >= vim_max_textfields.   " Auswahl über Popup !!!
      EXIT.
    ENDIF.
  ENDLOOP.
ENDFORM.                               "VIM_SELECT_TEXTFIELDS

*---------------------------------------------------------------------*
*       FORM VIM_INITIALIZE_D0100                                     *
*---------------------------------------------------------------------*
* Initialierung der Attribute für Dynprofelder des Texterfassungs-    *
* Dynpros D0100 (View-unabhängig)                                     *
*---------------------------------------------------------------------*
FORM vim_initialize_d0100.
  DATA: fdescr_wa TYPE vimty_screen_fdescr.

  REFRESH vim_d0100_fdescr_ini.
* Keys
  CLEAR fdescr_wa.
  fdescr_wa-active = 'X'.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-KEY1'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
  CLEAR fdescr_wa-active.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-KEY2'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-KEY3'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-KEY4'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-KEY5'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-KEY6'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-KEY7'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-KEY8'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-KEY9'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-KEY10'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
* Sprache
  fdescr_wa-vislength = 10.
  fdescr_wa-active = 'X'.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-SPTXT'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
* Texte
  fdescr_wa-name = 'VIM_D0100_WORKAREA-TEXT1'.
  fdescr_wa-textfld = 'X'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
  CLEAR fdescr_wa-active.
  fdescr_wa-textfld = 'X'.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-TEXT2'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-TEXT3'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-TEXT4'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-TEXT5'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-TEXT6'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-TEXT7'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
  fdescr_wa-name = 'VIM_D0100_WORKAREA-TEXT8'.
  APPEND fdescr_wa TO vim_d0100_fdescr_ini.
ENDFORM.                               " VIM_INITIALIZE_D0100

*---------------------------------------------------------------------*
*       FORM VIM_ACTUALIZE_D0100                                      *
*---------------------------------------------------------------------*
* Attribute für Dynprofelder für aktuellen View aktualisieren         *
* (bzw. der ausgewählten Textfelder, falls mehr als 8 ex.             *
*          !!! noch nicht unterstützt  !!!                )           *
*---------------------------------------------------------------------*
FORM vim_actualize_d0100.
  DATA: fdescr_wa TYPE vimty_screen_fdescr,
        next_tabix LIKE sy-tabix,
        nr_of_field TYPE i,
        tot_keylen TYPE i,
        vislen_0(1) TYPE c,
        max_textlen TYPE i,
        tmp_len TYPE i,
        nr_of_text TYPE i.
  FIELD-SYMBOLS: <title> LIKE vimnamtab-scrtext.

  PERFORM vim_select_textfields.
  CLEAR: max_textlen, nr_of_text.
  LOOP AT x_namtab WHERE textfldsel = 'X'.
    nr_of_text = nr_of_text + 1.
    IF max_textlen < x_namtab-outputlen.
      max_textlen = x_namtab-outputlen.
    ENDIF.
  ENDLOOP.
  IF max_textlen > 30. max_textlen = 30. ENDIF.

  CLEAR: tot_keylen, nr_of_field, vislen_0.
  LOOP AT x_namtab WHERE keyflag = 'X' AND texttabfld <> 'X'.
    CHECK x_namtab-datatype <> 'CLNT' OR x_namtab-position > 0.
    CHECK x_namtab-readonly <> 'S' AND x_namtab-readonly <> 'H'.
    CHECK x_header-delmdtflag = space OR x_header-ptfrkyexst = space OR
          x_namtab-domname <> vim_delim_date_domain OR
          ( x_namtab-rollname NOT in VIM_BEGDA_TYPES and
            X_NAMTAB-ROLLNAME not IN vim_endda_types ).
    nr_of_field = nr_of_field + 1.
    tot_keylen = tot_keylen + x_namtab-outputlen.
    IF nr_of_field <= vim_max_keyfields.
      READ TABLE vim_d0100_fdescr_ini INDEX nr_of_field INTO fdescr_wa.
      fdescr_wa-title = x_namtab-scrtext.
      fdescr_wa-active = 'X'.
      fdescr_wa-fixlength = x_namtab-outputlen.
      tmp_len = tot_keylen + max_textlen.
      IF vislen_0 = 'X'.
        fdescr_wa-vislength = 0.
      ELSEIF tmp_len  > 70.            "???
        fdescr_wa-vislength = 70 - max_textlen -
                                 ( tot_keylen - x_namtab-outputlen ).
        vislen_0 = 'X'.
        IF fdescr_wa-vislength < 0.
          fdescr_wa-vislength = 0.
        ENDIF.
      ELSE.
        fdescr_wa-vislength = fdescr_wa-fixlength.
      ENDIF.
      IF nr_of_field < vim_max_keyfields.
        MODIFY vim_d0100_fdescr_ini FROM fdescr_wa INDEX nr_of_field.
      ENDIF.
    ELSE.
     fdescr_wa-fixlength = fdescr_wa-fixlength + x_namtab-outputlen + 1.
    ENDIF.
  ENDLOOP.
  IF nr_of_field >= vim_max_keyfields.
    fdescr_wa-title = '...'.
    fdescr_wa-active = 'X'.
    fdescr_wa-vislength = 0.
    MODIFY vim_d0100_fdescr_ini FROM fdescr_wa INDEX vim_max_keyfields.
  ELSE.
    next_tabix = nr_of_field + 1.
    LOOP AT vim_d0100_fdescr_ini INTO fdescr_wa
            FROM next_tabix TO vim_max_keyfields.
      CLEAR fdescr_wa-active.
      fdescr_wa-fixlength = 0.
      fdescr_wa-vislength = 0.
      CLEAR fdescr_wa-title.
      MODIFY vim_d0100_fdescr_ini FROM fdescr_wa.
    ENDLOOP.
  ENDIF.
  next_tabix = vim_max_keyfields + 1.                       "Sprachfeld

  LOOP AT x_namtab WHERE textfldsel = 'X'.
    IF x_namtab-readonly = space OR x_namtab-readonly = 'R'."SW 25.3.97
      next_tabix = next_tabix + 1.
      READ TABLE vim_d0100_fdescr_ini INDEX next_tabix INTO fdescr_wa.
      IF x_namtab-readonly = space.    "SW 25.3.1997
        fdescr_wa-active = 'X'.
      ELSEIF x_namtab-readonly = 'R'.  "SW 25.3.1997 ..
        fdescr_wa-active = 'R'.
      ENDIF.                           ".. SW 25.3.1997
      fdescr_wa-title = x_namtab-scrtext.
      fdescr_wa-fixlength = x_namtab-outputlen.
      fdescr_wa-vislength = x_namtab-outputlen.
      MODIFY vim_d0100_fdescr_ini FROM fdescr_wa INDEX next_tabix.
    ENDIF.
  ENDLOOP.

  next_tabix = next_tabix + 1.
  LOOP AT vim_d0100_fdescr_ini INTO fdescr_wa FROM next_tabix.
    CLEAR fdescr_wa-active.
    fdescr_wa-fixlength = 0.
    fdescr_wa-vislength = 0.
    CLEAR fdescr_wa-title.
    MODIFY vim_d0100_fdescr_ini FROM fdescr_wa.
  ENDLOOP.
ENDFORM.                               "VIM_ACTUALIZE_D0100

*---------------------------------------------------------------------*
*       FORM VIM_READ_TEXTTAB_FOR_LANGUS                              *
*---------------------------------------------------------------------*
* Texteinträge von der DB nachlesen für alle Sprachen, für die noch   *
* nicht eingelesen wurde                                              *
*---------------------------------------------------------------------*
* --> SEL_LANGUS         ausgewählte Sprachen
* --> ALL_LANGUS         'X' alle Sprachen wurden ausgewählt
*---------------------------------------------------------------------*
FORM vim_read_texttab_for_langus TABLES sel_langus STRUCTURE h_t002
                                 USING all_langus TYPE c.
  DATA: diff_langus_exist(1) TYPE c,
        diff_langus LIKE h_t002 OCCURS 0 WITH HEADER LINE.

  IF vim_texttab_container-all_langus = 'X'. EXIT. ENDIF. "alles eingel.

  vim_texttab_container-all_langus = all_langus.
  REFRESH diff_langus. CLEAR diff_langus_exist.
  LOOP AT sel_langus.
    READ TABLE <vim_read_langus> WITH KEY sel_langus-spras
                            TRANSPORTING NO FIELDS BINARY SEARCH.
    IF sy-subrc <> 0.
      INSERT sel_langus-spras INTO <vim_read_langus> INDEX sy-tabix.
      diff_langus = sel_langus-spras.
      APPEND diff_langus.
      diff_langus_exist = 'X'.
    ENDIF.
  ENDLOOP.

  IF diff_langus_exist = 'X' OR all_langus = 'X'.
    IF diff_langus_exist = 'X'.
      PERFORM vim_get_texttab_data TABLES diff_langus
                                 CHANGING <vim_texttab>.
    ENDIF.
    MODIFY vim_texttab_container INDEX vim_texttab_container_index.
*                        wegen <vim_read_langus> und <vim_texttab>
  ENDIF.
ENDFORM.                               " VIM_READ_TEXTTAB_FOR_LANGUS

*---------------------------------------------------------------------*
*       FORM VIM_FILL_TEXTTAB_FOR_MAINT                               *
*---------------------------------------------------------------------*
* Die zur Texterfassung in anderen Sprachen ausgewählten Texte werden *
* (anhand der markierten Einträge sowie der ausgewählten Sprachen)    *
* in die Tabelle zur Verarbeitung auf dem Dynpro übernommen.          *
*---------------------------------------------------------------------*
* --> SEL_LANGUS         ausgewählte Sprachen
* --> CURR_SPTXT         SPTXT von Sy-Langu
* <-- TEXTTAB_FOR_MAINT  Verarbeitungstabelle der ausgewählten Texte
*                        auf dem Dynpro
*---------------------------------------------------------------------*
FORM vim_fill_texttab_for_maint TABLES sel_langus STRUCTURE h_t002
               USING curr_sptxt LIKE t002t-sptxt
               CHANGING texttab_for_maint TYPE vimty_multilangu_texttab.

  DATA: textmaint_record TYPE vimty_textmaint_record,
        textmaint_field TYPE vimty_textfield,
        align1 TYPE f,
        texttab_wa TYPE vim_line_ul,
        align2 TYPE f,
        tmp_wa TYPE tabl8000,
        condense(1) TYPE c,
        texttab_tabix LIKE sy-tabix,
        extract_index LIKE sy-tabix,
        keylen type i.
  FIELD-SYMBOLS: <extract_key> TYPE x,
                 <next_spras> TYPE spras,
                 <text_rec_key> TYPE x, <h_texttab_wa> TYPE x,
                 <viewkey_in_texttab> TYPE x, <txtfld> TYPE ANY,
                 <h_tmp> TYPE x, <tmp_struc> TYPE ANY,
                 <h_texttab> TYPE x, <texttab_struc> TYPE ANY.

  IF x_header-delmdtflag <> space AND  "zeitabh. & part. Fremdschl.
     x_header-ptfrkyexst  = 'X'.       "      -> zeitunabh. Texttab.
    condense = 'X'.
    ASSIGN <vim_ext_mkey_beforex> TO <extract_key>.
*    ASSIGN <vim_ext_mkey_before> TO <extract_key>.
    keylen = x_header-after_keyc
     - vim_datum_length * cl_abap_char_utilities=>charsize.
*    keylen = x_header-keylen - vim_datum_length.
    CLEAR <vim_old_mkey_beforex>.
  ELSE.
    ASSIGN <vim_xextract_key> TO <extract_key>.
    keylen = x_header-after_keyc.
*    keylen = x_header-keylen.
    CLEAR condense.
  ENDIF.
  ASSIGN: texttab_wa TO <h_texttab_wa> CASTING,
          <h_texttab_wa>(keylen) TO <viewkey_in_texttab>,
*          texttab_wa+keylen(x_header-textkeylen) TO <texttab_key>,
          <h_texttab_wa>+keylen(x_header-texttablen) TO <h_texttab>,
          tmp_wa+keylen(x_header-texttablen)
           TO <h_tmp>,
          <h_texttab> TO <texttab_struc>
           CASTING TYPE (x_header-texttab),
          <h_tmp> TO <tmp_struc> CASTING TYPE (x_header-texttab),
          COMPONENT x_header-sprasfield OF STRUCTURE <texttab_struc>
           TO <next_spras>,
           textmaint_record-keys TO <text_rec_key> CASTING.
*  ASSIGN texttab_wa+offset(vim_spras_length) TO <next_spras>.
  IF status-mode = list_bild.
    extract_index = 1.
  ELSE.
    extract_index = nextline.
  ENDIF.

  LOOP AT extract FROM extract_index.  "Loop für Detail nicht nötig
    CHECK status-mode = detail_bild OR <xmark> = markiert.
    CHECK condense = ' ' OR
          <vim_old_mkey_beforex> <> <vim_ext_mkey_beforex>.
    IF condense = 'X'.
      <vim_old_mkey_beforex> = <vim_ext_mkey_beforex>.
    ENDIF.
*   Texte in Sy-Langu
    CLEAR textmaint_record.
    <text_rec_key> = <extract_key>.
*    textmaint_record-keys = <extract_key>.
    PERFORM vim_external_repr_for_key TABLES textmaint_record-keytab
                                      USING <vim_xextract_key>.
    textmaint_record-spras = sy-langu.
    textmaint_record-sptxt = curr_sptxt.
    IF x_header-bastab = space.
* view
      LOOP AT x_namtab WHERE textfldsel = 'X'.
        textmaint_field-namtab_idx = sy-tabix.
        textmaint_field-outplen = x_namtab-flength.
        ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE
         <vim_extract_struc> TO <txtfld>.
        textmaint_field-text = <txtfld>.
*      textmaint_field-text(x_namtab-flength) =
*                          extract+x_namtab-position(x_namtab-flength).
        APPEND textmaint_field TO textmaint_record-texttab.
      ENDLOOP.
    ELSE.
* tab + texttab
      LOOP AT x_namtab WHERE textfldsel = 'X'.
        textmaint_field-namtab_idx = sy-tabix.
        textmaint_field-outplen = x_namtab-flength.
        ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE
         <vim_ext_txt_struc> TO <txtfld>.
        textmaint_field-text = <txtfld>.
*      textmaint_field-text(x_namtab-flength) =
*                          extract+x_namtab-position(x_namtab-flength).
        APPEND textmaint_field TO textmaint_record-texttab.
      ENDLOOP.
    ENDIF.
    APPEND textmaint_record TO texttab_for_maint.

*   Texte in ausgewählten Sprachen
************************************************************************
    CLEAR: <viewkey_in_texttab>, <texttab_struc>.
*    CLEAR texttab_wa.
    READ TABLE <vim_texttab> WITH KEY <extract_key>
                               INTO texttab_wa. " BINARY SEARCH.
    texttab_tabix = sy-tabix.
    LOOP AT sel_langus.
      CLEAR textmaint_record.
      <text_rec_key> = <extract_key>.
*      textmaint_record-keys = <extract_key>.             "SW Langtext
      textmaint_record-spras = sel_langus-spras.
      textmaint_record-sptxt = sel_langus-sptxt.

      IF <viewkey_in_texttab> = <extract_key> AND
         <next_spras> < sel_langus-spras.                 "#EC PORTABLE
        LOOP AT <vim_texttab> FROM texttab_tabix INTO texttab_wa.
          IF <viewkey_in_texttab> <> <extract_key> OR
             <next_spras> >= sel_langus-spras.            "#EC PORTABLE
            texttab_tabix = sy-tabix.
            EXIT.
          ENDIF.
        ENDLOOP.
      ENDIF.   " <next_spras> >= sel_langus-spras oder ex. nicht
      IF <next_spras> <> sel_langus-spras OR
         <viewkey_in_texttab> <> <extract_key>.  "Text ex. nicht in Spr.
        CLEAR <tmp_struc>.
*        CLEAR tmp_wa.
      ELSE.
        tmp_wa = <h_texttab_wa>.
      ENDIF.
      LOOP AT x_namtab WHERE textfldsel = 'X'.
        textmaint_field-namtab_idx = sy-tabix.
        textmaint_field-outplen = x_namtab-flength.
        ASSIGN COMPONENT x_namtab-bastabfld OF STRUCTURE
*        ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE    "HCG wrong
        <tmp_struc> TO <txtfld>.    "HCG for txtfldname in view differs
        textmaint_field-text = <txtfld>.
*        offset = keylen + x_namtab-texttabpos.
*        textmaint_field-text(x_namtab-flength) =
*                   tmp_wa+offset(x_namtab-flength).
        APPEND textmaint_field TO textmaint_record-texttab.
      ENDLOOP.
      APPEND textmaint_record TO texttab_for_maint.
    ENDLOOP.                           " SEL_LANGUS

    IF status-mode = detail_bild. EXIT. ENDIF.
  ENDLOOP.                                                  " EXTRACT
ENDFORM.                               " VIM_FILL_TEXTTAB_FOR_MAINT

*&--------------------------------------------------------------------*
*&      Form  VIM_EXTERNAL_REPR_FOR_KEY                               *
*&--------------------------------------------------------------------*
* --> INT_KEY    Interne Darstellung der Schlüsselfelder
* <-- KEYTAB     Tabelle, externe      "
*&--------------------------------------------------------------------*
FORM vim_external_repr_for_key TABLES keytab "TYPE VIMTY_TEXTFIELD
                               USING int_key TYPE x.
  DATA: keynr TYPE i,
        keyfield TYPE vimty_textfield,
        namtab_idx LIKE sy-tabix.
  FIELD-SYMBOLS: <i_value> TYPE ANY, <e_value> TYPE c.

  CLEAR: keynr, keyfield. REFRESH keytab.
  MOVE int_key TO <table1_wax>.
  LOOP AT x_namtab WHERE keyflag = 'X' AND texttabfld <> 'X'.
    namtab_idx = sy-tabix.
*   Mandant nicht anzeigen
    CHECK x_namtab-datatype <> 'CLNT' OR x_header-clidep = space.
*   Subset- und Readonly-Felder nicht anzeigen
    CHECK x_namtab-readonly <> 'S' AND x_namtab-readonly <> 'H'.
*   Datum bei zeitunabh. Texttabelle nicht anzeigen
    CHECK x_header-delmdtflag = space OR x_header-ptfrkyexst = space OR
          x_namtab-domname <> vim_delim_date_domain OR
          ( x_namtab-rollname NOT in VIM_BEGDA_TYPES and
            X_NAMTAB-ROLLNAME not IN vim_endda_types ).
    keynr = keynr + 1.
    IF keynr > vim_max_keyfields.
      keyfield-text+keyfield-outplen(1) = '|'.
      keyfield-outplen = keyfield-outplen + 1.
    ENDIF.
    ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE <table1_wa>
     TO <i_value>.
*    ASSIGN int_key+x_namtab-position(x_namtab-flength) TO <i_value>.
    ASSIGN keyfield-text+keyfield-outplen(x_namtab-outputlen)
                                                       TO <e_value>.
    CALL FUNCTION 'VIEW_CONVERSION_OUTPUT'
      EXPORTING
        value_intern = <i_value>
        tabname      = x_header-maintview
        fieldname    = x_namtab-viewfield
        outputlen    = x_namtab-outputlen
        intlen       = x_namtab-flength
      IMPORTING
        value_extern = <e_value>.

    IF keynr < vim_max_keyfields.
      keyfield-namtab_idx = namtab_idx.
      keyfield-outplen = x_namtab-outputlen.
      APPEND keyfield TO keytab.
      CLEAR keyfield.
    ELSE.
      keyfield-outplen = keyfield-outplen + x_namtab-outputlen.
    ENDIF.
  ENDLOOP.

  IF keynr >= vim_max_keyfields.
    APPEND keyfield TO keytab.
  ENDIF.
ENDFORM.                               "VIM_EXTERNAL_REPR_FOR_KEY

*&--------------------------------------------------------------------*
*&      Form  VIM_FILL_TEXTTAB_KEY                                    *
*&--------------------------------------------------------------------*
* UF210800: Not unicode-compatible: Please use form
* MAP_VIEWKEY_TO_TEXTTABKEY instead
*
*&--------------------------------------------------------------------*
* --> VIEW_WA  WA of view                                             *
* --> SPRAS    Sprachschlüssel                                        *
* --> SPRAS_POS Position des Sprachschlüssel in VIEW_WA
* <-- TEXT_WA  Key of text table                                      *
*&--------------------------------------------------------------------*
*FORM vim_fill_texttab_key USING view_wa
*                                spras LIKE t002-spras
*                                spras_pos LIKE vimdesc-sprasfdpos
*                       CHANGING text_wa.
*
** Sprachschlüssel
** TEXT_WA+X_HEADER-SPRASFDPOS(VIM_SPRAS_LENGTH) = SPRAS.
*  text_wa+spras_pos(vim_spras_length) = spras.
** Schlüsselfelder der Text-Tabelle
*  LOOP AT x_namtab WHERE txttabfldn <> space AND keyflag <> space.
*    text_wa+x_namtab-texttabpos(x_namtab-flength) =
*         view_wa+x_namtab-position(x_namtab-flength).
*  ENDLOOP.
*ENDFORM.                               "VIM_FILL_TEXTTAB_KEY
*
*&--------------------------------------------------------------------*
*&      Form  VIM_FILL_VIEW_KEY                                       *
*&--------------------------------------------------------------------*
* Not usable in unicode-systems!!!!
* Please use form MAP_TEXTTABKEY_TO_VIEWKEY instead!
*&--------------------------------------------------------------------*
* --> TEXTTAB_WA  WA of text table                                    *
* <-- VIEW_KEY    KEY of view / table                                 *
* <-- SPRAS                                                           *
*&--------------------------------------------------------------------*
FORM vim_fill_view_key USING texttab_wa TYPE vim_line_ul
                   CHANGING view_key
                            spras LIKE t002-spras.

  LOOP AT x_namtab WHERE txttabfldn <> space AND keyflag <> space.
*   alle Schlüsselfelder, zu denen es Felder in der Texttabelle gibt
    view_key+x_namtab-position(x_namtab-flength) =
         texttab_wa+x_namtab-texttabpos(x_namtab-flength).
  ENDLOOP.
  spras = texttab_wa+x_header-sprasfdpos(vim_spras_length).
ENDFORM.                               "VIM_FILL_VIEW_KEY

*---------------------------------------------------------------------*
*       FORM VIM_UPDATE_TEXTTAB                                       *
*---------------------------------------------------------------------*
* Die vom Benutzer erfaßten/geänderten Texte  werden in die interne   *
* Texttabelle <VIM_TEXTTAB> übernommen                                *
*---------------------------------------------------------------------*
FORM vim_update_texttab
                USING texttab_for_maint TYPE vimty_multilangu_texttab.
  DATA: textmaint_record TYPE vimty_textmaint_record,
        textmaint_field TYPE vimty_textfield,
        align TYPE f,
        texttab_wa TYPE vim_line_ul,
        search_key TYPE tabl8000,
        offset LIKE sy-fdpos,
        keylen LIKE sy-fdpos,
        extract_index LIKE sy-tabix,
        total_index   LIKE sy-tabix,
        texttab_tabix LIKE sy-tabix,
        new_entry(1)  TYPE c,
        keylen_char type i.
  FIELD-SYMBOLS:
        <search_key> TYPE x, <rec_key> TYPE x, <curr_spras> TYPE ANY,
        <h_texttab_wa> TYPE x,
        <viewkey_in_texttab> TYPE x, "Key aus View/Tab in Texttab
        <texttab_key> TYPE x, <texttab_struc> TYPE ANY,
        <h_texttab> TYPE x, <tot_fld> TYPE ANY, <ext_fld> TYPE ANY,
        <texttab_action> TYPE c,
        <t_action>, <e_action>.

  IF x_header-delmdtflag <> space AND     "zeitabh. & part. Fremdschl.
     x_header-ptfrkyexst  = 'X'.          "      -> zeitunabh. Texttab.
    keylen = x_header-after_keyc
     - vim_datum_length * cl_abap_char_utilities=>charsize.
  ELSE.
    keylen = x_header-after_keyc.
  ENDIF.
  keylen_char = keylen / cl_abap_char_utilities=>charsize.
  ASSIGN: search_key(keylen) TO <search_key>,
          textmaint_record-keys(keylen_char) TO <rec_key> CASTING,
          texttab_wa TO <h_texttab_wa> CASTING,
          <h_texttab_wa>(keylen) TO <viewkey_in_texttab>,
          <h_texttab_wa>+keylen(x_header-textkeylen) TO <texttab_key>,
          <h_texttab_wa>+keylen(x_header-texttablen) TO <h_texttab>,
          <h_texttab> TO <texttab_struc>
           CASTING TYPE (x_header-texttab),
          COMPONENT x_header-sprasfield OF STRUCTURE <texttab_struc>
           TO <curr_spras>.
  offset = keylen + x_header-aft_txttbc.
  ASSIGN <h_texttab_wa>+offset(cl_abap_char_utilities=>charsize)
   TO <texttab_action> CASTING.
  IF x_header-bastab = 'X'.
* tab+texttab
    ASSIGN <action_text> TO <t_action>.
    ASSIGN <xact_text> TO <e_action>.
  ELSE.
    ASSIGN <action> TO <t_action>.
    ASSIGN <xact> TO <e_action>.
  ENDIF.

  LOOP AT texttab_for_maint INTO textmaint_record.
    IF textmaint_record-spras = sy-langu.
      <search_key> = <rec_key>.
      READ TABLE extract WITH KEY <search_key> BINARY SEARCH.
      extract_index = sy-tabix.
    ENDIF.
    CHECK textmaint_record-action = 'X'.      " Texte wurden modifiziert

    IF textmaint_record-spras = sy-langu.
*     Texte in Sy-Langu  => Update in Total und Extract
*      READ TABLE EXTRACT WITH KEY <SEARCH_KEY> BINARY SEARCH.
*      EXTRACT_INDEX = SY-TABIX.
      READ TABLE total WITH KEY <search_key> BINARY SEARCH.
      total_index = sy-tabix.
      IF x_header-bastab = 'X'
       AND <vim_xextract_text> = <text_initial_x>.
        PERFORM map_viewkey_to_texttabkey TABLES x_namtab
                                          USING x_header
                                                sy-langu
                                                <vim_xtotal>
                                          CHANGING <vim_xextract_text>.
        PERFORM map_viewkey_to_texttabkey TABLES x_namtab
                                          USING x_header
                                                sy-langu
                                                <vim_xtotal>
                                          CHANGING <vim_xtotal_text>.
*        PERFORM vim_fill_texttab_key USING <search_key> sy-langu
*                                           x_header-sprasfdpos
*                                  CHANGING <extract_text>.
*        PERFORM vim_fill_texttab_key USING <search_key> sy-langu
*                                           x_header-sprasfdpos
*                                  CHANGING <total_text>.
        <e_action> = neuer_eintrag.
        <t_action> = neuer_eintrag.
      ELSEIF <e_action> = original.
        <e_action> = aendern.
        <t_action> = aendern.
*     Else.                     " neuer_eintrag / aendern => ok
      ENDIF.
      LOOP AT textmaint_record-texttab INTO textmaint_field.
        READ TABLE x_namtab INDEX textmaint_field-namtab_idx.
        IF x_namtab-lowercase = space.
          TRANSLATE textmaint_field-text TO UPPER CASE.
        ENDIF.
        IF x_header-bastab = 'X'.
* tab + texttab
          ASSIGN: COMPONENT x_namtab-viewfield OF STRUCTURE
                   <vim_ext_txt_struc> TO <ext_fld>,
                  COMPONENT x_namtab-viewfield OF STRUCTURE
                   <vim_tot_txt_struc> TO <tot_fld>.
        ELSE.
* view
          ASSIGN: COMPONENT x_namtab-viewfield OF STRUCTURE
                   <vim_extract_struc> TO <ext_fld>,
                  COMPONENT x_namtab-viewfield OF STRUCTURE
                   <vim_total_struc> TO <tot_fld>.
        ENDIF.
        <tot_fld> = textmaint_field-text.
        <ext_fld> = textmaint_field-text.
*        extract+x_namtab-position(x_namtab-flength) =
*           textmaint_field-text(x_namtab-flength).
*        total+x_namtab-position(x_namtab-flength) =
*           textmaint_field-text(x_namtab-flength).
      ENDLOOP.                         "TEXTMAINT_RECORD-TEXTTAB
      MODIFY extract INDEX extract_index.
      MODIFY total INDEX total_index.

    ELSE.
* different language: Update in texttable
      CLEAR: <h_texttab_wa>, <texttab_struc>.
      READ TABLE <vim_texttab> WITH KEY <search_key>
                               INTO texttab_wa BINARY SEARCH.
      texttab_tabix = sy-tabix.
      IF <viewkey_in_texttab> = <search_key> AND   "Text ex. in and. Spr
         <curr_spras> < textmaint_record-spras.
        LOOP AT <vim_texttab> FROM texttab_tabix INTO texttab_wa.
          IF <viewkey_in_texttab> <> <search_key> OR
             <curr_spras> >= textmaint_record-spras.
            texttab_tabix = sy-tabix.
            EXIT.
          ELSEIF <curr_spras> < textmaint_record-spras.
            texttab_tabix = sy-tabix + 1.
          ENDIF.
        ENDLOOP.
      ENDIF.   " <next_spras> >= sel_langus-spras oder ex. nicht
      IF <viewkey_in_texttab> <> <search_key> OR
         <curr_spras> <> textmaint_record-spras.
        CLEAR: <texttab_struc>.
*        CLEAR texttab_wa.
        new_entry = 'X'.
        <viewkey_in_texttab> = <search_key>.
*        texttab_wa = <search_key>.
        <texttab_action> = neuer_eintrag.
        PERFORM map_viewkey_to_texttabkey TABLES x_namtab
                                          USING x_header
                                                textmaint_record-spras
                                                <viewkey_in_texttab>
                                          CHANGING <texttab_key>.
**        PERFORM vim_fill_texttab_key
*                            USING <search_key> textmaint_record-spras
*                                  x_header-sprasfdpos
*                            CHANGING <texttab_key>.
      ELSE.
        CLEAR new_entry.
      ENDIF.
*     Text-Values übernehmen
      LOOP AT textmaint_record-texttab INTO textmaint_field.
        READ TABLE x_namtab INDEX textmaint_field-namtab_idx.
*        offset = keylen + x_namtab-texttabpos.
        IF x_namtab-lowercase = space.
          TRANSLATE textmaint_field-text TO UPPER CASE.
        ENDIF.
        IF x_header-bastab = 'X'."HCG Custmessage 282684/02------------
* tab + texttab
          ASSIGN: COMPONENT x_namtab-viewfield OF STRUCTURE
*                   <vim_ext_txt_struc> TO <ext_fld>.
                   <texttab_struc> TO <ext_fld>. "XB int.40684/02
        ELSE.
* view, basis table field name.
          ASSIGN: COMPONENT x_namtab-BASTABFLD OF STRUCTURE
*                   <vim_extract_struc> TO <ext_fld>.
                   <texttab_struc> TO <ext_fld>. "XB int.. 40684
        ENDIF.
*        ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE
*---------      <texttab_struc> TO <ext_fld>."HCG Custmessage 282684/02
        <ext_fld> = textmaint_field-text.
*        texttab_wa+offset(x_namtab-flength) =
*           textmaint_field-text(x_namtab-flength).
      ENDLOOP.
      IF <texttab_action> = original.
        <texttab_action> = aendern.
      ENDIF.
      IF new_entry = 'X'.
        INSERT texttab_wa INTO <vim_texttab> INDEX texttab_tabix.
      ELSE.
        MODIFY <vim_texttab> FROM texttab_wa INDEX texttab_tabix.
      ENDIF.

    ENDIF.                             " Sy-Langu
  ENDLOOP.                             " TEXTTAB_FOR_MAINT

ENDFORM.                               " VIM_UPDATE_TEXTTAB

*---------------------------------------------------------------------*
*       FORM VIM_TEMP_DELIM_TEXTTAB                                   *
*---------------------------------------------------------------------*
* Abgrenzen für zeitabh. Texttabelle :                                *
*    neuen Eintrag für <vim_xtotal_key> für alle Sprachen in
*      Texttabelle erzeugen, bzw. -falls schon ex.- Texte darin ersetzen
*      Texte werden aus Originaleintrag ORIG_KEY übernommen
*    im Eintrag ENDDATE Texte löschen;
*      falls dieser neu ist -> gesammten Eintrag löschen
*---------------------------------------------------------------------*
* <vim_xtotal_key> = aktuell bearb. Intervall, entstanden durch
*                    Abgrenzen
* --> ENDDATE   Endedatum des neuen Intervalls
* --> ORIG_KEY  altes Endedatum des aktuellen Intervalls vor Abgrenzen
*---------------------------------------------------------------------*
FORM vim_temp_delim_texttab USING value(enddate)
                                  value(orig_key) TYPE x.
  DATA: texttab_orig TYPE vim_line_ul,
        texttab_new  TYPE vim_line_ul,
        align        TYPE f,
        old_key      TYPE tabl8000,
        orig_tabix LIKE sy-tabix,
        new_tabix  LIKE sy-tabix,
        len TYPE i,
        offset TYPE i,
        langus_selected(1) TYPE c,
        curr_sptxt LIKE t002t-sptxt,
        sel_langus LIKE h_t002 OCCURS 0 WITH HEADER LINE.
  FIELD-SYMBOLS: <texttab_orig_x> TYPE x,
                 <txttb_orig_struc> TYPE ANY,
                 <viewkey_in_orig> TYPE x,    "-> texttab_orig
                 <texttab_new_x> TYPE x,
                 <txttb_new_struc> TYPE ANY,
                 <viewkey_in_new> TYPE x,     "-> texttab_new
                 <spras_in_orig> TYPE spras,
                 <spras_in_new> TYPE spras,
                 <date_in_textkey_new> LIKE sy-datum,
                 <action_in_orig>,
                 <action_in_new>,
                 <textfields_in_new> TYPE x,
                 <textfields_in_orig> TYPE x,
                 <h_old_key> TYPE x, <old_key_enddate> LIKE sy-datum,
                 <old_keyx> TYPE x, <old_key_struc> TYPE ANY.

  CALL FUNCTION 'VIEW_GET_LANGUAGES'
    EXPORTING
      all_without_selection = 'X'
    IMPORTING
      languages_selected    = langus_selected
      curr_sptxt            = curr_sptxt
    TABLES
      languages             = sel_langus.
  IF x_header-frm_tl_get NE space.
    PERFORM (x_header-frm_tl_get) IN PROGRAM (x_header-fpoolname)
                                  TABLES sel_langus.
  ELSE.
    PERFORM vim_read_texttab_for_langus TABLES sel_langus USING 'X'.
  ENDIF.

  READ TABLE <vim_texttab> WITH KEY orig_key
                           BINARY SEARCH TRANSPORTING NO FIELDS.
  CHECK sy-subrc = 0.
  orig_tabix = sy-tabix.
  ASSIGN: texttab_orig TO <texttab_orig_x> CASTING,
          <texttab_orig_x>(x_header-keylen) TO <viewkey_in_orig>,
          <texttab_orig_x>+x_header-after_keyc
           TO <txttb_orig_struc> CASTING TYPE (x_header-texttab),
          COMPONENT x_header-sprasfield OF STRUCTURE <txttb_orig_struc>
           TO <spras_in_orig>.
  ASSIGN: texttab_new TO <texttab_new_x> CASTING,
          <texttab_new_x>(x_header-keylen) TO <viewkey_in_new>,
          <texttab_new_x>+x_header-after_keyc
           TO <txttb_new_struc> CASTING TYPE (x_header-texttab),
          COMPONENT x_header-sprasfield OF STRUCTURE <txttb_new_struc>
           TO <spras_in_new>.
  offset = x_header-after_keyc + x_header-textkeylen.
  len = x_header-aft_txttbc - x_header-textkeylen.
  ASSIGN: <texttab_new_x>+offset(len) TO <textfields_in_new>,
          <texttab_orig_x>+offset(len) TO <textfields_in_orig>.
  ASSIGN: old_key TO <h_old_key> CASTING,
          <h_old_key>(x_header-keylen) TO <old_keyx>,
          old_key TO <old_key_struc> CASTING TYPE (x_header-maintview).
*  ASSIGN texttab_orig(x_header-keylen) TO <viewkey_in_orig>.
*  ASSIGN texttab_new(x_header-keylen) TO <viewkey_in_new>.
*  offset = x_header-keylen + x_header-sprasfdpos.
*  ASSIGN texttab_orig+offset(vim_spras_length) TO <spras_in_orig>.
*  ASSIGN texttab_new+offset(vim_spras_length) TO <spras_in_new>.
  LOOP AT x_namtab WHERE keyflag = 'X' AND
    ( texttabfld = 'X' OR txttabfldn <> space ) AND
      domname EQ vim_delim_date_domain AND
    ( rollname IN vim_begda_types OR rollname IN vim_endda_types ).
*      offset = x_header-keylen + x_namtab-texttabpos.
*      len = x_namtab-flength.
    EXIT.
  ENDLOOP.
  ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE <txttb_new_struc>
   TO <date_in_textkey_new>.
*    ASSIGN texttab_new+offset(len) TO <date_in_textkey_new> TYPE 'D'.
  offset = ( x_header-after_keyc + x_header-aft_txttbc )
           / cl_abap_char_utilities=>charsize.
*  offset = x_header-keylen + x_header-texttablen.
  ASSIGN texttab_orig+offset(1) TO <action_in_orig>.
  ASSIGN texttab_new+offset(1) TO <action_in_new>.
*  ASSIGN texttab_new+offset(len) TO <textfields_in_new>.
*  ASSIGN texttab_orig+offset(len) TO <textfields_in_orig>.

  LOOP AT <vim_texttab> INTO texttab_orig FROM orig_tabix.
    IF <viewkey_in_orig> <> orig_key. EXIT. ENDIF.
    READ TABLE <vim_texttab> WITH KEY <vim_xtotal_key>
                     INTO texttab_new BINARY SEARCH.
    new_tabix = sy-tabix.
    IF <viewkey_in_new> = <vim_xtotal_key> AND
       <spras_in_new> < <spras_in_orig>.                  "#EC PORTABLE
      LOOP AT <vim_texttab> FROM new_tabix INTO texttab_new.
        IF <viewkey_in_new> <> <vim_xtotal_key> OR
           <spras_in_new> >= <spras_in_orig>.             "#EC PORTABLE
          new_tabix = sy-tabix.
          EXIT.
        ELSEIF <spras_in_new> < <spras_in_orig>.          "#EC PORTABLE
          new_tabix = sy-tabix + 1.
        ENDIF.
      ENDLOOP.
    ENDIF.
    IF <viewkey_in_new> <> <vim_xtotal_key> OR
       <spras_in_new> <> <spras_in_orig>.
*    es gibt noch keinen Eintrag mit neuem Schlüssel
      texttab_new = texttab_orig.
      <viewkey_in_new> = <vim_xtotal_key>.
      <date_in_textkey_new> = <vim_enddate>.
      <action_in_new> = neuer_eintrag.
      INSERT texttab_new INTO <vim_texttab> INDEX new_tabix.
    ELSE.
      IF <action_in_new> = original.
        <action_in_new> = aendern.
      ENDIF.
      <textfields_in_new> = <textfields_in_orig>.
      MODIFY <vim_texttab> FROM texttab_new INDEX new_tabix.
    ENDIF.
  ENDLOOP.

* Text in neuen Eintrag löschen
  <old_keyx> = <vim_xtotal_key>.
*  ASSIGN old_key(x_header-keylen) TO <old_key>.
  LOOP AT x_namtab WHERE keyflag = 'X' AND
    ( texttabfld = 'X' OR txttabfldn <> space ) AND
    domname EQ vim_delim_date_domain AND
    ( rollname IN vim_begda_types OR rollname IN vim_endda_types ).
    EXIT.
  ENDLOOP.
  ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE <old_key_struc>
   TO <old_key_enddate>.
  <old_key_enddate> = enddate.
*  old_key+x_namtab-position(x_namtab-flength) = enddate.
  READ TABLE <vim_texttab> WITH KEY <old_keyx>
                           BINARY SEARCH TRANSPORTING NO FIELDS.
*  READ TABLE <vim_texttab> WITH KEY <old_key>
*                           BINARY SEARCH TRANSPORTING NO FIELDS.
  IF sy-subrc = 0.
    LOOP AT <vim_texttab> INTO texttab_orig FROM sy-tabix.
      IF <viewkey_in_orig> <> <old_keyx>. EXIT. ENDIF.
      IF <action_in_orig> = neuer_eintrag.
        DELETE <vim_texttab>.
      ELSE.
        CLEAR <textfields_in_orig>.
        IF <action_in_orig> = original.
          <action_in_orig> = aendern.
        ENDIF.
        MODIFY <vim_texttab> FROM texttab_orig.
      ENDIF.
    ENDLOOP.
  ENDIF.
  MODIFY vim_texttab_container INDEX vim_texttab_container_index.
ENDFORM.                               " VIM_TEMP_DELIM_TEXTTAB

*---------------------------------------------------------------------*
*       FORM VIM_CHECK_UPD_TEXTTAB                                    *
*---------------------------------------------------------------------*
* Setzen von <STATUS>-UPD_FLAG, falls Änderungen in Texttabelle       *
*---------------------------------------------------------------------*
FORM vim_check_upd_texttab.
  DATA: texttab_wa TYPE vim_line_ul,
        offset TYPE i.
  FIELD-SYMBOLS: <texttab_action>.

  IF x_header-delmdtflag <> space AND  "zeitabh. & part. Fremdschl.
     x_header-ptfrkyexst  = 'X'.       "      -> zeitunabh. Texttab.
    offset = x_header-after_keyc
     - vim_datum_length * cl_abap_char_utilities=>charsize.
  ELSE.
    offset = x_header-after_keyc.
  ENDIF.
  offset = ( offset + x_header-aft_txttbc )
           / cl_abap_char_utilities=>charsize.
  ASSIGN texttab_wa+offset(1) TO <texttab_action>.
  LOOP AT <vim_texttab> INTO texttab_wa.
    CHECK <texttab_action> <> original.
    MOVE 'X' TO <status>-upd_flag.
    EXIT.
  ENDLOOP.

ENDFORM.                               "VIM_CHECK_UPD_TEXTTAB

*---------------------------------------------------------------------*
*       FORM VIM_SET_TEXTTAB_ACTION_DELETE                            *
*---------------------------------------------------------------------*
* Für alle als 'GELOESCHT' gekennzeichneten Einträge in TOTAL         *
* entsprechende Einträge in der Texttabelle als 'GELOESCHT' kennz.    *
*---------------------------------------------------------------------*
FORM vim_set_texttab_action_delete.
  DATA: texttab_tabix LIKE sy-tabix,
        offset TYPE i,
        texttab_wa TYPE vim_line_ul.
  FIELD-SYMBOLS: <h_texttab_wa> TYPE x,
                 <texttab_action> TYPE char01,
                 <viewkey_in_texttab> TYPE x,
                 <total_key> TYPE x.

  IF x_header-delmdtflag <> space AND  "zeitabh. & part. Fremdschl.
     x_header-ptfrkyexst  = 'X'.       "      -> zeitunabh. Texttab.
    offset = x_header-after_keyc
             - vim_datum_length * cl_abap_char_utilities=>charsize.
    ASSIGN <vim_tot_mkey_beforex> TO <total_key>.
  ELSE.
    offset = x_header-after_keyc.
    ASSIGN <vim_xtotal_key> TO <total_key>.
  ENDIF.
  ASSIGN: texttab_wa TO <h_texttab_wa> CASTING,
          <h_texttab_wa>(offset) TO <viewkey_in_texttab>.
  offset = ( offset + x_header-aft_txttbc )
           / cl_abap_char_utilities=>charsize.
  ASSIGN texttab_wa+offset(1) TO <texttab_action>.

* Text-Einträge werden nur in dieser Routine, also in PREPARE_SAVING,
* als gelöscht gekennzeichnet, und nach dem eigentlichen Sichern,
* in AFTER_SAVING, aus der internen Texttabelle gelöscht.
* Hier sollten daher keine Einträge als gelöscht gekennzeichnet sein,
* außer wenn im User_exit vor dem Sichern das Sichern abgebrochen wurde.
  LOOP AT <vim_texttab> INTO texttab_wa.
    CHECK <texttab_action> = geloescht OR
          <texttab_action> = update_geloescht OR
          <texttab_action> = neuer_geloescht.
    TRANSLATE <texttab_action> USING 'D XNYU'.
    MODIFY <vim_texttab> FROM texttab_wa.
  ENDLOOP.

  LOOP AT total.
    CHECK <action> = update_geloescht OR
          <action> = geloescht OR
          <action> = neuer_geloescht.
    READ TABLE <vim_texttab> WITH KEY <total_key>
                               BINARY SEARCH TRANSPORTING NO FIELDS.
    IF sy-subrc = 0.
      texttab_tabix = sy-tabix.
      LOOP AT <vim_texttab> FROM texttab_tabix INTO texttab_wa.
        IF <viewkey_in_texttab> <> <total_key>.
          EXIT.
        ENDIF.
        TRANSLATE <texttab_action> USING ' DNXUY'.
        MODIFY <vim_texttab> FROM texttab_wa.
      ENDLOOP.
    ENDIF.
  ENDLOOP.
ENDFORM.                               "VIM_SET_TEXTTAB_ACTION_DELETE

*---------------------------------------------------------------------*
*    VIM_TEXTTAB_MODIF_FOR_KEY
*---------------------------------------------------------------------*
* <-- MODIF       'X' -> es gibt mind. einen modifizierten Eintrag
*                        in anderer Sprache
*---------------------------------------------------------------------*
* aktueller Eintrag steht in Kopfzeile von EXTRACT
*---------------------------------------------------------------------*
FORM vim_texttab_modif_for_key CHANGING modif.
  DATA: texttab_wa TYPE vim_line_ul,
        texttab_tabix LIKE sy-tabix,
        keylen TYPE i,
        offset TYPE i.
  FIELD-SYMBOLS: <h_texttab_wa> TYPE x,
                 <texttab_action> type xfeld,
                 <viewkey_in_texttab> type x,
                 <extract_key> type x.

  IF x_header-delmdtflag <> space AND  "zeitabh. & part. Fremdschl.
     x_header-ptfrkyexst  = 'X'.       "      -> zeitunabh. Texttab.
    ASSIGN <vim_ext_mkey_beforex> TO <extract_key>.
    keylen = x_header-after_keyc
     - vim_datum_length * cl_abap_char_utilities=>charsize.
  ELSE.
    ASSIGN <vim_xextract_key> TO <extract_key>.
    keylen = x_header-after_keyc.
  ENDIF.

  CLEAR modif.
  READ TABLE <vim_texttab> WITH KEY <vim_xextract_key>
                           BINARY SEARCH TRANSPORTING NO FIELDS.
  IF sy-subrc = 0.
    texttab_tabix = sy-tabix.
  ELSE.
    EXIT.     "keine Texte zum Key in anderen Sprachen erfaßt
  ENDIF.

  ASSIGN: texttab_wa TO <h_texttab_wa> CASTING,
          <h_texttab_wa>(keylen) TO <viewkey_in_texttab>.
  offset = ( keylen + x_header-aft_txttbc )
           / cl_abap_char_utilities=>charsize.
  ASSIGN texttab_wa+offset(1) TO <texttab_action>.
  LOOP AT <vim_texttab> FROM texttab_tabix INTO texttab_wa.
    IF <viewkey_in_texttab> <> <extract_key>.
      EXIT.
    ELSEIF <texttab_action> <> original.
      modif = 'X'.
      EXIT.
    ENDIF.
  ENDLOOP.
ENDFORM.                               "VIM_TEXTTAB_MODIF_FOR_KEY

*---------------------------------------------------------------------*
*       FORM VIM_TEXT_KEYTAB_ENTRIES
*---------------------------------------------------------------------*
* Korrektureinträge für Texttabellenänderungen
* UF170200 Dump DATA_LENGTH_TOO_LARGE: Keylen not changed anymore in
* header line of X_HEADER but received in CORR_UPD and added to
* interface (P_KEYLEN).
*---------------------------------------------------------------------*
FORM vim_text_keytab_entries USING value(vake_action) TYPE c
                                   vake_rc TYPE i
                                   value(p_keylen) TYPE syfleng
                                   value(p_txtkeylen) TYPE syfleng.
  DATA: rc1 LIKE sy-subrc,
        offset TYPE i,
        texttab_wa TYPE vim_line_ul.
  FIELD-SYMBOLS: <h_texttab_wa> type x,
                 <texttab_action> type c, <texttab_key> type x,
                 <x_header2> TYPE vimdesc.

  IF x_header-delmdtflag <> space AND  "zeitabh. & part. Fremdschl.
     x_header-ptfrkyexst  = 'X'.       "      -> zeitunabh. Texttab.
    p_keylen = p_keylen
     - vim_datum_length * cl_abap_char_utilities=>charsize.  "UF170200
  ENDIF.
  ASSIGN: texttab_wa to <h_texttab_wa> casting,
          <h_texttab_wa>+p_keylen(x_header-textkeylen) TO <texttab_key>.
  offset = p_keylen + x_header-aft_txttbc.
  ASSIGN <h_texttab_wa>+offset(cl_abap_char_utilities=>charsize)
          TO <texttab_action> casting.

  corr_keytab =  e071k.
  corr_keytab-objname = x_header-texttab.

  vake_rc = 8.
  LOOP AT <vim_texttab> INTO texttab_wa.
    CHECK <texttab_action> <> original AND
          <texttab_action> <> neuer_geloescht.
    MOVE <texttab_key> TO <vim_corr_keyx>(p_txtkeylen).
*    MOVE <texttab_key> TO corr_keytab-tabkey(p_txtkeylen).
    PERFORM update_corr_keytab USING vake_action rc1.
    IF rc1 = 0.
      CLEAR vake_rc.
    ELSE.
      IF vake_action EQ pruefen. vake_rc = 8. EXIT. ENDIF.
    ENDIF.
  ENDLOOP.
ENDFORM.                               "VIM_TEXT_KEYTAB_ENTRIES

*---------------------------------------------------------------------*
*       FORM VIM_TEXT_KEYTAB_ENTRY
*---------------------------------------------------------------------*
* Korrektureintrag für Entry in allen vorhandenen Sprachen
*---------------------------------------------------------------------*
FORM vim_text_keytab_entry USING value(viewkey) TYPE x
                                 value(vake_action) TYPE c
                                 vake_rc TYPE i.
  DATA: rc1 LIKE sy-subrc,
        sys_type(10) TYPE c,
        keylen TYPE i,
        offset TYPE i,
        tbx LIKE sy-tabix,
        align TYPE f,
        texttab_wa TYPE vim_line_ul,
        key_wa TYPE vim_line_ul,
        wheretab LIKE vimwheretb OCCURS 0 WITH HEADER LINE,
        tmp_sellist LIKE vimsellist OCCURS 0 WITH HEADER LINE,
        tmp_texttab TYPE REF TO data, w_tmp_texttab type ref to data.
  FIELD-SYMBOLS: <tmp_texttab> TYPE STANDARD TABLE,
                 <texttab_wax> TYPE x,
                 <texttab_x> TYPE x, <texttab_struc> TYPE ANY,
                 <texttab_key> TYPE x, <texttab_action> TYPE c,
                 <keyvalue> TYPE ANY, <lang> TYPE spras,
                 <viewkey_in_texttab>, <viewkey> TYPE x.

  vake_rc = 8.
  corr_keytab =  e071k.
  corr_keytab-objname = x_header-texttab.

  IF x_header-generictrp <> space OR x_header-genertxtrp <> space.
    keylen = x_header-maxtrkeyln.
  ELSE.
    keylen = x_header-keylen.
  ENDIF.
  CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'transport/systemtype'
                     ID 'VALUE' FIELD sys_type.

  ASSIGN: viewkey(keylen) TO <viewkey> CASTING.
  IF vim_texttab_container-all_langus = 'X'.
* texts have already been read
    ASSIGN: texttab_wa TO <texttab_wax> CASTING,
            <texttab_wax>+keylen(x_header-texttablen) TO <texttab_x>,
            <texttab_x>(x_header-textkeylen) TO <texttab_key>,
            <texttab_x> TO <texttab_struc>
             CASTING TYPE (x_header-texttab),
            COMPONENT x_header-sprasfield OF STRUCTURE
             <texttab_struc> TO <lang>.
    IF x_header-delmdtflag <> space AND"zeitabh. & part. Fremdschl.
       x_header-ptfrkyexst  = 'X'.     "      -> zeitunabh. Texttab.
      keylen = keylen
                - vim_datum_length * cl_abap_char_utilities=>charsize.
    ENDIF.
    ASSIGN <texttab_wax>(keylen) TO <viewkey_in_texttab>.
    offset = keylen + x_header-aft_txttbc.
    ASSIGN <texttab_wax>+offset(cl_abap_char_utilities=>charsize)
     TO <texttab_action> CASTING.

    READ TABLE <vim_texttab> WITH KEY <viewkey>
             BINARY SEARCH TRANSPORTING NO FIELDS.
    IF sy-subrc = 0.
      LOOP AT <vim_texttab> INTO texttab_wa FROM sy-tabix.
        CHECK <texttab_action> <> neuer_eintrag.
        IF <viewkey_in_texttab> <> <viewkey>. EXIT. ENDIF.
        MOVE <texttab_key> TO <vim_corr_keyx>(x_header-textkeylen).
*        WRITE <texttab_key> TO corr_keytab-tabkey(x_header-textkeylen).
        PERFORM update_corr_keytab USING vake_action rc1.
        IF rc1 = 0.
          CLEAR vake_rc.
        ELSE.
          IF vake_action EQ pruefen. vake_rc = 8. EXIT. ENDIF.
        ENDIF.
      ENDLOOP.
    ELSE.
      CLEAR vake_rc.
    ENDIF.
  ELSE.
* Texte direkt von DB lesen
    REFRESH wheretab.
    tmp_sellist-operator = 'EQ'.
    tmp_sellist-and_or = 'AND'.
    MOVE <viewkey> TO <f1_wax>.
    LOOP AT x_namtab WHERE keyflag NE space    "fill sellist for
                       AND txttabfldn <> space.             "texttab
      tmp_sellist-tabix = sy-tabix.
*      ASSIGN viewkey+x_namtab-position(x_namtab-flength) TO <keyvalue>.
      ASSIGN COMPONENT x_namtab-viewfield
       OF STRUCTURE <table1_wa> TO <keyvalue>.
      tmp_sellist-viewfield = x_namtab-txttabfldn.
      IF x_namtab-inttype = 'C' and x_namtab-convexit = space.
        tmp_sellist-value = <keyvalue>.
      ELSE.
        CALL FUNCTION 'VIEW_CONVERSION_OUTPUT'
          EXPORTING
            value_intern = <keyvalue>
            tabname      = x_header-maintview
            fieldname    = x_namtab-viewfield
            inttype      = x_namtab-inttype
            datatype     = x_namtab-datatype
            decimals     = x_namtab-decimals
            convexit     = x_namtab-convexit
            sign         = x_namtab-sign
            outputlen    = x_namtab-outputlen
            intlen       = x_namtab-flength
          IMPORTING
            value_extern = tmp_sellist-value
          EXCEPTIONS
            OTHERS       = 1.
      ENDIF.
      APPEND tmp_sellist.
      tbx   = sy-tabix.
    ENDLOOP.
    IF tbx > 0.
      CLEAR tmp_sellist-and_or.
      MODIFY tmp_sellist INDEX tbx.
      CALL FUNCTION 'VIEW_FILL_WHERETAB'
        EXPORTING
          tablename               = x_header-texttab
          only_cnds_for_keyflds   = 'X'
          is_texttable            = 'X'
        TABLES
          sellist                 = tmp_sellist
          wheretab                = wheretab
          x_namtab                = x_namtab
        EXCEPTIONS
          no_conditions_for_table = 01.
      CREATE DATA tmp_texttab TYPE STANDARD TABLE OF (x_header-texttab).
      CREATE DATA w_tmp_texttab TYPE (x_header-texttab).
      ASSIGN: tmp_texttab->* TO <tmp_texttab>,
              w_tmp_texttab->* to <texttab_struc>,
              <texttab_struc> TO <texttab_wax> CASTING,
              <texttab_wax>(x_header-textkeylen) TO <texttab_key>,
              COMPONENT x_header-sprasfield OF STRUCTURE
               <texttab_struc> TO <lang>.
      SELECT * FROM (x_header-texttab) INTO TABLE <tmp_texttab>
                                      WHERE (wheretab).
      IF sy-subrc = 0.
*        ASSIGN texttab_wa(x_header-textkeylen) TO <texttab_key>.
        LOOP AT <tmp_texttab> INTO <texttab_struc>.
          MOVE <texttab_key> TO <vim_corr_keyx>(x_header-textkeylen).
*          WRITE <texttab_key>
*           TO corr_keytab-tabkey(x_header-textkeylen).
          PERFORM update_corr_keytab USING vake_action rc1.
          IF rc1 = 0.
            CLEAR vake_rc.
          ELSE.
            IF vake_action EQ pruefen. vake_rc = 8. EXIT. ENDIF.
          ENDIF.
        ENDLOOP.
      ELSE.
        CLEAR vake_rc.
      ENDIF.
    ENDIF.
  ENDIF.

ENDFORM.                               "VIM_TEXT_KEYTAB_ENTRY

* "SW Textcopy
*---------------------------------------------------------------------*
*       FORM VIM_COPY_TEXTTAB_ENTRY                                   *
*---------------------------------------------------------------------*
* Kopieren für Texttabelle :                                          *
*    neuen Eintrag für NEW_KEY für alle Sprachen in Texttabelle erzeugen
*       ?? bzw. -falls schon ex.- Texte darin ersetzen ??
*    Texte werden aus Originaleintrag ORIG_KEY übernommen
*---------------------------------------------------------------------*
* --> NEW_KEY   Schlüssel des neuen Eintrags
* --> ORIG_KEY  Schlüssel des zu kopierenden Eintrags
*---------------------------------------------------------------------*
FORM vim_copy_texttab_entry USING value(new_key) TYPE x
                                  value(orig_key) TYPE x.
  DATA: texttab_orig TYPE vim_line_ul,
        texttab_new  TYPE vim_line_ul,
        orig_tabix LIKE sy-tabix,
        new_tabix  LIKE sy-tabix,
        len TYPE i,
        offset TYPE i,
        langus_selected(1) TYPE c,
        curr_sptxt LIKE t002t-sptxt,
        sel_langus LIKE h_t002 OCCURS 0 WITH HEADER LINE.
  FIELD-SYMBOLS: <texttab_orig_x> TYPE x,
                 <h_texttab_orig_x> TYPE x,
                 <txttb_orig_struc> TYPE ANY,
                 <viewkey_in_orig> TYPE x,    "-> texttab_orig
                 <texttab_new_x> TYPE x,
                 <h_texttab_new_x> TYPE x,
                 <txttb_new_struc> TYPE ANY,
                 <viewkey_in_new> TYPE x,     "-> texttab_new
                 <spras_in_orig> TYPE spras,
                 <spras_in_new> TYPE spras,
                 <action_in_orig>,
                 <action_in_new>,
                 <textfields_in_new> TYPE x,
                 <textfields_in_orig> TYPE x,
                 <textkey_in_new> TYPE x.

  CALL FUNCTION 'VIEW_GET_LANGUAGES'
    EXPORTING
      all_without_selection = 'X'
    IMPORTING
      languages_selected    = langus_selected
      curr_sptxt            = curr_sptxt
    TABLES
      languages             = sel_langus.
  IF x_header-frm_tl_get NE space.
    PERFORM (x_header-frm_tl_get) IN PROGRAM (x_header-fpoolname)
                                  TABLES sel_langus.
  ELSE.
    PERFORM vim_read_texttab_for_langus TABLES sel_langus USING 'X'.
  ENDIF.

  READ TABLE <vim_texttab> WITH KEY orig_key
                           BINARY SEARCH TRANSPORTING NO FIELDS.
  CHECK sy-subrc = 0.
  orig_tabix = sy-tabix.
  ASSIGN: texttab_orig TO <texttab_orig_x> CASTING,
          <texttab_orig_x>(x_header-keylen) TO <viewkey_in_orig>,
          <texttab_orig_x>+x_header-after_keyc(x_header-texttablen)
           TO <h_texttab_orig_x>,
          <h_texttab_orig_x>
           TO <txttb_orig_struc> CASTING TYPE (x_header-texttab),
          COMPONENT x_header-sprasfield OF STRUCTURE <txttb_orig_struc>
           TO <spras_in_orig>.
  ASSIGN: texttab_new TO <texttab_new_x> CASTING,
          <texttab_new_x>(x_header-keylen) TO <viewkey_in_new>,
          <texttab_new_x>+x_header-after_keyc(x_header-textkeylen)
           TO <textkey_in_new>,
          <texttab_new_x>+x_header-after_keyc(x_header-texttablen)
           TO <h_texttab_new_x>,
          <h_texttab_new_x>
           TO <txttb_new_struc> CASTING TYPE (x_header-texttab),
          COMPONENT x_header-sprasfield OF STRUCTURE <txttb_new_struc>
           TO <spras_in_new>.
  offset = x_header-after_keyc + x_header-textkeylen.
  len = x_header-aft_txttbc - x_header-textkeylen.
  ASSIGN: <texttab_new_x>+offset(len) TO <textfields_in_new>,
          <texttab_orig_x>+offset(len) TO <textfields_in_orig>.
  offset = ( x_header-after_keyc + x_header-aft_txttbc )
           / cl_abap_char_utilities=>charsize.
  ASSIGN texttab_orig+offset(1) TO <action_in_orig>.
  ASSIGN texttab_new+offset(1) TO <action_in_new>.
*  ASSIGN texttab_orig(x_header-keylen) TO <viewkey_in_orig>.
*  ASSIGN texttab_new(x_header-keylen) TO <viewkey_in_new>.
*  ASSIGN texttab_new+x_header-keylen(x_header-textkeylen)
*                                       TO <textkey_in_new>.
*  offset = x_header-keylen + x_header-sprasfdpos.
*  ASSIGN texttab_orig+offset(vim_spras_length) TO <spras_in_orig>.
*  ASSIGN texttab_new+offset(vim_spras_length) TO <spras_in_new>.
*  offset = x_header-keylen + x_header-texttablen.
*  ASSIGN texttab_new+offset(1) TO <action_in_new>.
*  offset = x_header-keylen + x_header-textkeylen.
*  len = x_header-texttablen - x_header-textkeylen.
*  ASSIGN texttab_new+offset(len) TO <textfields_in_new>.
*  ASSIGN texttab_orig+offset(len) TO <textfields_in_orig>.

  LOOP AT <vim_texttab> INTO texttab_orig FROM orig_tabix.
    IF <viewkey_in_orig> <> orig_key. EXIT. ENDIF.
    READ TABLE <vim_texttab> WITH KEY new_key
                     INTO texttab_new BINARY SEARCH.
    new_tabix = sy-tabix.
    IF <viewkey_in_new> = new_key AND
       <spras_in_new> < <spras_in_orig>.                  "#EC PORTABLE
      LOOP AT <vim_texttab> FROM new_tabix INTO texttab_new.
        IF <viewkey_in_new> <> new_key OR                 "#EC PORTABLE
           <spras_in_new> >= <spras_in_orig>.
          new_tabix = sy-tabix.
          EXIT.
        ELSEIF <spras_in_new> < <spras_in_orig>.          "#EC PORTABLE
          new_tabix = sy-tabix + 1.
        ENDIF.
      ENDLOOP.
    ENDIF.
    IF <viewkey_in_new> <> new_key OR
       <spras_in_new> <> <spras_in_orig>.
*    es gibt noch keinen Eintrag mit neuem Schlüssel
      texttab_new = texttab_orig.
      <viewkey_in_new> = new_key.
      PERFORM map_viewkey_to_texttabkey TABLES x_namtab
                                        USING x_header
                                              <spras_in_orig>
                                              new_key
                                        CHANGING <textkey_in_new>.
*      PERFORM vim_fill_texttab_key USING new_key
*                          <spras_in_orig> x_header-sprasfdpos
*                                   CHANGING <textkey_in_new>.
      <action_in_new> = neuer_eintrag.
      INSERT texttab_new INTO <vim_texttab> INDEX new_tabix.
    ELSE.
      IF <action_in_new> = original.
        <action_in_new> = aendern.
      ENDIF.
      <textfields_in_new> = <textfields_in_orig>.
      MODIFY <vim_texttab> FROM texttab_new INDEX new_tabix.
    ENDIF.
  ENDLOOP.
  MODIFY vim_texttab_container INDEX vim_texttab_container_index.
ENDFORM.                               " VIM_COPY_TEXTTAB_ENTRY
*----------------------------------------------------------------------*
*   INCLUDE LSVIMFXP  form routines to activate profiles               *
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  GET_PROFILES
*&---------------------------------------------------------------------*
* NOT IN USE ANYMORE BUT CALLED IN APPLICATION FUNCTION GROUPS e.g.0WCA
*       Get customizing profiles using Function
*       SCPR_SHOW_CUT_OF_VIEW
*----------------------------------------------------------------------*
*  <--  p_selected  Flag X: Profil wurde bereits ausgewählt und
*                           importiert ==> nur anzeigen
*----------------------------------------------------------------------*
FORM get_profiles USING p_selected TYPE c.

  DATA: cobj_type VALUE 'V'.           "customizing-objecttype

  IF x_header-bastab NE space.
    cobj_type = vim_tabl.
  ENDIF.
  CLEAR vim_pr_activating.
  CALL FUNCTION 'SCPR_SHOW_OUT_OF_VIEW'
       EXPORTING
            tabname            = x_header-viewname
            tabtype            = cobj_type
            preselection       = p_selected
            cluster            = vim_called_by_cluster
       TABLES
            header             = x_header
            namtab             = x_namtab
            sellist            = <vim_ck_sellist>
       EXCEPTIONS
            user_abort         = 1
            no_profile_found   = 2
            profile_dont_exist = 3
            no_data            = 4
            OTHERS             = 5.
  CASE sy-subrc.
    WHEN 2.
      MESSAGE s820(sv).
*   Kein Profil gefunden.
    WHEN 3.
      IF cobj_type = 'S'.
        MESSAGE s822(sv) WITH x_header-viewname.
*   Zur Tabelle & existiert kein Profil.
      ELSE.
        MESSAGE s821(sv) WITH x_header-viewname.
*   Zur View & existiert kein Profil.
      ENDIF.
  ENDCASE.
ENDFORM.                               " GET_PROFILES
*&---------------------------------------------------------------------*
*&      Form  IMPORT_PROFILE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*----------------------------------------------------------------------*
FORM import_profile USING actopts TYPE scpractopt.

  DATA:          ext_field(1000),
                 pr_field(1000),
                 next,
                 i TYPE i VALUE 1,
                 extr_lin TYPE i,
                 len_text TYPE i, profile_used,
                 imported_to_all VALUE 'X'.
  FIELD-SYMBOLS: <pr_field>, <bc_total_key>,
                 <bc_total>, <bc_total_action>, <bc_total_mark>,
                 <w_record> TYPE vim_pr_tab_type.

  len_text = x_header-texttablen - x_header-textkeylen.
  CASE status-action.
    WHEN aendern.
* import in update mode
      IF status-mode = list_bild.
* import in list screen
        LOOP AT vim_pr_tab ASSIGNING <w_record>.
          IF <w_record>-action = aendern.
* update existing entry
            LOOP AT extract.
              CHECK <w_record>-keys = <vim_xextract_key>.
              PERFORM bcset_force_into_entry USING    <w_record>
                                                      aendern actopts.
              MODIFY extract.
              EXIT.
            ENDLOOP.
          ELSE.
* new entry
            MOVE <initial_x> TO <vim_xextract>.
            <vim_xextract_key> = <w_record>-keys.
            PERFORM bcset_force_into_entry USING    <w_record>
                                                  neuer_eintrag actopts.
            APPEND extract.
            ADD 1 TO maxlines.
          ENDIF.
        ENDLOOP.
        SORT extract BY <vim_xextract_key>.
      ELSE.
* import in detail mode
        LOOP AT vim_pr_tab ASSIGNING <w_record> WHERE
         action = neuer_eintrag.
          MOVE <initial_x> TO <vim_xextract>.
          <vim_xextract_key> = <w_record>-keys.
          PERFORM bcset_force_into_entry USING    <w_record>
                                               neuer_eintrag actopts.
          APPEND extract.
          ADD 1 TO maxlines.
        ENDLOOP.
* update existing entries
        LOOP AT vim_pr_tab ASSIGNING <w_record> WHERE action = aendern.
          CLEAR profile_used.
          LOOP AT extract.
            CHECK <w_record>-keys = <vim_xextract_key>.
            PERFORM bcset_force_into_entry USING    <w_record>
                                                    aendern actopts.
            MODIFY extract.
            profile_used = 'X'.
            EXIT.
          ENDLOOP.
          IF profile_used = space.
            LOOP AT total INTO extract.
              CHECK <w_record>-keys = <vim_xextract_key>.
              PERFORM bcset_force_into_entry USING    <w_record>
                                                      aendern actopts.
              APPEND extract.
              ADD 1 TO maxlines.
              EXIT.
            ENDLOOP.
          ENDIF.
        ENDLOOP.
        SORT extract BY <vim_xextract_key>.
      ENDIF.
    WHEN hinzufuegen.
* import from append status
      IF status-mode = list_bild.
* import in list mode
        DESCRIBE TABLE extract LINES extr_lin.
        LOOP AT vim_pr_tab ASSIGNING <w_record> WHERE
         action = neuer_eintrag.
          IF extr_lin LE i.
* add blank line to extract
            CLEAR extract. MOVE leer TO <xact>.
            APPEND extract.
          ENDIF.
* new entry
          LOOP AT extract FROM i.
            CHECK <xact> = leer.
            i = sy-tabix + 1.
            ADD 1 TO maxlines.
            <vim_xextract_key> = <w_record>-keys.
            PERFORM bcset_force_into_entry USING    <w_record>
                                                 neuer_eintrag actopts.
            MODIFY extract.
            EXIT.
          ENDLOOP.
        ENDLOOP.
      ELSE.
* import in detail mode
        MOVE <initial_x> TO <vim_xextract>.
        LOOP AT vim_pr_tab ASSIGNING <w_record> WHERE
         action = neuer_eintrag.
          <vim_xextract_key> = <w_record>-keys.
          PERFORM bcset_force_into_entry USING    <w_record>
                                               neuer_eintrag actopts.
          APPEND extract.
          ADD 1 TO maxlines.
        ENDLOOP.
      ENDIF.
* update existing entries
      LOOP AT vim_pr_tab ASSIGNING <w_record> WHERE action = aendern.
        LOOP AT total INTO extract.
          CHECK <w_record>-keys = <vim_xextract_key>.
          PERFORM bcset_force_into_entry USING    <w_record>
                                                  aendern actopts.
          APPEND extract.
          EXIT.
        ENDLOOP.
      ENDLOOP.
      SORT extract BY <vim_xextract_key>.
  ENDCASE.
ENDFORM.                               " IMPORT_PROFILE
*&---------------------------------------------------------------------*
*&      Form  GET_PROFILE_STATUS
*&---------------------------------------------------------------------*
*       Checks key fields of the profile whether they're fixed or not
*       and concatenates profile keys into the lines of vim_pr_tab
*       according to their nametab-position.
*       Table & Texttable: Fills textfield value and initial text key
*       into VIM_PR_TAB.
*----------------------------------------------------------------------*
*  <--  VIM_PR_TAB     contains for every record key status, key values
*                      and textfields
*  <--  VIM_PR_FIELDS  Contains all profile fields filled with
*                      values. Used to set the request-flag in PBO.
*----------------------------------------------------------------------*
FORM get_profile_status CHANGING vim_pr_tab LIKE vim_pr_tab
                                 vim_pr_fields LIKE vim_pr_fields[].

  DATA:          w_profile TYPE scpr_vals,
                 w_vim_pr_tab TYPE vim_pr_tab_type,
                 w_vim_pr_fields TYPE vim_pr_fields_type,
                 recnumber LIKE scprvals-recnumber,
                 text(1000), value LIKE vimsellist-value,
                 gottext, first, rc LIKE sy-subrc,
                 fieldname TYPE fnam_____4.
  FIELD-SYMBOLS: <pr_key>, <x_keys> TYPE x, <x_text> TYPE x,
                 <bc_val> TYPE ANY, <imp_val> TYPE ANY,
                 <keys_struc> TYPE ANY, <text_struc> TYPE ANY.

  ASSIGN: w_vim_pr_tab-keys TO <x_keys> CASTING,
          <x_keys> TO <keys_struc> CASTING TYPE (x_header-maintview).
  IF x_header-bastab <> space AND x_header-texttbexst <> space.
    ASSIGN: w_vim_pr_tab-textrecord TO <x_text> CASTING,
            <x_text> TO <text_struc> CASTING TYPE (x_header-texttab).
  ENDIF.
  RANGES dont_use FOR scprvals-recnumber.
  dont_use-sign = 'E'. dont_use-option = 'EQ'.

  LOOP AT vim_pr_tab INTO w_vim_pr_tab.
    READ TABLE vim_pr_fields INTO w_vim_pr_fields WITH KEY
     recnumber = w_vim_pr_tab-recnumber.
    <x_keys> = <initial_x>(x_header-keylen).
*    w_vim_pr_tab-keys = <initial>(x_header-keylen).
    IF x_header-bastab <> space AND x_header-texttbexst <> space.
      <x_text> = <initial_textkey_x>.
*      w_vim_pr_tab-textrecord = <initial_textkey>.
    ENDIF.
* Fill key fields
    LOOP AT x_namtab WHERE keyflag = 'X' AND texttabfld IS INITIAL.
      IF x_namtab-datatype = 'CLNT' AND x_header-clidep <> space.
*        MOVE sy-mandt TO
*             w_vim_pr_tab-keys+x_namtab-position(x_namtab-flength).
        DELETE TABLE w_vim_pr_fields-fields WITH TABLE KEY
         fieldname = x_namtab-viewfield.
        MODIFY TABLE vim_pr_fields FROM w_vim_pr_fields.
*        IF x_header-bastab <> space AND x_header-texttbexst <> space.
*          MOVE sy-mandt TO
*         w_vim_pr_tab-textrecord+x_namtab-texttabpos(x_namtab-flength).
*        ENDIF.
      ELSE.
        CLEAR w_profile.
        READ TABLE vim_profile_values INTO w_profile WITH KEY
                   tablename = x_header-viewname
                   fieldname = x_namtab-viewfield
                   recnumber = w_vim_pr_tab-recnumber.
        IF w_profile-flag = vim_profile_fixkey.
          CASE w_vim_pr_tab-keys_fix.
            WHEN space.
              w_vim_pr_tab-keys_fix = vim_pr_all_fix.
            WHEN vim_pr_open.
              w_vim_pr_tab-keys_fix = vim_pr_some_fix.
          ENDCASE.
        ELSE.
          CASE w_vim_pr_tab-keys_fix.
            WHEN space.
              w_vim_pr_tab-keys_fix = vim_pr_open.
            WHEN vim_pr_all_fix.
              w_vim_pr_tab-keys_fix = vim_pr_some_fix.
          ENDCASE.
        ENDIF.
        IF x_namtab-readonly <> subset."subsetf. already in <initial>
* use profile keyfield
          CONCATENATE x_header-maintview x_namtab-viewfield
           INTO fieldname SEPARATED BY '-'.
          ASSIGN: w_profile-value TO <bc_val> CASTING TYPE (fieldname),
                      COMPONENT x_namtab-viewfield
                       OF STRUCTURE <keys_struc> TO <imp_val>.
          <imp_val> = <bc_val>.
*          MOVE w_profile-value(x_namtab-flength) TO
*          w_vim_pr_tab-keys+x_namtab-position(x_namtab-flength).
          IF x_header-bastab <> space AND x_header-texttbexst <> space.
* make text table key (for finding the suitable text value only)
            ASSIGN COMPONENT x_namtab-txttabfldn
                   OF STRUCTURE <text_struc> TO <imp_val>.
            <imp_val> = <bc_val>.
*            MOVE w_profile-value(x_namtab-flength) TO
*         w_vim_pr_tab-textrecord+x_namtab-texttabpos(x_namtab-flength).
          ENDIF.
        ENDIF.                         "x_namtab-readonly <> subset
        w_vim_pr_fields-keys_fix = w_vim_pr_tab-keys_fix.
        MODIFY vim_pr_fields FROM w_vim_pr_fields TRANSPORTING keys_fix
                 WHERE recnumber = w_vim_pr_fields-recnumber.
      ENDIF.                           "x_namtab-datatype = 'CLNT'
    ENDLOOP.
    IF x_header-bastab <> space AND x_header-texttbexst <> space AND
       w_vim_pr_tab-keys_fix <> vim_pr_error.
* get record for text table
      CLEAR recnumber.
      IF vim_pr_records > 1.
        WHILE gottext = space.
          gottext = 'X'.
          first = 'X'.
          LOOP AT vim_profile_values INTO w_profile WHERE
                          tablename = x_header-texttab
                          AND recnumber IN dont_use[].
            IF first = 'X'.
              recnumber = w_profile-recnumber.
              CLEAR first.
            ELSE.
              IF recnumber <> w_profile-recnumber.
                IF gottext <> space. EXIT. ENDIF.
                recnumber = w_profile-recnumber.
              ENDIF.
            ENDIF.
            IF w_profile-flag+2 = 'Y'. "keY, ukY or fkY -> Key fields
* check key-value
              IF w_profile-fieldname = x_header-sprasfield.
                IF w_profile-value(1) <> sy-langu.
                  dont_use-low = recnumber.
                  APPEND dont_use.
                  CLEAR: text, gottext.
                  CONTINUE.
                ENDIF.
              ELSE.
                READ TABLE x_namtab WITH KEY
                                    viewfield = w_profile-fieldname
                                    keyflag = 'X' texttabfld = 'X'.
                CONCATENATE x_header-texttab x_namtab-txttabfldn
                         INTO fieldname SEPARATED BY '-'.
                ASSIGN: w_profile-value TO <bc_val>
                         CASTING TYPE (fieldname),
                        COMPONENT x_namtab-txttabfldn
                         OF STRUCTURE <text_struc> TO <imp_val>.
*                ASSIGN w_profile-value(x_namtab-flength) TO <vgl1>.
*   ASSIGN w_vim_pr_tab-textrecord+x_namtab-texttabpos(x_namtab-flength)
*                                                          TO <vgl2>.
*                IF <vgl1> <> <vgl2>.
                IF <imp_val> <> <bc_val>.
                  CLEAR gottext.
                  dont_use-low = recnumber.
                  APPEND dont_use.
*                    CLEAR text.
                  CONTINUE.
                ENDIF.
              ENDIF.
*              ELSE.
** store textfield.
*                text = w_profile-value.
*                APPEND w_profile-fieldname TO w_vim_pr_fields-fields.
            ENDIF.                                          "key field
          ENDLOOP.
        ENDWHILE.
        IF gottext <> space.
          recnumber = w_profile-recnumber.
        ENDIF.
*          IF NOT text IS INITIAL.
*            READ TABLE x_namtab WITH KEY keyflag = space
*                                         texttabfld = 'X'.
*            MOVE text TO
*         w_vim_pr_tab-textrecord+x_namtab-texttabpos(x_namtab-flength).
*            CLEAR: text, gottext.
*          ENDIF.
      ELSEIF vim_pr_records = 1.
* insert language into text table key
*           READ TABLE x_namtab WITH KEY viewfield = x_header-sprasfield
*                                        keyflag = 'X' texttabfld = 'X'.
        ASSIGN COMPONENT x_header-sprasfield
                      OF STRUCTURE <text_struc> TO <imp_val>.
        <imp_val> = sy-langu.
*            MOVE sy-langu TO
*         w_vim_pr_tab-textrecord+x_namtab-texttabpos(x_namtab-flength).
        READ TABLE vim_profile_values INTO w_profile WITH KEY
                   tablename = x_header-texttab
                   fieldname = x_header-sprasfield
                   value = sy-langu.
        IF sy-subrc = 0.
* textfield value found
          recnumber = w_profile-recnumber.
        ENDIF.
      ENDIF.                                                "lines = 1
      IF NOT recnumber IS INITIAL.
*textvalue in bc-set found
        LOOP AT x_namtab WHERE keyflag = space AND
                                     texttabfld = 'X'.
          CONCATENATE x_header-texttab x_namtab-viewfield
                   INTO fieldname SEPARATED BY '-'.
          READ TABLE vim_profile_values INTO w_profile WITH KEY
                           tablename = x_header-texttab
                           recnumber = recnumber
                           fieldname = x_namtab-viewfield.
          ASSIGN: w_profile-value TO <bc_val>
                   CASTING TYPE (fieldname),
                  COMPONENT x_namtab-viewfield
                   OF STRUCTURE <text_struc> TO <imp_val>.
          <imp_val> = <bc_val>.
*                MOVE w_profile-value
*      TO w_vim_pr_tab-textrecord+x_namtab-texttabpos(x_namtab-flength).
          APPEND w_profile-fieldname TO w_vim_pr_fields-fields.
        ENDLOOP.
      ELSE.
* no text value in bc-set
        MOVE <text_initial_x> TO <x_text>.
      ENDIF.
    ENDIF.                             "text table exists
    MODIFY vim_pr_tab FROM w_vim_pr_tab.
    MODIFY TABLE vim_pr_fields FROM w_vim_pr_fields.
  ENDLOOP.
ENDFORM.                                            "get_profile_status
*&---------------------------------------------------------------------*
*&      Form  ACTIVATE_PROFILE
*&---------------------------------------------------------------------*
*     No longer in use: For 6.20 the funcionality of BC set activation
*     via SM30 was abolished
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM activate_profile CHANGING p_selected
TYPE c.

  DATA: pr_rc TYPE i, pr_funcsafe(4), pr_counter TYPE i,
        pr_mark_entries VALUE 'X', hf1  TYPE i, hf  TYPE i,
        cobj_type VALUE 'V', pr_key_da, pr_recnumber TYPE scpr_recnr,
        bc_id TYPE scpr_id, bc_rec_found(1) TYPE c,
        actopts TYPE scpractopt."HCG always empty, only nec. 46C 610
  STATICS: viewname LIKE vimdesc-viewname.
  FIELD-SYMBOLS: <pr_f1> TYPE x, <w_record> TYPE vim_pr_tab_type,
                 <bc_key> TYPE x.

  CHECK status-action NE anzeigen AND  "ignore wrong setted requestflags
        status-action NE transportieren. "due to individual F4 modules
  CLEAR vim_pr_activating.
  IF p_selected IS INITIAL.
* read profile
    REFRESH: vim_profile_values, vim_pr_tab.
*    CALL FUNCTION 'SCPR_ACTIVATE'     // Ast stillgelegt, der Baustein
*                                      // existiert nicht mehr
*        EXPORTING
*             tabname          = x_header-viewname
*             initial          = <initial>
*       IMPORTING
*            PROFID           =
*        TABLES
*             values           = vim_profile_values
*             sellist          = dpl_sellist
*        EXCEPTIONS
*             user_abort       = 1
*             no_profile_found = 2
*             OTHERS           = 3.
*    CASE sy-subrc.
*      WHEN 0.
*        p_selected = 'X'. viewname = x_header-viewname.
*        SORT vim_profile_values BY id version tablename recnumber.
*        IF 'AU' CA status-action.
* get records the profile contains
*          PERFORM get_pr_nbr_records USING vim_profile_values
*                                           x_header
*                                     CHANGING pr_rc
*                                              bc_id
*                                              vim_pr_records
*                                              vim_pr_tab
*                                              vim_pr_fields.
* check key-status
*          PERFORM get_profile_status CHANGING vim_pr_tab
*                                              vim_pr_fields.
*        ENDIF.
*      WHEN 1.
*        EXIT.
*      WHEN 2.
*        IF x_header-bastab NE space.
*          cobj_type = vim_tabl.
*        ENDIF.
*        IF cobj_type = 'S'.
*          MESSAGE e822(sv) WITH x_header-viewname.
*   Zur Tabelle & existiert kein Profil.
*        ELSE.
*          MESSAGE e821(sv) WITH x_header-viewname.
*   Zur View & existiert kein Profil.
*        ENDIF.
*    ENDCASE.
  ELSE.
    IF vim_called_by_cluster <> space AND
     viewname <> x_header-viewname.
* update key values according to current view and selection
      viewname = x_header-viewname.
      IF 'AU' CA status-action.
* get records the profile contains
        PERFORM get_pr_nbr_records USING vim_profile_values
                                         x_header
                                   CHANGING pr_rc
                                            bc_id
                                            vim_pr_records
                                            vim_pr_tab
                                            vim_pr_fields.
* check key-status
        PERFORM get_profile_status CHANGING vim_pr_tab
                                            vim_pr_fields.
      ENDIF.
    ENDIF.
  ENDIF.
* check, if bc-set-records refer to existing datasets
  PERFORM bcset_key_check_in_total.
  PERFORM markiere_alle USING nicht_markiert.
  PERFORM import_profile USING actopts.
* viewcluster: show list of views to work on
  IF vim_called_by_cluster <> space.
    CALL FUNCTION 'VIEWCLUSTER_PR_IMPORT_CTRL'
         EXPORTING
              viewname        = x_header-viewname
              action          = 'M'
         TABLES
              profile_values  = vim_profile_values
         EXCEPTIONS
              wrong_parameter = 1
              OTHERS          = 2.
  ENDIF.
  replace_mode = 'X'.
  vim_special_mode = vim_upgrade.
* handle changed entries
  ASSIGN <vim_xtotal>(x_header-tablen) TO <pr_f1> CASTING.
  LOOP AT extract.
    CHECK <xact> = aendern OR <xact> = neuer_eintrag.
    CLEAR vim_bc_entry_list_wa.
    vim_bc_entry_list_wa-id = bc_id.
    vim_bc_entry_list_wa-viewname = x_header-viewname.
    hf = sy-tabix.
    READ TABLE total WITH KEY <vim_xextract_key> BINARY SEARCH.
    IF sy-subrc EQ 0.                  "entry exists in current client
      hf1 = sy-tabix.
      IF <xact> EQ neuer_eintrag AND
      <action> EQ geloescht OR <action> EQ neuer_geloescht OR
      <action> EQ update_geloescht.
        status-delete = geloescht.
* entry deleted in cur clnt -> first undelete it
        <xact> = <action>.
        MODIFY extract.
        pr_funcsafe = function.
        clear pr_rc.
        PERFORM vim_mark_and_process USING hf 'UNDO' hf1
                                           pr_rc.
        CLEAR status-delete. function = pr_funcsafe.
        CHECK pr_rc NE 4.
        IF pr_rc EQ 8.
          EXIT.
        ENDIF.
        READ TABLE extract INDEX hf.
        READ TABLE total WITH KEY <vim_xextract_key> BINARY SEARCH.
        hf1 = sy-tabix.
        <xact> = aendern. MODIFY extract.
      ENDIF.
      IF <vim_xtotal_key> = <vim_xextract_key>.
* record already exists: do not import but save
        <action> = aendern.
        MODIFY total INDEX hf1.
        IF x_header-bastab NE space AND x_header-texttbexst NE space.
          TRANSLATE <status>-upd_flag USING ' ETX'.
        ELSE.
          <status>-upd_flag = 'X'.
        ENDIF.
      ENDIF.
    ENDIF.                             "sy-subrc eq 0.
    CLEAR vim_pr_fields_wa.
    CLEAR bc_rec_found.
    LOOP AT vim_pr_tab ASSIGNING <w_record>.
      ASSIGN <w_record>-keys(x_header-keylen) TO <bc_key>.
      CHECK <bc_key> = <vim_xextract_key>.
      bc_rec_found = 'X'.
      READ TABLE vim_pr_fields INTO vim_pr_fields_wa WITH KEY
       recnumber = <w_record>-recnumber.
      vim_bc_entry_list_wa-id = bc_id.
      vim_bc_entry_list_wa-recnumber = <w_record>-recnumber.
      vim_bc_entry_list_wa-keys = <bc_key>.
*      if x_header-bastab <> space and x_header-texttbexst <> space.
** table with text table
*        vim_bc_entry_list_wa-keys + x_header-keylen =
*         <w_record>-textrecord(x_header-textkeylen).
*      endif.
      vim_bc_entry_list_wa-action = neuer_eintrag.
      INSERT LINES OF vim_pr_fields_wa-fields INTO TABLE
       vim_bc_entry_list_wa-fields.
      EXIT.
    ENDLOOP.
    CHECK NOT bc_rec_found IS INITIAL.
    IF <xact> <> aendern OR <pr_f1> <> <table2_x>.
* import bc-set record
      CHECK NOT vim_pr_fields_wa IS INITIAL.
      <status>-prof_found = vim_pr_into_view.
      PERFORM vim_modify_view_entry USING hf pr_rc.
      <status>-prof_found = vim_profile_found.
      CHECK pr_rc NE 4.
      IF pr_rc EQ 8.
        EXIT.
      ENDIF.
    ENDIF.
    READ TABLE total WITH KEY <vim_xtotal_key> BINARY SEARCH
                     TRANSPORTING NO FIELDS.
    IF <mark> EQ nicht_markiert.
      <mark> = markiert. ADD 1 TO mark_total.
      MODIFY total INDEX sy-tabix.
    ENDIF.
    extract = total.
    MODIFY extract.
    INSERT vim_bc_entry_list_wa INTO TABLE vim_bc_entry_list.
    IF sy-subrc = 4.
      MODIFY TABLE vim_bc_entry_list FROM vim_bc_entry_list_wa.
    ENDIF.
    ADD 1 TO pr_counter.
  ENDLOOP.
  IF pr_counter < vim_pr_records.
    MESSAGE s818(sv) WITH pr_counter vim_pr_records.
*   Es wurden &1 von &2 Einträgen des Business-Configuration-Sets import
  ELSE.
    MESSAGE s819(sv).
*   Das Business-Configuration-Set wurde vollständig importiert.
  ENDIF.
  nextline = 1.
  CLEAR: vim_special_mode, replace_mode.
  PERFORM fill_extract.
  IF status-action EQ hinzufuegen.
    status-action = aendern.
    title-action  = aendern.
    CLEAR <status>-selected.
  ENDIF.
  IF status-mode = detail_bild.
* return to list screen
    vim_next_screen = liste. vim_leave_screen = 'X'.
  ENDIF.
ENDFORM.                               " ACTIVATE_PROFILE
*&---------------------------------------------------------------------*
*&      Form  SET_PROFILE_KEY_ATTRIBUTES
*&---------------------------------------------------------------------*
*       sets screen input attribute according to profile attributes
*       of key field p_name
*----------------------------------------------------------------------*
*      <--P_SCREEN_INPUT  text
*      <--P_VIM_MODIFY_SCREEN  text
*----------------------------------------------------------------------*
FORM set_profile_key_attributes
                    USING p_name LIKE vim_objfield
                    CHANGING p_screen_input LIKE screen-input
                             p_modify_screen LIKE vim_modify_screen.

  DATA: w_field TYPE vimty_fields_type.

  p_screen_input = '0'.
  CASE vim_pr_fields_wa-keys_fix.
    WHEN vim_pr_open.
      p_screen_input = '1'. p_modify_screen = 'X'.
    WHEN vim_pr_all_fix.
      p_screen_input = '0'.
    WHEN vim_pr_some_fix.
      READ TABLE vim_pr_fields_wa-fields INTO w_field
          WITH KEY fieldname = p_name.
      IF w_field-flag <> vim_profile_fixkey.
        p_screen_input = '1'. p_modify_screen = 'X'.
      ENDIF.
  ENDCASE.
ENDFORM.                               " SET_PROFILE_KEY_ATTRIBUTES
*&---------------------------------------------------------------------*
*&      Form  PROFILE_PUT_INTO_WA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p_record  bc-set
*  -->  p_subset  flag: put "initial" value into subsetfield
*  -->  p_action  action-flag from EXTRACT
*  <--  p_field   view-maintenance dataset
*----------------------------------------------------------------------*
FORM profile_put_into_wa USING p_bc_set LIKE vim_profile_values
                               p_record TYPE vim_pr_tab_type
                               p_header TYPE vimdesc
                               p_namtab LIKE x_namtab[]
                               p_subset TYPE xfeld
                               p_action TYPE char1
                               actopts type scpractopt
                         CHANGING p_field.
  DATA:          w_profile TYPE scpr_vals,
                 fieldname TYPE fnam_____4,
                 old_guid TYPE REF TO data,
                 tabname_wa TYPE objs-tabname,
                 objecttype TYPE objs-objecttype VALUE 'S'.
  STATICS:       loc_viewname TYPE objs-objectname,
                 piecelist TYPE TABLE OF objs-tabname.

  FIELD-SYMBOLS: <namtab> TYPE vimnamtab, <field> TYPE ANY,
                 <old_guid> TYPE ANY, <work_area> TYPE ANY,
                 <bc_value> type any.

  CONSTANTS: no_standard(1) TYPE c VALUE 'F',
             stan(3) TYPE c VALUE 'USE'.

  ASSIGN p_field TO <work_area> CASTING TYPE (p_header-maintview).
  LOOP AT p_namtab ASSIGNING <namtab> WHERE keyflag = space
   AND texttabfld = space.
    ASSIGN COMPONENT <namtab>-viewfield OF STRUCTURE <work_area>
     TO <field>.
    CONCATENATE p_header-maintview <namtab>-viewfield
     INTO fieldname SEPARATED BY '-'.
    IF <namtab>-domname IN vim_guid_domain.
* GUID field
      IF p_action = neuer.
*     Overtake GUID from BC-Set for new entries.
      ELSE.
      IF p_record-keys_fix = vim_pr_all_fix.
        IF p_header-frm_af_uid <> space.
* prepare event 27
          CREATE DATA old_guid TYPE (fieldname).
*          ASSIGN p_field+<namtab>-position(<namtab>-flength)
*           TO <guid> CASTING TYPE (fieldname).
          ASSIGN: old_guid->* TO <old_guid>.
          <old_guid> = <field>.
        ENDIF.
      ELSE.
        CONTINUE.
* Use GUID from BC-Set only if complete key is given fix
      ENDIF.
    ENDIF.
    ENDIF.
    CASE <namtab>-readonly.
      WHEN space.
        READ TABLE p_bc_set INTO w_profile WITH KEY
        tablename = p_header-viewname fieldname = <namtab>-viewfield
        recnumber = p_record-recnumber TRANSPORTING flag value.
        CHECK sy-subrc = 0.
        ASSIGN w_profile-value TO <bc_value> CASTING TYPE (fieldname).
*       Do not overwrite field of existing dataset with BC-Set value
*       if standard field (flag = USE) and actopts-no_standard = Y.
        if actopts-no_standrd NE no_standard OR w_profile-flag NE stan.
          <field> = <bc_value>.
        endif.
*        MOVE w_profile-value(<namtab>-flength)
*             TO p_field+<namtab>-position(<namtab>-flength).
      WHEN rdonly OR vim_hidden.       "HCG Check if table in piece list
        IF p_header-viewname NE loc_viewname.
          loc_viewname = p_header-viewname.
          REFRESH piecelist.
          IF p_header-bastab EQ space. objecttype = 'V'. ENDIF.
          SELECT tabname FROM objs INTO tabname_wa   "Get info from OBJS
                       WHERE objectname = p_header-viewname
                       AND   objecttype = objecttype.
            APPEND tabname_wa TO piecelist.
          ENDSELECT.
        ENDIF.
        READ TABLE p_bc_set INTO w_profile WITH KEY
           tablename = p_header-viewname fieldname = <namtab>-viewfield
              recnumber = p_record-recnumber TRANSPORTING flag value.
        CHECK sy-subrc = 0.
        READ TABLE piecelist INTO tabname_wa WITH KEY
                                               <namtab>-bastabname.
        IF sy-subrc EQ 0. "HCG If table is not in piecelist: skip field
          ASSIGN w_profile-value TO <bc_value> CASTING TYPE (fieldname).
*         Do not overwrite field of existing dataset with BC-Set value
*         if standard field (flag = USE) and actopts-no_standard = Y.
          IF actopts-no_standrd NE no_standard OR
                                   w_profile-flag NE stan.
            <field> = <bc_value>.
          ENDIF.
        ENDIF.
      WHEN subset.
        CHECK p_subset <> space.
        ASSIGN COMPONENT <namtab>-viewfield OF STRUCTURE <initial>
         TO <bc_value>.
*        MOVE <initial>+<namtab>-position(<namtab>-flength)
*         TO p_field+<namtab>-position(<namtab>-flength).
    ENDCASE.
    IF <namtab>-domname IN vim_guid_domain
     AND p_record-keys_fix = vim_pr_all_fix
     AND  p_header-frm_af_uid <> space.
* event 27 for GUID field
      PERFORM (p_header-frm_af_uid) IN PROGRAM (p_header-fpoolname)
                                    USING <old_guid>
                                    CHANGING <field>
                                             <work_area>.
    ENDIF.
  ENDLOOP.
ENDFORM.                               " PROFILE_PUT_INTO_WA
*&---------------------------------------------------------------------*
*&      Form  GET_PR_NBR_RECORDS
*&---------------------------------------------------------------------*
*       Get the number of records the chosen profile contains and get
*       the fields every record contains.
*----------------------------------------------------------------------*
*      -->VIM_PROFILE_VALUES  contains bc-set
*      -->X_HEADER
*      -->P_RC                = 4: no record found
*      <--VIM_PR_RECORDS      number of records in bc-set
*      <--VIM_PR_TAB          table of bc-set-records, initialized
*      <--VIM_PR_FIELDS       lists of matched fields for every record
*----------------------------------------------------------------------*
FORM get_pr_nbr_records USING vim_profile_values
                               LIKE vim_profile_values
                              x_header TYPE vimdesc
                        CHANGING p_rc like sy-subrc
                                 p_bc_id TYPE scpr_id
                                 vim_pr_records TYPE i
                                 vim_pr_tab LIKE vim_pr_tab
                                 vim_pr_fields LIKE vim_pr_fields.

  DATA: w_vim_pr_tab TYPE vim_pr_tab_type, first VALUE 'X',
        w_vim_pr_fields TYPE vim_pr_fields_type,
        w_fields TYPE vimty_fields_type, recnumber TYPE scpr_recnr.
  FIELD-SYMBOLS: <profile_value> LIKE LINE OF vim_profile_values.

  REFRESH: vim_pr_tab, vim_pr_fields.
  CLEAR: vim_pr_records, p_rc.
  LOOP AT vim_profile_values ASSIGNING <profile_value>
       WHERE tablename = x_header-viewname.
    IF <profile_value>-recnumber <> recnumber.
      recnumber = <profile_value>-recnumber.
      IF first = space.
        APPEND w_vim_pr_tab TO vim_pr_tab.
        APPEND w_vim_pr_fields TO vim_pr_fields. CLEAR w_vim_pr_fields.
      ENDIF.
      CLEAR first.
      w_vim_pr_fields-recnumber = w_vim_pr_tab-recnumber
       = <profile_value>-recnumber.
      ADD 1 TO vim_pr_records.
    ENDIF.
    w_fields-fieldname = <profile_value>-fieldname.
    w_fields-flag = <profile_value>-flag.
    APPEND w_fields TO w_vim_pr_fields-fields.
  ENDLOOP.
  p_rc = sy-subrc.
  CHECK sy-subrc = 0.
  APPEND w_vim_pr_tab TO vim_pr_tab.
  APPEND w_vim_pr_fields TO vim_pr_fields.
  p_bc_id = <profile_value>-id.
*  IF w_vim_pr_tab-recnumber IS INITIAL.
*    w_vim_pr_tab-recnumber = 1. APPEND w_vim_pr_tab TO vim_pr_tab.
*    ADD 1 TO vim_pr_records.
*  ENDIF.
ENDFORM.                               " GET_PR_NBR_RECORDS
*&---------------------------------------------------------------------*
*&      Form  GET_PR_FIELD_FROM_SEL
*&---------------------------------------------------------------------*
*       extracts value for field P_PR_NAMTAB-VIEWFIELD from P_PR_SELLIST
*       into P_VIM_SEL_VALUE.
*----------------------------------------------------------------------*
*      <--P_SEL_VALUE   extracted value, P_SEL_VALUE remain sunchanged
*      <--P_RC          0: o.k.  1: no selection defined, P_SEL_VALUE
*                       remains unchanged  2: no unambiguous
*                       extraction possible, P_SEL_VALUE cleared
*      -->P_PR_SELLIST  text
*      -->P_PR_NAMTAB   text
*      -->P_PR_CLUSTER  Flag: View maintenance called by cluster
*----------------------------------------------------------------------*
FORM get_pr_field_from_sel
       USING    p_pr_sellist TYPE vimsellist_type
                p_pr_namtab LIKE vimnamtab
       CHANGING p_sel_value LIKE dpl_sellist-value
                p_rc LIKE sy-subrc.

  DATA: w_sellist LIKE vimsellist, first.

  p_rc = 1. first = 'X'.
  LOOP AT p_pr_sellist INTO w_sellist.
    CHECK w_sellist-viewfield = p_pr_namtab-viewfield.
    IF first = space OR w_sellist-operator <> 'EQ'.
      CLEAR p_sel_value. p_rc = 2. EXIT.
    ELSE.
      MOVE w_sellist-value(p_pr_namtab-flength) TO
       p_sel_value(p_pr_namtab-flength).
      p_rc = 0.
    ENDIF.
    CLEAR first.
  ENDLOOP.
ENDFORM.                               " GET_PR_FIELD_FROM_SEL
*&---------------------------------------------------------------------*
*&      Form  VIM_PR_mand_fields
*&---------------------------------------------------------------------*
*       Appending profiles in detail mode: Leaves screen to reset
*       mandatory attribute and to process sreen in background if
*       at least one dynpro-field is mandatory.
*----------------------------------------------------------------------*
FORM vim_pr_mand_fields.
  LOOP AT SCREEN.
    CHECK screen-required <> '0'.
    vim_pr_activating = 'X'.
    SET SCREEN detail. LEAVE SCREEN.
  ENDLOOP.
ENDFORM.                               " VIM_PR_AT_EXIT_COM
*&---------------------------------------------------------------------*
*&      Form  bcset_key_check_in_total
*&---------------------------------------------------------------------*
*       check, if bc-set-key already exists
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM bcset_key_check_in_total.

  DATA: w_record TYPE vim_pr_tab_type.
  FIELD-SYMBOLS: <bc_key> TYPE x.

  ASSIGN w_record-keys(x_header-keylen) TO <bc_key>.
  LOOP AT vim_pr_tab INTO w_record.
    CLEAR w_record-action.
    READ TABLE total WITH KEY <bc_key> BINARY SEARCH
     TRANSPORTING NO FIELDS.
    IF sy-subrc = 0.
      w_record-action = aendern.
    ELSE.
      w_record-action = neuer_eintrag.
    ENDIF.
    MODIFY vim_pr_tab FROM w_record.
  ENDLOOP.
ENDFORM.                               " bcset_key_check_in_total
*&---------------------------------------------------------------------*
*&      Form  bcset_force_into_entry
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_<W_RECORD>  text
*      <--P_AENDERN  text
*----------------------------------------------------------------------*
FORM bcset_force_into_entry USING    p_record TYPE vim_pr_tab_type
                                     p_action TYPE char1
                                     actopts TYPE scpractopt.

  field-symbols: <textrec_x> type x.

    IF <xmark> = nicht_markiert.
    <xmark> = markiert. ADD 1 TO mark_extract.
  ENDIF.
  <xact> = p_action.
  PERFORM profile_put_into_wa USING vim_profile_values
                                    p_record
                                    x_header
                                    x_namtab[]
                                    'X'
                                    p_action
                                    actopts
                              CHANGING <vim_xextract>.
*                              CHANGING <table2>.
  IF x_header-texttbexst <> space AND x_header-bastab <> space.
    assign p_record-textrecord(x_header-texttablen)
     to <textrec_x> casting.
    move <textrec_x> to <vim_xextract_text>.
*    MOVE p_record-textrecord+x_header-textkeylen(len_text)
*             TO <extract_text>+x_header-textkeylen(len_text).
  ENDIF.
ENDFORM.                               " bcset_force_into_entry
*----------------------------------------------------------------------*
*   INCLUDE LSVIMFX2                                                   *
*----------------------------------------------------------------------*
*---------------------------------------------------------------------*
*       FORM DETAILBILD                                               *
*---------------------------------------------------------------------*
*       .........                                                     *
*---------------------------------------------------------------------*
FORM detailbild.
  IF status-mode NE list_bild OR status-type NE zweistufig.
    MESSAGE i001(sv).
    EXIT.
  ENDIF.
  nextline = firstline + l - 1.
  IF l EQ 0 OR nextline GT maxlines.
    MESSAGE s032(sv).
    MOVE firstline TO nextline.
    EXIT.
  ENDIF.
  IF mark_extract > 0.                 "ufdetailb
    PERFORM set_mark_only USING nextline.
  ENDIF.                               "ufdetaile
  IF x_header-delmdtflag NE space.
    TRANSLATE vim_no_mainkey_exists USING vim_no_mkey_not_procsd_patt.
  ENDIF.
  PERFORM process_detail_screen USING 'S'.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM DETAIL_ABBRECHEN
**---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM detail_abbrechen.
  IF replace_mode EQ space AND
     ( sy-datar NE space OR
       ( x_header-bastab EQ space OR x_header-texttbexst EQ space )
       AND <table1_x> NE <table2_x>
       OR  x_header-bastab NE space AND x_header-texttbexst NE space
       AND ( <table1_x> NE <vim_xextract_enti>
             OR <table1_xtext> NE <vim_xextract_text> ) ).
    CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
         EXPORTING
              titel          = svim_text_007
              textline1      = svim_text_009
              textline2      = svim_text_006
              defaultoption  = 'N'
              cancel_display = ' '
         IMPORTING
              answer         = answer.
    IF answer NE 'J'.
      EXIT.
    ENDIF.
  ENDIF.
  IF status-action EQ kopieren.
    SET SCREEN 0.
    LEAVE SCREEN.
  ENDIF.
  IF maxlines LE 1.
*   IF STATUS-ACTION EQ HINZUFUEGEN OR STATUS-ACTION EQ KOPIEREN.
    IF status-action EQ hinzufuegen.
      status-action = aendern.
      title-action  = aendern.
      CLEAR <status>-selected.
    ENDIF.
    PERFORM fill_extract.
    nextline = 1.
  ENDIF.
  neuer = 'N'.
  IF vim_single_entry_function EQ space.
    <status>-upd_flag = space.
    IF replace_mode EQ space AND vim_special_mode NE vim_delete.
      l = nextline - <status>-firstline + 1.
      IF l LE 0 OR l GT looplines.
        l = 1.
      ENDIF.
      nextline = <status>-firstline.
      SET SCREEN liste.
    ELSE.
      SET SCREEN 0. CLEAR vim_act_dynp_view.
    ENDIF.
  ELSE.                                "single_entry_function
    function = end. SET SCREEN 0. CLEAR vim_act_dynp_view.
    PERFORM update_status.
  ENDIF.
  LEAVE SCREEN.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM DETAIL_BACK                                              *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM detail_back.

  DATA:count TYPE i.

  CASE status-action.
    WHEN aendern.
      PERFORM update_tab.
    WHEN hinzufuegen.
*      WRITE <f1> TO entry(x_header-keylen).
      move <f1_x> to <f1_wax>.
      PERFORM update_tab.
      neuer = 'N'.
*      SORT extract BY <vim_extract_key>.
      SORT extract BY <vim_xextract_key>.
*      MOVE entry TO <table1>.
*      READ TABLE extract WITH KEY <f1> BINARY SEARCH.
      READ TABLE extract WITH KEY <f1_x>.
      firstline = 1.
      IF sy-tabix GT looplines AND looplines GT 0.
        count = ( sy-tabix - firstline ) div looplines + 1.
        DO count TIMES.
          firstline = firstline + looplines - 1.
        ENDDO.
        MOVE firstline TO <status>-firstline.
      ENDIF.
      l = sy-tabix - firstline + 1.
      MOVE l TO <status>-cur_line.
      MOVE <initial> TO <table1>.
      IF x_header-bastab NE space AND x_header-texttbexst NE space.
        MOVE <text_initial_x> TO <table1_xtext>.
*        MOVE <text_initial> TO <table1_text>.
      ENDIF.
  ENDCASE.
  IF status-data EQ auswahldaten AND maxlines LE 1.
    <table1_wax> = <vim_xextract>.
    IF status-delete = geloescht.
      status-delete = nicht_geloescht.
      title-action  = aendern.
      PERFORM markiere_alle USING nicht_markiert.
    ENDIF.
    IF status-action EQ hinzufuegen.
      status-action = aendern.
      title-action  = aendern.
      CLEAR <status>-selected.
    ENDIF.
    IF x_header-delmdtflag NE space.
      <vim_h_mkey>(x_header-keylen) = <f1_x>.
      LOOP AT vim_collapsed_mainkeys. "WHERE mkey_bf EQ <vim_f1_before>.
        IF vim_collapsed_mainkeys-mkey_bf EQ space. "SW: wie liste_back
* change XB 11.06.02 BCEK060520/BCEK060521 ----------begin--------------
* if <vim_collapsed_mkey_bfx> should be changed, only when it isn't
* constant 4B00, that means data isn't at position 0.
          if <vim_collapsed_mkey_bfx> NE <vim_mkey_beforex>.
          <vim_collapsed_mkey_bfx> = <vim_collapsed_logkeyx>.
*          vim_collapsed_mainkeys-mkey_bf =
*                                       vim_collapsed_mainkeys-log_key.
          endif.
* change XB 11.06.02 BCEK060520/BCEK060521 ------------end--------------
          CLEAR vim_collapsed_mainkeys-log_key.
        ENDIF.                                              "SW
        <f1_x> = <vim_h_coll_mkey>.
*        <f1> = vim_collapsed_mainkeys-mainkey.
        <vim_enddate_mask> = space.
        <vim_h_coll_mkey> = <f1_x>.
*        vim_collapsed_mainkeys-mainkey = <f1>.
        MODIFY vim_collapsed_mainkeys.
      ENDLOOP.
      IF vim_delim_expa_excluded NE space.
        DELETE excl_cua_funct WHERE function EQ 'EXPA'.
        CLEAR vim_delim_expa_excluded.
      ENDIF.
      IF status-action = aendern AND title-action = hinzufuegen.
        title-action  = aendern.
      ENDIF.
    ENDIF.
    PERFORM fill_extract.
*    <table1> = entry(x_header-keylen).
*    READ TABLE extract WITH KEY <f1>.
    READ TABLE extract WITH KEY <f1_wax>.
    IF sy-subrc EQ 0.
      nextline = sy-tabix.
    ELSE.
      nextline = 1.
    ENDIF.
  ELSE.
    MOVE firstline TO nextline.
  ENDIF.
  vim_next_screen = liste. vim_leave_screen = 'X'.
ENDFORM.
*&--------------------------------------------------------------------*
*&      Form  DETAIL_EXIT_COMMAND                                     *
*&--------------------------------------------------------------------*
* handle exit commands on detail screen                               *
*&--------------------------------------------------------------------*
FORM detail_exit_command.
  DATA: answer.
  function = ok_code.
  CLEAR vim_old_viewkey.
  TRANSLATE vim_no_mainkey_exists USING vim_no_mkey_not_procsd_patt.
  CASE ok_code.
    WHEN 'ABR '.
      CLEAR ok_code.
      PERFORM detail_abbrechen.
    WHEN 'IGN '.
      PERFORM ignorieren.
    WHEN 'UPRF'.                       "UFprofileB
      CHECK vim_pr_activating = space.
*      IF SY-DATAR <> SPACE.
*        CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
*             EXPORTING
*                  TEXTLINE1      = SVIM_TEXT_PRF
*                  TEXTLINE2      = SVIM_TEXT_PRG
*                  TITEL          = SVIM_TEXT_PRE
*                  CANCEL_DISPLAY = ' '
*             IMPORTING
*                  ANSWER         = ANSWER.
*        IF ANSWER <> 'J'.
*          CLEAR: FUNCTION, OK_CODE.
*        ENDIF.
*      ENDIF.
      IF NOT function IS INITIAL.
        PERFORM vim_pr_mand_fields.
      ENDIF.
    WHEN 'GPRF'.
      CHECK vim_pr_activating = space.
      PERFORM vim_pr_mand_fields         .         "UFprofileE
  ENDCASE.
ENDFORM.                               "detail_exit_command
*---------------------------------------------------------------------*
*       FORM DETAIL_INIT                                              *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM detail_init.
  CONSTANTS: forward VALUE 'X'.
  IF function NE space.
    status-mode = detail_bild.
    title-mode  = detail_bild.
    IF <xmark> EQ markiert.
      status-mark = markiert.
    ELSE.
      status-mark = nicht_markiert.
    ENDIF.
    IF status-action NE kopieren AND neuer NE 'J'.
      IF <status>-selected = by_field_contents AND nextline > maxlines.
        nextline = 1.                  "377434/1999 UF011299
      ENDIF.
      IF x_header-subsetflag NE space AND replace_mode EQ space.
        PERFORM fill_subsetfields.
      ENDIF.
* ========== XB int225314/03 H601454 begin ==========
* maxlines must GT nextline in EXTRACT, otherweise the
* empty entry in EXTRACT will be readed.
      if nextline > maxlines.
        PERFORM read_table USING maxlines.
      else.
        PERFORM read_table USING nextline.
      endif.
* ========== XB int225314/03 H601454 end   ==========
      IF x_header-subsetflag NE space.
        PERFORM complete_subsetfields.
      ENDIF.
    ENDIF.
    IF vim_special_mode EQ vim_delimit.
      MOVE vim_sval_tab-value TO <vim_new_begdate>.
    ENDIF.
  ENDIF.
  CLEAR: vim_key_alr_checked, vim_keyrange_alr_checked.
  vim_act_dynp_view = x_header-viewname.
  PERFORM set_title USING title <name>.
  CASE replace_mode.
    WHEN space.
*     SET PF-STATUS STATUS EXCLUDING EXCL_CUA_FUNCT.
      IF neuer NE 'X'. "error in CHECK_KEY for timedep. objects
        IF vim_special_mode NE vim_delete.
          PERFORM set_pf_status USING status.
        ELSE.
          PERFORM set_pf_status USING 'REPLACE'.
        ENDIF.
      ENDIF.
    WHEN OTHERS.
*     SUPPRESS DIALOG.
*     SET PF-STATUS 'REPLACE'.
      PERFORM set_pf_status USING 'REPLACE'.
*     IF X_HEADER-BASTAB NE SPACE AND X_HEADER-TEXTTBEXST NE SPACE.
*     IF VIM_SPECIAL_MODE NE VIM_UPGRADE AND
*        X_HEADER-BASTAB NE SPACE AND X_HEADER-TEXTTBEXST NE SPACE.
*       IF REPLACE_TEXTTABLE_FIELD NE SPACE.
*         MOVE 'T' TO <STATUS>-UPD_FLAG.
*       ELSE.
*         MOVE 'E' TO <STATUS>-UPD_FLAG.
*       ENDIF.
*     ELSE.
*       MOVE 'X' TO <STATUS>-UPD_FLAG.
*     ENDIF.
*     EXIT.
  ENDCASE.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM DETAIL_LOESCHE                                           *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM detail_loesche.
  DATA: tot_ix LIKE sy-tabix, rec LIKE sy-subrc,
        delete_fix_value(1) TYPE c,
        entry_contains_fix_val(1) TYPE c,
        w_field TYPE vimty_fields_type,
        bc_fix_del_info_sent(1) TYPE c VALUE ' '.

*   -------Authority check before deleting fix values from BC-Sets------
    delete_fix_value = vim_bc_chng_allowed.
    IF vim_bc_chng_allowed = space.  "fix field changeability forced
      READ TABLE vim_bc_entry_list INTO vim_bc_entry_list_wa
      WITH TABLE KEY viewname = x_header-viewname
      keys = <vim_xextract_key>.
      IF sy-subrc = 0.
        CLEAR entry_contains_fix_val.
        LOOP at vim_bc_entry_list_wa-fields into w_field.
          IF w_field-flag = vim_profile_fix.
            entry_contains_fix_val = 'X'.
          ENDIF.
        ENDLOOP.
        IF entry_contains_fix_val = 'X'.
          IF bc_fix_del_info_sent EQ SPACE AND
             <status>-bcfixdelinfosent NE 'Y'."HCG: del dependent VCL
            bc_fix_del_info_sent = 'X'.
            <status>-bcfixdelinfosent = 'X'.
            MESSAGE i177(SV).
          ENDIF.
        ELSE.
          delete_fix_value = 'X'.
        ENDIF.
      ELSE.
        delete_fix_value = 'X'.
      ENDIF.
    ENDIF.
    CHECK delete_fix_value EQ 'X'.
*   -------------------------------------------------------------"HCG---
  IF <xmark> NE uebergehen.
    READ TABLE total WITH KEY <vim_xextract_key> BINARY SEARCH.
    MOVE sy-tabix TO tot_ix.
    IF x_header-existency EQ 'M'.      "no mainkey delete allowed
      PERFORM check_if_entry_can_be_deleted.
      IF sy-subrc NE 0.
        <xmark> = uebergehen. ignored_entries_exist = 'X'.
        MODIFY extract INDEX nextline.
        <mark> = uebergehen.
        MODIFY total INDEX tot_ix.
        EXIT.
      ENDIF.
    ENDIF.
    PERFORM logical_delete_from_total USING tot_ix.
    IF <xmark> EQ markiert.
      mark_total  = mark_total - 1.
      mark_extract = mark_extract - 1.
    ENDIF.
    IF x_header-delmdtflag NE space.
      IF vim_special_mode NE vim_upgrade.
        PERFORM check_if_entry_is_to_display USING 'L' <vim_xtotal_key>
                                                   space <vim_begdate>.
      ELSE.
        CLEAR sy-subrc.
      ENDIF.
    ENDIF.
    IF x_header-delmdtflag EQ space OR sy-subrc LT 8.
      rec = sy-subrc.
      DELETE extract INDEX nextline.
      IF rec EQ 4.
        LOOP AT total.
          PERFORM select USING <status>-selected.
          CHECK sy-subrc EQ 0.
          CHECK <vim_tot_mkey_beforex> EQ <vim_old_mkey_beforex> AND
                ( vim_mkey_after_exists EQ space OR
                  <vim_tot_mkey_afterx> EQ <vim_old_mkey_afterx> ).
*          CHECK <vim_tot_mkey_before> EQ <vim_old_mkey_before> AND
*                ( vim_mkey_after_exists EQ space OR
*                  <vim_tot_mkey_after> EQ <vim_old_mkey_after> ).
          vim_mainkey = vim_old_viewkey.
          extract = total.
          PERFORM mod_extract_and_mainkey_tab USING 'I' nextline.
          EXIT.
        ENDLOOP.
      ENDIF.
    ENDIF.
    IF vim_special_mode EQ vim_upgrade.
      counter = 1.
      EXIT.
    ENDIF.
    IF ignored_entries_exist EQ space AND maxlines GT 1.
      MESSAGE s013(sv).
    ELSE.
      MESSAGE i013(sv).
    ENDIF.
  ENDIF.
  IF <status>-mark_only <> space.      "ufdetailb
    DESCRIBE TABLE extract LINES maxlines.
    IF mark_extract = 0.
* last marked entry deleted
      nextline = 1.
      vim_next_screen = liste. vim_leave_screen = 'X'.
    ELSE.
* search next marked entry
      nextline = nextline - 1.
      PERFORM get_marked_entry USING 'X'
                  CHANGING nextline
                           rec.
      IF rec <> 0.
* search previous marked entry
        nextline = nextline + 1.
        PERFORM get_marked_entry USING space
                    CHANGING nextline
                             rec.
      ENDIF.
      IF rec <> 0.
        nextline = 1. vim_next_screen = liste. vim_leave_screen = 'X'.
      ELSE.
        PERFORM get_page_and_position USING nextline
                                            looplines
                                      CHANGING firstline
                                               l.
      ENDIF.
    ENDIF.

  ELSE.                                "ufdetaile
    DESCRIBE TABLE extract LINES maxlines.
    IF maxlines EQ 0.
      nextline = 1.
      IF status-action EQ hinzufuegen.
        status-action = aendern.
        title-action = aendern.
      ENDIF.
      PERFORM fill_extract.
      vim_next_screen = liste. vim_leave_screen = 'X'.
    ENDIF.
    IF nextline GT maxlines.
      nextline = maxlines.
    ENDIF.
  ENDIF.                               "ufdetail
  READ TABLE total INDEX tot_ix.
  CLEAR vim_old_viewkey.
  TRANSLATE vim_no_mainkey_exists USING vim_no_mkey_not_procsd_patt.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM DETAIL_MARKIERE                                          *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM detail_markiere.
  IF neuer EQ 'J'.
    EXIT.
  ENDIF.
  PERFORM update_tab.
* PERFORM MARKIERE USING FIRSTLINE.
  PERFORM markiere USING nextline.
  CLEAR function.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM DETAIL_MARKIERTE                                         *
*---------------------------------------------------------------------*
*       UF300798 Detail-screen only with marked entries except line-
*                selection on list-screen
*---------------------------------------------------------------------*
FORM detail_markierte.

  DATA: rc LIKE sy-subrc.

  IF status-mode NE list_bild OR status-type NE zweistufig.
    MESSAGE i001(sv).
    EXIT.
  ENDIF.
  IF mark_extract = 0.
* no entries marked
    PERFORM detailbild.
    EXIT.
  ENDIF.
  <status>-mark_only = 'X'.
** current entry marked?
*  nextline = firstline + l - 1.
*  PERFORM check_marked USING nextline
*                       CHANGING rc.
*  IF rc <> 0.
* search first marked entry
  nextline = 0.
  PERFORM get_marked_entry USING 'X'
                           CHANGING nextline
                                    rc.
  IF rc <> 0. PERFORM detailbild. EXIT. ENDIF.
*  ENDIF.
  IF x_header-delmdtflag NE space.
    TRANSLATE vim_no_mainkey_exists USING vim_no_mkey_not_procsd_patt.
  ENDIF.
  PERFORM process_detail_screen USING 'S'.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM DETAIL_PAI                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
* <--- NEXT_SCREEN - next screen to process                           *
* <--- LEAVE_SCREEN - flag: X - leave screen necessary                *
*---------------------------------------------------------------------*
FORM detail_pai.
  CLEAR: vim_next_screen, vim_leave_screen.
  MOVE: status-data TO <status>-st_data,
        status-mode TO <status>-st_mode,
        status-delete TO <status>-st_delete,
        status-action TO <status>-st_action,
        title         TO <status>-title,
        maxlines      TO <status>-maxlines,
        mark_extract  TO <status>-mk_xt,
        mark_total    TO <status>-mk_to,
        function      TO <status>-fcode.
  IF x_header-ptfrkyexst NE space.
    PERFORM consistency_prt_frky_fields USING 'X'.
  ENDIF.
* IF TEMPORAL_DELIMITATION_HAPPENED NE SPACE AND
*    STATUS-ACTION NE KOPIEREN.
  IF <status>-prof_found <> space.
    CLEAR vim_pr_fields_wa.            "UFprofiles
  ENDIF.
  IF vim_special_mode NE vim_upgrade AND
     temporal_delimitation_happened NE space AND
     status-action NE kopieren.
    PERFORM update_tab.
    PERFORM after_temporal_delimitation.
    CLEAR temporal_delimitation_happened.
    PERFORM check_if_entry_is_to_display USING 'L' <f1_x> space
                                               <vim_begdate>.
    IF status-action EQ hinzufuegen.
      IF function NE 'NEXT'.
        CASE sy-subrc.
          WHEN 0.                      "expanded mode or new entry
            PERFORM read_table USING nextline.
          WHEN 4.                      "collapsed mode and actual entry
            READ TABLE extract WITH KEY <f1_x>.
            nextline = sy-tabix.
            extract = total.
            CLEAR function.
          WHEN OTHERS.                 "collapsed mode and other entry
            LOOP AT extract.
              CHECK <vim_ext_mkey_beforex> EQ <vim_f1_beforex> AND
                    ( vim_mkey_after_exists EQ space OR
                    <vim_ext_mkey_afterx> EQ <vim_f1_afterx> ).
              nextline = sy-tabix.
              EXIT.
            ENDLOOP.
            extract = total.
            CLEAR function.
        ENDCASE.
      ENDIF.
    ELSE.
      IF sy-subrc EQ 0.
        ADD 1 TO exind.
        nextline = exind.
      ENDIF.
    ENDIF.
  ENDIF.
* FUNCTION = OK_CODE.
  CLEAR ok_code.
  IF replace_mode NE space AND
     ( vim_special_mode NE vim_upgrade OR
       NOT function IN exted_functions ).
    PERFORM update_tab.
*   SET SCREEN 0.
    vim_next_screen = 0. vim_leave_screen = 'X'.
    EXIT.
  ELSEIF vim_special_mode EQ vim_delete.
    vim_next_screen = 0. vim_leave_screen = 'X'. EXIT.
  ENDIF.
  IF vim_single_entry_function NE space AND function NE space.
    IF vim_single_entry_ins_key_input EQ space.
      TRANSLATE status-action USING 'AU'. status-data = gesamtdaten.
    ENDIF.
    IF function EQ 'UEBE'.
      function = 'ENDE'.
    ENDIF.
  ENDIF.
  CASE function.
    WHEN 'ADDR'.
      PERFORM address_maintain.
    WHEN 'AEND'.
      PERFORM anzg_to_aend.
    WHEN 'ALCO'.
      PERFORM selektiere USING transportieren.
    WHEN 'ALMK'.
      PERFORM selektiere USING markiert.
    WHEN 'ALNC'.
      PERFORM selektiere USING space.
    WHEN 'ALOE'.
      PERFORM selektiere USING geloescht.
    WHEN 'ALNW'.
      PERFORM selektiere USING neuer_eintrag.
    WHEN 'ANZG'.
      PERFORM update_tab.
      IF l EQ 0. MOVE: 1 TO l, 1 TO <status>-cur_line. ENDIF.
*        SET SCREEN 0. LEAVE SCREEN.
      vim_next_screen = 0. vim_leave_screen = 'X'.
    WHEN 'ATAB'.
      PERFORM update_tab.
      IF l EQ 0. MOVE: 1 TO l, 1 TO <status>-cur_line. ENDIF.
*     SET SCREEN 0. LEAVE SCREEN.
      vim_next_screen = 0. vim_leave_screen = 'X'.
    WHEN 'BCCH'.                       "change fix bc-set fields
      PERFORM vim_chng_fix_flds.
    WHEN 'BCSH'.                        " show fix bc-set fields
      PERFORM vim_bc_show_fix_flds.
    WHEN 'DELE'.
*     PERFORM DETAIL_LOESCHE.
      PERFORM loeschen.
      IF replace_mode NE space.
        <status>-mk_to = mark_total.
        <status>-mk_xt = mark_extract.
        vim_next_screen = 0. vim_leave_screen = 'X'.
        EXIT.
      ENDIF.
    WHEN 'DELM'.
      PERFORM delimitation.
    WHEN 'ENDE'.
      PERFORM update_tab.
      IF l EQ 0. MOVE: 1 TO l, 1 TO <status>-cur_line. ENDIF.
*     SET SCREEN 0. LEAVE SCREEN.
      vim_next_screen = 0. vim_leave_screen = 'X'.
    WHEN 'EXPA'.
*     perform ........
    WHEN 'FDOC'.                       "HW Functiondocu
      PERFORM show_function_docu.
      CLEAR function.
*    WHEN 'GPRF'.                       "UF Profile
* choose profile
*      CLEAR: <status>-prof_found, vim_pr_records.
*      PERFORM get_profiles USING <status>-prof_found.
    WHEN 'KOPE'.
      counter = 0.
      PERFORM kopiere.
    WHEN 'KOPF'.
*       IF X_HEADER-ADRNBRFLAG NE SPACE.
*         PERFORM ADDRESS_MAINTAIN.
*       ENDIF.
      PERFORM kopiere_eintrag USING <orig_key>.
    WHEN 'LANG'.                       "SW Texttransl
      PERFORM vim_set_languages.
      CLEAR function.
    WHEN 'MKEZ'.
      PERFORM detail_markiere.
    WHEN 'NEWL'.
      PERFORM update_tab.
      CLEAR <status>-mark_only.        "UFdetail
      PERFORM hinzufuegen.
    WHEN 'NEXT'.
      PERFORM naechster.
    WHEN 'ORDR'.
      PERFORM order_administration.
    WHEN 'ORGI'.
      PERFORM original_holen.
    WHEN 'POSI'.
      PERFORM popup_positionieren.
    WHEN 'PREV'.
      PERFORM voriger.
    WHEN 'PRMO'.
* 4.6A: obsolete, left only for individual status
      PERFORM update_tab.
      PERFORM list_alv.
    WHEN 'PROT'.
      PERFORM logs_analyse.
    WHEN 'PRST'.
      PERFORM update_tab.
      PERFORM list_alv.
    WHEN 'SAVE'.
      PERFORM update_tab.
      IF status-action EQ hinzufuegen.
        SORT extract BY <vim_xextract_key>.
*        READ TABLE extract WITH KEY extract BINARY SEARCH.
        READ TABLE extract WITH KEY <vim_xextract_key>.
        <status>-cur_line = l = sy-tabix - firstline + 1.
      ENDIF.
*     SET SCREEN 0. LEAVE SCREEN.
      vim_next_screen = 0. vim_leave_screen = 'X'.
    WHEN 'SCRF'.
      PERFORM update_tab.
      PERFORM vim_sapscript_form_maint.
    WHEN 'SEAR'.
      PERFORM update_tab.
      PERFORM suchen.
    WHEN 'SELU'.
      PERFORM selektiere USING aendern.
    WHEN 'TEXT'.
      PERFORM update_tab.
      PERFORM vim_multi_langu_text_maint.
    WHEN 'TREX'.
      MOVE geloescht TO corr_action.
      PERFORM update_corr.
      IF replace_mode NE space.
        <status>-mk_to = mark_total.
        <status>-mk_xt = mark_extract.
        vim_next_screen = 0. vim_leave_screen = 'X'.
        EXIT.
      ENDIF.
    WHEN 'TRIN'.
      MOVE hinzufuegen TO corr_action.
      PERFORM update_corr.
      IF replace_mode NE space.
        <status>-mk_to = mark_total.
        <status>-mk_xt = mark_extract.
        vim_next_screen = 0. vim_leave_screen = 'X'.
        EXIT.
      ENDIF.
    WHEN 'TRSP'.
*     SET SCREEN 0. LEAVE SCREEN.
      IF x_header-cursetting NE space AND
         x_header-flag EQ vim_transport_denied.
        x_header-flag = x_header-cursetting.
        TRANSLATE x_header-flag USING 'X YX'.
        MODIFY x_header INDEX 1.
      ENDIF.
      vim_next_screen = 0. vim_leave_screen = 'X'.
    WHEN 'UEBE'.
      PERFORM detail_back.
    WHEN 'UPRF'.
* activate chosen profile
*      PERFORM activate_profile CHANGING <status>-prof_found.
      message s175(SV).
    WHEN 'UNDO'.
*     PERFORM DETAIL_ZURUECKHOLEN.
      PERFORM zurueckholen.
      IF replace_mode NE space.
        <status>-mk_to = mark_total.
        <status>-mk_xt = mark_extract.
        vim_next_screen = 0. vim_leave_screen = 'X'.
        EXIT.
      ENDIF.
    WHEN '    '.
      IF vim_prt_fky_flds_updated NE space.
        CLEAR vim_prt_fky_flds_updated.
        PERFORM update_tab.
      ELSE.
        IF x_header-frm_h_flds NE space.
          PERFORM (x_header-frm_h_flds) IN PROGRAM.
        ENDIF.
        IF neuer EQ 'J' AND vim_key_alr_checked EQ space.
*          IF x_header-guidflag <> space.
*            PERFORM vim_make_guid.
*          ENDIF.
          IF x_header-frm_on_new NE space.
            PERFORM (x_header-frm_on_new) IN PROGRAM.
          ENDIF.
        ENDIF.
        PERFORM check_key.
      ENDIF.
    WHEN OTHERS.
      IF vim_called_by_cluster NE space.                    "SW Crtl ..
        CALL FUNCTION 'VIEWCLUSTER_NEXT_ACTION'
             EXPORTING
                  detail       = 'X'
             IMPORTING
                  leave_screen = vim_leave_screen
             CHANGING
                  fcode        = function.
        IF vim_leave_screen NE space.
          PERFORM update_tab.
          vim_next_screen = 0.
        ENDIF.
      ENDIF.                           ".. SW Ctrl
  ENDCASE.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM DETAIL_ZURUECKHOLEN                                       *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM detail_zurueckholen.
  DATA: tot_ix LIKE sy-tabix, msg_type(1) TYPE c, msg_no LIKE sy-msgno,
        rc LIKE sy-subrc.
  IF x_header-delmdtflag NE space.
    counter = 1.
    PERFORM temporal_delimitation.
  ENDIF.
  IF <xmark> EQ markiert.
    mark_total  = mark_total - 1.
    mark_extract = mark_extract - 1.
  ENDIF.
  READ TABLE total WITH KEY <vim_xextract_key> BINARY SEARCH.
  MOVE sy-tabix TO tot_ix.
  PERFORM logical_undelete_total USING sy-tabix.
  IF temporal_delimitation_happened NE space.
    CLEAR vim_delim_entries.
    PERFORM check_if_entry_is_to_display USING 'L' <vim_xtotal_key>
                                               space <vim_begdate>.
    IF sy-subrc LT 8.
      vim_delim_entries-index3 = nextline.
      IF sy-subrc EQ 4.
        LOOP AT total.
          CHECK <action> EQ geloescht OR <action> EQ neuer_geloescht OR
                <action> EQ update_geloescht.
          CHECK <vim_tot_mkey_beforeX> EQ <vim_old_mkey_beforeX> AND
                ( vim_mkey_after_exists EQ space OR
                  <vim_tot_mkey_afterX> EQ <vim_old_mkey_afterX> ).
*          CHECK <vim_tot_mkey_before> EQ <vim_old_mkey_before> AND
*                ( vim_mkey_after_exists EQ space OR
*                  <vim_tot_mkey_after> EQ <vim_old_mkey_after> ).
          vim_delim_entries-index1 = sy-tabix.
          vim_delim_entries-index2 = vim_delim_entries-index3.
          EXIT.
        ENDLOOP.
      ENDIF.
      APPEND vim_delim_entries.
    ENDIF.
    PERFORM after_temporal_delimitation.
    CLEAR temporal_delimitation_happened.
  ELSE.
    IF replace_mode NE space AND vim_external_mode EQ space.
      extract = total.
      MODIFY extract INDEX nextline.   "no deletion in upgrade mode
    ELSE.
      DELETE extract INDEX nextline.
      SUBTRACT 1 FROM maxlines.
    ENDIF.
  ENDIF.
  IF replace_mode EQ space.
    IF counter GT 1. msg_no = '002'. ELSE. msg_no = '003'. ENDIF.
    IF ignored_entries_exist EQ space.
      msg_type = 'S'.
    ELSE.
      msg_type = 'W'.
    ENDIF.
    MESSAGE ID 'SV' TYPE msg_type NUMBER msg_no WITH counter.
    IF nextline NE 1 AND nextline GT maxlines.
      nextline = maxlines.
    ENDIF.
    IF maxlines EQ 0.
      title-action = aendern.
      status-delete = nicht_geloescht.
      vim_next_screen = liste. vim_leave_screen = 'X'.
    ELSEIF <status>-mark_only <> space.
      IF mark_extract = 0.
* last marked entry deleted
        nextline = 1.
        vim_next_screen = liste. vim_leave_screen = 'X'.
      ELSE.
* search next marked entry
        nextline = nextline - 1.
        PERFORM get_marked_entry USING 'X'
                    CHANGING nextline
                             rc.
        IF rc <> 0.
* search previous marked entry
          nextline = nextline + 1.
          PERFORM get_marked_entry USING space
                      CHANGING nextline
                               rc.
        ENDIF.
        IF rc <> 0.
          nextline = 1. vim_next_screen = liste. vim_leave_screen = 'X'.
        ELSE.
          PERFORM get_page_and_position USING nextline
                                              looplines
                                        CHANGING firstline
                                                 l.
        ENDIF.
      ENDIF.
    ENDIF.
    READ TABLE total INDEX tot_ix.
  ELSE.
    counter = 1.
  ENDIF.
  CLEAR vim_old_viewkey.
  TRANSLATE vim_no_mainkey_exists USING vim_no_mkey_not_procsd_patt.
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  GET_MARKED_ENTRY
*&---------------------------------------------------------------------*
*       Search marked entries in EXTRACT beginning at index p_index
*----------------------------------------------------------------------*
*      -->P_FORWARD  'X': search forward
*                    ' ': search backward
*      <--P_index    in: start from here (including)
*                    out: index of first marked entry found
*      <--P_RC       0: further marked entry found
*                    4: no further marked entry found
*----------------------------------------------------------------------*
FORM get_marked_entry USING    p_forward TYPE sychar01
                      CHANGING p_index LIKE sy-tabix
                               p_rc LIKE sy-subrc.
  DATA: bw_index LIKE sy-tabix.

  p_rc = 4.
  IF p_forward IS INITIAL.
* search backward
    bw_index = p_index - 1.
    WHILE bw_index > 0.
      READ TABLE extract INDEX bw_index.
      IF <xmark> = markiert.
        p_index = bw_index.
        CLEAR p_rc.
        EXIT.
      ENDIF.
      bw_index = bw_index - 1.
    ENDWHILE.
  ELSE.
* search forward.
    p_index = p_index + 1.
    LOOP AT extract FROM p_index.
      CHECK <xmark> = markiert.
      p_index = sy-tabix.
      CLEAR p_rc.
      EXIT.
    ENDLOOP.
    IF p_rc > 0.
      p_index = p_index - 1.
    ENDIF.
  ENDIF.
ENDFORM.                               " GET_MARKED_ENTRY
*---------------------------------------------------------------------*
*       FORM NAECHSTER                                                *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM naechster.
  DATA: last_list_pos LIKE sy-tabix, rc LIKE sy-subrc.
  IF status-action NE anzeigen AND status-action NE transportieren
  AND status-mode NE list_bild.
    PERFORM update_tab.
  ENDIF.
  IF <status>-mark_only = space.       "ufdetail
* jump to next entry
    nextline = nextline + 1.
    IF nextline GT maxlines.
      IF status-action NE hinzufuegen.
        nextline = maxlines.
        MESSAGE s008(sv).
        EXIT.
      ELSE.
        IF status-type EQ zweistufig AND
           status-mode EQ detail_bild.
          neuer = 'J'.
          MOVE <initial> TO <table1>.
          MOVE <table1> TO <vim_extract_struc>.
          IF x_header-bastab NE space AND x_header-texttbexst NE space.
            MOVE: <text_initial_x> TO <table1_xtext>,
                 <table1_xtext> TO <vim_xextract_text>.
*            MOVE: <text_initial_x> TO <table1_text>,
*                  <table1_text> TO <extract_text>.
          ENDIF.
          nextline = maxlines + 1.
        ELSE.
          nextline = nextline - 1.
          MESSAGE s008(sv).
        ENDIF.
      ENDIF.
    ENDIF.
  ELSE.                                "ufdetailb
* jump to next marked entry
    PERFORM get_marked_entry USING 'X'
                             CHANGING nextline
                                      rc.
    IF rc <> 0.
      MESSAGE s830(sv).
*   Letzter markierter Eintrag bereits erreicht.
      EXIT.
    ENDIF.
  ENDIF.                               "ufdetaile
  IF looplines = 0.
* coming from lower viewcluster-node
    l = nextline - firstline + 1.
    MOVE l TO <status>-cur_line.
  ELSEIF looplines = 1.
    firstline = l = 1.
    MOVE: firstline TO <status>-firstline,
          l         TO <status>-cur_line.
  ELSEIF looplines > 1.
    IF status-mode EQ detail_bild.
      last_list_pos = firstline + looplines - 1.
      IF nextline GT last_list_pos.
        IF <status>-mark_only = space. "ufdetail
          firstline = firstline + looplines - 1.
          l = 2.
        ELSE.                          "ufdetailb
          PERFORM get_page_and_position USING nextline
                                              looplines
                                        CHANGING firstline
                                                 l.
        ENDIF.                         "ufdetaile
        MOVE: firstline TO <status>-firstline,
              l         TO <status>-cur_line.
      ELSE.
        IF status-mode NE list_bild.
          l = nextline - firstline + 1.
          MOVE l TO <status>-cur_line.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  SET_MARK_ONLY
*&---------------------------------------------------------------------*
*       Sets status flag if entry with index p_index is marked.
*----------------------------------------------------------------------*
*      -->P_index  EXTRACT-index
*----------------------------------------------------------------------*
FORM set_mark_only USING    p_index LIKE sy-tabix.
  DATA: rc LIKE sy-subrc.
  PERFORM check_marked USING p_index
                       CHANGING rc.
  IF rc = 0.
    <status>-mark_only = 'X'.
  ENDIF.
ENDFORM.                               " SET_MARK_ONLY
*---------------------------------------------------------------------*
*       FORM PROCESS_DETAIL_SCREEN                                    *
*---------------------------------------------------------------------*
* process detail screen call                                          *
*---------------------------------------------------------------------*
* ---> MODE - C -> call mode (CALL SCREEN), S -> set mode (SET SCREEN)*
*---------------------------------------------------------------------*
FORM process_detail_screen USING value(mode) TYPE c.
  DATA: modulpool LIKE trdir-name, no_input_happened(1) TYPE c,
        state_action(1) TYPE c.
  IF detail NE '0000'.
    IF mode EQ 'S'.
      SET SCREEN detail.
      LEAVE SCREEN.
    ELSE.
      PERFORM vim_imp_call_screen USING detail.
    ENDIF.
  ELSE.
    RAISE detail_scr_nbr_missing.
  ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM VORIGER                                                  *
*---------------------------------------------------------------------*
*       NEXTLINE:   Index of current entry in table EXTRACT
*       FIRSTLINE:  EXTRACT-index of first line shown on list screen
*       L:          Line number of list screen, where entry was chosen
*                   via F2
*       LOOPLINES:  Number of step loop lines in list screen
*---------------------------------------------------------------------*
FORM voriger.
  DATA: rc LIKE sy-subrc, n TYPE i.

  IF status-action NE anzeigen AND status-action NE transportieren
  AND status-mode NE list_bild.
    PERFORM update_tab.
  ENDIF.
  IF <status>-mark_only = space.       "ufdetail
* jump to previous entry
    nextline = nextline - 1.
    IF nextline LE 0.
      nextline = 1.
      MESSAGE s007(sv).
    ELSEIF nextline LT firstline.
* scroll upwards
      IF looplines > firstline.
* bumping into top of EXTRACT
        firstline = 1.
        l = nextline.
      ELSE.
        firstline = firstline - looplines + 1.
        l = looplines - 1.
      ENDIF.
      MOVE: firstline TO <status>-firstline,
           l         TO <status>-cur_line.
    ELSE.
      l = nextline - firstline + 1.
      MOVE l TO <status>-cur_line.
    ENDIF.
  ELSE.                                "ufdetailb
* jump to previous marked entry
    n = nextline DIV ( looplines - 1 ).
    PERFORM get_marked_entry USING space
                             CHANGING nextline rc.
    IF rc > 0.
      MESSAGE s831(sv).
*   Erster markierter Eintrag bereits erreicht.
    ELSE.
      IF nextline LT firstline.
        PERFORM get_page_and_position USING nextline
                                            looplines
                                      CHANGING firstline
                                               l.
        MOVE: firstline TO <status>-firstline,
              l         TO <status>-cur_line.
      ELSE.
        l = nextline - firstline + 1.
        MOVE l TO <status>-cur_line.
      ENDIF.
    ENDIF.
  ENDIF.                               "ufdetaile
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  CHECK_MARKED
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_P_INDEX  text
*      <--P_RC  text
*----------------------------------------------------------------------*
FORM check_marked USING    p_index LIKE sy-tabix
                  CHANGING p_rc LIKE sy-subrc.

  p_rc = 4.
  READ TABLE extract INDEX p_index.
  IF sy-subrc = 0 AND <xmark> = markiert. CLEAR p_rc. ENDIF.
ENDFORM.                               " CHECK_MARKED
*&---------------------------------------------------------------------*
*&      Form  GET_PAGE_AND_POSITION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LINE      line in EXTRACT
*      -->P_LOOPLINES # lines in list screen
*      <--P_FIRST     number of first line in list screen
*      <--P_PAGELINE  number of line no. P_LINE in list screen
*----------------------------------------------------------------------*
FORM get_page_and_position USING    p_line LIKE sy-tabix
                                    p_looplines LIKE sy-tabix
                           CHANGING p_first LIKE sy-tabix
                                    p_pageline LIKE sy-tabix.
  DATA: m TYPE i.
  m = p_line DIV ( p_looplines - 1 ).
  p_first = m * ( p_looplines - 1 ) + 1.
  p_pageline = p_line MOD ( p_looplines - 1 ).
ENDFORM.                               " GET_PAGE_AND_POSITION

*---------------------------------------------------------------------*
*       FORM  VIM_MODIFY_DETAIL_SCREEN                                *
*---------------------------------------------------------------------*
* Modifizieren der Screen-Attribute für das Detailbild                *
*---------------------------------------------------------------------*
FORM vim_modify_detail_screen.

  DATA: dummyflag TYPE xfeld.

  CLEAR vim_set_from_bc_pbo.
* dataset from BC-set? --> get field parameters
  IF replace_mode = space AND status-action = aendern
   AND vim_bc_chng_allowed = space.    "force changeability
    READ TABLE vim_bc_entry_list INTO vim_bc_entry_list_wa
     WITH TABLE KEY viewname = x_header-viewname
     keys = <vim_xextract_key>.
    IF sy-subrc = 0.
      vim_set_from_bc_pbo = 'X'.
    ENDIF.
  ENDIF.
  LOOP AT SCREEN.
    SPLIT screen-name AT '-' INTO vim_object vim_objfield. "Subviews ..
    IF status-action EQ anzeigen OR status-action EQ transportieren OR
       status-delete EQ geloescht.
      screen-input = '0'.
    ELSE.
      IF screen-group1 EQ 'KEY' AND screen-required NE 0 AND
         screen-input NE '0'.
        screen-input = '0'.
      ENDIF.
      IF status-action EQ hinzufuegen OR
         status-action EQ kopieren.
        IF neuer CO 'XJ' .
          IF screen-group1 EQ 'KEY'.
            IF ( vim_single_entry_function NE 'INS' OR
                 vim_single_entry_ins_key_input NE space ) AND
               ( x_header-existency NE 'M' OR
                 screen-name EQ vim_enddate_name ).
              screen-input = '1'.
            ENDIF.
            IF vim_single_entry_function EQ 'INS'.
              screen-request = '1'. sy-subrc = 8.
            ENDIF.
          ENDIF.
          IF vim_special_mode EQ vim_upgrade AND function NE 'DELE'.
            IF <status>-prof_found = vim_pr_into_view "UFprofiles begin
             AND screen-group1 = 'KEY'.
              PERFORM set_profile_key_attributes USING vim_objfield
                                                 CHANGING screen-input
                                                     vim_modify_screen.
              CLEAR vim_modify_screen.
            ENDIF.                     "UFprofiles end
            screen-request = '1'. sy-subrc = 8.
          ENDIF.
        ENDIF.
        IF vim_pr_activating <> space.
          IF screen-required = '1'.
* obligatory fields shall not stop profile import
            screen-required = '0'.     "UFprofile
          ENDIF.
        ENDIF.
      ELSE.
        IF replace_mode NE space.
          CASE vim_special_mode.
            WHEN vim_replace.
              IF screen-name EQ sel_field_for_replace_l.
                screen-request = '1'. sy-subrc = 8.
                IF screen-invisible = '1'.
                  screen-input = '1'.
                ENDIF.
              ENDIF.
            WHEN vim_upgrade.
              IF NOT function IN exted_functions.
                screen-request = '1'. sy-subrc = 8.
              ENDIF.
*             screen-input = '1'.
          ENDCASE.
        ELSE.
          IF vim_special_mode EQ vim_delete.
            screen-input = '0'.
          ENDIF.
          IF x_header-delmdtflag NE space AND
             x_header-existency EQ 'U' AND
             screen-name EQ vim_begdate_name.
            screen-input = '0'.
          ENDIF.
        ENDIF.
        IF status-action = aendern AND neuer <> 'J'.
          IF vim_set_from_bc_pbo <> space.
* Dataset comes from BC-set -> check field parameter
            PERFORM vim_bc_logs_use USING    vim_objfield
                                             vim_bc_entry_list_wa
                                    CHANGING screen
                                             dummyflag.
          ENDIF.
        ENDIF.
      ENDIF. "status-action EQ hinzufuegen OR status-action EQ kopieren.
    ENDIF.
    IF <xmark> EQ markiert AND <status>-mark_only = space. "ufdetail
      screen-intensified = '1'.
    ENDIF.
    IF vim_objfield <> space AND vim_object = x_header-maintview.
      LOOP AT x_namtab WHERE viewfield = vim_objfield AND
                             ( texttabfld = space OR keyflag = space ).
        IF x_namtab-readonly = vim_hidden.
          screen-active = '0'.
        ELSEIF x_namtab-readonly = rdonly.
          screen-input = '0'.
        ENDIF.
        EXIT.
      ENDLOOP.
    ENDIF.                             ".. Subviews
    MODIFY SCREEN.
  ENDLOOP.
ENDFORM.                               "vim_modify_detail_screen
*----------------------------------------------------------------------*
*   INCLUDE LSVIMFX3                                                   *
*----------------------------------------------------------------------*
*&--------------------------------------------------------------------*
*&      Form LIST_ALV                                               *
*&--------------------------------------------------------------------*
* D_VIA_SELECTION_SCREEN --> X - mit Selektion, ' ' - Standardliste   *
*&--------------------------------------------------------------------*
FORM list_alv.

*  STATICS: vim_alv_fcat TYPE slis_t_fieldcat_alv,  --> global
*           alv_events TYPE slis_t_event,
*           alv_layout TYPE slis_layout_alv.
  STATICS: texttab_begin LIKE sy-tabix,
           textlen TYPE intlen, unittab TYPE tabname,
           unitname TYPE fieldname, cukytab TYPE tabname,
           cukyname TYPE fieldname,
           glob_unitvalue(3) TYPE c,    "vim_unit,UF296573/2000
           glob_cukyvalue TYPE vim_cuky.
  DATA: textfld_no, textoffset TYPE intlen, rc LIKE sy-subrc,
        progname LIKE sy-repid, value_len TYPE intlen,
        w_alv_value_tab TYPE tabl8000.
  FIELD-SYMBOLS: <alv_fcat> LIKE LINE OF vim_alv_fcat,
                 <textfields>.

  IF x_header-frm_bf_prn <> space.
* old user exit for printing still used
    PERFORM drucken_ztp_alt.
    EXIT.
  ENDIF.
  IF NOT vim_alv_fcat[] IS INITIAL.
    READ TABLE vim_alv_fcat ASSIGNING <alv_fcat> INDEX 1.
    IF <alv_fcat>-ref_tabname <> view_name.
      UNASSIGN <alv_fcat>. FREE vim_alv_fcat.
    ENDIF.
  ENDIF.
  IF vim_alv_fcat[] IS INITIAL.
* build up field catalogue from X_NAMTAB
    PERFORM fill_alv_fieldcat CHANGING vim_alv_fcat
                                       texttab_begin
                                       vim_alv_value_length
                                       unittab
                                       unitname
                                       glob_unitvalue
                                       cukytab
                                       cukyname
                                       glob_cukyvalue.
    PERFORM define_alv_callbacks CHANGING vim_alv_events.
    PERFORM make_list_commentary USING unittab
                                       unitname
                                       glob_unitvalue
                                       cukytab
                                       cukyname
                                       glob_cukyvalue
                                 CHANGING vim_list_header.
    PERFORM make_alv_layout CHANGING vim_alv_layout
                                     vim_alv_print.
    PERFORM init_alv_variant CHANGING vim_var_save
                                      vim_var_default
                                      vim_alv_variant.
    vim_alv_called_by = 'VIM_CALL_ALV'.
*    REFRESH: vim_alv_excluding, vim_alv_special_groups,
*             vim_alv_sort, vim_alv_event_exit.
*    CLEAR:   vim_alv_print, vim_alv_sel_hide.
  ENDIF.                               "new structure table
  REFRESH alv_value_tab.
  IF status-mode = list_bild.
* Build ALV_VALUE_TAB
    LOOP AT extract.
      w_alv_value_tab = <vim_xextract>.
*    LOOP AT extract ASSIGNING <extract_line>.
*      alv_value_tab = <extract_line>.
      APPEND w_alv_value_tab TO alv_value_tab.
    ENDLOOP.
  ELSE.
* Build VALUE_TAB with single line
    w_alv_value_tab = <vim_xextract>.
*    alv_value_tab = extract.
    APPEND w_alv_value_tab TO alv_value_tab.
  ENDIF.
  IF x_header-bastab <> space AND x_header-texttbexst <> space.
* table and texttable
    textlen = x_header-aft_txttbc - x_header-aft_txtkc.
*  IF x_header-bastab = space OR x_header-texttbexst = space
*   OR x_header-maintview NE x_header-viewname.
* no table & texttable
*    CLEAR textlen.
*  ENDIF.
*  IF textlen <> 0.
* Shift fields
    PERFORM maintain_alv_value_tab_text USING    textlen.
  ELSE.
    vim_alv_value_length = x_header-tablen.
  ENDIF.
  IF x_header-frm_bf_alv <> space.
    PERFORM (x_header-frm_bf_alv) IN PROGRAM (sy-repid).
* Release 6.10(Unicode): alv_value_tab has got type RAW!
* useful parameters:
*   vim_alv_value_length     int. length of dataset in alv_value_tab
*   vim_alv_called_by        form routine calling FM ALV_LIST_DISPLAY
*                            preset value: 'VIM_CALL_ALV'
*   alv_value_tab[]          internal table containing values
*   vim_alv_fcat[]     \
*   vim_alv_events[]    |
*   vim_list_header[]   >    preset by view-maintenance
*   vim_alv_variant     |
*   vim_alv_layout     /
    CHECK NOT alv_value_tab[] IS INITIAL. "suppress list
  ENDIF.
  PERFORM check_list_before_alv CHANGING rc.
  CHECK rc = 0.
  progname = sy-repid.
  CALL FUNCTION 'REUSE_ALV_TABLE_CREATE'
    EXPORTING
      it_fieldcat        = vim_alv_fcat
      i_callback_program = progname
      i_formname         = vim_alv_called_by.
  FREE alv_value_tab.
ENDFORM.                               " LIST_ALV

*&--------------------------------------------------------------------*
*&      Form DRUCKEN_ZTP_ALT                                          *
*&--------------------------------------------------------------------*
* Keeps compatibility of view maintenance dialogs using old user exit
* "before printing"
* D_VIA_SELECTION_SCREEN --> X - mit Selektion, ' ' - Standardliste   *
*&--------------------------------------------------------------------*
FORM drucken_ztp_alt.
  DATA: rc_safe LIKE sy-subrc, texttab_begin LIKE sy-tabix, x TYPE i,
        entifct_begin LIKE sy-tabix, len TYPE i,
        after_text_assigned TYPE c, hname LIKE d021s-fnam.
  DATA: fcat_entry TYPE slis_fieldcat_alv, i TYPE i,
        cukytab TYPE tabname, unittab TYPE tabname, rc LIKE sy-subrc,
        cukyname TYPE fieldname, unitname TYPE fieldname,
        cukyvalue TYPE vim_cuky, unitvalue TYPE vim_unit,
        length TYPE doffset, cukylength TYPE doffset,
        fcat_entry2 TYPE slis_fieldcat_alv, progname LIKE sy-repid,
        alv_called_by TYPE char30 VALUE 'VIM_CALL_ALV'.
  FIELD-SYMBOLS: <before_text>, <text>, <after_text>, <cuky>, <unit>,
                 <value> TYPE tabl8000, <w_value_tab_x> TYPE x.

  CLEAR structure_table.
  DESCRIBE TABLE structure_table.
  IF sy-tfill NE 0. READ TABLE structure_table INDEX 1. ENDIF.
  IF structure_table-tabname NE view_name.
    CALL FUNCTION 'VIEW_GET_FIELDTAB'
      EXPORTING
        view_name = view_name
      TABLES
        fieldtab  = structure_table.
    IF x_header-bastab NE space AND x_header-texttbexst NE space
       AND x_header-maintview = x_header-viewname.           "Subviews
* einfügen text-felder in structure_table hinter entity-key
      LOOP AT x_namtab WHERE texttabfld NE space
                         AND keyflag NE space.
        texttab_begin = sy-tabix.
        EXIT.
      ENDLOOP.
      LOOP AT x_namtab WHERE texttabfld EQ space
                         AND keyflag EQ space.
        entifct_begin = sy-tabix.
        EXIT.
      ENDLOOP.
      IF sy-subrc NE 0.  "no entifct fields -> delete text key fields
        LOOP AT structure_table FROM texttab_begin
                                WHERE keyflag NE space.
          DELETE structure_table.
        ENDLOOP.
      ELSE.
        WHILE sy-subrc EQ 0.
          LOOP AT structure_table FROM texttab_begin.
            DELETE structure_table.
            IF structure_table-keyflag EQ space.
              EXIT.
            ENDIF.
          ENDLOOP.
          IF sy-subrc EQ 0.
            INSERT structure_table INDEX entifct_begin.
            ADD: 1 TO entifct_begin, 1 TO texttab_begin.
          ENDIF.
        ENDWHILE.
      ENDIF.
* aktualisieren von offset und position in structure_table
      len = 0.
      LOOP AT structure_table.
        structure_table-offset = len.
        structure_table-position = sy-tabix.
* Alignment
        IF 'CNDT' CS structure_table-inttype.
* Character-like datatypes
          x = ( structure_table-offset
                + cl_abap_char_utilities=>charsize )
                MOD cl_abap_char_utilities=>charsize.
          IF x NE 0.
            structure_table-offset = structure_table-offset
                               + cl_abap_char_utilities=>charsize - x.
          ENDIF.
        ELSE.
          CASE structure_table-datatype.
            WHEN 'INT2' OR 'PREC'.
              x = ( structure_table-offset + 2 ) MOD 2.
              IF x NE 0.
                structure_table-offset = structure_table-offset + 2 - x.
              ENDIF.
            WHEN 'INT4'.
              x = ( structure_table-offset + 4 ) MOD 4.
              IF x NE 0.
                structure_table-offset = structure_table-offset + 4 - x.
              ENDIF.
            WHEN 'FLTP'.
              x = ( structure_table-offset + 8 ) MOD 8.
              IF x NE 0.
                structure_table-offset = structure_table-offset + 8 - x.
              ENDIF.
          ENDCASE.
        ENDIF.
        MODIFY structure_table.
        len = structure_table-offset + structure_table-intlen.
      ENDLOOP.
    ENDIF.                             "table with texttable
    IF x_header-hiddenflag NE space.   "hidden fields exist
* ignore hidden fields
      LOOP AT x_namtab WHERE readonly EQ vim_hidden OR
       domname IN vim_guid_domain.
        LOOP AT structure_table WHERE fieldname EQ x_namtab-viewfield.
          DELETE structure_table.
          EXIT.
        ENDLOOP.
      ENDLOOP.
* aktualisieren von offset und position in structure_table
      len = 0.
      LOOP AT structure_table.
        structure_table-offset = len.
        structure_table-position = sy-tabix.
        IF 'CNDT' CS structure_table-inttype.
* Character-like datatypes
          x = ( structure_table-offset
                + cl_abap_char_utilities=>charsize )
                MOD cl_abap_char_utilities=>charsize.
          IF x NE 0.
            structure_table-offset = structure_table-offset
                               + cl_abap_char_utilities=>charsize - x.
          ENDIF.
        ELSE.
          CASE structure_table-datatype.
            WHEN 'INT2' OR 'PREC'.
              x = ( structure_table-offset + 2 ) MOD 2.
              IF x NE 0.
                structure_table-offset = structure_table-offset + 2 - x.
              ENDIF.
            WHEN 'INT4'.
              x = ( structure_table-offset + 4 ) MOD 4.
              IF x NE 0.
                structure_table-offset = structure_table-offset + 4 - x.
              ENDIF.
            WHEN 'FLTP'.
              x = ( structure_table-offset + 8 ) MOD 8.
              IF x NE 0.
                structure_table-offset = structure_table-offset + 8 - x.
              ENDIF.
          ENDCASE.
        ENDIF.
        MODIFY structure_table.
        len = structure_table-offset + structure_table-intlen.
      ENDLOOP.
    ENDIF.                             "hidden fields exist
  ENDIF.                               "new structure table
* Aufbau der Value_tab
  ASSIGN value_tab TO <w_value_tab_x> CASTING.
  IF x_header-bastab NE space AND x_header-texttbexst NE space
                                       "base table with text table
     AND x_header-maintview = x_header-viewname.
    CLEAR value_tab.
    IF status-mode EQ list_bild.
      LOOP AT extract.
        PERFORM build_valtab_hfields.
      ENDLOOP.
    ELSE.
      PERFORM build_valtab_hfields.
    ENDIF.
*    ENDIF.
  ELSE.
* view or base table without text table and user exits exists or hidden
* fields exist
    CLEAR value_tab.
    IF x_header-hiddenflag EQ space AND"no hidden fields
       x_header-fieldorder EQ space.   "Subviews /untersch. Feldreihenf.
      IF status-mode EQ list_bild.
        LOOP AT extract.
          MOVE <vim_xextract> TO <w_value_tab_x>(x_header-tablen).
*          MOVE extract TO value_tab(tablen).
          APPEND value_tab.
        ENDLOOP.
      ELSE.
        MOVE <vim_xextract> TO <w_value_tab_x>(x_header-tablen).
*        MOVE extract TO value_tab(tablen).
        APPEND value_tab.
      ENDIF.
    ELSE. "hidden fields exist -> move field by field
      IF status-mode EQ list_bild.
        LOOP AT extract.
          PERFORM build_valtab_hfields.
        ENDLOOP.
      ELSE.
        PERFORM build_valtab_hfields.
      ENDIF.
    ENDIF.
  ENDIF.                               "base table with text_table.
  IF x_header-frm_bf_prn NE space.     "user exit exists
* perform user exit
    PERFORM (x_header-frm_bf_prn) IN PROGRAM (sy-repid).
  ENDIF.
  CHECK NOT value_tab[] IS INITIAL.    "suppress list
************************************************************************
* Build up ALV fieldcatalogue from STRUCTURE
  REFRESH vim_alv_fcat.
  LOOP AT structure_table.
    CLEAR fcat_entry.
    PERFORM conv_dfies_fcat USING structure_table
                                  sy-tabix
                            CHANGING fcat_entry.
    APPEND fcat_entry TO vim_alv_fcat.
  ENDLOOP.
  length = structure_table-offset + structure_table-intlen.
* consider CUKY or UNIT fields.......
  DESCRIBE TABLE vim_alv_fcat LINES i.
  LOOP AT vim_alv_fcat INTO fcat_entry WHERE datatype = 'CURR'
   OR datatype = 'QUAN'.
    CASE fcat_entry-datatype.
      WHEN 'CURR'.
        READ TABLE x_namtab WITH KEY viewfield = fcat_entry-cfieldname
            TRANSPORTING NO FIELDS.
        IF sy-subrc <> 0.
* try to get global currency field
          READ TABLE x_namtab WITH KEY viewfield = fcat_entry-fieldname.
          cukytab = x_namtab-reftable.
          cukyname = x_namtab-reffield.
          CONCATENATE x_namtab-reftable '-' x_namtab-reffield
                  INTO hname.
          ASSIGN (hname) TO <cuky>.
          IF sy-subrc = 0.
* global currency key exists to be inserted in value table
            fcat_entry-currency = cukyvalue = <cuky>.
          ENDIF.
        ENDIF.
      WHEN 'QUAN'.
        READ TABLE x_namtab WITH KEY viewfield = fcat_entry-qfieldname
            TRANSPORTING NO FIELDS.
        IF sy-subrc <> 0.
* try to get global quantity field
          READ TABLE x_namtab WITH KEY viewfield = fcat_entry-fieldname.
          unittab = x_namtab-reftable.
          unitname = x_namtab-reffield.
          CONCATENATE x_namtab-reftable '-' x_namtab-reffield
                  INTO hname.
          ASSIGN (hname) TO <unit>.
          IF sy-subrc = 0.
* global unit key exists to be inserted in value table
            fcat_entry-quantity = unitvalue = <unit>.
          ENDIF.
        ENDIF.
    ENDCASE.
    MODIFY vim_alv_fcat FROM fcat_entry.
  ENDLOOP.
  REFRESH alv_value_tab.
  LOOP AT value_tab.
    APPEND <w_value_tab_x> TO alv_value_tab.
  ENDLOOP.
*  APPEND LINES OF value_tab TO alv_value_tab.
  FREE value_tab.
  IF NOT cukyname IS INITIAL.
* Append global currency to value_tab
    LOOP AT alv_value_tab ASSIGNING <value>.
      <value>+length = cukyvalue.
    ENDLOOP.
    length = length + cukylength.
  ENDIF.
  IF NOT unitname IS INITIAL.
* Append global unit to value_tab
    LOOP AT alv_value_tab ASSIGNING <value>.
      <value>+length = unitvalue.
    ENDLOOP.
  ENDIF.
  PERFORM define_alv_callbacks CHANGING vim_alv_events.
  PERFORM make_list_commentary USING unittab
                                     unitname
                                     unitvalue
                                     cukytab
                                     cukyname
                                     cukyvalue
                               CHANGING vim_list_header.
  PERFORM make_alv_layout CHANGING vim_alv_layout
                                   vim_alv_print.
  PERFORM init_alv_variant CHANGING vim_var_save
                                    vim_var_default
                                    vim_alv_variant.
  progname = sy-repid.
  PERFORM check_list_before_alv CHANGING rc.
  CHECK rc = 0.
  CALL FUNCTION 'REUSE_ALV_TABLE_CREATE'
    EXPORTING
      it_fieldcat        = vim_alv_fcat
      i_callback_program = progname
      i_formname         = alv_called_by.
  FREE alv_value_tab.
*  if sy-subrc ne 0. raise print_error. endif.
ENDFORM.                               " DRUCKEN_ZTP_ALT

*&---------------------------------------------------------------------*
*&      Form  MAKE_LIST_COMMENTARY
*&---------------------------------------------------------------------*
*       Build up list header
*----------------------------------------------------------------------*
*      <--P_LIST_COMMENTARY  text
*----------------------------------------------------------------------*
FORM make_list_commentary USING p_unittab TYPE tabname
                                p_unitname TYPE fieldname
                                p_unitvalue TYPE any
                                                "vim_unitUF296573/2000
                                p_cukytab TYPE tabname
                                p_cukyname TYPE fieldname
                                p_cukyvalue TYPE vim_cuky
                       CHANGING p_list_header TYPE slis_t_listheader.
  DATA: h_header TYPE slis_listheader,
        text(40), w_dfies TYPE dfies.

  REFRESH p_list_header.
  h_header-typ = 'H'.
  h_header-info = x_header-ddtext.
  APPEND h_header TO p_list_header.
  h_header-typ = 'S'.
  IF x_header-bastab NE space AND x_header-texttbexst NE space
   AND x_header-maintview = x_header-viewname.
    h_header-key = svim_text_p01.
  ELSE.
    h_header-key = svim_text_p02.
  ENDIF.
  h_header-info = x_header-viewname.
  APPEND h_header TO p_list_header.
  IF x_header-clidep <> space.
    h_header-key = svim_text_p03.
    h_header-info = sy-mandt.
    APPEND h_header TO p_list_header.
  ENDIF.
  IF p_unitname <> space.
    CLEAR h_header.
    h_header-typ = 'S'.
    PERFORM vim_get_reffield_alv USING p_unitname
                                       p_unittab
                                  CHANGING w_dfies.
    IF w_dfies <> space.
      IF w_dfies-scrtext_m <> space.
        h_header-key = w_dfies-scrtext_m(20).
      ELSE.
        IF w_dfies-scrtext_l <> space.
          h_header-key = w_dfies-scrtext_l(20).
        ELSE.
          IF w_dfies-scrtext_s <> space.
            h_header-key = w_dfies-scrtext_s(10).
          ELSE.
            IF w_dfies-reptext <> space.
              h_header-key = w_dfies-reptext(20).
            ELSE.
              h_header-key = w_dfies-fieldname.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
    h_header-info = p_unitvalue.
    APPEND h_header TO p_list_header.
  ENDIF.
  IF p_cukyname <> space.
    CLEAR h_header.
    h_header-typ = 'S'.
    PERFORM vim_get_reffield_alv USING p_cukyname
                                       p_cukytab
                                  CHANGING w_dfies.
    IF w_dfies <> space.
      IF w_dfies-scrtext_m <> space.
        h_header-key = w_dfies-scrtext_m(20).
      ELSE.
        IF w_dfies-scrtext_l <> space.
          h_header-key = w_dfies-scrtext_l(20).
        ELSE.
          IF w_dfies-scrtext_s <> space.
            h_header-key = w_dfies-scrtext_s(10).
          ELSE.
            IF w_dfies-reptext <> space.
              h_header-key = w_dfies-reptext(20).
            ELSE.
              h_header-key = w_dfies-fieldname.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
    h_header-info = p_cukyvalue.
    APPEND h_header TO p_list_header.
  ENDIF.
ENDFORM.                               " MAKE_LIST_COMMENTARY
*&---------------------------------------------------------------------*
*&      Form  DEFINE_ALV_CALLBACKS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_ALV_EVENTS  text
*----------------------------------------------------------------------*
FORM define_alv_callbacks CHANGING p_alv_events TYPE slis_t_event.
  DATA: h_event TYPE slis_alv_event.
  CONSTANTS: formname_top_of_list TYPE slis_formname
             VALUE 'ALV_TOP_OF_LIST',
             formname_top_of_page TYPE slis_formname
             VALUE 'ALV_TOP_OF_PAGE',
             formname_end_of_page TYPE slis_formname
             VALUE 'ALV_END_OF_PAGE',
             formname_end_of_list TYPE slis_formname
             VALUE 'ALV_END_OF_LIST'.
  REFRESH p_alv_events.
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type = 0
    IMPORTING
      et_events   = p_alv_events.
* define TOP_OF_LIST event
  READ TABLE p_alv_events WITH KEY name = slis_ev_top_of_list
                           INTO h_event.
  IF sy-subrc = 0.
    h_event-form = formname_top_of_list.
    APPEND h_event TO p_alv_events.
  ENDIF.
* define TOP_OF_PAGE event
  READ TABLE p_alv_events WITH KEY name = slis_ev_top_of_page
                           INTO h_event.
  IF sy-subrc = 0.
    h_event-form = formname_top_of_page.
    APPEND h_event TO p_alv_events.
  ENDIF.
* define END_OF_PAGE event
  READ TABLE p_alv_events WITH KEY name = slis_ev_end_of_page
                           INTO h_event.
  IF sy-subrc = 0.
    h_event-form = formname_end_of_page.
    APPEND h_event TO p_alv_events.
  ENDIF.
* define END_OF_LIST event
  READ TABLE p_alv_events WITH KEY name = slis_ev_end_of_list
                           INTO h_event.
  IF sy-subrc = 0.
    h_event-form = formname_end_of_list.
    APPEND h_event TO p_alv_events.
  ENDIF.
ENDFORM.                    "define_alv_callbacks

*&---------------------------------------------------------------------*
*&      Form  ALV_TOP_OF_LIST
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM alv_top_of_list.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = vim_list_header.

ENDFORM.                               " ALV_TOP_OF_LIST
*&---------------------------------------------------------------------*
*&      Form  ALV_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM alv_top_of_page.
  WRITE AT (sy-linsz) sy-datum RIGHT-JUSTIFIED.
ENDFORM.                               " ALV_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*&      Form  ALV_END_OF_PAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM alv_end_of_page.
  WRITE AT (sy-linsz) sy-pagno CENTERED.
ENDFORM.                               " ALV_END_OF_PAGE

*&---------------------------------------------------------------------*
*&      Form  MAKE_ALV_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_ALV_LAYOUT  text
*----------------------------------------------------------------------*
FORM make_alv_layout CHANGING p_alv_layout TYPE slis_layout_alv
                              p_alv_print  TYPE slis_print_alv.
* screen layout
  CLEAR p_alv_layout.
  p_alv_layout-colwidth_optimize = 'X'.
  p_alv_layout-f2code = '&ETA'.
  p_alv_layout-detail_popup = 'X'.
* print layout
*  p_alv_print-reserve_lines = 2.
  p_alv_print-no_print_listinfos = 'X'.
ENDFORM.                               " MAKE_ALV_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  FILL_ALV_FIELDCAT
*&---------------------------------------------------------------------*
*       Builds up ALV-fieldcatalogue from X_NAMTAB
*----------------------------------------------------------------------*
*      <--P_VIM_ALV_FCAT  ALV-fieldctalogue
*----------------------------------------------------------------------*
FORM fill_alv_fieldcat CHANGING p_vim_alv_fcat TYPE slis_t_fieldcat_alv
                                texttab_begin LIKE sy-tabix
                                p_value_length TYPE intlen
*                                p_textlen TYPE intlen
                                p_unittab TYPE tabname
                                p_unitname TYPE fieldname
                                p_unitvalue TYPE any "vim_unit
                                       "UF296573/2000
                                p_cukytab TYPE tabname
                                p_cukyname TYPE fieldname
                                p_cukyvalue TYPE vim_cuky.

  DATA: fcat_header TYPE slis_fieldcat_alv, textfld_no TYPE i,
        fcat_reffield TYPE slis_fieldcat_alv, rc LIKE sy-subrc,
        first TYPE xfeld VALUE 'X', list_width TYPE outputlen,
        i TYPE i, first_func_field TYPE i, text_outp_len TYPE outputlen,
        fldno(2) TYPE n, strln TYPE i,
        hname TYPE fnam_____4, maintview, global_unit_set,
        global_cuky_set.

  CONSTANTS: max_list_width TYPE i VALUE 250.

  FIELD-SYMBOLS: <alv_fcat> LIKE LINE OF p_vim_alv_fcat,
                 <alv_fcat2> LIKE LINE OF p_vim_alv_fcat, "UF412290/2001
                 <x_namt> LIKE LINE OF x_namtab, <cuky> TYPE vim_cuky,
                 <unit> TYPE ANY.      "vim_unit. UF296573/2000

  REFRESH p_vim_alv_fcat.
  CLEAR:  p_unitname, p_cukyname, p_unitvalue, p_cukyvalue,
          p_value_length.
  IF x_header-bastab EQ space OR x_header-texttbexst EQ space
   OR x_header-maintview NE x_header-viewname.
    maintview = 'X'.                   "It's a maintenance view!
  ENDIF.
* Build up field catalogue
  LOOP AT x_namtab ASSIGNING <x_namt> WHERE texttabfld = space
   OR keyflag = space.
    i = i + 1.
    fcat_header-col_pos = i.
    fcat_header-fieldname = <x_namt>-viewfield.
    IF maintview = space.
      fcat_header-ref_tabname = <x_namt>-bastabname.
    ELSE.
      fcat_header-ref_tabname = x_header-maintview.
    ENDIF.
    fcat_header-key = <x_namt>-keyflag.
    fcat_header-seltext_l = <x_namt>-scrtext_l.
    fcat_header-seltext_m = <x_namt>-scrtext_m.
    fcat_header-seltext_s = <x_namt>-scrtext_s.
    fcat_header-reptext_ddic = <x_namt>-reptext.
    fcat_header-datatype = <x_namt>-datatype.
    fcat_header-inttype = <x_namt>-inttype.
    fcat_header-ddic_outputlen = <x_namt>-outputlen.
    fcat_header-intlen = <x_namt>-flength.
    fcat_header-lowercase = <x_namt>-lowercase.
    CASE <x_namt>-datatype.
      WHEN 'CLNT'.
        IF x_header-clidep <> space.
          fcat_header-tech = 'X'.
        ENDIF.
      WHEN 'CURR'.
        READ TABLE x_namtab WITH KEY viewfield = <x_namt>-reffield
            TRANSPORTING NO FIELDS.
        IF sy-subrc = 0 AND <x_namt>-reftable = x_header-maintview.
          "UF163276/2001
* currency field in structure
          fcat_header-cfieldname = <x_namt>-reffield.
        ELSE.
          IF p_cukyvalue IS INITIAL.
* try to get global currency field
            p_cukytab = <x_namt>-reftable.
            p_cukyname = <x_namt>-reffield.
            CONCATENATE <x_namt>-reftable '-' <x_namt>-reffield
                    INTO hname.
            ASSIGN (hname) TO <cuky>.
            IF sy-subrc = 0.
* global currency key exists to be inserted in value table
              fcat_header-currency = p_cukyvalue = <cuky>.
            ENDIF.
          ELSE.
            fcat_header-currency = p_cukyvalue.
          ENDIF.
        ENDIF.
      WHEN 'QUAN'.
        READ TABLE x_namtab WITH KEY viewfield = <x_namt>-reffield
            TRANSPORTING NO FIELDS.
        IF sy-subrc = 0 AND <x_namt>-reftable = x_header-maintview.
          "UF163276/2001.
* quantity field in structure
          fcat_header-qfieldname = <x_namt>-reffield.
        ELSE.
* try to get global quantity field
          IF p_unitvalue IS INITIAL.
            p_unittab = <x_namt>-reftable.
            p_unitname = <x_namt>-reffield.
            CONCATENATE <x_namt>-reftable '-' <x_namt>-reffield
                    INTO hname.
            ASSIGN (hname) TO <unit>.
            IF sy-subrc = 0.
* global unit key exists to be inserted in value table
              fcat_header-quantity = p_unitvalue = <unit>.
            ENDIF.
          ELSE.
            fcat_header-quantity = p_unitvalue.
          ENDIF.
        ENDIF.
    ENDCASE.
    IF <x_namt>-readonly = vim_hidden
* hide hidden fields
     OR <x_namt>-domname IN vim_guid_domain.
* no GUID-values
      fcat_header-tech = 'X'.
    ELSE.
      list_width = list_width + <x_namt>-outputlen + 1.
    ENDIF.
    p_value_length = p_value_length + fcat_header-intlen.
    APPEND fcat_header TO p_vim_alv_fcat.
    CLEAR fcat_header.
    CHECK <x_namt>-texttabfld <> space.
    textfld_no = textfld_no + 1.       "get no. of text fields
*    p_textlen = p_textlen + <x_namt>-flength. "int. length of text flds
    CHECK <x_namt>-readonly <> vim_hidden.
    IF first <> space.
      texttab_begin = i.               "position of 1st text fld
      CLEAR first.
    ENDIF.
    text_outp_len = text_outp_len + <x_namt>-outputlen.
  ENDLOOP.
  first = 'X'.
  CLEAR i.
  IF x_header-bastab NE space AND x_header-texttbexst NE space
   AND x_header-maintview = x_header-viewname.
* Place text fields behind key fields.
    LOOP AT p_vim_alv_fcat ASSIGNING <alv_fcat> WHERE key = space.
      IF first <> space.
        first_func_field = <alv_fcat>-col_pos.
        CLEAR first.
      ENDIF.
      IF sy-tabix < texttab_begin.
        <alv_fcat>-col_pos = <alv_fcat>-col_pos + textfld_no.
      ELSE.
        i = i + 1.
        <alv_fcat>-col_pos = first_func_field + i - 1.
      ENDIF.
    ENDLOOP.
    first = 'X'.
    SORT p_vim_alv_fcat BY col_pos.
  ENDIF.
  IF list_width > max_list_width.
* line size to large for one line
    list_width = i = 1.
    LOOP AT p_vim_alv_fcat ASSIGNING <alv_fcat>.
      list_width = list_width + <alv_fcat>-ddic_outputlen + 1.
      IF list_width > max_list_width.
        i = i + 1.
        list_width = <alv_fcat>-ddic_outputlen + 1.
      ENDIF.
      <alv_fcat>-row_pos = i.
    ENDLOOP.
  ENDIF.
  IF maintview = space.                  "UF412290/2001b
*check field catalogue for doublettes and change their fieldname
    LOOP AT p_vim_alv_fcat ASSIGNING <alv_fcat>.
      i = sy-tabix.
      CLEAR fldno.
      LOOP AT p_vim_alv_fcat ASSIGNING <alv_fcat2>
       WHERE fieldname = <alv_fcat>-fieldname.
        CHECK sy-tabix <> i.
        <alv_fcat2>-ref_fieldname = <alv_fcat2>-fieldname.
        ADD 1 TO fldno.
        CONCATENATE <alv_fcat2>-fieldname fldno
         INTO <alv_fcat2>-fieldname.
        IF sy-subrc <> 0.
          strln = strlen( <alv_fcat2>-fieldname ) - 2.
          CONCATENATE <alv_fcat2>-fieldname(strln) fldno
          INTO <alv_fcat2>-fieldname.
        ENDIF.
      ENDLOOP.
    ENDLOOP.
  ENDIF.                                 "UF412290/2001e
ENDFORM.                               " FILL_ALV_FIELDCAT

*&---------------------------------------------------------------------*
*&      Form  VIM_CALL_ALV
*&---------------------------------------------------------------------*
*       Calls ABAP List Viewer. Has to be called from Function Module
*       REUSE_ALV_TABLE_CREATE.
*----------------------------------------------------------------------*
*      -->VALUE_TAB
*----------------------------------------------------------------------*
FORM vim_call_alv TABLES value_tab.

  DATA: progname LIKE sy-repid.
  FIELD-SYMBOLS: <alv_value_tab_x> TYPE tabl8000,
                 <value_tab_x> TYPE x.

  REFRESH value_tab.
  ASSIGN value_tab TO <value_tab_x> CASTING.
  LOOP AT alv_value_tab ASSIGNING <alv_value_tab_x>.
    <value_tab_x> = <alv_value_tab_x>.
    APPEND value_tab.
  ENDLOOP.
*  APPEND LINES OF alv_value_tab TO value_tab.
  progname = sy-repid.
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
      EXPORTING
           i_callback_program       = progname
           is_layout                = vim_alv_layout
           it_fieldcat              = vim_alv_fcat
*           it_excluding             = vim_alv_excluding
*           it_special_groups        = vim_alv_special_groups
*           it_sort                  = vim_alv_sort
*            IT_FILTER                =
*           is_sel_hide              = vim_alv_sel_hide
           i_default                = vim_var_default
           i_save                   = vim_var_save
           is_variant               = vim_alv_variant
           it_events                = vim_alv_events
*           it_event_exit            = vim_alv_event_exit
           is_print                 = vim_alv_print
*            IS_REPREP_ID             =
*            I_SCREEN_START_COLUMN    = 0
*            I_SCREEN_START_LINE      = 0
*            I_SCREEN_END_COLUMN      = 0
*            I_SCREEN_END_LINE        = 0
*       IMPORTING
*            E_EXIT_CAUSED_BY_CALLER  =
*            ES_EXIT_CAUSED_BY_USER   =
       TABLES
            t_outtab                 = value_tab[]
       EXCEPTIONS
            program_error            = 1
            OTHERS                   = 2.
  IF sy-subrc NE 0. RAISE print_error. ENDIF.
ENDFORM.                               "vim_call_alv
*&---------------------------------------------------------------------*
*&      Form  MAINTAIN_ALV_VALUE_TAB_TEXT
*&---------------------------------------------------------------------*
*       shift textfield directly behind key
*----------------------------------------------------------------------*
*      -->P_TEXTLEN  text
*----------------------------------------------------------------------*
FORM maintain_alv_value_tab_text USING    p_textlen TYPE intlen.

  DATA: x TYPE i, record TYPE tabl8000, textoffset TYPE intlen,
        BEGIN OF new_offs,
          ref_tabname TYPE tabname,
          fieldname TYPE viewfield,
          ref_fieldname TYPE fieldname,
          offset TYPE tabfdpos,
        END OF new_offs.

  STATICS: t_fld_offs LIKE SORTED TABLE OF new_offs WITH UNIQUE KEY
                           ref_tabname fieldname ref_fieldname
                           INITIAL SIZE 1,
           viewname TYPE viewname.
  FIELD-SYMBOLS: <x_namt> LIKE LINE OF x_namtab,
                 <alv_fcat> TYPE slis_fieldcat_alv,
                 <alv_val>.

  IF viewname <> x_header-viewname.
    viewname = x_header-viewname.
    REFRESH t_fld_offs.
    new_offs-offset = x_header-after_keyc.
*    new_offs-offset = x_header-keylen.
* Offset aktualisieren
    LOOP AT vim_alv_fcat ASSIGNING <alv_fcat> WHERE key = space.
      new_offs-ref_tabname = <alv_fcat>-ref_tabname.
      new_offs-fieldname = <alv_fcat>-fieldname.
      new_offs-ref_fieldname = <alv_fcat>-ref_fieldname. "UF412290/2001
* Alignment
      IF 'CNDT' CS <alv_fcat>-inttype.
* Character-like datatypes
        x = ( new_offs-offset + cl_abap_char_utilities=>charsize )
              MOD cl_abap_char_utilities=>charsize.
        IF x NE 0.
          new_offs-offset = new_offs-offset
                             + cl_abap_char_utilities=>charsize - x.
        ENDIF.
      ELSE.
        CASE <alv_fcat>-datatype.
          WHEN 'INT2' OR 'PREC'.
            x = ( new_offs-offset + 2 ) MOD 2.
            IF x NE 0.
              new_offs-offset = new_offs-offset + 2 - x.
            ENDIF.
          WHEN 'INT4'.
            x = ( new_offs-offset + 4 ) MOD 4.
            IF x NE 0.
              new_offs-offset = new_offs-offset + 4 - x.
            ENDIF.
          WHEN 'FLTP'.
            x = ( new_offs-offset + 8 ) MOD 8.
            IF x NE 0.
              new_offs-offset = new_offs-offset + 8 - x.
            ENDIF.
        ENDCASE.
      ENDIF.
      INSERT new_offs INTO TABLE t_fld_offs.
      new_offs-offset = new_offs-offset + <alv_fcat>-intlen.
    ENDLOOP.
  ENDIF.
  textoffset = x_header-after_tabc + x_header-aft_txtkc.
*  textoffset = x_header-tablen + x_header-textkeylen.
  LOOP AT alv_value_tab ASSIGNING <alv_val>.
    record(x_header-after_keyc) = <alv_val>(x_header-after_keyc).
*    record = <alv_val>(x_header-keylen).
    IF p_textlen > 0.
      record+x_header-after_keyc(p_textlen) =
       <alv_val>+textoffset(p_textlen).
*      record+x_header-keylen(p_textlen) =
*       <alv_val>+textoffset(p_textlen).
    ENDIF.
    LOOP AT x_namtab ASSIGNING <x_namt> WHERE keyflag = space AND
                                              texttabfld = space.
      READ TABLE t_fld_offs INTO new_offs WITH TABLE KEY
                                    ref_tabname = <x_namt>-bastabname
                                    fieldname = <x_namt>-viewfield
                                    ref_fieldname = space.
      IF sy-subrc = 0.
        record+new_offs-offset(<x_namt>-flength) =
         <alv_val>+<x_namt>-position(<x_namt>-flength).
      ELSE.                                "UF412290/2001b
* field had to be renamed because of doublettes
        READ TABLE t_fld_offs INTO new_offs WITH KEY
                                    ref_tabname = <x_namt>-bastabname
                                    ref_fieldname = <x_namt>-viewfield.
        IF sy-subrc = 0.
          record+new_offs-offset(<x_namt>-flength) =
           <alv_val>+<x_namt>-position(<x_namt>-flength).
        ENDIF.                             "UF412290/2001e
      ENDIF.
    ENDLOOP.
    CLEAR <alv_val>.
    <alv_val> = record.
  ENDLOOP.
ENDFORM.                               " MAINTAIN_ALV_VALUE_TAB_TEXT
*&---------------------------------------------------------------------*
*&      Form  VIM_GET_REFFIELD_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_REFFIELD  text
*      -->P_REFTABLE  text
*      <--P_DFIES Entry for ALV-Fieldcatalogue
*----------------------------------------------------------------------*
FORM vim_get_reffield_alv USING value(p_reffield) TYPE fieldname
                                value(p_reftable) TYPE tabname
                      CHANGING p_dfies TYPE dfies.

  DATA: dfies_tab TYPE TABLE OF dfies.

  CALL FUNCTION 'DDIF_FIELDINFO_GET'
    EXPORTING
      tabname        = p_reftable
      fieldname      = p_reffield
      langu          = sy-langu
    TABLES
      dfies_tab      = dfies_tab
    EXCEPTIONS
      not_found      = 1
      internal_error = 2
      OTHERS         = 3.
  IF sy-subrc <> 0.
    EXIT.
  ELSE.
    READ TABLE dfies_tab INTO p_dfies INDEX 1.
  ENDIF.
ENDFORM.                               " VIM_GET_REFFIELD_ALV

*&---------------------------------------------------------------------*
*&      Form  CONV_DFIES_FCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_P_DFIES  text
*      <--P_P_FCAT_REFFIELD  text
*----------------------------------------------------------------------*
FORM conv_dfies_fcat USING    p_dfies LIKE dfies
                              i TYPE i
                    CHANGING p_fcat_reffield TYPE slis_fieldcat_alv.

  p_fcat_reffield-col_pos = i.
  p_fcat_reffield-fieldname = p_dfies-fieldname.
  p_fcat_reffield-ref_tabname = p_dfies-tabname.
  p_fcat_reffield-key = p_dfies-keyflag.
  p_fcat_reffield-seltext_l = p_dfies-scrtext_l.
  p_fcat_reffield-seltext_m = p_dfies-scrtext_m.
  p_fcat_reffield-seltext_s = p_dfies-scrtext_s.
  p_fcat_reffield-reptext_ddic = p_dfies-reptext.
  p_fcat_reffield-datatype = p_dfies-datatype.
  p_fcat_reffield-inttype = p_dfies-inttype.
  p_fcat_reffield-ddic_outputlen = p_dfies-outputlen.
  p_fcat_reffield-intlen = p_dfies-intlen.
  p_fcat_reffield-lowercase = p_dfies-lowercase.
  CASE p_dfies-datatype.
    WHEN 'CLNT'.
      CHECK x_header-clidep <> space AND p_fcat_reffield-key <> space.
      p_fcat_reffield-tech = 'X'.
    WHEN 'CURR'.
* currency field in structure
      p_fcat_reffield-cfieldname = p_dfies-reffield.
    WHEN 'QUAN'.
* currency field in structure
      p_fcat_reffield-qfieldname = p_dfies-reffield.
  ENDCASE.
ENDFORM.                               " CONV_DFIES_FCAT
*&---------------------------------------------------------------------*
*&      Form  INIT_ALV_VARIANT
*&---------------------------------------------------------------------*
*       define path for list variant names
*----------------------------------------------------------------------*
*      <--P_VARIANT  text
*      <--P_SAVE     text
*----------------------------------------------------------------------*
FORM init_alv_variant CHANGING p_save
                               p_default
                               p_variant STRUCTURE disvariant.

  CONCATENATE x_header-viewname sy-repid INTO p_variant-report.
  p_save = 'A'.
  p_default = 'X'.
ENDFORM.                               " INIT_ALV_VARIANT
*&---------------------------------------------------------------------*
*&      Form  ALV_END_OF_LIST
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM alv_end_of_list.
  WRITE AT /(sy-linsz) sy-pagno CENTERED.
ENDFORM.                               " ALV_END_OF_LIST

*---------------------------------------------------------------------*
*       FORM INITIALISIEREN                                           *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM initialisieren.
  LOCAL: counter.
  TYPES: BEGIN OF i_fnamecnt,
           name LIKE vimsellist-viewfield,
           cnt TYPE i,
         END OF i_fnamecnt.
  DATA: keydate_alr_assigned(1) TYPE c,
        program LIKE d020s-prog,
        namlen TYPE i,
        length TYPE i,
        name(25) TYPE c,
        fname(50) TYPE c,
        dynnr LIKE liste,
        i_fnametb TYPE SORTED TABLE OF i_fnamecnt WITH UNIQUE KEY name,
        i_fnameln TYPE i_fnamecnt, initexclfldtabs(1) TYPE c,
        i_objtype LIKE objh-objecttype,
        f_fieldname(50) type c.
  DATA: h_f1(70) TYPE c, h_f2(8)  TYPE c, h_f3(20) TYPE c.
  FIELD-SYMBOLS: <m1>, <mili> TYPE ANY, <x_namtab> TYPE vimnamtab,
                 <f_fld_value> TYPE any.

  IF nbrd_texts_alr_read EQ space.
    CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'transport/systemtype'
                       ID 'VALUE' FIELD vim_system_type.
    PERFORM set_numbered_texts.
    length = vim_position_info_lg1 + 2 + vim_position_info_lg3.
* XB 585898B - remove the unused characters ';;'.
    IF sy-langu = 'J'.
      REPLACE ';;' IN svim_text_027 WITH '  '.
    ENDIF.
* XB 585898E
    WRITE: svim_text_027 TO
             vim_position_info_mask(vim_position_info_lg1),
           svim_text_028 TO
             vim_position_info_mask+length(vim_position_info_lg2).
    vim_posi_push = '@3Y@'. vim_posi_push+4 = svim_text_029.
    MOVE: 'I'   TO mark_functions-sign,
          'I'   TO adrnbr_domain-sign,
          'I'   TO exted_functions-sign,
          'EQ'  TO mark_functions-option,
          'EQ'  TO adrnbr_domain-option,
          'EQ'  TO exted_functions-option,
          space TO mark_functions-high,
          space TO adrnbr_domain-high,
          space TO exted_functions-high.
    MOVE 'ADDR' TO mark_functions-low. APPEND mark_functions.
    MOVE 'ALMK' TO mark_functions-low. APPEND mark_functions.
    MOVE 'DELE' TO mark_functions-low. APPEND mark_functions.
    MOVE 'DELM' TO mark_functions-low. APPEND mark_functions.
    MOVE 'EXPA' TO mark_functions-low. APPEND mark_functions.
    MOVE 'KOPE' TO mark_functions-low. APPEND mark_functions.
    MOVE 'MKLO' TO mark_functions-low. APPEND mark_functions.
    MOVE 'ORGI' TO mark_functions-low. APPEND mark_functions.
    MOVE 'REPL' TO mark_functions-low. APPEND mark_functions.
    MOVE 'TEXT' TO mark_functions-low. APPEND mark_functions.
    MOVE 'TREX' TO mark_functions-low. APPEND mark_functions.
    MOVE 'TRIN' TO mark_functions-low. APPEND mark_functions.
    MOVE 'UNDO' TO mark_functions-low. APPEND mark_functions.
    MOVE 'BCSH' TO mark_functions-low. APPEND mark_functions.
    MOVE 'UNDO' TO exted_functions-low. APPEND exted_functions.
    MOVE 'DELE' TO exted_functions-low. APPEND exted_functions.
    MOVE 'TRIN' TO exted_functions-low. APPEND exted_functions.
    MOVE 'TREX' TO exted_functions-low. APPEND exted_functions.
    PERFORM vim_fill_vim_guid_domain.
    PERFORM vim_fill_date_type.
    DO.
      ASSIGN COMPONENT sy-index OF STRUCTURE vim_adrnbr_domains TO <m1>.
      IF sy-subrc NE 0. EXIT. ENDIF.
      MOVE <m1> TO adrnbr_domain-low. APPEND adrnbr_domain.
    ENDDO.
    PERFORM vim_initialize_d0100.      " SW Texttransl
    MOVE 'X' TO nbrd_texts_alr_read.
  ENDIF.
  READ TABLE x_header INDEX 1.
  IF x_header-existency NE 'R'.
* SOBJ-Eintrag da?
    IF x_header-bastab EQ space OR
     ( x_header-maintview NE x_header-viewname AND          "UF160998
       x_header-bastab NE space ).
      i_objtype = 'V'.
    ELSE.
      i_objtype = 'S'.
    ENDIF.
    SELECT SINGLE * FROM objh WHERE objectname EQ x_header-viewname
                                AND objecttype EQ i_objtype.
    IF sy-subrc NE 0.                  "no obj.descr. -> run RSVIM30A
      MESSAGE a138(sv) WITH x_header-viewname x_header-area.
    ENDIF.
  ENDIF.
  CLEAR: vim_nbr_of_scrfrm_pointers.
  vim_view_name = vim_addresses_to_save-viewname = x_header-viewname.
  MOVE: x_header-liste TO liste,
        x_header-detail TO detail.
  CASE x_header-type.
    WHEN '1'. MOVE einstufig TO status-type.
    WHEN '2'. MOVE zweistufig TO status-type.
  ENDCASE.
  counter = strlen( x_header-ddtext ).
  IF counter EQ 0. counter = 1. x_header-ddtext(1) = '?'. ENDIF.
  vim_title_name = x_header-ddtext.
  ASSIGN: vim_title_name(counter) TO <name>.
  MOVE <name> TO vim_frame_field.
* set up status vector
  IF x_header-bastab NE space.
    MOVE: 'STATUS_' TO name,
          x_header-maintview TO name+7.                     "Subviews
    ASSIGN (name) TO <status>.
    MOVE: '*' TO name,
          x_header-maintview TO name+1.
    ASSIGN (x_header-maintview) TO <table1>.
    IF sy-subrc = 4.
      MESSAGE a173(sv) WITH x_header-maintview x_header-area.
    ENDIF.
    ASSIGN (name) TO <initial> CASTING TYPE (x_header-maintview).
* XB H606530B
* check if the time-field exists: Yes, then reset initial value.
    loop at x_namtab where datatype = 'TIMS'.
      CONCATENATE '<initial>' x_namtab-viewfield into f_fieldname
              SEPARATED BY '-'.
      assign (f_fieldname) to <f_fld_value>.
      clear <f_fld_value> with space.
    endloop.
* XB H606530E
    IF x_header-texttbexst NE space.
      MOVE x_header-texttab TO name+1.
      ASSIGN: (x_header-texttab)  TO <table1_text>,
              (name)              TO <text_initial>,
              <table1_text>       TO <table1_xtext> CASTING,
              <table1_xtext>(x_header-textkeylen)  TO <textkey_x>,
              <text_initial>      TO <text_initial_x> CASTING,
              <text_initial_x>(x_header-textkeylen)
               TO <initial_textkey_x>.
      IF x_header-generictrp <> 'X'
       AND cl_abap_char_utilities=>charsize = 1.
* charlike key and non-unicode-system (FS only assigned for
* downward compatibility).
        ASSIGN: <table1_text>(x_header-textkeylen) TO <textkey>,
           <text_initial>(x_header-textkeylen) TO <initial_textkey>.
      ELSE.
        ASSIGN: <table1_xtext> TO <textkey>,
               <initial_textkey_x> TO <initial_textkey>.
      ENDIF.
    ENDIF.
    IF x_header-viewname = x_header-maintview.              "Subviews
      CLEAR e071k-viewname.
      master_type = transp_object.
    ELSE.      "View auf Tab.                              "Subviews ..
      e071k-viewname = view_name.
      master_type = vim_view_type.
    ENDIF.                             ".. Subviews
  ELSE.                                                     "view
* XB H606530B
* check if the time-field exists: Yes, then reset initial value.
    loop at x_namtab where datatype = 'TIMS'.
      CONCATENATE '<initial>' x_namtab-viewfield into f_fieldname
              SEPARATED BY '-'.
      assign (f_fieldname) to <f_fld_value>.
      clear <f_fld_value> with space.
    endloop.
* XB H606530B
    WRITE: x_header-maintview TO compl_formname+compl_form_offs,
           x_header-maintview TO corr_formname+corr_form_offs.
    MOVE: view_name     TO e071k-viewname,
          vim_view_type TO master_type.
  ENDIF.
* set up screens
  MOVE: 'TCTRL_' TO name,
        x_header-maintview TO name+6.
* Übergangslösung Tablecontrol Anfang
  DATA: h LIKE d020s, f LIKE d021s OCCURS 10, e LIKE d022s OCCURS 10,
        m LIKE d023s OCCURS 10, e_h LIKE d022s,
        i_dynid(44) TYPE c.            "VALUE 'SAPL'.
  i_dynid  = x_header-fpoolname.                            "4.0B
  i_dynid+40(4) = x_header-liste.
  IMPORT DYNPRO h f e m ID i_dynid.
  IF sy-subrc EQ 0.
    LOOP AT e INTO e_h WHERE line CS name.
      EXIT.
    ENDLOOP.
    IF sy-subrc EQ 0.
      vim_tabctrl_active = 'X'.
    ELSE.
      CLEAR vim_tabctrl_active.
    ENDIF.
    ASSIGN h-mili TO <mili> CASTING TYPE x.
    IF <mili> O vim_template_dynpro.   "SW: gen. Dynpros sind evtl.
      h-mili = h-mili - vim_template_dynpro.   "fälschlicherweise als
      EXPORT DYNPRO h f e m ID i_dynid."Vorlagedynpros gekennzeichnet
      GENERATE DYNPRO h f e m ID i_dynid
                              MESSAGE h_f1 LINE h_f2 WORD h_f3.
    ENDIF.
  ELSE.
    CLEAR vim_tabctrl_active.
  ENDIF.
  IF x_header-type = '2'.
    i_dynid+40(4) = x_header-detail.
    IMPORT DYNPRO h f e m ID i_dynid.
    ASSIGN h-mili TO <mili> CASTING TYPE x.
    IF sy-subrc = 0
     AND <mili> O vim_template_dynpro. "UF: Auch Einzelbilder sind
      h-mili = h-mili - vim_template_dynpro.   "evtl. fälschlicherweise
      EXPORT DYNPRO h f e m ID i_dynid."als Vorlagedynpros
      GENERATE DYNPRO h f e m ID i_dynid       "gekennzeichnet
       MESSAGE h_f1 LINE h_f2 WORD h_f3.
    ENDIF.
  ENDIF.
  IF vim_tabctrl_active NE space.
* Übergangslösung Tablecontrol Ende
    ASSIGN (name) TO <vim_tctrl>.
    IF sy-subrc EQ 0.
      vim_tabctrl_active = 'X'.
      IF last_view_info <> space.      "Subviews ..
        REFRESH CONTROL name FROM SCREEN x_header-liste.
      ENDIF.                           ".. Subviews
      IF vim_restore_mode EQ space.
        <status>-l_sel_mode = <vim_tctrl>-line_sel_mode.
      ENDIF.
      IF x_header-maintview <> x_header-viewname.           "Subviews ..
        LOOP AT x_namtab WHERE readonly = vim_hidden.
          CONCATENATE x_header-maintview '-' x_namtab-viewfield
                                                             INTO fname.
          LOOP AT <vim_tctrl>-cols INTO vim_tc_cols
                                   WHERE screen-name = fname.
            vim_tc_cols-vislength = 0.
            vim_tc_cols-invisible = '1'.
            MODIFY <vim_tctrl>-cols FROM vim_tc_cols.
            EXIT.
          ENDLOOP.
        ENDLOOP.
      ENDIF.                           ".. Subviews
    ELSE.
      CLEAR vim_tabctrl_active.
    ENDIF.
  ENDIF.
* process assigns to structure
  vim_ctabkeylen =
   x_header-after_keyc / cl_abap_char_utilities=>charsize.
  IF x_header-clidep NE space.
    READ TABLE x_namtab ASSIGNING <x_namtab>
     WITH KEY datatype = 'CLNT'.
    ASSIGN COMPONENT <x_namtab>-viewfield OF STRUCTURE <table1>
     TO <client>.
    ASSIGN COMPONENT <x_namtab>-viewfield OF STRUCTURE <initial>
     TO <vim_client_initial>.
    <vim_client_initial> = sy-mandt.
  ELSE.
    ASSIGN mandant TO <vim_client_initial>.
  ENDIF.
  master_name = view_name.
  ASSIGN: (x_header-maintview) TO <table1_x> CASTING,
          <table1_x>(x_header-keylen) TO <f1_x>,
          vim_view_wax TO <table1_wa>
           CASTING TYPE (x_header-maintview),
          vim_view_wax TO <table1_wax> CASTING,
          <table1_wax>(x_header-keylen) TO <f1_wax> CASTING.
  IF x_header-generictrp <> 'X'
   AND cl_abap_char_utilities=>charsize = 1.
* charlike key or non-unicode-system (<f1> is only assigned for
* downward compatibility).
    ASSIGN <table1>(vim_ctabkeylen) TO <f1>.
  ELSE.
    ASSIGN <f1_x> TO <f1>.
  ENDIF.
  PERFORM vim_set_init_from_sellist USING x_header-maintview
                                          x_namtab[]
                                          dba_sellist[]
                                          vim_hidden
                                    CHANGING <initial>.
  IF last_view_info NE space.          "store old exclfldtabs
    MOVE: last_view_info TO vim_excl_xxx_tab_safe-viewname,
          excl_pos_tab[] TO vim_excl_xxx_tab_safe-excl_pos_tab,
          excl_rpl_tab[] TO vim_excl_xxx_tab_safe-excl_rpl_tab,
          excl_que_tab[] TO vim_excl_xxx_tab_safe-excl_que_tab.
    MODIFY TABLE vim_excl_xxx_tab_safe.
    IF sy-subrc NE 0.
      INSERT TABLE vim_excl_xxx_tab_safe.
    ENDIF.
  ENDIF.
  READ TABLE vim_excl_xxx_tab_safe WITH TABLE KEY
                                   viewname = x_header-viewname.
  IF sy-subrc EQ 0.
    excl_pos_tab[] = vim_excl_xxx_tab_safe-excl_pos_tab.
    excl_rpl_tab[] = vim_excl_xxx_tab_safe-excl_rpl_tab.
    excl_que_tab[] = vim_excl_xxx_tab_safe-excl_que_tab.
  ELSE.
    REFRESH: excl_rpl_tab, excl_que_tab, excl_pos_tab, exclude_tab.
    CLEAR: excl_rpl_tab, excl_que_tab, excl_pos_tab, exclude_tab.
    initexclfldtabs = 'X'.
  ENDIF.
  IF x_header-subsetflag NE space OR x_header-adrnbrflag NE space OR
     x_header-rdonlyflag NE space OR x_header-usrexiflag NE space OR
     x_header-hiddenflag NE space OR x_header-scrfrmflag NE space OR
     x_header-guidflag NE space.
* no positioning or replacing for certain kinds of fields
    LOOP AT x_namtab WHERE readonly NE space
                        OR domname IN adrnbr_domain
                        OR domname EQ vim_scrform_domain
                        OR domname IN vim_guid_domain.
      IF x_namtab-domname IN adrnbr_domain.
*        ASSIGN <table1>+x_namtab-position(x_namtab-flength)
*                    TO <address_number>.
        ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE <table1>
         TO <address_number>.
        MOVE x_namtab-readonly TO adrnbr_roflag.
        vim_addr_basetable = x_namtab-bastabname.
        vim_addr_bastab_field = x_namtab-bastabfld.
        CHECK initexclfldtabs NE space.
        MOVE x_namtab-viewfield TO excl_rpl_tab-fieldname.
        MOVE x_namtab-viewfield TO excl_que_tab-fieldname.
        MOVE x_namtab-viewfield TO excl_pos_tab-fieldname.
        COLLECT excl_rpl_tab.
        COLLECT excl_que_tab.
        COLLECT excl_pos_tab.
        CONTINUE.
      ELSEIF x_namtab-domname EQ vim_scrform_domain.
*        ASSIGN <table1>+x_namtab-position(x_namtab-flength)
*                    TO <vim_scrform_name>.
        ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE <table1>
         TO <vim_scrform_name>.
        ADD 1 TO vim_nbr_of_scrfrm_pointers.
      ELSEIF x_namtab-domname IN vim_guid_domain.
        MOVE x_namtab-viewfield TO excl_rpl_tab-fieldname.
        MOVE x_namtab-viewfield TO excl_que_tab-fieldname.
        MOVE x_namtab-viewfield TO excl_pos_tab-fieldname.
        COLLECT excl_rpl_tab.
        COLLECT excl_que_tab.
        COLLECT excl_pos_tab.
        CONTINUE.
      ENDIF.
      CHECK initexclfldtabs NE space.
      CASE x_namtab-readonly.
        WHEN subset.
          MOVE x_namtab-viewfield TO excl_rpl_tab-fieldname.
          MOVE x_namtab-viewfield TO excl_que_tab-fieldname.
          APPEND excl_rpl_tab.
          APPEND excl_que_tab.
        WHEN usrexi.
*         check initexclfldtabs ne space.
          MOVE x_namtab-viewfield TO excl_rpl_tab-fieldname.
          MOVE x_namtab-viewfield TO excl_que_tab-fieldname.
          MOVE x_namtab-viewfield TO excl_pos_tab-fieldname.
          APPEND excl_rpl_tab.
          APPEND excl_que_tab.
          APPEND excl_pos_tab.
        WHEN vim_hidden.
          MOVE x_namtab-viewfield TO excl_rpl_tab-fieldname.
          MOVE x_namtab-viewfield TO excl_que_tab-fieldname.
          MOVE x_namtab-viewfield TO excl_pos_tab-fieldname.
          APPEND excl_rpl_tab.
          APPEND excl_que_tab.
          APPEND excl_pos_tab.
        WHEN rdonly.
          MOVE x_namtab-viewfield TO excl_rpl_tab-fieldname.
          APPEND excl_rpl_tab.
      ENDCASE.
    ENDLOOP.
  ENDIF.
  IF x_header-scrfrmflag NE space AND vim_nbr_of_scrfrm_pointers EQ 1.
    mark_functions-low = 'SCRF'. APPEND mark_functions.
  ELSE.
    DELETE mark_functions WHERE low EQ 'SCRF'.
  ENDIF.
  IF x_header-selection NE space AND initexclfldtabs NE space.
    i_fnameln-cnt = 1.
    LOOP AT dba_sellist WHERE ddic CO ddic_marks
                        AND ( negation EQ space AND operator EQ 'EQ' OR
                              negation EQ 'NOT' AND operator EQ 'NE' ).
      i_fnameln-name = dba_sellist-viewfield.
      COLLECT i_fnameln INTO i_fnametb.
    ENDLOOP.
    LOOP AT i_fnametb INTO i_fnameln WHERE cnt EQ 1.
      excl_rpl_tab-fieldname = i_fnameln-name.
      COLLECT excl_rpl_tab.
      excl_que_tab-fieldname = i_fnameln-name.
      COLLECT excl_que_tab.
    ENDLOOP.
  ENDIF.
  IF x_header-delmdtflag NE space.
    VIM_TDEP_TITLE = svim_text_104.
    CLEAR: vim_old_viewkey, vim_old_st_selected.          "SW wegen Vcl
    REFRESH vim_sval_tab. CLEAR vim_sval_tab.
    MOVE: x_header-viewname TO vim_sval_tab-tabname,
          x_header-maintview TO vim_begdate_name-tabname,
          x_header-maintview TO vim_enddate_name-tabname,
          'X' TO vim_sval_tab-field_obl,
          sy-datum TO vim_sval_tab-value.
    vim_begdate_name-dash = vim_enddate_name-dash = '-'.
    IF x_header-delmdtflag EQ 'E'.
      ASSIGN d0001_field_tab-end TO <key_date>.
    ELSE.
      ASSIGN d0001_field_tab-begin TO <key_date>.
    ENDIF.
    ASSIGN: vim_mainkey TO <vim_h_mkey> CASTING,
            vim_old_viewkey TO <vim_h_old_mkey> CASTING,
            vim_collapsed_mainkeys-mainkey TO <vim_h_coll_mkey> CASTING,
            vim_collapsed_mainkeys-log_key TO <vim_h_coll_logkey>
             CASTING,
            vim_collapsed_mainkeys-mkey_bf TO <vim_h_coll_bfkey>
             CASTING,
            vim_merged_entries-merged_key TO <vim_h_merged_key> CASTING.
    LOOP AT x_namtab WHERE domname EQ vim_delim_date_domain
                       AND ( rollname IN vim_begda_types OR
                             rollname IN vim_endda_types ).
      IF x_namtab-rollname IN vim_begda_types.
* begin date
        IF x_header-delmdtflag EQ 'E'.
* end date is key field
          IF x_namtab-texttabfld EQ space.
*            ASSIGN: <table1>+x_namtab-position(x_namtab-flength)
*                                   TO <vim_new_begdate> TYPE 'D',
*                    <table1>+x_namtab-position(x_namtab-flength)
*                                   TO <vim_begdate_mask> TYPE 'C'.
            ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE <table1>
             TO <vim_new_begdate>.
            ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE <table1>
             TO <vim_begdate_mask> CASTING TYPE c.
            MOVE: x_namtab-viewfield TO vim_sval_tab-fieldname,
                  x_namtab-viewfield TO vim_begdate_name-fieldname.
            vim_begdate_is_ro = x_namtab-readonly.
          ENDIF.
        ELSE.
* begin date is key field
          CHECK keydate_alr_assigned EQ space.
          keydate_alr_assigned = 'X'.
          IF x_namtab-texttabfld EQ space.
*            ASSIGN: <table1>+x_namtab-position(x_namtab-flength)
*                                   TO <vim_enddate_mask> TYPE 'C'.
            ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE <table1>
             TO <vim_enddate_mask> CASTING TYPE c.
            IF x_namtab-position GT 0.
              IF x_header-generictrp <> 'X'.
** charlike key or non-unicode-system (FS is only assigned for
** downward compatibility).
                length = x_namtab-position
                          DIV cl_abap_char_utilities=>charsize.
                ASSIGN: <table1>(length)
                         TO <vim_f1_before> CASTING TYPE c,
                        vim_mainkey(length)
                          TO <vim_mkey_before> CASTING TYPE c,
                        vim_old_viewkey(length)
                          TO <vim_old_mkey_before> CASTING TYPE c.
              ENDIF.
              IF NOT ( <vim_f1_before> IS ASSIGNED
                       OR <vim_mkey_before> IS ASSIGNED
                       OR <vim_old_mkey_before> IS ASSIGNED ).
** could not be assigned because unicode flag is set in function
** group and key is non charlike
                ASSIGN: <table1_x>(x_namtab-position)
                         TO <vim_f1_before> CASTING TYPE x,
                        <vim_h_mkey>(x_namtab-position)
                          TO <vim_mkey_before> CASTING TYPE x,
                        <vim_h_old_mkey>(x_namtab-position)
                          TO <vim_old_mkey_before> CASTING TYPE x.
              ENDIF.
              ASSIGN: <table1_x>(x_namtab-position)
                       TO <vim_f1_beforex>,
                      <vim_h_mkey>(x_namtab-position)
                        TO <vim_mkey_beforex>,
                      <vim_h_old_mkey>(x_namtab-position)
                        TO <vim_old_mkey_beforex>,
                      <vim_h_coll_bfkey>(x_namtab-position)
                        TO <vim_collapsed_mkey_bfx>.
              CLEAR vim_no_mainkey_exists.
            ELSE.
              ASSIGN: vim_dummy_mainkey TO <vim_mkey_before> TYPE 'C',
                      <vim_mkey_before> TO <vim_old_mkey_before>,
                      <vim_mkey_before> TO <vim_f1_before>,
                      vim_dummy_mainkey TO <vim_mkey_beforex> CASTING,
                      <vim_mkey_beforex> TO <vim_old_mkey_beforex>,
                      <vim_mkey_beforex> TO <vim_f1_beforex>,
                      <vim_mkey_beforex> TO <vim_collapsed_mkey_bfx>.
              vim_no_mainkey_exists = 'X'.
            ENDIF.
            MOVE x_namtab-viewfield TO vim_enddate_name-fieldname.
            PERFORM vim_assign_mainkey_after USING sy-tabix.
          ENDIF.
        ENDIF.                         "x_header-delmdtflag eq 'E'
      ELSE.
* end date
        IF x_header-delmdtflag EQ 'E'.
* end date is key field
          CHECK keydate_alr_assigned EQ space.
          keydate_alr_assigned = 'X'.
          IF x_namtab-texttabfld EQ space.
*            ASSIGN: <table1>+x_namtab-position(x_namtab-flength)
*                                   TO <vim_enddate_mask> TYPE 'C'.
            ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE <table1>
             TO <vim_enddate_mask> CASTING TYPE c.
            IF x_namtab-position GT 0.
              IF x_header-generictrp <> 'X'.
** charlike key or non-unicode-system (FS is only assigned for
** downward compatibility).
                length = x_namtab-position
                          DIV cl_abap_char_utilities=>charsize.
                ASSIGN: <table1>(length)
                         TO <vim_f1_before> CASTING TYPE c,
                        vim_mainkey(length)
                          TO <vim_mkey_before> CASTING TYPE c,
                        vim_old_viewkey(length)
                          TO <vim_old_mkey_before> CASTING TYPE c.
              ENDIF.
              IF NOT ( <vim_f1_before> IS ASSIGNED
                       OR <vim_mkey_before> IS ASSIGNED
                       OR <vim_old_mkey_before> IS ASSIGNED ).
** could not be assigned because unicode flag is set in function
** group and key is non charlike
                ASSIGN: <table1_x>(x_namtab-position)
                         TO <vim_f1_before> CASTING TYPE x,
                        vim_mainkey(x_namtab-position)
                          TO <vim_mkey_before> CASTING TYPE x,
                        vim_old_viewkey(x_namtab-position)
                          TO <vim_old_mkey_before> CASTING TYPE x.
              ENDIF.
              ASSIGN: <table1_x>(x_namtab-position)
                       TO <vim_f1_beforex>,
                      <vim_h_mkey>(x_namtab-position)
                        TO <vim_mkey_beforex>,
                      <vim_h_old_mkey>(x_namtab-position)
                        TO <vim_old_mkey_beforex>,
                      <vim_h_coll_bfkey>(x_namtab-position)
                        TO <vim_collapsed_mkey_bfx>.
*              ASSIGN: <table1>(x_namtab-position)
*                                     TO <vim_f1_before> TYPE 'C',
*                      vim_mainkey(x_namtab-position)
*                                     TO <vim_mkey_before> TYPE 'C',
*                      vim_old_viewkey(x_namtab-position)
*                                     TO <vim_old_mkey_before> TYPE 'C'.
              CLEAR vim_no_mainkey_exists.
            ELSE.
              ASSIGN: vim_dummy_mainkey TO <vim_mkey_before> TYPE 'C',
                      <vim_mkey_before> TO <vim_old_mkey_before>,
                      <vim_mkey_before> TO <vim_f1_before>,
                      vim_dummy_mainkey TO <vim_mkey_beforex> CASTING,
                      <vim_mkey_beforex> TO <vim_old_mkey_beforex>,
                      <vim_mkey_beforex> TO <vim_f1_beforex>,
                      <vim_mkey_beforex> TO <vim_collapsed_mkey_bfx>.
              vim_no_mainkey_exists = 'X'.
            ENDIF.
            MOVE x_namtab-viewfield TO vim_enddate_name-fieldname.
            PERFORM vim_assign_mainkey_after USING sy-tabix.
          ENDIF.
        ELSE.
* begin date is key field
          IF x_namtab-texttabfld EQ space.
*            ASSIGN: <table1>+x_namtab-position(x_namtab-flength)
*                                   TO <vim_new_begdate> TYPE 'D',
*                    <table1>+x_namtab-position(x_namtab-flength)
*                                   TO <vim_begdate_mask> TYPE 'C'.
            ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE <table1>
             TO <vim_new_begdate>.
            ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE <table1>
             TO <vim_begdate_mask> CASTING TYPE c.
            MOVE: x_namtab-viewfield TO vim_sval_tab-fieldname,
                  x_namtab-viewfield TO vim_begdate_name-fieldname.
            vim_begdate_is_ro = x_namtab-readonly.
          ENDIF.
        ENDIF.                         "x_header-delmdtflag eq 'E'
      ENDIF.
    ENDLOOP.
    APPEND vim_sval_tab.
    CONDENSE: vim_begdate_name NO-GAPS, vim_enddate_name NO-GAPS.
    MOVE: x_header-viewname TO vim_memory_id_1-viewname,
          sy-uname          TO vim_memory_id_1-user.
    IMPORT vim_collapsed_mainkeys FROM MEMORY ID vim_memory_id_1.
    IF sy-subrc NE 0.
      REFRESH vim_collapsed_mainkeys.
    ENDIF.
    ASSIGN: <vim_h_coll_mkey>(x_header-keylen)
                              TO <vim_collapsed_keyx>,
            <vim_h_coll_logkey>(x_header-keylen)
                              TO <vim_collapsed_logkeyx>,
            <vim_h_merged_key>(x_header-keylen)
                              TO <vim_merged_keyx>.
    IF x_header-generictrp <> 'X'.
      ASSIGN: vim_collapsed_mainkeys-mainkey(x_header-keylen)
                                    TO <vim_collapsed_key>,
              vim_collapsed_mainkeys-log_key(x_header-keylen)
                                    TO <vim_collapsed_logkey>,
              vim_merged_entries-merged_key(x_header-keylen)
                                    TO <vim_merged_key>.
    ELSE.
      ASSIGN: <vim_collapsed_keyx> TO <vim_collapsed_key>,
              <vim_collapsed_logkeyx> TO <vim_collapsed_logkey>,
              <vim_merged_keyx> TO <vim_merged_key>.
    ENDIF.
  ENDIF.                               "x_header-delmdtflag ne space
* if necessary. -> how to decide this ? X_HEADER-PTFRKYEXST, later
  ASSIGN vim_mainkey(x_header-keylen) TO <vim_mainkey_mask>.
  CLEAR vim_prtfky_assigned.
* endif.
* consider clusters in transport defaults
  IF vim_called_by_cluster NE space.
    master_type = vim_clus_type.
    master_name = vim_calling_cluster.
  ENDIF.
* set transport defaults.....
  MOVE: transporter   TO e071-pgmid,
        master_type   TO e071-object,
        master_name   TO e071-obj_name,
        e071_objfunc  TO e071-objfunc,
        transporter   TO e071k-pgmid,
        transp_object TO e071k-object,
        space         TO e071k-as4pos,
        master_type   TO e071k-mastertype,
        master_name   TO e071k-mastername,
        space         TO e071k-objfunc,
        space         TO e071k-flag.
  PERFORM vim_get_img_activity
   CHANGING e071k-activity.           "UF738595/2001
  IF x_header-existency EQ space OR x_header-existency EQ 'M'.
    MOVE sortflag_with_existency TO e071k-sortflag.
  ELSE.
    MOVE sortflag_without_existency TO e071k-sortflag.
  ENDIF.
  REFRESH vim_corr_objtab. CLEAR vim_corr_obj_viewname.
  IF x_header-texttbexst <> space.     "SW Texttransl
    PERFORM vim_initialize_texttab.
    vim_texttab_is_ro = 'X'.
    LOOP AT x_namtab WHERE keyflag EQ space
                       AND bastabname EQ x_header-texttab
                       AND readonly NE rdonly.
      CLEAR vim_texttab_is_ro.
      EXIT.
    ENDLOOP.
  ENDIF.
  CLEAR looplines.
* possible to select profiles?
  vim_coming_from_img = 'N'.
  IF vim_called_by_cluster = space.
*    IF x_header-adrnbrflag = space.
*      CALL FUNCTION 'SCPR_MEMORY_FLAG'
*        IMPORTING
*          coming_from_img = vim_coming_from_img.
*    ENDIF.
  ELSE.
    CALL FUNCTION 'VIEWCLUSTER_PR_IMPORT_CTRL'
      EXPORTING
        viewname        = x_header-viewname
        action          = 'P'
      CHANGING
        coming_from_img = vim_coming_from_img
      EXCEPTIONS
        wrong_parameter = 1
        OTHERS          = 2.
  ENDIF.
  last_view_info = view_name.
  PERFORM vim_maint_selflag USING    'I'
                            CHANGING x_header-selection.
ENDFORM.                    "initialisieren

*---------------------------------------------------------------------*
*       FORM VIM_INITIALIZE_TEXTTAB                                   *
*---------------------------------------------------------------------*
* Initialisierung vin <VIM_TEXTTAB> und <VIM_READ_LANGUS>
*---------------------------------------------------------------------*
FORM vim_initialize_texttab.
  DATA: idx LIKE sy-tabix,
        texttab_l TYPE i.

  READ TABLE vim_texttab_container WITH KEY viewname = view_name
                                   BINARY SEARCH.
  vim_texttab_container_index = sy-tabix.
  IF sy-subrc <> 0.
    CLEAR vim_texttab_container-tabdata-valid_idx.
    REFRESH vim_texttab_container-tabdata-tab_us.
    REFRESH vim_texttab_container-tabdata-tab_vs.
    REFRESH vim_texttab_container-tabdata-tab_s.
    REFRESH vim_texttab_container-tabdata-tab_m.
    REFRESH vim_texttab_container-tabdata-tab_l.
    REFRESH vim_texttab_container-tabdata-tab_vl.
    REFRESH vim_texttab_container-tabdata-tab_ul.
    REFRESH vim_texttab_container-sel_langus.
    CLEAR vim_texttab_container.

    vim_texttab_container-viewname = view_name.
*   Texttabellenbreite bestimmen
    texttab_l = ( x_header-after_keyc + x_header-aft_txttbc )
                 / cl_abap_char_utilities=>charsize + 1.
*    texttab_l = x_header-keylen + x_header-texttablen + 1.
    IF texttab_l LE ultra_short_tab.
      vim_texttab_container-tabdata-valid_idx = 2.
    ELSEIF texttab_l LE very_short_tab.
      vim_texttab_container-tabdata-valid_idx = 3.
    ELSEIF texttab_l LE short_tab.
      vim_texttab_container-tabdata-valid_idx = 4.
    ELSEIF texttab_l LE middle_tab.
      vim_texttab_container-tabdata-valid_idx = 5.
    ELSEIF texttab_l LE long_tab.
      vim_texttab_container-tabdata-valid_idx = 6.
    ELSEIF texttab_l LE very_long_tab.
      vim_texttab_container-tabdata-valid_idx = 7.
    ELSEIF texttab_l LE ultra_long_tab.
      vim_texttab_container-tabdata-valid_idx = 8.
    ENDIF.
    INSERT vim_texttab_container INDEX vim_texttab_container_index.
  ENDIF.
  idx = vim_texttab_container-tabdata-valid_idx.
  ASSIGN COMPONENT idx OF STRUCTURE
         vim_texttab_container-tabdata TO <vim_texttab>.
  ASSIGN vim_texttab_container-sel_langus TO <vim_read_langus>.
ENDFORM.                               "VIM_INITIALIZE_TEXTTAB
*&---------------------------------------------------------------------*
*&      Form  vim_fill_vim_guid_domain
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM vim_fill_vim_guid_domain.
  MOVE: 'I'   TO vim_guid_domain-sign,
        'EQ'  TO vim_guid_domain-option.
  MOVE 'SYSUUID' TO vim_guid_domain-low. APPEND vim_guid_domain.
  MOVE 'SYSUUID_C' TO vim_guid_domain-low. APPEND vim_guid_domain.
  MOVE 'SYSUUID_22' TO vim_guid_domain-low. APPEND vim_guid_domain.
  MOVE 'SYSUUID_25' TO vim_guid_domain-low. APPEND vim_guid_domain.
ENDFORM.                    " vim_fill_vim_guid_domain
*&---------------------------------------------------------------------*
*&      Form  vim_set_init_from_sellist
*&---------------------------------------------------------------------*
*       If sellist defines values unambiguously, set them into initial
*       WA.
*----------------------------------------------------------------------*
*      -->P_TABNAME   tabname
*      -->P_NAMTAB[]  nametab info
*      -->P_SELLIST   selection
*      <--P_INIT      initial view-wa
*----------------------------------------------------------------------*
FORM vim_set_init_from_sellist USING    p_tabname TYPE tabname
                                        p_namtab LIKE x_namtab[]
                                        p_sellist LIKE dba_sellist[]
                                        p_maintdesc TYPE vfldroflag
                               CHANGING p_init TYPE any.

  DATA: count TYPE i, h_ix TYPE i, rcode TYPE xfeld,
        tabfld TYPE tabfield.
  FIELD-SYMBOLS: <namtab> TYPE vimnamtab, <sel_wa> TYPE vimsellist,
                 <value> TYPE ANY.

  LOOP AT p_namtab ASSIGNING <namtab> WHERE readonly = p_maintdesc.
    CLEAR: rcode, count, h_ix.
    LOOP AT p_sellist ASSIGNING <sel_wa>
     WHERE viewfield EQ <namtab>-viewfield
           AND ( negation EQ space AND operator EQ 'EQ' OR
                 negation EQ 'NOT' AND operator EQ 'NE' )
           AND ( ddic      CO 'XB' OR
                 ddic      CO 'SB' ).
      ADD 1 TO count.
      CHECK <sel_wa>-and_or EQ space OR <sel_wa>-and_or EQ 'AND'.
      rcode = 'X'. h_ix = sy-tabix.
    ENDLOOP.
    IF rcode = space OR count > 1.
      CLEAR: rcode, count.
      LOOP AT p_sellist ASSIGNING <sel_wa>
       WHERE viewfield EQ <namtab>-viewfield
        AND ( negation EQ space AND operator EQ 'EQ' OR
                   negation EQ 'NOT' AND operator EQ 'NE' )
             AND ( ddic EQ 'A' ).
        ADD 1 TO count.
        CHECK <sel_wa>-and_or EQ space OR <sel_wa>-and_or EQ 'AND'.
        rcode = 'X'. h_ix = sy-tabix.
      ENDLOOP.
    ENDIF.
    IF rcode <> space AND count = 1.
     ASSIGN COMPONENT <namtab>-viewfield OF STRUCTURE p_init TO <value>.
      CHECK sy-subrc = 0.
      tabfld-tabname = p_tabname.
      tabfld-fieldname = tabfld-lfieldname = <namtab>-viewfield.
      CALL FUNCTION 'RS_CONV_EX_2_IN'
        EXPORTING
          input_external  = <sel_wa>-value
          table_field     = tabfld
        IMPORTING
          output_internal = <value>
        EXCEPTIONS
          OTHERS          = 1.
      IF sy-subrc <> 0.
        CLEAR <value>.
      ENDIF.
    ENDIF.
  ENDLOOP.
ENDFORM.                    " vim_set_init_from_sellist
*&---------------------------------------------------------------------*
*&      Form  vim_fill_date_type
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM vim_fill_date_type.

  MOVE: 'I'   TO vim_begda_types-sign,
        'EQ'  TO vim_begda_types-option.
  MOVE vim_begdate_dtel1 TO vim_begda_types-low. APPEND vim_begda_types.
  MOVE vim_begdate_dtel2 TO vim_begda_types-low. APPEND vim_begda_types.
  MOVE vim_begdate_dtel3 TO vim_begda_types-low. APPEND vim_begda_types.
  MOVE vim_begdate_dtel4 TO vim_begda_types-low. APPEND vim_begda_types.
  MOVE vim_enddate_dtel1 TO vim_begda_types-low.
  APPEND vim_begda_types TO vim_endda_types.
  MOVE vim_enddate_dtel2 TO vim_begda_types-low.
  APPEND vim_begda_types TO vim_endda_types.
  MOVE vim_enddate_dtel3 TO vim_begda_types-low.
  APPEND vim_begda_types TO vim_endda_types.
  MOVE vim_enddate_dtel4 TO vim_begda_types-low.
  APPEND vim_begda_types TO vim_endda_types.
ENDFORM.                    " vim_fill_date_type

*---------------------------------------------------------------------*
*       FORM VIM_PROCESS_ASSIGNS                                      *
*---------------------------------------------------------------------*
* process assigns                                                     *
*---------------------------------------------------------------------*
FORM vim_process_assigns.
  DATA: length TYPE i, keydate_alr_assigned(1) TYPE c,
        tablength TYPE i, texttablength TYPE i, keylen_bef_date TYPE i,
        xlength type i.

  TRANSLATE vim_prtfky_assigned USING 'XY'.
  ASSIGN: <initial> TO <initial_x> CASTING,
          total TO <vim_ctotal> CASTING TYPE c,
          total TO <vim_total_struc> CASTING TYPE (x_header-maintview),
          total to <vim_xtotal> casting,
          extract TO <vim_cextract> CASTING TYPE c,
          extract TO <vim_extract_struc>
           CASTING TYPE (x_header-maintview),
          extract to <vim_xextract> casting,
          corr_keytab-tabkey to <vim_corr_keyx> casting.
  tablength = x_header-after_tabc / cl_abap_char_utilities=>charsize.
  texttablength =
   x_header-aft_txttbc / cl_abap_char_utilities=>charsize.

  IF x_header-bastab NE space AND x_header-texttbexst NE space.
    length = tablength + texttablength.
    xlength = x_header-texttablen + x_header-tablen.
    ASSIGN: <vim_ctotal>+tablength(texttablength) TO <total_text>,
            <vim_xtotal>+x_header-after_tabc(x_header-texttablen)
             to <vim_xtotal_text>,
            <vim_xtotal_text> to <vim_tot_txt_struc>
             casting type (x_header-texttab),
            <vim_cextract>(tablength) TO <extract_enti>,
            <vim_cextract>+tablength(texttablength) TO <extract_text>,
            <vim_xextract>+x_header-after_tabc(x_header-texttablen)
             to <vim_xextract_text>,
            <vim_xextract_text> to <vim_ext_txt_struc>
             casting type (x_header-texttab).
ELSE.
    length = tablength.
    xlength = x_header-tablen.
  ENDIF.
  ASSIGN: <vim_ctotal>+length(1) TO <action>,
          <action>+1(1) TO <mark>,
          <vim_cextract>(length) TO <table2>,
          <vim_xextract>(xlength) to <table2_x>,
          <vim_xextract>(x_header-tablen) to <vim_xextract_enti>,
          <vim_cextract>+length(1) TO <xact>,
          <xact>+1(1)  TO <xmark>,
          <vim_ctotal>(vim_ctabkeylen) TO <vim_total_key>,
          <vim_cextract>(vim_ctabkeylen) TO <vim_extract_key>,
          <vim_xtotal>(x_header-keylen) TO <vim_xtotal_key>,
          <vim_xextract>(x_header-keylen) TO <vim_xextract_key>.

  IF x_header-bastab NE space AND x_header-texttbexst NE space.
    ASSIGN: <mark>+1(1) TO <action_text>,
            <xmark>+1(1) TO <xact_text>.
  ENDIF.
  IF x_header-adrnbrflag NE space.
    assign vim_addresses_to_save-handle to <vim_addr_handle_x> casting.
    LOOP AT x_namtab WHERE domname IN adrnbr_domain.
      ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE
       <vim_total_struc> TO <vim_total_address_number>.
      EXIT.
    ENDLOOP.
  ENDIF.
  IF x_header-delmdtflag NE space.
    LOOP AT x_namtab WHERE domname EQ vim_delim_date_domain
                       AND ( rollname in vim_begda_types or
                             rollname in vim_endda_types ).
      IF x_namtab-rollname in vim_begda_types.
* begin date
        IF x_header-delmdtflag EQ 'E'.
* end date is key field
          IF x_namtab-texttabfld EQ space.
            ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE
             <vim_total_struc> TO <vim_begdate>.
*            ASSIGN total+x_namtab-position(x_namtab-flength)
*                                   TO <vim_begdate> TYPE 'D'.
          ENDIF.
        ELSE.                          "begin date is key field
          CHECK keydate_alr_assigned EQ space OR
                keydate_alr_assigned EQ 'E' AND
                x_namtab-texttabfld NE space OR
                keydate_alr_assigned EQ 'T' AND
                x_namtab-texttabfld EQ space.
          IF x_namtab-texttabfld EQ space.
            TRANSLATE keydate_alr_assigned USING ' ETX'.
            ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE
             <vim_total_struc> TO <vim_enddate>.
*            ASSIGN total+x_namtab-position(x_namtab-flength)
*                                  TO <vim_enddate> TYPE 'D'.
            IF x_namtab-position GT 0.
              ASSIGN: <vim_xtotal>(x_namtab-position)
                       TO <vim_tot_mkey_beforex> casting,
                      <vim_xextract>(x_namtab-position)
                       TO <vim_ext_mkey_beforex> casting.
* for downward compatibility only:
              keylen_bef_date =
               x_namtab-position DIV cl_abap_char_utilities=>charsize.
              ASSIGN: <vim_ctotal>(keylen_bef_date)
                                     TO <vim_tot_mkey_before> TYPE 'C',
                      <vim_cextract>(keylen_bef_date)
                                     TO <vim_ext_mkey_before> TYPE 'C'.
            ELSE.
              ASSIGN:
*      begin correction if position <= 0, should be fitted to unicode.
                      vim_dummy_mainkey TO <vim_tot_mkey_beforex>
                                                              casting ,
                      vim_dummy_mainkey TO <vim_tot_mkey_beforex>
                                                              casting ,
*      end correction von XB am 22.03.02 for csn int1332679 2002
                      vim_dummy_mainkey TO <vim_tot_mkey_before>
                                                              TYPE 'C',
                      <vim_tot_mkey_before> TO <vim_ext_mkey_before>
                                                              TYPE 'C'.
            ENDIF.
            IF vim_mkey_after_exists NE space.
              PERFORM vim_assign_mkey_after_2 USING sy-tabix.
            ENDIF.
          ELSE.
            TRANSLATE keydate_alr_assigned USING ' TEX'.
            ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE
             <vim_tot_txt_struc> TO <vim_text_enddate>.
*            ASSIGN total+x_namtab-position(x_namtab-flength)
*                                  TO <vim_text_enddate> TYPE 'D'.
          ENDIF.
        ENDIF.                         "x_header-delmdtflag eq 'E'
      ELSE.
* end date
        IF x_header-delmdtflag EQ 'E'.
* end date is key field
          CHECK keydate_alr_assigned EQ space OR
                keydate_alr_assigned EQ 'E' AND
                x_namtab-texttabfld NE space OR
                keydate_alr_assigned EQ 'T' AND
                x_namtab-texttabfld EQ space.
          IF x_namtab-texttabfld EQ space.
            TRANSLATE keydate_alr_assigned USING ' ETX'.
            ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE
             <vim_total_struc> TO <vim_enddate>.
*            ASSIGN total+x_namtab-position(x_namtab-flength)
*                                  TO <vim_enddate> TYPE 'D'.
            IF x_namtab-position GT 0.
              ASSIGN: <vim_xtotal>(x_namtab-position)
                       TO <vim_tot_mkey_beforex> casting,
                      <vim_xextract>(x_namtab-position)
                       TO <vim_ext_mkey_beforex> casting.
* for downward compatibility only:
              keylen_bef_date =
               x_namtab-position DIV cl_abap_char_utilities=>charsize.
              ASSIGN:
                      <vim_ctotal>(keylen_bef_date)
                                     TO <vim_tot_mkey_before> TYPE 'C',
                      <vim_cextract>(keylen_bef_date)
                                     TO <vim_ext_mkey_before> TYPE 'C'.
*              ASSIGN: total(x_namtab-position)
*                                     TO <vim_tot_mkey_before> TYPE 'C',
*                      extract(x_namtab-position)
*                                     TO <vim_ext_mkey_before> TYPE 'C'.
            ELSE.
              ASSIGN:
*      begin correction if position <= 0, should be fitted to unicode.
                      vim_dummy_mainkey TO <vim_tot_mkey_beforex>
                                                              casting ,
                      vim_dummy_mainkey TO <vim_ext_mkey_beforex>
                                                              casting ,
*      end correction von XB am 22.03.02 for csn int1332679 2002
                      vim_dummy_mainkey TO <vim_tot_mkey_before>
                                                              TYPE 'C',
                      <vim_tot_mkey_before> TO <vim_ext_mkey_before>
                                                              TYPE 'C'.
            ENDIF.
            IF vim_mkey_after_exists NE space.
              PERFORM vim_assign_mkey_after_2 USING sy-tabix.
            ENDIF.
          ELSE.
            TRANSLATE keydate_alr_assigned USING ' TEX'.
            ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE
             <vim_tot_txt_struc> TO <vim_text_enddate>.
*            ASSIGN total+x_namtab-position(x_namtab-flength)
*                                  TO <vim_text_enddate> TYPE 'D'.
          ENDIF.
        ELSE.                          "begin date is key field
          IF x_namtab-texttabfld EQ space.
            ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE
             <vim_total_struc> TO <vim_begdate>.
*            ASSIGN total+x_namtab-position(x_namtab-flength)
*                                   TO <vim_begdate> TYPE 'D'.
          ENDIF.
        ENDIF.                         "x_header-delmdtflag eq 'E'
      ENDIF.
    ENDLOOP.
  ENDIF.
ENDFORM.                               "vim_process_assigns

*---------------------------------------------------------------------*
*       FORM VIM_ASSIGN_MKEY_AFTER_2                                  *
*---------------------------------------------------------------------*
* assign symbols to after-date-part of mainkey part 2                 *
*---------------------------------------------------------------------*
FORM vim_assign_mkey_after_2 USING value(vama2_tabix) TYPE i.
  LOCAL:x_namtab.
  DATA: vama_ix TYPE i, keylen TYPE i, position TYPE i.
  FIELD-SYMBOLS: <x_namtab> TYPE vimnamtab.

  check vim_mkey_after_exists <> space.
  vama_ix = vama2_tabix + 1.
  READ TABLE x_namtab ASSIGNING <x_namtab> INDEX vama_ix.
  vama_ix = x_header-keylen - <x_namtab>-position.
  ASSIGN: <vim_xtotal>+<x_namtab>-position(vama_ix)
                            TO <vim_tot_mkey_afterx>,
          <vim_xextract>+<x_namtab>-position(vama_ix)
                            TO <vim_ext_mkey_afterx>.
  IF x_header-generictrp <> 'X'.
* charlike key or non-unicode-system (FS is only assigned for
* downward compatibility).
    keylen = x_header-keylen / cl_abap_char_utilities=>charsize.
    position = <x_namtab>-position / cl_abap_char_utilities=>charsize.
    vama_ix = keylen - position.
    ASSIGN: <vim_ctotal>+position(vama_ix)
                              TO <vim_tot_mkey_after> TYPE 'C',
            <vim_cextract>+position(vama_ix)
                              TO <vim_ext_mkey_after> TYPE 'C'.
  ELSE.
    ASSIGN: <vim_xtotal>+<x_namtab>-position(vama_ix)
             TO <vim_tot_mkey_after>,
            <vim_xextract>+<x_namtab>-position(vama_ix)
             TO <vim_ext_mkey_after>.
  ENDIF.
ENDFORM.                               "vim_assign_mkey_after_2

*---------------------------------------------------------------------*
*       FORM VIM_ASSIGN_MAINKEY_AFTER                                 *
*---------------------------------------------------------------------*
* assign symbols to after-date-part of mainkey                        *
*---------------------------------------------------------------------*
FORM vim_assign_mainkey_after USING value(vama_tabix) TYPE i.
  DATA: vama_ix TYPE i, length TYPE i.
  FIELD-SYMBOLS: <x_namtab> TYPE vimnamtab.

  vama_ix = vama_tabix + 1.
  READ TABLE x_namtab ASSIGNING <x_namtab> INDEX vama_ix.
  IF sy-subrc EQ 0 AND                 "entry found and
   <x_namtab>-texttabfld EQ space AND  "key continues
   <x_namtab>-position LT x_header-keylen. "after date field
    vama_ix = x_header-keylen - <x_namtab>-position.
    ASSIGN: <table1_x>+<x_namtab>-position(vama_ix)
                              TO <vim_f1_afterx>,
            <vim_h_coll_mkey>+<x_namtab>-position(vama_ix)
                              TO <vim_collapsed_key_afx>,
            <vim_h_mkey>+<x_namtab>-position(vama_ix)
                              TO <vim_mkey_afterx>,
            <vim_h_old_mkey>+<x_namtab>-position(vama_ix)
                              TO <vim_old_mkey_afterx>. " TYPE 'C'.
    IF x_header-generictrp <> 'X'.
** charlike key or non-unicode-system (FS is only assigned for
** downward compatibility).
      length = <x_namtab>-position
                DIV cl_abap_char_utilities=>charsize.
      vama_ix = vama_ix DIV cl_abap_char_utilities=>charsize.
      ASSIGN: <table1>+length(vama_ix)
                                TO <vim_f1_after>,
              vim_collapsed_mainkeys-mainkey+length(vama_ix)
                                TO <vim_collapsed_key_af>,
              vim_mainkey+length(vama_ix)
                                TO <vim_mkey_after>,
              vim_old_viewkey+length(vama_ix)
                                TO <vim_old_mkey_after>.
    ELSE.
      ASSIGN: <vim_f1_afterx> TO <vim_f1_after>,
              <vim_collapsed_key_afx> TO <vim_collapsed_key_af>,
              <vim_mkey_afterx> TO <vim_mkey_after>,
              <vim_old_mkey_afterx> TO <vim_old_mkey_after>.
    ENDIF.
    vim_mkey_after_exists = 'X'.
    CLEAR vim_no_mainkey_exists.
  ELSE.
    CLEAR vim_mkey_after_exists.
  ENDIF.
ENDFORM.                               "vim_asign_mainkey_after

*---------------------------------------------------------------------*
*       FORM SET_POSITION_INFO                                        *
*---------------------------------------------------------------------*
* fill position info                                                  *
*---------------------------------------------------------------------*
* SPI_POSITION      ---> current position                             *
* SPI_ENTRIES       ---> total number of entries                      *
* VIM_POSITION_INFO <--- (global) string filled with position info    *
*---------------------------------------------------------------------*
FORM SET_POSITION_INFO USING VALUE(SPI_POSITION) TYPE I
                             VALUE(SPI_ENTRIES) TYPE I.
  DATA: HF1 TYPE I, HF2 TYPE I, HF3 TYPE I,
        P_VIM_POSITION_INFO_LEN TYPE I.

  MOVE VIM_POSITION_INFO_MASK TO VIM_POSITION_INFO.
  HF1 = VIM_POSITION_INFO_LG1 + 1.
  IF SPI_ENTRIES EQ 0.
    HF3 = 0.
  ELSE.
    HF3 = SPI_POSITION.
  ENDIF.
  WRITE HF3 TO
    VIM_POSITION_INFO+HF1(VIM_POSITION_INFO_LG3) NO-SIGN.
  HF1 = VIM_POSITION_INFO_LG1 + VIM_POSITION_INFO_LG2
                                    + VIM_POSITION_INFO_LG3 + 3.
  WRITE SPI_ENTRIES TO
    VIM_POSITION_INFO+HF1(VIM_POSITION_INFO_LG3) NO-SIGN.
  DO.
    CONDENSE VIM_POSITION_INFO.
* XB 585898B
* call methode to caculat the visible length of vim_position_info
    CALL METHOD cl_scp_linebreak_util=>get_visual_stringlength
      EXPORTING
        im_string               = VIM_POSITION_INFO
        IM_LANGU                = SY-LANGU
      IMPORTING
        EX_POS_VIS              = P_VIM_POSITION_INFO_LEN
*      EXCEPTIONS
*        INVALID_TEXT_ENVIROMENT = 1
*        others                  = 2
        .
    IF sy-subrc <> 0.
*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

*    HF2 = VIM_POSITION_INFO_LEN - STRLEN( VIM_POSITION_INFO ).
    HF2 = VIM_POSITION_INFO_LEN - P_VIM_POSITION_INFO_LEN.
* XB 585898E

    IF HF2 GT 0.
      SHIFT VIM_POSITION_INFO RIGHT BY HF2 PLACES.
    ENDIF.
    IF HF2 GE 0. EXIT. ENDIF.
    HF1 = STRLEN( SVIM_TEXT_028 ).
    REPLACE SVIM_TEXT_028 LENGTH HF1 WITH '/' INTO VIM_POSITION_INFO.
    IF SY-SUBRC NE 0.
      HF1 = STRLEN( SVIM_TEXT_027 ) + HF2 - 1.
      IF HF1 GT 0.
        WRITE '.' TO VIM_POSITION_INFO+HF1(1).
        ADD 1 TO HF1. HF2 = - HF2.
        WRITE '          ' TO VIM_POSITION_INFO+HF1(HF2).
      ELSE.
        EXIT.
      ENDIF.
    ENDIF.
  ENDDO.
ENDFORM.                               "set_position_info

*---------------------------------------------------------------------*
*       FORM SET_NUMBERED_TEXTS                                       *
*---------------------------------------------------------------------*
* numerierte Texte aus Textpool übernehmen                            *
*---------------------------------------------------------------------*
FORM SET_NUMBERED_TEXTS.
  DATA: NAME(20) TYPE C.
  FIELD-SYMBOLS: <M1>.
  READ TEXTPOOL MASTER_FPOOL INTO TEXTPOOL_TAB LANGUAGE SY-LANGU.
  SORT TEXTPOOL_TAB BY ID KEY.
  MOVE NBRD_TEXTS_PREFIX TO NAME.
  LOOP AT TEXTPOOL_TAB WHERE ID EQ 'I'.
    WRITE TEXTPOOL_TAB-KEY TO NAME+NBRD_TEXTS_PREFIX_LENGTH.
    ASSIGN (NAME) TO <M1>.
    IF SY-SUBRC = 0.
      " not all text elements are needed ???
      MOVE TEXTPOOL_TAB-ENTRY TO <M1>.
    ENDIF.
  ENDLOOP.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM INIT_STATE_VECTOR                                        *
*---------------------------------------------------------------------*
* viewspezif. Statusvektor initialisieren                             *
*---------------------------------------------------------------------*
FORM INIT_STATE_VECTOR.
* IF <STATUS>-ALR_SETUP EQ SPACE.
  NEXTLINE = 1.
  MOVE: NICHT_GELOESCHT   TO <STATUS>-ST_DELETE,
        GESAMTDATEN       TO <STATUS>-ST_DATA,
        GESAMTDATEN       TO TITLE-DATA,
        LIST_BILD         TO <STATUS>-ST_MODE,
        LIST_BILD         TO TITLE-MODE,
        MAINT_MODE        TO <STATUS>-ST_ACTION,
        MAINT_MODE        TO TITLE-ACTION,
        <STATUS>-CORR_NBR TO <STATUS>-L_CORR_NBR,
        CORR_NBR          TO <STATUS>-CORR_NBR,
        TITLE             TO <STATUS>-TITLE,
        1                 TO <STATUS>-CUR_LINE,
        1                 TO <STATUS>-FIRSTLINE,
        0                 TO <STATUS>-MK_XT,
        0                 TO <STATUS>-MK_TO,
        0                 TO <STATUS>-MAXLINES,
        0                 TO <STATUS>-CUR_OFFSET,
        SPACE             TO <STATUS>-FCODE,
        SPACE             TO <STATUS>-CUR_FIELD,
        SPACE             TO <STATUS>-UPD_FLAG,
        SPACE             TO <STATUS>-CRCNTSKNWN,
        SPACE             TO <STATUS>-KEYTBMODFD,
        SPACE             TO <STATUS>-DLCLALRCKD,
        SPACE             TO <STATUS>-TR_ALRCHKD,
*         'X'               TO <STATUS>-ALR_SETUP,
        'x'               TO <STATUS>-INITIALIZD,
        NICHT_MARKIERT    TO BLOCK_SW.
  IF MAINT_MODE = STATUS-ACTION OR MAINT_MODE = ANZEIGEN.  "UF profilesb
    CLEAR <STATUS>-PROF_FOUND.
  ENDIF.                               "UF profilese
  CLEAR <STATUS>-NEWADRCNT.
* ENDIF.
  CLEAR FILL_EXTR_FIRST_PROC.
* Übergangslösung Sortierungsproblem Anfang
* CLEAR <STATUS>-ALR_SORTED.
  TRANSLATE <STATUS>-ALR_SORTED USING 'RXX '.
* Übergangslösung Sortierungsproblem Ende
  CLEAR: VIM_OLD_VIEWKEY, VIM_OLD_ST_SELECTED.
  TRANSLATE VIM_NO_MAINKEY_EXISTS USING VIM_NO_MKEY_NOT_PROCSD_PATT.
  LAST_CORR_NUMBER = <STATUS>-L_CORR_NBR.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM SET_STATUS_NOKEYSELCNDS                                  *
*---------------------------------------------------------------------*
* ........                                                            *
*---------------------------------------------------------------------*
FORM SET_STATUS_NOKEYSELCNDS.
  CLEAR <STATUS>-NOKEYSLCDS.
* LOOP AT DPL_SELLIST.
  LOOP AT <VIM_CK_SELLIST> INTO DPL_SELLIST.
    READ TABLE X_NAMTAB INDEX DPL_SELLIST-TABIX.
    IF X_NAMTAB-KEYFLAG EQ SPACE.
      <STATUS>-NOKEYSLCDS = 'X'. EXIT.
    ENDIF.
  ENDLOOP.
  <STATUS>-INITIALIZD = 'X'.
ENDFORM.                               "set_status_nokeyselcnds

*---------------------------------------------------------------------*
*       FORM EXCLUDE_CUA_FUNCTIONS                                    *
*---------------------------------------------------------------------*
* ggf. Funktionen ausschließen                                        *
*---------------------------------------------------------------------*
FORM exclude_cua_functions.
  MOVE 'SLCT' TO excl_cua_funct-function. COLLECT excl_cua_funct.
  IF x_header-delmdtflag EQ space.
    MOVE 'DELM' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    MOVE 'EXPA' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    TRANSLATE x_header-existency USING 'MU'.
    MODIFY x_header INDEX 1.
  ELSEIF vim_begdate_is_ro NE space.
    MOVE 'DELM' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    MODIFY x_header INDEX 1.
  ENDIF.
  CASE x_header-existency.
    WHEN 'U'.                          "update only
      MOVE 'NEWL' TO excl_cua_funct-function. COLLECT excl_cua_funct.
      MOVE 'ALNW' TO excl_cua_funct-function. COLLECT excl_cua_funct.
      MOVE 'ALOE' TO excl_cua_funct-function. COLLECT excl_cua_funct.
      MOVE 'DELE' TO excl_cua_funct-function. COLLECT excl_cua_funct.
      MOVE 'KOPE' TO excl_cua_funct-function. COLLECT excl_cua_funct.
      MOVE 'DELM' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    WHEN 'M'.                          "update only for main key
      MOVE 'NEWL' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    WHEN 'R'.                          "read only
      MOVE 'AEND' TO excl_cua_funct-function. COLLECT excl_cua_funct.
  ENDCASE.
  IF x_header-clidep EQ space OR sy-mandt EQ '000'.
    MOVE 'COMP' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    IF x_header-clidep EQ space.
      MOVE 'CMPO' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    ENDIF.
  ENDIF.
  IF x_header-flag NE space AND x_header-cursetting EQ 'Y' AND
     NOT ( x_header-frm_e071 NE space OR x_header-frm_e071ks NE space OR
           x_header-frm_e071ka NE space ).
    MOVE 'TRSP' TO excl_cua_funct-function. COLLECT excl_cua_funct.
  ENDIF.
  IF x_header-adrnbrflag EQ space.
    MOVE 'ADDR' TO excl_cua_funct-function. COLLECT excl_cua_funct.
  ELSE.
    LOOP AT excl_cua_funct WHERE function EQ 'ADDR'.
      DELETE excl_cua_funct.
    ENDLOOP.
  ENDIF.
  IF x_header-scrfrmflag EQ space.
    MOVE 'SCRF' TO excl_cua_funct-function. COLLECT excl_cua_funct.
  ELSE.
    LOOP AT excl_cua_funct WHERE function EQ 'SCRF'.
      DELETE excl_cua_funct.
    ENDLOOP.
  ENDIF.
  IF x_header-texttbexst EQ space.     "SW Texttransl
    MOVE 'LANG' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    MOVE 'TEXT' TO excl_cua_funct-function. COLLECT excl_cua_funct.
  ENDIF.
  IF vim_coming_from_img = 'N'.        "UF profiles
* profiles can't be activated
    MOVE 'GPRF' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    MOVE 'UPRF' TO excl_cua_funct-function. COLLECT excl_cua_funct.
  ELSE.
    IF maint_mode = anzeigen.
* profile activating not allowed
      MOVE 'UPRF' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    ELSE.
      DELETE excl_cua_funct WHERE function = 'UPRF'.
    ENDIF.
  ENDIF.
  IF <status>-bcfixnochg = space.
    MOVE 'BCCH' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    MOVE 'BCSH' TO excl_cua_funct-function. COLLECT excl_cua_funct.
  ELSE.
    DELETE excl_cua_funct WHERE function = 'BCCH'.
    DELETE excl_cua_funct WHERE function = 'BCSH'.
  ENDIF.
ENDFORM.                    "EXCLUDE_CUA_FUNCTIONS

*---------------------------------------------------------------------*
*       FORM SET_PF_STATUS                                            *
*---------------------------------------------------------------------*
* PF-Status setzen: entweder allgemein oder angegeb. Programm         *
*---------------------------------------------------------------------*
FORM set_pf_status USING value(sps_status).
  DATA: sps_state LIKE sy-pfkey, sps_stat TYPE state_vector.
  CASE x_header-gui_prog.
    WHEN master_fpool.
      MOVE sps_status TO sps_state.
      CALL FUNCTION 'VIEW_SET_PF_STATUS'
        EXPORTING
          status         = sps_state
          objimp         = x_header-importable
        TABLES
          excl_cua_funct = excl_cua_funct.
    WHEN sy-repid.
      MOVE sps_status TO sps_stat.
      IF sps_stat-action EQ anzeigen OR
         sps_stat-action EQ transportieren OR
         ( sy-mandt EQ '000' AND vim_system_type NE 'SAP' ) OR
         x_header-importable = vim_not_importable.
        vim_comp_menue_text = svim_text_045.
      ELSE.
        vim_comp_menue_text = svim_text_046.
      ENDIF.
      vim_pr_stat_txt_ch = svim_text_prb.
      vim_pr_stat_txt_ta = svim_text_prc.
      vim_pr_stat_txt_me = svim_text_pri.
      vim_pr_stat_txt_or = svim_text_prj.
      SET PF-STATUS sps_status EXCLUDING excl_cua_funct.
    WHEN OTHERS.
      RAISE wrong_gui_programm.
  ENDCASE.
ENDFORM.                    "SET_PF_STATUS

*---------------------------------------------------------------------*
*       FORM SET_TITLE                                                *
*---------------------------------------------------------------------*
* Titel setzen: entweder allgemein oder angegeb. Programm             *
*---------------------------------------------------------------------*
FORM set_title USING st_title st_title_text.
  DATA: st_state LIKE sy-pfkey.
  CASE x_header-gui_prog.
    WHEN master_fpool.
      MOVE st_title TO st_state.
      CALL FUNCTION 'VIEW_SET_PF_STATUS'
        EXPORTING
          status         = st_state
          title          = 'X'
          title_text     = st_title_text
          objimp         = x_header-importable
        TABLES
          excl_cua_funct = excl_cua_funct.
    WHEN sy-repid.
      SET TITLEBAR st_title WITH st_title_text.
    WHEN OTHERS.
      RAISE wrong_gui_programm.
  ENDCASE.
ENDFORM.                    "SET_TITLE

*---------------------------------------------------------------------*
*       FORM JUSTIFY_ACTION_MODE                                      *
*---------------------------------------------------------------------*
* ggf. VIEW_ACTION aendern und View entsperren                        *
*---------------------------------------------------------------------*
FORM justify_action_mode.
  DATA: action_changed(1) TYPE c, assigned(1) TYPE c.
  DATA: i_statetab LIKE adrstatus OCCURS 0 WITH HEADER LINE,
        i_messnbr LIKE sy-msgno.

  FIELD-SYMBOLS: <f_fld_value> TYPE any.  " XB H612358

  IF fcode = vim_read_text.            "SW Textimp ...
    PERFORM vim_read_texttab_all_langus.
    EXIT.
  ENDIF.                               "... SW Textimp

* XB H612358B
* check if the time-field exists: Yes, then reset initial value.
    LOOP AT x_namtab WHERE datatype = 'TIMS'.
      ASSIGN COMPONENT x_namtab-viewfield of STRUCTURE <initial>
           TO <f_fld_value>.
      IF <f_fld_value> <> SPACE.
        CLEAR <f_fld_value> WITH SPACE.
      ENDIF.
    ENDLOOP.
* XB H612358B

  IF x_header-selection EQ space.
    DESCRIBE TABLE dba_sellist.
    IF sy-tfill GT 0.
      MOVE 'X' TO x_header-selection.
      MODIFY x_header INDEX 1.
*      IF last_view_info EQ view_name.                       "UF443580b
** <initial> not yet filled in INITIALISIEREN
*        PERFORM vim_set_init_from_sellist USING x_header-maintview
*                                                x_namtab[]
*                                                dba_sellist[]
*                                                vim_hidden
*                                          CHANGING <initial>.
*      ENDIF.                                                "UF443580e
    ELSE.
      DESCRIBE TABLE dpl_sellist.
      IF sy-tfill GT 0.
        MOVE 'X' TO x_header-selection.
        MODIFY x_header INDEX 1.
      ENDIF.
    ENDIF.
  ELSEIF x_header-selection = 'X'.     "XB BCEK064860 begin
*<inital> not filled because the F3. XB int4436226
    DESCRIBE TABLE dba_sellist.
    IF sy-tfill GT 0.
      IF last_view_info EQ view_name.                       "UF443580b
* <initial> not yet filled in INITIALISIEREN
* because with F3 the last_view_info exists.
        PERFORM vim_set_init_from_sellist USING x_header-maintview
                                                x_namtab[]
                                                dba_sellist[]
                                                vim_hidden
                                          CHANGING <initial>.
      ENDIF.                                    "UF443580e
    ENDIF.           "XB BCEK064860 end
  ENDIF.
  IF x_header-adrnbrflag NE space.
* 4.0: check if new version of address maintenance must be used
    CALL FUNCTION 'ADDR_TSADRV_READ'
      EXPORTING
        ddic_tablename  = vim_addr_basetable
        ddic_fieldname  = vim_addr_bastab_field
      IMPORTING
        tsadrv_wa       = vim_tsadrv
      EXCEPTIONS
        entry_not_found = 1.
    IF sy-subrc NE 0.                  "no tsadrv entry found...
      IF x_header-adrnbrflag EQ 'N'.   "new version requires entry
        MESSAGE i287(am) WITH vim_addr_basetable vim_addr_bastab_field.
        CLEAR x_header-adrnbrflag. MODIFY x_header INDEX 1.
      ELSE. "old version runs but is old fashioned....
        IF vim_system_type EQ 'SAP'.   "sap system
          MESSAGE i290(am) WITH vim_addr_basetable  "...send message
                                vim_addr_bastab_field.
        ELSE.
          MESSAGE i291(am) WITH vim_addr_basetable  "...send message
                                vim_addr_bastab_field.
        ENDIF.
      ENDIF.
    ELSE.                              "entry found....
      IF vim_tsadrv-addr_group IS INITIAL. "...but not complete
*       I_TSADRV-ADDR_GROUP = 'CA01'. "default: Customizing Address
        IF x_header-adrnbrflag EQ 'N'. "new version
          i_messnbr = '292'.
        ELSE.                          "old version
          IF vim_system_type EQ 'SAP'. "sap system
            i_messnbr = '288'.
          ELSE.                        "customer system
            i_messnbr = '289'.
          ENDIF.
        ENDIF.
        MESSAGE ID 'AM' TYPE 'I' NUMBER i_messnbr
                        WITH vim_addr_basetable
                             vim_addr_bastab_field
                             vim_tsadrv-tablename
                             vim_tsadrv-fieldname.
        CLEAR x_header-adrnbrflag. MODIFY x_header INDEX 1.
      ELSE.                            "entry in TSADRV is complete
        vim_addr_group = vim_tsadrv-addr_group.
        IF x_header-adrnbrflag EQ 'O'.
          CALL FUNCTION 'ADDR_GET_STATUS_INFO'
            TABLES
              status_table = i_statetab.
          READ TABLE i_statetab WITH KEY
               constant = vim_tsadrv-addr_group.
          IF sy-subrc NE 0. CLEAR i_statetab-value. ENDIF.
          TRANSLATE i_statetab-value USING ' OXN'.
          x_header-adrnbrflag = i_statetab-value.
          MODIFY x_header INDEX 1.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.
  PERFORM vim_process_assigns.
  IF <status>-initializd EQ space.     "not processed yet
* reset dropdown lists
    CALL FUNCTION 'VRM_REFRESH_VALUES'.
    IF x_header-frm_af_ini NE space.   "user exit exists AND
* set environment for user exit.
      ASSIGN dba_sellist-*sys* TO <vim_sellist>.
      vim_enqueue_range = x_header-subsetflag. assigned = 'X'.
* perform user exit -> 3.0B processed in JUSTIFY_ACTION_MODE
      PERFORM (x_header-frm_af_ini) IN PROGRAM (sy-repid).
    ENDIF.
* backup DBA_SELLIST
*    REFRESH vim_dba_sel_kept.                        "UF210200b
*    APPEND LINES OF dba_sellist TO vim_dba_sel_kept.
* remove multiple values for subsets
    DELETE dba_sellist WHERE ddic = 'M'.
    DESCRIBE TABLE dba_sellist.
    IF sy-tfill GT 0.
      READ TABLE dba_sellist INDEX sy-tfill.
      CLEAR dba_sellist-and_or.
      MODIFY dba_sellist INDEX sy-tabix.
    ENDIF.                                                  "UF210200e
  ENDIF.
  IF view_action EQ aendern AND
     function EQ switch_to_update_mode AND
     vim_enq_s_u_rc NE 0.
    MOVE anzeigen TO view_action. action_changed = 'X'.
  ENDIF.
  IF x_header-existency EQ rdonly AND  "read only view
     ( view_action EQ aendern OR       "update or
       view_action EQ transportieren )."transport request
    MOVE anzeigen TO view_action. action_changed = 'X'.
    MESSAGE i044(sv).
  ENDIF.
  IF <status>-corr_nbr EQ vim_locked_in_corr AND "object locked and
     ( view_action EQ aendern OR       "update or
       view_action EQ transportieren )."transport request
    MOVE anzeigen TO view_action. action_changed = 'X'.
  ENDIF.
  IF view_action EQ aendern.
    IF vim_last_objh_view NE view_name.
      PERFORM vim_set_ale_edit_lock.
    ENDIF.
    IF vim_ale_edit_lock NE space.
      MOVE anzeigen TO view_action. action_changed = 'X'.
*     MESSAGE I044(SV).
      MESSAGE ID vim_ale_msgid TYPE 'I' NUMBER vim_ale_msgno
              WITH vim_ale_msgv1 vim_ale_msgv2
                   vim_ale_msgv3 vim_ale_msgv4.
    ENDIF.
  ENDIF.
  IF x_header-frm_on_aut NE space AND  "4.5a: support indiv. auth. chck
     <status>-initializd EQ space.     "not processed yet
    vim_auth_action = view_action.
    vim_auth_event = vim_auth_initial_check.
    ASSIGN dba_sellist[] TO <vim_auth_sellist>.
    PERFORM (x_header-frm_on_aut) IN PROGRAM.
    IF vim_auth_rc NE 0.
      MESSAGE ID vim_auth_msgid TYPE 'I' NUMBER vim_auth_msgno
              WITH vim_auth_msgv1 vim_auth_msgv2
                   vim_auth_msgv3 vim_auth_msgv4.
      CASE vim_auth_rc.
        WHEN 4.                        "show only
          MOVE anzeigen TO view_action. action_changed = 'X'.
        WHEN 8.                        "exit
          RAISE missing_corr_number.
      ENDCASE.
    ENDIF.
  ENDIF.
  IF action_changed NE space.
    IF assigned EQ space.
      ASSIGN dba_sellist-*sys* TO <vim_sellist>.
      vim_enqueue_range = x_header-subsetflag.
    ENDIF.
    PERFORM enqueue USING 'D' x_header-frm_af_enq. "dequeue view
  ENDIF.
  IF x_header-texttbexst <> space.     "SW Texttransl
    PERFORM vim_actualize_d0100.
  ENDIF.
ENDFORM.                    "justify_action_mode

*---------------------------------------------------------------------*
*       FORM VIM_SET_ALE_EDIT_LOCK                                    *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM VIM_SET_ALE_EDIT_LOCK.
  DATA: I_EDITLOCK(1) TYPE C.

  VIM_LAST_OBJH_VIEW = VIEW_NAME.
  REFRESH VIM_ALE_KEYSPEC_OBJTAB.
  IF X_HEADER-FLAG EQ SPACE.           "standard transport required
    PERFORM VIM_CHECK_ALE_EDIT_LOCK USING E071-OBJECT I_EDITLOCK.
    VIM_ALE_EDIT_LOCK = I_EDITLOCK.
    IF VIM_ALE_EDIT_LOCK NE SPACE. EXIT. ENDIF.
  ENDIF.
  IF X_HEADER-FRM_E071 NE SPACE. "individual transport objects exist
    IF VIM_CORR_OBJ_VIEWNAME NE X_HEADER-VIEWNAME.
      PERFORM (X_HEADER-FRM_E071) IN PROGRAM (SY-REPID).
      CLEAR VIM_CORR_OBJ_VIEWNAME.
    ENDIF.
    LOOP AT VIM_CORR_OBJTAB.
      PERFORM VIM_CHECK_ALE_EDIT_LOCK USING VIM_CORR_OBJTAB-OBJECT
                                            I_EDITLOCK.
      VIM_ALE_EDIT_LOCK = I_EDITLOCK.
      IF VIM_ALE_EDIT_LOCK NE SPACE. EXIT. ENDIF.
    ENDLOOP.
  ENDIF.
ENDFORM.                               "vim_set_ale_edit_lock


*---------------------------------------------------------------------*
*       FORM VIM_CHECK_ALE_EDIT_LOCK                                  *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM VIM_CHECK_ALE_EDIT_LOCK USING VALUE(VCAEL_OBJECT) LIKE E071-OBJECT
                                   VCAEL_LOCK TYPE C.
  DATA: OBJ_TYPE LIKE OBJH-OBJECTTYPE, OBJ_NAME LIKE OBJH-OBJECTNAME.

* OBJ_NAME = VIEW_NAME.
  OBJ_NAME = MASTER_NAME.
  CASE VCAEL_OBJECT.
    WHEN VIM_VIEW_TYPE.                "-> view
      OBJ_TYPE = VIM_VIEW.
    WHEN TRANSP_OBJECT.                "-> tables
      OBJ_TYPE = VIM_TABL.
    WHEN VIM_CLUS_TYPE.                "-> viewcluster
      OBJ_TYPE = VIM_CLST.
    WHEN VIM_TRAN_TYPE.                "-> individual transaction
      OBJ_TYPE = VIM_TRAN.
    WHEN OTHERS.                       "-> may be LOGO object ?
      OBJ_TYPE = VIM_LOGO. OBJ_NAME = VCAEL_OBJECT.
*     SELECT SINGLE * FROM OBJH WHERE OBJECTNAME EQ OBJ_NAME "required ?
*                                 AND OBJECTTYPE EQ OBJ_TYPE.
*     IF SY-SUBRC NE 0. CLEARVCAEL_LOCK. EXIT. ENDIF. "no logo-object
  ENDCASE.
  CALL FUNCTION 'ALE_EDIT_CHECK'
       EXPORTING
            OBJECTTYPE      = OBJ_TYPE
            OBJECTNAME      = OBJ_NAME
       IMPORTING
            SOMEKEYS_NOEDIT = VIM_ALE_KEYSPEC_CHECK
       EXCEPTIONS
            NO_CALL         = 1
            NO_EDIT         = 2.
  IF SY-SUBRC GT 1.
    VCAEL_LOCK = 'X'.
    VIM_ALE_MSGID = SY-MSGID. VIM_ALE_MSGNO = SY-MSGNO.
    VIM_ALE_MSGV1 = SY-MSGV1. VIM_ALE_MSGV2 = SY-MSGV2.
    VIM_ALE_MSGV3 = SY-MSGV3. VIM_ALE_MSGV4 = SY-MSGV4.
  ELSE.
    CLEAR VCAEL_LOCK.
    IF VIM_ALE_KEYSPEC_CHECK NE SPACE AND OBJ_TYPE NE VIM_LOGO.
      VIM_ALE_KEYSPEC_OBJTAB-ONAME = OBJ_NAME.
      VIM_ALE_KEYSPEC_OBJTAB-OTYPE = OBJ_TYPE.
      APPEND VIM_ALE_KEYSPEC_OBJTAB.
    ENDIF.
  ENDIF.
ENDFORM.                               "vim_check_ale_edit_lock

*---------------------------------------------------------------------*
*       FORM VIM_SAPSCRIPT_FORM_MAINT.                                *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM VIM_SAPSCRIPT_FORM_MAINT.
  LOCAL: STATUS-MODE.
  DATA: VSFM_TABLE LIKE VIMDESC-VIEWNAME, VSFM_FLAG(1) TYPE C,
        VSFM_FIELD LIKE VIMNAMTAB-VIEWFIELD, VSFM_HF TYPE I.

  IF X_HEADER-SCRFRMFLAG EQ SPACE.
    MESSAGE E001(SV).
    EXIT.
  ENDIF.
  IF VIM_NBR_OF_SCRFRM_POINTERS GT 1.
    IF STATUS-MODE EQ DETAIL_BILD. GET CURSOR FIELD F. ENDIF.
    SPLIT F AT '-' INTO VSFM_TABLE VSFM_FIELD.
    IF X_HEADER-BASTAB NE SPACE AND X_HEADER-TEXTTBEXST NE SPACE AND
       VSFM_TABLE EQ X_HEADER-TEXTTAB.
      VSFM_FLAG = 'X'.
    ENDIF.
    READ TABLE X_NAMTAB WITH KEY VIEWFIELD = VSFM_FIELD
                                 TEXTTABFLD = VSFM_FLAG.
    IF X_NAMTAB-DOMNAME NE VIM_SCRFORM_DOMAIN.
      MESSAGE S161(SV). " Bitte stellen Sie den Cursor auf einen Formula
      CLEAR FUNCTION.
      EXIT.
    ENDIF.
*    ASSIGN <TABLE1>+X_NAMTAB-POSITION(X_NAMTAB-FLENGTH)
*                                       TO <VIM_SCRFORM_NAME>.
    ASSIGN component x_namtab-viewfield of structure <TABLE1>
     TO <VIM_SCRFORM_NAME>.
    IF STATUS-MODE EQ LIST_BILD.
      VSFM_HF = FIRSTLINE + L - 1.
      STATUS-MODE = DETAIL_BILD.
    ELSE.
      VSFM_HF = NEXTLINE.
    ENDIF.
    READ TABLE EXTRACT INDEX VSFM_HF.
    PERFORM MOVE_EXTRACT_TO_VIEW_WA.
  ENDIF.
  IF STATUS-MODE EQ LIST_BILD.
    LOOP AT EXTRACT.
      CHECK <XMARK> EQ MARKIERT.
      PERFORM MOVE_EXTRACT_TO_VIEW_WA.
      CALL FUNCTION 'EDIT_FORM'
           EXPORTING
                FORM              = <VIM_SCRFORM_NAME>
*           LANGUAGE          = SY-LANGU
                DISPLAY           = 'X'
*           COMPONENT         = 'HEADER'
           EXCEPTIONS
                UNKNOWN_ACTIVITY  = 1
                UNKNOWN_COMPONENT = 2.
      IF SY-SUBRC NE 0.
        MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO WITH
                SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        CONTINUE.
      ENDIF.
      <XMARK> = NICHT_MARKIERT.
      MODIFY EXTRACT.
      READ TABLE TOTAL WITH KEY <VIM_xEXTRACT_KEY> BINARY SEARCH.
      <MARK> = NICHT_MARKIERT.
      MODIFY TOTAL INDEX SY-TABIX.
      SUBTRACT: 1 FROM MARK_EXTRACT,
                1 FROM MARK_TOTAL.
    ENDLOOP.
  ELSE.                                "detail bild
    CALL FUNCTION 'EDIT_FORM'
         EXPORTING
              FORM              = <VIM_SCRFORM_NAME>
*             LANGUAGE          = SY-LANGU
              DISPLAY           = 'X'
*             COMPONENT         = 'HEADER'
         EXCEPTIONS
              UNKNOWN_ACTIVITY  = 1
              UNKNOWN_COMPONENT = 2.
    IF SY-SUBRC NE 0.
      MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO WITH
              SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      CLEAR FUNCTION. EXIT.
    ENDIF.
    IF <XMARK> EQ MARKIERT.
      <XMARK> = NICHT_MARKIERT.
      MODIFY EXTRACT INDEX NEXTLINE.
      READ TABLE TOTAL WITH KEY <VIM_xEXTRACT_KEY> BINARY SEARCH.
      <MARK> = NICHT_MARKIERT.
      MODIFY TOTAL INDEX SY-TABIX.
      SUBTRACT: 1 FROM MARK_EXTRACT,
                1 FROM MARK_TOTAL.
    ENDIF.
  ENDIF.                               "status-mode eq list_bild
  CLEAR FUNCTION.
ENDFORM.                               "vim_sapscript_form_maint

*---------------------------------------------------------------------*
*       FORM AEND_TO_ANZG                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM aend_to_anzg.
* was not used 'til 4.6C
  IF status-action EQ anzeigen.
    MESSAGE i001(sv).
  ELSE.
    IF NOT vim_oc_inst IS INITIAL.
* new selection because of different authorisation? --> Message
* >>>check whether there's really a difference between upd and show<<<
      MESSAGE s764(sv).
*   Veränderte Auswahl von Datensätzen.
    ENDIF.
*    CLEAR: <status>-mk_xt,
*           <status>-mk_to,
*           block_sw.
*    PERFORM beenden.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM ANZG_TO_AEND                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM anzg_to_aend.
  DATA: rc LIKE sy-subrc, dummy TYPE scpr_id, value(200) TYPE c,
        value_is_external TYPE xfeld, lfieldname TYPE fnam_____4,
        keyvalues TYPE occheckkeyflds, w_keyvalue TYPE occheckkey,
        oc_rangetab TYPE TABLE OF vimsellist, lines TYPE i,
        any_substflds_initial TYPE xfeld, field1 LIKE sy-msgv1,
        field2 LIKE sy-msgv2, field3 LIKE sy-msgv3,
        field4 LIKE sy-msgv4.
  FIELD-SYMBOLS: <w_dba_sel> TYPE vimsellist, <x_namtab> TYPE vimnamtab,
                 <value> TYPE c.

  IF status-action NE anzeigen AND status-action NE transportieren.
    MESSAGE i001(sv).
  ELSE.
    IF status-action EQ anzeigen.
* check authority
      IF x_header-newgener EQ space. "4.5a: support individual auth.chck
        CALL FUNCTION 'VIEW_AUTHORITY_CHECK'
           EXPORTING
                view_action                = aendern
                view_name                  = view_name
                no_warning_for_clientindep = vim_no_warning_for_cliindep
           CHANGING
                org_crit_inst              = vim_oc_inst
           EXCEPTIONS
                no_authority                   = 8
                no_clientindependent_authority = 9
                no_linedependent_authority     = 11.
        rc = sy-subrc.
        IF sy-subrc = 11.
          MOVE: sy-msgid TO vim_auth_msgid,
                sy-msgno TO vim_auth_msgno,
                sy-msgv1 TO vim_auth_msgv1,
                sy-msgv2 TO vim_auth_msgv2,
                sy-msgv3 TO vim_auth_msgv3,
                sy-msgv4 TO vim_auth_msgv4.
        ENDIF.
      ENDIF.
      IF x_header-frm_on_aut NE space.
        vim_auth_action = aendern.
        vim_auth_event = vim_auth_switch_to_update_mode.
        ASSIGN <vim_ck_sellist> TO <vim_auth_sellist>.
        PERFORM (x_header-frm_on_aut) IN PROGRAM.
        IF vim_auth_rc NE 0. rc = 10. ENDIF.
      ENDIF.
    ENDIF.
    CASE rc.
      WHEN 0.
        IF NOT vim_oc_inst IS INITIAL AND vim_called_by_cluster = space.
* check line-dependent authorisation (viewclusters: will be done in
* viewcluster maintenance.)
* 1st: check non-subset-values
          INSERT LINES OF dba_sellist[] INTO TABLE oc_rangetab.
          LOOP AT x_namtab ASSIGNING <x_namtab> WHERE keyflag <> space
           AND readonly = subset.
            DELETE oc_rangetab WHERE viewfield = <x_namtab>-viewfield.
          ENDLOOP.
          IF sy-subrc = 0.
            DESCRIBE TABLE oc_rangetab LINES lines.
            if lines > 0.
              READ TABLE oc_rangetab ASSIGNING <w_dba_sel> INDEX lines.
              CLEAR <w_dba_sel>-and_or.
            endif.
          ENDIF.
          CALL METHOD vim_oc_inst->check_oc_auth_vim_sellist
            EXPORTING
              sellist    = oc_rangetab
              action     = '02'
*          CHANGING
*            KEY_FIELDS =
            EXCEPTIONS
              no_auth    = 1
              OTHERS     = 2.
          IF sy-subrc <> 0.
            MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
            EXIT.
          ENDIF.
          IF x_header-subsetflag <> space.
* 2nd: check subset values
            CALL METHOD vim_oc_inst->build_key_value_tab
              EXPORTING
                entry     = <initial>
              IMPORTING
                keyvalues = keyvalues.
            LOOP AT keyvalues INTO w_keyvalue.
              READ TABLE x_namtab ASSIGNING <x_namtab>
               WITH KEY viewfield = w_keyvalue-keyname.
              CHECK <x_namtab>-readonly <> subset.
              DELETE keyvalues.
            ENDLOOP.
            CALL METHOD vim_oc_inst->check_oc_authority
              EXPORTING
                activity        = '02'
              CHANGING
                key_values      = keyvalues
              EXCEPTIONS
                no_auth         = 1
                key_incomplete  = 2
*              WRONG_PARAMETER = 3
                OTHERS          = 4.
            IF sy-subrc = 1.
              MOVE: sy-msgv1 TO field1, sy-msgv2 TO field2,
                    sy-msgv3 TO field3, sy-msgv4 TO field4.
* no authorisation for current subset values
              MESSAGE i763(sv) WITH field1 field2 field3 field4.
*   Sie haben keine Pflegeberechtigung für die angezeigten Datensätze.
              LOOP AT keyvalues INTO w_keyvalue WHERE noauth <> space.
                READ TABLE dba_sellist ASSIGNING <w_dba_sel>
                 WITH KEY viewfield = w_keyvalue-keyname.
                CLEAR: <w_dba_sel>-value, <w_dba_sel>-initial,
                       <w_dba_sel>-from_auth.                "UF210200
              ENDLOOP.
*              CALL METHOD vim_oc_inst->convert_oc_selections
*                        EXPORTING
*                            activity   = '02'
*                        IMPORTING
*                            oc_vimsell = oc_rangetab.
** if possible: fill subset selection in RANGETAB from authority
** (authority object S_TABU_LIN)
*              PERFORM vim_merge_sellists USING    oc_rangetab
*                                                  x_namtab[]
*                                                  'X'
*                                         CHANGING x_header[]
*                                                  dba_sellist
*                                                  rc.
*              PERFORM check_all_substfields TABLES dba_sellist
*                      CHANGING any_substflds_initial.
*              IF any_substflds_initial <> space.
              CALL FUNCTION 'TABLE_RANGE_INPUT'
                   EXPORTING
                        table             = x_header-viewname
                        oc_inst           = vim_oc_inst
                   TABLES
                        sellist           = dba_sellist
                        x_header          = x_header
                        x_namtab          = x_namtab
                   EXCEPTIONS
                        cancelled_by_user = 1
                        no_input          = 2
                        OTHERS            = 3.
              IF sy-subrc <> 0.
                EXIT.
              ENDIF.
*              refresh vim_dba_sel_kept.            "UF210200
*              ENDIF.
            ENDIF.
          ELSE.
* new selection because of different authorisation? --> Message
* >>>check whether there's really a difference between upd and show<<<
            MESSAGE s764(sv).
*   Veränderte Auswahl von Datensätzen.
          ENDIF.                       "subsets exist
        ENDIF.                         "oc exists
        IF status-action EQ transportieren.
          function = switch_transp_to_upd_mode.
          CLEAR <status>-crcntsknwn.
          IF <status>-corr_enqud NE space.
            CALL FUNCTION 'DEQUEUE_E_TRKORR'
                 EXPORTING
                      trkorr = <status>-corr_nbr.
*             X_TRKORR = E02.
            CLEAR <status>-corr_enqud.
          ENDIF.
          IF x_header-cursetting NE space.
            CLEAR: vim_corr_obj_viewname, <status>-tr_alrchkd.
          ENDIF.
        ELSE.
          CLEAR vim_corr_obj_viewname.
          IF <status>-prof_found = vim_profile_found    "UF profileb
             AND vim_pr_records = 0.
* get records the profile contains
            PERFORM get_pr_nbr_records USING vim_profile_values
                                             x_header
                                       CHANGING rc
                                                dummy
                                                vim_pr_records
                                                vim_pr_tab
                                                vim_pr_fields.
* check key-status
            PERFORM get_profile_status CHANGING vim_pr_tab
                                                vim_pr_fields.
            PERFORM bcset_key_check_in_total.
          ENDIF.                       "UF profileb
        ENDIF.
*       SET SCREEN 0.
*       LEAVE SCREEN.
        vim_next_screen = 0. vim_leave_screen = 'X'.
      WHEN 8.                          "no authority for update
        MESSAGE i051(sv).              "only show allowed
      WHEN 9.
        MESSAGE ID 'TB' TYPE 'I' NUMBER 109.      "no cli-indep auth
      WHEN 10 OR 11.
        MESSAGE ID vim_auth_msgid TYPE 'I' NUMBER vim_auth_msgno
                WITH vim_auth_msgv1 vim_auth_msgv2  vim_auth_msgv3
                     vim_auth_msgv4.
    ENDCASE.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM BEENDEN                                                  *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM beenden.
  DATA: line1(30) TYPE c,
        handle TYPE ad_handle,
        adrnum TYPE ad_addrnum.

  CASE function.
    WHEN 'ANZG'.
      line1 = svim_text_001.
    WHEN 'ATAB'.
      line1 = svim_text_008.
    WHEN 'ENDE'.
      line1 = svim_text_003.
  ENDCASE.
  CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
       EXPORTING
            titel     = line1
            textline1 = svim_text_018  "Daten wurden verändert.
            textline2 = svim_text_019  "Änderungen vorher sichern ?
       IMPORTING
            answer    = answer.
  CASE answer.
    WHEN 'J'.
      sy-subrc = 0.
    WHEN 'N'.
      CLEAR <status>-upd_flag.
      IF maint_mode EQ transportieren.
        <status>-keytbinvld = 'X'.
      ELSEIF maint_mode EQ aendern. "AND x_header-adrnbrflag EQ 'N'.
* reset unsaved addresses                          UF557286/2000b
        LOOP AT vim_addresses_to_save.
          IF vim_addresses_to_save-addrnumber CP '@NEW*'.
            CLEAR adrnum.
            handle = vim_addresses_to_save-handle.
          ELSE.
            CLEAR handle.
            adrnum = vim_addresses_to_save-addrnumber.
          ENDIF.
          CALL FUNCTION 'ADDR_SINGLE_RESET'
               EXPORTING
                    address_number = adrnum
                    address_handle = handle
               EXCEPTIONS
                    OTHERS         = 1.
          IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
        ENDLOOP.
        REFRESH vim_addresses_to_save.
      ENDIF.                                            "UF557286/2000e
      sy-subrc = 8.
    WHEN 'A'.
      sy-subrc = 12.
  ENDCASE.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM LISTE_BACK                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM liste_back.
  IF status-action EQ hinzufuegen.
    status-action = <status>-st_action = aendern.
    title-action  = aendern.
    CLEAR <status>-selected.
    neuer = 'N'.
  ENDIF.
  IF status-delete = geloescht.
    status-delete = <status>-st_delete = nicht_geloescht.
    title-action  = aendern.
    PERFORM markiere_alle USING nicht_markiert.
  ENDIF.
  IF x_header-delmdtflag NE space.
    LOOP AT vim_collapsed_mainkeys.
      IF vim_collapsed_mainkeys-mkey_bf EQ space.
        vim_collapsed_mainkeys-mkey_bf = vim_collapsed_mainkeys-log_key.
        CLEAR vim_collapsed_mainkeys-log_key.
      ENDIF.
      <f1_x> = <vim_h_coll_mkey>.
*      <f1> = vim_collapsed_mainkeys-mainkey.
      <vim_enddate_mask> = space.
      <vim_h_coll_mkey> = <f1_x>.
*      vim_collapsed_mainkeys-mainkey = <f1>.
      MODIFY vim_collapsed_mainkeys.
    ENDLOOP.
    IF vim_delim_expa_excluded NE space.
      DELETE excl_cua_funct WHERE function EQ 'EXPA'.
      CLEAR vim_delim_expa_excluded.
    ENDIF.
    IF status-action = aendern AND title-action = hinzufuegen.
      title-action  = aendern.
    ENDIF.
  ENDIF.
  PERFORM fill_extract.
  nextline = 1.
  mark_extract = mark_total.
  SET SCREEN liste.
  LEAVE SCREEN.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM LISTE_ABBRECHEN                                          *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM LISTE_ABBRECHEN.
* CHECK REPLACE_MODE EQ SPACE.
*(DEL)  IF STATUS-ACTION EQ ANZEIGEN.
*(DEL)    MESSAGE I001(SV).
*(DEL)    EXIT.
*(DEL)  ENDIF.
  IF SY-DATAR NE SPACE.
    CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
         EXPORTING
              TITEL          = SVIM_TEXT_005
              TEXTLINE1      = SVIM_TEXT_009
              TEXTLINE2      = SVIM_TEXT_006
              DEFAULTOPTION  = 'N'
              CANCEL_DISPLAY = ' '
         IMPORTING
              ANSWER         = ANSWER.
    IF ANSWER EQ 'J'.
      NEUER = 'N'.
      IF STATUS-ACTION EQ KOPIEREN.
        SET SCREEN 0.
      ELSE.
        SET SCREEN LISTE.
        NEXTLINE = FIRSTLINE.
      ENDIF.
      CLEAR <STATUS>-UPD_FLAG.
      LEAVE SCREEN.
    ELSE.
      CLEAR FUNCTION.
    ENDIF.
  ELSE.
    IF VIM_SINGLE_ENTRY_FUNCTION NE SPACE.
      TRANSLATE STATUS-ACTION USING 'AU'. STATUS-MODE = GESAMTDATEN.
    ENDIF.
    CASE STATUS-ACTION.
      WHEN HINZUFUEGEN. PERFORM LISTE_BACK.
      WHEN KOPIEREN.    SET SCREEN 0.
      WHEN OTHERS.
        FUNCTION = 'BACK'. SET SCREEN 0. CLEAR VIM_ACT_DYNP_VIEW.
        PERFORM UPDATE_STATUS.
    ENDCASE.
    LEAVE SCREEN.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM IGNORIEREN                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM IGNORIEREN. "wird nur noch auf Detailbild prozessiert
  <STATUS>-UPD_FLAG = SPACE.
  IF STATUS-ACTION EQ KOPIEREN OR VIM_SPECIAL_MODE EQ VIM_DELETE.
    SET SCREEN 0.
    LEAVE SCREEN.
  ENDIF.
* IF MAXLINES LE 1.
*   STATUS-ACTION = AENDERN.
*   TITLE-ACTION  = AENDERN.
*   PERFORM FILL_EXTRACT.
* ELSE.
*   SORT EXTRACT.
* ENDIF.
  NEUER = 'N'.
  IF REPLACE_MODE EQ SPACE.
    CLEAR FUNCTION.
*   IF STATUS-MODE EQ DETAIL_BILD.
*     FUNCTION = 'DETA'.
*     SET SCREEN DETAIL.
    IF STATUS-ACTION EQ HINZUFUEGEN.
      FUNCTION = 'NEWL'.
      PERFORM HINZUFUEGEN.
    ELSE.
      SET SCREEN LISTE.
      LEAVE SCREEN.
    ENDIF.
*   ELSE.
*     NEXTLINE = 1.
*     SET SCREEN LISTE.
*   ENDIF.
  ELSE.
    CLEAR VIM_ACT_DYNP_VIEW. SET SCREEN 0. LEAVE SCREEN.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM BLAETTERN                                                *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM BLAETTERN.
  DATA: B_OVERLAPPING(1) TYPE C VALUE 'X'.
  IF MAXLINES EQ 0.
    EXIT.
  ENDIF.
  IF STATUS-ACTION EQ KOPIEREN OR LOOPLINES EQ 1.
    CLEAR B_OVERLAPPING.
  ENDIF.
  CALL FUNCTION 'SCROLLING_IN_TABLE'
       EXPORTING
            ENTRY_TO       = MAXLINES
            LOOPS          = LOOPLINES
            OK_CODE        = FUNCTION
            ENTRY_ACT      = FIRSTLINE
            LAST_PAGE_FULL = ' '
*           OVERLAPPING    = 'X'
            OVERLAPPING    = B_OVERLAPPING
       IMPORTING
            ENTRY_NEW      = NEXTLINE.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM CHECK_UPD                                                *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM CHECK_UPD.
  data: leave.
  CHECK STATUS-ACTION NE ANZEIGEN.
  IF <STATUS>-UPD_FLAG EQ SPACE.
    IF STATUS-ACTION EQ TRANSPORTIEREN.
      MOVE <STATUS>-KEYTBMODFD TO <STATUS>-UPD_FLAG.
    ELSE.
      LOOP AT TOTAL.
*       CHECK <ACTION> NE NEUER_GELOESCHT AND <ACTION> NE ORIGINAL.
        CHECK <ACTION> NE ORIGINAL.
        MOVE 'X' TO <STATUS>-UPD_FLAG.
        EXIT.
      ENDLOOP.
      IF <STATUS>-UPD_FLAG EQ SPACE AND X_HEADER-BASTAB NE SPACE AND
         X_HEADER-TEXTTBEXST NE SPACE.
        LOOP AT TOTAL.
*         CHECK <ACTION_TEXT> NE NEUER_GELOESCHT AND
          CHECK <ACTION_TEXT> NE ORIGINAL.
          MOVE 'X' TO <STATUS>-UPD_FLAG.
          EXIT.
        ENDLOOP.
      ENDIF.
      IF <STATUS>-UPD_FLAG EQ SPACE AND X_HEADER-TEXTTBEXST <> SPACE.
        PERFORM VIM_CHECK_UPD_TEXTTAB. "SW Texttransl
      ENDIF.
      IF <STATUS>-UPD_FLAG EQ SPACE AND X_HEADER-ADRNBRFLAG EQ 'N'.
        DESCRIBE TABLE VIM_ADDRESSES_TO_SAVE.
        IF SY-TFILL GT 0.
          MOVE 'X' TO <STATUS>-UPD_FLAG.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.
  IF X_HEADER-FRM_AF_CHK NE SPACE AND STATUS-ACTION NE TRANSPORTIEREN.
    PERFORM (X_HEADER-FRM_AF_CHK) IN PROGRAM (SY-REPID).
  ENDIF.
  if <status>-upd_flag = space and vim_called_by_cluster = space and
   ( function = back OR function = end ).
    perform vim_add_img_notices_pai using 'E'
                                    changing leave.
    if leave = space.
      clear function.
    endif.
  endif.
  MOVE 'X' TO <STATUS>-UPD_CHECKD.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM POPUP_POSITIONIEREN                                      *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM popup_positionieren.
  DATA: pp_program LIKE sy-repid, hf1 TYPE i, hf2 TYPE i,
        dummy type xfeld.

  IF status-action NE anzeigen AND status-action NE transportieren
  AND status-mode NE list_bild.
    PERFORM update_tab.
  ENDIF.
  pp_program = sy-repid.
  <table1> = <initial>.
  CALL FUNCTION 'TABLE_GET_KEY_TO_SET_CUR_ROW'
       EXPORTING
            table             = x_header-maintview          "Subviews
            f4_programname    = pp_program
            f4_formname       = 'F4_POSITIONIEREN'
       IMPORTING
            table_key         = dummy
       TABLES
            sellist           = <vim_ck_sellist>
            exclude_fields    = excl_pos_tab
       CHANGING
            table_key_new     = <f1_x>
       EXCEPTIONS
            cancelled_by_user = 01
            table_not_found   = 02.
  CHECK sy-subrc EQ 0000.
  IF x_header-frm_h_flds NE space.
    PERFORM (x_header-frm_h_flds) IN PROGRAM.
  ENDIF.
  IF x_header-frm_rp_pos NE space.
    PERFORM (x_header-frm_rp_pos) IN PROGRAM.
  ELSEIF status-action EQ hinzufuegen AND status-mode EQ list_bild.
    nextline = 0.
    LOOP AT extract.
      IF <xact> EQ leer. EXIT. ENDIF.
*      CHECK <vim_extract_key> LE <f1>.
      CHECK <vim_xextract_key> LE <f1_x>.
      hf1 = sy-tabix.
      CHECK <vim_xextract_key> EQ <f1_x>.
      nextline = sy-tabix. EXIT.
    ENDLOOP.
    IF nextline EQ 0.
      IF hf1 EQ maxlines.
        nextline = hf1.
      ELSE.
        nextline = hf1 + 1.
      ENDIF.
    ENDIF.
  ELSE.
*    READ TABLE extract WITH KEY <f1> BINARY SEARCH
*                                     TRANSPORTING NO FIELDS.
    READ TABLE extract WITH KEY <f1_x> BINARY SEARCH
                                       TRANSPORTING NO FIELDS.
    nextline = sy-tabix.
    IF sy-subrc = 8 AND nextline GT 1.
      nextline = nextline - 1.                              "last entry
    ENDIF.
  ENDIF.
  IF status-mode EQ detail_bild.
    READ TABLE extract INDEX nextline.                      "ufdetailb
    IF <xmark> <> markiert.
      CLEAR <status>-mark_only.
    ENDIF.                                                  "ufdetaile
    hf2 = firstline + looplines - 1.
    IF looplines EQ 0.
      l = 1. MOVE: l TO <status>-cur_line,
                   nextline TO <status>-firstline.
      hf1 = 0.
    ELSEIF nextline GE firstline AND nextline LE hf2.
* nothing to scroll.
    ELSEIF nextline LT firstline.                  "xb2002 int405493/99
*if the nextline less than firstline, move the nextline to firstline.
      firstline = nextline.
    ELSE.                                           "xb2002 int405493/99
* if the nextline larger than firstline, move the nextline to firstline.
       firstline = nextline.
    ENDIF.
    l = nextline - firstline + 1.
    MOVE: firstline TO <status>-firstline,
          l         TO <status>-cur_line.
  ELSE.
    MOVE 1 TO l.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM F4_POSITIONIEREN                                         *
*---------------------------------------------------------------------*
*       called externally from POPUP_GET_VALUES_USER_HELP             *
*---------------------------------------------------------------------*
FORM f4_positionieren USING value(tabname) TYPE tabname
                            value(fieldname) TYPE fieldname
                            value(display)
                      CHANGING returncode
                               value TYPE any.
  STATICS: field_tab TYPE TABLE OF dfies INITIAL SIZE 20.

  DATA: tabval(132) TYPE c,
        v_tab LIKE TABLE OF tabval INITIAL SIZE 500,
        w_dfies TYPE dfies,
        return_tab TYPE TABLE OF ddshretval INITIAL SIZE 1,
        BEGIN OF out_conv_function,
         prefix(16) TYPE c VALUE 'CONVERSION_EXIT_',
         exit LIKE vimnamtab-convexit,
         suffix(7) TYPE c VALUE '_OUTPUT',
        END OF out_conv_function,
        f4_length TYPE i.    "total length of to be displayed fields
  FIELD-SYMBOLS: <hf1>, <dfies> TYPE dfies, <retval> TYPE ddshretval.

  READ TABLE field_tab INDEX 1 ASSIGNING <dfies>.
  IF sy-subrc <> 0 OR <dfies>-tabname <> x_header-maintview.
    REFRESH field_tab.

* xb  06.02 csn ext.237151 2002, BCEK061005 ---------begin----------
* check the total display length of F4-List
    f4_length = 0.
    IF x_header-tablen > 1000.
      LOOP AT x_namtab.
        IF x_header-clidep NE space.       "ignore client field
          CHECK sy-tabix NE 1.
        ENDIF.
        IF x_namtab-keyflag NE space OR    "all key fields or
           x_namtab-datatype EQ 'CHAR' AND "all possibly text fields
           x_namtab-flength  GE 10     AND
           x_namtab-lowercase  NE space.

          f4_length = f4_length + x_namtab-outputlen.
        ENDIF.
      ENDLOOP.
    ENDIF.

    IF f4_length < 1000.          "check the fields length
* xb  06.02 csn ext.237151 2002, BCEK061005 ----------end-----------
    LOOP AT x_namtab.
      IF x_header-clidep NE space.       "ignore client field
        CHECK sy-tabix NE 1.
      ENDIF.
      CHECK x_namtab-readonly <> vim_hidden.                  "Subviews
      IF x_header-bastab NE space AND x_header-texttbexst NE space.
        CHECK x_namtab-keyflag NE space AND   "all entity keyfields
              x_namtab-texttabfld EQ space OR                 "or
            x_namtab-keyflag EQ space AND   "all texttab function fields
              x_namtab-texttabfld NE space.
      ELSE.
        CHECK x_namtab-keyflag NE space OR    "all key fields or
              x_namtab-datatype EQ 'CHAR' AND "all possibly text fields
              x_namtab-flength  GE 10     AND
              x_namtab-lowercase  NE space.
        ENDIF.
        IF x_namtab-texttabfld NE space.
          w_dfies-tabname = x_header-texttab.
        ELSE.
          w_dfies-tabname = x_header-maintview.              "Subviews
        ENDIF.
        w_dfies-fieldname = x_namtab-viewfield.
        APPEND w_dfies TO field_tab.
      ENDLOOP.
    ELSE.
* xb  06.02 csn ext.237151 2002, BCEK061005 ---------begin----------
      MESSAGE I810(SV) WITH x_header-viewname.
*   Die gesamte Länge der View & ist mehr als 1000 Charakter. Nur Key
*   Field wird gezeigt.
      LOOP AT x_namtab.
        IF x_header-clidep NE space.       "ignore client field
          CHECK sy-tabix NE 1.
        ENDIF.
       CHECK x_namtab-readonly <> vim_hidden.                  "Subviews
        IF x_header-bastab NE space AND x_header-texttbexst NE space.
          CHECK x_namtab-keyflag NE space AND   "all entity keyfields
                x_namtab-texttabfld EQ space OR                 "or
            x_namtab-keyflag EQ space AND   "all texttab function fields
                x_namtab-texttabfld NE space.
        ELSE.
          CHECK x_namtab-keyflag NE space.    "all key fields
      ENDIF.
      IF x_namtab-texttabfld NE space.
        w_dfies-tabname = x_header-texttab.
      ELSE.
        w_dfies-tabname = x_header-maintview.                  "Subviews
      ENDIF.
      w_dfies-fieldname = x_namtab-viewfield.
      append w_dfies to field_tab.
    ENDLOOP.
* xb  06.02 csn ext.237151 2002, BCEK061005 ----------end-----------
    ENDIF.
  ENDIF.


  LOOP AT extract.
    LOOP AT field_tab ASSIGNING <dfies>.
      READ TABLE x_namtab WITH KEY viewfield = <dfies>-fieldname.
      IF x_header-bastab NE space AND x_header-texttbexst NE space.
        IF x_namtab-keyflag EQ space AND x_namtab-texttabfld NE space.
* Type S: text field
          ASSIGN COMPONENT x_namtab-viewfield
           OF STRUCTURE <vim_ext_txt_struc> TO <hf1>.
        ELSEIF x_namtab-keyflag NE space
         AND x_namtab-texttabfld EQ space.
* Type S: key field
          ASSIGN COMPONENT x_namtab-viewfield
           OF STRUCTURE <vim_extract_struc> TO <hf1>.
        ENDIF.
      ELSE.
* viewfield
        ASSIGN COMPONENT x_namtab-viewfield
         OF STRUCTURE <vim_extract_struc> TO <hf1>.
      ENDIF.
      CHECK <hf1> IS ASSIGNED.
*        IF X_HEADER-BASTAB NE SPACE AND X_HEADER-TEXTTBEXST NE SPACE.
*          CHECK X_NAMTAB-KEYFLAG NE SPACE AND   "all entity keyfields
*                X_NAMTAB-TEXTTABFLD EQ SPACE OR             "or
*                X_NAMTAB-KEYFLAG EQ SPACE AND   "all texttab function
*                X_NAMTAB-TEXTTABFLD NE SPACE.
*        ENDIF.
*        ASSIGN EXTRACT+X_NAMTAB-POSITION(X_NAMTAB-FLENGTH) TO <HF1>
*               TYPE 'C'.
      WRITE <hf1> TO tabval(x_namtab-outputlen).
      APPEND tabval TO v_tab.
      CLEAR tabval.
    ENDLOOP.
  ENDLOOP.
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
*     DDIC_STRUCTURE         = ' '
      retfield               = fieldname
*     PVALKEY                = ' '
*     DYNPPROG               = ' '
*     DYNPNR                 = ' '
*     DYNPROFIELD            = ' '
*     STEPL                  = 0
*     WINDOW_TITLE           =
*     VALUE                  = ' '
*     VALUE_ORG              = 'C'
*     MULTIPLE_CHOICE        = ' '
      display                = display
*     CALLBACK_PROGRAM       = ' '
*     CALLBACK_FORM          = ' '
*     MARK_TAB               =
    TABLES
      value_tab              = v_tab
      field_tab              = field_tab
      return_tab             = return_tab
*     DYNPFLD_MAPPING        =
    EXCEPTIONS
      parameter_error        = 1
      no_values_found        = 2
      OTHERS                 = 3.
  IF sy-subrc = 0.
    READ TABLE return_tab INDEX 1 ASSIGNING <retval>.
    IF sy-subrc = 0.
      value = <retval>-fieldval.
    ENDIF.
  ELSE.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

ENDFORM.                               "f4_positionieren

*---------------------------------------------------------------------*
*       FORM LISTE_MARKIERE                                           *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM LISTE_MARKIERE.
  INDEX = FIRSTLINE + L - 1.
  IF L EQ 0 OR INDEX GT MAXLINES.
    MESSAGE S032(SV).
    EXIT.
  ENDIF.
  PERFORM MARKIERE USING INDEX.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM MARKIERE_BLOCK                                           *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM MARKIERE_BLOCK.
  INDEX = FIRSTLINE + L - 1.
  IF L EQ 0 OR INDEX GT MAXLINES.
    MESSAGE S032(SV).
    EXIT.
  ENDIF.
  PERFORM MARKIERE USING INDEX.
  IF BLOCK_SW EQ MARKIERT.
    BLOCK_2 = INDEX.
    BLOCK_SW = NICHT_MARKIERT.
  ELSE.
    BLOCK_1 = INDEX.
    BLOCK_SW = MARKIERT.
    MESSAGE S066(SV).                  "Bitte Blockende markieren
    EXIT.
  ENDIF.
  COUNTER = 0.
  LOOP AT EXTRACT.
    COUNTER = COUNTER + 1.
    IF BLOCK_1 LE BLOCK_2.
      CHECK COUNTER BETWEEN BLOCK_1 AND BLOCK_2.
    ELSE.
      CHECK COUNTER BETWEEN BLOCK_2 AND BLOCK_1.
    ENDIF.
    READ TABLE TOTAL WITH KEY <VIM_xEXTRACT_KEY> BINARY SEARCH.
    IF <XMARK> NE MARKIERT.
      MARK_EXTRACT = MARK_EXTRACT + 1.
      MARK_TOTAL  = MARK_TOTAL  + 1.
    ENDIF.
    <XMARK> = MARKIERT.
    <MARK>  = MARKIERT.
    MODIFY TOTAL INDEX SY-TABIX.
    MODIFY EXTRACT.
  ENDLOOP.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM MARKIERE                                                 *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  I                                                             *
*---------------------------------------------------------------------*
FORM MARKIERE USING I.
  READ TABLE EXTRACT INDEX I.
  READ TABLE TOTAL WITH KEY <VIM_xEXTRACT_KEY> BINARY SEARCH.
  IF <XMARK> EQ MARKIERT.
    <XMARK> = NICHT_MARKIERT.
    <MARK>  = NICHT_MARKIERT.
    MARK_EXTRACT = MARK_EXTRACT - 1.
    MARK_TOTAL  = MARK_TOTAL  - 1.
  ELSE.
    <XMARK> = MARKIERT.
    <MARK>  = MARKIERT.
    MARK_EXTRACT = MARK_EXTRACT + 1.
    MARK_TOTAL  = MARK_TOTAL  + 1.
  ENDIF.
  MODIFY TOTAL INDEX SY-TABIX.
  MODIFY EXTRACT INDEX I.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM MARKIERE_ALLE                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  ACTION                                                        *
*---------------------------------------------------------------------*
FORM MARKIERE_ALLE USING ACTION.
  CHECK MAXLINES NE 0.
  LOOP AT EXTRACT.
    CHECK <XACT> NE LEER.
    CHECK <XMARK> NE ACTION.
    READ TABLE TOTAL WITH KEY <VIM_xEXTRACT_KEY> BINARY SEARCH.
    <XMARK> = ACTION.
    <MARK>  = ACTION.
    MODIFY TOTAL INDEX SY-TABIX.
    MODIFY EXTRACT.
    IF ACTION EQ MARKIERT.
      ADD: 1 TO MARK_EXTRACT,
           1 TO MARK_TOTAL.
    ELSE.
      SUBTRACT: 1 FROM MARK_EXTRACT,
                1 FROM MARK_TOTAL.
      CLEAR BLOCK_SW.
    ENDIF.
  ENDLOOP.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM LISTE_ZURUECKHOLEN                                       *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM LISTE_ZURUECKHOLEN.
  DATA: IX TYPE I.
* IF STATUS-ACTION NE AENDERN OR STATUS-DELETE NE GELOESCHT.
*   MESSAGE I001(SV).
*   EXIT.
* ENDIF.
  COUNTER = 0.
  LOOP AT EXTRACT.
    CHECK <XMARK> EQ MARKIERT.
    IF X_HEADER-DELMDTFLAG NE SPACE.
      IX = SY-TABIX.
      PERFORM MOVE_EXTRACT_TO_VIEW_WA.
      PERFORM TEMPORAL_DELIMITATION.
    ENDIF.
    COUNTER = COUNTER + 1.
    READ TABLE TOTAL WITH KEY <VIM_xEXTRACT_KEY> BINARY SEARCH.
    PERFORM LOGICAL_UNDELETE_TOTAL USING SY-TABIX.
    MARK_TOTAL  = MARK_TOTAL - 1.
    MARK_EXTRACT = MARK_EXTRACT - 1.
    IF REPLACE_MODE NE SPACE AND VIM_EXTERNAL_MODE EQ SPACE.
      <XACT> = <ACTION>. <XMARK> = NICHT_MARKIERT.
      MODIFY EXTRACT.                  "no deletion in upgrade mode
    ELSE.
      IF TEMPORAL_DELIMITATION_HAPPENED NE SPACE.
        CLEAR VIM_DELIM_ENTRIES.
        VIM_DELIM_ENTRIES-INDEX3 = IX.
        APPEND VIM_DELIM_ENTRIES.
      ELSE.
        DELETE EXTRACT.
      ENDIF.
    ENDIF.
  ENDLOOP.
  IF TEMPORAL_DELIMITATION_HAPPENED NE SPACE.
    PERFORM AFTER_TEMPORAL_DELIMITATION.
    CLEAR TEMPORAL_DELIMITATION_HAPPENED.
  ENDIF.
  CHECK REPLACE_MODE EQ SPACE.
  DESCRIBE TABLE EXTRACT LINES MAXLINES.
  IF IGNORED_ENTRIES_EXIST EQ SPACE.
    MESSAGE S002(SV) WITH COUNTER.
  ELSE.
    MESSAGE W002(SV) WITH COUNTER.
  ENDIF.
  IF MAXLINES EQ 0.
    TITLE-ACTION = AENDERN.
    STATUS-DELETE = NICHT_GELOESCHT.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM LOGICAL_UNDELETE_TOTAL                                    *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM logical_undelete_total USING value(cur_index) TYPE i.
  CASE <action>.
    WHEN neuer_geloescht.
      <action> = neuer_eintrag.
    WHEN geloescht.
      <action> = original.
    WHEN update_geloescht.
      <action> = aendern.
  ENDCASE.
*  perform vim_bc_logs_maintain using zurueckholen
*                                           x_header
*                                     changing vim_bc_entry_list.
  IF x_header-bastab NE space AND x_header-texttbexst NE space.
    CASE <action_text>.
      WHEN neuer_geloescht.
        <action_text>         = neuer_eintrag.
      WHEN geloescht.
        <action_text>         = original.
      WHEN update_geloescht.
        <action_text>         = aendern.
      WHEN dummy_geloescht.
        <action_text>         = original.
        <vim_xtotal_text> = <text_initial_x>.
*        <TOTAL_TEXT> = <TEXT_INITIAL>.
    ENDCASE.
  ENDIF.
  <mark> = nicht_markiert.
  MODIFY total INDEX cur_index.
ENDFORM.                               "logical_undelete_total

*---------------------------------------------------------------------*
*       FORM SELEKTIERE                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  PARAM                                                         *
*---------------------------------------------------------------------*
FORM selektiere USING param.
  DATA: rec LIKE sy-subrc VALUE 9, s_screenmode(1) TYPE c VALUE 'S'.
  IF status-action EQ hinzufuegen.
    status-action = aendern.
    title-action = aendern.
  ENDIF.
  IF status-mode EQ detail_bild.
    PERFORM update_tab.
  ENDIF.
  REFRESH extract. CLEAR vim_mainkey. l = 1.
  TRANSLATE vim_no_mainkey_exists USING vim_no_mkey_not_procsd_patt.
  LOOP AT total.
    PERFORM select USING param.
    CHECK sy-subrc EQ 0.
    IF x_header-delmdtflag NE space.
      PERFORM check_and_modify_mainkey_tab USING rec.
      IF rec NE 0.
        vim_coll_mainkeys_beg_ix = vim_last_coll_mainkeys_ix.
      ENDIF.
      CHECK rec LT 8.
      IF rec EQ 4. rec = 9. ENDIF.
    ENDIF.
    extract = total.
    APPEND extract.
  ENDLOOP.
  vim_coll_mainkeys_beg_ix = 1.
  IF rec NE 9 AND rec NE 0.
    PERFORM mod_extract_and_mainkey_tab USING 'A' 0.
  ENDIF.
  IF param EQ geloescht.
    status-delete = geloescht.
    title-action  = geloescht.
  ENDIF.
  <status>-selected = param.
  DESCRIBE TABLE extract LINES maxlines.
  status-data   = auswahldaten.
  title-data    = auswahldaten.
  nextline = 1.
  IF maxlines EQ 0.
    status-delete = nicht_geloescht.
    title-action  = nicht_geloescht.
    PERFORM fill_extract.
    PERFORM set_pf_status USING status.
    MESSAGE i004(sv).
    SET SCREEN liste.
    LEAVE SCREEN.
  ENDIF.
  IF maxlines EQ 1.
    MESSAGE s005(sv).
    IF vim_single_entry_function NE space.
      IF status-type EQ zweistufig.
        <status>-firstline = <status>-cur_line = nextline.
        PERFORM process_detail_screen USING 'C'.
      ELSE.
        CALL SCREEN liste.
      ENDIF.
    ELSE.
      IF status-type EQ zweistufig.
        <status>-firstline = <status>-cur_line = nextline.
        PERFORM process_detail_screen USING 'S'.
      ENDIF.
    ENDIF.
  ELSE.
    IF status-mode EQ detail_bild.
      vim_next_screen = liste. vim_leave_screen = 'X'.
    ENDIF.
    MESSAGE s006(sv) WITH maxlines.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM NORMAL_SELECT                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
* <--- sy-subrc                                                       *
*---------------------------------------------------------------------*
FORM normal_select.
  FIELD-SYMBOLS: <ns_tab> TYPE table, <vim_tot_txt_struc_loc> TYPE ANY.
  sy-subrc = 8.
  CHECK <action> NE neuer_geloescht
    AND <action> NE update_geloescht
    AND <action> NE geloescht.
  CLEAR sy-subrc.
  IF x_header-selection NE space.
    IF vim_special_adjust_mode NE space.
      ASSIGN dba_sellist[] TO <ns_tab>.
    ELSE.
      ASSIGN dpl_sellist[] TO <ns_tab>.
    ENDIF.
    IF x_header-bastab <> space AND x_header-texttbexst <> space.
      ASSIGN <vim_tot_txt_struc> TO <vim_tot_txt_struc_loc>.
    ELSE.
      ASSIGN <vim_total_struc> TO <vim_tot_txt_struc_loc>.
    ENDIF.
    CALL FUNCTION 'TABLE_RANGE_CHECK'
      EXPORTING
        tabname                   = x_header-maintview
        entry                     = total
        entry_text                = <vim_tot_txt_struc_loc>
        ddic                      = 'N'
        key                       = 'N'
        ignore_blank_subsetfields = 'N'
      TABLES
        x_namtab                  = x_namtab
        x_header                  = x_header
        sellist                   = <ns_tab>
      EXCEPTIONS
        entry_not_fits            = 1
        no_value_for_subset_ident = 2.
    IF sy-subrc EQ 2.
      RAISE no_value_for_subset_ident.
    ENDIF.
  ENDIF.
ENDFORM.                    "NORMAL_SELECT

*---------------------------------------------------------------------*
*       FORM SELECT                                                   *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  PARAM                                                         *
*  <--  SY-SUBRC                                                      *
*---------------------------------------------------------------------*
FORM select USING param.
  FIELD-SYMBOLS: <vim_tot_txt_struc_loc> TYPE ANY.

  sy-subrc = 8.
  IF param EQ space AND status-action NE transportieren.
    "normal selection (not deleted entries)
    PERFORM normal_select.
  ELSE.
    CASE param.
      WHEN geloescht.
        CHECK <action>         EQ geloescht
        OR    <action>         EQ neuer_geloescht
        OR    <action>         EQ update_geloescht.
        CLEAR sy-subrc.
        IF x_header-selection NE space.
          IF x_header-bastab <> space AND x_header-texttbexst <> space.
            ASSIGN <vim_tot_txt_struc> TO <vim_tot_txt_struc_loc>.
          ELSE.
            ASSIGN <vim_total_struc> TO <vim_tot_txt_struc_loc>.
          ENDIF.
          CALL FUNCTION 'TABLE_RANGE_CHECK'
            EXPORTING
              tabname                   = x_header-maintview
              entry                     = total
              entry_text                = <vim_tot_txt_struc_loc>
              ddic                      = 'N'
              key                       = 'N'
              ignore_blank_subsetfields = 'N'
            TABLES
              x_namtab                  = x_namtab
              x_header                  = x_header
              sellist                   = dpl_sellist
            EXCEPTIONS
              entry_not_fits            = 1
              no_value_for_subset_ident = 2.
          IF sy-subrc EQ 2.
            RAISE no_value_for_subset_ident.
          ENDIF.
        ENDIF.
      WHEN markiert.
        IF status-delete EQ geloescht.
          CHECK <action> EQ geloescht OR <action> EQ neuer_geloescht OR
                <action> EQ update_geloescht.
        ENDIF.
        CHECK <mark>   EQ param.
        CLEAR sy-subrc.
        IF x_header-selection NE space.
          IF x_header-bastab <> space AND x_header-texttbexst <> space.
            ASSIGN <vim_tot_txt_struc> TO <vim_tot_txt_struc_loc>.
          ELSE.
            ASSIGN <vim_total_struc> TO <vim_tot_txt_struc_loc>.
          ENDIF.

          CALL FUNCTION 'TABLE_RANGE_CHECK'
            EXPORTING
              tabname                   = x_header-maintview
              entry                     = total
              entry_text                = <vim_tot_txt_struc_loc>
              ddic                      = 'N'
              key                       = 'N'
              ignore_blank_subsetfields = 'N'
            TABLES
              x_namtab                  = x_namtab
              x_header                  = x_header
              sellist                   = dpl_sellist
            EXCEPTIONS
              entry_not_fits            = 1
              no_value_for_subset_ident = 2.
          IF sy-subrc EQ 2.
            RAISE no_value_for_subset_ident.
          ENDIF.
        ENDIF.
      WHEN bcset_only.               "HCG Display only data from BC-Set
        READ TABLE vim_bc_entry_list INTO vim_bc_entry_list_wa
                   WITH TABLE KEY viewname = x_header-viewname
                                  keys = <vim_xtotal_key>.
        IF sy-subrc NE 0. sy-subrc = 8. ENDIF.
        CHECK sy-subrc EQ 0.
        IF x_header-selection NE space.
          IF x_header-bastab <> space AND x_header-texttbexst <> space.
            ASSIGN <vim_tot_txt_struc> TO <vim_tot_txt_struc_loc>.
          ELSE.
            ASSIGN <vim_total_struc> TO <vim_tot_txt_struc_loc>.
          ENDIF.
          CALL FUNCTION 'TABLE_RANGE_CHECK'
            EXPORTING
              tabname                   = x_header-maintview
              entry                     = total
              entry_text                = <vim_tot_txt_struc_loc>
              ddic                      = 'N'
              key                       = 'N'
              ignore_blank_subsetfields = 'N'
            TABLES
              x_namtab                  = x_namtab
              x_header                  = x_header
              sellist                   = dpl_sellist
            EXCEPTIONS
              entry_not_fits            = 1
              no_value_for_subset_ident = 2.
          IF sy-subrc EQ 2.
            RAISE no_value_for_subset_ident.
          ENDIF.
        ENDIF.
      WHEN by_field_contents.
        PERFORM normal_select.
        CHECK sy-subrc EQ 0.
        IF x_header-bastab NE space AND x_header-texttbexst NE space.
* table with texttable
          CALL FUNCTION 'QUERY_CHECK'
            EXPORTING
              record            = <vim_total_struc>
              textrecord        = <vim_tot_txt_struc>
            EXCEPTIONS
              no_hits_in_record = 4
              parameter_error   = 8.
        ELSE.
* view or single table
          CALL FUNCTION 'QUERY_CHECK'
               EXPORTING
                    record            = <vim_total_struc>
*                  record            = total
               EXCEPTIONS
                    no_hits_in_record = 4
                    parameter_error   = 8.
        ENDIF.
      WHEN OTHERS.                     "neuer_eintrag or aendern
       IF x_header-bastab NE space AND x_header-texttbexst NE space AND
                  param EQ aendern.
          CHECK <action> EQ param OR <action_text> EQ param OR
                <action> NE neuer_eintrag AND
                <action_text> EQ neuer_eintrag.
        ELSE.
          CHECK <action> EQ param.
        ENDIF.
        CLEAR sy-subrc.
        IF x_header-selection NE space.
          IF x_header-bastab <> space AND x_header-texttbexst <> space.
            ASSIGN <vim_tot_txt_struc> TO <vim_tot_txt_struc_loc>.
          ELSE.
            ASSIGN <vim_total_struc> TO <vim_tot_txt_struc_loc>.
          ENDIF.

          CALL FUNCTION 'TABLE_RANGE_CHECK'
            EXPORTING
              tabname                   = x_header-maintview
              entry                     = total
              entry_text                = <vim_tot_txt_struc_loc>
              ddic                      = 'N'
              key                       = 'N'
              ignore_blank_subsetfields = 'N'
            TABLES
              x_namtab                  = x_namtab
              x_header                  = x_header
              sellist                   = dpl_sellist
            EXCEPTIONS
              entry_not_fits            = 1
              no_value_for_subset_ident = 2.
          IF sy-subrc EQ 2.
            RAISE no_value_for_subset_ident.
          ENDIF.
        ENDIF.
    ENDCASE.
  ENDIF."param eq space and status-action ne transportieren
ENDFORM.                    "select

*---------------------------------------------------------------------*
*       FORM FILL_EXTRACT                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM fill_extract.
 DATA: rec LIKE sy-subrc VALUE 9, total_safe(4096) TYPE c, indei TYPE i,
                   hf TYPE i VALUE 1.
  FIELD-SYMBOLS: <begdate_mask>.
  REFRESH: extract. CLEAR extract.
  CLEAR vim_mainkey.
  TRANSLATE vim_no_mainkey_exists USING vim_no_mkey_not_procsd_patt.
  IF x_header-delmdtflag NE space.
    ASSIGN <vim_new_begdate> TO <begdate_mask> TYPE 'C'.
  ENDIF.
  LOOP AT total.
    PERFORM normal_select.
    CHECK sy-subrc EQ 0.
    IF x_header-delmdtflag NE space AND
       vim_ignore_collapsed_mainkeys EQ space.
      PERFORM check_and_modify_mainkey_tab USING rec.
      IF rec NE 0.
        vim_coll_mainkeys_beg_ix = vim_last_coll_mainkeys_ix.
      ENDIF.
      CHECK rec LT 8.
      IF rec EQ 4. rec = 9. ENDIF.
    ENDIF.
    extract = total.
    APPEND extract.
  ENDLOOP.
  vim_coll_mainkeys_beg_ix = 1.
  IF rec NE 9 AND rec NE 0.
    PERFORM mod_extract_and_mainkey_tab USING 'A' 0.
  ENDIF.
  DESCRIBE TABLE extract LINES maxlines.
  mark_extract = mark_total.
  status-data = gesamtdaten.
  title-data  = gesamtdaten.
  CLEAR <status>-selected.
* <STATUS>-DISPL_MODE = EXPANDED. "default display mode
  IF maxlines EQ 0.
    PERFORM vim_send_sv005_or_sv766 USING '766'
                                          'RESET'.
    IF function NE 'DELE' AND function NE 'SAVE'.           "HWR
      IF x_header-selection EQ space AND fill_extr_first_proc EQ space.
        IF NOT vim_oc_inst IS INITIAL
* data access restricted?
          AND ( ( <status>-st_action = aendern
                AND NOT vim_oc_inst->oc_selcrit_maint_tab IS INITIAL )
          OR ( 'ST' CS <status>-st_action
                AND NOT vim_oc_inst->oc_selcrit_read_tab IS INITIAL ) ).
          MESSAGE s766(sv).
*   Eingeschränkte Anzeige von Datensätzen.
        ELSE.
          MESSAGE s065(sv).            "keine Einträge vorhanden
        ENDIF.
        MOVE 'X' TO fill_extr_first_proc.
      ELSE.
        MESSAGE s004(sv). "keine Einträge gemäß Selektion gefunden
      ENDIF.
    ENDIF.                                                  "HWR
    EXIT.
  ELSEIF maxlines EQ 1.
    PERFORM vim_maintain_single_set.    "UFint2329966/2000
  ELSEIF NOT vim_oc_inst IS INITIAL AND
   function NE 'DELE' AND function NE 'SAVE'.
* data access restricted?
    IF ( <status>-st_action = aendern
         AND NOT vim_oc_inst->oc_selcrit_maint_tab IS INITIAL )
     OR ( 'ST' CS <status>-st_action
          AND NOT vim_oc_inst->oc_selcrit_read_tab IS INITIAL ).
      PERFORM vim_send_sv005_or_sv766 USING '766'
                                          'SENDIT'.
*   Eingeschränkte Anzeige von Datensätzen.
    ENDIF.
  ELSE.
    PERFORM vim_send_sv005_or_sv766 USING '766'
                                          'RESET'.
  ENDIF.
ENDFORM.                    "fill_extract

*---------------------------------------------------------------------*
*       FORM MOD_EXTRACT_AND_MAINKEY_TAB                              *
*---------------------------------------------------------------------*
*       Modify EXTRACT and mainkey table                              *
*---------------------------------------------------------------------*
FORM mod_extract_and_mainkey_tab USING value(meamt_mode) TYPE c
                                       value(meamt_index) TYPE i.
  CASE meamt_mode.
    WHEN 'A'.
      APPEND extract.
    WHEN 'I'.
      IF meamt_index EQ 0.
        INSERT extract.                                 "#EC *
      ELSE.
        INSERT extract INDEX meamt_index.
      ENDIF.
    WHEN 'M'.
      IF meamt_index EQ 0.
        MODIFY extract.                                 "#EC *
      ELSE.
        MODIFY extract INDEX meamt_index.
      ENDIF.
  ENDCASE.
  LOOP AT vim_collapsed_mainkeys.
    CHECK <vim_collapsed_mkey_bfx> EQ <vim_mkey_beforex>
     AND <vim_collapsed_keyx> NE <vim_xextract_key>.
*  LOOP AT vim_collapsed_mainkeys WHERE mkey_bf EQ <vim_mkey_before>
*                                   AND mainkey NE <vim_extract_key>.
    IF vim_mkey_after_exists NE space.
      CHECK <vim_collapsed_key_afx> EQ <vim_mkey_afterx>.
*      CHECK <vim_collapsed_key_af> EQ <vim_mkey_after>.
    ENDIF.
    <vim_collapsed_keyx> = <vim_xextract_key>.
*    vim_collapsed_mainkeys-mainkey = <vim_extract_key>.
* changed XB. 12.06.02  BCEK060520/BCEK060521 -------begin----------
    if <vim_collapsed_mkey_bfx> NE <vim_ext_mkey_beforex>.
      <vim_collapsed_mkey_bfx> = <vim_ext_mkey_beforex>.
*    vim_collapsed_mainkeys-mkey_bf = <vim_ext_mkey_before>.
    endif.
* changed XB. 12.06.02  BCEK060520/BCEK060521 ---------end-----------
    MODIFY vim_collapsed_mainkeys.
  ENDLOOP.
ENDFORM.                               "mod_extract_and_mainkey_tab.

*---------------------------------------------------------------------*
*       FORM CHECK_AND_MODIFY_MAINKEY_TAB                             *
*---------------------------------------------------------------------*
* ...............                                                     *
*---------------------------------------------------------------------*
FORM check_and_modify_mainkey_tab USING cammt_rec.
  CHECK vim_ignore_collapsed_mainkeys EQ space.
  IF vim_no_mainkey_exists EQ vim_no_mkey_not_procsd OR
     <vim_tot_mkey_beforex> NE <vim_mkey_beforex> OR
     ( vim_mkey_after_exists NE space AND
       <vim_tot_mkey_afterx> NE <vim_mkey_afterx> ).
*     <vim_tot_mkey_before> NE <vim_mkey_before> OR
*     ( vim_mkey_after_exists NE space AND
*       <vim_tot_mkey_after> NE <vim_mkey_after> ).
    IF cammt_rec NE 9 AND cammt_rec NE 0.
      PERFORM mod_extract_and_mainkey_tab USING 'A' 0.
      CLEAR cammt_rec.
    ENDIF.
    <vim_h_mkey>(x_header-keylen) = <vim_xtotal_key>.
*    vim_mainkey = <vim_total_key>.
    extract = total. "this statement is necessary, do not delete it !!
    TRANSLATE vim_no_mainkey_exists USING vim_no_mkey_procsd_patt.
  ELSE.
    CHECK cammt_rec NE 9 AND cammt_rec NE 0.
  ENDIF.
  PERFORM check_if_entry_is_to_display USING space <vim_xtotal_key>
                                             'X' <vim_begdate>.
  cammt_rec = sy-subrc.
ENDFORM.                               "modify_mainkey_tab

*  INCLUDE LSVIMF34 .  " CHECK_IF_ENTRY_IS_TO_BE_MERGED

*---------------------------------------------------------------------*
*       FORM CHECK_IF_ENTRY_IS_TO_DISPLAY                             *
*---------------------------------------------------------------------*
* <--- SY_SUBRC - 0: display entry, expanded mode or new entry        *
*               - 4: display entry, collapsed mode and actual entry   *
*               - 8: don't display entry, collapsed mode              *
*---------------------------------------------------------------------*
FORM check_if_entry_is_to_display USING value(key_local) TYPE char01
                                        value(key_in)    TYPE any
                                        value(mod_flag)  TYPE char01
                                        value(begdate)   TYPE d.
  DATA: rec TYPE i, act_entry_flag(1) TYPE c.
  LOCAL: total, extract.
  FIELD-SYMBOLS: <key_x> TYPE x, <key_h> TYPE x.


  CLEAR: <table1_wa>.
  <f1_wax> = <f1_x>.
  ASSIGN: key_in TO <key_h> CASTING,
          <key_h>(x_header-keylen) TO <key_x>.
  MOVE <key_x> TO <f1_x>.
  IF mod_flag NE space AND
     x_header-delmdtflag EQ 'E' AND begdate LE sy-datum AND
     <vim_enddate_mask> GE sy-datum OR x_header-delmdtflag EQ 'B' AND
     begdate GE sy-datum AND <vim_enddate_mask> LE sy-datum.
    act_entry_flag = 'X'.
  ENDIF.
  LOOP AT vim_collapsed_mainkeys FROM vim_coll_mainkeys_beg_ix.
    CHECK <vim_collapsed_mkey_bfx> = <vim_f1_beforex>.
*                                 WHERE mkey_bf EQ <vim_f1_before>.
    IF vim_mkey_after_exists NE space.
      CHECK <vim_collapsed_key_afx> EQ <vim_f1_afterx>.
*      CHECK <vim_collapsed_key_af> EQ <vim_f1_after>.
    ENDIF.
    vim_last_coll_mainkeys_ix = sy-tabix.
    IF act_entry_flag NE space.
      IF mod_flag EQ 'D'.
        READ TABLE extract WITH KEY <vim_collapsed_keyx>
                           TRANSPORTING NO FIELDS.
        IF sy-subrc EQ 0.
          DELETE extract INDEX sy-tabix.
        ENDIF.
      ENDIF.
      IF <key_x> NE <vim_collapsed_keyx>.
*      IF key_in NE vim_collapsed_mainkeys-mainkey.
        <vim_collapsed_keyx> = <key_x>.
*        vim_collapsed_mainkeys-mainkey = key_in.
        <vim_xtotal_key> = <key_x>.
        if <vim_collapsed_mkey_bfx> ne <vim_tot_mkey_beforex>.
          <vim_collapsed_mkey_bfx> = <vim_tot_mkey_beforex>.
        endif.
*        vim_collapsed_mainkeys-mkey_bf = <vim_tot_mkey_before>.
        MODIFY vim_collapsed_mainkeys.
      ENDIF.
      rec = 4.
    ELSE.
      IF <key_x> NE <vim_collapsed_keyx>.
*      IF key_in NE vim_collapsed_mainkeys-mainkey.
        rec = 8.
      ELSE.
        rec = 4.
      ENDIF.
    ENDIF.
    EXIT.
  ENDLOOP.
  IF sy-subrc NE 0.
    CLEAR rec.
  ENDIF.
  IF key_local NE space.
    <f1_x> = <f1_wax>.
  ENDIF.
  sy-subrc = rec.
ENDFORM.                               "check_if_entry_is_to_display

*---------------------------------------------------------------------*
*       FORM READ_TABLE                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  IND                                                           *
*---------------------------------------------------------------------*
FORM read_table USING ind.
  IF replace_mode NE space OR vim_special_mode EQ vim_delete.
    EXIT.
  ENDIF.
  READ TABLE extract INDEX ind.
  MOVE sy-tabix TO exind.
  IF sy-subrc NE 0.
    MOVE <initial> TO <table1>.
    MOVE <table1> TO <vim_extract_struc>.
    IF x_header-bastab NE space AND x_header-texttbexst NE space.
      MOVE: <text_initial_x> TO <vim_xextract_text>,
            <text_initial_x> to <table1_xtext>.
*            <table1_text> TO <extract_text>.
    ENDIF.
    IF status-mode EQ detail_bild AND status-action EQ hinzufuegen AND
       neuer EQ 'N'.                   "e.g. 'PREV' without input
      neuer = 'J'.
    ENDIF.
  ELSE.
    PERFORM move_extract_to_view_wa.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM UPDATE_TAB                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM update_tab.
  DATA: rc_safe LIKE sy-subrc, tabix LIKE sy-tabix, h_ix TYPE i,
        begdate_safe TYPE d, enddate_safe TYPE d.
  CHECK status-action NE anzeigen.
  CHECK status-action NE transportieren.
  CHECK status-delete NE geloescht.
  IF <status>-upd_flag EQ space.
    neuer = 'N'.
    EXIT.
  ENDIF.
  IF status-type EQ einstufig AND status-action EQ hinzufuegen.
    IF ( ( x_header-bastab EQ space OR x_header-texttbexst EQ space )
           AND <table2_x> EQ <initial_x>
         OR x_header-bastab NE space AND x_header-texttbexst NE space
           AND <vim_xextract_enti> EQ <initial_x>
         OR ( vim_special_mode EQ vim_upgrade OR
           vim_single_entry_function NE space ) )
        AND <xact> EQ leer.            "int943578/2000
      neuer = 'J'.
    ELSE.
      neuer = 'N'.
    ENDIF.
  ENDIF.
  IF x_header-frm_h_flds NE space.
    PERFORM (x_header-frm_h_flds) IN PROGRAM.               "Zp 21
  ENDIF.
  IF neuer EQ 'J'.
    IF x_header-guidflag <> space.
      PERFORM vim_make_guid USING space.
    ENDIF.
    IF x_header-frm_on_new NE space.
      PERFORM (x_header-frm_on_new) IN PROGRAM.             "Zp 05
    ENDIF.
    PERFORM check_key.
    MOVE: sy-subrc TO rc_safe, sy-tabix TO tabix.
    IF x_header-adrnbrflag NE space.
      IF vim_special_mode NE vim_upgrade.
        PERFORM address_maintain.
      ELSE.
        PERFORM vim_address_adjust.
      ENDIF.
    ENDIF.
    IF vim_called_by_cluster NE space AND vim_extcopy_mode NE space.
      h_ix = nextline + 1.
      READ TABLE extract INDEX h_ix.
      DELETE extract INDEX h_ix.
      IF x_header-texttbexst <> space. "SW Textcopy
        PERFORM vim_copy_texttab_entry USING <f1_x> <vim_xextract_key>.
      ENDIF.
      PERFORM vim_store_state_info.
      CALL FUNCTION 'VIEWCLUSTER_COPY_DEPENDENT'
           EXPORTING
                view_name   = x_header-viewname
                maintview   = x_header-maintview
                status_mode = status-mode
                workarea    = extract
                new_entry   = <table1>
                no_dialog   = vim_external_mode.
    ENDIF.
    PERFORM nicht_vorhanden USING rc_safe tabix.
  ELSE.
    IF vim_special_mode EQ vim_upgrade.
      PERFORM vim_address_adjust.
    ENDIF.
    IF vim_called_by_cluster NE space.
      CALL FUNCTION 'VIEWCLUSTER_CHECK_MASTER_ENTRY'
           EXPORTING
                check_entry   = <table1>
                view_name     = x_header-viewname
           EXCEPTIONS
                invalid_key   = 1
                invalid_value = 2.
      IF sy-subrc NE 0.
        IF status-mode EQ list_bild.
          SET CURSOR FIELD sy-msgv1 LINE l.
        ELSE.
          SET CURSOR FIELD sy-msgv1.
        ENDIF.
        MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ENDIF.
    MOVE exind TO index.
    READ TABLE total WITH KEY <f1_x> BINARY SEARCH.
    IF vim_special_mode NE vim_upgrade.
      PERFORM vorhanden.               "update both tables
    ELSE.
      PERFORM update_entry USING 'X'.
    ENDIF.
  ENDIF.
  MOVE space TO <status>-upd_flag.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM VORHANDEN                                                *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM VORHANDEN.
  PERFORM UPDATE_ENTRY USING SPACE.
ENDFORM.                               "vorhanden

*---------------------------------------------------------------------*
*       FORM UPDATE_ENTRY                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM update_entry USING value(ue_total_only).
  DATA: rec LIKE sy-subrc, tabix LIKE sy-tabix.
  tabix = sy-tabix.
  IF <status>-upd_flag EQ 'X' OR <status>-upd_flag EQ 'E' OR
     <status>-upd_flag EQ 'Y'.
    IF x_header-customauth CO sap_cust_ctrl_classes OR
       vim_ale_keyspec_check NE space.
      PERFORM check_allowed_keyranges.
    ENDIF.
    move <table1> to <vim_total_struc>.
*    WRITE <table1> TO total(x_header-tablen).
    IF <xact> EQ original.
      <action>          = aendern.
    ELSE.
      <action>          = <xact>.
    ENDIF.
  ENDIF.
  IF x_header-bastab NE space AND x_header-texttbexst NE space AND
     <status>-upd_flag EQ 'X' OR <status>-upd_flag EQ 'T' OR
     <status>-upd_flag EQ 'Y'.
    IF x_header-customauth CO sap_cust_ctrl_classes OR
       vim_ale_keyspec_check NE space.
      PERFORM check_allowed_keyranges.
    ENDIF.
    IF <status>-upd_flag NE 'Y'.
      IF <vim_xtotal_text> EQ <text_initial_x>.
        <action_text> = neuer_eintrag.
      ELSE.
        IF <xact_text> EQ original.
          <action_text>          = aendern.
        ELSE.
          <action_text>          = <xact_text>.
        ENDIF.
      ENDIF.
    ENDIF.
    MOVE <table1_xtext> TO <vim_xtotal_text>.
*    MOVE <table1_text> TO <total_text>.
  ENDIF.
  IF replace_mode NE space.
    <mark> = nicht_markiert.
  ELSE.
    <mark> = <xmark>.
  ENDIF.
  MODIFY total  INDEX tabix.
  IF ue_total_only EQ space.
    IF x_header-delmdtflag NE space.
      PERFORM check_if_entry_is_to_display USING 'L' <vim_xtotal_key>
                                                 'X' <vim_begdate>.
      rec = sy-subrc.
    ENDIF.
    extract = total.
    IF x_header-delmdtflag EQ space OR rec LT 8.
      MODIFY extract INDEX index.
    ENDIF.
  ENDIF.
ENDFORM.                               "update_entry

*---------------------------------------------------------------------*
*       FORM NICHT_VORHANDEN                                          *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM nicht_vorhanden USING rc tabind.
  DATA: dum TYPE i VALUE 0.

*  MOVE <table1> TO total.
  move <table1> to <vim_total_struc>.
  IF x_header-bastab NE space AND x_header-texttbexst NE space.
    MOVE <table1_xtext> TO <vim_xtotal_text>.
* nec. if special types in texttab
*    MOVE <table1_text> TO <total_text>.
    IF <status>-upd_flag EQ 'X' OR <status>-upd_flag EQ 'T'.
      <action_text> = neuer_eintrag.
    ENDIF.
  ENDIF.
  <action>          = neuer_eintrag.
  CASE rc.                                                  "aro
    WHEN 0.                                                 "aro
      MODIFY total INDEX tabind.                            "aro
    WHEN 4.
      INSERT total INDEX tabind.
    WHEN 8.                                                 "aro
      APPEND total.
  ENDCASE.                                                  "aro
  IF vim_special_mode NE vim_upgrade AND                    "aro
     status-action NE kopieren.                             "aro
    IF status-mode EQ list_bild.
      IF vim_single_entry_function EQ space.
        CLEAR <xmark>.
        APPEND extract.
      ELSE.
        nbr_of_added_dummy_entries = 0.
      ENDIF.
      extract = total.
      MODIFY extract INDEX nextline.
    ELSE.
      IF x_header-delmdtflag NE space.
        PERFORM check_if_entry_is_to_display USING 'L' <vim_xtotal_key>
                                                   'D' <vim_begdate>.
        IF sy-subrc EQ 0.
          PERFORM check_new_mainkey.
          IF sy-subrc EQ 0.
            READ TABLE vim_collapsed_mainkeys WITH KEY <vim_xtotal_key>
                                             BINARY SEARCH
                                             TRANSPORTING NO FIELDS.
            <vim_collapsed_keyx> = <vim_xtotal_key>.
*            vim_collapsed_mainkeys-mainkey = <vim_total_key>.
            <vim_collapsed_mkey_bfx> = <vim_tot_mkey_before>.
*            vim_collapsed_mainkeys-mkey_bf = <vim_tot_mkey_before>.
            INSERT vim_collapsed_mainkeys INDEX sy-tabix.
          ENDIF.
          CLEAR sy-subrc.
        ENDIF.
      ENDIF.
      IF x_header-delmdtflag EQ space OR sy-subrc LT 8.
        extract = total.
        APPEND extract.
        exind = sy-tabix.
      ENDIF.
    ENDIF.
  ENDIF.                                                    "aro
  neuer = 'N'.
  DESCRIBE TABLE extract LINES maxlines.
  IF status-mode EQ list_bild.                              "aro
    SUBTRACT nbr_of_added_dummy_entries FROM maxlines.
    dum = maxlines - firstline - sy-loopc + 1.              "aro
    IF dum EQ 0.                                            "aro
      destpage = maxlines.
    ENDIF.                                                  "aro
  ENDIF.                                                    "aro
ENDFORM.

*---------------------------------------------------------------------*
*       FORM CHECK_NEW_MAINKEY                                        *
*---------------------------------------------------------------------*
* check if current mainkey is a new one                               *
*---------------------------------------------------------------------*
* <-- SY-SUBRC : 0 -> mainkey is new, others -> mainkey already exists*
*---------------------------------------------------------------------*
FORM check_new_mainkey.
  LOCAL: total, <table1>.
  DATA: hf TYPE i, rec TYPE i.

  MOVE: <vim_xtotal_key> TO <f1_x>.
  READ TABLE total WITH KEY <f1_x> BINARY SEARCH TRANSPORTING NO FIELDS.
  IF sy-subrc EQ 0."new entry already inserted into TOTAL
    hf = sy-tabix - 1.
    READ TABLE total INDEX hf.         "read previous entry
    IF <vim_tot_mkey_beforex> EQ <vim_f1_beforex> AND
       ( vim_mkey_after_exists EQ space OR
         <vim_tot_mkey_afterx> EQ <vim_f1_afterx> ). "same mainkey
*    IF <vim_tot_mkey_before> EQ <vim_f1_before> AND
*       ( vim_mkey_after_exists EQ space OR
*         <vim_tot_mkey_after> EQ <vim_f1_after> ). "same mainkey
      rec = 8.                         "-> mainkey already exists
    ELSE. "not the same mainkey -> check also next entry
      hf = hf + 2.
      READ TABLE total INDEX hf.       "read next entry
      IF <vim_tot_mkey_beforex> EQ <vim_f1_beforex> AND
         ( vim_mkey_after_exists EQ space OR
           <vim_tot_mkey_afterx> EQ <vim_f1_afterx> ). "same mainkey
*      IF <vim_tot_mkey_before> EQ <vim_f1_before> AND
*         ( vim_mkey_after_exists EQ space OR
*           <vim_tot_mkey_after> EQ <vim_f1_after> ). "same mainkey
        rec = 8.                       "-> mainkey already exists
      ENDIF.
    ENDIF.
  ENDIF.
  sy-subrc = rec.
ENDFORM.                               "check_new_mainkey

*---------------------------------------------------------------------*
*       FORM HINZUFUEGEN                                              *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM hinzufuegen.
  DATA: h_screenmode(1) TYPE c VALUE 'S'.
  CASE status-action.
    WHEN hinzufuegen.
      nextline = maxlines.
    WHEN aendern.
      REFRESH extract.
      maxlines = 0.
      nextline = <status>-cur_line = 1.
      IF status-type EQ zweistufig.
        firstline = <status>-firstline = nextline.
      ENDIF.
      IF vim_single_entry_function EQ 'INS'.
        h_screenmode = 'C'.
      ENDIF.
    WHEN OTHERS.
      MESSAGE i001(sv).
      EXIT.
  ENDCASE.
  MOVE <initial> TO <table1>.
  IF x_header-clidep NE space.
    MOVE sy-mandt TO <client>.
  ENDIF.
  MOVE <table1> TO <vim_extract_struc>.
  IF x_header-bastab NE space AND x_header-texttbexst NE space.
    MOVE: <text_initial> TO <table1_text>,
          <table1_xtext> TO <vim_xextract_text>.
*          <table1_text> TO <extract_text>.
  ENDIF.
  status-action = hinzufuegen.
  <status>-selected = neuer_eintrag.
  status-data   = auswahldaten.
  title-action  = hinzufuegen.
  title-data    = auswahldaten.
  neuer  = 'J'.
  IF status-type EQ zweistufig.
    PERFORM process_detail_screen USING h_screenmode.
  ELSE.
    IF vim_single_entry_function EQ 'INS'.
      nbr_of_added_dummy_entries = 1.
    ELSEIF looplines EQ 0.
      MOVE 50 TO nbr_of_added_dummy_entries.
    ELSE.
      MOVE looplines TO nbr_of_added_dummy_entries.
    ENDIF.
    MOVE leer TO <xact>. clear <xmark>.
    DO nbr_of_added_dummy_entries TIMES.
      APPEND extract.
    ENDDO.
    IF h_screenmode EQ 'S'.
      SET SCREEN liste.
      LEAVE SCREEN.
    ELSE.
      CALL SCREEN liste.
    ENDIF.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM CHECK_KEY                                                *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM check_key.
  DATA: s LIKE sy-tabix, mess_type(1) TYPE c VALUE 'E', ck_tabix TYPE i,
        ck_check_tab LIKE vimdesc-viewname, ck_slcnds_nokey(1) TYPE c,
        ck_clause TYPE vim_ck_selcond, ck_wa TYPE REF TO data,
        ck_wheretab LIKE vimwheretb OCCURS 10, ck_rc LIKE sy-subrc,
        oc_keys TYPE occheckkeyflds, n(1) TYPE n, ocmes TYPE fieldname,
        field1 TYPE fieldname, field2 TYPE fieldname,
        field3 TYPE fieldname, field4 TYPE fieldname,
        w_oc_keys TYPE occheckkey, fieldname TYPE fnam_____4.
  FIELD-SYMBOLS: <ck_1> TYPE ANY, <noauth> TYPE fieldname,
                 <namtab> TYPE vimnamtab, <ck_wa> TYPE ANY,
                 <table1_txt_loc> type any.

  CHECK neuer CO 'JX'.
  IF vim_key_alr_checked NE space.
    READ TABLE total WITH KEY <f1_x> BINARY SEARCH.
    EXIT.
  ELSE.
    vim_key_alr_checked = 'X'.
  ENDIF.
* first check namespace
  IF x_header-customauth CO sap_cust_classes OR
     vim_ale_keyspec_check NE space.
    PERFORM check_allowed_keyranges.
  ENDIF.
* check if user is authorised for this key
  IF NOT vim_oc_inst IS INITIAL.
    CALL METHOD vim_oc_inst->build_key_value_tab
      EXPORTING
        entry     = <table1>
      IMPORTING
        keyvalues = oc_keys.
    CALL METHOD vim_oc_inst->check_oc_authority
      EXPORTING
        activity        = '02'
      CHANGING
        key_values      = oc_keys
      EXCEPTIONS
        no_auth         = 1
*        key_incomplete  = 2
        wrong_parameter = 3
        OTHERS          = 4.
    CASE sy-subrc.
      WHEN 1.
        PERFORM set_pf_status USING 'ERROR'.
        CLEAR vim_key_alr_checked.
        LOOP AT oc_keys INTO w_oc_keys WHERE noauth = 'X'.
          n = n + 1.
          CONCATENATE 'FIELD' n INTO ocmes.
          IF n <= '4'.
            ASSIGN (ocmes) TO <noauth>.
            READ TABLE x_namtab ASSIGNING <namtab> WITH KEY
             viewfield = w_oc_keys-keyname.
            CHECK sy-subrc = 0.
            IF <namtab>-scrtext_s <> space.
              <noauth> = <namtab>-scrtext_s.
            ELSE.
              <noauth> = w_oc_keys-keyname.
            ENDIF.
          ELSE.
*            ocmiss4 = text-001.
          ENDIF.
        ENDLOOP.
        MESSAGE e757(sv) WITH field1 field2 field3 field4.
      WHEN OTHERS.
*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDCASE.
  ENDIF.
* second check if entry fits selection conditions
  IF x_header-selection NE space.
    if x_header-bastab <> space and x_header-texttbexst <> space.
      assign <table1_text> to <table1_txt_loc>.
    else.
      assign <table1> to <table1_txt_loc>.
    endif.
    CALL FUNCTION 'TABLE_RANGE_CHECK'
         EXPORTING
              tabname                   = x_header-maintview
              entry                     = <table1>
              entry_text                = <table1_txt_loc>
              ddic                      = 'J'
              key                       = 'J'
              ignore_blank_subsetfields = 'N'
         TABLES
              x_namtab                  = x_namtab
              x_header                  = x_header
              sellist                   = <vim_ck_sellist>
         EXCEPTIONS
              entry_not_fits            = 1.
    IF sy-subrc EQ 1.
      PERFORM set_pf_status USING 'ERROR'.
      CLEAR vim_key_alr_checked.
      MESSAGE e033(sv).
    ENDIF.
  ENDIF.                               "x_header-selection ne space.
* Forkey-Check for subset fields in import mode
  IF vim_called_by_cluster = space AND
   ( vim_import_mode_active <> space OR
     vim_special_mode = vim_upgrade ).
    CALL FUNCTION 'VIEW_FORKEY_CHECK'
         EXPORTING
              viewname     = view_name
              entry        = <table1>
         TABLES
              namtab       = x_namtab
         EXCEPTIONS
              forkey_error = 1.
    IF sy-subrc EQ 1.
      PERFORM set_pf_status USING 'ERROR'.
      CLEAR vim_key_alr_checked.
      MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  ENDIF.
* third check against TOTAL anyway
  READ TABLE total WITH KEY <f1_x> BINARY SEARCH.
  ck_tabix = sy-tabix.
* fourth check against db if not found and nokey-selconds exist
  IF sy-subrc NE 0 AND                 "entry not found in TOTAL and
     x_header-selection NE space AND   "selconds exist and
   <status>-nokeyslcds NE space.       "nokey-selconds: check against db
    IF x_header-bastab EQ space.
      ck_check_tab = x_header-roottab.
    ELSE.
      ck_check_tab = x_header-maintview.
    ENDIF.
    LOOP AT x_namtab WHERE keyflag NE space. "all keyfields
      IF x_header-bastab NE space AND x_header-texttbexst NE space.
        CHECK x_namtab-texttabfld EQ space. "ignore texttab-keyfields
      ELSEIF x_header-bastab EQ space. "view -> safety check langu key
        CHECK x_namtab-bastabname EQ x_header-roottab.
      ENDIF.
      PERFORM vim_ck_append_wheretab TABLES ck_wheretab
                                     USING ck_clause.
      IF x_header-bastab EQ space.
        ck_clause-field = x_namtab-bastabfld.
      ELSE.
        ck_clause-field = x_namtab-viewfield.
      ENDIF.
      ck_clause-operator = 'EQ'.
      ck_clause-hk1 = ''''.
      ck_clause-hk2 = ''''.
      ck_clause-and = 'AND'.
      IF x_namtab-inttype CO 'DTN'.
        ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE <table1>
         TO <ck_1> CASTING TYPE c.
*        ASSIGN <f1>+x_namtab-position(x_namtab-flength) TO <ck_1>
*                                                        TYPE 'C'.
*      ELSEIF x_namtab-inttype CO 'IPX'.
      ELSE.
       CONCATENATE x_header-maintview x_namtab-viewfield INTO fieldname
           SEPARATED BY '-'.
        ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE <table1>
         TO <ck_1> CASTING TYPE (fieldname).
*        ASSIGN <f1>+x_namtab-position(x_namtab-flength) TO <ck_1>
*                                            TYPE x_namtab-inttype.
*      ELSE.
*        ASSIGN <f1>+x_namtab-position(x_namtab-flength) TO <ck_1>.
      ENDIF.
      ck_clause-value = <ck_1>.
    ENDLOOP.
    CLEAR ck_clause-and.
    PERFORM vim_ck_append_wheretab TABLES ck_wheretab
                                   USING ck_clause.
    CREATE DATA ck_wa TYPE (ck_check_tab).
    ASSIGN ck_wa->* TO <ck_wa>.
    SELECT SINGLE * INTO <ck_wa> FROM (ck_check_tab)
                                 WHERE (ck_wheretab).
    IF sy-subrc EQ 8.                  "key not qualified
      RAISE impossible_error.
    ENDIF.
    ck_rc = sy-subrc.
  ELSE. "entry found in TOTAL or no nokey-selconds
    ck_rc = sy-subrc.
  ENDIF.                               "x_header-selection ne space.
  IF ck_rc NE 0 AND vim_called_by_cluster NE space.
    CALL FUNCTION 'VIEWCLUSTER_CHECK_MASTER_ENTRY'
         EXPORTING
              check_entry   = <table1>
              view_name     = x_header-viewname
         EXCEPTIONS
              invalid_key   = 1
              invalid_value = 2.
    IF sy-subrc NE 0.
      IF status-mode EQ list_bild.
        SET CURSOR FIELD sy-msgv1 LINE l.
      ELSE.
        SET CURSOR FIELD sy-msgv1.
      ENDIF.
      CLEAR vim_key_alr_checked.
      PERFORM set_pf_status USING 'ERROR'.
      MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  ENDIF.
  sy-subrc = ck_rc. sy-tabix = ck_tabix.
  CHECK ck_rc EQ 0.
  IF x_header-delmdtflag NE space AND status-mode EQ detail_bild.
    mess_type = 'S'.
  ENDIF.
  PERFORM set_pf_status USING 'ERROR'.
  CLEAR vim_key_alr_checked.
  IF <action> EQ geloescht
  OR <action> EQ neuer_geloescht
  OR <action> EQ update_geloescht.
    MESSAGE ID 'SV' TYPE mess_type NUMBER '010'.
  ELSE.
    MESSAGE ID 'SV' TYPE mess_type NUMBER '009'.
  ENDIF.
  IF x_header-delmdtflag NE space AND status-mode EQ detail_bild.
    <vim_h_old_mkey>(x_header-keylen) = <f1_x>.
*    vim_old_viewkey = <f1>.
    TRANSLATE neuer USING 'JX'.
    CLEAR: function, ok_code. LEAVE SCREEN.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM VIM_CK_APPEND_WHERETAB                                   *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM VIM_CK_APPEND_WHERETAB TABLES VCAW_WHERETAB STRUCTURE VIMWHERETB
                            USING VALUE(LINE) TYPE VIM_CK_SELCOND.
DATA: BEGIN OF HF, F1(1) TYPE C, F2 LIKE VIMSELLIST-VALUE, F3(1) TYPE C,
                  END OF HF.
DATA: len TYPE i,l_line(134) TYPE c.
CONSTANTS: wheretab_length TYPE i VALUE 72.
  CHECK NOT LINE IS INITIAL.
  IF LINE-VALUE EQ SPACE.
    HF = ''' '''.
  ELSE.
    CONCATENATE: LINE-HK1
                 LINE-VALUE
                 LINE-HK2
      INTO HF.
  ENDIF.
  CONCATENATE: LINE-FIELD
               LINE-OPERATOR
               HF
               LINE-AND
    INTO VCAW_WHERETAB SEPARATED BY SPACE.
  IF SY-SUBRC EQ 0.
    APPEND VCAW_WHERETAB.
  ELSE.
    CONCATENATE: LINE-FIELD
                 LINE-OPERATOR
      INTO VCAW_WHERETAB SEPARATED BY SPACE.
    APPEND VCAW_WHERETAB.
    CONCATENATE: HF
                 LINE-AND
      INTO l_line SEPARATED BY SPACE.
    vcaw_wheretab = l_line.
    APPEND vcaw_wheretab.
    len = strlen( l_line ).
    IF len > wheretab_length.
      CLEAR vcaw_wheretab.
      vcaw_wheretab = l_line+wheretab_length.
      APPEND vcaw_wheretab.
    ENDIF.
    IF line-and <> space.
      vcaw_wheretab = line-and.
        APPEND VCAW_WHERETAB.
    ENDIF.
  ENDIF.
ENDFORM.                               "vim_ck_append_wheretab

*---------------------------------------------------------------------*
*       FORM LISTE_LOESCHE                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM liste_loesche.
  DATA: rec LIKE sy-subrc,
        delete_fix_value(1) TYPE c,
        entry_contains_fix_val(1) TYPE c,
        w_field TYPE vimty_fields_type,
        bc_fix_del_info_sent(1) TYPE c VALUE ' '.

  READ TABLE extract INDEX firstline.
  IF x_header-delmdtflag <> space.
    <vim_h_old_mkey>(x_header-keylen) = <vim_xextract_key>.
  ENDIF.
*  vim_old_viewkey = <vim_extract_key>.
  counter = 0.
  LOOP AT extract.
    CHECK <xmark> EQ markiert.
*   -------Authority check before deleting fix values from BC-Sets------
    delete_fix_value = vim_bc_chng_allowed.
    IF vim_bc_chng_allowed = space.  "fix field changeability forced
      READ TABLE vim_bc_entry_list INTO vim_bc_entry_list_wa
      WITH TABLE KEY viewname = x_header-viewname
      keys = <vim_xextract_key>.
      IF sy-subrc = 0.
        CLEAR entry_contains_fix_val.
        LOOP at vim_bc_entry_list_wa-fields into w_field.
          IF w_field-flag = vim_profile_fix.
            entry_contains_fix_val = 'X'.
          ENDIF.
        ENDLOOP.
        IF entry_contains_fix_val = 'X'.
          IF bc_fix_del_info_sent EQ SPACE AND
             <status>-bcfixdelinfosent NE 'Y'."HCG: del dependent VCL
            bc_fix_del_info_sent = 'X'.
            <status>-bcfixdelinfosent = 'X'.
            MESSAGE i177(SV).
          ENDIF.
        ELSE.
          delete_fix_value = 'X'.
        ENDIF.
      ELSE.
        delete_fix_value = 'X'.
      ENDIF.
    ENDIF.
    CHECK delete_fix_value EQ 'X'.
*   -------------------------------------------------------------"HCG---
    READ TABLE total WITH KEY <vim_xextract_key> BINARY SEARCH.
    rec = sy-tabix.
    IF x_header-existency EQ 'M'.      "no mainkey delete allowed
      PERFORM check_if_entry_can_be_deleted.
      IF sy-subrc NE 0.
        <xmark> = uebergehen. ignored_entries_exist = 'X'.
        MODIFY extract.
        <mark> = uebergehen.
        MODIFY total INDEX rec.
        CONTINUE.
      ENDIF.
    ENDIF.
    PERFORM delete_check_keyrange.
    CASE sy-subrc.
      WHEN 0.
      WHEN 4. CONTINUE.
      WHEN 8. EXIT.
    ENDCASE.
    counter = counter + 1.
    PERFORM logical_delete_from_total USING rec.
    IF x_header-delmdtflag NE space.
      IF vim_special_mode NE vim_upgrade.
        PERFORM check_if_entry_is_to_display USING 'L' <vim_xtotal_key>
                                                   space <vim_begdate>.
      ELSE.
        CLEAR sy-subrc.
      ENDIF.
      CASE sy-subrc.
        WHEN 0. DELETE extract.
        WHEN 4.
          <f1_x> = <vim_xtotal_key>. CLEAR <vim_enddate_mask>.
          <vim_h_old_mkey>(x_header-keylen) = <f1_x>.
*          vim_old_viewkey = <f1>.
          <vim_h_mkey> = <vim_xtotal_key>.
*          vim_mainkey = <vim_total_key>.
          rec = 8.
          LOOP AT total.
            PERFORM select USING <status>-selected.
            CHECK sy-subrc EQ 0.
            CHECK <vim_tot_mkey_beforex> EQ <vim_f1_beforex> AND
               ( vim_mkey_after_exists EQ space OR
               <vim_tot_mkey_afterx> EQ <vim_f1_afterx> ). "same mainkey
*            CHECK <vim_tot_mkey_before> EQ <vim_f1_before> AND
*                  ( vim_mkey_after_exists EQ space OR
*                    <vim_tot_mkey_after> EQ <vim_f1_after> ).
            extract = total.
            PERFORM mod_extract_and_mainkey_tab USING 'M' 0.
            CLEAR rec.
            EXIT.
          ENDLOOP.
          IF rec NE 0.
            DELETE extract.
          ENDIF.
      ENDCASE.
    ELSE.
      DELETE extract.
    ENDIF.
    mark_total  = mark_total - 1.
    mark_extract = mark_extract - 1.
  ENDLOOP.
  CHECK vim_special_mode NE vim_upgrade.
  DESCRIBE TABLE extract LINES maxlines.
  IF status-action EQ hinzufuegen.
    SUBTRACT nbr_of_added_dummy_entries FROM maxlines.
  ENDIF.
  IF ignored_entries_exist EQ space AND maxlines GT 0.
    MESSAGE s011(sv) WITH counter.
  ELSE.
    MESSAGE i011(sv) WITH counter.
  ENDIF.
  IF x_header-delmdtflag <> space.
    <f1_x> = <vim_h_old_mkey>.
  ENDIF.
*  <f1> = vim_old_viewkey.
  READ TABLE extract WITH KEY <f1_x>.
  IF sy-subrc NE 8.
    rec = firstline + looplines - 1.
    IF sy-tabix GT rec OR nextline GT maxlines.
      nextline = sy-tabix.
    ENDIF.
  ELSE.
    nextline = 1.
  ENDIF.
  IF maxlines EQ 0 AND status-action EQ hinzufuegen.
    status-action = aendern.
    title-action = aendern.
    l = 1. o = 0.
  ENDIF.
  CLEAR vim_old_viewkey.
  TRANSLATE vim_no_mainkey_exists USING vim_no_mkey_not_procsd_patt.
ENDFORM.

*---------------------------------------------------------------------*
*       LOGICAL_DELETE_FROM_TOTAL                                     *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM logical_delete_from_total USING value(cur_index) TYPE i.
  CASE <action>.
    WHEN neuer_eintrag.
      <action>         = neuer_geloescht.
    WHEN original.
      <action>         = geloescht.
    WHEN aendern.
      <action>         = update_geloescht.
  ENDCASE.
*  perform vim_bc_logs_maintain using geloescht
*                                     x_header
*                               changing vim_bc_entry_list.
  IF x_header-bastab NE space AND x_header-texttbexst NE space.
    CASE <action_text>.
      WHEN neuer_eintrag.
        <action_text>         = neuer_geloescht.
      WHEN original.
        IF <vim_xtotal_text> NE <text_initial_x>.
*        IF <total_text> NE <text_initial>.
          <action_text>         = geloescht.
        ELSE.
          PERFORM (vim_frm_fill_textkey) IN PROGRAM (sy-repid)
                                       USING <vim_total_struc>
                                             <vim_tot_txt_struc>.
* Unicode: Form FILL_TEXTTAB_KEY_UC instead of FILL_TEXTTAB_KEY_UC
*                                       USING <vim_total_key>
*                                             <total_text>.
          <action_text>         = dummy_geloescht. "always del texttbent
        ENDIF.
      WHEN aendern.
        <action_text>         = update_geloescht.
    ENDCASE.
  ENDIF.
  <mark>       = nicht_markiert.
  MODIFY total INDEX cur_index.
ENDFORM.                               "logical_delete_from_total

*---------------------------------------------------------------------*
*       FORM CHECK_IF_ENTRY_CAN_BE_DELETED                            *
*---------------------------------------------------------------------*
* check if entry of existency-M-table/view can be deleted             *
*---------------------------------------------------------------------*
* SY_SUBRC <-- 0: yes, deleteable, others: no, not deleteable         *
*---------------------------------------------------------------------*
FORM check_if_entry_can_be_deleted.
  LOCAL: <f1_x>, total, <vim_xextract_key>.
  DATA: hf TYPE i, rec TYPE i VALUE 8.

  <vim_xextract_key> = <f1_x> = <vim_xtotal_key>.
  CLEAR <vim_enddate_mask>.
  READ TABLE total WITH KEY <f1_x> BINARY SEARCH TRANSPORTING NO FIELDS.
  hf = sy-tabix.
  LOOP AT total FROM hf.
    IF <vim_tot_mkey_beforex> NE <vim_f1_beforex> OR
       ( vim_mkey_after_exists NE space AND
         <vim_tot_mkey_afterx> NE <vim_f1_afterx> ).
*    IF <vim_tot_mkey_before> NE <vim_f1_before> OR
*       ( vim_mkey_after_exists NE space AND
*         <vim_tot_mkey_after> NE <vim_f1_after> ).
      EXIT.
    ENDIF.
    CHECK <action> NE geloescht AND <action> NE neuer_geloescht AND
          <action> NE update_geloescht AND
          <vim_xtotal_key> NE <vim_xextract_key>.
    CLEAR rec. EXIT.
  ENDLOOP.
  sy-subrc = rec.
ENDFORM.                               "check_if_entry_can_be_deleted

*---------------------------------------------------------------------*
*       FORM SUCHEN                                                   *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM suchen.
  DESCRIBE TABLE exclude_tab.
  IF sy-tfill GT 0.                    "entries in old exclude_tab
    PERFORM consider_old_exclude_tab TABLES excl_que_tab.
  ENDIF.
  CALL FUNCTION 'QUERY_GET_OPERATION'
       EXPORTING
            table             = x_header-maintview
       TABLES
            exclude_fields    = excl_que_tab
       EXCEPTIONS
            table_not_found   = 0004
            no_valid_fields   = 0008
            cancelled_by_user = 0012.
  CASE sy-subrc.
    WHEN 0.
    WHEN 8.
      MESSAGE s039(sv) WITH view_name.
      EXIT.
    WHEN OTHERS.
      EXIT.
  ENDCASE.
  status-data   = auswahldaten.
  title-data    = auswahldaten.
  IF title-action EQ geloescht.
    status-delete = nicht_geloescht.
    title-action = aendern.
  ENDIF.
  REFRESH extract.
  LOOP AT total.
    PERFORM select USING by_field_contents.
    CHECK sy-subrc EQ 0.
    extract = total.
    APPEND extract.
  ENDLOOP.
  <status>-selected = by_field_contents.
  DESCRIBE TABLE extract LINES maxlines.
  nextline = 1.
  IF maxlines EQ 0.
    PERFORM fill_extract.
    MESSAGE s004(sv).
    EXIT.
  ENDIF.
  IF maxlines EQ 1.
    MESSAGE s005(sv).
    IF status-type EQ zweistufig.
      PERFORM read_table USING maxlines.
      PERFORM process_detail_screen USING 'S'.
    ENDIF.
  ELSE.
    IF status-mode EQ detail_bild.
      vim_next_screen = liste. vim_leave_screen = 'X'.
    ENDIF.
  ENDIF.
  MESSAGE s006(sv) WITH maxlines.
  mark_extract = 0.
  LOOP AT extract.
    IF <xmark> EQ markiert.
      mark_extract = mark_extract + 1.
    ENDIF.
  ENDLOOP.
  IF x_header-delmdtflag <> space.        "SW CSS-Problem 83157/1999
    LOOP AT extract.
      LOOP AT vim_collapsed_mainkeys.
        CHECK <vim_collapsed_mkey_bfx> = <vim_ext_mkey_beforex>
         AND <vim_collapsed_keyx> <> <vim_xextract_key>.
*      LOOP AT vim_collapsed_mainkeys WHERE
*                mkey_bf = <vim_ext_mkey_before>.
*        IF vim_collapsed_mainkeys-mainkey <> <vim_extract_key>.
        DELETE vim_collapsed_mainkeys.
*        ENDIF.
      ENDLOOP.
    ENDLOOP.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM CONSIDER_OLD_EXCLUDE_TAB                                 *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM CONSIDER_OLD_EXCLUDE_TAB
                  TABLES NEW_EXCLUDE_TAB STRUCTURE VIMEXCLFLD.
  DATA: BEGIN OF VIEWNAME_PATTERN,
          VIEWNAME LIKE VIMDESC-VIEWNAME,
          WILDCARD(1) TYPE C VALUE '*',
        END OF VIEWNAME_PATTERN.

  VIEWNAME_PATTERN-VIEWNAME = X_HEADER-MAINTVIEW.
  CONDENSE VIEWNAME_PATTERN NO-GAPS.
  LOOP AT EXCLUDE_TAB WHERE FIELD CP VIEWNAME_PATTERN.
    SHIFT EXCLUDE_TAB-FIELD UP TO '-'. SHIFT EXCLUDE_TAB-FIELD.
    NEW_EXCLUDE_TAB-FIELDNAME = EXCLUDE_TAB-FIELD.
    COLLECT NEW_EXCLUDE_TAB.
  ENDLOOP.
ENDFORM.                               "consider_old_exclude_tab

*---------------------------------------------------------------------*
*       FORM REPLACE                                                  *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM replace.
  DATA: firstline_safe TYPE i.
  DESCRIBE TABLE exclude_tab.
  IF sy-tfill GT 0.                    "entries in old exclude_tab
    PERFORM consider_old_exclude_tab TABLES excl_rpl_tab.
  ENDIF.
  CALL FUNCTION 'REPLACE_GET_FIELD'
       EXPORTING
            table                  = x_header-maintview
       IMPORTING
            name_of_selected_field = sel_field_for_replace
       TABLES
            exclude_fields         = excl_rpl_tab
       EXCEPTIONS
            cancelled_by_user      = 0004
            no_valid_fields        = 8.
  CASE sy-subrc.
    WHEN 4.
      function = 'ABR '. EXIT.
    WHEN 8.
      MESSAGE s039(sv) WITH view_name. EXIT.
  ENDCASE.
  LOOP AT x_namtab WHERE viewfield EQ sel_field_for_replace.
    IF x_header-bastab NE space AND x_header-texttbexst NE space
                                AND x_namtab-texttabfld NE space.
      assign component x_namtab-viewfield of structure
                <vim_ext_txt_struc> to <replace_field>.
    else.
      assign component x_namtab-viewfield of structure
                <vim_extract_struc> to <replace_field>.
    endif.
*    ASSIGN extract+x_namtab-position(x_namtab-flength)
*                              TO <replace_field> TYPE x_namtab-inttype.
    IF x_header-bastab NE space AND x_header-texttbexst NE space.
      MOVE x_namtab-texttabfld TO replace_texttable_field.
    ELSE.
      CLEAR replace_texttable_field.
    ENDIF.
  ENDLOOP.
  IF replace_texttable_field EQ space. "view or base table field
    CONCATENATE x_header-maintview sel_field_for_replace
       INTO sel_field_for_replace_l SEPARATED BY '-'.
  ELSE.                                "text table field
    CONCATENATE x_header-texttab sel_field_for_replace
       INTO sel_field_for_replace_l SEPARATED BY '-'.
  ENDIF.
  IF x_header-frm_bf_rpl NE space.
    PERFORM (x_header-frm_bf_rpl) IN PROGRAM (sy-repid).
  ENDIF.
* SET PF-STATUS 'REPLACE'.
  PERFORM set_pf_status USING 'REPLACE'.
  replace_mode = 'X'. vim_special_mode = vim_replace.
  counter = 0.
  firstline_safe = firstline.
  LOOP AT extract.
    CHECK <xmark> EQ markiert.
    nextline = exind = sy-tabix.
    IF replace_texttable_field EQ space.  "view or base table field
      CALL FUNCTION 'REPLACE_SET_VALUE'
           EXPORTING
                old_table = <vim_xextract>
           IMPORTING
                new_table = <table1_x>.
      IF x_header-bastab NE space AND x_header-texttbexst NE space.
        <table1_xtext> = <vim_xextract_text>.
      ENDIF.
    ELSE.                              "text table field
      MOVE <vim_extract_struc> TO <table1>.
      CALL FUNCTION 'REPLACE_SET_VALUE'
           EXPORTING
                old_table = <vim_xextract_text>
           IMPORTING
                new_table = <table1_xtext>.
    ENDIF.
    CASE status-type.
      WHEN einstufig.
        CALL SCREEN liste.
      WHEN zweistufig.
        PERFORM process_detail_screen USING 'C'.
        <vim_extract_struc> = <table1>.
        IF x_header-bastab NE space AND x_header-texttbexst NE space.
          <vim_xextract_text> = <table1_xtext>.
        ENDIF.
    ENDCASE.
    CHECK ok_code NE 'IGN '.
    IF function EQ 'ABR '.
      EXIT.
    ENDIF.
    counter = counter + 1.
    SUBTRACT 1 FROM mark_extract.
    SUBTRACT 1 FROM mark_total.
  ENDLOOP.
  firstline = nextline = firstline_safe.
  replace_mode = vim_special_mode = space.
  MESSAGE s012(sv) WITH counter.
  IF x_header-frm_af_rpl NE space.
    PERFORM (x_header-frm_af_rpl) IN PROGRAM (sy-repid).
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM KOPIERE                                                  *
*---------------------------------------------------------------------*
* Kopieren als... und teilweise Gültigkeit abgrenzen                  *
*---------------------------------------------------------------------*
FORM kopiere.
  DATA: z LIKE sy-tabix VALUE 1,
        stat TYPE c, dum1 TYPE i.
  status-action = kopieren.
  MOVE status-data TO stat.
  status-data = auswahldaten.
  title-data = auswahldaten.
  ADD 1 TO vim_copy_call_level.
  IF vim_special_mode EQ vim_delimit.
    title-action = vim_delimit.
*  ELSEIF <STATUS>-PROF_FOUND NE VIM_PR_INTO_DET.           "UFprofile
*    TITLE-ACTION = KOPIEREN.
  ENDIF.
*  ASSIGN extract(x_header-keylen) TO <orig_key>.
  ASSIGN <vim_xextract_key> TO <orig_key>.
  IF status-mode EQ list_bild.
    LOOP AT extract.
      IF <xmark> NE markiert.
        DELETE extract.
      ELSE.
        <xmark> = nicht_markiert.
        MODIFY extract.
      ENDIF.
    ENDLOOP.
    mark_extract = <status>-mk_xt = 0.
    nextline = 1.
    DESCRIBE TABLE extract LINES maxlines.
    IF vim_copy_call_level = 1.
      VIM_NR_ENTRIES_TO_COPY = maxlines.            "SW 510129/1999
    ENDIF.
    IF status-type EQ einstufig.
      IF vim_special_mode NE vim_delimit.
        MESSAGE s024(sv).
      ELSE.
        MESSAGE s124(sv).
      ENDIF.
      CALL SCREEN liste.
      IF function NE 'ABR '.
        DESCRIBE TABLE vim_copied_indices.
        IF sy-tfill LT VIM_NR_ENTRIES_TO_COPY.     "SW 510129/1999
                             "not all selected entries where proc.
          LOOP AT extract.
            READ TABLE vim_copied_indices
                 WITH KEY level = vim_copy_call_level ex_ix = z.
            IF sy-subrc EQ 0.
              DELETE extract.
            ELSE.
              <xmark> = markiert. MODIFY extract.
            ENDIF.
            ADD 1 TO z.
          ENDLOOP.
          PERFORM kopiere.
        ENDIF.
      ENDIF.
    ELSE.
      LOOP AT extract.
        IF vim_special_mode NE vim_delimit.
          neuer = 'J'.
          MESSAGE s025(sv).
        ELSE.
          MESSAGE s125(sv).
        ENDIF.
        PERFORM move_extract_to_view_wa.
        PERFORM process_detail_screen USING 'C'.
        neuer = 'N'.
        <status>-upd_flag = space.
        IF temporal_delimitation_happened NE space.
          CLEAR temporal_delimitation_happened.
        ENDIF.
        IF vim_special_mode EQ vim_delimit.
          REFRESH vim_delim_entries.
        ENDIF.
        IF function EQ 'ABR '.
          EXIT.
        ENDIF.
      ENDLOOP.
    ENDIF.
    IF vim_copy_call_level GT 1.
      SUBTRACT 1 FROM vim_copy_call_level.
      EXIT.
    ENDIF.
    IF vim_special_mode NE vim_delimit AND counter LE 1.
      PERFORM fill_extract.
      mark_extract = mark_total.
      title-data = gesamtdaten.
      IF counter EQ 1.
        READ TABLE vim_copied_indices INDEX 1.
        READ TABLE total INDEX vim_copied_indices-ix.
        IF x_header-delmdtflag EQ space.
          READ TABLE extract WITH KEY <vim_xtotal_key>
                             TRANSPORTING NO FIELDS.
          nextline = sy-tabix.
        ELSE.
          nextline = 0.
          LOOP AT vim_collapsed_mainkeys.
            check <vim_collapsed_mkey_bfx> = <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.
            nextline = sy-tabix.
            EXIT.
          ENDLOOP.
          IF sy-subrc NE 0 OR nextline EQ 0.
            READ TABLE extract WITH KEY <vim_xtotal_key>
                               TRANSPORTING NO FIELDS.
            IF sy-subrc NE 0.
              nextline = 1.
            ELSE.
              nextline = sy-tabix.
            ENDIF.
          ENDIF.
        ENDIF.
      ELSE.
        nextline = 1.
      ENDIF.
    ELSE.
      status-action = title-action = hinzufuegen.
      status-data = title-data = auswahldaten.
      <status>-selected = neuer_eintrag.
      REFRESH: extract, vim_delim_entries.
      CLEAR: vim_mainkey, temporal_delimitation_happened.
      TRANSLATE vim_no_mainkey_exists USING vim_no_mkey_not_procsd_patt.
      mark_extract = 0.
      LOOP AT vim_copied_indices.
        READ TABLE total INDEX vim_copied_indices-ix.
        extract = total.
        APPEND extract.
        IF x_header-delmdtflag NE space.
          LOOP AT vim_collapsed_mainkeys.
            check <vim_collapsed_mkey_bfx> = <vim_ext_mkey_beforex>.
*                             WHERE mkey_bf EQ <vim_ext_mkey_before>.
            IF vim_mkey_after_exists NE space.
              CHECK <vim_collapsed_key_afx> EQ <vim_ext_mkey_afterx>.
*              CHECK <vim_collapsed_key_af> EQ <vim_ext_mkey_after>.
            ENDIF.
            READ TABLE excl_cua_funct WITH KEY function = 'EXPA'.
            IF sy-subrc NE 0.
              APPEND 'EXPA' TO excl_cua_funct.
              vim_delim_expa_excluded = 'X'.
            ENDIF.
            vim_collapsed_mainkeys-log_key =
                                        vim_collapsed_mainkeys-mkey_bf.
            CLEAR vim_collapsed_mainkeys-mkey_bf.
            MODIFY vim_collapsed_mainkeys. EXIT.
          ENDLOOP.
        ENDIF.
      ENDLOOP.
      vim_coll_mainkeys_beg_ix = 1.
      nextline = 1.
    ENDIF.
    l = 1.
    DESCRIBE TABLE extract LINES maxlines.
  ELSE.
* Detailbild
    CLEAR <status>-mark_only.          "ufdetail
    IF vim_special_mode NE vim_delimit.
      neuer = 'J'.
      MESSAGE s025(sv).
    ELSE.
      MESSAGE s125(sv).
    ENDIF.
    PERFORM process_detail_screen USING 'C'.
    neuer = 'N'.
    <status>-upd_flag = space.
    IF function NE 'IGN ' AND function NE 'ABR '.
      IF vim_special_mode NE vim_delimit.
* copy mode
        IF status-mark EQ markiert.
          READ TABLE extract WITH KEY <orig_key> BINARY SEARCH.
          IF sy-subrc EQ 0.
            <xmark> = nicht_markiert.
            MODIFY extract INDEX sy-tabix.
            SUBTRACT 1 FROM mark_extract.
          ENDIF.
        ENDIF.
      ELSE.
* delimit mode
        IF temporal_delimitation_happened NE space.
          PERFORM after_temporal_delimitation.
        ENDIF.
      ENDIF.
      READ TABLE total WITH KEY <f1_x> BINARY SEARCH.
      extract = total.
*     IF <STATUS>-DISPL_MODE EQ EXPANDED OR SY-SUBRC NE 0.
      IF x_header-delmdtflag NE space.
        PERFORM check_if_entry_is_to_display USING 'L' <vim_xtotal_key>
                                                   'D' <vim_begdate>.
        IF sy-subrc EQ 0.
          PERFORM check_new_mainkey.
          IF sy-subrc EQ 0.
            READ TABLE vim_collapsed_mainkeys
             WITH KEY <vim_tot_mkey_beforex>
*            READ TABLE vim_collapsed_mainkeys WITH KEY <vim_total_key>
                                             BINARY SEARCH
                                             TRANSPORTING NO FIELDS.
            <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>.
            INSERT vim_collapsed_mainkeys INDEX sy-tabix.
          ENDIF.
          CLEAR sy-subrc.
        ENDIF.
      ENDIF.
      IF x_header-delmdtflag EQ space OR sy-subrc LT 8.
        READ TABLE extract WITH KEY <vim_xextract_key> BINARY SEARCH
         TRANSPORTING NO FIELDS.       "UF 333778/1999
        CASE sy-subrc.
          WHEN 0.         "UF 333778/1999, for temporal delimitation
            MODIFY extract INDEX sy-tabix.
          WHEN 4.
            INSERT extract INDEX sy-tabix.
          WHEN 8.
            APPEND extract.
        ENDCASE.
        MOVE: sy-tabix TO exind,
              sy-tabix TO nextline.
      ENDIF.
      IF looplines GT 0.
        IF nextline LE firstline.
          dum1 = ( firstline - nextline ) / looplines.
          ADD 1 TO dum1.
          DO dum1 TIMES.
            firstline = firstline - looplines + 1.
          ENDDO.
          IF firstline LE 0. firstline = 1. ENDIF.
        ELSE.
          dum1 = firstline + looplines - 1.
          IF nextline GT dum1.
            dum1 = ( nextline - firstline ) / looplines.
            DO dum1 TIMES.
              firstline = firstline + looplines - 1.
            ENDDO.
          ENDIF.
        ENDIF.
        l = nextline - firstline + 1.
      ELSE.
        l = nextline.
      ENDIF.
      MOVE: firstline TO <status>-firstline,
            l         TO <status>-cur_line.
      DESCRIBE TABLE extract LINES maxlines.
    ENDIF.
    MOVE: stat TO status-data,
          stat TO title-data.
  ENDIF.
  REFRESH vim_copied_indices.
  SUBTRACT 1 FROM vim_copy_call_level.
  IF vim_special_mode NE vim_delimit.
    MESSAGE s014(sv) WITH counter.
  ELSE.
    IF counter EQ 1.
      MESSAGE s122(sv).
    ELSE.
      MESSAGE s123(sv) WITH counter.
    ENDIF.
  ENDIF.
  status-action = aendern.
  IF title-action NE hinzufuegen.
    title-action = aendern.
  ENDIF.
  CLEAR vim_old_viewkey.
  TRANSLATE vim_no_mainkey_exists USING vim_no_mkey_not_procsd_patt.
  IF function EQ 'ABR '.
    vim_next_screen = liste. vim_leave_screen = 'X'.
  ELSEIF function NE 'IGN '.
    IF vim_special_mode EQ vim_delimit AND status-mode EQ detail_bild.
      function = 'DETA'.
    ELSE.
      CLEAR function.
    ENDIF.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM KOPIERE_EINTRAG                                          *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  ORIGIN                                                        *
*---------------------------------------------------------------------*
FORM kopiere_eintrag USING origin.
  DATA: ke_index LIKE sy-tabix, ke_rc LIKE sy-subrc, ke_hf TYPE i.
  field-symbols: <x_origin> type x.

  IF status-mode EQ list_bild AND function NE 'KOPF' AND "scrolling &
     <status>-upd_flag EQ space.       "no changes
    EXIT.
  ENDIF.
  assign origin to <x_origin> casting.
  IF vim_special_mode NE vim_delimit.
    IF x_header-guidflag <> space.
      PERFORM vim_make_guid using space.
    ENDIF.
    IF x_header-frm_on_new NE space.
      IF replace_mode NE space.
        <status>-mk_to = mark_total.
        <status>-mk_xt = mark_extract.
        vim_next_screen = 0. vim_leave_screen = 'X'.
        EXIT.
      ENDIF.
      PERFORM (x_header-frm_on_new) IN PROGRAM (sy-repid).
    ENDIF.
    IF <f1_x> EQ <x_origin>.
      PERFORM set_pf_status USING 'ERROR'.
      MESSAGE e015(sv).
      EXIT.
    ELSE.
      neuer = 'J'.
      PERFORM check_key.
      neuer = 'N'.
      CHECK sy-subrc NE 0.
      MOVE: sy-subrc TO ke_rc,
            sy-tabix TO ke_index.
    ENDIF.
  ELSE.
    READ TABLE total WITH KEY <f1_x> BINARY SEARCH.
    MOVE: sy-subrc TO ke_rc,
          sy-tabix TO ke_index.
  ENDIF.
* gültiger Eintrag.
  IF vim_special_mode NE vim_delimit.  "copy mode
    IF x_header-bastab NE space AND x_header-texttbexst NE space AND
       <status>-upd_flag EQ 'E'.
      PERFORM (vim_frm_text_upd_flag) IN PROGRAM.
    ENDIF.
    IF x_header-adrnbrflag NE space.
      PERFORM address_maintain.
    ENDIF.
    IF x_header-texttbexst <> space.   "SW Textcopy
      PERFORM vim_copy_texttab_entry USING <f1_x> <vim_xextract_key>.
    ENDIF.
    IF vim_called_by_cluster NE space.
      PERFORM vim_store_state_info.
      CALL FUNCTION 'VIEWCLUSTER_COPY_DEPENDENT'
           EXPORTING
                view_name   = x_header-viewname
                maintview   = x_header-maintview
                status_mode = status-mode
                workarea    = extract
                new_entry   = <table1>
                no_dialog   = vim_external_mode.
      PERFORM vim_restore_state_info.
    ENDIF.
  ENDIF.
  IF vim_special_mode NE vim_delimit OR ke_rc NE 0.
    <action> = neuer_eintrag.
    <mark> = nicht_markiert.
  ELSE.                                "delimit mode and existing entry
    IF <action> EQ original. <action> = aendern. ENDIF.
  ENDIF.
  ADD 1 TO counter.
*  MOVE <table1> TO total(x_header-tablen).
  MOVE <table1> TO <vim_total_struc>.
  IF x_header-bastab NE space AND x_header-texttbexst NE space AND
     <status>-upd_flag EQ 'X' OR <status>-upd_flag EQ 'T'.
    MOVE <table1_xtext> TO <vim_xtotal_text>.
    IF vim_special_mode NE vim_delimit OR ke_rc NE 0.
      MOVE neuer_eintrag TO <action_text>.
    ELSE.
      IF <action_text> EQ original. <action_text> = aendern. ENDIF.
    ENDIF.
  ENDIF.
  vim_copied_indices-ex_ix = nextline.
  vim_copied_indices-level = vim_copy_call_level.
  CASE ke_rc.
    WHEN 0.
      MODIFY total INDEX ke_index.
      READ TABLE vim_copied_indices WITH KEY ix = ke_index
                                    BINARY SEARCH
                                    TRANSPORTING NO FIELDS.
      IF sy-subrc NE 0.
        vim_copied_indices-ix = ke_index.
        INSERT vim_copied_indices INDEX sy-tabix.
      ENDIF.
    WHEN 4.
      INSERT total INDEX ke_index.
      READ TABLE vim_copied_indices WITH KEY ix = ke_index
                                    BINARY SEARCH
                                    TRANSPORTING NO FIELDS.
      vim_copied_indices-ix = ke_index.
      INSERT vim_copied_indices INDEX sy-tabix.
      ke_hf = sy-tabix + 1.
      LOOP AT vim_copied_indices FROM ke_hf.
        ADD 1 TO vim_copied_indices-ix.
        MODIFY vim_copied_indices.
      ENDLOOP.
    WHEN 8.
      APPEND total.
      vim_copied_indices-ix = ke_index.
      APPEND vim_copied_indices.
  ENDCASE.
  neuer = 'N'.
  <status>-upd_flag = space.
  READ TABLE total WITH KEY <x_origin> BINARY SEARCH.
  IF sy-subrc = 0 AND <mark> EQ markiert.
    <mark> = nicht_markiert.
    SUBTRACT 1 FROM mark_total.
    MODIFY total INDEX sy-tabix.
  ENDIF.
  IF status-mode EQ detail_bild.
    vim_next_screen = 0. vim_leave_screen = 'X'.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM CALL_DYNPRO                                              *
*---------------------------------------------------------------------*
*       UF170200: transp. mode: don't fill CORR_KEYTAB-TABKEY with
*                 more than 120 chars
*
*---------------------------------------------------------------------*
FORM call_dynpro.
  DATA: state_init TYPE c, rc LIKE sy-subrc,
        dpl_sel_entries TYPE i, cd_specmode_safe(1) TYPE c,
        addr_e071k LIKE e071k, cd_addr_71ktab LIKE e071k OCCURS 0,
        object_key TYPE ad_objkey,
        max_trsp_keylength_in_byte type i.

  field-symbols: <object_keyx> type x.

  max_trsp_keylength_in_byte = vim_max_trsp_keylength
   * cl_abap_char_utilities=>charsize.
  CASE vim_adjust_middle_level_mode.
    WHEN space.
    WHEN subset OR 'X'.
      vim_special_mode = vim_direct_upgrade.
      IF vim_adjust_middle_level_mode EQ subset.
        x_namtab[] = vim_adj_namtab.
      ENDIF.
    WHEN 'L'.
      CLEAR vim_adjust_middle_level_mode. function = 'ENDE'.
      EXIT.
  ENDCASE.
* IF <STATUS>-ALR_SETUP EQ SPACE.
  IF <status>-initializd EQ space.
    PERFORM init_state_vector.
  ENDIF.
  DESCRIBE TABLE dpl_sellist LINES dpl_sel_entries.
  IF x_header-selection EQ space.
    IF dpl_sel_entries GT 0.
      MOVE 'X' TO x_header-selection.
      MODIFY x_header INDEX 1.
      ASSIGN dpl_sellist-*sys* TO <vim_ck_sellist>.
    ELSE.
      DESCRIBE TABLE dba_sellist.
      IF sy-tfill GT 0.
        MOVE 'X' TO x_header-selection.
        MODIFY x_header INDEX 1.
*       ASSIGN DBA_SELLIST-*SYS* TO <VIM_CK_SELLIST>.
      ENDIF.
      ASSIGN dba_sellist-*sys* TO <vim_ck_sellist>.
    ENDIF.
  ELSE.
    IF dpl_sel_entries GT 0.
      ASSIGN dpl_sellist-*sys* TO <vim_ck_sellist>.
    ELSE.
      ASSIGN dba_sellist-*sys* TO <vim_ck_sellist>.
    ENDIF.
  ENDIF.
  PERFORM vim_maint_selflag USING 'I'
                            CHANGING x_header-selection.
* Übergangslösung Sortierungsproblem Anfang
  IF <status>-alr_sorted EQ space.
    SORT total BY <vim_xtotal_key>.
    MOVE 'X' TO <status>-alr_sorted.
  ENDIF.
* Übergangslösung Sortierungsproblem Ende
  PERFORM exclude_cua_functions.
  IF x_header-frm_on_aut NE space AND  "4.5a: support indiv. auth. chck
     <status>-auth_check NE space.     "auth check is requested
    vim_auth_action = view_action.
    vim_auth_event = vim_auth_requested_check.
    ASSIGN <vim_ck_sellist> TO <vim_auth_sellist>.
    PERFORM (x_header-frm_on_aut) IN PROGRAM.
    IF vim_auth_rc NE 0.
      PERFORM vim_process_message USING vim_auth_msgid 'I' 'E'
                                        vim_auth_msgno
                                        vim_auth_msgv1 vim_auth_msgv2
                                        vim_auth_msgv3 vim_auth_msgv4.
      CASE vim_auth_rc.
        WHEN 4.                        "show only
          maint_mode = anzeigen.
          excl_cua_funct-function = 'AEND'. COLLECT excl_cua_funct.
        WHEN 8.                        "exit
          RAISE missing_corr_number.
      ENDCASE.
    ENDIF.
  ENDIF.
  IF maint_mode NE anzeigen AND maint_mode NE transportieren AND
     <status>-dlclalrckd EQ space.
    IF vim_system_type NE 'SAP' AND
       x_header-customauth CO sap_only_classes.
*     MESSAGE I137(SV). "keine Änderungen, Daten gehören SAP
      PERFORM vim_process_message USING 'SV' 'I' 'I' '137'
                                        space space space space.
    ENDIF.
    MOVE 'X' TO <status>-dlclalrckd.
  ENDIF.
  IF x_header-subsetflag NE space AND <status>-sbsid_rcvd CO ' R'.
    PERFORM init_subset_keyfields.
  ENDIF.
  IF x_header-selection NE space AND <status>-selcd_rcvd EQ space.
    LOOP AT dpl_sellist WHERE ddic EQ space OR ( operator EQ 'GE' OR
                                                 operator EQ 'GT' OR
                                                 operator EQ 'LE' OR
                                                 operator EQ 'LT' ).
      MOVE 'X' TO state_init.
      EXIT.
    ENDLOOP.
    IF sy-subrc NE 0. "no entries in DPL_SELLIST -> all entries req.
      DESCRIBE TABLE total.
      IF <status>-maxlines NE sy-tfill AND  "missing entries in EXTRACT
         <status>-st_data EQ gesamtdaten.   "and no selection made
        IF x_header-delmdtflag NE space.
*         DESCRIBE TABLE VIM_COLLAPSED_MAINKEYS. "SW int.M. 1599934/1999
*         IF <STATUS>-MAXLINES NE SY-TFILL."missing entries in EXTRACT
          IF <status>-maxlines = 0.    "SW int.M. 1599934/1999
            MOVE 'X' TO state_init.
          ENDIF.
        ELSE.
          MOVE 'X' TO state_init.
        ENDIF.
      ENDIF.
    ENDIF.
    IF state_init NE space.
      CLEAR: <status>-maxlines,
             <status>-cur_field,
             <status>-cur_offset.
      MOVE: 1 TO <status>-cur_line,
            1 TO <status>-firstline,
            nicht_geloescht TO <status>-st_delete,
            maint_mode TO <status>-st_action,
            list_bild TO <status>-st_mode.
      PERFORM set_status_nokeyselcnds.
    ENDIF.
    MOVE 'X' TO <status>-selcd_rcvd.
  ENDIF.
  IF <status>-initializd EQ 'x'.
    PERFORM set_status_nokeyselcnds.
  ENDIF.
  IF maint_mode NE anzeigen AND
     corr_nbr NE space AND corr_nbr NE <status>-corr_nbr.
    MOVE: <status>-corr_nbr TO <status>-l_corr_nbr,
          corr_nbr TO <status>-corr_nbr.
  ENDIF.
  IF maint_mode EQ transportieren.
    PERFORM request_corr_number.
    IF x_header-flag EQ vim_transport_denied.
      MESSAGE i142(sv).
      function = ucomm = end. EXIT.
    ENDIF.
  ELSEIF maint_mode EQ aendern.
    PERFORM check_transp_objs_for_maint USING rc.
    CASE rc.
      WHEN 4.
        maint_mode = anzeigen.
        excl_cua_funct-function = 'AEND'. COLLECT excl_cua_funct.
      WHEN 8.
        RAISE missing_corr_number.
    ENDCASE.
  ELSE.
    vim_client_state = vim_noact.
  ENDIF.
  MOVE: maint_mode          TO status-action,
        <status>-st_delete  TO status-delete,
        <status>-st_data    TO status-data,
        <status>-title      TO title,
        <status>-firstline  TO firstline,
        <status>-mk_xt      TO mark_extract,
        <status>-mk_to      TO mark_total,
        <status>-cur_line   TO l,
        <status>-cur_field  TO f,
        <status>-cur_offset TO o,
        <status>-maxlines   TO maxlines,
        maint_mode          TO title-action,
        firstline           TO nextline.
  IF status-action EQ aendern AND   "ignore history when mode was chngd.
     <status>-st_action EQ hinzufuegen.
    MOVE: <status>-st_action TO status-action,
          <status>-st_action TO title-action.
  ENDIF.
  IF <status>-st_delete EQ geloescht.
    DESCRIBE TABLE extract LINES maxlines.
    IF maxlines EQ 0.
      CLEAR status-delete.
      MOVE list_bild TO <status>-st_mode.
    ENDIF.
  ELSEIF <status>-st_mode = detail_bild"SW (1248405/98) ..
     AND <status>-st_action <> hinzufuegen.
    DESCRIBE TABLE extract LINES maxlines.
    IF maxlines EQ 0.
      MOVE list_bild TO <status>-st_mode.
*    nur ein Eintrag  -> automatisch wieder auf Detailbild verzweigt
*    mehrere Einträge -> Listbild, da kein Eintrag ausgezeichnet
    ENDIF.                             ".. SW
  ENDIF.
  IF ( status-action EQ transportieren AND                  "UF28042000
      <status>-l_corr_nbr NE <status>-corr_nbr )
   OR ( vim_client_state EQ vim_log AND 'ST' NS status-action ) .
    PERFORM prepare_corr.
  ENDIF.
  IF status-action EQ transportieren AND get_corr_keytab NE space.
    PERFORM get_keytab.
  ENDIF.
  IF status-action EQ transportieren AND <status>-crcntsknwn EQ space.
    LOOP AT vim_addr_e071k_tab INTO addr_e071k.
      addr_e071k-trkorr = <status>-corr_nbr.
      MODIFY vim_addr_e071k_tab FROM addr_e071k.
    ENDLOOP.
    LOOP AT total.    "note entries already contained in CORR_KEYTAB
      MOVE <vim_total_struc> TO <table1>.
      IF x_header-bastab EQ space.     "view
        PERFORM (corr_formname) IN PROGRAM (sy-repid) USING pruefen rc.
      ELSE.                            "base table
        corr_keytab =  e071k.
        corr_keytab-objname = x_header-maintview.
        IF x_header-keylen GT max_trsp_keylength_in_byte.
*        IF x_header-keylen GT vim_max_trsp_keylength.     "UF170200b
          MOVE <vim_xtotal_key> TO <vim_corr_keyx>(x_header-maxtrkeyln).
*          MOVE total TO corr_keytab-tabkey(x_header-maxtrkeyln).
        ELSE.                          "UF170200e
          MOVE <vim_xtotal_key> TO <vim_corr_keyx>(x_header-keylen).
*          MOVE total TO corr_keytab-tabkey(x_header-keylen).
        ENDIF.                                              "UF170200
        PERFORM update_corr_keytab USING pruefen rc.
        IF rc EQ 0.
          IF x_header-texttbexst NE space AND  "text table
             <vim_xtotal_text> NE <text_initial_x>.
*             <total_text> NE <text_initial>.
            corr_keytab =  e071k.
            corr_keytab-objname = x_header-texttab.
            IF x_header-textkeylen GT max_trsp_keylength_in_byte.
*           IF x_header-textkeylen GT vim_max_trsp_keylength. "UF170200b
              MOVE <vim_xtotal_text> TO
                             <vim_corr_keyx>(x_header-maxtrkeyln).
*              MOVE <total_text> TO
*                             corr_keytab-tabkey(x_header-maxtrtxkln).
            ELSE.                      "UF170200e
              MOVE <vim_xtotal_text> TO
                             <vim_corr_keyx>(x_header-textkeylen).
*              MOVE <total_text> TO
*                             corr_keytab-tabkey(x_header-textkeylen).
            ENDIF.                                          "UF170200
            PERFORM update_corr_keytab USING pruefen rc.
          ENDIF.
        ENDIF.
      ENDIF.
      IF rc = 0 AND x_header-texttbexst <> space AND "SW Texttransl ..
        vim_texttab_is_ro EQ space.
        PERFORM vim_text_keytab_entry USING <vim_xtotal_key> pruefen rc.
      ENDIF.                           ".. Texttransl
      IF rc EQ 0.
        MOVE transportieren TO <action>.
        IF x_header-adrnbrflag EQ 'O' AND <address_number> NE space.
          PERFORM vim_address_keytab_entries USING pruefen rc.
        ELSEIF x_header-adrnbrflag EQ 'N' AND <address_number> NE space.
          APPEND LINES OF vim_addr_e071k_tab TO cd_addr_71ktab.
          assign object_key to <object_keyx> casting.
          move <vim_xtotal_key> to <object_keyx>(x_header-keylen).
*          object_key = <vim_total_key>.
          CALL FUNCTION 'ADDR_TRANSPORT_ENTRIES'
               EXPORTING
                    addrnumber = <address_number>
                    table_name = vim_addr_basetable
                    field_name = vim_addr_bastab_field
                    objkey     = object_key
               TABLES
                    e071k_tab  = cd_addr_71ktab.
          vim_exit_11_12_active = 'X'.
          LOOP AT cd_addr_71ktab INTO corr_keytab WHERE
           mastername = vim_addr_e071k_master_46 or    "UF688403/2000
           mastername = vim_addr_e071k_master.
* Rel < 4.6A: ignore old type address entries inserted only for downward
*             compatibility
            PERFORM update_corr_keytab USING pruefen rc.
            IF rc NE 0. EXIT. ENDIF.
          ENDLOOP.
          CLEAR vim_exit_11_12_active.
        ENDIF.
        IF rc EQ 0.
          IF x_header-frm_e071ks NE space.
            vim_exit_11_12_active = 'X'.
            MOVE pruefen TO corr_action.
            PERFORM (x_header-frm_e071ks) IN PROGRAM (sy-repid).
            IF sy-subrc NE 0. CLEAR <action>. ENDIF.
            CLEAR vim_exit_11_12_active.
          ENDIF.
        ELSE.
          CLEAR <action>.
        ENDIF.
      ELSE.
        CLEAR <action>.
      ENDIF.
      IF maxlines GT 0 AND
         vim_special_mode NE vim_extedit.                "SW 1.4.1998
        READ TABLE extract WITH KEY <f1_x>.
        IF sy-subrc EQ 0.
          MOVE: <mark> TO <xmark>, <action> TO <xact>.
          MODIFY extract INDEX sy-tabix.
        ENDIF.
      ENDIF.
      MODIFY total.
    ENDLOOP.
    MOVE 'X' TO <status>-crcntsknwn.
  ENDIF.
  IF vim_restore_mode NE space.
    status-mode = <status>-st_mode.
    CLEAR vim_restore_mode.
    EXIT.
  ENDIF.
  IF vim_special_mode NE vim_extedit.
    CASE vim_single_entry_function.
      WHEN space OR 'UPD' OR 'SHOW'.
        IF <status>-st_mode EQ detail_bild.
          MOVE: 'DETA' TO function,
                nextline TO firstline.
          nextline = firstline + l - 1.
          DESCRIBE TABLE extract LINES maxlines.
          IF maxlines EQ 0.
            IF <status>-st_action EQ hinzufuegen.
              neuer = 'J'.
            ELSE.
              PERFORM fill_extract.
            ENDIF.
          ENDIF.
*         CALL SCREEN DETAIL.
          PERFORM process_detail_screen USING 'C'.
        ELSE.
          CALL SCREEN liste.
        ENDIF.
      WHEN 'INS'.
        function = 'NEWL'. PERFORM hinzufuegen.
      WHEN 'DEL'.
        cd_specmode_safe = vim_special_mode.
        vim_special_mode = vim_extedit.
        READ TABLE total INTO extract INDEX 1. <xact> = geloescht.
        APPEND extract.
        PERFORM vim_external_edit.
        vim_special_mode = cd_specmode_safe.
        excl_cua_funct-function = 'UNDO'. COLLECT excl_cua_funct.
        PERFORM selektiere USING geloescht.
    ENDCASE.
    MOVE: function TO ucomm.
* only relevant in viewcluster(navigation from detail screen):
    IF status-mode = detail_bild.
      last_act_entry = nextline.
    ELSE.
* navigation in viewcluster by tree-control: unuseable
      last_act_entry = <status>-firstline + <status>-cur_line - 1.
    ENDIF.
  ELSE.                                "ext. edit.
    PERFORM vim_external_edit.
    <status>-maxlines = 0.             "SW  int. Meldung 519239/1999
  ENDIF.
  IF function NE 'ORGD' AND function NE 'ORGL' AND
     function NE 'SAVE' AND function NE 'TRSP' AND function NE 'TRAE'.
    IF x_header-subsetflag NE space AND <status>-sbsid_rcvd NE 'S'.
      CLEAR <status>-sbsid_rcvd.
    ENDIF.
*   ELSEIF X_HEADER-SUBSETFLAG EQ SPACE AND
    IF x_header-selection NE space AND
       <status>-selcd_rcvd NE space.
      CLEAR <status>-selcd_rcvd.
    ENDIF.
    IF x_header-delmdtflag NE space.
      EXPORT vim_collapsed_mainkeys TO MEMORY ID vim_memory_id_1.
    ENDIF.
    ASSIGN dba_sellist-*sys* TO <vim_sellist>.
    vim_enqueue_range = x_header-subsetflag.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM VIM_STORE_STATE_INFO                                     *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM VIM_STORE_STATE_INFO.
  MOVE: STATUS-DATA TO <STATUS>-ST_DATA,
        STATUS-MODE TO <STATUS>-ST_MODE,
        STATUS-DELETE TO <STATUS>-ST_DELETE,
        STATUS-ACTION TO <STATUS>-ST_ACTION,
        TITLE         TO <STATUS>-TITLE,
        MAXLINES      TO <STATUS>-MAXLINES,
        F             TO <STATUS>-CUR_FIELD,
        O             TO <STATUS>-CUR_OFFSET,
        FUNCTION      TO <STATUS>-FCODE.
  IF L EQ 0.
    MOVE 1 TO <STATUS>-CUR_LINE.
  ELSE.
    MOVE L TO <STATUS>-CUR_LINE.
  ENDIF.
ENDFORM.                               "vim_store_state_info

*---------------------------------------------------------------------*
*       FORM VIM_RESTORE_STATE_INFO                                   *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM VIM_RESTORE_STATE_INFO.
  STATUS-DATA = <STATUS>-ST_DATA.
  STATUS-MODE =  <STATUS>-ST_MODE.
  STATUS-DELETE =  <STATUS>-ST_DELETE.
  STATUS-ACTION =  <STATUS>-ST_ACTION.
  TITLE         =  <STATUS>-TITLE.
  MAXLINES      =  <STATUS>-MAXLINES.
  F             =  <STATUS>-CUR_FIELD.
  O             =  <STATUS>-CUR_OFFSET.
  FUNCTION      =  <STATUS>-FCODE.
  L = <STATUS>-CUR_LINE.
ENDFORM.                               "vim_restore_state_info

*---------------------------------------------------------------------*
*       FORM VIM_EXTERNAL_EDIT                                        *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM vim_external_edit.
  TYPES: vee_sellist LIKE vimsellist OCCURS 10.
  DATA: ee_rc TYPE i, upd_flags(3) TYPE c, del_flags(3) TYPE c,
      h_flag(1) TYPE c, repmode_safe(1) TYPE c, specmode_safe(1) TYPE c,
        extmode_safe(1) TYPE c, vee_results LIKE vimmodres, h_ix TYPE i.
  FIELD-SYMBOLS: <h_sellist> TYPE vee_sellist, <hf> TYPE ANY.

  IF maint_mode EQ anzeigen.
    vee_results-rc_udl = vee_results-rc_ins = vee_results-rc_upd =
    vee_results-rc_del = vee_results-rc_tin = vee_results-rc_del = 8.
    vim_results_of_ext_mod = vee_results.
    EXIT.
  ENDIF.
  MOVE: aendern TO upd_flags, neuer_eintrag TO upd_flags+1,
        kopieren TO upd_flags+2,
        geloescht TO del_flags, update_geloescht TO del_flags+1,
        neuer_geloescht TO del_flags+2.
  repmode_safe = replace_mode. replace_mode = 'X'.
  specmode_safe = vim_special_mode. vim_special_mode = vim_upgrade.
  extmode_safe = vim_external_mode. vim_external_mode = 'X'.
  maxlines = 1.
  clear <status>-bcfixdelinfosent.
  LOOP AT extract.
    IF <xact> EQ zurueckholen.
      h_flag = status-delete. status-delete = geloescht.
      PERFORM vim_mark_and_process USING sy-tabix 'UNDO'
                                         vee_results-nbr_of_udl
                                         vee_results-rc_udl.
      status-delete = h_flag.
      ee_rc = vee_results-rc_udl.
    ELSEIF <xact> CO upd_flags.
      IF <xact> EQ kopieren.
        h_ix = sy-tabix + 1.
        vim_extcopy_mode = 'X'.
        <xact> = neuer_eintrag.
        ASSIGN <vim_ck_sellist> TO <h_sellist>.
        LOOP AT <h_sellist> INTO dpl_sellist
                            WHERE value EQ space AND initial EQ space.
* check if sellist is filled completely & fill it if not
          READ TABLE x_namtab INDEX dpl_sellist-tabix.
          IF sy-subrc EQ 0.
            IF x_header-bastab = space.
* view
              ASSIGN COMPONENT x_namtab-viewfield
               OF STRUCTURE <vim_total_struc> TO <hf>.
            ELSE.
              IF x_namtab-texttabfld NE space.
* Type S: text field
                ASSIGN COMPONENT x_namtab-viewfield
                 OF STRUCTURE <vim_ext_txt_struc> TO <hf>.
              ELSE.
* Type S: key field
                ASSIGN COMPONENT x_namtab-viewfield
                 OF STRUCTURE <vim_extract_struc> TO <hf>.
              ENDIF.
            ENDIF.
*            ASSIGN TOTAL+X_NAMTAB-POSITION(X_NAMTAB-FLENGTH) TO <HF>.
            READ TABLE extract INTO total INDEX h_ix.
            dpl_sellist-value = <hf>.
            IF <hf> EQ space. dpl_sellist-initial = 'X'. ENDIF.
            CLEAR dpl_sellist-converted.
            MODIFY <h_sellist> FROM dpl_sellist.
          ENDIF.
        ENDLOOP.
      ENDIF.
      h_flag = <xact>.
      PERFORM vim_modify_view_entry USING sy-tabix ee_rc.
      CLEAR vim_extcopy_mode.
      DELETE extract.                                       "190298
      IF ee_rc EQ 0.
        IF h_flag EQ neuer_eintrag.
          ADD 1 TO vee_results-nbr_of_ins.
        ELSE.
          ADD 1 TO vee_results-nbr_of_upd.
        ENDIF.
      ELSE.
        IF h_flag EQ neuer_eintrag.
          vee_results-rc_ins = ee_rc.
        ELSE.
          vee_results-rc_upd = ee_rc.
        ENDIF.
      ENDIF.
    ELSEIF <xact> CO del_flags.
      PERFORM vim_mark_and_process USING sy-tabix 'DELE'
                                         vee_results-nbr_of_del
                                         vee_results-rc_del.
      ee_rc = vee_results-rc_del.
    ELSEIF <xact> EQ task_add.
      PERFORM vim_mark_and_process USING sy-tabix 'TRIN'
                                         vee_results-nbr_of_tin
                                         vee_results-rc_tin.
      ee_rc = vee_results-rc_tin.
    ELSEIF <xact> EQ task_del.
      PERFORM vim_mark_and_process USING sy-tabix 'TREX'
                                         vee_results-nbr_of_tex
                                         vee_results-rc_tex.
      ee_rc = vee_results-rc_tex.
    ENDIF.
    IF ee_rc EQ 8. EXIT. ENDIF.
    IF <status>-bcfixdelinfosent EQ 'X'.
      <status>-bcfixdelinfosent = 'Y'.
    ENDIF.
  ENDLOOP.
  clear <status>-bcfixdelinfosent.
  vim_results_of_ext_mod = vee_results.
* CLEAR: REPLACE_MODE, VIM_SPECIAL_MODE, VIM_EXTERNAL_MODE.
  replace_mode = repmode_safe. vim_special_mode = specmode_safe.
  vim_external_mode = extmode_safe.
ENDFORM.                               "external_edit

*---------------------------------------------------------------------*
*       FORM VIM_MARK_AND_PROCESS                                     *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM VIM_MARK_AND_PROCESS USING VALUE(VMAP_EXIX) TYPE I
                                VALUE(VMAP_OKCODE) LIKE OK_CODE
                                VMAP_NBR TYPE I VMAP_RC TYPE I.
  DATA: VMAP_I_RC TYPE I.
  READ TABLE TOTAL WITH KEY <VIM_xEXTRACT_KEY> BINARY SEARCH.
  <MARK> = MARKIERT. ADD 1 TO MARK_TOTAL.
  MODIFY TOTAL INDEX SY-TABIX.
  <XACT> = <ACTION>.
  <XMARK> = MARKIERT. ADD 1 TO MARK_EXTRACT.
  MODIFY EXTRACT.
  PERFORM VIM_PROCESS_VIEW_ENTRY USING VMAP_EXIX VMAP_OKCODE VMAP_I_RC.
  IF VMAP_I_RC EQ 0.
    ADD 1 TO VMAP_NBR.
  ELSE.
    VMAP_RC = VMAP_I_RC.
  ENDIF.
ENDFORM.                               "vim_mark_and_process

*---------------------------------------------------------------------*
*       FORM CHECK_DYNAMIC_SELECT_OPTIONS                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM check_dynamic_select_options.
  DATA: total_ix TYPE i VALUE '2', flag.
  DATA: cdso_sellist LIKE vimsellist OCCURS 10,
        oc_to_be_checked TYPE xfeld,
        keyvalues TYPE occheckkeyflds,
        activity TYPE xuval.
  FIELD-SYMBOLS: <vim_tot_txt_struc_loc> TYPE ANY.

  IF x_header-delmdtflag NE space.
    PERFORM build_mainkey_tab_0.
  ENDIF.
  IF x_header-subsetflag NE space.
    MOVE 'R' TO <status>-sbsid_rcvd.
    LOOP AT dba_sellist WHERE ddic CO vim_subset_marks
                          AND value EQ space
                          AND initial EQ space.
      CLEAR <status>-sbsid_rcvd. EXIT.
    ENDLOOP.
  ENDIF.
  READ TABLE total INDEX 1.
  IF sy-subrc NE 0.
    EXIT.
  ENDIF.
  IF NOT vim_oc_inst IS INITIAL.
* check authorisation for lines: only for conditions from authorisation
* which could not be included into dba_sellist
    CALL METHOD vim_oc_inst->get_to_be_checked
      IMPORTING
        to_be_checked = oc_to_be_checked.
    IF oc_to_be_checked <> space.
      IF <status>-st_action = anzeigen.
        activity = svorg_read.
      ELSE.
        activity = svorg_maint.
      ENDIF.
      LOOP AT total.
        CALL METHOD vim_oc_inst->build_key_value_tab
          EXPORTING
            entry     = total
          IMPORTING
            keyvalues = keyvalues.
        CALL METHOD vim_oc_inst->check_oc_authority
          EXPORTING
            activity        = activity
          CHANGING
            key_values      = keyvalues
           EXCEPTIONS
             no_auth         = 1
             key_incomplete  = 2
*          WRONG_PARAMETER = 3
             OTHERS          = 4.
        IF sy-subrc = 1.
          DELETE total.
*       MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
      ENDLOOP.
    ENDIF.
  ENDIF.
  LOOP AT dba_sellist.
    IF dba_sellist-ddic CO ddic_marks. "only ddic-limits
      READ TABLE x_namtab INDEX dba_sellist-tabix.
      IF x_namtab-texttabfld NE space OR x_header-bastab EQ space AND
         x_namtab-bastabname NE x_header-roottab.
        CLEAR dba_sellist-ddic.
      ENDIF.
    ENDIF.
    APPEND dba_sellist TO cdso_sellist.
  ENDLOOP.
  IF x_header-bastab <> space AND x_header-texttbexst <> space.
    ASSIGN <vim_tot_txt_struc> TO <vim_tot_txt_struc_loc>.
  ELSE.
    ASSIGN <vim_total_struc> TO <vim_tot_txt_struc_loc>.
  ENDIF.
  CALL FUNCTION 'TABLE_RANGE_CHECK'
    EXPORTING
      tabname                   = x_header-maintview
      entry                     = total
      entry_text                = <vim_tot_txt_struc_loc>
      ddic                      = 'N'
      key                       = 'N'
      ignore_blank_subsetfields = 'J'
    TABLES
      x_namtab                  = x_namtab
      x_header                  = x_header
      sellist                   = cdso_sellist
    EXCEPTIONS
      entry_not_fits            = 1
      no_value_for_subset_ident = 2.
  CASE sy-subrc.
    WHEN 0.
      IF x_header-delmdtflag NE space.
        PERFORM build_mainkey_tab_1. flag = 'X'.
      ENDIF.
    WHEN 1.
      DELETE total INDEX 1.
      SUBTRACT 1 FROM total_ix.
    WHEN 2.
      CLEAR <status>-sbsid_rcvd.
  ENDCASE.
  LOOP AT total FROM total_ix.
    CALL FUNCTION 'TABLE_RANGE_CHECK'
      EXPORTING
        tabname                   = x_header-maintview
        entry                     = total
        entry_text                = <vim_tot_txt_struc_loc>
        ddic                      = 'N'
        key                       = 'N'
        ignore_blank_subsetfields = 'J'
      TABLES
        x_namtab                  = x_namtab
        x_header                  = x_header
        sellist                   = cdso_sellist
      EXCEPTIONS
        entry_not_fits            = 1
        no_value_for_subset_ident = 2.
    CASE sy-subrc.
      WHEN 0.
        IF x_header-delmdtflag NE space.
          PERFORM build_mainkey_tab_1. flag = 'X'.
        ENDIF.
      WHEN 1.
        DELETE total.
      WHEN 2.
        CLEAR <status>-sbsid_rcvd.
    ENDCASE.
  ENDLOOP.
  IF flag NE space.
    PERFORM build_mainkey_tab_2.
  ENDIF.
ENDFORM.                    "check_dynamic_select_options

*---------------------------------------------------------------------*
*       FORM MODIFY_TABLES                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  VALUE(TAB_INDEX)                                              *
*---------------------------------------------------------------------*
FORM modify_tables USING value(tab_index).
  CLEAR <status>-upd_flag.
  IF <xmark> EQ markiert.
    SUBTRACT: 1 FROM <status>-mk_xt,
              1 FROM <status>-mk_to.
  ENDIF.
  READ TABLE total WITH KEY <vim_xextract_key> BINARY SEARCH.
  MOVE <table1> TO <vim_extract_struc>.
  IF x_header-bastab NE space AND x_header-texttbexst NE space.
    MOVE: <table1_xtext> TO <vim_xextract_text>,
          original TO <xact_text>.
  ENDIF.
  <xmark> = nicht_markiert.
  <xact> = original.
  IF tab_index NE 0.
    MODIFY extract INDEX tab_index.
  ENDIF.
  total = extract.
  MODIFY total INDEX sy-tabix.
  IF x_header-frm_on_org NE space.
    PERFORM (x_header-frm_on_org) IN PROGRAM (sy-repid).
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM INIT_SUBSET_KEYFIELDS                                    *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM init_subset_keyfields.
  DATA: all_flds_blank TYPE c VALUE 'X', state_init TYPE c.
  FIELD-SYMBOLS: <key> type x.
  ASSIGN <initial_x>(x_header-keylen) TO <key>.
  clear <table1_wa>.
  MOVE <key> TO <f1_wax>.
  IF <status>-sbsid_rcvd NE space.
    CALL FUNCTION 'VIEW_INIT_SUBST_KEYFLDS'
         EXPORTING
              visk_tabname         = x_header-maintview
              workarea_in          = <initial>
         IMPORTING
              workarea_out         = <initial>
              all_fields_blank     = all_flds_blank
              state_init_necessary = state_init
         TABLES
              sellist              = dba_sellist
              x_namtab             = x_namtab.
  ELSE.
    CALL FUNCTION 'VIEW_INIT_SUBST_KEYFLDS'
         EXPORTING
              visk_tabname         = x_header-maintview
              workarea_in          = <initial>
         IMPORTING
              workarea_out         = <initial>
              all_fields_blank     = all_flds_blank
              state_init_necessary = state_init
         TABLES
              sellist              = dpl_sellist
              x_namtab             = x_namtab.
    IF all_flds_blank NE space.
      RAISE no_value_for_subset_ident.
    ENDIF.
    IF <key> NE <f1_wax>.
      MOVE 'X' TO state_init.
    ELSE.  "nicht-Key Subsetfelder, für die in ZP19 Keyflag gesetzt
      LOOP AT x_namtab where keyflag  <> SPACE  AND
                             readonly =  subset AND
                             position >= x_header-keylen.
        MOVE 'X' TO state_init. EXIT.
      ENDLOOP.
    ENDIF.
    IF state_init NE space.
      CLEAR: <status>-maxlines,
             <status>-cur_field,
             <status>-cur_offset.
      MOVE: 1 TO <status>-cur_line,
            1 TO <status>-firstline,
            maint_mode TO <status>-st_action,
            nicht_geloescht TO <status>-st_delete,
            list_bild TO <status>-st_mode.
      PERFORM set_status_nokeyselcnds.
    ELSE.
* further selection criteria?
      LOOP AT dpl_sellist TRANSPORTING NO FIELDS
                          WHERE ddic EQ space OR ( operator EQ 'GE' OR
                                                   operator EQ 'GT' OR
                                                   operator EQ 'LE' OR
                                                   operator EQ 'LT' ).
        EXIT.
      ENDLOOP.
      IF sy-subrc <> 0 and <status>-maxlines <> 0.
        <status>-selcd_rcvd = 'X'.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM INIT_SUBSET_FCTFIELDS                                    *
*---------------------------------------------------------------------*
* init subset fields which are not keyfields                          *
*---------------------------------------------------------------------*
* FORMNAME --> name of FORM to get view work area filled with current *
*              subset field values                                    *
* PROGNAME --> program of FORM 'FORMNAME'                             *
*---------------------------------------------------------------------*
FORM init_subset_fctfields USING value(formname) value(progname).

  DATA: alr_read TYPE c.

  LOOP AT x_namtab WHERE readonly EQ subset AND keyflag EQ space.
    ASSIGN component x_namtab-viewfield of structure <initial>
           TO <subsetfield>.
    ASSIGN component x_namtab-viewfield of structure <table1>
           TO <value>.
    IF alr_read EQ space.
      MOVE <initial> TO <table1>.
      IF x_header-clidep NE space.
        MOVE sy-mandt TO <client>.
      ENDIF.
      IF x_header-frm_rp_cpl NE space.   "event AD
        PERFORM (x_header-frm_rp_cpl) IN PROGRAM (sy-repid).
      ELSEIF formname NE compl_formname OR progname NE sy-repid.
        PERFORM (formname) IN PROGRAM (progname) USING <table1>.
      ELSEIF maxlines EQ 0.
        PERFORM (compl_formname) IN PROGRAM (sy-repid) USING <table1>
                                 IF FOUND.
      ELSE.
        READ TABLE extract INDEX 1.
        MOVE <vim_extract_struc> TO <table1>.
      ENDIF.
      IF vim_called_by_cluster NE space.
        CALL FUNCTION 'VIEWCLUSTER_COMPL_SUBSET_VALUE'
             EXPORTING
                  view_name = x_header-viewname
             CHANGING
                  workarea  = <table1>.
      ENDIF.
      MOVE 'X' TO  alr_read.
    ENDIF.
    MOVE <value> TO <subsetfield>.
  ENDLOOP.
  IF sy-subrc NE 0 AND maxlines EQ 0.
    MOVE <initial> TO <table1>.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM FILL_SUBSETFIELDS                                        *
*---------------------------------------------------------------------*
*  fill subset fields in *view-wa                                     *
*---------------------------------------------------------------------*
FORM FILL_SUBSETFIELDS.
  DATA: progname LIKE sy-repid.
  IF <STATUS>-SBSID_RCVD CO ' R'.
    progname = sy-repid.
    PERFORM INIT_SUBSET_FCTFIELDS USING COMPL_FORMNAME progname.
    TRANSLATE <STATUS>-SBSID_RCVD USING ' XRS'.
  ELSE.
    IF MAXLINES EQ 0 OR VIM_CALLED_BY_CLUSTER NE SPACE.
      MOVE <INITIAL> TO <TABLE1>.
    ENDIF.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM COMPLETE_EXPROFIELDS                                     *
*---------------------------------------------------------------------*
*  fill read only fields of referenced tables (exp ro tables)         *
*---------------------------------------------------------------------*
FORM COMPLETE_EXPROFIELDS.
  IF X_HEADER-FRM_RP_CPL NE SPACE.
    PERFORM (X_HEADER-FRM_RP_CPL) IN PROGRAM.
  ELSE.
    PERFORM (COMPL_FORMNAME) IN PROGRAM (SY-REPID) USING <TABLE1>
                                 IF FOUND.
  ENDIF.
  IF VIM_CALLED_BY_CLUSTER NE SPACE.
    CALL FUNCTION 'VIEWCLUSTER_COMPL_SUBSET_VALUE'
         EXPORTING
              VIEW_NAME = X_HEADER-VIEWNAME
         CHANGING
              WORKAREA  = <TABLE1>.
  ENDIF.
ENDFORM.                               "complete_exprofields

*---------------------------------------------------------------------*
*       FORM COMPLETE_SUBSETFIELDS                                    *
*---------------------------------------------------------------------*
*  fill subset comment fields in view-wa from *view-wa (detail screen)*
*---------------------------------------------------------------------*
FORM complete_subsetfields.

  FIELD-SYMBOLS: <namtab> TYPE vimnamtab.

  LOOP AT x_namtab ASSIGNING <namtab>
   WHERE readonly EQ subset AND keyflag EQ space.
    ASSIGN: COMPONENT <namtab>-viewfield OF STRUCTURE <initial>
             TO <value>,
            COMPONENT <namtab>-viewfield OF STRUCTURE <table1>
             TO <subsetfield>.
*    ASSIGN <INITIAL>+X_NAMTAB-POSITION(X_NAMTAB-FLENGTH)
*           TO <VALUE>.
*    ASSIGN <TABLE1>+X_NAMTAB-POSITION(X_NAMTAB-FLENGTH)
*           TO <SUBSETFIELD>.
    MOVE <value> TO <subsetfield>.
  ENDLOOP.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM X_ENQUEUE                                                *
*---------------------------------------------------------------------*
* enqueue view (external call)                                        *
*---------------------------------------------------------------------*
* XE_SELLIST       ---> table of selection conditions for view/table  *
* VALUE(XE_NAME)   ---> name of view/table to process                 *
* VALUE(XE_ACT)    ---> action: E -> enqueue, D -> dequeue            *
* VALUE(EXIT_FORM) ---> name of exit form to process after enqueue    *
* VALUE(XE_ENQRNG) ---> flag: X -> enqueue range, ' ' -> full table   *
*---------------------------------------------------------------------*
FORM X_ENQUEUE TABLES XE_SELLIST STRUCTURE VIMSELLIST
               USING VALUE(XE_NAME) VALUE(XE_ACT) VALUE(EXIT_FORM)
                     VALUE(XE_ENQRNG).
  DATA: VIEWNAME_SAFE LIKE VIMDESC-VIEWNAME, ENQ_RANGE_SAFE(1) TYPE C.

  VIEWNAME_SAFE = VIM_VIEW_NAME. ENQ_RANGE_SAFE = VIM_ENQUEUE_RANGE.
  VIM_VIEW_NAME = XE_NAME. VIM_ENQUEUE_RANGE = XE_ENQRNG.
  ASSIGN XE_SELLIST-*SYS* TO <VIM_SELLIST>.
  PERFORM ENQUEUE USING XE_ACT EXIT_FORM.
  VIM_VIEW_NAME = VIEWNAME_SAFE. VIM_ENQUEUE_RANGE = ENQ_RANGE_SAFE.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM ENQUEUE                                                  *
*---------------------------------------------------------------------*
* enqueue view                                                        *
*---------------------------------------------------------------------*
* VALUE(E_ACT) --> action: E -> enqueue, D -> dequeue                 *
* VALUE(EXIT_FORM) ---> name of exit form to process after enqueue    *
*---------------------------------------------------------------------*
FORM enqueue USING value(e_act) value(exit_form).
*----------------------------------------------------------------------*
*      enqueue view
*----------------------------------------------------------------------*
  CALL FUNCTION 'VIEW_ENQUEUE'
       EXPORTING
            view_name        = vim_view_name
            action           = e_act
            enqueue_mode     = 'E'
            enqueue_range    = vim_enqueue_range
       TABLES
            sellist          = <vim_sellist>
       EXCEPTIONS
            foreign_lock     = 1
            system_failure   = 2
            table_not_found  = 5
            client_reference = 7.

  DATA: rc LIKE sy-subrc.

  CASE sy-subrc.
    WHEN 1.
      MESSAGE i049(sv) WITH sy-msgv1.
      sy-subrc = 1.
    WHEN 2.
      MESSAGE a050(sv) WITH view_name.
    WHEN 3.
      MESSAGE a037(sv) WITH view_name.
    WHEN 5.
      MESSAGE a028(sv) WITH view_name.
    WHEN 7.
      MESSAGE w054(sv) WITH sy-mandt.
      sy-subrc = 7.
  ENDCASE.
  rc = sy-subrc.
  IF exit_form NE space.
    PERFORM (exit_form) IN PROGRAM (sy-repid).
  ENDIF.
  IF e_act EQ 'E'.
    IF sy-subrc <> 0.
      vim_enq_s_u_rc = sy-subrc.
    ELSEIF rc <> 0.
      vim_enq_s_u_rc = rc.
    ELSE.
      vim_enq_s_u_rc = 0.
    ENDIF.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM LISTE_ADDRESS_MAINTAIN                                   *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM LISTE_ADDRESS_MAINTAIN.
  IF X_HEADER-ADRNBRFLAG EQ SPACE.
    MESSAGE E001(SV).
    EXIT.
  ENDIF.
  LOOP AT EXTRACT.
    CHECK <XMARK> EQ MARKIERT.
    MOVE SY-TABIX TO EXIND.
    PERFORM MOVE_EXTRACT_TO_VIEW_WA.
    PERFORM ADDRESS_MAINTAIN.
    PERFORM UPDATE_TAB.
  ENDLOOP.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM ADDRESS_MAINTAIN                                         *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM address_maintain.
  DATA: mode, return TYPE i, kz, answer, am_save(1) TYPE c,
        am_pos LIKE sy-fdpos, am_length LIKE sy-fdpos,
        func_name TYPE rs38l_fnam.
  DATA: am_handletab LIKE addr1_dia OCCURS 1 WITH HEADER LINE,
        am_sel LIKE addr1_sel, am_address LIKE addr1_val,
        am_ucomm LIKE sy-ucomm, am_title LIKE sy-title.
  DATA: keytab TYPE TABLE OF vimty_textfield,
        keytab_wa TYPE vimty_textfield,
        am_key TYPE vimty_max_textline.

  FIELD-SYMBOLS: <am_title> TYPE c, <am_key> TYPE c,
                 <am_handle_x> TYPE x,
                 <namtab> TYPE vimnamtab, <keyfld> TYPE ANY.
  IF x_header-adrnbrflag EQ space.
    MESSAGE e001(sv).
    EXIT.
  ENDIF.
  IF status-action NE anzeigen AND status-action NE transportieren AND
     adrnbr_roflag EQ space.
    MOVE svim_text_012 TO am_title.    "Adresse bearbeiten
  ELSE.
    MOVE svim_text_017 TO am_title.    "Adresse anzeigen
  ENDIF.
  am_pos = strlen( am_title ).
  am_length = 70 - am_pos.
  ASSIGN am_title+am_pos(am_length) TO <am_title>.
  MOVE ':' TO <am_title>.
  ADD 2 TO am_pos.
  SUBTRACT 2 FROM am_length.
  ASSIGN am_title+am_pos(am_length) TO <am_title>.
  CLEAR am_pos.
  PERFORM vim_external_repr_for_key TABLES keytab
                                    USING <f1_x>.
  LOOP AT keytab INTO keytab_wa.
    CONCATENATE am_key keytab_wa-text INTO am_key SEPARATED BY space.
    am_pos = am_pos + keytab_wa-outplen + 1.
    IF am_pos > am_length. EXIT. ENDIF.
  ENDLOOP.
  IF sy-subrc = 0.
    ASSIGN am_key(am_pos) TO <am_key>.
*  IF x_header-clidep NE space.
*    am_length = x_header-keylen - client_length.
*    ASSIGN <f1>+client_length(am_length) TO <am_key>.
*  ELSE.
*    ASSIGN <f1> TO <am_key>.
*  ENDIF.
    MOVE <am_key> TO <am_title>.
  ENDIF.
  ASSIGN am_handletab-handle TO <am_handle_x> CASTING.
  IF x_header-adrnbrflag EQ 'O'.       "use old technique
* Übergangslösung Adressumstellung 3.0F Anfang
    IF <address_number> NE space.
      SELECT adrnr FROM sadr INTO sadr-adrnr
                             WHERE adrnr EQ <address_number>.
        EXIT.
      ENDSELECT.
      IF sy-subrc NE 0.
        CALL FUNCTION 'ADDR_CONVERT_ADRC_TO_SADR'
          CHANGING
            address_number = <address_number>.
*     IF <ADDRESS_NUMBER> NE SPACE AND "new address number -> update
*        STATUS-ACTION NE ANZEIGEN AND STATUS-ACTION NE TRANSPORTIEREN.
*       <STATUS>-UPD_FLAG = 'X'.
*     ENDIF.  "not necessary, adrnbr will never be changed
      ENDIF.
    ENDIF.
* Übergangslösung Adressumstellung 3.0F Ende
    MOVE <address_number> TO sadr-adrnr.
    kz = space.
   IF status-action NE anzeigen AND status-action NE transportieren AND
             adrnbr_roflag EQ space.
      IF <address_number> EQ space.
        mode = 'A'.
      ELSE.
        mode = 'M'.
      ENDIF.
      IF status-action EQ kopieren.
        IF <address_number> NE space.
          SELECT * FROM sadr WHERE adrnr EQ <address_number>.
            kz = 'X'.
            EXIT.
          ENDSELECT.
        ELSE.
          CLEAR sadr.
        ENDIF.
        CLEAR <address_number>.
        mode = 'A'.
      ENDIF.
    ELSE.
      mode = 'D'.
    ENDIF.
    func_name = 'ADDRESS_MAINTAIN'. "struggling against extended check
    DO.
      CALL FUNCTION func_name
        EXPORTING
          adrswa_in         = sadr
          processing_status = mode
          kennzeichen       = kz
          save_intern       = 'X'
          title             = am_title
        IMPORTING
          adrswa_out        = sadr
          returncode        = return
          update_flag       = am_save
        EXCEPTIONS
          not_found         = 4.
      IF sy-subrc NE 0.
        IF status-action NE anzeigen AND
           status-action NE transportieren AND
           adrnbr_roflag EQ space.
          CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
            EXPORTING
              diagnosetext1 = svim_text_013   "Die Adresse für das
              diagnosetext2 = <am_key>
              diagnosetext3 = svim_text_014 "wurde nicht gefunden.
              textline1     = svim_text_015"Möchten Sie eine neue er
              titel         = svim_text_016"Adresse nicht vorhanden
            IMPORTING
              answer        = answer.
          IF answer EQ 'J'.
            mode = 'A'.
          ELSE.
            return = 4.
            EXIT.
          ENDIF.
        ELSE.
          MESSAGE i055(sv) WITH <am_key>.
          return = 4.
          EXIT.
        ENDIF.
      ELSE.
        EXIT.
      ENDIF.
    ENDDO.
   IF status-action NE anzeigen AND status-action NE transportieren AND
             adrnbr_roflag EQ space.
      IF return NE 4 AND sadr-adrnr NE <address_number> OR
         am_save NE space. "transport for address changes is requested
        MOVE: 'X' TO <status>-upd_flag,
               sadr-adrnr TO <address_number>.
      ENDIF.
    ENDIF.
    CLEAR am_ucomm.
  ELSE. "4.0: use new version of address maintenance
   IF status-action NE anzeigen AND status-action NE transportieren AND
             adrnbr_roflag EQ space.
      IF status-action EQ kopieren.
        IF <address_number> NE space.
          IF <address_number> NP '@NEW*'.
            am_sel-addrnumber = <address_number>.
          ELSE.
            am_sel-addrhandle = <f1_x>.
          ENDIF.
          CALL FUNCTION 'ADDR_GET'
            EXPORTING
              address_selection = am_sel
            IMPORTING
              address_value     = am_address
            EXCEPTIONS
              parameter_error   = 1
              address_not_exist = 2
              version_not_exist = 3
              internal_error    = 4.
          IF sy-subrc EQ 0.
            MOVE-CORRESPONDING am_address TO am_handletab. "#EC *
          ENDIF.
        ENDIF.
        CLEAR <address_number>.
        am_handletab-maint_mode = 'CREATE'.
      ELSE.
        IF <address_number> EQ space.
          am_handletab-maint_mode = 'CREATE'.
        ELSE.
          am_handletab-maint_mode = 'CHANGE'.
        ENDIF.
      ENDIF.                           "status-action eq kopieren.
    ELSE.
      IF <address_number> IS INITIAL.  "no address assigned
        MESSAGE i055(sv) WITH <am_key>.
        EXIT.
      ENDIF.
      am_handletab-maint_mode = 'DISPLAY'.
    ENDIF.
    IF am_handletab-maint_mode EQ 'CREATE' OR
       <address_number> CP '@NEW*'.
      <am_handle_x>(x_header-keylen) = <f1_x>.
*      am_handletab-handle = <f1>.
    ELSE.
      CLEAR am_handletab-handle.
    ENDIF.
    IF <address_number> NP '@NEW*'.
      am_handletab-addrnumber = <address_number>.
    ELSE.
      CLEAR am_handletab-addrnumber.
    ENDIF.
    am_handletab-addr_group = vim_addr_group.
    APPEND am_handletab.
* individual preparation of address dialog requested?.....
    CLEAR: vim_addr_field_selection,
           vim_addr_keywords,
           vim_addr_chng_deflt_comm_types,
           vim_addr_frame_text,
           vim_addr_excluded_functions.
    REFRESH vim_addr_excluded_functions.
    vim_addr_titlebar = am_title.
    CLEAR vim_skip_adr_maint.                               "UF120400
    IF x_header-frm_bf_adr NE space.   "...yes
      PERFORM (x_header-frm_bf_adr) IN PROGRAM.
    ENDIF.
    CHECK vim_skip_adr_maint IS INITIAL.                    "UF120400
    CALL FUNCTION 'ADDR_DIALOG_PREPARE'
         EXPORTING
              field_selection           = vim_addr_field_selection
              keywords                  = vim_addr_keywords
*             TITLEBAR                  = AM_TITLE
              titlebar                  = vim_addr_titlebar
              change_default_comm_types = vim_addr_chng_deflt_comm_types
              frame_text                = vim_addr_frame_text
         TABLES
              excluded_functions        = vim_addr_excluded_functions
*             ERROR_TABLE               =
         EXCEPTIONS
              internal_error            = 1
              OTHERS                    = 2.
    IF am_handletab-maint_mode EQ 'CHANGE' AND
       am_handletab-addrnumber NE space.
      READ TABLE vim_locked_addresses FROM am_handletab-addrnumber
                                      TRANSPORTING NO FIELDS.
      IF sy-subrc NE 0.                "not yet locked
        CALL FUNCTION 'ADDR_ENQUEUE'
             EXPORTING
                  address_number    = am_handletab-addrnumber
*               MODE_ADRC         = 'E'
*               _SCOPE            = '2'
*               _WAIT             = ' '
*               _COLLECT          = ' '
             EXCEPTIONS
                  address_not_exist = 1
                  foreign_lock      = 2
                  system_failure    = 3
                  internal_error    = 4.
        CASE sy-subrc.
          WHEN 0.
            INSERT am_handletab-addrnumber INTO TABLE
                                           vim_locked_addresses.
          WHEN 1.
            IF status-action NE anzeigen AND
               status-action NE transportieren AND
               adrnbr_roflag EQ space.
              CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
                EXPORTING
                  diagnosetext1 = svim_text_013"Die Adresse für das Obj:
                  diagnosetext2 = <am_key>
                  diagnosetext3 = svim_text_014"wurde nicht gefunden.
                  textline1     = svim_text_015"Möchten Sie eine neue er
                  titel         = svim_text_016"Adresse nicht vorhanden
                IMPORTING
                  answer        = answer.
              IF answer EQ 'J'.
                am_handletab-maint_mode = 'CREATE'.
                IF <address_number> NP '@NEW*'.
                  <am_handle_x>(x_header-keylen) = <f1_x>.
*                  am_handletab-handle = <f1>.
                  CLEAR am_handletab-addrnumber.
                ENDIF.
                MODIFY am_handletab INDEX 1.
              ELSE.
                EXIT.
              ENDIF.
            ELSE.
              MESSAGE i055(sv) WITH <am_key>.
              EXIT.
            ENDIF.
          WHEN 2.
            MESSAGE i049(sv) WITH sy-msgv1.
            am_handletab-maint_mode = 'DISPLAY'.
          WHEN OTHERS.
            MESSAGE i050(sv) WITH <am_key>.
            am_handletab-maint_mode = 'DISPLAY'.
        ENDCASE.
      ENDIF.                           "not yet locked
    ENDIF. "am_handletab-maint_mode eq 'CHANGE' and no new address
    DO.
      CALL FUNCTION 'ADDR_DIALOG'
           IMPORTING
                ok_code           = am_ucomm
           TABLES
                number_handle_tab = am_handletab
*             VALUES            =
           EXCEPTIONS
                address_not_exist = 1
                group_not_valid   = 2
                parameter_error   = 3
                internal_error    = 4.
      CASE sy-subrc.
        WHEN 0.
          READ TABLE am_handletab INDEX 1.
          EXIT.
        WHEN 1.
          IF status-action NE anzeigen AND
             status-action NE transportieren AND
             adrnbr_roflag EQ space.
            CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
              EXPORTING
                diagnosetext1 = svim_text_013 "Die Adresse für das
                diagnosetext2 = <am_key>
                diagnosetext3 = svim_text_014"wurde nicht gefunden.
                textline1     = svim_text_015"Möchten Sie eine neue er
                titel         = svim_text_016"Adresse nicht vorhanden
              IMPORTING
                answer        = answer.
            IF answer EQ 'J'.
              READ TABLE am_handletab INDEX 1.
              am_handletab-maint_mode = 'CREATE'.
              IF <address_number> NP '@NEW*'.
                <am_handle_x>(x_header-keylen) = <f1_x>.
*                am_handletab-handle = <f1>.
                CLEAR am_handletab-addrnumber.
              ENDIF.
              MODIFY am_handletab INDEX 1.
            ELSE.
              am_ucomm = 'CANC'.
              EXIT.
            ENDIF.
          ELSE.
            MESSAGE i055(sv) WITH <am_key>.
            am_ucomm = 'CANC'.
            EXIT.
          ENDIF.
        WHEN OTHERS.
          MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno WITH
                  sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          am_ucomm = 'CANC'. EXIT.
      ENDCASE.
    ENDDO.
    IF am_handletab-maint_mode EQ 'CHANGE' AND
       am_handletab-addrnumber NE space    AND
       ( am_ucomm EQ 'CANC' OR am_handletab-updateflag EQ space ).
      READ TABLE vim_locked_addresses FROM am_handletab-addrnumber
                                      TRANSPORTING NO FIELDS.
      IF sy-subrc EQ 0.                "dequeue
        CALL FUNCTION 'ADDR_DEQUEUE'
               EXPORTING
                 address_number    = am_handletab-addrnumber
*                MODE_ADRC         = 'E'
*                _SCOPE            = '3'
*                _SYNCHRON         = ' '
*                _COLLECT          = ' '
               EXCEPTIONS
                 address_not_exist = 1
                 internal_error    = 2.
      ENDIF.
    ENDIF.
   IF status-action NE anzeigen AND status-action NE transportieren AND
             adrnbr_roflag EQ space.
      IF am_ucomm NE 'CANC'.
        IF am_handletab-maint_mode EQ 'CREATE'.
          <address_number> = '@NEW'.
          <address_number>+4(6) = <status>-newadrcnt.
          ADD 1 TO <status>-newadrcnt.
          <status>-upd_flag = 'X'.
        ENDIF.
        IF am_handletab-updateflag NE space. "addr. itself is to be save
          READ TABLE vim_addresses_to_save
                              WITH KEY viewname = x_header-viewname
                                       addrnumber = <address_number>
                              BINARY SEARCH TRANSPORTING NO FIELDS.
          IF sy-subrc NE 0.
            vim_addresses_to_save-addrnumber = <address_number>.
            CLEAR vim_addresses_to_save-handle.
            <vim_addr_handle_x>(x_header-keylen) = <f1_x>.
*            vim_addresses_to_save-handle = <f1>.
            INSERT vim_addresses_to_save INDEX sy-tabix.
          ENDIF.
          IF vim_client_state EQ vim_log AND
             x_header-flag NE vim_transport_denied.
            <status>-upd_flag = 'X'. "nec. for transport of master entry
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
    CLEAR return.
  ENDIF.                               "am_statetab-value eq space.
* IF STATUS-ACTION NE KOPIEREN AND STATUS-ACTION NE HINZUFUEGEN.
  IF status-action NE kopieren AND status-action NE hinzufuegen AND
     vim_single_entry_function NE 'INS'.
    IF return NE 4 AND am_ucomm NE 'CANC'.
      IF <xmark> EQ markiert.
        <xmark> = nicht_markiert.
        IF <status>-upd_flag EQ space.
          MODIFY extract INDEX exind.
          READ TABLE total WITH KEY <vim_xextract_key> BINARY SEARCH.
          <mark> = nicht_markiert.
          MODIFY total INDEX sy-tabix.
        ENDIF.
        SUBTRACT: 1 FROM mark_extract,
                  1 FROM mark_total.
      ENDIF.
    ENDIF.
    CLEAR function.
  ENDIF.
ENDFORM.                    "address_maintain

*---------------------------------------------------------------------*
*       FORM ORIGINAL_HOLEN                                           *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM original_holen.
  DATA: count1 TYPE i, count2 TYPE i, count3 TYPE i, sum TYPE i,
        texttab_mod(1) TYPE c.         "SW Texttransl
  IF status-action NE aendern OR status-delete EQ geloescht.
    MESSAGE i001(sv).
    EXIT.
  ENDIF.
  IF status-mode EQ list_bild.
    LOOP AT extract.
      CLEAR texttab_mod.
      CHECK <xmark> EQ markiert.
      ADD 1 TO count1.
      IF x_header-texttbexst <> space. "SW Texttransl
        PERFORM vim_texttab_modif_for_key CHANGING texttab_mod.
      ENDIF.
      IF x_header-bastab NE space AND x_header-texttbexst NE space.
        CHECK <xact> EQ neuer_eintrag OR ( <xact> EQ original AND
              <xact_text> EQ original  AND texttab_mod EQ space ).
      ELSE.
        CHECK <xact> EQ neuer_eintrag OR ( <xact> EQ original
                                     AND texttab_mod EQ space ).
      ENDIF.
      IF <xact> EQ neuer_eintrag.
        ADD 1 TO count2.
      ELSE.
        ADD 1 TO count3.
      ENDIF.
    ENDLOOP.
  ELSE.
    ADD 1 TO count1.
    CASE <xact>.
      WHEN neuer_eintrag.
        ADD 1 TO count2.
      WHEN original.
        CLEAR texttab_mod.
        IF x_header-texttbexst <> space.              "SW Texttransl
          PERFORM vim_texttab_modif_for_key CHANGING texttab_mod.
        ENDIF.
        IF x_header-bastab NE space AND x_header-texttbexst NE space.
*          IF sy-datar EQ space AND <table1> EQ <extract_enti> AND
          IF sy-datar EQ space AND <table1> EQ <vim_extract_struc>
           AND <table1_xtext> EQ <vim_xextract_text>
           AND texttab_mod EQ space.
            ADD 1 TO count3.
          ENDIF.
        ELSE.
*          IF sy-datar EQ space AND <table1> EQ <table2>
          IF sy-datar EQ space AND <table1> EQ <vim_extract_struc>
                               AND texttab_mod EQ space.
            ADD 1 TO count3.
          ENDIF.
        ENDIF.
    ENDCASE.
  ENDIF.
  sum = count2 + count3.
  IF count1 EQ 0.
    MESSAGE s056(sv).
  ELSEIF count1 EQ count2.
    IF count1 EQ 1.
      MESSAGE s057(sv).
      IF status-mode EQ detail_bild.
        CLEAR function.
      ENDIF.
    ELSE.
      MESSAGE s058(sv).
    ENDIF.
  ELSEIF count1 EQ count3.
    IF count1 EQ 1.
      MESSAGE s059(sv).
    ELSE.
      MESSAGE s060(sv).
    ENDIF.
  ELSEIF count1 EQ sum.
    MESSAGE s061(sv) WITH count3 count2.
  ELSE.
    CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
         EXPORTING
              titel     = svim_text_010
              textline1 = svim_text_009
              textline2 = svim_text_011
         IMPORTING
              answer    = answer.
    IF answer EQ 'J'.
      IF status-mode EQ list_bild.
        function = 'ORGL'.
      ELSE.
        IF <xact> NE original OR texttab_mod NE space.
          function = 'ORGD'.
        ELSE.
          answer = 'N'.
        ENDIF.
      ENDIF.
      IF answer = 'J'.
*       SET SCREEN 0. LEAVE SCREEN.
        vim_next_screen = 0. vim_leave_screen = 'X'.
      ENDIF.
    ELSE.
      CLEAR function.
    ENDIF.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM ORDER_ADMINISTRATION                                     *
*---------------------------------------------------------------------*
* get client state and transport objects                              *
*---------------------------------------------------------------------*
FORM ORDER_ADMINISTRATION.
  DATA: RC LIKE SY-SUBRC.
  IF STATUS-ACTION EQ ANZEIGEN AND
     VIM_CORR_OBJ_VIEWNAME NE X_HEADER-VIEWNAME.
    CLEAR E071-TRKORR.
    PERFORM GET_TRANSP_INFO.
    VIM_CORR_OBJ_VIEWNAME = X_HEADER-VIEWNAME.
  ENDIF.
  IF X_HEADER-FLAG EQ VIM_TRANSPORT_DENIED.
    MESSAGE S001(SV). EXIT.
  ENDIF.
  DO.
    CALL FUNCTION 'TR_TASK_OVERVIEW'
         EXPORTING
              IV_USERNAME      = SY-UNAME
              IV_CATEGORY      = OBJH-OBJCATEG
              IV_CLIENT        = SY-MANDT
         EXCEPTIONS
              INVALID_CATEGORY = 01
              OTHERS           = 02.
    RC = SY-SUBRC.
    IF SY-SUBRC EQ 1 AND
       OBJH-OBJCATEG EQ VIM_CUST_SYST OR OBJH-OBJCATEG EQ VIM_APPL.
      OBJH-OBJCATEG = VIM_SYST.
      CONTINUE.
    ENDIF.
    EXIT.
  ENDDO.
  IF RC NE 0.
    MESSAGE ID      SY-MSGID
            TYPE    'I'
            NUMBER  SY-MSGNO
            WITH    SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  CLEAR FUNCTION.
ENDFORM.                               "order_administration

*---------------------------------------------------------------------*
*       FORM GET_TRANSP_INFO                                          *
*---------------------------------------------------------------------*
* get client state and transport objects                              *
*---------------------------------------------------------------------*
FORM get_transp_info.
  LOCAL: e071.
  DATA: obj_type LIKE objh-objecttype, last_category LIKE objh-objcateg,
        last_clidep LIKE objh-clidep VALUE 'X', gti_e071 LIKE e071,
        last_protect LIKE objh-protect, gti_cliindep_state(1) TYPE c,
        gti_x030l LIKE x030l, gti_tabname TYPE tabname,
        gti_client_role LIKE t000-cccategory, gti_flag_safe(1) TYPE c,
        cursetting TYPE cursetting, addr_e071k LIKE e071k,
        importable TYPE objimp value '4',
        tr_result LIKE trpari-s_checked, addr_e071k2 LIKE e071k.

* check if logging of changes is necessary
  gti_flag_safe = x_header-flag.
  IF x_header-customauth CO no_transport_classes."transport impossible
    x_header-flag = vim_transport_denied. "no standard logging
    CLEAR: x_header-frm_e071,          "no individual transport
           x_header-frm_e071ks,
           x_header-frm_e071ka.
    IF maint_mode EQ aendern.
      MOVE 'TRSP' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    ELSEIF maint_mode EQ transportieren.
      MESSAGE i128(sv) WITH "Auslieferungsklasse &, kein Transport mög
              x_header-customauth.
      RAISE missing_corr_number.
    ENDIF.
    MOVE 'ORDR' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    sy-subrc = 9.
  ELSEIF x_header-customauth CO no_transport_log_classes.
    IF x_header-frm_e071 EQ space AND x_header-frm_e071ks EQ space AND
       x_header-frm_e071ka EQ space.   "no individual transport routines
      x_header-flag = vim_transport_denied. "no transport
      IF maint_mode EQ aendern.
        MOVE 'TRSP' TO excl_cua_funct-function. COLLECT excl_cua_funct.
      ELSEIF maint_mode EQ transportieren.
        MESSAGE i128(sv) WITH "Auslieferungsklasse &, kein Transport mög
                x_header-customauth.
        RAISE missing_corr_number.
      ENDIF.
      MOVE 'ORDR' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    ELSE.
      x_header-flag = 'X'.             "no standard logging
    ENDIF.
    sy-subrc = 9.
  ENDIF.
  IF sy-subrc EQ 9.
    MODIFY x_header INDEX 1.
  ENDIF.
*<<< Übergangslösung Transportstatus des Mandanten Anfang
* check if client allows transport
  CALL FUNCTION 'VIEW_GET_CLIENT_STATE'
    IMPORTING
      transp_state   = vim_client_state
      cliindep_state = gti_cliindep_state
      client_state   = gti_client_role.
  IF x_header-clidep NE space AND      "clientdependent and
     x_header-customauth CN sap_only_classes. "not delclass `S`
    CASE vim_client_state.
      WHEN vim_local_clnt. "client is local -> transport denied
        IF maint_mode EQ aendern OR maint_mode EQ anzeigen.
          excl_cua_funct-function = 'TRSP'. COLLECT excl_cua_funct.
          excl_cua_funct-function = 'ORDR'. COLLECT excl_cua_funct.
          x_header-flag = vim_transport_denied.
        ELSE.
          MESSAGE i130(sv) WITH "Mandant ist lokal, keine Transporte m
                  sy-mandt.
          RAISE missing_corr_number.
        ENDIF.
      WHEN vim_locked. "client is locked -> no changes but transport
*       IF MAINT_MODE EQ AENDERN.  "only for CUST/CUSY objects!!!!!!
*         MESSAGE I430(TK) WITH SY-MANDT."Mandant &1 'nicht änderbar'
*         MAINT_MODE = STATUS-ACTION = ANZEIGEN.
*         EXIT.
*       ENDIF.
    ENDCASE.
  ELSE. "clientindependent or deliveryclass 'S'
    vim_client_state = vim_log.        "such objects always log
  ENDIF.                               "xheader-clidep ne space.
*<<< Übergangslösung Transportstatus des Mandanten Ende
* if transport allowed -> get transport objects
  REFRESH vim_corr_objtab.
  gti_e071 = e071.
  IF x_header-frm_e071 NE space.       "individual transport objects
    PERFORM (x_header-frm_e071) IN PROGRAM (sy-repid).
  ENDIF.
  IF gti_flag_safe EQ space.                                "240997
* automatic recording of changes switched on in SE54
    APPEND gti_e071 TO vim_corr_objtab.
    IF x_header-adrnbrflag EQ 'N'.     "new version of addresses used
* addresses
      REFRESH: vim_addr_e071k_tab, vim_addr_e071_tab.
      CALL FUNCTION 'ADDR_TRANSPORT_TDAT_ENTRIES'
        TABLES
          e071k_tab = vim_addr_e071k_tab.
      addr_e071k2 = e071k.
      LOOP AT vim_addr_e071k_tab INTO addr_e071k.
        gti_e071-object = addr_e071k2-mastertype
         = addr_e071k-mastertype.
        gti_e071-obj_name = addr_e071k2-mastername
         = addr_e071k-mastername.
        APPEND gti_e071 TO vim_addr_e071_tab.
        APPEND gti_e071 TO vim_corr_objtab.
        MODIFY vim_addr_e071k_tab FROM addr_e071k2.
      ENDLOOP.
    ENDIF.
  ELSEIF x_header-frm_e071 EQ space AND    "no individual transport
         x_header-frm_e071ks EQ space AND  "routines and no standard
         x_header-frm_e071ka EQ space.
* no events concerning change recording are used
    APPEND gti_e071 TO vim_corr_objtab.    "but check cliiendep settings
    x_header-flag = vim_transport_denied. MODIFY x_header INDEX 1.
    IF maint_mode EQ aendern.
      MOVE 'TRSP' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    ENDIF.
    MOVE 'ORDR' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    gti_flag_safe = '@'.
  ENDIF.
* get object category and client dependency for transport objects
  LOOP AT vim_corr_objtab.
    CASE vim_corr_objtab-object.
      WHEN vim_view_type.              "-> view
        obj_type = vim_view.
      WHEN transp_object.              "-> tables
        obj_type = vim_tabl.
      WHEN vim_tran_type.              "-> individual transaction
        obj_type = vim_tran.
      WHEN vim_clus_type.           "-> cluster of views/tables/clusters
        obj_type = vim_clst.
      WHEN OTHERS.                     "-> may be: TLOGO object ?
        obj_type = vim_logo.
    ENDCASE.
    IF obj_type NE vim_logo.
      SELECT SINGLE * FROM objh
                      WHERE objectname EQ vim_corr_objtab-obj_name
                        AND objecttype EQ obj_type.
    ELSE. "TLOGO -> use obj type as obj name
      SELECT SINGLE * FROM objh
                      WHERE objectname EQ vim_corr_objtab-object
                        AND objecttype EQ obj_type.
    ENDIF.
    IF sy-subrc NE 0.
      IF obj_type NE vim_logo. "set defaults for table transp. obj.
        IF x_header-viewname EQ vim_corr_objtab-obj_name AND
           ( x_header-bastab EQ space AND
             vim_corr_objtab-object EQ vim_view_type OR
             x_header-bastab NE space AND
             vim_corr_objtab-object EQ transp_object ) OR
           vim_called_by_cluster NE space AND
           vim_calling_cluster EQ vim_corr_objtab-obj_name AND
           vim_corr_objtab-object EQ vim_clus_type.
          IF x_header-clidep EQ space. "clientindependent
            IF x_header-customauth CO customizing_delivery_classes.
              objh-objcateg = vim_cust_syst.
            ELSEIF x_header-customauth CO sap_only_classes.
              objh-objcateg = vim_syst.
            ELSEIF x_header-customauth CO application_delivery_classes.
              objh-objcateg = vim_appl.
            ELSE.
              objh-objcateg = vim_syst.
            ENDIF.
          ELSE.                        "clientdependent
            IF x_header-customauth CO customizing_delivery_classes.
              objh-objcateg = vim_cust.
            ELSEIF x_header-customauth CO sap_only_classes.
              objh-objcateg = vim_cust_syst.
            ELSEIF x_header-customauth CO application_delivery_classes.
              objh-objcateg = vim_appl.
            ELSE.
              objh-objcateg = vim_syst.
            ENDIF.
          ENDIF.
          objh-clidep   = x_header-clidep.
        ELSE.           "unknown object -> check if clientdep. table
          IF vim_corr_objtab-object EQ transp_object. "table
            gti_tabname = vim_corr_objtab-obj_name.
            CALL FUNCTION 'DDIF_NAMETAB_GET'
              EXPORTING
                tabname   = gti_tabname
              IMPORTING
                x030l_wa  = gti_x030l
              EXCEPTIONS
                not_found = 1
                OTHERS    = 2.
            IF sy-subrc EQ 0 AND gti_x030l-flagbyte O vim_clidep.
              objh-objcateg = vim_cust."clientdependent table
              objh-clidep   = 'X'.
            ELSE.                      "no nametab or clientindependent
              objh-objcateg = vim_syst.
              objh-clidep   = space.
            ENDIF.
          ELSE.                        "unknown object -> syst
            objh-objcateg = vim_syst.
            objh-clidep   = space.
          ENDIF.
        ENDIF.
      ELSE. "vim_logo                  "no objh-object -> syst
        objh-objcateg = vim_syst.
        objh-clidep   = space.
* note lockable transport object
        vim_corr_objtab-lockable = 'X'.
        MODIFY vim_corr_objtab.
      ENDIF.                           "obj_type ne vim_logo
    ELSE.
* entry in OBJH found -> check current setting, importability,
* protect-flag
      IF objh-cursetting <> space.           "UF615995/2000b
        cursetting = objh-cursetting.
      ENDIF.                                 "UF615995/2000e
      IF objh-importable <> space
       AND objh-importable < importable.     "#EC PORTABLE
* "most unimportable" object sets standard
        importable = objh-importable.
      ENDIF.
      IF objh-protect NE space.
        IF objh-objectname EQ x_header-viewname AND "current VIM object
           ( x_header-bastab EQ space AND objh-objecttype EQ vim_view OR
             x_header-bastab NE space AND objh-objecttype EQ vim_tabl ).
          IF x_header-frm_e071 EQ space AND
             x_header-frm_e071ks EQ space AND
             x_header-frm_e071ka EQ space. "no individ. transp. routines
            x_header-flag = vim_transport_denied. "no transport
            MOVE 'TRSP' TO excl_cua_funct-function.
            COLLECT excl_cua_funct.
            MOVE 'ORDR' TO excl_cua_funct-function.
            COLLECT excl_cua_funct.
*           EXIT.                                         "240997
          ELSE.
            x_header-flag = 'X'.       "no standard logging
            DELETE vim_corr_objtab.
          ENDIF.
          MODIFY x_header INDEX 1.
        ENDIF. "curr. VIM obj./ignore added individual transport objects
      ENDIF.                           "protect ne space
*     IF OBJH-OBJECTTYPE EQ VIM_LOGO.
* note object as lockable transport object until TR_OBJECTS_* force
* TLOGO-objects too  "changed in 4.0
      IF objh-checkid EQ 'L'.          "note lockable object!
        vim_corr_objtab-lockable = 'X'.
        MODIFY vim_corr_objtab.
      ENDIF.
    ENDIF.                             "sy-subrc ne 0.
    IF ( objh-objcateg EQ vim_syst OR
         objh-objcateg EQ vim_cust_syst ) AND
       last_category NE vim_syst.
      last_category = objh-objcateg.
    ENDIF.
    IF objh-clidep EQ space.
      last_clidep = objh-clidep.
    ENDIF.
  ENDLOOP.
* IF SY-SUBRC NE 0.  "may be user exits.....
  IF sy-subrc NE 0.
    IF ( x_header-frm_e071 NE space OR
       x_header-frm_e071ks EQ space AND x_header-frm_e071ka EQ space ).
      x_header-flag = vim_transport_denied. MODIFY x_header INDEX 1.
      IF maint_mode EQ aendern.
        MOVE 'TRSP' TO excl_cua_funct-function. COLLECT excl_cua_funct.
      ENDIF.
      MOVE 'ORDR' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    ENDIF.
    EXIT. "if no object could be determined exit this routine
  ELSEIF gti_flag_safe EQ '@'.         "temporaryly appended
    REFRESH vim_corr_objtab.
  ENDIF.
* CHECK X_HEADER-FLAG NE VIM_TRANSPORT_DENIED.             "240997
  IF objh-objcateg NE vim_syst AND
     ( last_category EQ vim_syst OR
       last_category EQ vim_cust_syst ).
    objh-objcateg = last_category.
  ENDIF.
  objh-clidep = last_clidep.
* no logging for settings in productive clients
  IF cursetting NE space.
    x_header-cursetting = x_header-flag.
    TRANSLATE x_header-cursetting USING ' XXY'.
    MODIFY x_header INDEX 1.
  ENDIF.
* put importable-flag into x_header.
  IF importable <> 4.
    x_header-importable = importable.
    MODIFY x_header INDEX 1.
  ENDIF.
  IF maint_mode EQ aendern AND objh-clidep NE space AND
     cursetting NE space AND gti_client_role EQ 'P'.
    x_header-flag = vim_transport_denied. MODIFY x_header INDEX 1.
    MOVE 'ORDR' TO excl_cua_funct-function. COLLECT excl_cua_funct.
    EXIT.                                                   "240997
  ENDIF.
* CHECK X_HEADER-FLAG NE VIM_TRANSPORT_DENIED.          "240997
  IF x_header-flag NE vim_transport_denied AND
     vim_client_state EQ vim_locked AND
     ( objh-objcateg EQ vim_cust OR objh-objcateg EQ vim_cust_syst ) AND
     maint_mode EQ aendern.            "only for CUST/CUSY objects!!!!!!
    MESSAGE i430(tk) WITH sy-mandt.    "Mandant &1 'nicht änderbar'
    maint_mode = status-action = anzeigen.
    ASSIGN dba_sellist-*sys* TO <vim_sellist>.
    vim_enqueue_range = x_header-subsetflag.
    PERFORM enqueue
                USING
                    'D'
                    space.
    EXIT.
  ENDIF.
  CASE gti_cliindep_state.
    WHEN vim_noact.
    WHEN vim_nocliindep_cust.
      IF maint_mode EQ aendern AND objh-objcateg = vim_cust_syst.
        CHECK x_header-flag NE vim_transport_denied.
        MESSAGE i731(tk).              " WITH SY-MANDT.
        maint_mode = status-action = anzeigen.
        ASSIGN dba_sellist-*sys* TO <vim_sellist>.
        vim_enqueue_range = x_header-subsetflag.
        PERFORM enqueue
                    USING
                        'D'
                        space.
        vim_client_state = vim_noact. EXIT.
      ENDIF.
    WHEN vim_noreposiandcust.
      IF maint_mode EQ aendern AND
       ( objh-objcateg = vim_syst OR objh-objcateg = vim_cust_syst ).
        CHECK x_header-flag NE vim_transport_denied.
        MESSAGE i730(tk).              " WITH SY-MANDT.
        maint_mode = status-action = anzeigen.
        ASSIGN dba_sellist-*sys* TO <vim_sellist>.
        vim_enqueue_range = x_header-subsetflag.
        PERFORM enqueue
                    USING
                        'D'
                        space.
        vim_client_state = vim_noact. EXIT.
      ENDIF.
    WHEN vim_noreposichanges.
      LOOP AT vim_corr_objtab INTO e071.
        CALL FUNCTION 'TR_CHECK_TYPE'
          EXPORTING
            wi_e071   = e071
          IMPORTING
            pe_result = tr_result.
*  PE_RESULT        syntax  transport  TADIR     TLOCK
*           SPACE     -         -        -         -
*             S       X         -        -         -
*             R       X         X        -         -
*             T       X         X        X         -  (only for sapsccs)
*             L       X         X        X         X
*             P     system object or illegal name selection
*                   (T100, SAPL...., ... )
* no repository object and not lockable?
        IF 'TLP' CS tr_result.
          MESSAGE i729(tk).              "WITH SY-MANDT.
          IF x_header-flag NE vim_transport_denied.
            maint_mode = status-action = anzeigen.
            ASSIGN dba_sellist-*sys* TO <vim_sellist>.
            vim_enqueue_range = x_header-subsetflag.
            PERFORM enqueue
                        USING
                            'D'
                            space.
            vim_client_state = vim_noact.
          ENDIF.
          EXIT.
        ENDIF.
      ENDLOOP.
  ENDCASE.
ENDFORM.                               "get_transp_info

*---------------------------------------------------------------------*
*       FORM REQUEST_CORR_NUMBER                                      *
*---------------------------------------------------------------------*
*       request correction number                                     *
*---------------------------------------------------------------------*
FORM request_corr_number.
  DATA: rc LIKE sy-subrc, e071_safe LIKE e071.

  CHECK maint_mode EQ transportieren.  "manual transport mode
  IF <status>-l_corr_nbr NE space.
    IF <status>-corr_nbr NE <status>-l_corr_nbr.
      CLEAR: <status>-tr_alrchkd, <status>-corr_enqud.
    ELSE.
      IF vim_external_mode EQ space.
        TRANSLATE <status>-tr_alrchkd USING 'Xx'.
      ENDIF.
    ENDIF.
  ENDIF.
  PERFORM vim_get_img_activity CHANGING e071-activity.  "UF738595/2001
  IF vim_corr_obj_viewname NE x_header-viewname.
    CLEAR e071-trkorr.
    PERFORM get_transp_info.
    CHECK x_header-flag NE vim_transport_denied.
  ENDIF.
  IF <status>-tr_alrchkd EQ space.
* first get corr nbr for lockable transport objects
    e071_safe = e071.
    CLEAR vim_last_source_system.
    LOOP AT vim_corr_objtab WHERE lockable NE space.
      e071 = vim_corr_objtab.
      PERFORM check_lockable_object USING e071 rc.
      CASE rc.
        WHEN 4. maint_mode = anzeigen.
        WHEN 8. RAISE missing_corr_number.
      ENDCASE.
      IF maint_mode EQ anzeigen OR
         x_header-flag EQ vim_transport_denied.
        EXIT.
      ENDIF.
    ENDLOOP.
    e071 = e071_safe.
  ENDIF.                               "<status>-tr_alrchkd eq space
  CHECK maint_mode NE anzeigen AND
        x_header-flag NE vim_transport_denied.
  vim_corr_obj_viewname = x_header-viewname.
  IF <status>-corr_nbr NE space AND    "task specified and...
     corr_nbr EQ space AND          "...task not setted by caller and...
     <status>-corr_enqud EQ space.     "...corr not yet enqueued
    CALL FUNCTION 'ENQUEUE_E_TRKORR'
         EXPORTING
              trkorr = <status>-corr_nbr
*               X_TRKORR = E02
         EXCEPTIONS
              foreign_lock = 01
              system_failure = 02.
    CASE sy-subrc.
      WHEN 1.
        MESSAGE s092(sv) WITH <status>-corr_nbr. "Korr. wird ger.bearb.
      WHEN 2.
        MESSAGE a095(sv) WITH <status>-corr_nbr. "Systemfehler
    ENDCASE.
    <status>-corr_enqud = 'X'.
  ENDIF.
* if no lockable objects exist get corr nbr for other objects...
* but only if objects exist....
  DESCRIBE TABLE vim_corr_objtab.
  IF <status>-corr_nbr EQ space AND sy-tfill GT 0.
    DO.
      CALL FUNCTION 'TR_ORDER_CHOICE_CORRECTION'
           EXPORTING
                iv_category            = objh-objcateg
                iv_cli_dep             = objh-clidep
           IMPORTING
                ev_order               = <status>-order_nbr
                ev_task                = <status>-corr_nbr
           EXCEPTIONS
                invalid_category       = 01
                no_correction_selected = 02.
      CASE sy-subrc.
        WHEN 1.
          IF objh-objcateg NE vim_syst AND objh-objcateg NE vim_cust.
            CASE objh-objcateg.
              WHEN vim_cust_syst. objh-objcateg = vim_syst.
              WHEN vim_appl.      objh-objcateg = vim_syst.
              WHEN OTHERS.
                MESSAGE ID     sy-msgid
                        TYPE   'I'
                        NUMBER sy-msgno
                        WITH sy-msgv1 sy-msgv2  sy-msgv3 sy-msgv4.
                RAISE missing_corr_number.
            ENDCASE.
            CONTINUE.
          ENDIF.
        WHEN 2.
          CLEAR vim_corr_obj_viewname.
          RAISE missing_corr_number.
      ENDCASE.
      CALL FUNCTION 'ENQUEUE_E_TRKORR'
           EXPORTING
                trkorr = <status>-corr_nbr
*               X_TRKORR = E02
           EXCEPTIONS
                foreign_lock = 01
                system_failure = 02.
      CASE sy-subrc.
*       WHEN 0.
        WHEN 1.
          MESSAGE s092(sv) WITH <status>-corr_nbr. "Korr. wirdger.bearb.
          CONTINUE.
        WHEN 2.
          MESSAGE a095(sv) WITH <status>-corr_nbr. "Systemfehler
          CONTINUE.
      ENDCASE.
      IF ( last_corr_number NE space AND
           <status>-corr_nbr NE last_corr_number ) OR
         <status>-tr_alrchkd EQ space.
        LOOP AT corr_keytab.           "UF 514599/1999beg
          READ TABLE vim_corr_objtab
           WITH KEY pgmid    = corr_keytab-pgmid
           object   = corr_keytab-object obj_name = corr_keytab-objname.
          CHECK sy-subrc = 0 AND vim_corr_objtab-lockable = space.
* new corrnumber for unlockable objects only
          CLEAR vim_corr_objtab-trkorr.
* will be filled again in form PREPARE_CORR
          MODIFY vim_corr_objtab INDEX sy-tabix.
        ENDLOOP.                       "UF 514599/1999end
        REFRESH corr_keytab.
        MOVE <status>-corr_nbr TO last_corr_number.
      ELSEIF last_corr_number EQ space.
        LOOP AT corr_keytab WHERE
                                ( mastertype EQ vim_unlockable_object OR
                                  mastertype EQ vim_lockable_object ).
*                           AND TRKORR EQ SPACE.
* SW: bei TRSP -> neue Korrnummer, alte blieb aber in CORR_KEYTAB-TRKORR
          IF  corr_keytab-trkorr EQ space.
            corr_keytab-trkorr = <status>-corr_nbr.
            MODIFY corr_keytab.
          ELSE.                        "SW ..
            READ TABLE vim_corr_objtab
                    WITH KEY pgmid    = corr_keytab-pgmid
                             object   = corr_keytab-object
                             obj_name = corr_keytab-objname.
            IF sy-subrc = 0.
              corr_keytab-trkorr = <status>-corr_nbr.
              MODIFY corr_keytab.
            ENDIF.
          ENDIF.                       ".. SW
        ENDLOOP.
      ENDIF.
      EXIT.
    ENDDO.
    <status>-corr_enqud = 'X'.
  ENDIF.                               "<status>-corr_nbr eq space
  MOVE: <status>-corr_nbr TO e071k-trkorr,
        <status>-corr_nbr TO e071-trkorr,
        <status>-corr_nbr TO e070-trkorr.
  TRANSLATE <status>-tr_alrchkd USING ' x'.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM CHECK_LOCKABLE_OBJECT                                    *
*---------------------------------------------------------------------*
*  check lockable transport objects                                   *
*---------------------------------------------------------------------*
* <---> CLO_E071 ......
* <---- return code: 0 - ok, 4 - display only, 8 - cancel edit        *
*---------------------------------------------------------------------*
FORM CHECK_LOCKABLE_OBJECT USING CLO_E071 STRUCTURE E071
                                 CLO_RETURN TYPE I.
  DATA: CLO_TADIR LIKE TADIR, CLO_DDERR LIKE DDERR,
        CLO_LOCKED(1) TYPE C, CLO_LOCKABLE(1) TYPE C,
        CLO_EDITABLE(1) TYPE C, CLO_LOCK_TASK LIKE E071-TRKORR,
        CLO_LOCK_USER LIKE SY-UNAME, CLO_LOCK_ORDER LIKE E071-TRKORR,
        CLO_TRANSPORTABLE(1) TYPE C, CLO_ICORR LIKE E070-TRKORR,
        CLO_TE071 LIKE KO200 OCCURS 0, CLO_TTADIR LIKE TADIR OCCURS 0,
        CLO_TE071K LIKE E071K OCCURS 0.

  APPEND CLO_E071 TO CLO_TE071.
  CALL FUNCTION 'TR_EDIT_CHECK_OBJECTS_KEYS'
       EXPORTING
            WI_ORDER                       = CLO_E071-TRKORR
            WI_WITH_DIALOG                 = 'R'
*           WI_OBJ_CATEGOGY_MIX            = 'X'
            WI_SEND_MESSAGE                = ' '
       IMPORTING
*           WE_ORDER                       =
            WE_TASK                        = CLO_E071-TRKORR
*           WE_OBJECTS_APPENDABLE          =
*           EV_ERRNUM                      =
*           EV_OBJECT_UNLOCKED             =
       TABLES
            WT_E071                        = CLO_TE071
            WT_E071K                       = CLO_TE071K
            WT_TADIR                       = CLO_TTADIR
       EXCEPTIONS
            CANCEL_EDIT_APPEND_ERROR_KEYS  = 1
            CANCEL_EDIT_APPEND_ERROR_OBJCT = 2
            CANCEL_EDIT_APPEND_ERROR_ORDER = 3
            CANCEL_EDIT_BUT_SE01           = 4
            CANCEL_EDIT_NO_HEADER_OBJECT   = 5
            CANCEL_EDIT_NO_ORDER_SELECTED  = 6
            CANCEL_EDIT_REPAIRED_OBJECT    = 7
            CANCEL_EDIT_SYSTEM_ERROR       = 8
            CANCEL_EDIT_TADIR_MISSING      = 9
            CANCEL_EDIT_TADIR_UPDATE_ERROR = 10
            CANCEL_EDIT_UNKNOWN_DEVCLASS   = 11
            CANCEL_EDIT_UNKNOWN_OBJECTTYPE = 12
            CANCEL_EDIT_NO_CHECK_CALL      = 13
            CANCEL_EDIT_CATEGORY_MIXTURE   = 14
            CANCEL_EDIT_USER_AFTER_ERROR   = 15
            CANCEL_EDIT_CUSTOM_OBJ_AT_SAP  = 16
            CANCEL_EDIT_ACCESS_DENIED      = 17
            SHOW_ONLY_CLOSED_SYSTEM        = 18
            SHOW_ONLY_CONSOLIDATION_LEVEL  = 19
            SHOW_ONLY_DDIC_IN_CUSTOMER_SYS = 20
            SHOW_ONLY_DELIVERY_SYSTEM      = 21
            SHOW_ONLY_DIFFERENT_ORDERTYPES = 22
            SHOW_ONLY_DIFFERENT_TASKTYPES  = 23
            SHOW_ONLY_ENQUEUE_FAILED       = 24
            SHOW_ONLY_GENERATED_OBJECT     = 25
            SHOW_ONLY_ILL_LOCK             = 26
            SHOW_ONLY_LOCK_ENQUEUE_FAILED  = 27
            SHOW_ONLY_MIXED_ORDERS         = 28
            SHOW_ONLY_MIX_LOCAL_TRANSP_OBJ = 29
            SHOW_ONLY_NO_SHARED_REPAIR     = 30
            SHOW_ONLY_OBJECT_LOCKED        = 31
            SHOW_ONLY_REPAIRED_OBJECT      = 32
            SHOW_ONLY_SHOW_CLIENT          = 33
            SHOW_ONLY_TADIR_MISSING        = 34
            SHOW_ONLY_UNKNOWN_DEVCLASS     = 35
            SHOW_ONLY_CLOSED_CLIENT        = 36
            SHOW_ONLY_CLOSED_ALE_OBJECT    = 37
            SHOW_ONLY_UNALLOWED_SUPERUSER  = 38
            SHOW_ONLY_NO_REPAIR_SYSTEM     = 39
            SHOW_ONLY_NO_LICENSE           = 40
            SHOW_ONLY_CENTRAL_BASIS        = 41
            SHOW_ONLY_USER_AFTER_ERROR     = 42
            SHOW_ONLY_OBJECT_NOT_PATCHABLE = 43.
  IF SY-SUBRC NE 0.
    MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    IF SY-SUBRC LE 17.
      CLO_RETURN = 8. EXIT.
    ELSE.
      CLO_RETURN = 4. <STATUS>-CORR_NBR = VIM_LOCKED_IN_CORR. EXIT.
    ENDIF.
  ELSE.
    READ TABLE CLO_TE071 INTO CLO_E071 INDEX 1.
    READ TABLE CLO_TTADIR INTO CLO_TADIR INDEX 1.
    IF CLO_TADIR-DEVCLASS IS INITIAL.
      CALL FUNCTION 'TR_EDIT_CHECK_OBJECTS_KEYS'
           EXPORTING
                WI_ORDER                       = CLO_E071-TRKORR
                WI_WITH_DIALOG                 = 'X'
*           WI_OBJ_CATEGOGY_MIX            = 'X'
                WI_SEND_MESSAGE                = ' '
           IMPORTING
*           WE_ORDER                       =
                WE_TASK                        = CLO_E071-TRKORR
*           WE_OBJECTS_APPENDABLE          =
*           EV_ERRNUM                      =
*           EV_OBJECT_UNLOCKED             =
           TABLES
                WT_E071                        = CLO_TE071
                WT_E071K                       = CLO_TE071K
                WT_TADIR                       = CLO_TTADIR
           EXCEPTIONS
                CANCEL_EDIT_APPEND_ERROR_KEYS  = 1
                CANCEL_EDIT_APPEND_ERROR_OBJCT = 2
                CANCEL_EDIT_APPEND_ERROR_ORDER = 3
                CANCEL_EDIT_BUT_SE01           = 4
                CANCEL_EDIT_NO_HEADER_OBJECT   = 5
                CANCEL_EDIT_NO_ORDER_SELECTED  = 6
                CANCEL_EDIT_REPAIRED_OBJECT    = 7
                CANCEL_EDIT_SYSTEM_ERROR       = 8
                CANCEL_EDIT_TADIR_MISSING      = 9
                CANCEL_EDIT_TADIR_UPDATE_ERROR = 10
                CANCEL_EDIT_UNKNOWN_DEVCLASS   = 11
                CANCEL_EDIT_UNKNOWN_OBJECTTYPE = 12
                CANCEL_EDIT_NO_CHECK_CALL      = 13
                CANCEL_EDIT_CATEGORY_MIXTURE   = 14
                CANCEL_EDIT_USER_AFTER_ERROR   = 15
                CANCEL_EDIT_CUSTOM_OBJ_AT_SAP  = 16
                CANCEL_EDIT_ACCESS_DENIED      = 17
                SHOW_ONLY_CLOSED_SYSTEM        = 18
                SHOW_ONLY_CONSOLIDATION_LEVEL  = 19
                SHOW_ONLY_DDIC_IN_CUSTOMER_SYS = 20
                SHOW_ONLY_DELIVERY_SYSTEM      = 21
                SHOW_ONLY_DIFFERENT_ORDERTYPES = 22
                SHOW_ONLY_DIFFERENT_TASKTYPES  = 23
                SHOW_ONLY_ENQUEUE_FAILED       = 24
                SHOW_ONLY_GENERATED_OBJECT     = 25
                SHOW_ONLY_ILL_LOCK             = 26
                SHOW_ONLY_LOCK_ENQUEUE_FAILED  = 27
                SHOW_ONLY_MIXED_ORDERS         = 28
                SHOW_ONLY_MIX_LOCAL_TRANSP_OBJ = 29
                SHOW_ONLY_NO_SHARED_REPAIR     = 30
                SHOW_ONLY_OBJECT_LOCKED        = 31
                SHOW_ONLY_REPAIRED_OBJECT      = 32
                SHOW_ONLY_SHOW_CLIENT          = 33
                SHOW_ONLY_TADIR_MISSING        = 34
                SHOW_ONLY_UNKNOWN_DEVCLASS     = 35
                SHOW_ONLY_CLOSED_CLIENT        = 36
                SHOW_ONLY_CLOSED_ALE_OBJECT    = 37
                SHOW_ONLY_UNALLOWED_SUPERUSER  = 38
                SHOW_ONLY_NO_REPAIR_SYSTEM     = 39
                SHOW_ONLY_NO_LICENSE           = 40
                SHOW_ONLY_CENTRAL_BASIS        = 41
                SHOW_ONLY_USER_AFTER_ERROR     = 42
                SHOW_ONLY_OBJECT_NOT_PATCHABLE = 43.
      IF SY-SUBRC NE 0.
        MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        IF SY-SUBRC LE 17.
          CLO_RETURN = 8. EXIT.
        ELSE.
          CLO_RETURN = 4. <STATUS>-CORR_NBR = VIM_LOCKED_IN_CORR. EXIT.
        ENDIF.
      ELSE.
        READ TABLE CLO_TE071 INTO CLO_E071 INDEX 1.
        READ TABLE CLO_TTADIR INTO CLO_TADIR INDEX 1.
      ENDIF.
    ENDIF.
  ENDIF.
* PERFORM MCOMMEDITCHECK(RDDINSYS)
*                        CHANGING CLO_E071 CLO_TADIR CLO_DDERR.
* IF CLO_DDERR-SEVERITY EQ 'F'.
*   IF CLO_DDERR-ERRNUM EQ '16'.       "repair requested
*     PERFORM FCOMMEDITCHECK(RDDINSYS)
*                            CHANGING CLO_E071 CLO_TADIR CLO_DDERR.
*     IF CLO_DDERR-SEVERITY EQ 'F'.
*       CASE CLO_DDERR-ERRNUM.
*         WHEN 4.                      "display
**          MAINT_MODE = STATUS-ACTION = ANZEIGEN.
**          EXIT.
*           CLO_RETURN = 4. <STATUS>-CORR_NBR = VIM_LOCKED_IN_CORR.
*           EXIT.
*         WHEN 12.                     "cancel edit
**          RAISE MISSING_CORR_NUMBER.
*           CLO_RETURN = 8. EXIT.
*       ENDCASE.
*     ENDIF.
*   ELSEIF CLO_DDERR-ERRNUM EQ '17' OR "no TADIR or
*          CLO_DDERR-ERRNUM EQ '18'.   "missing devclass
*     IF CLO_DDERR-ERRNUM EQ '17'.
*       MESSAGE S133(SV). "Bitte Transporteigenschaften eingeben
*     ELSE.
*       MESSAGE S486(TK) WITH CLO_TADIR-DEVCLASS.
*     ENDIF.
*     CLO_TADIR-PGMID    = CLO_E071-PGMID.
*     CLO_TADIR-OBJECT   = CLO_E071-OBJECT.
*     CLO_TADIR-OBJ_NAME = CLO_E071-OBJ_NAME.
*     CALL FUNCTION 'TADIR_PFLEGE'
*          EXPORTING
*               ADIR      = CLO_TADIR
*               E71TEMP   = CLO_E071
*               START_ROW = 2
*          IMPORTING
*               NEWADIR   = CLO_TADIR
*               PDDERR    = CLO_DDERR
*          EXCEPTIONS
*               ILL_TYPE  = 01.
*     IF SY-SUBRC NE 0.
*       MESSAGE I095(SV) WITH E071-TRKORR. "Systemfehler
**      RAISE MISSING_CORR_NUMBER.
*       CLO_RETURN = 8. EXIT.
*     ENDIF.
*     IF CLO_DDERR-SEVERITY EQ 'F'.
*       CASE CLO_DDERR-ERRNUM.
*         WHEN 4.                      "display
**          MAINT_MODE = STATUS-ACTION = ANZEIGEN.
**          EXIT.
*           CLO_RETURN = 4. <STATUS>-CORR_NBR = VIM_LOCKED_IN_CORR.
*           EXIT.
*         WHEN 12.                     "cancel edit
**          RAISE MISSING_CORR_NUMBER.
*           CLO_RETURN = 8. EXIT.
*       ENDCASE.
*     ELSE.
*       CALL FUNCTION 'TRINT_CHANGE_TADIR_MASTERLANG'
*            EXPORTING
*                 WI_TADIR_PGMID               = CLO_TADIR-PGMID
*                 WI_TADIR_OBJECT              = CLO_TADIR-OBJECT
*                 WI_TADIR_OBJ_NAME            = CLO_TADIR-OBJ_NAME
*                 WI_TADIR_MASTERLANG          = SY-LANGU
*            EXCEPTIONS
*                 MASTERLANG_NOT_ALLOWED       = 1.
*       IF SY-SUBRC NE 0. "language not allowed
*         MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
*           WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*       ENDIF.
*     ENDIF.
*   ELSE.  "other problems in MCOMM....
*     MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
*             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
**    MESSAGE I733(TK).
*     IF CLO_DDERR-ERRNUM EQ '4'.   "display
*       CLO_RETURN = 4. <STATUS>-CORR_NBR = VIM_LOCKED_IN_CORR.
*       EXIT.
*     ELSE.                         "cancel
*       CLO_RETURN = 8. EXIT.
*     ENDIF.
**    MESSAGE I095(SV) WITH E071-TRKORR. "Systemfehler
**    RAISE MISSING_CORR_NUMBER.
*   ENDIF.                             " clo_dderr-errnum in ( 17, 18 )
* ENDIF.                               "clo_dderr-severity eq 'F'
* first check if devclass is ok
* SELECT SINGLE * FROM TADIR INTO CLO_TADIR "already done in MCOMMEDITCH
*                            WHERE PGMID    = CLO_E071-PGMID
*                              AND OBJECT   = CLO_E071-OBJECT
*                              AND OBJ_NAME = CLO_E071-OBJ_NAME.
* IF TADIR-DEVCLASS(1) EQ '$'. "local object -> no transport
  IF CLO_TADIR IS INITIAL.             "may be no lockable object?
    CALL FUNCTION 'TR_CHECK_OBJECT_LOCK'
         EXPORTING
              WI_OBJECT                  = CLO_E071-OBJECT
              WI_OBJNAME                 = CLO_E071-OBJ_NAME
              WI_PGMID                   = CLO_E071-PGMID
         IMPORTING
              WE_LOCKABLE_OBJECT         = CLO_LOCKABLE
              WE_LOCKED                  = CLO_LOCKED
              WE_LOCK_TASK               = CLO_LOCK_TASK
              WE_LOCK_TASK_USER          = CLO_LOCK_USER
              WE_LOCK_ORDER              = CLO_LOCK_ORDER
              WE_OBJECT_EDITABLE         = CLO_EDITABLE
* 4.0 Namesp. WE_POSSIBLE_USER_EDIT_TASK = CLO_TADIR-KORRNUM
              WE_POSSIBLE_USER_EDIT_TASK = CLO_ICORR
         EXCEPTIONS
              EMPTY_KEY                  = 01
              NO_SYSTEMNAME              = 02
              NO_SYSTEMTYPE              = 03
              UNALLOWED_LOCK_ORDER       = 04.
    IF SY-SUBRC NE 0.
      MESSAGE I095(SV) WITH E071-TRKORR. "Systemfehler
*     RAISE MISSING_CORR_NUMBER.
      CLO_RETURN = 8. EXIT.
    ENDIF.
    IF CLO_LOCKABLE EQ SPACE.          "yes no lockable object
      VIM_CORR_OBJTAB-LOCKABLE = SPACE.
      MODIFY VIM_CORR_OBJTAB.
      EXIT.
    ELSE.                              "inconsistent object.
      MESSAGE I095(SV) WITH E071-TRKORR. "Systemfehler
      CLO_RETURN = 8. EXIT.
    ENDIF.
  ENDIF.                               "clo_tadir is initial
  CALL FUNCTION 'VIEW_GET_DEVCLASS_STATE'
       EXPORTING
            DEV_CLASS          = CLO_TADIR-DEVCLASS
       IMPORTING
            TRANSPORT_POSSIBLE = CLO_TRANSPORTABLE
       EXCEPTIONS
            NOT_FOUND          = 01.
  IF CLO_TRANSPORTABLE EQ SPACE.       "local object -> no transport
    X_HEADER-FLAG = VIM_TRANSPORT_DENIED.
    MODIFY X_HEADER INDEX 1.
  ELSE.
* second check if all objects have valid source systems
    IF VIM_LAST_SOURCE_SYSTEM EQ SPACE.
      VIM_LAST_SOURCE_SYSTEM = CLO_TADIR-SRCSYSTEM.
    ELSE.
      IF CLO_TADIR-SRCSYSTEM EQ SY-SYSID.    "if one object has sy-sysid
        IF VIM_LAST_SOURCE_SYSTEM NE SY-SYSID."all objs must have sy-sys
          MESSAGE I134(SV). "Inkonsistenz in Objektdefinition, nur Anzei
*       MAINT_MODE = STATUS-ACTION = ANZEIGEN.
*       EXIT.
          CLO_RETURN = 4. <STATUS>-CORR_NBR = VIM_LOCKED_IN_CORR. EXIT.
        ENDIF.
      ELSE. "if one object has another source system, all objects must
        IF VIM_LAST_SOURCE_SYSTEM EQ SY-SYSID. "another source system
          MESSAGE I134(SV). "Inkonsistenz in Objektdefinition, nur Anzei
*       MAINT_MODE = STATUS-ACTION = ANZEIGEN.
*       EXIT.
          CLO_RETURN = 4. <STATUS>-CORR_NBR = VIM_LOCKED_IN_CORR. EXIT.
        ENDIF.
      ENDIF.
    ENDIF.
    CALL FUNCTION 'TR_CHECK_OBJECT_LOCK'
         EXPORTING
              WI_OBJECT                  = CLO_E071-OBJECT
              WI_OBJNAME                 = CLO_E071-OBJ_NAME
              WI_PGMID                   = CLO_E071-PGMID
         IMPORTING
              WE_LOCKABLE_OBJECT         = CLO_LOCKABLE
              WE_LOCKED                  = CLO_LOCKED
              WE_LOCK_TASK               = CLO_LOCK_TASK
              WE_LOCK_TASK_USER          = CLO_LOCK_USER
              WE_LOCK_ORDER              = CLO_LOCK_ORDER
              WE_OBJECT_EDITABLE         = CLO_EDITABLE
* 4.0 Namesp. WE_POSSIBLE_USER_EDIT_TASK = CLO_TADIR-KORRNUM
              WE_POSSIBLE_USER_EDIT_TASK = CLO_ICORR
         EXCEPTIONS
              EMPTY_KEY                  = 01
              NO_SYSTEMNAME              = 02
              NO_SYSTEMTYPE              = 03
              UNALLOWED_LOCK_ORDER       = 04.
    IF SY-SUBRC NE 0.
      MESSAGE I095(SV) WITH E071-TRKORR. "Systemfehler
*     RAISE MISSING_CORR_NUMBER.
      CLO_RETURN = 8. EXIT.
    ENDIF.
    IF CLO_LOCKABLE EQ SPACE.
      VIM_CORR_OBJTAB-LOCKABLE = SPACE.
      MODIFY VIM_CORR_OBJTAB.
      EXIT.
    ENDIF.
    IF CLO_LOCKED NE SPACE.
      IF CLO_EDITABLE EQ SPACE.
        MESSAGE I132(SV) WITH CLO_LOCK_TASK CLO_LOCK_USER.
*       MAINT_MODE = STATUS-ACTION = ANZEIGEN.
*       EXIT.
        CLO_RETURN = 4. <STATUS>-CORR_NBR = VIM_LOCKED_IN_CORR. EXIT.
      ELSE.
*       CLO_E071-TRKORR = CLO_TADIR-KORRNUM.   "4.0 Namespace
        CLO_E071-TRKORR = CLO_ICORR.   "4.0 Namespace
      ENDIF.
    ENDIF.                             "clo_locked
  ENDIF.                               "devclass
  IF <STATUS>-CORR_NBR NE SPACE AND CLO_E071-TRKORR NE SPACE.
    IF CLO_E071-TRKORR NE <STATUS>-CORR_NBR.
      IF <STATUS>-ORDER_NBR NE CLO_LOCK_ORDER.
        MESSAGE I129(SV). "Zusammengehörige Objekte in verschied
*       RAISE MISSING_CORR_NUMBER.
        CLO_RETURN = 4. <STATUS>-CORR_NBR = VIM_LOCKED_IN_CORR. EXIT.
      ENDIF.
      VIM_CORR_OBJTAB-TRKORR = CLO_E071-TRKORR.
      MODIFY VIM_CORR_OBJTAB.
    ENDIF.
  ELSE.
    IF <STATUS>-CORR_NBR EQ SPACE.
      <STATUS>-CORR_NBR = CLO_E071-TRKORR.
      <STATUS>-ORDER_NBR = CLO_LOCK_ORDER.
    ENDIF.
  ENDIF.
  TRANSLATE <STATUS>-TR_ALRCHKD USING ' x'.
  CLEAR CLO_RETURN.
ENDFORM.                               "check_lockable_object

*---------------------------------------------------------------------*
*       FORM CHECK_TRANSP_OBJS_FOR_MAINT                              *
*---------------------------------------------------------------------*
*  check transport objects for logging during maintenance             *
*---------------------------------------------------------------------*
FORM check_transp_objs_for_maint USING ctofm_return TYPE i.
  DATA: obj_appendable(1) TYPE c, rc LIKE sy-subrc, e071_safe LIKE e071,
      last_order LIKE e071-trkorr, ctofm_ko200_tab LIKE ko200 OCCURS 10,
        ctofm_keytab_safe LIKE corr_keytab OCCURS 50,
        last_corr LIKE e071-trkorr.

  CLEAR ctofm_return.
  CHECK maint_mode EQ aendern.
* Insert IMG-activity
  PERFORM vim_get_img_activity CHANGING e071-activity.  "UF738595/2001
  IF vim_corr_obj_viewname NE x_header-viewname.
    CLEAR e071-trkorr.
    PERFORM get_transp_info.
    CHECK x_header-flag NE vim_transport_denied.
    IF maint_mode EQ anzeigen. ctofm_return = 4. EXIT. ENDIF.
  ELSE. " csn ext.382209 2002 XB
    IF NOT objh IS INITIAL.
      IF x_header-importable IS INITIAL.
        x_header-importable = objh-importable.
      ENDIF.
    ENDIF.
  ENDIF.
  CHECK vim_client_state EQ vim_log.
  IF <status>-corr_nbr NE <status>-l_corr_nbr.
    CLEAR: <status>-tr_alrchkd, <status>-corr_enqud.
  ENDIF.
  IF <status>-tr_alrchkd NE space.
    vim_corr_obj_viewname = x_header-viewname.
    EXIT.
  ENDIF.
* first get corr nbr for lockable transport objects
  e071_safe = e071.
  CLEAR vim_last_source_system.
  LOOP AT vim_corr_objtab WHERE lockable NE space.
    e071 = vim_corr_objtab.
    PERFORM check_lockable_object USING e071 ctofm_return.
    IF ctofm_return NE 0 OR x_header-flag EQ vim_transport_denied.
      EXIT.
    ENDIF.
  ENDLOOP.
  IF ctofm_return NE 0 OR x_header-flag EQ vim_transport_denied.
    e071 = e071_safe. EXIT.
  ENDIF.
  vim_corr_obj_viewname = x_header-viewname.
* second: check unlockable objects
* REFRESH VIM_ULO_TRSP_OBJS.
  LOOP AT vim_corr_objtab WHERE lockable EQ space.
    e071 = vim_corr_objtab.
*   APPEND E071 TO VIM_ULO_TRSP_OBJS.
    APPEND e071 TO ctofm_ko200_tab.
  ENDLOOP.
  IF sy-subrc EQ 0.                    "only if unlockable objects exist
* CTOFM_KO200_TAB = VIM_ULO_TRSP_OBJS.
    LOOP AT corr_keytab.               "save keys of other objects
      LOOP AT vim_corr_objtab WHERE lockable EQ space
                                AND object   EQ corr_keytab-mastertype
                                AND obj_name EQ corr_keytab-mastername.
        EXIT.
      ENDLOOP.
      CHECK sy-subrc NE 0.
      APPEND corr_keytab TO ctofm_keytab_safe.
      DELETE corr_keytab.
    ENDLOOP.
    last_order = <status>-order_nbr.
    last_corr = <status>-corr_nbr.
    CALL FUNCTION 'TR_OBJECTS_CHECK'
      IMPORTING
        we_order                = <status>-order_nbr
        we_task                 = <status>-corr_nbr
        we_objects_appendable   = obj_appendable
      TABLES
        wt_ko200                = ctofm_ko200_tab
        wt_e071k                = corr_keytab
      EXCEPTIONS
        cancel_edit_other_error = 1
        show_only_other_error   = 2
        OTHERS                  = 3.
    IF sy-subrc NE 0.
      rc = sy-subrc.
      MESSAGE ID      sy-msgid
              TYPE    'I'
              NUMBER  sy-msgno
              WITH    sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      IF rc = 2.
*     MAINT_MODE = STATUS-ACTION = ANZEIGEN.
        ctofm_return = 4.
        e071 = e071_safe. EXIT.
      ELSE.                            "cancel edit
*     RAISE MISSING_CORR_NUMBER.
        ctofm_return = 8. e071 = e071_safe. EXIT.
      ENDIF.
    ENDIF.
    IF <status>-corr_nbr NE space AND last_corr NE space.
      IF last_corr NE <status>-corr_nbr.
        IF <status>-order_nbr NE last_order.
          MESSAGE i129(sv). "Zusammengehörige Objekte in verschied
*       RAISE MISSING_CORR_NUMBER.
          ctofm_return = 4. e071 = e071_safe. EXIT.
        ENDIF.
      ENDIF.
    ELSE.
      IF <status>-corr_nbr EQ space.
        <status>-corr_nbr = last_corr.
        <status>-order_nbr = last_order.
      ENDIF.
    ENDIF.
    LOOP AT ctofm_keytab_safe INTO corr_keytab. "restore saved entries
      APPEND corr_keytab.
    ENDLOOP.
    IF obj_appendable EQ space.        "no ...INSERT - call required
      vim_client_state = vim_noact.
    ENDIF.
  ENDIF.                               "unlockable objects exist
  e071 = e071_safe.
  <status>-tr_alrchkd = 'x'.
ENDFORM.                               "check_transp_objs_for_maint
*&---------------------------------------------------------------------*
*&      Form  vim_get_img_activity
*&---------------------------------------------------------------------*
*       Gets IMG-activity the dialogue has been called from.
*       UF738595/2001
*----------------------------------------------------------------------*
*      <--P_ACTIVITY  IMG-activity
*----------------------------------------------------------------------*
FORM vim_get_img_activity  CHANGING p_activity TYPE e071-activity.

  CALL FUNCTION 'READ_IMG_ACTIVITY_FROM_MEMORY'
    IMPORTING
      img_activity = p_activity.
ENDFORM.                    " get_img_activity

*---------------------------------------------------------------------*
*       FORM PREPARE_CORR                                             *
*---------------------------------------------------------------------*
*       prepare command file tables (E070, E071)                      *
*---------------------------------------------------------------------*
FORM prepare_corr.
  DATA: x030l_sadr type x030l,
        pc_objtype LIKE objs-objecttype,
        pc_maint_mode(1) TYPE c.

  CHECK x_header-flag NE vim_transport_denied.
  CHECK maint_mode EQ transportieren OR"transport mode or change mode
        vim_client_state EQ vim_log.   "and logging required
  IF <status>-tr_alrchkd EQ 'x'.
* send warning if generic transport is required "HCG and no BCset import
    IF x_header-generictrp NE space and vim_import_profile NE 'X'.
      MESSAGE i141(sv) WITH vim_max_trsp_keylength
                            vim_max_trsp_identical_key
                            x_header-maxtrkeyln.
    ELSEIF x_header-genertxtrp NE space and vim_import_profile NE 'X'.
      MESSAGE i141(sv) WITH vim_max_trsp_keylength
                            vim_max_trsp_identical_key
                            x_header-maxtrtxkln.
    ENDIF.
    DESCRIBE TABLE vim_corr_objtab.
    IF sy-tfill GT 0.                  "save objects in corr_keytab
      CLEAR corr_keytab.
      MOVE x_header-viewname TO corr_keytab-mastername.
      LOOP AT vim_corr_objtab.
        IF vim_corr_objtab-lockable EQ space.
          corr_keytab-mastertype = vim_unlockable_object.
        ELSE.
          corr_keytab-mastertype = vim_lockable_object.
        ENDIF.
        MOVE: vim_corr_objtab-pgmid    TO corr_keytab-pgmid,
              vim_corr_objtab-object   TO corr_keytab-object,
*             VIM_CORR_OBJTAB-OBJ_NAME TO CORR_KEYTAB-OBJNAME,
              vim_corr_objtab-objfunc  TO corr_keytab-objfunc,
        vim_corr_objtab-activity TO corr_keytab-activity. "UF738595/2001
        sy-fdpos = strlen( vim_corr_objtab-obj_name ).
        IF sy-fdpos GT vim_71k_name_length.
          corr_keytab-objname = vim_long_objname.
          corr_keytab-tabkey  = vim_corr_objtab-obj_name.
        ELSE.
          corr_keytab-objname = vim_corr_objtab-obj_name.
        ENDIF.
        READ TABLE corr_keytab
                   WITH KEY pgmid      = corr_keytab-pgmid
                            object     = corr_keytab-object
                            objname    = corr_keytab-objname
                            objfunc    = corr_keytab-objfunc
                            mastertype = corr_keytab-mastertype
                            mastername = corr_keytab-mastername
                   TRANSPORTING NO FIELDS.
        CHECK sy-subrc NE 0.
        IF vim_corr_objtab-trkorr EQ space.
          MOVE: <status>-corr_nbr    TO corr_keytab-trkorr,
                <status>-corr_nbr    TO vim_corr_objtab-trkorr.
          MODIFY vim_corr_objtab.
        ELSE.
          corr_keytab-trkorr = vim_corr_objtab-trkorr.
        ENDIF.
        corr_keytab-flag = 'V'.
        APPEND corr_keytab.
      ENDLOOP.
    ENDIF.                             "sy-tfill
  ENDIF.                               "<status>-tr_alrchkd eq 'x'.
  IF maint_mode EQ transportieren.
    MOVE 'X' TO get_corr_keytab.
    IF <status>-keytbinvld EQ space.
      LOOP AT vim_corr_objtab WHERE lockable EQ space.
        LOOP AT corr_keytab WHERE mastertype EQ vim_corr_objtab-object
                             AND mastername EQ vim_corr_objtab-obj_name.
          EXIT.
        ENDLOOP.
        IF sy-subrc EQ 0.
          CLEAR get_corr_keytab.
        ENDIF.
      ENDLOOP.
    ELSE.
      LOOP AT vim_corr_objtab WHERE lockable EQ space.
        LOOP AT corr_keytab WHERE mastertype EQ vim_corr_objtab-object
                             AND mastername EQ vim_corr_objtab-obj_name.
          DELETE corr_keytab.
        ENDLOOP.
      ENDLOOP.
    ENDIF.
  ENDIF.
  MOVE <status>-corr_nbr TO <status>-l_corr_nbr.
  <status>-tr_alrchkd = 'X'.
  IF ( status-action EQ transportieren OR
       vim_client_state EQ vim_log ) AND
     x_header-adrnbrflag EQ 'O' AND sadr_namtab_read EQ space.
    CALL FUNCTION 'DDIF_NAMETAB_GET'
      EXPORTING
        tabname           = 'SADR'
      IMPORTING
        X030L_WA          = x030l_sadr
      EXCEPTIONS
        OTHERS            = 2.
    IF sy-subrc EQ 0.
      MOVE 'X' TO sadr_namtab_read.
      sadr_keylen = x030l_sadr-keylen
                     / cl_abap_char_utilities=>charsize.
* Übrgangslösung Adreßtabellen SADR2...SADR5 zu 3.0A Anfang
      IF x_header-bastab EQ space.
        pc_objtype = 'V'.
      ELSE.
        pc_objtype = 'S'.
      ENDIF.
      CALL FUNCTION 'VIEW_CHECK_OBJ_LIST_FOR_ADDR'
        EXPORTING
          objectname                     = x_header-viewname
          objecttype                     = pc_objtype
        EXCEPTIONS
          not_all_address_tables_in_list = 01.
      IF sy-subrc NE 0. "regenerating of object list required
        pc_maint_mode = x_header-bastab.
        TRANSLATE pc_maint_mode USING ' VXS'.
        CALL FUNCTION 'OBJ_GENERATE'
          EXPORTING
            iv_objectname    = x_header-viewname
            iv_objecttype    = pc_maint_mode
            iv_maint_mode    = aendern
            iv_no_correction = 'X'
          EXCEPTIONS
            OTHERS           = 5.
      ENDIF.
* Übrgangslösung Adreßtabellen SADR2...SADR5 zu 3.0A Ende
    ELSE.
      RAISE nametab_get_failed.
    ENDIF.
  ENDIF.
ENDFORM.                    "PREPARE_CORR

*---------------------------------------------------------------------*
*       FORM UPDATE_CORR                                              *
*---------------------------------------------------------------------*
*       update correction command file                                *
* UF230499: no changing of X_HEADER-KEYLEN if key is to long for
*           transport. Move appropriate key length to KEYLEN instead.
* UF170200: same for translated text fields
*---------------------------------------------------------------------*
* CORR_ACTION ->(glob) action: D - delete from, A - add to command file
*---------------------------------------------------------------------*
FORM update_corr.
  LOCAL: x_header.
  DATA: rc LIKE sy-subrc, fails TYPE i, flag TYPE c, rc1 LIKE sy-subrc,
        uc_addr_71ktab LIKE e071k OCCURS 0, addr_e071k LIKE e071k,
        object_key TYPE ad_objkey, keylen TYPE syfleng,
        txtkeylen TYPE syfleng, sys_type(10) TYPE c,
        texttab_wa TYPE REF TO data,
        max_trsp_keylength_in_byte type i.
  FIELD-SYMBOLS: <adr_obj_key> TYPE x, <texttab_wa> TYPE ANY,
                 <texttab_wax> TYPE x, <lang> TYPE ANY.

  CHECK maint_mode EQ aendern OR maint_mode EQ transportieren.
  CHECK x_header-flag NE vim_transport_denied.
  max_trsp_keylength_in_byte = vim_max_trsp_keylength
   * cl_abap_char_utilities=>charsize.
  CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'transport/systemtype'
                     ID 'VALUE' FIELD sys_type.
  IF x_header-keylen GT max_trsp_keylength_in_byte.
    keylen = x_header-maxtrkeyln.                           "UF230499
  ELSE.                                                     "UF230499
    keylen = x_header-keylen.                               "UF230499
  ENDIF.
  IF x_header-textkeylen GT max_trsp_keylength_in_byte.
    txtkeylen = x_header-maxtrtxkln.                        "UF230499
  ELSE.                                                     "UF230499
    txtkeylen = x_header-textkeylen.                        "UF230499
  ENDIF.
  IF x_header-adrnbrflag EQ 'N'.
    ASSIGN object_key TO <adr_obj_key> CASTING.
    LOOP AT vim_addr_e071k_tab INTO addr_e071k.
      e071k-trkorr = <status>-corr_nbr.
    ENDLOOP.
  ENDIF.
  IF status-action EQ transportieren.
* force marked entries
************************************************************************
    CHECK vim_client_state NE vim_local_clnt.
    IF status-mode EQ list_bild.
* overview_screen
      IF ( x_header-frm_e071ks NE space OR x_header-flag EQ space ) AND
         vim_called_by_cluster NE space.
        PERFORM vim_store_state_info.
        CALL FUNCTION 'VIEWCLUSTER_TRANS_DEPENDENT'
          EXPORTING
            view_name   = x_header-viewname
            action      = corr_action
            status_mode = status-mode
            workarea    = extract
            no_dialog   = vim_external_mode
            corr_number = <status>-corr_nbr.
      ENDIF.
      CLEAR counter.
      LOOP AT extract.
        CHECK <xmark> EQ markiert.
        PERFORM move_extract_to_view_wa.
        IF x_header-flag EQ space.     "standard logging required
          IF x_header-bastab EQ space. "view
            PERFORM (corr_formname) IN PROGRAM (sy-repid)
                                                   USING corr_action rc.
          ELSE.                        "base table
            corr_keytab =  e071k.
            corr_keytab-objname = x_header-maintview.
            MOVE <vim_xextract_key> TO <vim_corr_keyx>(keylen).
            PERFORM update_corr_keytab USING corr_action rc.
            IF x_header-texttbexst NE space AND  "base table with
            <vim_xextract_text> NE <text_initial_x>.     "text table
* only texttable's original language shall be transported internally
              corr_keytab =  e071k.
              corr_keytab-objname = x_header-texttab.
              MOVE <vim_xextract_text> TO <vim_corr_keyx>(txtkeylen).
              PERFORM update_corr_keytab USING corr_action rc1.
              IF rc1 EQ 0. MOVE rc1 TO rc. ENDIF.
            ENDIF.
          ENDIF.
          IF x_header-texttbexst <> space AND        "SW Texttransl ..
             vim_texttab_is_ro EQ space.
            PERFORM vim_text_keytab_entry
                    USING <vim_xextract_key> corr_action rc1.
            IF rc1 EQ 0. MOVE rc1 TO rc. ENDIF.
          ENDIF.                       ".. Texttransl
          IF x_header-adrnbrflag EQ 'O' AND <address_number> NE space.
            PERFORM vim_address_keytab_entries USING corr_action rc1.
            IF rc1 EQ 0. MOVE rc1 TO rc. ENDIF.
          ELSEIF x_header-adrnbrflag EQ 'N' AND
                 <address_number> NE space.
            APPEND LINES OF vim_addr_e071k_tab TO uc_addr_71ktab.
*            object_key = <vim_total_key>.
            <adr_obj_key>(keylen) = <vim_xextract_key>. "UF474925/2000
            CALL FUNCTION 'ADDR_TRANSPORT_ENTRIES'
              EXPORTING
                addrnumber = <address_number>
                table_name = vim_addr_basetable
                field_name = vim_addr_bastab_field
                objkey     = object_key
              TABLES
                e071k_tab  = uc_addr_71ktab.
            vim_exit_11_12_active = 'X'.
            LOOP AT uc_addr_71ktab INTO corr_keytab WHERE
             mastername = vim_addr_e071k_master_46 OR    "UF688403/2000
             mastername = vim_addr_e071k_master.
* Rel < 4.6A: ignore old type address entries inserted only for downward
*             compatibility
              PERFORM update_corr_keytab USING corr_action rc1.
              IF rc1 EQ 0. MOVE rc1 TO rc. ENDIF.
            ENDLOOP.
            REFRESH uc_addr_71ktab.
            CLEAR vim_exit_11_12_active.
          ENDIF.
        ENDIF.                         "standard logging required
        IF x_header-frm_e071ks NE space.
          vim_exit_11_12_active = 'X'.
          PERFORM (x_header-frm_e071ks) IN PROGRAM (sy-repid).
          IF sy-subrc EQ 0. MOVE sy-subrc TO rc. ENDIF.
          CLEAR vim_exit_11_12_active.
        ELSE.
          IF x_header-frm_e071 NE space AND
             x_header-frm_e071ka EQ space.
            <status>-keytbmodfd = 'X'.
          ENDIF.
          IF x_header-flag NE space.
            EXIT.
          ENDIF.
        ENDIF.
        IF rc NE 0.
          ADD 1 TO fails.
          IF replace_mode NE space.
            READ TABLE total WITH KEY <vim_xextract_key> BINARY SEARCH.
            <mark> = <xmark> = nicht_markiert.
            MODIFY total INDEX sy-tabix.
            MODIFY extract.
            SUBTRACT: 1 FROM mark_total, 1 FROM mark_extract.
            ok_code = 'IGN '.
          ENDIF.
        ELSE.
          READ TABLE total WITH KEY <vim_xextract_key> BINARY SEARCH.
          <mark> = <xmark> = nicht_markiert.
*          IF rc EQ 0.                          "??? UF222098
          CASE corr_action.
            WHEN hinzufuegen.
              MOVE transportieren TO <action>.
            WHEN geloescht.
              CLEAR <action>.
          ENDCASE.
          <xact> = <action>.
*          ENDIF.
          MODIFY total INDEX sy-tabix.
          MODIFY extract.
          SUBTRACT: 1 FROM mark_total, 1 FROM mark_extract.
        ENDIF.
        ADD 1 TO counter.
      ENDLOOP.
      IF counter GT fails.
        IF fails GT 0.
          MOVE 4 TO rc.
        ELSE.
          CLEAR rc.
        ENDIF.
      ELSE.
        MOVE 8 TO rc.
      ENDIF.
      IF replace_mode EQ space.
        IF corr_action EQ hinzufuegen.
          IF counter EQ 1.
            IF rc EQ 0.
          MESSAGE s098(sv) WITH <status>-corr_nbr. "Eintr. in K. aufgen.
            ELSE.
          MESSAGE s107(sv) WITH <status>-corr_nbr. "Eintr. schon enthal.
            ENDIF.
          ELSE.
            SUBTRACT fails FROM counter.
            CASE rc.
              WHEN 0.
                MESSAGE s105(sv) WITH counter
                                <status>-corr_nbr. "Eintr. in K. aufgen.
              WHEN 4.
                MESSAGE s109(sv) WITH counter fails
                                  <status>-corr_nbr. "Eintr. schon enth.
              WHEN 8.
                MESSAGE s108(sv) WITH fails
                                  <status>-corr_nbr. "Eintr. schon enth.
            ENDCASE.
          ENDIF.
        ELSE.
          IF counter EQ 1.
            IF rc EQ 0.
          MESSAGE s099(sv) WITH <status>-corr_nbr. "Eintr.aus K. gelösch
            ELSE.
          MESSAGE s110(sv) WITH <status>-corr_nbr. "Eintr. schon enthal.
            ENDIF.
          ELSE.
            SUBTRACT fails FROM counter.
            CASE rc.
              WHEN 0.
                MESSAGE s106(sv) WITH counter
                               <status>-corr_nbr. "Eintr. aus K. gelösch
              WHEN 4.
                MESSAGE s111(sv) WITH counter fails
                                  <status>-corr_nbr. "Eintr. nicht enth.
              WHEN 8.
                MESSAGE s112(sv) WITH fails
                                  <status>-corr_nbr. "Eintr. nicht enth.
            ENDCASE.
          ENDIF.
        ENDIF.
      ENDIF.                           "replace_mode eq space
    ELSE.
* detail screen
      IF x_header-flag EQ space.
* standard logging required
        IF x_header-bastab EQ space.
* view
          PERFORM (corr_formname) IN PROGRAM (sy-repid)
                                                   USING corr_action rc.
        ELSE.
* base table
          corr_keytab =  e071k.
          corr_keytab-objname = x_header-maintview.
*          MOVE <table1> TO corr_keytab-tabkey(x_header-keylen).
          MOVE <table1_x> TO <vim_corr_keyx>(keylen).
          PERFORM update_corr_keytab USING corr_action rc.
          IF x_header-texttbexst NE space
           AND <table1_text> NE <text_initial>.
* base table with text table
            corr_keytab =  e071k.
            corr_keytab-objname = x_header-texttab.
            MOVE <table1_xtext> TO <vim_corr_keyx>(txtkeylen).
            PERFORM update_corr_keytab USING corr_action rc1.
            IF rc1 EQ 0. MOVE rc1 TO rc. ENDIF.
          ENDIF.
        ENDIF.
        IF x_header-texttbexst <> space AND        "SW Texttransl ..
           vim_texttab_is_ro EQ space.
          PERFORM vim_text_keytab_entry
                  USING <table1_x> corr_action rc1.
          IF rc1 EQ 0. MOVE rc1 TO rc. ENDIF.
        ENDIF.                         ".. Texttransl
        IF x_header-adrnbrflag EQ 'O' AND <address_number> NE space.
          PERFORM vim_address_keytab_entries USING corr_action rc1.
          IF rc1 EQ 0. MOVE rc1 TO rc. ENDIF.
        ELSEIF x_header-adrnbrflag EQ 'N' AND
               <address_number> NE space.
* transport addresses
          APPEND LINES OF vim_addr_e071k_tab TO uc_addr_71ktab.
*          object_key = <vim_extract_key>.
          <adr_obj_key>(keylen) = <vim_xextract_key>.
          CALL FUNCTION 'ADDR_TRANSPORT_ENTRIES'
            EXPORTING
              addrnumber = <address_number>
              table_name = vim_addr_basetable
              field_name = vim_addr_bastab_field
              objkey     = object_key
            TABLES
              e071k_tab  = uc_addr_71ktab.
          vim_exit_11_12_active = 'X'.
          LOOP AT uc_addr_71ktab INTO corr_keytab WHERE
           mastername = vim_addr_e071k_master_46 OR    "UF688403/2000
           mastername = vim_addr_e071k_master.
* Rel < 4.6A: ignore old type address entries inserted only for downward
*             compatibility
            PERFORM update_corr_keytab USING corr_action rc1.
            IF rc1 EQ 0. MOVE rc1 TO rc. ENDIF.
          ENDLOOP.
          REFRESH uc_addr_71ktab.
          CLEAR vim_exit_11_12_active.
        ENDIF.
      ENDIF.                           "standard logging required
      IF x_header-frm_e071ks NE space.
        vim_exit_11_12_active = 'X'.
        PERFORM (x_header-frm_e071ks) IN PROGRAM (sy-repid).
        IF sy-subrc EQ 0. MOVE sy-subrc TO rc. ENDIF.
        CLEAR vim_exit_11_12_active.
      ELSE.
        IF x_header-frm_e071 NE space AND
           x_header-frm_e071ka EQ space.
          IF x_header-flag NE space.
            <status>-keytbmodfd = 'E'.
          ELSE.
            <status>-keytbmodfd = 'X'.
          ENDIF.
        ENDIF.
      ENDIF.
      IF <status>-keytbmodfd NE 'E'.
        IF vim_called_by_cluster NE space.
          PERFORM vim_store_state_info.
          CALL FUNCTION 'VIEWCLUSTER_TRANS_DEPENDENT'
            EXPORTING
              view_name   = x_header-viewname
              action      = corr_action
              status_mode = status-mode
              workarea    = extract
              no_dialog   = vim_external_mode
              corr_number = <status>-corr_nbr.
        ENDIF.
      ELSE.
        <status>-keytbmodfd = 'X'.
      ENDIF.
      READ TABLE total WITH KEY <vim_xextract_key> BINARY SEARCH.
      IF rc EQ 0.
        CASE corr_action.
          WHEN hinzufuegen.
            MOVE transportieren TO <action>.
          WHEN geloescht.
            CLEAR <action>.
        ENDCASE.
        <xact> = <action>.
        MOVE 'X' TO flag.
      ELSE.
        IF replace_mode NE space.
          ok_code = 'IGN '.
        ENDIF.
      ENDIF.
      IF <xmark> EQ markiert.
        <mark> = <xmark> = nicht_markiert.
        SUBTRACT: 1 FROM mark_total, 1 FROM mark_extract.
        MOVE 'X' TO flag.
      ENDIF.
      IF flag NE space.
        MODIFY total INDEX sy-tabix.
        MODIFY extract INDEX nextline.
      ENDIF.
      IF replace_mode EQ space.
        IF corr_action EQ hinzufuegen.
          IF rc EQ 0.
            MESSAGE s098(sv) WITH <status>-corr_nbr."Eintr. in K. aufg.
          ELSE.
            MESSAGE s107(sv) WITH <status>-corr_nbr."Eintr. schon enthl.
          ENDIF.
        ELSE.
          IF rc EQ 0.
            MESSAGE s099(sv) WITH <status>-corr_nbr."Eintr.aus K. gelösc
          ELSE.
            MESSAGE s110(sv) WITH <status>-corr_nbr."Eintr. schon enthl.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
  ELSE.
* logging of changed entries
***********************************************************************
    CHECK vim_client_state EQ vim_log.
    corr_action = hinzufuegen.
*   REFRESH CORR_KEYTAB. "only delete all keys for current object
    LOOP AT vim_corr_objtab WHERE objfunc NE space.
      LOOP AT corr_keytab WHERE mastertype EQ vim_corr_objtab-object
                            AND mastername EQ vim_corr_objtab-obj_name.
        DELETE corr_keytab.
      ENDLOOP.
    ENDLOOP.
    LOOP AT total.
      IF x_header-flag EQ space.       "standard logging required
        IF x_header-bastab EQ space.   "view
          CHECK <action> NE original AND <action> NE neuer_geloescht.
          MOVE <vim_total_struc> TO <table1>.
          PERFORM (corr_formname) IN PROGRAM (sy-repid)
                                                  USING corr_action rc.
        ELSE.                          "base table
          IF x_header-texttbexst EQ space.
            CHECK <action> NE original AND <action> NE neuer_geloescht.
          ELSE.
          CHECK <action> NE original AND <action> NE neuer_geloescht OR
                                         <action_text> NE original AND
                                       <action_text> NE neuer_geloescht.
          ENDIF.
          MOVE <vim_total_struc> TO <table1>.
          corr_keytab =  e071k.
          corr_keytab-objname = x_header-maintview.
          MOVE <vim_xtotal_key> TO <vim_corr_keyx>(keylen).
          PERFORM update_corr_keytab USING corr_action rc.
          IF x_header-texttbexst NE space AND       "base table with
             <vim_xtotal_text> NE <text_initial_x>. "text table
            corr_keytab =  e071k.
            corr_keytab-objname = x_header-texttab.
            MOVE <vim_xtotal_text> TO <vim_corr_keyx>(txtkeylen).
            PERFORM update_corr_keytab USING corr_action rc1.
          ENDIF.
        ENDIF.                         "base table or view
        IF x_header-adrnbrflag EQ 'O' AND <address_number> NE space.
          PERFORM vim_address_keytab_entries USING corr_action rc1.
        ELSEIF x_header-adrnbrflag EQ 'N' AND <address_number> NE space.
          READ TABLE vim_addresses_to_save
                        WITH KEY viewname = x_header-viewname
                                 addrnumber = <address_number>
                        BINARY SEARCH TRANSPORTING NO FIELDS.
          IF sy-subrc NE 0.            "only existing addresses possible
            APPEND LINES OF vim_addr_e071k_tab TO uc_addr_71ktab.
*            object_key = <vim_extract_key>.
            <adr_obj_key>(keylen) = <vim_xtotal_key>. "UF686454/2000
            CALL FUNCTION 'ADDR_TRANSPORT_ENTRIES'
              EXPORTING
                addrnumber = <address_number>
                table_name = vim_addr_basetable
                field_name = vim_addr_bastab_field
                objkey     = object_key
              TABLES
                e071k_tab  = uc_addr_71ktab.
            vim_exit_11_12_active = 'X'.
            LOOP AT uc_addr_71ktab INTO corr_keytab WHERE
             mastername = vim_addr_e071k_master_46 OR    "UF688403/2000
             mastername = vim_addr_e071k_master.
* Rel < 4.6A: ignore old type address entries inserted only for downward
*             compatibility
              PERFORM update_corr_keytab USING corr_action rc1.
              IF rc1 EQ 0. MOVE rc1 TO rc. ENDIF.
            ENDLOOP.
            REFRESH uc_addr_71ktab.
            CLEAR vim_exit_11_12_active.
          ENDIF.
        ENDIF.
      ENDIF.                           "standard logging required
      IF x_header-frm_e071ks NE space.
        vim_exit_11_12_active = 'X'.
        PERFORM (x_header-frm_e071ks) IN PROGRAM (sy-repid).
        CLEAR vim_exit_11_12_active.
      ELSE.
        IF x_header-flag NE space.
          EXIT.
        ENDIF.
      ENDIF.
    ENDLOOP.
    IF x_header-flag EQ space AND      "standard logging required
       x_header-texttbexst <> space.   "SW Texttransl ..
      PERFORM vim_text_keytab_entries USING corr_action rc1
                                            keylen          "UF170200
                                            txtkeylen.      "UF170200
    ENDIF.                             ".. Texttransl
  ENDIF.                               "maint_mode transport or update
  IF x_header-frm_e071ka NE space.
    vim_exit_11_12_active = 'X'.
    PERFORM (x_header-frm_e071ka) IN PROGRAM (sy-repid).
    CLEAR vim_exit_11_12_active.
    IF status-action EQ transportieren AND x_header-flag NE space AND
       x_header-frm_e071 NE space AND x_header-frm_e071ks EQ space AND
       vim_called_by_cluster NE space.
      PERFORM vim_store_state_info.
      CALL FUNCTION 'VIEWCLUSTER_TRANS_DEPENDENT'
        EXPORTING
          view_name   = x_header-viewname
          action      = corr_action
          status_mode = status-mode
          workarea    = extract
          no_dialog   = vim_external_mode
          corr_number = <status>-corr_nbr.
    ENDIF.
  ENDIF.
ENDFORM.                    "update_corr

*---------------------------------------------------------------------*
*       FORM VIM_ADDRESS_KEYTAB_ENTRIES
*---------------------------------------------------------------------*
* create address related keytab entries
*---------------------------------------------------------------------*
FORM vim_address_keytab_entries USING value(vake_action) TYPE c
                                      vake_rc TYPE i.
  STATICS: sadr2_keylen type syfleng.
  DATA: rc1 LIKE sy-subrc, x030l_wa type x030l.

  if sadr2_keylen is initial.
    CALL FUNCTION 'DDIF_NAMETAB_GET'
      EXPORTING
        tabname           = 'SADR2'
      IMPORTING
        X030L_WA          = x030l_wa
      EXCEPTIONS
        OTHERS            = 2.
    IF sy-subrc = 0.
      sadr2_keylen = x030l_wa-keylen / cl_abap_char_utilities=>charsize.
    else.
      RAISE nametab_get_failed.
    ENDIF.
  endif.
  SELECT SINGLE * FROM sadr WHERE adrnr EQ <address_number>.
  IF sy-subrc NE 0.
* Übergangslösung Adressumstellung 30F Anfang
    CALL FUNCTION 'ADDR_CONVERT_ADRC_TO_SADR'
      CHANGING
        address_number = <address_number>.
    IF <address_number> NE space.
      SELECT SINGLE * FROM sadr WHERE adrnr EQ <address_number>.
    ELSE.
      EXIT.
    ENDIF.
  ENDIF.
* Übergangslösung Adressumstellung 30F Ende
  vake_rc = 8.
  PERFORM vim_addr_keytab_entries_intern USING 'SADR' sadr
                                               sadr_keylen
                                               vake_action rc1.
  IF rc1 EQ 0.
    CLEAR vake_rc.
  ELSE.
    IF vake_action EQ pruefen.
      EXIT.
    ENDIF.
  ENDIF.
  SELECT COUNT(*) FROM sadr2 WHERE adrnr EQ sadr-adrnr.
  CLEAR sadr2.
  MOVE: sadr-mandt TO sadr2-mandt,
        sadr-adrnr TO sadr2-adrnr,
        '*' TO sadr2-stdfl.
  IF sy-dbcnt GT 0.                    "only if entries exist
    PERFORM vim_addr_keytab_entries_intern USING 'SADR2' sadr2
                                                 sadr2_keylen
                                                 vake_action rc1.
    IF rc1 EQ 0.
      CLEAR vake_rc.
    ELSE.
      IF vake_action EQ pruefen.
        vake_rc = 8. EXIT.
      ENDIF.
    ENDIF.
  ENDIF.
  SELECT COUNT(*) FROM sadr3 WHERE adrnr EQ sadr-adrnr.
  IF sy-dbcnt GT 0.                    "only if entries exist
    sadr3 = sadr2.
    PERFORM vim_addr_keytab_entries_intern USING 'SADR3' sadr3
                                                 sadr2_keylen
                                                 vake_action rc1.
    IF rc1 EQ 0.
      CLEAR vake_rc.
    ELSE.
      IF vake_action EQ pruefen.
        vake_rc = 8. EXIT.
      ENDIF.
    ENDIF.
  ENDIF.
  SELECT COUNT(*) FROM sadr4 WHERE adrnr EQ sadr-adrnr.
  IF sy-dbcnt GT 0.                    "only if entries exist
    sadr4 = sadr2.
    PERFORM vim_addr_keytab_entries_intern USING 'SADR4' sadr4
                                                 sadr2_keylen
                                                 vake_action rc1.
    IF rc1 EQ 0.
      CLEAR vake_rc.
    ELSE.
      IF vake_action EQ pruefen.
        vake_rc = 8. EXIT.
      ENDIF.
    ENDIF.
  ENDIF.
  SELECT COUNT(*) FROM sadr5 WHERE adrnr EQ sadr-adrnr.
  IF sy-dbcnt GT 0.                    "only if entries exist
    sadr5 = sadr2.
    PERFORM vim_addr_keytab_entries_intern USING 'SADR5' sadr5
                                                  sadr2_keylen
                                                  vake_action rc1.
    IF rc1 EQ 0.
      CLEAR vake_rc.
    ELSE.
      IF vake_action EQ pruefen.
        vake_rc = 8.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM.                               "vim_address_keytab_entries

*---------------------------------------------------------------------*
*       FORM VIM_ADDRESS_KEYTAB_ENTRIES_INTERN
*---------------------------------------------------------------------*
* create address related keytab entries (intern)
*---------------------------------------------------------------------*
FORM vim_addr_keytab_entries_intern
                          USING value(vakei_tabname) TYPE tabname
                                value(vakei_table)
                                value(vakei_keylen) TYPE i
                                value(vakei_action) TYPE sychar01
                                vakei_rc type sy-subrc.
  corr_keytab =  e071k.
  corr_keytab-objname = vakei_tabname.
  MOVE vakei_table TO corr_keytab-tabkey(vakei_keylen).
  vim_exit_11_12_active = 'X'.
  PERFORM update_corr_keytab USING vakei_action vakei_rc.
  CLEAR vim_exit_11_12_active.
ENDFORM. "vim_address_keytab_entries_intern

*---------------------------------------------------------------------*
*       FORM UPDATE_CORR_KEYTAB
*---------------------------------------------------------------------*
*       update CORR_KEYTAB
*---------------------------------------------------------------------*
* UET_ACTION ---> action: A - add to, D - delete from CORR_KEYTAB     *
*                         P - check if entry exists in CORR_KEYTAB    *
*                         W - do nothing
* CORR_KEYTAB (global) ---> header of CORR_KEYTAB with current entry  *
*---------------------------------------------------------------------*
FORM update_corr_keytab USING value(uet_action) uet_rc.
  DATA: e071k_safe LIKE e071k,
        asteriskpos TYPE i.
  MOVE: 1 TO uet_rc,
        corr_keytab TO e071k_safe.
* modify tabkey if only generic transport allowed
  IF vim_exit_11_12_active EQ space.
    IF e071k_safe-objname EQ x_header-texttab.
      IF x_header-genertxtrp NE space.
        asteriskpos
         = x_header-trtxgkpos / cl_abap_char_utilities=>charsize.
        CHECK e071k_safe-tabkey NE space.
        e071k_safe-tabkey+asteriskpos = '*'.
      ENDIF.
    ELSE.
      asteriskpos
       = x_header-trgkeypos / cl_abap_char_utilities=>charsize.
      IF x_header-generictrp NE space.
        e071k_safe-tabkey+asteriskpos = '*'.
      ENDIF.
    ENDIF.
  ELSE. "exits active - clear VIEWNAME for non-ddic-viewtables.
    CLEAR e071k_safe-viewname.
  ENDIF.
  CASE uet_action.
    WHEN hinzufuegen.
      IF e071k_safe-object EQ transp_object.     "table keys
        LOOP AT corr_keytab WHERE objname    EQ e071k_safe-objname
                              AND tabkey     EQ e071k_safe-tabkey
                              AND mastername EQ e071k_safe-mastername.
          IF corr_keytab-pgmid EQ vim_deleted_key.
            MOVE e071k_safe TO corr_keytab.
            MODIFY corr_keytab.
            CLEAR uet_rc.
          ENDIF.
          EXIT.
        ENDLOOP.
      ELSE.                            "other objects
        LOOP AT corr_keytab WHERE pgmid      EQ e071k_safe-pgmid
                              AND object     EQ e071k_safe-object
                              AND objname    EQ e071k_safe-objname
                              AND tabkey     EQ e071k_safe-tabkey
                              AND mastername EQ e071k_safe-mastername.
          IF corr_keytab-objfunc EQ 'D'.
            MOVE e071k_safe TO corr_keytab.
            MODIFY corr_keytab.
            CLEAR uet_rc.
          ENDIF.
          EXIT.
        ENDLOOP.
      ENDIF.
      IF sy-subrc NE 0.
        MOVE e071k_safe TO corr_keytab.
        APPEND corr_keytab.
        CLEAR uet_rc.
      ENDIF.
    WHEN geloescht.
      IF e071k_safe-object EQ transp_object.     "table keys
        LOOP AT corr_keytab WHERE objname    EQ e071k_safe-objname
                              AND tabkey     EQ e071k_safe-tabkey
                              AND mastername EQ e071k_safe-mastername
                              AND pgmid      NE vim_deleted_key.
          corr_keytab-pgmid = vim_deleted_key.
          MODIFY corr_keytab.
          CLEAR uet_rc.
          EXIT.
        ENDLOOP.
      ELSE.                            "other objects
        IF e071k_safe-mastername EQ space. "avoid error in exit rout.
          e071k_safe-mastername = master_name.
        ENDIF.
        LOOP AT corr_keytab WHERE pgmid      EQ e071k_safe-pgmid
                              AND object     EQ e071k_safe-object
                              AND objname    EQ e071k_safe-objname
                              AND tabkey     EQ e071k_safe-tabkey
                              AND mastername EQ e071k_safe-mastername.
*                             AND OBJFUNC    NE 'D'.
          IF corr_keytab-objfunc NE 'D'.
            corr_keytab-objfunc = 'D'.
            MODIFY corr_keytab.
            CLEAR uet_rc.
          ENDIF.
          EXIT.
        ENDLOOP.
* << Übergangslösung, da objekte zum Tabkey noch nicht eingelesen werden
        IF sy-subrc NE 0.
          MOVE e071k_safe TO corr_keytab.
          corr_keytab-objfunc = 'D'.
          APPEND corr_keytab.
          CLEAR uet_rc.
        ENDIF.
* >> Übergangslösung, da objekte zum Tabkey noch nicht eingelesen werden
      ENDIF.
    WHEN pruefen.
      IF e071k_safe-object EQ transp_object.     "table keys
        LOOP AT corr_keytab WHERE objname    EQ e071k_safe-objname
                              AND tabkey     EQ e071k_safe-tabkey
                              AND mastername EQ e071k_safe-mastername
                              AND pgmid      NE vim_deleted_key.
          CLEAR uet_rc.
          EXIT.
        ENDLOOP.
      ELSE.                            "other objects
        LOOP AT corr_keytab WHERE pgmid      EQ e071k_safe-pgmid
                              AND object     EQ e071k_safe-object
                              AND objname    EQ e071k_safe-objname
                              AND tabkey     EQ e071k_safe-tabkey
                              AND mastername EQ e071k_safe-mastername
                              AND objfunc    NE 'D'.
          CLEAR uet_rc.
          EXIT.
        ENDLOOP.
      ENDIF.
    WHEN vim_writing_bc_imp_log.
      APPEND corr_keytab.
  ENDCASE.
  IF uet_rc EQ 0 AND uet_action NE pruefen.
    MOVE 'X' TO <status>-keytbmodfd.
  ENDIF.
ENDFORM.                    "UPDATE_CORR_KEYTAB

*---------------------------------------------------------------------*
*       FORM CORR_UPD.                                                *
*---------------------------------------------------------------------*
*       Behandlung des FCODES 'SAVE' im Transportmodus                *
*       logging of changes                                            *
*---------------------------------------------------------------------*
FORM corr_upd.
  DATA: ko200 LIKE ko200, cu_e071k_tab LIKE e071k OCCURS 100,
      cu_e071_tab LIKE e071 OCCURS 10, cu_trpar LIKE trpar_int OCCURS 1,
        cu_trmess LIKE trmess_int OCCURS 1, cu_tadir LIKE tadir,
        cu_e071_htb LIKE e071 OCCURS 10, cu_dderr LIKE dderr,
        cu_corr_keytab_safe LIKE corr_keytab OCCURS 50,
        cu_corr_keyhtb LIKE corr_keytab OCCURS 50,
        lockable_objects_exist(1) TYPE c, e071_safe LIKE e071,
       cu_ko200_tab LIKE ko200 OCCURS 10, cu_last_corr LIKE e071-trkorr,
        w_cu_ko200 LIKE ko200,
        corr_for_insert LIKE e071-trkorr, rc LIKE sy-subrc,
        cu_new_locks LIKE strlocktab OCCURS 10, cu_begix TYPE i,
        cu_hobjfunc(1) TYPE c, cu_tdevc LIKE tdevc,
        cu_order_type LIKE e070-trfunction, cu_obj_not_chkd(1) TYPE c,
        cu_task_type LIKE e070-trfunction, cu_appendable(1) TYPE c,
        cu_request TYPE trwbo_request, cu_category LIKE vim_syst,
        cu_corr_objtab LIKE LINE OF vim_corr_objtab OCCURS 0,
        cu_last_cat LIKE vim_syst, cu_h_flag(1) TYPE c,
        cu_h_e071 LIKE e071, cuiorder LIKE e071-trkorr,
        cuitask LIKE e071-trkorr.

  DATA: lt_edt_objects       TYPE tredt_objects,
        ls_edt_object        TYPE LINE OF tredt_objects.
  FIELD-SYMBOLS: <ls_e071>   TYPE e071.

  FIELD-SYMBOLS: <vim_corr_objtab> LIKE vim_corr_objtab,
                 <e071> LIKE e071.

  CHECK maint_mode EQ transportieren OR vim_client_state EQ vim_log.
  CHECK x_header-flag NE vim_transport_denied.
  cu_h_flag = x_header-flag.
  IF vim_corr_obj_viewname NE x_header-viewname.
    REFRESH vim_corr_objtab.
  ELSE.
    cu_corr_objtab = vim_corr_objtab[].
  ENDIF.
  e071_safe = e071.
  CLEAR e071.
  LOOP AT corr_keytab WHERE mastername EQ x_header-viewname
                        AND ( mastertype EQ vim_unlockable_object
                              OR mastertype EQ vim_lockable_object ).
    MOVE: corr_keytab-trkorr  TO e071-trkorr,    "fill object tab
          corr_keytab-pgmid   TO e071-pgmid,
          corr_keytab-object  TO e071-object,
*         CORR_KEYTAB-OBJNAME TO E071-OBJ_NAME,
          corr_keytab-objfunc TO e071-objfunc,
          corr_keytab-activity TO e071-activity. "UF738595/2001
    IF corr_keytab-objname EQ vim_long_objname.
      e071-obj_name = corr_keytab-tabkey.
    ELSE.
      e071-obj_name = corr_keytab-objname.
    ENDIF.
    APPEND e071 TO cu_e071_tab.
    READ TABLE vim_corr_objtab WITH KEY pgmid = e071-pgmid
                                        object = e071-object
                                        obj_name = e071-obj_name
                               TRANSPORTING NO FIELDS.
    IF sy-subrc NE 0.                  "entry not found...
*      vim_corr_objtab = e071.
      MOVE-CORRESPONDING e071 TO vim_corr_objtab.     "UNICODE
      IF corr_keytab-mastertype EQ vim_unlockable_object.
*       APPEND E071 TO VIM_ULO_TRSP_OBJS.
        vim_corr_objtab-lockable = space.
      ELSE.
*       APPEND E071 TO VIM_LCK_TRSP_OBJS.
        vim_corr_objtab-lockable = lockable_objects_exist = 'X'.
      ENDIF.
      APPEND vim_corr_objtab.
      IF corr_keytab-flag EQ 'V'.
        IF vim_corr_obj_viewname NE x_header-viewname.
          APPEND vim_corr_objtab TO cu_corr_objtab.
        ENDIF.
      ELSE.
        cu_obj_not_chkd = 'X'.
      ENDIF.
    ELSEIF corr_keytab-mastertype EQ vim_lockable_object.
      lockable_objects_exist = 'X'.
    ENDIF.
  ENDLOOP.
  LOOP AT cu_e071_tab INTO e071.
    LOOP AT corr_keytab WHERE mastertype EQ e071-object
                          AND mastername EQ e071-obj_name
                          AND pgmid EQ vim_deleted_key.
      corr_keytab-pgmid = transporter. "collect all keys to
      APPEND corr_keytab TO cu_e071k_tab. "delete for all objects
      DELETE corr_keytab.
    ENDLOOP.
  ENDLOOP.
  vim_corr_obj_viewname = x_header-viewname.
* save keytab entries related to objects not in e071 tab
  LOOP AT corr_keytab.
    IF x_header-flag NE space AND x_header-frm_e071 EQ space AND
       ( x_header-frm_e071ka NE space OR x_header-frm_e071ks NE space ).
      IF corr_keytab-objname EQ vim_long_objname.
        READ TABLE cu_e071_tab WITH KEY
         object = corr_keytab-object
         obj_name = corr_keytab-tabkey
         TRANSPORTING NO FIELDS.
      ELSE.
        READ TABLE cu_e071_tab WITH KEY
         object = corr_keytab-object
         obj_name = corr_keytab-objname
         TRANSPORTING NO FIELDS.
      ENDIF.
      IF sy-subrc EQ 0.                "delete corr_keytab anyway
        DELETE corr_keytab.
      ENDIF.
    ELSE.
      READ TABLE cu_e071_tab WITH KEY
       object = corr_keytab-mastertype
       obj_name = corr_keytab-mastername
       TRANSPORTING NO FIELDS.
    ENDIF.
    CHECK sy-subrc NE 0.
    APPEND corr_keytab TO cu_corr_keytab_safe.
    DELETE corr_keytab.
  ENDLOOP.
  IF maint_mode EQ aendern AND lockable_objects_exist EQ space AND
     cu_obj_not_chkd NE space.
* may be objects are not yet checked
    LOOP AT cu_e071_tab ASSIGNING <e071>.        "UNICODE
      MOVE-CORRESPONDING <e071> TO w_cu_ko200.   "UNICODE
      APPEND w_cu_ko200 TO cu_ko200_tab.         "UNICODE
*    cu_ko200_tab = cu_e071_tab.
    ENDLOOP.                                     "UNICODE
    CALL FUNCTION 'TR_OBJECTS_CHECK'
*       exporting
*            IV_NO_SHOW_OPTION              = 'X'
       IMPORTING
            we_order                       = cuiorder
            we_task                        = cuitask
            we_objects_appendable          = cu_appendable
         TABLES
              wt_ko200                     = cu_ko200_tab
              wt_e071k                     = corr_keytab
       EXCEPTIONS
       cancel_edit_other_error       = 1
       show_only_other_error         = 2
       OTHERS                        = 3.
    IF sy-subrc NE 0 OR cu_appendable EQ space.
      rc = sy-subrc.
      LOOP AT cu_corr_keytab_safe INTO corr_keytab.
        APPEND corr_keytab.
      ENDLOOP.
      e071 = e071_safe. vim_corr_objtab[] = cu_corr_objtab.
      IF rc NE 0.
        MESSAGE ID     sy-msgid
                TYPE   'I'
                NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2  sy-msgv3 sy-msgv4.
        RAISE saving_correction_failed.
      ELSE.
        sy-subrc = rc.
        EXIT.
      ENDIF.
    ELSEIF cuiorder NE space OR cuitask NE space.
      <status>-order_nbr = cuiorder.
      <status>-corr_nbr = cuitask.
    ENDIF.
    REFRESH cu_ko200_tab.
  ENDIF. "may be objects are not yet checked
  IF maint_mode EQ aendern AND lockable_objects_exist NE space OR
     maint_mode EQ transportieren AND cu_obj_not_chkd NE space.
    IF cu_obj_not_chkd NE space.
* first check previously unchecked lockable objects
      CLEAR vim_last_source_system.
      LOOP AT vim_corr_objtab WHERE lockable NE space.
        READ TABLE cu_corr_objtab
                         WITH KEY pgmid  = vim_corr_objtab-pgmid
                                 object  = vim_corr_objtab-object
                                 obj_name = vim_corr_objtab-obj_name
                         TRANSPORTING NO FIELDS.
        CHECK sy-subrc NE 0.
        e071 = vim_corr_objtab.
        PERFORM check_lockable_object USING e071 rc.
        IF rc NE 0 OR x_header-flag EQ vim_transport_denied.
          x_header-flag = cu_h_flag. MODIFY x_header INDEX 1.
          MESSAGE i162(sv) WITH vim_corr_objtab-pgmid
                                vim_corr_objtab-object
                                vim_corr_objtab-obj_name.
          IF maint_mode EQ aendern.
            rc = 9. EXIT.
          ELSE.
            DELETE vim_corr_objtab.
          ENDIF.
        ENDIF.
      ENDLOOP.
      DESCRIBE TABLE vim_corr_objtab.
      IF maint_mode EQ aendern AND rc NE 0 OR sy-tfill EQ 0.
* restore saved keytab entries and corr_objtab
        LOOP AT cu_corr_keytab_safe INTO corr_keytab.
          APPEND corr_keytab.
        ENDLOOP.
        e071 = e071_safe.
        RAISE saving_correction_failed.
      ENDIF.
    ENDIF.                             "cu_obj_not_chckd ne space
    IF <status>-corr_nbr EQ space.
      LOOP AT vim_corr_objtab INTO e071.
        CALL FUNCTION 'TR_CHECK_TYPE'
          EXPORTING
            wi_e071     = e071
          IMPORTING
            we_tadir    = cu_tadir
            we_category = cu_category.
       CHECK cu_category EQ vim_syst OR cu_category EQ vim_cust_syst OR
                     cu_category EQ vim_appl.
        cu_last_cat = vim_syst. cu_h_e071 = e071.
      ENDLOOP.
      IF cu_last_cat EQ space.
        cu_category = vim_cust.
      ELSE.
        cu_category = cu_last_cat. e071 = cu_h_e071.
      ENDIF.
      CALL FUNCTION 'TRINT_GET_REQUEST_TYPE'
* UF041099 inserted instead of TRINT_CHECK_ORDER_TYPE
           EXPORTING
                iv_pgmid                   = e071-pgmid
                iv_object                  = e071-object
                iv_obj_name                = e071-obj_name
                iv_category                = cu_category
                is_tadir                   = cu_tadir
                is_tdevc                   = cu_tdevc
*                IV_USE_MEMORY              = 'X'
           IMPORTING
                ev_request_type            = cu_order_type
                ev_task_type               = cu_task_type
*                EV_TARGET                  =
           EXCEPTIONS
                internal_error             = 1
                no_request_needed          = 2
                cts_initialization_failure = 3
                OTHERS                     = 4.
      CASE sy-subrc.
        WHEN 0.
        WHEN 2.
          cu_order_type = 'K'.
          cu_task_type = 'S'.
        WHEN OTHERS.
          LOOP AT cu_corr_keytab_safe INTO corr_keytab.
            APPEND corr_keytab.
          ENDLOOP.
          e071 = e071_safe. vim_corr_objtab[] = cu_corr_objtab.
          MESSAGE ID     sy-msgid
                  TYPE   'I'
                  NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2  sy-msgv3 sy-msgv4.
          RAISE saving_correction_failed.
      ENDCASE.
      DO.
        CALL FUNCTION 'TRINT_ORDER_CHOICE'
          EXPORTING
            wi_order_type          = cu_order_type
            wi_task_type           = cu_task_type
            wi_category            = cu_category
            wi_cli_dep             = space
          IMPORTING
            we_order               = <status>-order_nbr
            we_task                = <status>-corr_nbr
          TABLES
            wt_e071                = cu_e071_tab
            wt_e071k               = corr_keytab
          EXCEPTIONS
            no_correction_selected = 1
            display_mode           = 2
            object_append_error    = 3
            recursive_call         = 4
            OTHERS                 = 5.
        IF sy-subrc NE 0.
* restore saved keytab entries and corr_objtab
          LOOP AT cu_corr_keytab_safe INTO corr_keytab.
            APPEND corr_keytab.
          ENDLOOP.
          e071 = e071_safe. vim_corr_objtab[] = cu_corr_objtab.
          IF sy-subrc NE 1.
            MESSAGE ID     sy-msgid
                    TYPE   'I'
                    NUMBER sy-msgno
                    WITH sy-msgv1 sy-msgv2  sy-msgv3 sy-msgv4.
          ENDIF.
          RAISE saving_correction_failed.
        ENDIF.                         "sy-subrc ne 0
        IF maint_mode EQ transportieren.
* enqueue corr
          CALL FUNCTION 'ENQUEUE_E_TRKORR'
               EXPORTING
                    trkorr = <status>-corr_nbr
*               X_TRKORR = E02
               EXCEPTIONS
                    foreign_lock = 01
                    system_failure = 02.
          CASE sy-subrc.
            WHEN 0.
            WHEN 1.
          MESSAGE s092(sv) WITH <status>-corr_nbr. "Korr. wirdger.bearb.
              CONTINUE.
            WHEN 2.
              MESSAGE a095(sv) WITH <status>-corr_nbr. "Systemfehler
              CONTINUE.
          ENDCASE.
          <status>-corr_enqud = 'X'.
          EXIT.
        ELSE.                          "change mode
          EXIT.
        ENDIF.                         "maint_mode eq transportieren
      ENDDO.
    ENDIF.                             "<status>-corr_nbr eq space.
* store corr number into tables
    LOOP AT cu_e071_tab INTO e071 WHERE trkorr EQ space.
      e071-trkorr = <status>-corr_nbr.
      MODIFY cu_e071_tab FROM e071.
      LOOP AT vim_corr_objtab WHERE pgmid = e071-pgmid
                                AND object = e071-object
                                AND obj_name = e071-obj_name.
        vim_corr_objtab-trkorr = <status>-corr_nbr.
        MODIFY vim_corr_objtab. EXIT.
      ENDLOOP.
      sy-fdpos = strlen( e071-obj_name ).
      IF sy-fdpos GT vim_71k_name_length.
        READ TABLE corr_keytab WITH KEY pgmid = e071-pgmid
                                        object = e071-object
                                        objname = vim_long_objname
                                        tabkey  = e071-obj_name.
      ELSE.
        READ TABLE corr_keytab WITH KEY pgmid = e071-pgmid
                                        object = e071-object
                                        objname = e071-obj_name.
      ENDIF.
      IF sy-subrc EQ 0.
        corr_keytab-trkorr = <status>-corr_nbr.
        MODIFY corr_keytab INDEX sy-tabix.
      ENDIF.
    ENDLOOP.
  ENDIF.
  IF maint_mode EQ transportieren OR lockable_objects_exist NE space.
    SORT cu_e071_tab BY trkorr.
    LOOP AT cu_e071_tab INTO e071 WHERE objfunc NE 'D'.
      cu_begix = sy-tabix + 1.
      EXIT.
    ENDLOOP.
    IF sy-subrc EQ 0.
      APPEND e071 TO cu_e071_htb.
      LOOP AT corr_keytab WHERE mastertype EQ e071-object
                            AND mastername EQ e071-obj_name.
        APPEND corr_keytab TO cu_corr_keyhtb.
      ENDLOOP.
      cu_last_corr = e071-trkorr.
      LOOP AT cu_e071_tab INTO e071 FROM cu_begix WHERE objfunc NE 'D'.
        IF e071-trkorr NE cu_last_corr.
*___________________________________________________________________
          LOOP AT cu_e071_htb ASSIGNING <ls_e071>.
            MOVE-CORRESPONDING <ls_e071> TO ls_edt_object.
            APPEND ls_edt_object TO lt_edt_objects.
          ENDLOOP.
          CALL FUNCTION 'TR_EC_CUST_ORIG_LANG'
            EXPORTING
              it_objects   = lt_edt_objects
              iv_checkmode = ' '
              iv_dialog    = 'X'
            CHANGING
              ct_keys      = cu_corr_keyhtb
            EXCEPTIONS
              cancel       = 1
              display_only = 2
              OTHERS       = 3.
          IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
*--------------------------------------------------------------------
          CALL FUNCTION 'TRINT_APPEND_TO_COMM_ARRAYS'
            EXPORTING
              wi_trkorr     = cu_last_corr
            TABLES
              wt_e071       = cu_e071_htb
              wt_e071k      = cu_corr_keyhtb
              wt_trmess_int = cu_trmess
              wt_trpar_int  = cu_trpar
            EXCEPTIONS
              OTHERS        = 08.
          IF sy-subrc NE 0.
* restore saved keytab entries and corr_objtab
            LOOP AT cu_corr_keytab_safe INTO corr_keytab.
              APPEND corr_keytab.
            ENDLOOP.
            e071 = e071_safe. vim_corr_objtab[] = cu_corr_objtab.
            MESSAGE ID     sy-msgid
                    TYPE   'I'
                    NUMBER sy-msgno
                    WITH sy-msgv1 sy-msgv2  sy-msgv3 sy-msgv4.
            RAISE saving_correction_failed.
          ENDIF.
          REFRESH: cu_e071_htb, cu_corr_keyhtb.
          cu_last_corr = e071-trkorr.
        ENDIF.
        APPEND e071 TO cu_e071_htb.
        LOOP AT corr_keytab WHERE mastertype EQ e071-object
                              AND mastername EQ e071-obj_name.
          APPEND corr_keytab TO cu_corr_keyhtb.
        ENDLOOP.
      ENDLOOP.
    ENDIF.                             "sy-subrc of loop at e071_tab
    DESCRIBE TABLE cu_e071_htb.
    IF sy-tfill NE 0.
*      CALL FUNCTION 'TR_APPEND_TO_COMM_OBJS_KEYS'
*        EXPORTING
**         WI_SIMULATION                        = ' '
**         WI_SUPPRESS_KEY_CHECK                = ' '
*          wi_trkorr                            = e071-trkorr
*        tables
*          wt_e071                              = cu_e071_htb
*          wt_e071k                             = cu_corr_keyhtb
*       EXCEPTIONS
*         KEY_CHAR_IN_NON_CHAR_FIELD           = 1
*         KEY_CHECK_KEYSYNTAX_ERROR            = 2
*         KEY_INTTAB_TABLE                     = 3
*         KEY_LONGER_FIELD_BUT_NO_GENERC       = 4
*         KEY_MISSING_KEY_MASTER_FIELDS        = 5
*         KEY_MISSING_KEY_TABLEKEY             = 6
*         KEY_NON_CHAR_BUT_NO_GENERIC          = 7
*         KEY_NO_KEY_FIELDS                    = 8
*         KEY_STRING_LONGER_CHAR_KEY           = 9
*         KEY_TABLE_HAS_NO_FIELDS              = 10
*         KEY_TABLE_NOT_ACTIV                  = 11
*         KEY_UNALLOWED_KEY_FUNCTION           = 12
*         KEY_UNALLOWED_KEY_OBJECT             = 13
*         KEY_UNALLOWED_KEY_OBJNAME            = 14
*         KEY_UNALLOWED_KEY_PGMID              = 15
*         KEY_WITHOUT_HEADER                   = 16
*         OB_CHECK_OBJ_ERROR                   = 17
*         OB_DEVCLASS_NO_EXIST                 = 18
*         OB_EMPTY_KEY                         = 19
*         OB_GENERIC_OBJECTNAME                = 20
*         OB_ILL_DELIVERY_TRANSPORT            = 21
*         OB_ILL_LOCK                          = 22
*         OB_ILL_PARTS_TRANSPORT               = 23
*         OB_ILL_SOURCE_SYSTEM                 = 24
*         OB_ILL_SYSTEM_OBJECT                 = 25
*         OB_ILL_TARGET                        = 26
*         OB_INTTAB_TABLE                      = 27
*         OB_LOCAL_OBJECT                      = 28
*         OB_LOCKED_BY_OTHER                   = 29
*         OB_MODIF_ONLY_IN_MODIF_ORDER         = 30
*         OB_NAME_TOO_LONG                     = 31
*         OB_NO_APPEND_OF_CORR_ENTRY           = 32
*         OB_NO_APPEND_OF_C_MEMBER             = 33
*         OB_NO_CONSOLIDATION_TRANSPORT        = 34
*         OB_NO_ORIGINAL                       = 35
*         OB_NO_SHARED_REPAIRS                 = 36
*         OB_NO_SYSTEMNAME                     = 37
*         OB_NO_SYSTEMTYPE                     = 38
*         OB_NO_TADIR                          = 39
*         OB_NO_TADIR_NOT_LOCKABLE             = 40
*         OB_PRIVAT_OBJECT                     = 41
*         OB_REPAIR_ONLY_IN_REPAIR_ORDER       = 42
*         OB_RESERVED_NAME                     = 43
*         OB_SYNTAX_ERROR                      = 44
*         OB_TABLE_HAS_NO_FIELDS               = 45
*         OB_TABLE_NOT_ACTIV                   = 46
*         TR_ENQUEUE_FAILED                    = 47
*         TR_ERRORS_IN_ERROR_TABLE             = 48
*         TR_ILL_KORRNUM                       = 49
*         TR_LOCKMOD_FAILED                    = 50
*         TR_LOCK_ENQUEUE_FAILED               = 51
*         TR_NOT_OWNER                         = 52
*         TR_NO_SYSTEMNAME                     = 53
*         TR_NO_SYSTEMTYPE                     = 54
*         TR_ORDER_NOT_EXIST                   = 55
*         TR_ORDER_RELEASED                    = 56
*         TR_ORDER_UPDATE_ERROR                = 57
*         TR_WRONG_ORDER_TYPE                  = 58
*         OB_INVALID_TARGET_SYSTEM             = 59
*         TR_NO_AUTHORIZATION                  = 60
*         OB_WRONG_TABLETYP                    = 61
*         OB_WRONG_CATEGORY                    = 62
*         OB_SYSTEM_ERROR                      = 63
*         OB_UNLOCAL_OBJEKT_IN_LOCAL_ORD       = 64
*         TR_WRONG_CLIENT                      = 65
*         OB_WRONG_CLIENT                      = 66
*         KEY_WRONG_CLIENT                     = 67
*         OTHERS                               = 68
*                .
*___________________________________________________________________
          LOOP AT cu_e071_htb ASSIGNING <ls_e071>.
            MOVE-CORRESPONDING <ls_e071> TO ls_edt_object.
            APPEND ls_edt_object TO lt_edt_objects.
          ENDLOOP.
          CALL FUNCTION 'TR_EC_CUST_ORIG_LANG'
            EXPORTING
              it_objects   = lt_edt_objects
              iv_checkmode = ' '
              iv_dialog    = 'X'
            CHANGING
              ct_keys      = cu_corr_keyhtb
            EXCEPTIONS
              cancel       = 1
              display_only = 2
              OTHERS       = 3.
          IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
*--------------------------------------------------------------------
      CALL FUNCTION 'TRINT_APPEND_TO_COMM_ARRAYS'
           EXPORTING
                wi_trkorr     = e071-trkorr
           TABLES
                wt_e071       = cu_e071_htb
                wt_e071k      = cu_corr_keyhtb
                wt_trmess_int = cu_trmess
                wt_trpar_int  = cu_trpar
*           EXCEPTIONS
*                OTHERS        = 08.
       EXCEPTIONS
         key_check_keysyntax_error          = 1
         ob_check_obj_error                 = 2
         tr_lockmod_failed                  = 3
         tr_lock_enqueue_failed             = 4
         tr_wrong_order_type                = 5
         tr_order_update_error              = 6
         file_access_error                  = 7
         ob_no_systemname                   = 8
         OTHERS                             = 9.
      IF sy-subrc NE 0.
* restore saved keytab entries and corr_objtab
        LOOP AT cu_corr_keytab_safe INTO corr_keytab.
          APPEND corr_keytab.
        ENDLOOP.
        e071 = e071_safe. vim_corr_objtab[] = cu_corr_objtab.
        MESSAGE ID     sy-msgid
                TYPE   'I'
                NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2  sy-msgv3 sy-msgv4.
        RAISE saving_correction_failed.
      ENDIF.
    ENDIF.
    IF maint_mode EQ transportieren.
* process deletion
      LOOP AT cu_e071_tab INTO e071 WHERE objfunc NE space.
        IF e071-objfunc EQ 'K'.
          CALL FUNCTION 'TRINT_DELETE_COMM_KEYS'
            EXPORTING
              wi_e071                = e071
              wi_trkorr              = <status>-corr_nbr
            TABLES
              wt_e071k               = cu_e071k_tab
            EXCEPTIONS
              e070_update_error      = 01
              keys_protected         = 02
              order_already_released = 03
              unallowed_ordertyp     = 04
              user_not_owner         = 05
              wrong_client           = 06.
          IF sy-subrc NE 0.
* restore saved keytab entries and corr_objtab
            LOOP AT cu_corr_keytab_safe INTO corr_keytab.
              APPEND corr_keytab.
            ENDLOOP.
            e071 = e071_safe. vim_corr_objtab[] = cu_corr_objtab.
*         MESSAGE S097(SV) WITH <STATUS>-CORR_NBR.
            MESSAGE ID     sy-msgid
                    TYPE   'I'
                    NUMBER sy-msgno
                    WITH sy-msgv1 sy-msgv2  sy-msgv3 sy-msgv4.
            RAISE saving_correction_failed.
          ELSE.
* check if object is to be deleted and delete it if necessary
            LOOP AT corr_keytab WHERE mastertype EQ e071-object
                                  AND mastername EQ e071-obj_name.
              EXIT.
            ENDLOOP.
          ENDIF.                       "sy-subrc of function call
        ELSEIF e071-objfunc EQ 'D'.
          sy-subrc = 8.
        ELSE.
          CLEAR sy-subrc.
        ENDIF.                         "e071-objfunc
        IF sy-subrc NE 0.
* delete object
          cu_hobjfunc = e071-objfunc.
          cu_request-objects = cu_e071_tab.
          cu_request-objects_filled = 'X'.
          CALL FUNCTION 'TRINT_DELETE_COMM_OBJECT_KEYS'
               EXPORTING
                    is_e071_delete              = e071
                    iv_dialog_flag              = ' '
*                IMPORTING
*                     ET_NEW_LOCKS                =
               CHANGING
                    cs_request                  = cu_request
               EXCEPTIONS
                    OTHERS = 8.

          IF sy-subrc NE 0.
* restore saved keytab entries and corr_objtab
            LOOP AT cu_corr_keytab_safe INTO corr_keytab.
              APPEND corr_keytab.
            ENDLOOP.
            e071 = e071_safe. vim_corr_objtab[] = cu_corr_objtab.
            MESSAGE ID     sy-msgid
                    TYPE   'I'
                    NUMBER sy-msgno
                    WITH sy-msgv1 sy-msgv2  sy-msgv3 sy-msgv4.
            RAISE saving_correction_failed.
          ENDIF. "sy-subrc of function call corr_delete_entry.
          IF sy-subrc EQ 0 AND "del. was successful or entry didn't ex.
             cu_hobjfunc EQ 'D'.       "and no table entry
            DELETE cu_corr_keytab_safe
              WHERE pgmid EQ e071-pgmid AND object EQ e071-object
                AND ( objname EQ e071-obj_name OR
                      objname EQ vim_long_objname AND
                      tabkey EQ e071-obj_name )
                AND objfunc EQ e071-objfunc.
          ENDIF.
        ENDIF.                         "sy-subrc for deletion
      ENDLOOP.
      CLEAR: <status>-keytbmodfd, <status>-upd_flag.
      MESSAGE s096(sv) WITH <status>-corr_nbr.
    ENDIF.                             "maint_mode eq transportieren.
  ELSE.
* change mode and no lockable objects
    ASSIGN vim_corr_objtab TO <vim_corr_objtab>.
    LOOP AT vim_corr_objtab.
      MOVE-CORRESPONDING <vim_corr_objtab> TO w_cu_ko200. "UNICODE
      APPEND w_cu_ko200 TO cu_ko200_tab.                  "UNICODE
    ENDLOOP.
    IF <status>-order_nbr NE space.
      corr_for_insert = <status>-order_nbr.
    ELSE.
      corr_for_insert = <status>-corr_nbr.
    ENDIF.

    CALL FUNCTION 'TR_OBJECTS_INSERT'
         EXPORTING
*             WI_ORDER                       = <STATUS>-ORDER_NBR
              wi_order                       = corr_for_insert
         IMPORTING
              we_order                       = <status>-order_nbr
              we_task                        = <status>-corr_nbr
         TABLES
              wt_ko200                       = cu_ko200_tab
              wt_e071k                       = corr_keytab
         EXCEPTIONS
              cancel_edit_other_error        = 4
              show_only_other_error          = 6
              OTHERS                         = 8.
    IF sy-subrc NE 0.
      rc = sy-subrc.
* restore saved keytab entries and corr_objtab
      LOOP AT cu_corr_keytab_safe INTO corr_keytab.
        APPEND corr_keytab.
      ENDLOOP.
      e071 = e071_safe. vim_corr_objtab[] = cu_corr_objtab.
      IF rc GT 4.
*       MESSAGE I097(SV) WITH <STATUS>-CORR_NBR.
        MESSAGE ID     sy-msgid
                TYPE   'I'
                NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2  sy-msgv3 sy-msgv4.
      ENDIF.
      RAISE saving_correction_failed.
    ENDIF.
    PERFORM vim_synchronizer_call
                             USING
                                  cu_ko200_tab[]
                                  corr_keytab[]
                                  space.
  ENDIF. "maint_mode eq transportieren or lockable_objects_exist ne spac
* delete saved keytab entries - but not in transport mode
  IF maint_mode EQ aendern.
    IF x_header-flag NE space AND x_header-frm_e071 EQ space AND
       ( x_header-frm_e071ks NE space OR x_header-frm_e071ka NE space ).
      REFRESH corr_keytab.
    ELSE.
      DELETE corr_keytab WHERE mastertype NE vim_unlockable_object
                           AND mastertype NE vim_lockable_object.
    ENDIF.
  ENDIF.
* restore saved keytab entries and set used task number
  LOOP AT cu_corr_keytab_safe INTO corr_keytab.
    IF corr_keytab-mastername EQ x_header-viewname AND
       ( corr_keytab-mastertype EQ vim_unlockable_object OR
         corr_keytab-mastertype EQ vim_lockable_object ).
      corr_keytab-trkorr = <status>-corr_nbr.
    ENDIF.
    APPEND corr_keytab.
  ENDLOOP.
  SUBTRACT sy-subrc FROM sy-subrc.
  e071 = e071_safe.
  LOOP AT vim_corr_objtab.
    READ TABLE cu_corr_objtab WITH KEY pgmid = vim_corr_objtab-pgmid
                                       object = vim_corr_objtab-object
                                     obj_name = vim_corr_objtab-obj_name
                              TRANSPORTING NO FIELDS.
    CHECK sy-subrc NE 0.               "delete added entries
    DELETE vim_corr_objtab.
  ENDLOOP.
  e071-trkorr = <status>-corr_nbr.
  last_corr_number = <status>-l_corr_nbr = <status>-corr_nbr.
  CLEAR <status>-keytbmodfd.
  FREE: cu_e071k_tab, cu_trmess, cu_trpar, cu_e071_tab,
        cu_corr_keytab_safe, cu_ko200_tab, cu_e071_htb, cu_new_locks.
ENDFORM.                    "corr_upd

*---------------------------------------------------------------------*
*       FORM TRANSPORTIEREN                                           *
*---------------------------------------------------------------------*
*       send popup to confirm: saving etc.                            *
*---------------------------------------------------------------------*
FORM TRANSPORTIEREN.
  CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
       EXPORTING
            TITEL         = SVIM_TEXT_020  "Einträge transportieren
            DIAGNOSETEXT1 = SVIM_TEXT_018  "Daten wurden verändert.
            DIAGNOSETEXT2 =
               SVIM_TEXT_021           "Wenn die Änderungen transport
            DIAGNOSETEXT3 =
               SVIM_TEXT_022           "werden sollen, müssen sie ers
            TEXTLINE1     = SVIM_TEXT_023  "gesichert werden.
            TEXTLINE2     = SVIM_TEXT_019  "Änderungen vorher sichern ?
       IMPORTING
            ANSWER        = ANSWER.
  CASE ANSWER.
    WHEN 'J'.
      SY-SUBRC = 0.
    WHEN 'N'.
      CLEAR <STATUS>-UPD_FLAG.
      SY-SUBRC = 8.
    WHEN 'A'.
      SY-SUBRC = 12.
  ENDCASE.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM GET_KEYTAB                                               *
*---------------------------------------------------------------------*
*       read table e071k                                              *
*---------------------------------------------------------------------*
FORM GET_KEYTAB.
  LOCAL: E071.
  LOOP AT VIM_CORR_OBJTAB INTO E071.
    CALL FUNCTION 'TRINT_READ_COMM_KEYS'
         EXPORTING
              WI_APPENDING = 'X'
              WI_E071      = E071
              WI_TRKORR    = <STATUS>-CORR_NBR
         TABLES
              WT_E071K     = CORR_KEYTAB.
  ENDLOOP.
  CLEAR: <STATUS>-KEYTBMODFD, GET_CORR_KEYTAB, <STATUS>-KEYTBINVLD.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM PREPARE_READ_REQUEST                                     *
*---------------------------------------------------------------------*
*       prepare global data for read request                          *
*---------------------------------------------------------------------*
FORM prepare_read_request.

  DATA: action TYPE activ_auth, oc_to_be_checked TYPE xfeld,
        sellines TYPE i.

  PERFORM init_state_vector.
  PERFORM vim_reset_texttab USING view_name.           "SW Texttransl
  PERFORM vim_bc_logs_get USING view_name x_header x_namtab[]
                          CHANGING vim_bc_entry_list.
  IF vim_adjust_middle_level_mode EQ subset. "ignore subsets
    vim_adj_header = x_header[].
    CLEAR x_header-subsetflag. MODIFY x_header INDEX 1.
    vim_adj_namtab = x_namtab[].
    LOOP AT x_namtab WHERE readonly EQ subset AND keyflag NE space.
      CLEAR x_namtab-readonly. MODIFY x_namtab.
    ENDLOOP.
    vim_adj_dbasellist = dba_sellist[].
    LOOP AT dba_sellist WHERE ddic CO vim_subset_marks.
      IF dba_sellist-value IS INITIAL AND dba_sellist-initial EQ space.
        DELETE dba_sellist. "unvollständige Subsetbedingungen löschen
      ELSE.
        TRANSLATE dba_sellist-ddic USING 'S BX'. "'S A BXMX'.
        MODIFY dba_sellist.
      ENDIF.
    ENDLOOP.
    DESCRIBE TABLE dba_sellist.
    IF sy-tfill GT 0.
      READ TABLE dba_sellist INDEX sy-tfill.
      CLEAR dba_sellist-and_or.
      MODIFY dba_sellist INDEX sy-tabix.
    ENDIF.
  ENDIF.
* remove old selections from authorisation
*  if not vim_dba_sel_kept is initial and vim_called_by_cluster = space.
*    refresh dba_sellist[].                                 "UF210200b
*    append lines of vim_dba_sel_kept to dba_sellist.
*  endif.
*  DELETE dba_sellist WHERE ddic = 'M'.
  IF vim_called_by_cluster = space.
    DELETE dba_sellist WHERE from_auth <> space
     AND ddic <> 'S' and ddic <> 'B'.                       "UF210200e
    DESCRIBE TABLE dba_sellist LINES sellines.
    IF sellines GT 0.
      READ TABLE dba_sellist INDEX sellines.
      CLEAR dba_sellist-and_or.
      MODIFY dba_sellist INDEX sy-tabix.
    ENDIF.
  ENDIF.                                                     "UF210200
  IF NOT vim_oc_inst IS INITIAL.
* insert selection from authorisation into sellist
    IF <status>-st_action = anzeigen.
      action = svorg_read.
    ELSE.
      action = svorg_maint.
    ENDIF.
    CALL METHOD vim_oc_inst->combine_vimsel_with_auth
      EXPORTING
        action  = action
      CHANGING
        sellist = dba_sellist[].
    CALL METHOD vim_oc_inst->get_to_be_checked
      IMPORTING
        to_be_checked = oc_to_be_checked.
    IF oc_to_be_checked <> space or x_header-bastab <> space.
* check TOTAL vs. authorisation after reading
      PERFORM vim_maint_selflag USING    'S'
                                CHANGING x_header-selection.
    ENDIF.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM VIM_FILL_WHERETAB                                        *
*---------------------------------------------------------------------*
* fill internal table for dynamic select                              *
*---------------------------------------------------------------------*
FORM VIM_FILL_WHERETAB.
  CALL FUNCTION 'VIEW_FILL_WHERETAB'
       EXPORTING
            TABLENAME               = X_HEADER-ROOTTAB
       TABLES
            SELLIST                 = DBA_SELLIST
            WHERETAB                = VIM_WHERETAB
            X_NAMTAB                = X_NAMTAB
       EXCEPTIONS
            NO_CONDITIONS_FOR_TABLE = 01.
ENDFORM.                               "vim_fill_wheretab.

*&--------------------------------------------------------------------*
*&      Form  EDIT_VIEW_ENTRY                                         *
*&--------------------------------------------------------------------*
*       edit entry in TOTAL/EXTRACT due to foreign request            *
*---------------------------------------------------------------------*
* ENTRY  ---> entry to edit                                           *
* ACTION ---> action: UPD - add/update, DEL - delete, UDL - undelete  *
*             IGN - mark entry as to ignore, MRK - mark/unmark entry  *
* SY_SUBRC -> return code: 0 - all right, others: failure             *
* EXT    ---> table containing selected view entries                  *
* TOT    ---> table containing all view entries                       *
* HEADER ---> table containing header information of current view     *
* NAMTAB ---> table containing information about current viewfields   *
* SELLIST --> table containing select options                         *
*---------------------------------------------------------------------*
FORM edit_view_entry TABLES ext tot
                            header  STRUCTURE vimdesc
                            namtab  STRUCTURE vimnamtab
                            sellist STRUCTURE vimsellist
                     USING value(entry) value(action).
  DATA: state_vect_name(37) TYPE c,
        rc LIKE sy-subrc, pos LIKE sy-fdpos,
        texttablename(31) TYPE c VALUE '*          ', mmark(1) TYPE c,
        tab_rc LIKE sy-subrc, tab_ix LIKE sy-tabix,
        dummy_tab LIKE vimexclfun OCCURS 1, name(20) TYPE c.
  FIELD-SYMBOLS: <tot_x> TYPE x, <ext_x> TYPE x, <ent_x> TYPE x,
                 <viewkey> TYPE x, <act> TYPE c, <xact> TYPE c,
                 <mrk> TYPE c, <xmrk> TYPE c,
                 <txt_act> TYPE c,
                 <tot_struc> TYPE ANY, <ent_struc> TYPE ANY,
                 <tot_txt> TYPE x, <ent_txt> TYPE x, <ent_txt2> TYPE x,
                 <tot_txt_struc> TYPE ANY, <txt_init> TYPE ANY.

  READ TABLE header INDEX 1.
  pos = header-after_tabc.
*  MOVE HEADER-TABLEN TO POS.
  ASSIGN: tot TO <tot_x> CASTING, ext TO <ext_x> CASTING,
          entry TO <ent_x> CASTING,
          <tot_x> TO <tot_struc> CASTING TYPE (header-maintview),
          <ent_x> TO <ent_struc> CASTING TYPE (header-maintview).
  IF header-bastab NE space AND header-texttbexst NE space.
* tab+txttb
    ADD header-aft_txttbc TO pos.
    MOVE header-texttab TO texttablename+1.
    ASSIGN: <tot_x>+header-after_tabc(header-texttablen) TO <tot_txt>,
            <ent_x>+header-after_tabc(header-texttablen) TO <ent_txt>,
            <tot_txt> TO <tot_txt_struc> CASTING TYPE (header-texttab),
            (texttablename) TO <txt_init>.
*    ASSIGN: TOT+HEADER-TABLEN(HEADER-TEXTTABLEN) TO <TOT_TXT>,
*            ENTRY+HEADER-TABLEN(HEADER-TEXTTABLEN) TO <ENT_TXT>,
*            (TEXTTABLENAME) TO <TXT_INIT>.
  ENDIF.
  ASSIGN: <ent_x>(header-keylen) TO <viewkey>,
          <tot_x>+pos(cl_abap_char_utilities=>charsize)
           TO <act> CASTING,
          <ext_x>+pos(cl_abap_char_utilities=>charsize)
           TO <xact> CASTING.
  ADD cl_abap_char_utilities=>charsize TO pos.
  ASSIGN: <tot_x>+pos(cl_abap_char_utilities=>charsize)
           TO <mrk> CASTING,
          <ext_x>+pos(cl_abap_char_utilities=>charsize)
           TO <xmrk> CASTING.
  IF header-bastab NE space AND header-texttbexst NE space."tab+txttb
    ADD cl_abap_char_utilities=>charsize TO pos.
    ASSIGN <tot_x>+pos(cl_abap_char_utilities=>charsize)
     TO <txt_act> CASTING.
  ENDIF.
*  ASSIGN: ENTRY(HEADER-KEYLEN) TO <VIEWKEY>,
*          TOT+POS(1) TO <ACT>.
*  ADD 1 TO POS.
*  ASSIGN TOT+POS(1) TO <MRK>.
*  IF HEADER-BASTAB NE SPACE AND HEADER-TEXTTBEXST NE SPACE."tab+txttb
*    ADD 1 TO POS.
*    ASSIGN TOT+POS(1) TO <TXT_ACT>.
*    SUBTRACT 1 FROM POS.
*  ENDIF.
  IF header-viewname NE last_ext_modif_view.
    MOVE state_vect_prefix TO state_vect_name.
    WRITE header-maintview TO state_vect_name+state_vect_prefix_length.
    ASSIGN (state_vect_name) TO <state>.
    MOVE header-viewname TO last_ext_modif_view.
  ENDIF.
  READ TABLE tot WITH KEY <viewkey> BINARY SEARCH.
  tab_rc = sy-subrc. tab_ix = sy-tabix.
  IF sy-subrc EQ 0.                    " entry found in TOT
    CASE action.
      WHEN 'DEL'.
        CASE <act>.
          WHEN neuer_eintrag.
            <act> = neuer_geloescht.
          WHEN original.
            <act> = geloescht.
          WHEN aendern.
            <act> = update_geloescht.
        ENDCASE.
        IF header-bastab NE space AND header-texttbexst NE space.
          CASE <txt_act>.
            WHEN neuer_eintrag.
              <txt_act>            = neuer_geloescht.
            WHEN original.
              IF <tot_txt_struc> NE <txt_init>.
                <txt_act>             = geloescht.
              ENDIF.
            WHEN aendern.
              <txt_act>             = update_geloescht.
          ENDCASE.
        ENDIF.
        mmark = <mrk>.
        IF <mrk> EQ markiert.
          <mrk> = nicht_markiert. SUBTRACT 1 FROM <state>-mk_to.
        ENDIF.
        MODIFY tot INDEX sy-tabix.
        READ TABLE ext WITH KEY <viewkey>.
        IF sy-subrc EQ 0.
          IF mmark EQ markiert.
            SUBTRACT 1 FROM <state>-mk_xt.
          ENDIF.
          DELETE ext INDEX sy-tabix.
          SUBTRACT 1 FROM <state>-maxlines.
        ENDIF.
      WHEN 'UPD'.
        IF header-bastab NE space AND header-texttbexst NE space.
          IF <tot_txt> NE <ent_txt>.
            IF <tot_txt_struc> EQ <txt_init>.
              <txt_act> = neuer_eintrag.
            ELSE.
              IF <txt_act> EQ original.
                <txt_act> = aendern.
              ENDIF.
            ENDIF.
            MOVE <ent_txt> TO <tot_txt>.
          ENDIF.
        ENDIF.
        MOVE <ent_struc> TO <tot_struc>.
        IF <act> EQ original.
          <act> = aendern.
        ENDIF.
        MODIFY tot INDEX sy-tabix.
        READ TABLE ext WITH KEY <viewkey>.
        IF sy-subrc EQ 0.
          MOVE tot TO ext.
          MODIFY ext INDEX sy-tabix.
        ENDIF.
      WHEN 'UDL'.
        CASE <act>.
          WHEN neuer_geloescht.
            <act> = neuer_eintrag.
          WHEN geloescht.
            <act> = original.
          WHEN update_geloescht.
            <act> = aendern.
          WHEN OTHERS.
            rc = 8.
        ENDCASE.
        IF rc EQ 0.
          IF header-bastab NE space AND header-texttbexst NE space.
            CASE <txt_act>.
              WHEN neuer_geloescht.
                <txt_act>         = neuer_eintrag.
              WHEN geloescht.
                <txt_act>         = original.
              WHEN update_geloescht.
                <txt_act>         = aendern.
            ENDCASE.
          ENDIF.
          MODIFY tot INDEX sy-tabix.
          READ TABLE ext WITH KEY <viewkey>.
          IF sy-subrc EQ 0.
            IF <state>-selected EQ geloescht.
              DELETE ext INDEX sy-tabix.
            ELSE.
              <xmrk> = <mrk>.
              <xact> = <act>.
              MODIFY ext INDEX sy-tabix.
            ENDIF.
          ENDIF.
        ENDIF.
      WHEN 'IGN'.
        IF <mrk> EQ markiert.
          MOVE uebergehen TO <mrk>.
          MODIFY tot INDEX sy-tabix.
          READ TABLE ext WITH KEY <viewkey>.
          IF sy-subrc EQ 0.
            <xmrk> = <mrk>.
            MODIFY ext INDEX sy-tabix.
          ENDIF.
        ENDIF.
        rc = 1.
      WHEN 'MRK'.
        IF <mrk> EQ markiert.
          MOVE nicht_markiert TO <mrk>.
        ELSE.
          MOVE markiert TO <mrk>.
        ENDIF.
        MODIFY tot INDEX sy-tabix.
        IF <mrk> EQ markiert.
          ADD 1 TO <state>-mk_to.
        ELSE.
          SUBTRACT 1 FROM <state>-mk_to.
        ENDIF.
        READ TABLE ext WITH KEY <viewkey>.
        IF sy-subrc EQ 0.
          <xmrk> = <mrk>.
          MODIFY ext INDEX sy-tabix.
          IF <mrk> EQ markiert.
            ADD 1 TO <state>-mk_xt.
          ELSE.
            SUBTRACT 1 FROM <state>-mk_xt.
          ENDIF.
        ENDIF.
        rc = 1.
    ENDCASE.
  ELSE.                                "entry NOT found in TOT
    CLEAR sy-subrc.
    IF action NE 'UPD'.
      rc = 8.
    ELSE.
      IF header-selection NE space.
        IF header-bastab <> space AND header-texttbexst <> space.
          ASSIGN <ent_txt> TO <ent_txt2>.
        ELSE.
          ASSIGN <ent_x> TO <ent_txt2>.
        ENDIF.
        CALL FUNCTION 'TABLE_RANGE_CHECK'
          EXPORTING
            tabname                   = header-maintview
            entry                     = entry
            entry_text                = <ent_txt2>
            ddic                      = 'J'
            key                       = 'J'
            ignore_blank_subsetfields = 'N'
          TABLES
            x_namtab                  = namtab
            x_header                  = header
            sellist                   = sellist
          EXCEPTIONS
            entry_not_fits            = 8.
      ENDIF.
      IF sy-subrc EQ 0.
        MOVE <ent_struc> TO <tot_struc>.
        <act> = neuer_eintrag.
        <mrk> = nicht_markiert.
        IF header-bastab NE space AND header-texttbexst NE space.
          <tot_txt> = <ent_txt>.
          IF <tot_txt_struc> NE <txt_init>.
            <txt_act> = neuer_eintrag.
          ELSE.
            <txt_act> = original.
          ENDIF.
        ENDIF.
        CASE tab_rc.
          WHEN 4.
            INSERT tot INDEX tab_ix.
          WHEN 8.
            APPEND tot.
        ENDCASE.
      ELSE.
        rc = sy-subrc.
      ENDIF.
    ENDIF.
  ENDIF.
  IF rc EQ 0.
    MOVE 'X' TO <state>-upd_flag.
  ENDIF.
  sy-subrc = ( rc DIV 8 ) * 8.
ENDFORM.                               " EDIT_VIEW_ENTRY

*&--------------------------------------------------------------------*
*&      Form ZURUECKHOLEN                                             *
*&--------------------------------------------------------------------*
* Behandeln der Funktion 'UNDO'                                       *
*---------------------------------------------------------------------*
FORM zurueckholen.

  DATA: number_of_ign_entr TYPE i, key_safe TYPE tabl1024,
        z_ign_entr_ex(1) TYPE c, z_specmode_safe(1) TYPE c.

  IF status-action NE aendern OR status-delete NE geloescht.
    MESSAGE i001(sv).
    EXIT.
  ENDIF.
  CLEAR counter. z_specmode_safe = vim_special_mode.
  vim_special_mode = vim_undelete.
  IF status-mode EQ detail_bild.
    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 <STATUS>-DISPL_MODE EQ EXPANDED.
    IF x_header-delmdtflag EQ space OR number_of_ign_entr LT 8.
      READ TABLE extract INDEX nextline.
    ELSE.
      READ TABLE total WITH KEY key_safe BINARY SEARCH.
      extract = total.
    ENDIF.
  ENDIF.
  IF x_header-frm_bf_udl NE space.
    PERFORM (x_header-frm_bf_udl) IN PROGRAM (sy-repid).
  ENDIF.
  IF vim_called_by_cluster NE space.
    PERFORM vim_store_state_info.
    CALL FUNCTION 'VIEWCLUSTER_UNDO_DEPENDENT'
         EXPORTING
              view_name         = x_header-viewname
              status_mode       = status-mode
              workarea          = extract
              no_dialog         = vim_external_mode
         IMPORTING
              ign_entries_exist = z_ign_entr_ex.
    IF z_ign_entr_ex NE space.
      ignored_entries_exist = z_ign_entr_ex.
    ENDIF.
  ENDIF.
  IF status-mode EQ list_bild.
    PERFORM liste_zurueckholen.
  ELSE.
    IF <xmark> NE uebergehen.
      PERFORM detail_zurueckholen.
    ENDIF.
  ENDIF.
  IF replace_mode NE space AND counter EQ 0.
    function = ok_code = 'IGN '.
  ENDIF.
  IF x_header-frm_af_udl NE space.
    PERFORM (x_header-frm_af_udl) IN PROGRAM (sy-repid).
  ELSE.
    IF ignored_entries_exist NE space.
      PERFORM mark_ignored_entries CHANGING number_of_ign_entr.
      IF replace_mode EQ space.
        IF number_of_ign_entr EQ 1.
          MESSAGE s113(sv). "Eintrag konnte nicht zurückgeholt werden
        ELSEIF number_of_ign_entr GT 1.
          MESSAGE s114(sv) WITH number_of_ign_entr.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.
* CLEAR VIM_SPECIAL_MODE.
  vim_special_mode = z_specmode_safe.
ENDFORM.                               " ZURUECKHOLEN

*&--------------------------------------------------------------------*
*&      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

*&--------------------------------------------------------------------*
*&      Form DELETE_CHECK_KEYRANGE                                    *
*&--------------------------------------------------------------------*
* check keyrange for delete                                           *
*---------------------------------------------------------------------*
FORM DELETE_CHECK_KEYRANGE.
  LOCAL: EXTRACT, TOTAL, <TABLE1>.
  DATA: DCK_SPECMODE_SAFE LIKE VIM_SPECIAL_MODE.

  CLEAR SY-SUBRC.
  CHECK X_HEADER-CUSTOMAUTH CO SAP_CUST_CTRL_CLASSES OR
        VIM_ALE_KEYSPEC_CHECK NE SPACE.
  DCK_SPECMODE_SAFE = VIM_SPECIAL_MODE.
  PERFORM MOVE_EXTRACT_TO_VIEW_WA.
  IF STATUS-MODE EQ LIST_BILD.
    VIM_SPECIAL_MODE = VIM_DELETE.
  ELSE.
    CLEAR VIM_SPECIAL_MODE.
  ENDIF.
  CLEAR VIM_KEYRANGE_ALR_CHECKED.
  PERFORM CHECK_ALLOWED_KEYRANGES.
* "HCG: In synchronization, Adjust and BC-Set import keyrange-check
*  should be neglected and data should be deleted anyway 24/06/2002
  IF SY-SUBRC NE 0 AND vim_import_profile EQ SPACE.
* synchornization only in BC-Set, only vim_import_profile is enought
* to test, if it is called from BC-Set. XB H594362 07022003
*                   AND DCK_SPECMODE_SAFE NE vim_upgrade.
    IF STATUS-MODE EQ LIST_BILD.
      CASE STATUS-TYPE.
        WHEN EINSTUFIG.
          CALL SCREEN LISTE.
          IF OK_CODE EQ 'IGN '. FUNCTION = OK_CODE. ENDIF.
        WHEN ZWEISTUFIG.
          PERFORM PROCESS_DETAIL_SCREEN USING 'C'.
          STATUS-MODE = LIST_BILD.
      ENDCASE.
    ENDIF.
    IF VIM_ALE_KEYSPEC_CHECK NE SPACE. "never delete ALE-locked keys
      FUNCTION = 'IGN '.
    ENDIF.
    CLEAR: SY-SUBRC, OK_CODE.
    CASE FUNCTION.
      WHEN 'IGN '. SY-SUBRC = 4.
      WHEN 'ABR '. SY-SUBRC = 8.
    ENDCASE.
  ENDIF.
* CLEAR VIM_SPECIAL_MODE.
  VIM_SPECIAL_MODE = DCK_SPECMODE_SAFE.
  FUNCTION = 'DELE'.
ENDFORM.                               "delete_check_keyrange

*&--------------------------------------------------------------------*
*&      Form  MARK_IGNORED_ENTRIES                                    *
*&--------------------------------------------------------------------*
* Wiederherstellen der Markierungen für 'übergangene' Einträge        *
*---------------------------------------------------------------------*
FORM mark_ignored_entries CHANGING mie_number.
  DATA: translation_mask(2) TYPE c, h_ix LIKE sy-tabix.

  CHECK ignored_entries_exist NE space.
  MOVE: uebergehen TO translation_mask,
        markiert   TO translation_mask+1(1).
  IF status-mode EQ list_bild.
    CLEAR mie_number.
    LOOP AT total.
      CHECK <mark> EQ uebergehen.
      ADD 1 TO mie_number.
      READ TABLE extract WITH KEY <vim_xtotal_key> BINARY SEARCH.
      IF sy-subrc EQ 0.
        TRANSLATE <xmark> USING translation_mask.
        MODIFY extract INDEX sy-tabix.
      ENDIF.
      TRANSLATE <mark> USING translation_mask.
      MODIFY total.
    ENDLOOP.
  ELSE.
    MOVE deta_mark_safe TO translation_mask+1(1).
    READ TABLE extract INDEX nextline.
    CHECK sy-subrc = 0.               "UF Hw490645
    MOVE sy-tabix TO h_ix.
    READ TABLE total WITH KEY <vim_xextract_key> BINARY SEARCH.
    TRANSLATE <mark> USING translation_mask.
    MODIFY total INDEX sy-tabix.
    TRANSLATE <xmark> USING translation_mask.
    MODIFY extract INDEX h_ix.
    mie_number = 1.
  ENDIF.
  IF mie_number > 0.
    CLEAR ignored_entries_exist.
  ENDIF.
ENDFORM.                               " MARK_IGNORED_ENTRIES

*&--------------------------------------------------------------------*
*&      Form BUILD_VALTAB_HFIELDS                                     *
*&--------------------------------------------------------------------*
* build value tab ignoring hidden fields using structure table        *
*&--------------------------------------------------------------------*
FORM build_valtab_hfields.

  DATA: fieldname TYPE fnam_____4.
  FIELD-SYMBOLS: <value> TYPE ANY, <valfld> TYPE ANY,
                 <value_tab> TYPE x.
  CLEAR value_tab.
  ASSIGN value_tab TO <value_tab> CASTING.
  LOOP AT structure_table.
    IF x_header-bastab NE space AND x_header-texttbexst NE space AND
       structure_table-tabname EQ x_header-texttab.
* texttabfield
      ASSIGN COMPONENT structure_table-fieldname
       OF STRUCTURE <vim_ext_txt_struc> TO <value>.
*     READ TABLE x_namtab WITH KEY viewfield = structure_table-fieldname
*                                        texttabfld = 'X'.
    ELSE.
* viewfield
      LOOP AT x_namtab WHERE viewfield = structure_table-fieldname AND
                        ( texttabfld = space OR keyflag = space ).
        ASSIGN COMPONENT structure_table-fieldname
         OF STRUCTURE <vim_extract_struc> TO <value>.
        EXIT.
      ENDLOOP.
    ENDIF.
    CHECK <value> IS ASSIGNED.
    CONCATENATE structure_table-tabname structure_table-fieldname
     INTO fieldname SEPARATED BY '-'.
    ASSIGN <value_tab>+structure_table-offset(structure_table-intlen)
     TO <valfld> CASTING TYPE (fieldname).
    MOVE <value> TO <valfld>.
*    CHECK sy-subrc EQ 0.
*    MOVE extract+x_namtab-position(x_namtab-flength)
*     TO value_tab+structure_table-offset(structure_table-intlen).
  ENDLOOP.
  APPEND value_tab.
ENDFORM.                               "build_valtab_hfields

*&--------------------------------------------------------------------*
*&      Form CHECK_ALLOWED_KEYRANGES                                  *
*&--------------------------------------------------------------------*
* check new entries fitting allowed keyranges                         *
*---------------------------------------------------------------------*
*                                                                     *
*&--------------------------------------------------------------------*
FORM check_allowed_keyranges.
  DATA: roottab_key LIKE e071k-tabkey,
        tablename LIKE vimdesc-viewname,
        allowed,
        mess_type(1) TYPE c VALUE 'W',
        ale_msgty(1) TYPE c VALUE 'E', ale_msgno LIKE sy-msgno,
        ale_msgid LIKE sy-msgid, ale_msgv1 LIKE sy-msgv1,
        ale_msgv2 LIKE sy-msgv2, ale_msgv3 LIKE sy-msgv3,
        ale_msgv4 LIKE sy-msgv4.
  FIELD-SYMBOLS: <key_x> TYPE x, <h_old_mkey2> TYPE x.

  CHECK vim_keyrange_alr_checked EQ space.
* check ALE keyspecific stuff
  IF vim_ale_keyspec_check NE space.
    ASSIGN roottab_key TO <key_x> CASTING.
    <key_x> = <f1_x>. allowed = 'X'.
    LOOP AT vim_ale_keyspec_objtab.
      CALL FUNCTION 'ALE_EDIT_KEY_CHECK'
        EXPORTING
          objecttype          = vim_ale_keyspec_objtab-otype
          objectname          = vim_ale_keyspec_objtab-oname
          objectkey           = roottab_key
        EXCEPTIONS
          key_no_maintainance = 1.
      IF sy-subrc NE 0.
        allowed = 'A'. ale_msgno = sy-msgno. ale_msgid = sy-msgid.
        ale_msgv1 = sy-msgv1. ale_msgv2 = sy-msgv2.
        ale_msgv3 = sy-msgv3. ale_msgv4 = sy-msgv4.
        EXIT.
      ENDIF.
    ENDLOOP.
  ENDIF.
  IF allowed <> 'A'.                               "329818/2001
    vim_keyrange_alr_checked = 'X'.                "329818/2001
  ENDIF.
* check namespace
  IF vim_ale_keyspec_check EQ space OR                      "SW
   ( x_header-customauth CO sap_cust_ctrl_classes AND allowed CO ' X' ).
    IF x_header-bastab EQ space.       "view
      MOVE x_header-roottab TO tablename.
    ELSE.                              "base table
      MOVE x_header-viewname TO tablename.
    ENDIF.
    ASSIGN roottab_key TO <key_x> CASTING.
    IF x_header-generictrp <> space.
      MOVE <f1_x>(x_header-maxtrkeyln) TO <key_x>.
    ELSE.
      MOVE <f1_x>(x_header-keylen) TO <key_x>.
    ENDIF.
    CALL FUNCTION 'CHECK_CUSTOMER_NAMES'
      EXPORTING
        tablename   = tablename
        tablekey    = roottab_key
      IMPORTING
        key_allowed = allowed.
  ENDIF.

  IF allowed CO ' A'.
    EXPORT vimviewname FROM x_header-viewname TO MEMORY ID sy-uname.
    IF x_header-delmdtflag NE space AND status-mode EQ detail_bild.
      mess_type = 'S'.
    ELSEIF allowed EQ 'A'.
      mess_type = ale_msgty.
      PERFORM set_pf_status USING 'ERROR'.
    ENDIF.
    IF neuer EQ 'J'.                   "add mode
      IF x_header-delmdtflag <> space.
        ASSIGN <vim_h_old_mkey>(x_header-keylen) TO <h_old_mkey2>.
        IF <h_old_mkey2> = <f1_x>.
*      IF x_header-delmdtflag NE space AND <f1> EQ vim_old_viewkey.
          CHECK check_all_keyr_scnd_time EQ space. "simul. of warning
        ENDIF.
      ENDIF.
*     MESSAGE E019(SV). "Bitte den Schlüssel aus dem zulässigen Namensra
      CLEAR: vim_keyrange_alr_checked, vim_key_alr_checked.
      IF allowed NE 'A'.
        MESSAGE ID 'SV' TYPE mess_type NUMBER '019'.
      ELSE.
        MESSAGE ID ale_msgid TYPE mess_type NUMBER ale_msgno WITH
          ale_msgv1 ale_msgv2 ale_msgv3 ale_msgv4.
      ENDIF.
      IF x_header-delmdtflag NE space.
        IF status-mode EQ detail_bild.
          <h_old_mkey2> = <f1_x>.
*          vim_old_viewkey = <f1>.
          check_all_keyr_scnd_time = allowed.    "simulation of warning
          TRANSLATE check_all_keyr_scnd_time USING ' XA '.
          TRANSLATE neuer USING 'JX'.
          CLEAR: function, ok_code. LEAVE SCREEN.
        ENDIF.
        <h_old_mkey2> = <f1_x>.
*        vim_old_viewkey = <f1_x>.
        check_all_keyr_scnd_time = 'X'."simulation of warning
      ENDIF.
    ELSE.                              "update mode.
      IF allowed NE 'A'.
        IF vim_special_mode EQ vim_delete.
          mess_type = 'S'.
        ELSE.
          mess_type = 'W'.
        ENDIF.
        IF vim_system_type NE 'SAP'.
          MESSAGE ID 'SV' TYPE mess_type NUMBER '117'.
        ELSE.
*       MESSAGE W136(SV). "Vorsicht bei Änderungen, Eintrag gehört dem K
          MESSAGE ID 'SV' TYPE mess_type NUMBER '136'.
        ENDIF.
      ELSE.
        IF vim_special_mode EQ vim_delete.
          mess_type = 'S'.
        ELSE.
          mess_type = ale_msgty.
        ENDIF.
        MESSAGE ID ale_msgid TYPE mess_type NUMBER ale_msgno WITH
          ale_msgv1 ale_msgv2 ale_msgv3 ale_msgv4.
      ENDIF.
    ENDIF.
    sy-subrc = 8.
  ELSE.
    CLEAR sy-subrc.
  ENDIF.
ENDFORM.                    "check_allowed_keyranges

*&--------------------------------------------------------------------*
*&      Form  RESET_ENTRIES                                           *
*&--------------------------------------------------------------------*
* restore the last saved version for the marked entries of EXTRACT    *
*---------------------------------------------------------------------*
* --> RE_MODE requested mode: L - all marked entries, D - single entry*
*---------------------------------------------------------------------*
FORM RESET_ENTRIES USING VALUE(RE_MODE).
  DATA: TEXTTAB_MOD(1) TYPE C.         "SW Texttransl

  VIM_SPECIAL_MODE = VIM_RESET.
  CASE RE_MODE.
    WHEN LIST_BILD.
      MOVE: 0 TO REFCNT, 0 TO NEWCNT, 0 TO ORGCNT.
      LOOP AT EXTRACT.
        CLEAR TEXTTAB_MOD.
        CHECK <XMARK> EQ MARKIERT.
        MOVE SY-TABIX TO INDEX.
        ADD 1 TO NEWCNT.
        CHECK <XACT> NE NEUER_EINTRAG.
        ADD 1 TO ORGCNT.
        IF X_HEADER-TEXTTBEXST <> SPACE.             "SW Texttransl ..
          PERFORM VIM_TEXTTAB_MODIF_FOR_KEY CHANGING TEXTTAB_MOD.
        ENDIF.
        IF X_HEADER-BASTAB NE SPACE AND X_HEADER-TEXTTBEXST NE SPACE.
          CHECK <XACT> NE ORIGINAL OR <XACT_TEXT> NE ORIGINAL
                                   OR TEXTTAB_MOD = 'X'.
        ELSE.
          CHECK <XACT> NE ORIGINAL OR TEXTTAB_MOD = 'X'.
        ENDIF.
        PERFORM PROCESS_ENTRY_RESET USING INDEX.
      ENDLOOP.
      NEWCNT = NEWCNT - ORGCNT.
      ORGCNT = ORGCNT - REFCNT.
      IF ORGCNT EQ 0 AND NEWCNT EQ 0.
        MESSAGE S016(SV) WITH REFCNT.
      ELSE.
        IF ORGCNT NE 0 AND NEWCNT NE 0.
          MESSAGE S040(SV) WITH REFCNT ORGCNT NEWCNT.
        ELSE.
          IF ORGCNT NE 0.
            MESSAGE S041(SV) WITH REFCNT ORGCNT.
          ELSE.
            MESSAGE S042(SV) WITH REFCNT NEWCNT.
          ENDIF.
        ENDIF.
      ENDIF.
      PERFORM PROCESS_AFTER_ENTRY_RESET.
    WHEN DETAIL_BILD.
      READ TABLE EXTRACT INDEX NEXTLINE. "Extract-WA i.VCL-Kontext n. ok
      PERFORM PROCESS_ENTRY_RESET USING NEXTLINE.
      MESSAGE S017(SV).
      PERFORM PROCESS_AFTER_ENTRY_RESET.
      CLEAR VIM_OLD_VIEWKEY.
      TRANSLATE VIM_NO_MAINKEY_EXISTS USING VIM_NO_MKEY_NOT_PROCSD_PATT.
  ENDCASE.
  CLEAR VIM_SPECIAL_MODE.
ENDFORM.                               "reset_entries

*&--------------------------------------------------------------------*
*&      Form  PROCESS_ENTRY_RESET                                     *
*&--------------------------------------------------------------------*
* refresh entry from database                                         *
*---------------------------------------------------------------------*
* --> PER_INDEX current index for modifying EXTRACT                   *
*---------------------------------------------------------------------*
FORM PROCESS_ENTRY_RESET USING VALUE(PER_INDEX) TYPE I.
  DATA: PRT_FRKY_SAFE(255) TYPE C, PER_HF TYPE I,
        REFCNT_SAFE TYPE I.

  REFCNT_SAFE = REFCNT.
  PERFORM MOVE_EXTRACT_TO_VIEW_WA.
  IF <XACT> NE ORIGINAL OR             "SW Texttransl
     ( X_HEADER-BASTAB NE SPACE AND X_HEADER-TEXTTBEXST NE SPACE
                                AND <XACT_TEXT> NE ORIGINAL ).

*   check if the <vim_prtfky_wa> is assigned. If the field belong
*   EZN & KEY, the field will be assinged.
    IF vim_prtfky_assigned NE ' '.          "XB 07.2002 Y6BK009849
    IF X_HEADER-PTFRKYEXST NE SPACE.
      MOVE <VIM_PRTFKY_WA> TO PRT_FRKY_SAFE.
    ENDIF.
    ENDIF.

    IF X_HEADER-FRM_RP_ORG NE SPACE.
      PERFORM (X_HEADER-FRM_RP_ORG) IN PROGRAM (SY-REPID).
    ELSE.
      IF X_HEADER-BASTAB NE SPACE.
        PERFORM (VIM_TB_READ_SINGLE_FORM) IN PROGRAM (SY-REPID).
      ELSE.
        PER_HF = STRLEN( X_HEADER-MAINTVIEW ).
        IF PER_HF LE 10.
          MOVE X_HEADER-MAINTVIEW TO VIM_READ_SINGLE_FORM-VIEWNAME.
          PERFORM (VIM_READ_SINGLE_FORM) IN PROGRAM.
        ELSE.
          MOVE X_HEADER-MAINTVIEW TO VIM_READ_SINGLE_FORM_40-VIEWNAME.
          PERFORM (VIM_READ_SINGLE_FORM_40) IN PROGRAM.
        ENDIF.
      ENDIF.
    ENDIF.
    IF SY-SUBRC NE 0.
      IF X_HEADER-FRM_RP_ORG EQ SPACE.
        RAISE IMPOSSIBLE_ERROR.        "entry not found
      ENDIF.
    ELSE.

*   check if the <vim_prtfky_wa> is assigned. If the field belong
*   EZN & KEY, the field will be assinged.
      IF vim_prtfky_assigned NE ' '.          "XB 07.2002  Y6BK009849
      IF X_HEADER-PTFRKYEXST NE SPACE AND                      "SW
         <VIM_PRTFKY_WA> NE PRT_FRKY_SAFE.
        PERFORM CONSISTENCY_PRT_FRKY_FIELDS USING 'X'.
        ENDIF.
      ENDIF.

      IF X_HEADER-DELMDTFLAG NE SPACE.
        PERFORM TEMPORAL_DELIMITATION.
      ENDIF.
      PERFORM MODIFY_TABLES USING PER_INDEX.
      IF PER_INDEX NE 0.
        ADD 1 TO REFCNT.
      ENDIF.
    ENDIF.

  ENDIF.                               "SW Texttransl ..
  IF X_HEADER-TEXTTBEXST <> SPACE.     "SW Texttransl ..
    IF X_HEADER-FRM_TL_ORG NE SPACE.
      PERFORM (X_HEADER-FRM_TL_ORG) IN PROGRAM (SY-REPID).
    ELSE.
      PERFORM VIM_READ_TEXTTAB_ENTRY.
    ENDIF.
    IF REFCNT_SAFE = REFCNT AND SY-SUBRC = 0.
      ADD 1 TO REFCNT.
      CLEAR <STATUS>-UPD_FLAG.
      IF <XMARK> EQ MARKIERT.
        SUBTRACT: 1 FROM <STATUS>-MK_XT,
                  1 FROM <STATUS>-MK_TO.
        <XMARK> = NICHT_MARKIERT.
        IF PER_INDEX <> 0.
          MODIFY EXTRACT INDEX PER_INDEX.
        ENDIF.
        READ TABLE TOTAL WITH KEY <VIM_xEXTRACT_KEY> BINARY SEARCH.
        <MARK> = NICHT_MARKIERT.
        MODIFY TOTAL INDEX SY-TABIX.
      ENDIF.
    ENDIF.
  ENDIF.                               ".. Texttransl
ENDFORM.                               "process_entry_reset

*&--------------------------------------------------------------------*
*&      Form  PROCESS_AFTER_ENTRY_RESET                               *
*&--------------------------------------------------------------------*
*                                                                     *
*---------------------------------------------------------------------*
FORM PROCESS_AFTER_ENTRY_RESET.
  IF TEMPORAL_DELIMITATION_HAPPENED NE SPACE.
    PERFORM AFTER_TEMPORAL_DELIMITATION.
    CLEAR TEMPORAL_DELIMITATION_HAPPENED.
  ENDIF.
  PERFORM CHECK_UPD.
  IF X_HEADER-FRM_AF_ORG NE SPACE.
    PERFORM (X_HEADER-FRM_AF_ORG) IN PROGRAM (SY-REPID).
  ENDIF.
ENDFORM.                               "process_after_entry_reset

*&--------------------------------------------------------------------*
*&      Form UPGRADE                                                  *
*&--------------------------------------------------------------------*
* process upgrade                                                     *
*---------------------------------------------------------------------*
* U_MODE --> ' ' - client 000, 'O' - other client, others - remote sys*
*---------------------------------------------------------------------*
FORM upgrade USING value(u_mode) TYPE c.
  DATA: u_kind, u_update_happened, trans_pattern(8) TYPE c,
        hf TYPE i, u_client LIKE sy-mandt, u_tabind LIKE sy-tabix,
        u_it000 LIKE vim_t000 OCCURS 10, u_title(40) TYPE c,
        u_remote_sys LIKE rfcdes-rfcdest, u_t000 LIKE vim_t000,
        u_counter TYPE i, u_del_cnt TYPE i, u_rc TYPE i, hf1 TYPE i,
        u_funcsafe(4) TYPE c, u_txt_fu_beg TYPE i, u_txt_fu_lg TYPE i,
        u_newversion(1) TYPE c VALUE 'X', u_mark_entries(1) TYPE c,
        u_action(1) TYPE c, u_specmode_safe(1) TYPE c,
        u_called_from(1) TYPE c, u_oc_exst LIKE ntab_cmp-flag,
        u_sellist TYPE vimsellist_type, sellines TYPE i.
  CONSTANTS: u_text_frm(30) TYPE c VALUE 'FILL_TEXTTAB_KEY'.
  FIELD-SYMBOLS: <u_f1> TYPE x, <u_sellist> TYPE vimsellist_type,
                 <w_sellist> TYPE vimsellist.

* data and field symbols for copying the extract to and from
* the compare tool container:
  DATA:
    cmp_container_ref    TYPE REF TO data,
    cmp_container_wa_ref TYPE REF TO data,
    extract_len          TYPE i,
    subrc_buf            TYPE sy-subrc.
  FIELD-SYMBOLS:
    <cmp_cont>    TYPE STANDARD TABLE,
    <cmp_cont_wa> TYPE ANY,
    <x_dummy>     TYPE x.

  READ TABLE excl_cua_funct WITH KEY function = 'CMPR'.
  IF sy-subrc EQ 0.                    "upgrade is not allowed
    MESSAGE s001(sv).
    EXIT.
  ENDIF.
* upgrade with client 0 only if current client <> 000
* upgrade with other clients only if objects are clientdependent
  IF u_mode EQ space AND sy-mandt EQ '000' OR  "upgrade with client 000
     ( u_mode EQ space OR u_mode EQ 'O' ) AND
     x_header-clidep EQ space.
    MESSAGE s001(sv).
    EXIT.
  ENDIF.
* send warning if address number could be changed
  IF status-action EQ aendern AND
   ( x_header-adrnbrflag NE space AND x_header-adrnbrflag <> 'N' ).
    PERFORM set_pf_status USING 'ERROR'.
    MESSAGE i139(sv). "Adreßdaten werden nicht übernommen
    PERFORM set_pf_status USING status.
  ENDIF.
  CLEAR: u_client, u_remote_sys.
  IF u_mode EQ space.
    u_client = '000'.
  ELSEIF u_mode EQ 'O'.
    IF vim_default_upgr_clnt-client NE space AND
       vim_default_upgr_clnt-viewname EQ x_header-viewname.
      u_client = vim_default_upgr_clnt-client.
    ENDIF.
  ELSE.
    IF vim_default_rfc_dest-rfcdest NE space AND
       vim_default_rfc_dest-viewname EQ x_header-viewname.
      u_remote_sys = vim_default_rfc_dest-rfcdest.
    ENDIF.
  ENDIF.
  IF vim_special_mode EQ vim_direct_upgrade.
    function = 'ABR'.                  "avoid processing detail screen
    PERFORM fill_extract. CLEAR function.
    u_specmode_safe = vim_special_mode.
    ASSIGN dba_sellist[] TO <u_sellist>.
  ELSE.
    ASSIGN <vim_ck_sellist> TO <u_sellist>.
  ENDIF.
  vim_special_mode = vim_upgrade.
  MOVE: geloescht TO trans_pattern, aendern TO trans_pattern+1(1),
        neuer_geloescht TO trans_pattern+2(1),
        neuer_eintrag   TO trans_pattern+3(1),
        update_geloescht TO trans_pattern+4(1),
        aendern         TO trans_pattern+5(1),
        original  TO trans_pattern+6(1),
        aendern TO trans_pattern+7(1).
  IF x_header-bastab EQ space.         "view
    u_kind = 'V'.
  ELSE.
    IF x_header-texttbexst EQ space.   "base table
      u_kind = 'T'.
    ELSE.                              "base table with text table
      u_kind = 'X'.
    ENDIF.
  ENDIF.

* Add collapsed or merged timedep. entries
  IF x_header-delmdtflag NE space.
    DESCRIBE TABLE vim_collapsed_mainkeys LINES hf.
    DESCRIBE TABLE vim_merged_entries.
    IF sy-tfill GT 0 OR hf GT 0.
      vim_ignore_collapsed_mainkeys = 'X'.
      PERFORM fill_extract.
      CLEAR vim_ignore_collapsed_mainkeys.
    ENDIF.
  ENDIF.
  IF ( vim_system_type NE 'SAP' AND sy-mandt EQ '000' )
   OR x_header-importable = vim_not_importable.
    u_action = anzeigen.
  ELSE.
    u_action = status-action.
  ENDIF.
  TRANSLATE u_action USING 'SCUA'.
  IF vim_adjust_middle_level_mode NE space.
    TRANSLATE u_action USING 'Aa'.
  ENDIF.
  u_called_from = vim_special_adjust_mode.
  TRANSLATE u_called_from USING ' VSFXF'.
  IF NOT vim_oc_inst IS INITIAL.
* data access restricted?
    IF ( u_action = 'C'
         AND NOT vim_oc_inst->oc_selcrit_read_tab IS INITIAL )
     OR ( 'Aa' CS u_action
          AND NOT vim_oc_inst->oc_selcrit_maint_tab IS INITIAL ).
      u_oc_exst = 'X'.
    ENDIF.
  ENDIF.
  APPEND LINES OF <u_sellist> TO u_sellist.
  DELETE u_sellist WHERE from_auth <> space
   AND ddic <> 'S' AND ddic <> 'B'.
  IF sy-subrc = 0.
    DESCRIBE TABLE u_sellist LINES sellines.
    IF sellines GT 0.
      READ TABLE u_sellist INDEX sellines ASSIGNING <w_sellist>.
      CLEAR <w_sellist>-and_or.
    ENDIF.
  ENDIF.

* copy extract to compare tool container
  DESCRIBE FIELD extract LENGTH extract_len IN BYTE MODE.
  IF extract_len <= 64.
    CREATE DATA cmp_container_ref TYPE TABLE OF tbl64.
    ASSIGN cmp_container_ref->* TO <cmp_cont>.
    CREATE DATA cmp_container_wa_ref TYPE tbl64.
    ASSIGN cmp_container_wa_ref->* TO <cmp_cont_wa>.
  ELSEIF extract_len <= 256.
    CREATE DATA cmp_container_ref TYPE TABLE OF tbl256.
    ASSIGN cmp_container_ref->* TO <cmp_cont>.
    CREATE DATA cmp_container_wa_ref TYPE tbl256.
    ASSIGN cmp_container_wa_ref->* TO <cmp_cont_wa>.
  ELSEIF extract_len <= 1024.
    CREATE DATA cmp_container_ref TYPE TABLE OF tbl1024.
    ASSIGN cmp_container_ref->* TO <cmp_cont>.
    CREATE DATA cmp_container_wa_ref TYPE tbl1024.
    ASSIGN cmp_container_wa_ref->* TO <cmp_cont_wa>.
  ELSEIF extract_len <= 4096.
    CREATE DATA cmp_container_ref TYPE TABLE OF tbl4096.
    ASSIGN cmp_container_ref->* TO <cmp_cont>.
    CREATE DATA cmp_container_wa_ref TYPE tbl4096.
    ASSIGN cmp_container_wa_ref->* TO <cmp_cont_wa>.
  ELSEif extract_len <= 8192.
    CREATE DATA cmp_container_ref TYPE TABLE OF tbl8192.
    ASSIGN cmp_container_ref->* TO <cmp_cont>.
    CREATE DATA cmp_container_wa_ref TYPE tbl8192.
    ASSIGN cmp_container_wa_ref->* TO <cmp_cont_wa>.
  else.
    CREATE DATA cmp_container_ref TYPE TABLE OF tbl32000.
    ASSIGN cmp_container_ref->* TO <cmp_cont>.
    CREATE DATA cmp_container_wa_ref TYPE tbl32000.
    ASSIGN cmp_container_wa_ref->* TO <cmp_cont_wa>.
  ENDIF.

  ASSIGN <cmp_cont_wa> TO <x_dummy> CASTING.
  LOOP AT extract.
    CLEAR <x_dummy>.
    <x_dummy> = <vim_xextract>.
    APPEND <cmp_cont_wa> TO <cmp_cont>.
  ENDLOOP.

  CALL FUNCTION 'SCT1_VIEW_COMPARE_AND_ADJUST'
       EXPORTING
            iv_view_name              = x_header-maintview  "VIEWNAME
*             IV_VIEW_VARIANT    =
            iv_kind                   = u_kind
            iv_mode                   = u_action
*             IV_LANGUAGE        = SY-LANGU
*             IV_CLIENT_REMOTE   = U_CLIENT
            iv_rfc_destination        = u_remote_sys
            iv_called_from            = u_called_from
            iv_data_access_restricted = u_oc_exst
       IMPORTING
            ev_update          = u_update_happened
            ev_mark_entries    = u_mark_entries
       TABLES
            it_header          = x_header
            it_namtab          = x_namtab
            it_sellist         = u_sellist
            ct_box             = <cmp_cont>
       EXCEPTIONS
            canceled           = 1
            wrong_parameter    = 2
            compare_error      = 3
            OTHERS             = 4.
  subrc_buf = sy-subrc.

* copy compare tool container back to extract
  REFRESH extract.
  LOOP AT <cmp_cont> ASSIGNING <cmp_cont_wa>.
    ASSIGN <cmp_cont_wa> TO <x_dummy> CASTING.
    <vim_xextract> = <x_dummy>(extract_len).
    APPEND extract.
  ENDLOOP.

  sy-subrc = subrc_buf.
  IF sy-subrc GT 01.
    MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    MESSAGE s135(sv). sy-subrc = 01.
  ENDIF.
  IF status-action EQ anzeigen AND u_update_happened NE space.
    sy-subrc = 1.
  ENDIF.
  CASE sy-subrc.
    WHEN 0.
      IF u_update_happened NE space.
* transfer changed entries from EXTRACT into TOTAL
        CLEAR: u_counter, u_del_cnt. replace_mode = 'X'.
        DESCRIBE TABLE extract LINES maxlines.
* 1st: handle deleted entries
        LOOP AT extract.
          IF <xact> EQ original.
            DELETE extract. CONTINUE.
          ENDIF.
          CHECK <xact> EQ geloescht OR <xact> EQ neuer_geloescht OR
                <xact> EQ update_geloescht.
          hf = sy-tabix.
          READ TABLE total WITH KEY <vim_xextract_key> BINARY SEARCH.
          IF sy-subrc NE 0 OR ( sy-subrc EQ 0 AND <action> EQ <xact> ).
            DELETE extract. CONTINUE.
          ENDIF.
          <mark> = markiert. ADD 1 TO mark_total.
          MODIFY total INDEX sy-tabix.
          <xmark> = markiert. ADD 1 TO mark_extract.
          MODIFY extract.
          IF vim_special_adjust_mode EQ subset.
            PERFORM vim_restore_subset_conds.
          ENDIF.
          PERFORM vim_process_view_entry USING hf 'DELE' u_rc.
          CHECK u_rc NE 4.
          IF u_rc EQ 8.
            EXIT.
          ENDIF.
          ADD: counter TO u_del_cnt, 1 TO u_counter.
        ENDLOOP.
        IF u_counter GT u_del_cnt.
          SUBTRACT u_del_cnt FROM u_counter.
          MESSAGE i116(sv) WITH u_counter. "& Einträge konnten nicht g
        ENDIF.
        CLEAR u_counter.
        IF status-type EQ einstufig.
          CLEAR: ok_code, function.
        ELSE.
          function = ok_code = 'COMP'.
        ENDIF.
* 2nd: handle changed entries
        ASSIGN <vim_xtotal>(x_header-tablen) TO <u_f1>.
        LOOP AT extract.
          IF <xact> NE aendern AND <xact> NE neuer_eintrag.
            DELETE extract. CONTINUE.
          ENDIF.
          hf = sy-tabix.
          READ TABLE total WITH KEY <vim_xextract_key> BINARY SEARCH.
          IF sy-subrc EQ 0.            "entry exists in current client
            IF extract EQ total. "no changes -> delete and continue
              DELETE extract. CONTINUE.
            ELSEIF <xact> EQ neuer_eintrag AND "new entry exists and
                <action> EQ geloescht OR <action> EQ neuer_geloescht OR
                 <action> EQ update_geloescht."entry deleted in cur clnt
              status-delete = geloescht. " -> first undelete it
              <xact> = <action>. MODIFY extract. u_funcsafe = function.
              IF vim_special_adjust_mode EQ subset.
                PERFORM vim_restore_subset_conds.
              ENDIF.
              PERFORM vim_mark_and_process USING hf 'UNDO' hf1 u_rc.
              CLEAR status-delete. function = u_funcsafe.
              vim_special_mode = vim_upgrade.
              CHECK u_rc NE 4.
              IF u_rc EQ 8.
                EXIT.
              ENDIF.
              READ TABLE extract INDEX hf.
              READ TABLE total WITH KEY <vim_xextract_key>
                                                      BINARY SEARCH.
              IF <u_f1> EQ <table2_x>.   "no changes after undo
                DELETE extract. CONTINUE."delete & continue
              ELSE.
                <xact> = aendern. MODIFY extract.
              ENDIF.
            ELSEIF <u_f1> EQ <table2_x>. "no changes -> delete and cont
              DELETE extract. CONTINUE.
            ELSEIF <xact> EQ neuer_eintrag AND <action> EQ original.
              <xact> = aendern. MODIFY extract.
            ENDIF.
          ENDIF.                       "sy-subrc eq 0.
          IF vim_special_adjust_mode EQ subset.
            PERFORM vim_restore_subset_conds.
          ENDIF.
          PERFORM vim_modify_view_entry USING hf u_rc.
          CHECK u_rc NE 4.
          IF u_rc EQ 8.
            EXIT.
          ENDIF.
          IF u_mark_entries NE space.  "mark ajusted entries
            READ TABLE total WITH KEY <vim_xtotal_key> BINARY SEARCH
                             TRANSPORTING NO FIELDS.
            IF <mark> EQ nicht_markiert.
              <mark> = markiert. ADD 1 TO mark_total.
              MODIFY total INDEX sy-tabix.
              ADD 1 TO mark_extract.
            ENDIF.
          ENDIF.
          extract = total.
          MODIFY extract.
          ADD 1 TO u_counter.
        ENDLOOP.
        IF temporal_delimitation_happened NE space.
          REFRESH vim_delim_entries.
          CLEAR temporal_delimitation_happened.
        ENDIF.
        status-data = title-data = auswahldaten.
        nextline = l = 1.
        IF u_del_cnt NE 0 AND u_counter NE 0.
          MESSAGE s140(sv) "&1 Einträge geloescht, &2 Einträge übernom
            WITH u_del_cnt u_counter.
        ELSEIF u_del_cnt NE 0.
          MESSAGE s011(sv) WITH u_del_cnt. "Anzahl gelöschter Einträge
        ELSE.
          MESSAGE s012(sv) WITH u_counter. "Anzahl veränderter Einträg
        ENDIF.
        CLEAR replace_mode.
      ELSE.                            "no update happened
        IF x_header-delmdtflag NE space.
          PERFORM fill_extract. "consider collapsed or merged entries
        ENDIF.
      ENDIF.                           "u_update_happend ne space
      DESCRIBE TABLE extract LINES maxlines.
      nextline = 1.
      IF vim_special_adjust_mode NE space.
        CLEAR: vim_special_mode, vim_special_adjust_mode,
               <status>-upd_flag, maxlines, <status>-maxlines.
        vim_next_screen = 0. vim_leave_screen = 'X'.
        IF vim_adjust_middle_level_mode NE space.
          function = 'SAVE'.
        ENDIF.
      ENDIF.
    WHEN 1. "ignore changes in EXTRACT --> restore EXTRACT from TOTAL
      IF vim_special_adjust_mode NE space.
        CLEAR: vim_special_mode, vim_special_adjust_mode,
               <status>-upd_flag, maxlines, <status>-maxlines.
        vim_next_screen = 0. vim_leave_screen = 'X'.
        IF vim_adjust_middle_level_mode NE space.
          function = 'SAVE'.
        ENDIF.
      ENDIF.
      PERFORM fill_extract.
    WHEN OTHERS. RAISE upgrade_view_failed.
  ENDCASE.
  CLEAR vim_special_mode.
ENDFORM.                               " UPGRADE

*&--------------------------------------------------------------------*
*&      Form VIM_RESTORE_SUBSET_CONDS                                 *
*&--------------------------------------------------------------------*
* restore subset conditions                                           *
*&--------------------------------------------------------------------*
FORM vim_restore_subset_conds.
  DATA: hi TYPE i.
  FIELD-SYMBOLS: <ifield> TYPE ANY.
  LOOP AT dpl_sellist WHERE ddic CO vim_subset_marks.
    hi = sy-tabix.
    READ TABLE x_namtab INDEX dpl_sellist-tabix.
    ASSIGN COMPONENT x_namtab-viewfield
     OF STRUCTURE <vim_extract_struc> TO <ifield>.
*    ASSIGN EXTRACT+X_NAMTAB-POSITION(X_NAMTAB-FLENGTH) TO <IFIELD>.
    CALL FUNCTION 'VIEW_CONVERSION_OUTPUT'
         EXPORTING
              value_intern = <ifield>
              tabname      = x_header-maintview
              fieldname    = x_namtab-viewfield
              outputlen    = x_namtab-outputlen
              intlen       = x_namtab-flength
         IMPORTING
              value_extern = dpl_sellist-value.
    CLEAR dpl_sellist-converted.
    IF dpl_sellist-value IS INITIAL. dpl_sellist-initial = 'X'. ENDIF.
    MODIFY dpl_sellist INDEX hi.
  ENDLOOP.
  dba_sellist[] = dpl_sellist[].
ENDFORM.

*&--------------------------------------------------------------------*
*&      Form  VIM_PROCESS_VIEW_ENTRY                                  *
*&--------------------------------------------------------------------*
* process current function for view entry                             *
*&--------------------------------------------------------------------*
FORM VIM_PROCESS_VIEW_ENTRY USING VALUE(VPVE_EXIX) TYPE I
                                  VALUE(VPVE_OKCODE) LIKE OK_CODE
                                  VPVE_RC TYPE I.
  DATA: FUNCTION_SAFE LIKE FUNCTION.
  CLEAR VPVE_RC.
  NEXTLINE = EXIND = VPVE_EXIX.
  FUNCTION_SAFE = FUNCTION.
  FUNCTION = OK_CODE = VPVE_OKCODE.
  PERFORM MOVE_EXTRACT_TO_VIEW_WA.
  CASE STATUS-TYPE.
    WHEN EINSTUFIG.
*     CALL SCREEN LISTE.
      PERFORM VIM_IMP_CALL_SCREEN USING LISTE.
    WHEN ZWEISTUFIG.
*     PERFORM MOVE_EXTRACT_TO_VIEW_WA.
      PERFORM PROCESS_DETAIL_SCREEN USING 'C'.
  ENDCASE.
  IF OK_CODE EQ 'IGN '. VPVE_RC = 4. CLEAR OK_CODE. EXIT. ENDIF.
  IF FUNCTION EQ 'ABR '. VPVE_RC = 8. CLEAR FUNCTION. EXIT. ENDIF.
  FUNCTION = FUNCTION_SAFE.
ENDFORM.                               "vim_process_view_entry

*&--------------------------------------------------------------------*
*&      Form  VIM_MODIFY_VIEW_ENTRY                                   *
*&--------------------------------------------------------------------*
* update/insert entry, process all checks                             *
*&--------------------------------------------------------------------*
FORM vim_modify_view_entry USING value(vmve_exix) TYPE i
                                 vmve_rc TYPE i.
  DATA: h_ix TYPE i, h_act(1) TYPE c, hact2(1) TYPE c,
        fieldname TYPE fnam_____4.
  FIELD-SYMBOLS: <guid> TYPE ANY, <old_guid> TYPE ANY,
                 <guid_wa> TYPE ANY,
                 <extract_val> TYPE ANY, <total_val> TYPE ANY.
  CLEAR vmve_rc.
  nextline = exind = vmve_exix.
* new: transfer of changed entries from EXTRACT into TOTAL via dynps
* ... first: handle read-only fields and subset fields
  IF x_header-subsetflag NE space OR
     x_header-rdonlyflag NE space OR
     x_header-adrnbrflag NE space.
    IF <xact> NE neuer_eintrag.
      READ TABLE total WITH KEY <vim_xextract_key>
                       BINARY SEARCH.
      h_act = <action>.
    ELSE.
      h_act = <xact>.
    ENDIF.
    LOOP AT x_namtab WHERE readonly EQ rdonly
                       OR  ( readonly EQ subset AND
                             keyflag EQ space ).
      ASSIGN COMPONENT x_namtab-viewfield
       OF STRUCTURE <vim_extract_struc> TO <extract_val>.
      CHECK sy-subrc = 0.
      IF <xact> NE neuer_eintrag.
        ASSIGN COMPONENT x_namtab-viewfield
         OF STRUCTURE <vim_total_struc> TO <total_val>.
        IF sy-subrc = 0.
          <extract_val> = <total_val>.
        ENDIF.
*        extract+x_namtab-position(x_namtab-flength) =
*            total+x_namtab-position(x_namtab-flength).
      ELSE.
        ASSIGN COMPONENT x_namtab-viewfield
         OF STRUCTURE <initial> TO <total_val>.
        IF sy-subrc = 0.
          <extract_val> = <total_val>.
        ENDIF.
*        extract+x_namtab-position(x_namtab-flength) =
*            <initial>+x_namtab-position(x_namtab-flength).
      ENDIF.
    ENDLOOP.
    IF sy-subrc EQ 0.
      hact2 = <xact>. <xact> = h_act.
      MODIFY extract INDEX vmve_exix.
      <xact> = hact2.
    ENDIF.
  ENDIF.
  PERFORM move_extract_to_view_wa.
* ... second: handle address number and GUID
  CLEAR vim_upgr_address_number.
  IF x_header-adrnbrflag NE space.
    IF x_header-adrnbrflag = 'N'.
      vim_upgr_address_number = <address_number>.
    ENDIF.
    IF <xact> NE neuer_eintrag.
      <address_number> = <vim_total_address_number>.
    ELSE.
      CLEAR <address_number>.
    ENDIF.
  ENDIF.
  IF x_header-guidflag <> space AND <xact> <> neuer_eintrag.
* update only, GUID will be set in UPDATE_TAB for new entries
    LOOP AT x_namtab WHERE domname IN vim_guid_domain.
      CONCATENATE x_header-maintview x_namtab-viewfield
       INTO fieldname SEPARATED BY '-'.
      ASSIGN COMPONENT x_namtab-viewfield
       OF STRUCTURE <vim_extract_struc> TO <guid>.
      ASSIGN COMPONENT x_namtab-viewfield
       OF STRUCTURE <vim_total_struc> TO <old_guid>.
*      ASSIGN extract+x_namtab-position(x_namtab-flength) TO <guid>
*       CASTING TYPE (fieldname).
*      ASSIGN total+x_namtab-position(x_namtab-flength) TO <old_guid>
*       CASTING TYPE (fieldname).
      IF <guid> IS INITIAL AND <old_guid> IS INITIAL.
* no GUID-value imported from remote system and GUID not yet set in
* current entry
        PERFORM vim_make_guid USING x_namtab-viewfield.
        ASSIGN (fieldname) TO <guid_wa> CASTING TYPE (fieldname).
        <guid> = <guid_wa>.
* (including event 27)
      ELSEIF <guid> IS INITIAL.
* use old GUID
        <guid> = <old_guid>.
        IF x_header-frm_af_uid <> space.
          PERFORM (x_header-frm_af_uid) IN PROGRAM (x_header-fpoolname)
                                    USING <old_guid>
                                    CHANGING <guid>
                                             <vim_extract_struc>.
        ELSEIF x_header-frm_af_uid <> space.
* overwrite old GUID with GUID from remote client... or not?
          PERFORM (x_header-frm_af_uid) IN PROGRAM (x_header-fpoolname)
                                    USING <old_guid>
                                    CHANGING <guid>
                                             <vim_extract_struc>.
        ENDIF.
      ENDIF.
    ENDLOOP.
  ENDIF.
  IF <xact> EQ neuer_eintrag.
    status-action = hinzufuegen.
    <vim_extract_struc> = <initial>.
    IF x_header-bastab NE space AND
       x_header-texttbexst NE space.
      <vim_xextract_text> = <text_initial_x>.
    ENDIF.
    <xact> = leer.
  ELSE.
    status-action = aendern. <xact> = h_act.
  ENDIF.
  MODIFY extract INDEX vmve_exix.
* ...third: call screen a la replace
  CASE status-type.
    WHEN einstufig.
      PERFORM vim_imp_call_screen USING liste.
    WHEN zweistufig.
      IF <xact> EQ leer.
        neuer = 'J'.
      ENDIF.
      PERFORM process_detail_screen USING 'C'.
  ENDCASE.
  status-action = <status>-st_action = aendern.
  IF ok_code EQ 'IGN '. vmve_rc = 4. CLEAR ok_code. EXIT. ENDIF.
  IF function EQ 'ABR '. vmve_rc = 8. CLEAR function. EXIT. ENDIF.
ENDFORM.                               "vim_modify_view_entry

*&--------------------------------------------------------------------*
*&      Form VIM_SET_IMPRES_HEADER                                    *
*&--------------------------------------------------------------------*
* ...                                                                 *
*&--------------------------------------------------------------------*
FORM VIM_SET_IMPRES_HEADER.
  IF VIM_CALLED_BY_CLUSTER EQ SPACE.
    IMP_RESULTS-OBJTAB-OBJECT-OBJECTNAME = X_HEADER-VIEWNAME.
    IF X_HEADER-VIEWNAME <> X_HEADER-MAINTVIEW.             "Subviews ..
      CLEAR IMP_RESULTS-OBJTAB-OBJECT-OBJECTTYPE.
    ELSE.
      IMP_RESULTS-OBJTAB-OBJECT-OBJECTTYPE = X_HEADER-BASTAB.
    ENDIF.                             ".. Subviews
    TRANSLATE IMP_RESULTS-OBJTAB-OBJECT-OBJECTTYPE USING ' VXS'.
  ELSE.
    IMP_RESULTS-OBJTAB-OBJECT-OBJECTNAME = VIM_CALLING_CLUSTER.
    IMP_RESULTS-OBJTAB-OBJECT-OBJECTTYPE = 'C'.
  ENDIF.
  IF X_HEADER-BASTAB NE SPACE.
    IMP_RESULTS-OBJTAB-TABNAME = X_HEADER-MAINTVIEW.
    IF X_HEADER-VIEWNAME <> X_HEADER-MAINTVIEW.             "Subviews ..
      IMP_RESULTS-OBJTAB-VIEWNAME = X_HEADER-VIEWNAME.
    ELSE.                              ".. Subviews
      CLEAR IMP_RESULTS-OBJTAB-VIEWNAME.
    ENDIF.
  ELSE.
    IMP_RESULTS-OBJTAB-TABNAME = X_HEADER-ROOTTAB.
    IMP_RESULTS-OBJTAB-VIEWNAME = X_HEADER-VIEWNAME.
  ENDIF.
  IMP_RESULTS-KEYLEN = X_HEADER-KEYLEN.                     "SW
  IMP_RESULTS-GENKEYLEN = X_HEADER-KEYLEN.                  "SW
ENDFORM.                               "vim_set_impres_header

*&--------------------------------------------------------------------*
*&      Form VIM_CONVERT_TABKEY                                       *
*&--------------------------------------------------------------------*
* ...                                                                 *
*&--------------------------------------------------------------------*
FORM vim_convert_tabkey USING value(vct_key_int) TYPE x
                                    vct_key_ext TYPE vim_tabkey_c
                                    vct_xkeylen TYPE i.
  FIELD-SYMBOLS: <h1>, <h2>.
  CLEAR vct_xkeylen.
  <f1_wax> = vct_key_int.
  LOOP AT x_namtab WHERE keyflag NE space AND texttabfld EQ space.
    CHECK x_namtab-position LT x_header-keylen.
*    ASSIGN: vct_key_int+x_namtab-position(x_namtab-flength) TO <h1>,
*            vct_key_ext+vct_xkeylen(x_namtab-outputlen) TO <h2>.
    ASSIGN: COMPONENT x_namtab-viewfield OF STRUCTURE <table1_wa>
             TO <h1>,
            vct_key_ext+vct_xkeylen(x_namtab-outputlen) TO <h2>.
    IF ( x_namtab-inttype NE 'C' AND x_namtab-inttype NE 'N' )"SW
       OR x_namtab-convexit NE space.
      CALL FUNCTION 'VIEW_CONVERSION_OUTPUT'
           EXPORTING
                value_intern = <h1>
                tabname      = x_header-maintview
                fieldname    = x_namtab-viewfield
*                inttype      = x_namtab-inttype
*                datatype     = x_namtab-datatype
*                decimals     = x_namtab-decimals
*                convexit     = x_namtab-convexit
*                sign         = x_namtab-sign
                outputlen    = x_namtab-outputlen
                intlen       = x_namtab-flength
           IMPORTING
                value_extern = <h2>.
    ELSE.
      <h2> = <h1>.
    ENDIF.
    ADD x_namtab-outputlen TO vct_xkeylen.
  ENDLOOP.
ENDFORM.                               "vim_convert_tabkey

*&--------------------------------------------------------------------*
*&      Form VIM_IMP_CALL_SCREEN                                      *
*&--------------------------------------------------------------------*
* ...                                                                 *
*&--------------------------------------------------------------------*
FORM vim_imp_call_screen USING vics_screen LIKE d020s-dnum.
  DATA: program LIKE sy-repid, import_action LIKE sy-msgv4,
        key_safe1 LIKE sy-msgv1, key_safe2 LIKE sy-msgv2,
        key_safe3 LIKE sy-msgv3, key_safe TYPE vim_tabkey_c,
        vics_xkeylen TYPE i.           ", vics_int_entsafe(4096) TYPE c.
  LOCAL: imp_results.                  "SW  wg. rek. Aufruf im Cluster

  FIELD-SYMBOLS: <res_tabkey> TYPE x, <errkey> TYPE x.

  ASSIGN: imp_results-tabkey TO <res_tabkey> CASTING,
          vim_profile_errorkey TO <errkey> CASTING.
  CLEAR vim_view_wax.
  IF vim_import_mode_active NE space.
*    VICS_INT_ENTSAFE = <TABLE1>.
    <table1_wax> = <table1_x>.
    PERFORM vim_set_impres_header.
    PERFORM vim_convert_tabkey USING <f1_x> key_safe vics_xkeylen.
*    imp_results-tabkey = <f1>.
    <res_tabkey> = <f1_x>.
    key_safe1 = key_safe.
    IF vics_xkeylen GT 50.
      key_safe2 = key_safe+50.
      IF vics_xkeylen GT 100.
        key_safe3 = key_safe+100.
      ENDIF.
    ENDIF.
    IF vim_called_by_cluster = 'X'.                         "SW
      CONCATENATE '(' view_name ')' INTO key_safe3.         "SW
    ENDIF.                                                  "SW
    IF status-action EQ hinzufuegen.
      import_action = 'INS'.
    ELSEIF function EQ 'DELE'.
      import_action = 'DEL'.
    ELSEIF status-action EQ aendern.
      import_action = 'UPD'.
    ENDIF.
    CLEAR: imp_results-import, vim_last_logged_message.
    IF vim_import_profile = 'X'.
*      vim_profile_errorkey = <f1>.
      <errkey>(x_header-keylen) = <f1_x>.
    ELSE.
      vim_import_no_message = 'X'.
      PERFORM vim_process_message USING 'SV' 'S' 'S' '150' key_safe1
                                      key_safe2 key_safe3 import_action.
    ENDIF.
  ENDIF.
  IF vim_import_mode_active EQ space OR vim_no_dialog EQ space.
    CALL SCREEN vics_screen.
  ELSE.
    program = sy-repid. CLEAR vim_import_no_message.
    CALL FUNCTION 'VIEW_CALL_SCREEN'
         EXPORTING
              screen_number = vics_screen
              program       = program
         EXCEPTIONS
              error_message = 1.
    IF sy-subrc NE 0.
      CLEAR vim_act_dynp_view.
      IF vim_last_logged_message-id NE sy-msgid OR
         vim_last_logged_message-nbr NE sy-msgno.
        vim_import_no_message = 'X'.
        PERFORM vim_process_message USING sy-msgid sy-msgty sy-msgty
                                          sy-msgno sy-msgv1 sy-msgv2
                                          sy-msgv3 sy-msgv4.
      ENDIF.
      IF vim_import_forcemode EQ space.
        ok_code = 'IGN '. neuer = 'N'.
      ELSE.                            "force mode
*        <table1> = vics_int_entsafe.
        <table1_x> = <table1_wax>.
        CASE import_action.
          WHEN 'UPD'.
            <status>-upd_flag = 'X'. neuer = 'N'.
            PERFORM update_tab.
          WHEN 'INS'.
            <status>-upd_flag = 'X'. neuer = 'J'.
            PERFORM update_tab.
          WHEN 'DEL'.
            READ TABLE total WITH KEY <f1_x> BINARY SEARCH
                                             TRANSPORTING NO FIELDS.
            IF sy-subrc EQ 0.
              PERFORM logical_delete_from_total USING sy-tabix.
            ENDIF.
        ENDCASE.
      ENDIF.
    ENDIF.
    IF vim_import_profile = 'X'.
      CLEAR vim_profile_errorkey.
    ELSE.
      vim_import_no_message = 'X'.
      PERFORM vim_process_message USING 'SV' 'S' 'S' '151' key_safe1
                                      key_safe2 key_safe3 import_action.
    ENDIF.
    CLEAR vim_import_no_message.
  ENDIF.
  IF vim_import_mode_active NE space.
    IF ok_code EQ 'IGN ' OR function EQ 'ABR '. "error
      imp_results-import-errors = 1.
    ENDIF.
    IF ok_code NE 'IGN' AND function NE 'ABR' OR
       vim_import_forcemode NE space.
      CASE import_action.
        WHEN 'UPD'. imp_results-import-updated = 1.
        WHEN 'INS'. imp_results-import-inserted = 1.
        WHEN 'DEL'. imp_results-import-deleted = 1.
      ENDCASE.
    ENDIF.
    APPEND imp_results.
  ENDIF.
ENDFORM.                               "vim_imp_call_screen

*&--------------------------------------------------------------------*
*&      Form  MOVE_EXTRACT_TO_VIEW_WA                                 *
*&--------------------------------------------------------------------*
* move EXTRACT entry to view-/table-/texttable-workarea               *
*&--------------------------------------------------------------------*
FORM move_extract_to_view_wa.

  MOVE <vim_extract_struc> TO <table1>.
*  MOVE EXTRACT TO <TABLE1>.
  IF x_header-bastab NE space AND x_header-texttbexst NE space.
*    MOVE <extract_text> TO <table1_text>.
    MOVE <vim_xextract_text> TO <table1_xtext>.
  ENDIF.
ENDFORM.                               "move_extract_to_view_wa.

*&--------------------------------------------------------------------*
*&      Form PREPARE_SAVING                                           *
*&--------------------------------------------------------------------*
* prepare saving of changed data in data base                         *
*&--------------------------------------------------------------------*
* <-- SY-SUBRC: 0 - ok, save, others: - don't save                    *
* SY-SUBRC soll abgelöst werden durch:
* <-- VIM_ABORT_SAVING: space -> save, others -> don't save
*&--------------------------------------------------------------------*
FORM prepare_saving.
  DATA: rc LIKE sy-subrc,
        ps_addr_ref LIKE addr_ref, ps_transp_addrs(1) TYPE c,
        ps_e071k_tab LIKE e071k OCCURS 0, ps_tot_ix TYPE i,
        ps_ko200 LIKE ko200, ps_addrrc LIKE szad_field-returncode,
        ps_ko200_tab LIKE ko200 OCCURS 0, addr_e071 LIKE e071,
        addr_e071k LIKE e071k, dummy TYPE char1,
        ps_addr_errtab LIKE addr_error OCCURS 0 WITH HEADER LINE,
        new_addr_group TYPE ad_group, object_key TYPE ad_objkey.

  FIELD-SYMBOLS: <object_key_x> TYPE x, <addr_key> TYPE x.

  IF vim_adjust_middle_level_mode EQ subset.
    x_header[] = vim_adj_header.
    READ TABLE x_header INDEX 1.
    x_namtab[] = vim_adj_namtab.
  ENDIF.
  CLEAR vim_abort_saving.
  IF <status>-upd_checkd EQ space.
    PERFORM check_upd.
  ENDIF.
  IF <status>-upd_flag NE space.
    IF maint_mode EQ aendern.
      CLEAR sy-subrc.
      IF x_header-frm_bf_sav NE space.
        PERFORM (x_header-frm_bf_sav) IN PROGRAM.
*       CHECK SY-SUBRC EQ 0. "if sy-subrc ne 0 don't save -> exit
        IF sy-subrc <> 0 OR vim_abort_saving NE space.
          vim_abort_saving = 'X'. sy-subrc = 8.
          EXIT.
        ENDIF.
      ENDIF.
      IF x_header-texttbexst <> space.
        PERFORM vim_set_texttab_action_delete.          "SW Texttransl
      ENDIF.
      IF vim_client_state IS INITIAL OR
       ( vim_called_by_cluster <> space AND       "SW  CSS 80009987/1998
          vim_client_state = vim_noact ).
        CALL FUNCTION 'VIEW_GET_CLIENT_STATE'
             IMPORTING
                  transp_state = vim_client_state.
      ENDIF.
    ENDIF.
    PERFORM vim_bc_logs_maintain USING x_header
                                       vim_import_profile
                                 CHANGING vim_bc_entry_list.
   IF ( vim_no_dialog EQ space OR vim_import_mode_active NE space ) AND
        ( vim_client_state EQ vim_log OR maint_mode EQ transportieren ).
      IF corr_nbr NE space AND corr_nbr NE <status>-corr_nbr.
        <status>-corr_nbr = corr_nbr.
      ENDIF.
      IF maint_mode EQ transportieren.
        IF <status>-corr_nbr EQ space.
          PERFORM request_corr_number.
          IF x_header-flag NE vim_transport_denied AND
             <status>-l_corr_nbr NE <status>-corr_nbr.
            PERFORM prepare_corr.
          ENDIF.
        ENDIF.
      ELSE.
        PERFORM check_transp_objs_for_maint USING rc.
        IF rc NE 0.
          RAISE missing_corr_number.
        ENDIF.
        IF x_header-flag NE vim_transport_denied.
          PERFORM prepare_corr.
          PERFORM update_corr.
        ENDIF.
      ENDIF.
      PERFORM corr_upd.
*    elseif not VIM_BC_ENTRY_LIST is initial.
* fill corr_keytab for bc-set import log
*      perform vim_bc_fill_corr_keytab.
    ENDIF.
    IF vim_import_testmode NE space.   "testrun for import
      CLEAR <status>-upd_flag.         "do not save if testrun happens
      vim_import_no_message = 'X'.
      PERFORM vim_process_message USING 'SV' 'I' 'I' '154'
                                        space space space space.
      CLEAR vim_import_no_message.
    ELSE.
* log begin of database changes
      CALL FUNCTION 'VIEW_WRITE_CHANGELOG_HEADER'
           EXPORTING
                viewname = x_header-viewname
                bastab   = x_header-bastab
                begin    = 'X'
                clidep   = x_header-clidep.
* save addresses.
      IF x_header-adrnbrflag EQ 'N'.   "only new technique
        ASSIGN: object_key TO <object_key_x> CASTING,
                ps_addr_ref-appl_key TO <addr_key> CASTING.
        IF ( maint_mode EQ transportieren OR
             vim_client_state EQ vim_log ) AND
           x_header-flag NE vim_transport_denied.
          IF x_header-flag EQ space.   "standard logging required
            LOOP AT vim_addr_e071_tab INTO addr_e071.
              addr_e071-trkorr = <status>-corr_nbr.
              MODIFY vim_addr_e071_tab FROM addr_e071.
              ps_ko200 = addr_e071.
              APPEND ps_ko200 TO ps_ko200_tab.
            ENDLOOP.
            ps_transp_addrs = 'X'.
          ENDIF.
        ENDIF.
        LOOP AT vim_addresses_to_save
                                  WHERE viewname EQ x_header-viewname.
*          <f1_x> = vim_addresses_to_save-handle.
          <f1_x> = <vim_addr_handle_x>.
          READ TABLE total WITH KEY <f1_x> BINARY SEARCH.
          ps_tot_ix = sy-tabix.
          object_key = vim_addresses_to_save-handle.
          IF <action> NE geloescht AND <action> NE neuer_geloescht AND
             <action> NE update_geloescht.
* save adress
            REFRESH ps_e071k_tab.
            APPEND LINES OF vim_addr_e071k_tab TO ps_e071k_tab.
            IF vim_addresses_to_save-addrnumber CP '@NEW*'.
* new address
              ps_addr_ref-appl_table = vim_tsadrv-tablename.
              ps_addr_ref-appl_field = vim_tsadrv-fieldname.
              ps_addr_ref-appl_key   = object_key.
              ps_addr_ref-addr_group = vim_addr_group.
              ps_addr_ref-owner = 'X'.
              CALL FUNCTION 'ADDR_NUMBER_GET'
                   EXPORTING
                       address_handle    = vim_addresses_to_save-handle
                        address_reference = ps_addr_ref
*                     PERSONAL_ADDRESS           = ' '
*                     NUMBERRANGE_NUMBER         = '01'
                        generate_transport_entries = ps_transp_addrs
*                     OWNER                      = 'X'
                        table_name  = vim_addr_basetable
                        field_name  = vim_addr_bastab_field
                        objkey      = object_key
                   IMPORTING
                      address_number = vim_addresses_to_save-addrnumber
*                     RETURNCODE_NUMBERRANGE     =
                   TABLES
                        e071k_tab                  = ps_e071k_tab
                   EXCEPTIONS
                        address_handle_not_exist   = 1
                        internal_error             = 2
                        parameter_error            = 3.
              IF sy-subrc NE 0.
                MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno WITH
                           sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
                RAISE saving_correction_failed.
              ENDIF.
            ELSE.
* existing address
              IF ps_transp_addrs NE space.
                CALL FUNCTION 'ADDR_TRANSPORT_ENTRIES'
                     EXPORTING
                          addrnumber = vim_addresses_to_save-addrnumber
                          table_name = vim_addr_basetable
                          field_name = vim_addr_bastab_field
                          objkey     = object_key
                     TABLES
                          e071k_tab  = ps_e071k_tab.
              ENDIF.
            ENDIF.                       "new address
          <vim_total_address_number> = vim_addresses_to_save-addrnumber.
            TRANSLATE <action> USING ' U'.
            READ TABLE extract WITH KEY <vim_xtotal_key>
                               TRANSPORTING NO FIELDS.
            IF sy-subrc EQ 0.
              extract = total. MODIFY extract INDEX sy-tabix.
            ENDIF.
            MODIFY total INDEX ps_tot_ix.
            IF ps_transp_addrs NE space.
              CALL FUNCTION 'TR_OBJECTS_INSERT'
                   EXPORTING
                        wi_order = <status>-order_nbr
                   TABLES
                        wt_ko200 = ps_ko200_tab
                        wt_e071k = ps_e071k_tab
                   EXCEPTIONS
                        OTHERS   = 8.
              IF sy-subrc NE 0.
                MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno WITH
                           sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
                RAISE saving_correction_failed.
              ENDIF.
            ENDIF.
            CALL FUNCTION 'ADDR_SINGLE_SAVE'
                 EXPORTING
                    address_number         = <vim_total_address_number>
*                   PERSON_NUMBER          = ' '
*                   ADDRESS_TYPE           = 1
*                   EXECUTE_IN_UPDATE_TASK = ' '
                 EXCEPTIONS
                      address_not_exist      = 1
                      person_not_exist       = 2
                      address_number_missing = 3
                      reference_missing      = 4
                      internal_error         = 5
                      database_error         = 6
                      parameter_error        = 7.
            IF sy-subrc NE 0.
              MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno WITH
                         sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
              RAISE saving_correction_failed.
            ENDIF.
            CALL FUNCTION 'ADDR_DEQUEUE'
                 EXPORTING
                      address_number    = <vim_total_address_number>
                 EXCEPTIONS
                      address_not_exist = 1
                      internal_error    = 2
                      OTHERS            = 3.
          ELSEIF <action> EQ neuer_geloescht.
* reset address (UF557286/2000)
            CALL FUNCTION 'ADDR_SINGLE_RESET'
              EXPORTING
                address_handle         = vim_addresses_to_save-handle
              EXCEPTIONS
*               NUMBER_NOT_FOUND       = 1
*               HANDLE_NOT_FOUND       = 2
*               PARAMETER_ERROR        = 3
                internal_error         = 1
                OTHERS                 = 0.
            IF sy-subrc = 1.
              MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
            ENDIF.
          ENDIF.
          DELETE vim_addresses_to_save.
        ENDLOOP.                       "at vim_addresses to save.
* Delete addresses (temporary: put address into address-groups CADE or
* ZADE)
        IF vim_addr_group = 'CA01'.
          new_addr_group = 'CADE'.
        ELSEIF vim_addr_group = 'ZA01'.
          new_addr_group = 'ZADE'.
        ENDIF.
        IF NOT new_addr_group IS INITIAL.
          LOOP AT total.
            CHECK
             ( <action> EQ geloescht OR <action> EQ update_geloescht )
             AND <vim_total_address_number> NP '@NEW*'.
            <object_key_x> = <f1_x>.
            IF ps_transp_addrs NE space.
              REFRESH ps_e071k_tab.
              APPEND LINES OF vim_addr_e071k_tab TO ps_e071k_tab.
              CALL FUNCTION 'ADDR_TRANSPORT_ENTRIES'
                   EXPORTING
                        addrnumber = <vim_total_address_number>
                        table_name = vim_addr_basetable
                        field_name = vim_addr_bastab_field
                        objkey     = object_key
                   TABLES
                        e071k_tab  = ps_e071k_tab.
              CALL FUNCTION 'TR_OBJECTS_INSERT'
                   EXPORTING
                        wi_order = <status>-order_nbr
                   TABLES
                        wt_ko200 = ps_ko200_tab
                        wt_e071k = ps_e071k_tab
                   EXCEPTIONS
                        OTHERS   = 8.
              IF sy-subrc NE 0.
                MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno WITH
                           sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
                RAISE saving_correction_failed.
              ENDIF.
            ENDIF.
*            PS_ADDR_REF-APPL_TABLE = vim_tsadrv-TABLENAME.
*            PS_ADDR_REF-APPL_FIELD = vim_tsadrv-FIELDNAME.
*            PS_ADDR_REF-APPL_KEY   = <VIM_TOTAL_KEY>.
*            PS_ADDR_REF-ADDR_GROUP = VIM_ADDR_GROUP.
*            PS_ADDR_REF-OWNER = 'X'.
*            CALL FUNCTION 'ADDR_DELETE'
*                 EXPORTING
**                   ADDRESS_HANDLE      = ' '
*                      ADDRESS_NUMBER      = <VIM_TOTAL_ADDRESS_NUMBER>
*                      ADDRESS_REFERENCE   = PS_ADDR_REF
**                   DATE_FROM           = '00010101'
*                 IMPORTING
*                      RETURNCODE          = PS_ADDRRC
*                 TABLES
*                      ERROR_TABLE         = PS_ADDR_ERRTAB
*                 EXCEPTIONS
*                      ADDRESS_NOT_EXIST   = 1
*                      PARAMETER_ERROR     = 2
*                      INTERNAL_ERROR      = 3
*                      REFERENCE_NOT_EXIST = 4.
*            IF SY-SUBRC NE 0.
            IF NOT <vim_total_address_number> IS INITIAL.
              CALL FUNCTION 'ADDR_GROUP_CHANGE'
                   EXPORTING
                        address_number    = <vim_total_address_number>
*                    ADDRESS_HANDLE    = ' '
                        new_address_group = new_addr_group
                   EXCEPTIONS
                        address_not_exist = 1
                        parameter_error   = 2
                        internal_error    = 3
                        OTHERS            = 4.
              IF sy-subrc = 1.
              ELSEIF sy-subrc = 2.
                MESSAGE i298(am) WITH new_addr_group.
*   Adreßgruppe & nicht definiert, Löschvormerkung für Adresse nicht mög
                RAISE saving_correction_failed.
              ELSEIF sy-subrc <> 0.
                MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
                RAISE saving_correction_failed.
              ENDIF.
*            ENDIF.
*            IF PS_ADDRRC NE SPACE.
*              LOOP AT PS_ADDR_ERRTAB.
*                MESSAGE ID PS_ADDR_ERRTAB-MSG_ID TYPE 'I'
*                        NUMBER PS_ADDR_ERRTAB-MSG_NUMBER WITH
*                        PS_ADDR_ERRTAB-MSG_VAR1 PS_ADDR_ERRTAB-MSG_VAR2
*                       PS_ADDR_ERRTAB-MSG_VAR3 PS_ADDR_ERRTAB-MSG_VAR4.
*              ENDLOOP.
*              IF PS_ADDRRC EQ 'E'.
*                RAISE SAVING_CORRECTION_FAILED.
*              ENDIF.
*            ENDIF.
              CALL FUNCTION 'ADDR_SINGLE_SAVE'
                   EXPORTING
                    address_number         = <vim_total_address_number>
*                   PERSON_NUMBER          = ' '
*                   ADDRESS_TYPE           = 1
*                   EXECUTE_IN_UPDATE_TASK = ' '
                   EXCEPTIONS
                        address_not_exist      = 1
                        person_not_exist       = 2
                        address_number_missing = 3
                        reference_missing      = 4
                        internal_error         = 5
                        database_error         = 6
                        parameter_error        = 7.
              IF sy-subrc NE 0 AND  sy-subrc NE 1.
                MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno WITH
                           sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
                RAISE saving_correction_failed.
              ENDIF.
            ENDIF.            "not <vim_total_address_number> is initial
          ENDLOOP.                                          "at total
        ENDIF.                         "new_addr_group not initial
        CLEAR sy-subrc.
      ENDIF.                           "x_header-adrnbrflag eq 'N'.
    ENDIF.                             "vim_import_testmode ne space.
  ELSE.
    IF vim_adjust_middle_level_mode EQ space.
      MESSAGE s043(sv).
      IF function = save AND vim_called_by_cluster = space.
        PERFORM vim_add_img_notices_pai USING 'S'
                                        CHANGING dummy.
      ENDIF.
    ELSE.
      vim_adjust_middle_level_mode = 'L'.
    ENDIF.
  ENDIF.                               "<status>-upd_flag ne space
ENDFORM.                               "prepare_saving

*&--------------------------------------------------------------------*
*&      Form AFTER_SAVING                                             *
*&--------------------------------------------------------------------*
* process after-treatment of saving                                   *
*&--------------------------------------------------------------------*
FORM after_saving.
  DATA: dummy.
  DATA  e071_loctab TYPE vim_ko200_tab_type.

  IF x_header-texttbexst <> space AND  "SW Texttransl ..
     vim_abort_saving EQ space.
    IF x_header-frm_tl_upd NE space.
      PERFORM (x_header-frm_tl_upd) IN PROGRAM.
    ELSE.
      PERFORM vim_texttab_db_update.
    ENDIF.
  ENDIF.                               ".. TEXTTRANSL
  IF vim_abort_saving = space AND vim_called_by_cluster = space.
    PERFORM vim_add_img_notices_pai USING 'S'
                                    CHANGING dummy.
  ENDIF.
  IF x_header-frm_af_sav NE space.
    PERFORM (x_header-frm_af_sav) IN PROGRAM.
  ENDIF.
*    Call synchronizer
  IF vim_abort_saving EQ space.
    REFRESH e071_loctab.
    APPEND e071 TO e071_loctab.
    PERFORM vim_synchronizer_call
                  USING e071_loctab[]
                        corr_keytab[]
                        'X'.
  ENDIF.
  IF <status>-selected CO 'NUD'.
    CLEAR <status>-selected.
  ENDIF.
  IF vim_abort_saving = space.
* build up BC-Set import log
    PERFORM vim_bc_logs_put CHANGING vim_bc_entry_list.
  ENDIF.
  CLEAR vim_abort_saving.
* log end of database changes
  CALL FUNCTION 'VIEW_WRITE_CHANGELOG_HEADER'
    EXPORTING
      viewname = x_header-viewname
      bastab   = x_header-bastab
      begin    = space
      clidep   = x_header-clidep.
  TRANSLATE vim_adjust_middle_level_mode USING 'XLSL'.
ENDFORM.                               "after_saving

*&--------------------------------------------------------------------*
*&      Form  BEFORE_LEAVING_EXT                                      *
*&--------------------------------------------------------------------*
* do all the things necessary before leaving - external call          *
*&--------------------------------------------------------------------*
FORM BEFORE_LEAVING_EXT USING VALUE(VIEWNAME) LIKE VIMDESC-VIEWNAME
                              VALUE(MAINTVIEW) LIKE VIMDESC-MAINTVIEW
                              VALUE(EXIT_FORM) LIKE VIMDESC-FRM_BF_END.
  DATA: NAME(20) TYPE C VALUE 'STATUS_'.
  FIELD-SYMBOLS: <BLE_STATUS>.

  ASSIGN <STATUS> TO <BLE_STATUS>.
* NAME+7 = VIEWNAME.
  NAME+7 = MAINTVIEW.                  "Subviews
  ASSIGN (NAME) TO <STATUS>.
  IF VIM_CORR_OBJ_VIEWNAME NE VIEWNAME.
    CLEAR MAINT_MODE.
  ELSE.
    MAINT_MODE = <STATUS>-ST_ACTION.
  ENDIF.
  PERFORM BEFORE_LEAVING_FRAME_FUNCTION USING EXIT_FORM.
  ASSIGN <BLE_STATUS> TO <STATUS>.
ENDFORM.                               "before_leaving_ext

*&--------------------------------------------------------------------*
*&      Form  BEFORE_LEAVING_FRAME_FUNCTION.                          *
*&--------------------------------------------------------------------*
* do all the things necessary before leaving the frame function unit  *
*&--------------------------------------------------------------------*
FORM before_leaving_frame_function
                        USING value(exit_form) LIKE vimdesc-frm_bf_end.

  DATA: prc TYPE sy-subrc, dummy TYPE c, dummi TYPE i.

  IF <status>-corr_enqud NE space.
    CALL FUNCTION 'DEQUEUE_E_TRKORR'
         EXPORTING
              trkorr = <status>-corr_nbr.
*             X_TRKORR = E02.
    CLEAR <status>-corr_enqud.
  ENDIF.
  CLEAR <status>-corr_nbr.
  CLEAR <status>-initializd.
  CLEAR <initial>. <vim_client_initial> = sy-mandt.
  IF ( maint_mode EQ anzeigen OR maint_mode EQ transportieren ) AND
     vim_corr_obj_viewname NE space.
    CLEAR vim_corr_obj_viewname.
  ENDIF.
  PERFORM vim_reset_texttab USING view_name.        "SW Texttransl
  CALL FUNCTION 'VIEW_RESET_LANGUAGES'."SW Texttransl
  IF exit_form NE space.
    PERFORM (exit_form) IN PROGRAM.
  ENDIF.
  CLEAR function.
  FREE vim_bc_entry_list.
  CLEAR: <status>-bcfixnochg, vim_bc_chng_allowed,
         <status>-bcfixdelinfosent.
** test getting profiles: begin
*  IF SY-UNAME = 'FRENZELU' OR SY-UNAME = 'ROSENTHAL'    "UF Profile
*   OR SY-UNAME = 'BUEHLERM'.
*    CALL FUNCTION 'SCPR_MEMORY_DELETE'.
*  ENDIF.
** test getting profiles: end
  CLEAR vim_oc_inst.
*  refresh vim_dba_sel_kept.                              "UF210200
*delete after_nonkey flag in check_range.
  PERFORM check_range IN PROGRAM saplsvix
             USING space 0 'E' space space space
             CHANGING dummy prc.
ENDFORM.                               "before_leaving_frame_function

*&--------------------------------------------------------------------*
*&      Form  LISTE_EXIT_COMMAND                                      *
*&--------------------------------------------------------------------*
* handle exit commands on list screen                                 *
*&--------------------------------------------------------------------*
FORM LISTE_EXIT_COMMAND.
  CASE OK_CODE.
    WHEN 'ABR '.
      FUNCTION = OK_CODE.
      CLEAR OK_CODE.
      CASE VIM_SPECIAL_MODE.
        WHEN VIM_REPLACE.
          CLEAR VIM_ACT_DYNP_VIEW. SET SCREEN 0. LEAVE SCREEN.
        WHEN VIM_DELETE.
          SET SCREEN 0. LEAVE SCREEN.
        WHEN VIM_UPGRADE.
*         CLEAR: VIM_SPECIAL_MODE, MAXLINES. LEAVE SCREEN.
          CLEAR VIM_ACT_DYNP_VIEW. NEUER = 'N'.
          SET SCREEN 0. LEAVE SCREEN.
        WHEN OTHERS.
          PERFORM LISTE_ABBRECHEN.
      ENDCASE.
    WHEN 'IGN '.
      CASE VIM_SPECIAL_MODE.
        WHEN VIM_REPLACE.
          CLEAR VIM_ACT_DYNP_VIEW. SET SCREEN 0. LEAVE SCREEN.
        WHEN VIM_DELETE.
          SET SCREEN 0. LEAVE SCREEN.
*       WHEN VIM_UPGRADE.  "impossible
*         CLEAR OK_CODE. LEAVE SCREEN.
        WHEN VIM_UPGRADE.
          CLEAR VIM_ACT_DYNP_VIEW. NEUER = 'N'.
          SET SCREEN 0. LEAVE SCREEN.
        WHEN OTHERS.
          LOOP AT SCREEN.
            SCREEN-ACTIVE = 0.
            MODIFY SCREEN.
          ENDLOOP.
      ENDCASE.
      NEUER = 'N'.
      CLEAR <STATUS>-UPD_FLAG.
  ENDCASE.
ENDFORM.                               "liste_exit_command.

*&--------------------------------------------------------------------*
*&      Form VIM_GET_GLOBAL_TABLE                                     *
*&--------------------------------------------------------------------*
* get global field table (for external call)                          *
*&--------------------------------------------------------------------*
FORM vim_get_global_table USING value(name_of_table_to_get) TYPE c
                                table_out TYPE ANY TABLE
                                vggt_return LIKE sy-subrc.

  FIELD-SYMBOLS: <table> TYPE ANY TABLE.
  ASSIGN (name_of_table_to_get) TO <table>.
  IF sy-subrc EQ 0.
    table_out = <table>.
  ENDIF.
  vggt_return = sy-subrc.
ENDFORM.                               "vim_get_global_field_value

*&--------------------------------------------------------------------*
*&      Form VIM_GET_GLOBAL_FIELD_VALUE                               *
*&--------------------------------------------------------------------*
* get global field value (for external call)                          *
*&--------------------------------------------------------------------*
FORM vim_get_global_field_value USING value(name_of_field_to_get) TYPE c
                                      value(type_of_field_to_get) TYPE c
                                      field_value
                                      vggfv_return LIKE sy-subrc.

  FIELD-SYMBOLS: <field> TYPE ANY.
  ASSIGN (name_of_field_to_get) TO <field>
   CASTING TYPE (type_of_field_to_get).
  IF sy-subrc EQ 0.
    field_value = <field>.
  ENDIF.
  vggfv_return = sy-subrc.
ENDFORM.                               "vim_get_global_field_value

*&--------------------------------------------------------------------*
*&      Form VIM_SET_GLOBAL_FIELD_VALUE                               *
*&--------------------------------------------------------------------*
* set global field value (for external call)                          *
*&--------------------------------------------------------------------*
FORM VIM_SET_GLOBAL_FIELD_VALUE USING VALUE(NAME_OF_FIELD_TO_SET) TYPE C
                                      VALUE(TYPE_OF_FIELD_TO_SET) TYPE C
                                      VALUE(VALUE_TO_SET)
                                      VSGFV_RETURN LIKE SY-SUBRC.

  FIELD-SYMBOLS: <FIELD>.
  ASSIGN (NAME_OF_FIELD_TO_SET) TO <FIELD> TYPE TYPE_OF_FIELD_TO_SET.
  IF SY-SUBRC EQ 0.
    <FIELD> = VALUE_TO_SET.
  ENDIF.
  VSGFV_RETURN = SY-SUBRC.
ENDFORM.                               "vim_set_global_field_value

*&--------------------------------------------------------------------*
*&      Form VIM_APPEND_GLOBAL_TABLE                                  *
*&--------------------------------------------------------------------*
* set global field value (for external call)                          *
*&--------------------------------------------------------------------*
FORM VIM_APPEND_GLOBAL_TABLE USING VALUE(NAME_OF_TABLE) TYPE C
                                   VALUE(BASE_TABLE) LIKE TVDIR-FLAG
                                   VALUE(TABLEN) LIKE VIMDESC-TABLEN
                                   VALUE(ENTRY_TO_APPEND)
                                   VALUE(ACT_FLAG) LIKE TVDIR-FLAG
                                   VALUE(MRK_FLAG) LIKE TVDIR-FLAG
                                   VALUE(TXTACT_FLAG) LIKE TVDIR-FLAG
                                   VAGT_RETURN LIKE SY-SUBRC.
  DATA: WA(4096) TYPE C, DUM TYPE I.
  FIELD-SYMBOLS: <TABLE> TYPE TABLE, <ENTRY>.
  ASSIGN (NAME_OF_TABLE) TO <TABLE>.
  IF SY-SUBRC EQ 0.
    WA = ENTRY_TO_APPEND.
    WA+TABLEN(1) = ACT_FLAG. DUM = TABLEN + 1.
    WA+DUM(1) = MRK_FLAG. ADD 1 TO DUM.
    IF BASE_TABLE NE SPACE.
      WA+DUM(1) = TXTACT_FLAG. ADD 1 TO DUM.
    ENDIF.
    ASSIGN WA(DUM) TO <ENTRY>.
    APPEND <ENTRY> TO <TABLE>.
  ENDIF.
  VAGT_RETURN = SY-SUBRC.
ENDFORM.                               "vim_append_globall_table

*&--------------------------------------------------------------------*
*&      Form VIM_RESTORE_LOCAL_MEMORY                                 *
*&--------------------------------------------------------------------*
* restore local memory of function pool (for external call)           *
*&--------------------------------------------------------------------*
FORM VIM_RESTORE_LOCAL_MEMORY.
  DATA: H_NAME(31) TYPE C VALUE '*', H_STATE(30) VALUE 'STATUS_'.

  VIEW_NAME = X_HEADER-VIEWNAME.
  IF X_HEADER-BASTAB EQ SPACE.
    H_NAME+1 = X_HEADER-MAINTVIEW. H_STATE+7 = X_HEADER-MAINTVIEW.
    ASSIGN: (X_HEADER-MAINTVIEW) TO <TABLE1>, (H_NAME) TO <INITIAL>,
            (H_STATE) TO <STATUS>.
  ENDIF.
  VIM_RESTORE_MODE = 'X'.
  PERFORM INITIALISIEREN.
  VIEW_ACTION = <STATUS>-ST_ACTION. TRANSLATE VIEW_ACTION USING 'CUAU'.
  PERFORM JUSTIFY_ACTION_MODE.
  MOVE: VIEW_ACTION TO MAINT_MODE,
        <STATUS>-CORR_NBR TO CORR_NBR,
        <STATUS>-FCODE TO FUNCTION.
  PERFORM CALL_DYNPRO.
ENDFORM.                               "vim_restore_local_memory

*&--------------------------------------------------------------------*
*&      Form X_CALL_VIEWMAINTENANCE                                   *
*&--------------------------------------------------------------------*
* external call of view maintenance                                   *
*&--------------------------------------------------------------------*
* --> XCV_USE_LCL_TBL:  'X' Datencontainer XCV_TOTAL und XCV_EXTRACT
*                       sind nicht struktueriert und nicht vom Typ X
*                       => Daten müssen in lokale Container umgesetzt
*                       werden.
* --> XCV_IMP_SPECMODE: 'P' Profilimport/
*                       'T' Testmodus Import/'F' Forcemodus Import /
*                       'B' T + F Import
*&--------------------------------------------------------------------*
FORM x_call_viewmaintenance USING
                                value(xcv_use_lcl_tbl) LIKE tvdir-flag
                                value(xcv_import) LIKE tvdir-flag
                                xcv_corrnbr LIKE e070-trkorr
                                value(xcv_fcode) TYPE vimty_tcode
                                value(xcv_action) LIKE tvdir-flag
                                value(xcv_name) TYPE vimty_tablename
                                value(xcv_tot_name) TYPE c
                                value(xcv_ext_name) TYPE c
                                value(xcv_upgr_dest) LIKE rfcdes-rfcdest
                                value(xcv_upgr_clnt) LIKE sy-mandt
                                xcv_upd_requ LIKE tvdir-flag
                                xcv_e071k TYPE table
                                xcv_dba_sel TYPE table
                                xcv_dpl_sel TYPE table
                                xcv_excufc TYPE table
                                xcv_extract TYPE table
                                xcv_total TYPE table
                                xcv_header TYPE table
                                xcv_namtab TYPE table
                                xcv_last_command TYPE vimty_tcode
                                xcv_last_act_entry LIKE sy-tabix
                                xcv_results LIKE vimmodres
                                xcv_imp_results TYPE slctr_tables_keys
                                value(xcv_imp_specmode) LIKE tvdir-flag
                                value(xcv_cmp_slcnds) LIKE tvdir-flag.

  DATA: xcv_return TYPE i, xcv_i_fcode TYPE vimty_tcode,
        line_name(30) TYPE c, length TYPE i, tabtype type ob_typ,
        header_wa_loc TYPE vimdesc,
        BEGIN OF tabline,
          line(4096) TYPE c,
        END OF tabline.
  FIELD-SYMBOLS: <total> TYPE table, <extract> TYPE table,
                 <tabline> TYPE ANY, <tabline_x> TYPE x,
                 <tabline2> TYPE ANY, <tabline2_x> TYPE x,
                 <header> TYPE vimdesc.
  LOCAL: vim_import_mode_active, vim_no_dialog, vim_import_testmode,
        vim_import_forcemode.          "SW  wg. Rekurs. im Cluster

  vim_no_dialog = xcv_import. TRANSLATE vim_no_dialog USING 'H DX'.
  IF xcv_imp_specmode = 'P'.           "Profilimp
    vim_import_profile = 'X'.
  ENDIF.
  vim_import_testmode = xcv_imp_specmode.
  TRANSLATE vim_import_testmode USING 'TXBXF P '.
  vim_import_forcemode = xcv_imp_specmode.
  TRANSLATE vim_import_forcemode USING 'T BXFXP '.
  IF xcv_use_lcl_tbl ne space.
    ASSIGN: (xcv_tot_name) TO <total>, (xcv_ext_name) TO <extract>.
    IF xcv_use_lcl_tbl ne 'L'.         "use not _only_ local tables
      READ TABLE xcv_header ASSIGNING <header> INDEX 1.
      IF <header>-bastab ne space and <header>-texttbexst ne space.
        length = <header>-after_tabc + <header>-aft_txttbc
                 + 3 * cl_abap_char_utilities=>charsize.
      ELSE.
        length = <header>-after_tabc
                 + 2 * cl_abap_char_utilities=>charsize.
      ENDIF.
      SEARCH xcv_tot_name FOR '[' IN CHARACTER MODE.
      MOVE xcv_tot_name(sy-fdpos) TO line_name.
      ASSIGN: (line_name) TO <tabline2>,
              <tabline2> TO <tabline2_x> CASTING.
      REFRESH: <total>, <extract>.
      LOOP AT xcv_total ASSIGNING <tabline>.
        ASSIGN <tabline> TO <tabline_x> CASTING.
        MOVE <tabline_x> TO <tabline2_x>(length).
        APPEND <tabline2> TO <total>.
      ENDLOOP.
      LOOP AT xcv_extract ASSIGNING <tabline>.
        ASSIGN <tabline> TO <tabline_x> CASTING.
        MOVE <tabline_x> TO <tabline2_x>(length).
        APPEND <tabline2> TO <extract>.
      ENDLOOP.
*      <total> = xcv_total. <extract> = xcv_extract.
    ENDIF.
  ELSE.
    ASSIGN: xcv_total TO <total>, xcv_extract TO <extract>.
  ENDIF.
  vim_import_mode_active = xcv_import. xcv_i_fcode = xcv_fcode.
  IF xcv_import ne space and xcv_fcode ne 'SAVE'.
  ELSEIF xcv_import ne space and xcv_fcode eq 'SAVE'.       "SW
    imp_results[] = xcv_imp_results[].                      "SW
  ELSEIF xcv_fcode eq 'INS' or xcv_fcode eq 'DEL' or
         xcv_fcode eq 'UPD' or xcv_fcode eq 'SHOW'.
    vim_single_entry_function = xcv_fcode. xcv_i_fcode = 'EDIT'.
  ENDIF.
  IF xcv_import eq 'D' and xcv_fcode eq 'SAVE'.
    vim_import_no_message = 'X'.
  ENDIF.
  CALL FUNCTION 'VIEW_MAINTENANCE_LOW_LEVEL'
    EXPORTING
      corr_number                 = xcv_corrnbr
      fcode                       = xcv_i_fcode
      view_action                 = xcv_action
      view_name                   = xcv_name
      rfc_destination_for_upgrade = xcv_upgr_dest
      client_for_upgrade          = xcv_upgr_clnt
      complex_selconds_used       = xcv_cmp_slcnds
    IMPORTING
      last_act_entry              = xcv_last_act_entry
      ucomm                       = xcv_last_command
      update_required             = xcv_upd_requ
      corr_number                 = xcv_corrnbr
    TABLES
      corr_keytab                 = xcv_e071k
      dba_sellist                 = xcv_dba_sel
      dpl_sellist                 = xcv_dpl_sel
      excl_cua_funct              = xcv_excufc
      extract                     = <extract>
      total                       = <total>
      x_header                    = xcv_header
      x_namtab                    = xcv_namtab
    EXCEPTIONS
      function_not_found          = 1
      missing_corr_number         = 2
      no_value_for_subset_ident   = 3
      saving_correction_failed    = 4.
*  IF xcv_import NE space AND
*     ( sy-subrc NE 0 OR
*       xcv_fcode EQ save AND <status>-upd_flag NE space ).
* "HCG BC-Set: sy-subrc NE 0 -> always error message in log
  IF ( xcv_import NE space OR vim_import_profile NE space ) AND
     ( sy-subrc ne 0 or
       xcv_fcode eq save and <status>-upd_flag ne space ).
    IF sy-msgid ne space.
      vim_import_no_message = 'X'.
      IF vim_import_profile = 'X'.
        read table xcv_header into header_wa_loc index 1.
        IF header_wa_loc-bastab EQ space.
          tabtype = 'V'.
        ELSE.
          tabtype = 'S'.
        ENDIF.
        PERFORM vim_bc_process_message USING sy-msgid 'I' 'E' sy-msgno
                        sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 tabtype.
      ELSE.
        PERFORM vim_process_message USING sy-msgid 'I' 'E' sy-msgno
                       sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      CLEAR vim_import_no_message.
    ENDIF.
*   IF XCV_IMPORT NE SPACE.
    LOOP AT imp_results.
      IF imp_results-import-inserted ne 0.
        imp_results-import-errors = imp_results-import-inserted.
        CLEAR imp_results-import-inserted.
      ELSEIF imp_results-import-updated ne 0.
        imp_results-import-errors = imp_results-import-updated.
        CLEAR imp_results-import-updated.
      ELSEIF imp_results-import-deleted ne 0.
        imp_results-import-errors = imp_results-import-deleted.
        CLEAR imp_results-import-deleted.
      ENDIF.
      MODIFY imp_results.
    ENDLOOP.
  ELSEIF xcv_import eq space and xcv_fcode eq 'READ' and
         sy-subrc ne 0.                "probably called by VIEW_GET_DATA
    IF sy-subrc eq 2. "probably individual authority check failed
      MESSAGE i053(sv) RAISING no_authority.
    ELSE.                              "other error
      MESSAGE i037(sv) WITH view_name RAISING no_viewmaint_tool.
    ENDIF.
  ENDIF.
  IF xcv_fcode eq 'EXED' or xcv_fcode eq 'DEL'.
    xcv_results = vim_results_of_ext_mod.
  ELSEIF xcv_fcode eq read.
    DESCRIBE TABLE <total> LINES xcv_results-nbr_of_upd.
  ELSEIF xcv_fcode eq save and xcv_import eq 'D'.
    CLEAR vim_import_no_message.
  ENDIF.
  IF xcv_use_lcl_tbl ne space and xcv_use_lcl_tbl ne 'L'.
    REFRESH: xcv_total, xcv_extract.
    ASSIGN: tabline TO <tabline2_x> CASTING.
    LOOP AT <total> ASSIGNING <tabline>.
      ASSIGN <tabline> TO <tabline_x> CASTING.
      MOVE <tabline_x> TO <tabline2_x>(length).
      APPEND tabline TO xcv_total.
    ENDLOOP.
    LOOP AT <extract> ASSIGNING <tabline>.
      ASSIGN <tabline> TO <tabline_x> CASTING.
      MOVE <tabline_x> TO <tabline2_x>(length).
      APPEND tabline TO xcv_extract.
    ENDLOOP.
*    MOVE: <total> TO xcv_total, <extract> TO xcv_extract.
  ENDIF.
  CLEAR vim_single_entry_function.                          "SW
  IF xcv_import ne space.
    xcv_imp_results = imp_results[].
    REFRESH imp_results.                                    "SW
  ENDIF.
ENDFORM.                               "x_call_viewmaintenance

*&--------------------------------------------------------------------*
*&      Form  X_CALL_SCREEN                                           *
*&--------------------------------------------------------------------*
* external call of specified view maintenance screen                  *
*&--------------------------------------------------------------------*
FORM X_CALL_SCREEN USING VALUE(XCS_SCREEN) LIKE D020S-DNUM.
  CALL SCREEN XCS_SCREEN.
ENDFORM.                               "x_call_screen

*&--------------------------------------------------------------------*
*&      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.

*&--------------------------------------------------------------------*
*&      Form  CHECK_DELIM_NEW_ENTRY                                   *
*&--------------------------------------------------------------------*
* check new entry for delimitation (called from validity period sbscr)*
*---------------------------------------------------------------------*
* BEGDATE ---> E: new begin date /B: new end date                     *
* ENDDATE ---> E: end date /B: begin date                             *
*&--------------------------------------------------------------------*
FORM check_delim_new_entry USING value(begdate) value(enddate).
  LOOP AT total.
    CHECK <vim_tot_mkey_beforex> EQ <vim_f1_beforex> AND
          ( vim_mkey_after_exists EQ space OR
            <vim_tot_mkey_afterx> EQ <vim_f1_afterx> ).
    CHECK <vim_enddate> NE enddate.
    CHECK <action> NE geloescht AND
          <action> NE neuer_geloescht AND
          <action> NE update_geloescht.
    IF x_header-delmdtflag EQ 'E'.     "end date is key field
      CHECK <vim_enddate> GE begdate AND <vim_begdate> LE enddate.
    ELSE.                              "begin date is key field
      CHECK <vim_enddate> LE begdate AND <vim_begdate> GE enddate. "entr
    ENDIF.                             "x_header-delmdtflag eq 'E'
    IF vim_special_mode NE vim_reset.
      MESSAGE w047(sv). "Überlagerte Sätze werden gelöscht
    ELSE.
      MESSAGE i047(sv). "Überlagerte Sätze werden gelöscht
    ENDIF.
    EXIT.
  ENDLOOP.
ENDFORM.                               "check_delim_new_entry

*&--------------------------------------------------------------------*
*&      Form  TEMP_DELIM_DEL_OVERLED_ENTRIES                          *
*&--------------------------------------------------------------------*
* delete entries with overlaying time ranges                          *
*---------------------------------------------------------------------*
* BEGDATE ---> E: new begin date /B: new end date                     *
* ENDDATE ---> E: end date /B: begin date                             *
*&--------------------------------------------------------------------*
FORM temp_delim_del_overld_entries USING value(begdate) TYPE d
                                         value(enddate) TYPE d.
  LOCAL: extract, <table1>.
  DATA: first(1) TYPE c VALUE 'X', overlayed(1) TYPE c, cur_ix TYPE i,
        date_increment TYPE i, enddate_safe(8) TYPE c, new_ix TYPE i,
        trans_pattern(6) TYPE c, act_safe, mark_safe, act_txt_safe,
        enddate_safe2(8) TYPE c, act, act_txt, hf TYPE i,
        key_safe LIKE vim_merged_entries-new_key, date_safe TYPE d,
*        old_key TYPE vim_line_ul,
        old_keyx type VRSDAT1000.

  IF vim_temp_delim_alr_checked NE space.
    CLEAR first.
  ENDIF.
  LOOP AT total.
    CHECK <vim_tot_mkey_beforex> EQ <vim_f1_beforex> AND
          ( vim_mkey_after_exists EQ space OR
            <vim_tot_mkey_afterx> EQ <vim_f1_afterx> ).
    IF vim_special_mode NE vim_upgrade AND
       vim_special_mode NE vim_reset AND
       vim_special_mode NE vim_replace.
      CHECK <vim_enddate> NE enddate.
    ENDIF.
    CHECK <action> NE geloescht AND
          <action> NE neuer_geloescht AND
          <action> NE update_geloescht.
    CLEAR overlayed.
    IF x_header-delmdtflag EQ 'E'.     "end date is key field
      CHECK <vim_enddate> GE begdate AND <vim_begdate> LE enddate.
      IF <vim_begdate> GE begdate AND <vim_enddate> LT enddate.
        MOVE 'F' TO overlayed. "whole old entry is overlayed by new one
      ELSEIF <vim_begdate> LT begdate AND <vim_enddate> GT enddate.
        MOVE 'M' TO overlayed. "middle of old entry is overl. by new one
      ELSEIF <vim_begdate> LE enddate AND <vim_enddate> GT enddate.
        MOVE 'P' TO overlayed. "part of old entry is overlayed by new on
      ELSEIF <vim_begdate> EQ begdate AND <vim_enddate> EQ enddate.
        temporal_delimitation_happened = 'N'. EXIT. "no delim required
      ELSEIF <vim_enddate> EQ enddate.
        MOVE 'E' TO overlayed. "end of old entry is overlayed by new one
      ENDIF.
      MOVE -1 TO date_increment.
    ELSE.                              "begin date is key field
      CHECK <vim_enddate> LE begdate AND <vim_begdate> GE enddate. "entr
      IF <vim_begdate> LE begdate AND <vim_enddate> GT enddate.
        MOVE 'F' TO overlayed. "whole old entry is overlayed by new one
      ELSEIF <vim_enddate> LT enddate AND <vim_begdate> GT begdate.
        MOVE 'M' TO overlayed. "middle of old entry is overl. by new one
      ELSEIF <vim_enddate> LE enddate AND <vim_begdate> GT enddate.
        MOVE 'P' TO overlayed. "part of old entry is overlayed by new on
      ELSEIF <vim_begdate> EQ begdate AND <vim_enddate> EQ enddate.
        temporal_delimitation_happened = 'N'. EXIT. "no delim required
      ELSEIF <vim_enddate> EQ enddate.
        MOVE 'E' TO overlayed. "begin of old entry is overlayed by new o
      ENDIF.
      MOVE 1 TO date_increment.
    ENDIF.                             "x_header-delmdtflag eq 'E'
    IF first NE space.
      IF vim_special_mode NE vim_reset.
        MESSAGE w047(sv). "Überlagerte Sätze werden gelöscht
      ELSE.
        MESSAGE i047(sv). "Überlagerte Sätze werden gelöscht
      ENDIF.
      CLEAR first.
    ENDIF.
    cur_ix = sy-tabix.
    CLEAR vim_delim_entries.
    READ TABLE extract WITH KEY <vim_xtotal_key>.
*    READ TABLE extract WITH KEY total.
    IF sy-subrc EQ 0.
      MOVE sy-tabix TO vim_delim_entries-index3.
      IF overlayed NE 'P' AND overlayed NE 'M' AND overlayed NE 'E'.
        APPEND vim_delim_entries.
      ENDIF.
    ENDIF.
    IF overlayed EQ space OR overlayed EQ 'F'.
* delete old entry which is overlayed
      MOVE: original TO trans_pattern, geloescht TO trans_pattern+1(1),
            aendern  TO trans_pattern+2(1), update_geloescht
                                                 TO trans_pattern+3(1),
            neuer_eintrag TO trans_pattern+4(1), neuer_geloescht
                                                 TO trans_pattern+5(1).
      TRANSLATE <action> USING trans_pattern.
      IF x_header-bastab NE space AND x_header-texttbexst NE space AND
         x_header-ptfrkyexst EQ space.
        TRANSLATE <action_text> USING trans_pattern.
      ENDIF.
      IF <mark> EQ markiert.
        <mark> = nicht_markiert.
        SUBTRACT 1 FROM mark_total.
      ENDIF.
      MODIFY total.
    ENDIF. "overlayed eq space or overlayed eq 'F'
    IF overlayed EQ space OR overlayed EQ 'M' OR overlayed EQ 'E'.
* create new entry due to delimitation
      IF overlayed EQ 'M'.
        MOVE: <vim_enddate> TO enddate_safe, <action> TO act_safe,
              <mark> TO mark_safe.
        IF x_header-bastab NE space AND x_header-texttbexst NE space.
          MOVE <action_text> TO act_txt_safe.
        ENDIF.
      ENDIF.
      CLEAR hf.
      old_keyx = <vim_xtotal_key>.                 "SW Texttransl
*      old_key = total.
      <vim_enddate> = begdate + date_increment.
      CHECK <vim_enddate> GE <vim_begdate>.                 "aro 070798
      <action> = neuer_eintrag.
      <mark> = nicht_markiert.
      IF x_header-texttbexst NE space AND
         x_header-ptfrkyexst EQ space.
        PERFORM vim_temp_delim_texttab
                 USING enddate old_keyx.  "SW Texttransl
        IF x_header-bastab NE space.
          MOVE: <vim_enddate> TO <vim_text_enddate>,
                neuer_eintrag TO <action_text>.
        ENDIF.
      ENDIF.
      IF vim_special_mode NE space.    "special mode
        PERFORM temp_delim_undelete USING <vim_enddate_mask>
                                          <vim_begdate>
                                          act act_txt new_ix.
        IF new_ix NE 0.
          MOVE act TO <action>.
          IF x_header-bastab NE space AND x_header-texttbexst NE space.
            MOVE act_txt TO <action_text>.
          ENDIF.
          MODIFY total INDEX new_ix.
        ENDIF.
      ENDIF.                           "special mode
      IF vim_special_mode EQ space OR sy-subrc NE 0.
        IF x_header-delmdtflag EQ 'E'. "end date is key field
          new_ix = cur_ix. INSERT total.
        ELSE.                          "begin date is key field
          new_ix = cur_ix + 1. INSERT total INDEX new_ix.
        ENDIF.                         "x_header-delmdtflag eq 'E'
      ENDIF.
      IF vim_special_mode NE vim_undelete AND
         vim_delim_entries-index3 NE 0.
        vim_delim_entries-index1 = new_ix.
        vim_delim_entries-index2 = vim_delim_entries-index3.
        sy-fdpos = vim_delim_entries-index3.
        CLEAR vim_delim_entries-index3.
        APPEND vim_delim_entries.
        vim_delim_entries-index3 = sy-fdpos.
      ENDIF.                           "no undelete mode
    ENDIF. "overlayed eq space or overlayed eq 'M'
    IF overlayed EQ 'P' OR overlayed EQ 'M'.
      IF overlayed EQ 'M'.
        MOVE: enddate_safe TO <vim_enddate>, act_safe TO <action>,
              mark_safe TO <mark>.
        IF x_header-bastab NE space AND x_header-texttbexst NE space.
          MOVE act_txt_safe TO <action_text>.
        ENDIF.
      ENDIF.
      CLEAR hf.
      <vim_begdate> = enddate - date_increment.
      MOVE: original TO trans_pattern, aendern TO trans_pattern+1(1).
      TRANSLATE <action> USING trans_pattern.
      IF <mark> EQ markiert.
        <mark> = nicht_markiert.
        SUBTRACT 1 FROM mark_total.
      ENDIF.
      MODIFY total.
      IF vim_delim_entries-index3 NE 0.
        vim_delim_entries-index1 = cur_ix.
        vim_delim_entries-index2 = vim_delim_entries-index3.
        APPEND vim_delim_entries.
      ENDIF.
    ENDIF. "overlayed eq 'P' or overlayed eq 'M'
  ENDLOOP.
  MOVE 'G' TO temporal_delimitation_happened.
ENDFORM.                               "temp_delim_del_overled_entries

*&--------------------------------------------------------------------*
*&      Form  TEMP_DELIM_UNDELETE                                     *
*&--------------------------------------------------------------------*
* process undelete of non-selected entries due to temp. delimitation  *
*&--------------------------------------------------------------------*
* TDU_ENDDA --> enddate to display during warning                     *
* TDU_ACT   --> value of action flag                                  *
* TDU_ACT_TXT --> value of action flag for text table                 *
* TDU_IX    --> index of entry to modify in TOTAL                     *
* COUNTER   <-> (global) number of undeleted entries                  *
* SY-SUBRC  <-- (global) 0 - curr. entry undeleted, others - new entry*
*&--------------------------------------------------------------------*
FORM temp_delim_undelete USING value(tdu_endda) value(tdu_begda)
                               tdu_act tdu_act_txt tdu_ix.
  LOCAL: total.
  DATA: trans_pattern(6) TYPE c, rec TYPE i, ix TYPE i.

  CLEAR tdu_ix.
  READ TABLE total WITH KEY <vim_xtotal_key> BINARY SEARCH.
  IF sy-subrc EQ 0. "new entry already exists - must be a deleted
    "by previous temporal delimitation one
    IF <action> EQ geloescht OR <action> EQ neuer_geloescht OR
       <action> EQ update_geloescht.
      tdu_ix = sy-tabix.
      READ TABLE extract WITH KEY <vim_xtotal_key>.
      rec = sy-subrc. ix = sy-tabix.
      IF sy-subrc EQ 0 AND <xact> EQ markiert.
        SUBTRACT 1 FROM mark_extract.
      ELSE.
        MOVE tdu_endda TO <vim_enddate_mask>.
        IF vim_special_mode EQ vim_reset.
          MESSAGE i120(sv)."Es werden weitere Einträge zurückgeholt
        ELSE.
          MESSAGE w120(sv)."Es werden weitere Einträge zurückgeholt
        ENDIF.
      ENDIF.
      ADD 1 TO counter.
      IF rec EQ 0.                     "read table extract subrc
        sy-fdpos = vim_delim_entries-index3.
        vim_delim_entries-index3 = ix.
        APPEND vim_delim_entries.
        vim_delim_entries-index3 = sy-fdpos.
      ENDIF.
      MOVE: geloescht TO trans_pattern,
              original TO trans_pattern+1(1),
            neuer_geloescht TO trans_pattern+2(1),
              neuer_eintrag TO trans_pattern+3(1),
            update_geloescht TO trans_pattern+4(1),
              aendern TO trans_pattern+5(1).
      TRANSLATE <action> USING trans_pattern.
      MOVE <action> TO tdu_act.
      IF x_header-bastab NE space AND
         x_header-texttbexst NE space.
        TRANSLATE <action_text> USING trans_pattern.
        MOVE <action_text> TO tdu_act_txt.
      ENDIF.
      IF tdu_begda NE <vim_begdate>.   "udl entry will be modified
        MOVE: original TO trans_pattern, aendern TO trans_pattern+1.
        TRANSLATE: tdu_act USING trans_pattern,
                   tdu_act_txt USING trans_pattern.
      ENDIF.
    ENDIF.                             "current entry is a deleted one
    CLEAR sy-subrc.
  ENDIF.                               "sy-subrc eq 0
ENDFORM.                               "temp_delim_undelete

*&--------------------------------------------------------------------*
*&      Form TEMPORAL_DELIMITATION                                    *
*&--------------------------------------------------------------------*
* process temporal delimitation                                       *
*&--------------------------------------------------------------------*
FORM temporal_delimitation.
  constants: highdate TYPE d VALUE '99991231'.
  DATA: entries_exist(1) TYPE c,
        enddate_safe TYPE d, act(1) TYPE c, act_txt(1) TYPE c,
        hf TYPE i,
        date_safe TYPE d,
        ok_code_safe LIKE ok_code, function_safe LIKE function,
        delim_entr_safe TYPE STANDARD TABLE OF vim_delim_entr_tl
         WITH DEFAULT KEY INITIAL SIZE 10,
        collapsed_mkeys_safe TYPE STANDARD TABLE
         OF vim_collapsed_mkeys_tl WITH DEFAULT KEY INITIAL SIZE 1,
        merged_entr_safe TYPE STANDARD TABLE      "merged entries
         OF vim_merged_entr_tl WITH DEFAULT KEY INITIAL SIZE 1.

  CHECK x_header-delmdtflag NE space.
* check if dates entered properly
  IF ( <vim_new_begdate> is initial OR
     <vim_enddate_mask> EQ vim_init_date ) AND
     status-mode EQ list_bild.         "only on list screen
    MESSAGE e127(sv)."Bitte den Gültigkeitsbereich eingrenzen
  ENDIF.
* process delimitation
  IF x_header-clidep NE space.
    MOVE sy-mandt TO <client>.
  ENDIF.
  IF <xact> NE leer AND neuer NE 'J' AND status-delete NE geloescht AND
     ( status-action NE kopieren AND vim_special_mode EQ space OR
       vim_special_mode EQ vim_delimit ).
    READ TABLE total WITH KEY <vim_xextract_key> BINARY SEARCH.
    CHECK sy-subrc EQ 0.
  ELSE. "entry is new (input, copy, undelete, reset, replace, upgrade)
    IF status-mode EQ list_bild.           "only on list screen
      IF x_header-delmdtflag EQ 'E' AND    "end date is key field
         <vim_new_begdate> GT <vim_enddate_mask>.
        MESSAGE e045(sv). "Bitte ein Beginn-Datum angeben, das vor dem
      ELSEIF x_header-delmdtflag EQ 'B' AND    "begin date is key field
             <vim_new_begdate> LT <vim_enddate_mask>.
        MESSAGE e046(sv). "Bitte ein Ende-Datum angeben, das nach dem be
      ENDIF.
    ENDIF.
    LOOP AT total.
      CHECK <vim_tot_mkey_beforex> EQ <vim_f1_beforex> AND
            ( vim_mkey_after_exists EQ space OR
              <vim_tot_mkey_afterx> EQ <vim_f1_afterx> ).
*      CHECK <vim_tot_mkey_before> EQ <vim_f1_before> AND
*            ( vim_mkey_after_exists EQ space OR
*              <vim_tot_mkey_after> EQ <vim_f1_after> ).
      MOVE 'X' TO entries_exist.
      EXIT.
    ENDLOOP.
    CHECK entries_exist NE space.
    MOVE: <table2_x> TO <vim_xtotal>,
          <vim_enddate_mask> TO <vim_enddate>.
    IF x_header-delmdtflag EQ 'E'.
      MOVE highdate TO <vim_begdate>.
    ELSE.
      CLEAR <vim_begdate>.
    ENDIF.
  ENDIF.
  CHECK <vim_new_begdate> NE <vim_begdate>.
* check allowed keyranges
  IF x_header-customauth CO sap_cust_ctrl_classes OR
     vim_ale_keyspec_check NE space.
    PERFORM check_allowed_keyranges.
  ENDIF.
  IF x_header-delmdtflag EQ 'E'.       "end date is key field
    IF <vim_new_begdate> GT <vim_enddate>.
      MESSAGE e045(sv). "Bitte ein Beginn-Datum angeben, das vor dem End
    ELSEIF <vim_new_begdate> LT <vim_begdate>.
      PERFORM temp_delim_del_overld_entries USING <vim_new_begdate>
                                                  <vim_enddate>.
    ELSE.
      <vim_enddate> = <vim_new_begdate> - 1.
      IF x_header-texttbexst NE space AND
         x_header-ptfrkyexst EQ space.
        PERFORM vim_temp_delim_texttab
          USING <vim_enddate_mask> <vim_xextract_key>. "SW Texttransl
        IF x_header-bastab NE space.
          MOVE: <vim_enddate> TO <vim_text_enddate>,
                neuer_eintrag TO <action_text>.
        ENDIF.
      ENDIF.
      READ TABLE total WITH KEY <vim_xtotal_key> BINARY SEARCH
                                                TRANSPORTING NO FIELDS.
*      READ TABLE total WITH KEY <vim_total_key> BINARY SEARCH
*                                                TRANSPORTING NO FIELDS.
      IF sy-subrc NE 0.
        <action> = neuer_eintrag.
        <mark> = nicht_markiert.       "new entries are never marked
        INSERT total INDEX sy-tabix.
      ELSE.
* entry MUST be a deleted one
        MESSAGE w121(sv). "Gelöschter Eintrag wird zurückgeholt und ggf.
        PERFORM temp_delim_determine_action USING sy-tabix act act_txt.
        <action> = act.
        IF x_header-bastab NE space AND x_header-texttbexst NE space.
          <action_text> = act_txt.
        ENDIF.
        MODIFY total INDEX sy-tabix.
      ENDIF.
    ENDIF.
  ELSE.                                "begin date is key field
    IF <vim_new_begdate> LT <vim_enddate>.
      MESSAGE e046(sv). "Bitte ein Ende-Datum angeben, das nach dem begi
    ELSEIF <vim_new_begdate> GT <vim_begdate>.
      PERFORM temp_delim_del_overld_entries USING <vim_new_begdate>
                                                  <vim_enddate>.
    ELSE.
      <vim_begdate> = <vim_new_begdate>.
      IF x_header-bastab NE space AND x_header-texttbexst NE space AND
         x_header-ptfrkyexst EQ space.
        IF <action_text> EQ original.
          MOVE aendern   TO <action_text>.
        ENDIF.
      ENDIF.
      IF <action> EQ original.
        <action> = aendern.
      ENDIF.
      MODIFY total INDEX sy-tabix.
      total = extract.
      <vim_enddate> = <vim_new_begdate> + 1.
      <action> = <xact> = neuer_eintrag.
      IF x_header-bastab NE space AND x_header-texttbexst NE space AND
         x_header-ptfrkyexst EQ space.
        MOVE: <vim_enddate> TO <vim_text_enddate>,
              neuer_eintrag TO <action_text>,
              neuer_eintrag TO <xact_text>.
      ENDIF.
      anz_pages = sy-tabix + 1.
      INSERT total INDEX anz_pages.
    ENDIF.
  ENDIF.                               "x_header-delmdtflag eq 'E'
  IF temporal_delimitation_happened EQ 'N'.
    CLEAR temporal_delimitation_happened. EXIT.
  ENDIF.
  IF temporal_delimitation_happened NE 'G'.
    MOVE sy-tabix TO anz_pages.
    LOOP AT vim_delim_entries WHERE index1 GE anz_pages.
      ADD 1 TO vim_delim_entries-index1.
      MODIFY vim_delim_entries.
    ENDLOOP.
    MOVE: anz_pages TO vim_delim_entries-index1,
          nextline  TO vim_delim_entries-index2,
          space     TO vim_delim_entries-index3.
    APPEND vim_delim_entries.
    MOVE 'X' TO temporal_delimitation_happened.
  ENDIF.
  IF <xact> NE leer AND neuer NE 'J' AND status-delete NE geloescht AND
     ( status-action NE kopieren AND vim_special_mode EQ space OR
       vim_special_mode EQ vim_delimit ).
    IF x_header-adrnbrflag NE space.
* if entry contains address number: ask if new address is wanted
      CALL FUNCTION 'POPUP_TO_DECIDE'
           EXPORTING
                defaultoption = '1'
                titel         = svim_text_037
                textline1     = svim_text_038
                textline2     = svim_text_039
                textline3     = svim_text_040
                text_option1  = svim_text_041
                text_option2  = svim_text_042
           IMPORTING
                answer        = answer.
      CASE answer.
        WHEN 'A'. EXIT.
        WHEN '2'.                      "clear old address number
          CLEAR <address_number>.
        WHEN OTHERS.                   "copy old address
* not yet possible
      ENDCASE.
    ENDIF.
    IF x_header-guidflag <> space.
      PERFORM vim_make_guid USING space.
    ENDIF.
* if user exit for hidden fields exists: perform exit routine
    IF x_header-frm_h_flds NE space.
      PERFORM (x_header-frm_h_flds) IN PROGRAM.
    ENDIF.
* if user exit for new entries exists: perform exit routine
    IF x_header-frm_on_new NE space.
      PERFORM (x_header-frm_on_new) IN PROGRAM.
    ENDIF.
* if entry contains address number: call address maintain
    IF x_header-adrnbrflag NE space AND answer EQ '2'.
      PERFORM address_maintain.
    ENDIF.
* if user exit after delimitation exists: perform exit routine
    IF x_header-frm_af_dlm NE space.
      delim_entr_safe = vim_delim_entries[].
      collapsed_mkeys_safe = vim_collapsed_mainkeys[].
      merged_entr_safe = vim_merged_entries[].
      IF status-mode EQ detail_bild.
        ok_code_safe = ok_code. function_safe = function.
      ENDIF.
      PERFORM (x_header-frm_af_dlm) IN PROGRAM.
      MOVE delim_entr_safe TO vim_delim_entries[].
      MOVE collapsed_mkeys_safe TO vim_collapsed_mainkeys[].
      MOVE merged_entr_safe TO vim_merged_entries[].
      IF status-mode EQ detail_bild.
        MOVE: ok_code_safe TO ok_code, function_safe TO function.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM.                               "temp_delimitation

*&--------------------------------------------------------------------*
*&      Form  TEMP_DELIM_DETERMINE_ACTION                             *
*&--------------------------------------------------------------------*
* determine action flag                                               *
*&--------------------------------------------------------------------*
FORM TEMP_DELIM_DETERMINE_ACTION USING VALUE(TDDA_INDEX) TDDA_ACT
                                                         TDDA_ACT_TXT.
  LOCAL: TOTAL.
  READ TABLE TOTAL INDEX TDDA_INDEX.
  IF <ACTION> EQ NEUER_GELOESCHT.
    TDDA_ACT = NEUER_EINTRAG.
  ELSE.
    TDDA_ACT = AENDERN.
  ENDIF.
  IF X_HEADER-BASTAB NE SPACE AND X_HEADER-TEXTTBEXST NE SPACE.
    IF <ACTION_TEXT> EQ NEUER_GELOESCHT.
      TDDA_ACT_TXT = NEUER_EINTRAG.
    ELSE.
      TDDA_ACT_TXT = AENDERN.
    ENDIF.
  ENDIF.
ENDFORM.                               "temp_delim_determine_action

*&--------------------------------------------------------------------*
*&      Form CONSISTENCY_PRT_FRKY_FIELDS                              *
*&--------------------------------------------------------------------*
* make sure, that part. forkey table fields are consistent            *
*&--------------------------------------------------------------------*
FORM consistency_prt_frky_fields
                               USING value(cpff_alert) LIKE tvdir-flag.
  DATA:  prtfky_field_changed(1) TYPE c, cur_mkey_found(1) TYPE c,
         count TYPE i, offs TYPE i,
         formname(19) TYPE c VALUE 'FILL_TEXTTAB_KEY_UC'.
  FIELD-SYMBOLS: <dummy1>.
  LOCAL: total, extract.

  CHECK status-action NE anzeigen.
  CHECK <status>-upd_flag NE space.
  MOVE: <f1_x> TO <vim_xtotal_key>,
        vim_date_mask TO <vim_enddate_mask>,
        <f1_x> TO <vim_h_mkey>,
*        <f1> TO <vim_mainkey_mask>,
        <vim_xtotal_key> TO <f1_x>.
*  vim_mainkey = <f1>.
  IF x_header-selection EQ space.
    LOOP AT total.
      CHECK <vim_xtotal_key> NE <f1_x> AND
            <vim_tot_mkey_beforex> EQ <vim_mkey_beforex> AND
            ( vim_mkey_after_exists EQ space OR
              <vim_tot_mkey_afterx> EQ <vim_mkey_afterx> ).
*      CHECK <vim_total_key> NE <f1> AND
*            <vim_tot_mkey_before> EQ <vim_mkey_before> AND
*            ( vim_mkey_after_exists EQ space OR
*              <vim_tot_mkey_after> EQ <vim_mkey_after> ).
      MOVE 99 TO count.
      EXIT.
    ENDLOOP.
  ELSE.
    MOVE 99 TO count.
  ENDIF.
  IF count EQ 99. "other entries for mainkey (may be) exist
* selections exist or
* prüfen: wurden Texte verändert ?????
* falls aktueller Text leer und hinzufügen --> text aus Extract nehmen
    IF vim_prtfky_assigned CO ' Y'.
* partial foreign key not assigned or VIM_PROCESS_ASSIGNS already
* processed
      CLEAR count.
      LOOP AT x_namtab WHERE prtfrkyfld NE space.
        CHECK x_namtab-readonly EQ space.
        IF vim_prtfky_assigned EQ space.
          IF x_header-bastab EQ space             "view
           OR x_header-texttbexst EQ space        "no texttable
           OR x_namtab-texttabfld EQ space.       "no texttabfield
* not a texttablefield in a table & texttable
            ASSIGN: COMPONENT x_namtab-viewfield OF STRUCTURE <table1>
*            ASSIGN <table1>+x_namtab-position(x_namtab-flength)
                    TO <vim_prtfky_wa>.
          ELSE.
            ASSIGN: COMPONENT x_namtab-viewfield
                     OF STRUCTURE <table1_text>
*            offs = x_namtab-position - x_header-tablen.
*            ASSIGN <table1_text>+offs(x_namtab-flength)
                     TO <vim_prtfky_wa>.
          ENDIF.
        ENDIF.
        IF x_header-bastab EQ space               "view
           OR x_header-texttbexst EQ space        "no texttable
           OR x_namtab-texttabfld EQ space.       "no texttabfield
          ASSIGN: COMPONENT x_namtab-viewfield
                   OF STRUCTURE <vim_total_struc>
                   TO <vim_prtfky_total>,
                  COMPONENT x_namtab-viewfield
                   OF STRUCTURE <vim_extract_struc>
                   TO  <vim_prtfky_extract>.
* not a texttablefield in a table & texttable
        ELSE.
          ASSIGN: COMPONENT x_namtab-viewfield
                    OF STRUCTURE <vim_tot_txt_struc>
                     TO <vim_prtfky_total>,
                    COMPONENT x_namtab-viewfield
                     OF STRUCTURE <vim_ext_txt_struc>
                     TO  <vim_prtfky_extract>.
        ENDIF.
*        ASSIGN: total+x_namtab-position(x_namtab-flength)
*                                 TO <vim_prtfky_total>,
*                extract+x_namtab-position(x_namtab-flength)
*                                 TO <vim_prtfky_extract>.
        CLEAR prtfky_field_changed.
        IF status-action EQ hinzufuegen OR status-action EQ kopieren OR
           vim_special_mode EQ vim_upgrade.
          CLEAR cur_mkey_found.
          LOOP AT total.               "            current mainkey.
            CHECK <vim_tot_mkey_beforex> EQ <vim_mkey_beforex> AND
                  ( vim_mkey_after_exists EQ space OR
                    <vim_tot_mkey_afterx> EQ <vim_mkey_afterx> ).
*            CHECK <vim_tot_mkey_before> EQ <vim_mkey_before> AND
*                  ( vim_mkey_after_exists EQ space OR
*                    <vim_tot_mkey_after> EQ <vim_mkey_after> ).
            cur_mkey_found = 'X'. EXIT.
          ENDLOOP.
          IF cur_mkey_found NE space.
            IF <vim_prtfky_wa> IS INITIAL. "no entry -> use exist. value
              MOVE <vim_prtfky_total> TO <vim_prtfky_wa>.
              TRANSLATE <status>-upd_flag USING 'EY'.
              IF <status>-upd_flag EQ 'Y'.
                PERFORM (formname) IN PROGRAM (sy-repid)
                                   USING <table1> <table1_text>.
              ENDIF.
            ELSEIF <vim_prtfky_wa> NE <vim_prtfky_total>.
              MOVE 'X' TO prtfky_field_changed.
            ENDIF.
          ENDIF.
        ELSEIF <vim_prtfky_wa> NE <vim_prtfky_extract>.
          MOVE 'X' TO prtfky_field_changed.
        ENDIF.
        ADD 1 TO count.
      ENDLOOP.
      IF count EQ 1.
        MOVE 'X' TO vim_prtfky_assigned.
      ENDIF.
    ELSE.     " vim_prtfky_assigned = 'X'
      IF status-action EQ hinzufuegen OR status-action EQ kopieren OR
         vim_special_mode EQ vim_upgrade.
        LOOP AT total.                 "            current mainkey.
          CHECK <vim_tot_mkey_beforex> EQ <vim_mkey_beforex> AND
                ( vim_mkey_after_exists EQ space OR
                  <vim_tot_mkey_afterx> EQ <vim_mkey_afterx> ).
*          CHECK <vim_tot_mkey_before> EQ <vim_mkey_before> AND
*                ( vim_mkey_after_exists EQ space OR
*                  <vim_tot_mkey_after> EQ <vim_mkey_after> ).
          cur_mkey_found = 'X'. EXIT.
        ENDLOOP.
        IF cur_mkey_found NE space.
          IF <vim_prtfky_wa> IS INITIAL. "no entry -> use exist. value
            MOVE <vim_prtfky_total> TO <vim_prtfky_wa>.
            TRANSLATE <status>-upd_flag USING 'EY'.
            IF <status>-upd_flag EQ 'Y'.
              PERFORM (formname) IN PROGRAM (sy-repid)
                                 USING <table1> <table1_text>.
            ENDIF.
          ELSEIF <vim_prtfky_wa> NE <vim_prtfky_total>.
            MOVE 'X' TO prtfky_field_changed.
          ENDIF.
        ENDIF.
      ELSEIF <vim_prtfky_wa> NE <vim_prtfky_extract>.
        MOVE 'X' TO prtfky_field_changed.
      ENDIF.
    ENDIF.
*  if verändert.
    IF prtfky_field_changed NE space.
      IF cpff_alert NE space.
        sy-msgv1 = svim_text_030.
        sy-msgv2 = <vim_mainkey_mask>. TRANSLATE sy-msgv2 USING '+ '.
        IF x_header-clidep NE space.
          SHIFT sy-msgv2 BY client_length PLACES.
        ENDIF.
        count = strlen( sy-msgv2 ).
        ASSIGN sy-msgv2(count) TO <dummy1>.
        REPLACE '&' WITH <dummy1> INTO sy-msgv1.
        CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
          EXPORTING
            diagnosetext1  = svim_text_031
            diagnosetext2  = svim_text_032
            diagnosetext3  = svim_text_033
            textline1      = svim_text_034
            textline2      = svim_text_035
            titel          = sy-msgv1
            cancel_display = space
          IMPORTING
            answer         = answer.
      ELSE.
        answer = 'J'.
      ENDIF.
      IF answer EQ 'A'.
        answer = 'N'.
      ENDIF.
      CASE answer.
*       WHEN 'A'. "cancel --> what to do ? same as NO ?
        WHEN 'J'.                      "yes, change all
          IF status-action EQ hinzufuegen OR status-action EQ kopieren.
            PERFORM check_key.
          ELSEIF ( x_header-customauth CO sap_cust_ctrl_classes OR
                   vim_ale_keyspec_check NE space ).
            PERFORM check_allowed_keyranges.
          ENDIF.
          LOOP AT total.
            CHECK <vim_xtotal_key> NE <f1_x> AND
                  <vim_tot_mkey_beforex> EQ <vim_mkey_beforex> AND
                  ( vim_mkey_after_exists EQ space OR
                    <vim_tot_mkey_afterx> EQ <vim_mkey_afterx> ).
*            CHECK <vim_total_key> NE <f1> AND
*                  <vim_tot_mkey_before> EQ <vim_mkey_before> AND
*                  ( vim_mkey_after_exists EQ space OR
*                    <vim_tot_mkey_after> EQ <vim_mkey_after> ).
*         move der entsprech. Felder --> gemäß X_NAMTAB, zum PBO füllen
            IF vim_prtfky_assigned CO ' Y'.
              LOOP AT x_namtab WHERE prtfrkyfld NE space.
                IF vim_prtfky_assigned EQ space.
                  IF x_header-bastab EQ space          "view
                   OR x_header-texttbexst EQ space     "no texttable
                   OR x_namtab-texttabfld EQ space.    "no texttabfield
* not a texttablefield in a table & texttable
                    ASSIGN: COMPONENT x_namtab-viewfield
                       OF STRUCTURE <table1>
                       TO <vim_prtfky_wa>,
                     COMPONENT x_namtab-viewfield
                      OF STRUCTURE <vim_total_struc>
                      TO <vim_prtfky_total>.
                  ELSE.
                    ASSIGN: COMPONENT x_namtab-viewfield
                             OF STRUCTURE <table1_text>
                             TO <vim_prtfky_wa>,
                            COMPONENT x_namtab-viewfield
                             OF STRUCTURE <vim_tot_txt_struc>
                             TO <vim_prtfky_total>.
                  ENDIF.
                ENDIF.
*                  IF x_header-bastab EQ space OR
*                     x_header-texttbexst EQ space OR
*                     x_namtab-texttabfld EQ space.
*                    ASSIGN <table1>+x_namtab-position(x_namtab-flength)
*                                              TO <vim_prtfky_wa>.
*                  ELSE.
*                    offs = x_namtab-position - x_header-tablen.
*                    ASSIGN <table1_text>+offs(x_namtab-flength)
*                                              TO <vim_prtfky_wa>.
*                  ENDIF.
*                ENDIF.
*                ASSIGN total+x_namtab-position(x_namtab-flength)
*                                         TO <vim_prtfky_total>.
                MOVE <vim_prtfky_wa> TO <vim_prtfky_total>.
              ENDLOOP.
            ELSE.
              MOVE <vim_prtfky_wa> TO <vim_prtfky_total>.
            ENDIF.
            MODIFY total.
            READ TABLE extract WITH KEY <vim_xtotal_key>.
            IF sy-subrc EQ 0.
              MOVE total TO extract.
              MODIFY extract INDEX sy-tabix.
            ENDIF.
          ENDLOOP.
          vim_prt_fky_flds_updated = 'X'.
        WHEN 'N'.
*       text aus Extract bzw. Total (hinzuf.) nehmen
          IF vim_prtfky_assigned CO ' Y'.
            LOOP AT x_namtab WHERE prtfrkyfld NE space.
              IF vim_prtfky_assigned EQ space.
                IF x_header-bastab EQ space             "view
                 OR x_header-texttbexst EQ space        "no texttable
               OR x_namtab-texttabfld EQ space.       "no texttabfield
* not a texttablefield in a table & texttable
                  ASSIGN: COMPONENT x_namtab-viewfield
                       OF STRUCTURE <table1>
                       TO <vim_prtfky_wa>,
                     COMPONENT x_namtab-viewfield
                      OF STRUCTURE <vim_total_struc>
                      TO <vim_prtfky_total>,
                     COMPONENT x_namtab-viewfield
                      OF STRUCTURE <vim_extract_struc>
                      TO  <vim_prtfky_extract>.
                ELSE.
                  ASSIGN: COMPONENT x_namtab-viewfield
                           OF STRUCTURE <table1_text>
                           TO <vim_prtfky_wa>,
                          COMPONENT x_namtab-viewfield
                           OF STRUCTURE <vim_tot_txt_struc>
                           TO <vim_prtfky_total>,
                          COMPONENT x_namtab-viewfield
                           OF STRUCTURE <vim_ext_txt_struc>
                           TO  <vim_prtfky_extract>.
                ENDIF.
              ENDIF.
*                IF x_header-bastab EQ space OR
*                   x_header-texttbexst EQ space OR
*                   x_namtab-texttabfld EQ space.
*                  ASSIGN <table1>+x_namtab-position(x_namtab-flength)
*                                            TO <vim_prtfky_wa>.
*                ELSE.
*                  offs = x_namtab-position - x_header-tablen.
*                  ASSIGN <table1_text>+offs(x_namtab-flength)
*                                            TO <vim_prtfky_wa>.
*                ENDIF.
*              ENDIF.
*              ASSIGN: total+x_namtab-position(x_namtab-flength)
*                                       TO <vim_prtfky_total>,
*                      extract+x_namtab-position(x_namtab-flength)
*                                       TO <vim_prtfky_extract>.
              IF status-action EQ hinzufuegen OR
                 status-action EQ kopieren OR
                 vim_special_mode EQ vim_upgrade.
                MOVE <vim_prtfky_total> TO <vim_prtfky_wa>.
              ELSE.
                MOVE <vim_prtfky_extract> TO <vim_prtfky_wa>.
              ENDIF.
            ENDLOOP.
          ELSE.
            IF status-action EQ hinzufuegen OR
               status-action EQ kopieren OR
               vim_special_mode EQ vim_upgrade.
              MOVE <vim_prtfky_total> TO <vim_prtfky_wa>.
            ELSE.
              MOVE <vim_prtfky_extract> TO <vim_prtfky_wa>.
            ENDIF.
          ENDIF.
          IF ( x_header-bastab EQ space OR  "view or no texttab and..
               x_header-texttbexst EQ space ) AND
             <table1_x> EQ <vim_xextract>.     "..no change
            CLEAR <status>-upd_flag.
          ELSEIF x_header-bastab NE space AND "bastab with texttab and
                 x_header-texttbexst NE space AND
                 <table1_xtext> EQ <vim_xextract_text>.
* no change of text
            TRANSLATE <status>-upd_flag USING 'XET '.
          ENDIF.
      ENDCASE.
    ENDIF. "vim_prtfky_field_changed ne space
  ENDIF. "COUNT eq 99   other entries for mainkey (may be) exist
ENDFORM.                               "consistency_prt_frky_fields

*&--------------------------------------------------------------------*
*&      Form DELIMITATION                                             *
*&--------------------------------------------------------------------*
* process temporal delimitation of marked EXTRACT entries             *
*&--------------------------------------------------------------------*
FORM DELIMITATION.
  LOCAL: <TABLE1>, <TABLE1_TEXT>.
  DATA: D_RC(1) TYPE C.
* request date to delimit
  CALL FUNCTION 'POPUP_GET_VALUES'
       EXPORTING
            POPUP_TITLE     = SVIM_TEXT_036
            START_COLUMN    = '10'
            START_ROW       = '10'
       IMPORTING
            RETURNCODE      = D_RC
       TABLES
            FIELDS          = VIM_SVAL_TAB
       EXCEPTIONS
            ERROR_IN_FIELDS = 01.
  IF SY-SUBRC NE 0. RAISE GET_VALUES_ERROR. ENDIF.
  CHECK D_RC NE 'A'.
  READ TABLE VIM_SVAL_TAB INDEX 1.
  VIM_SPECIAL_MODE = VIM_DELIMIT.
  CLEAR: COUNTER, VIM_OLD_VIEWKEY.
  TRANSLATE VIM_NO_MAINKEY_EXISTS USING VIM_NO_MKEY_NOT_PROCSD_PATT.

* Event 28 AFter Entering Delimitation Date                   "CG 7/2001
  if x_header-frm_af_edd NE SPACE.
    PERFORM (x_header-frm_af_edd) IN PROGRAM (x_header-fpoolname).
  endif.

  PERFORM KOPIERE.
  IF TEMPORAL_DELIMITATION_HAPPENED NE SPACE.
    REFRESH VIM_DELIM_ENTRIES. CLEAR TEMPORAL_DELIMITATION_HAPPENED.
  ENDIF.
  CLEAR: VIM_SPECIAL_MODE.
ENDFORM.                               "delimitation

*&--------------------------------------------------------------------*
*&      Form  TIME_DEPENDENT_DISPLAY_MODIF.                           *
*&--------------------------------------------------------------------*
* process display modification (collapse/expand)                      *
*&--------------------------------------------------------------------*
FORM time_dependent_display_modif.
  DATA: ex_ix TYPE i, modif_mode(1) TYPE c, first(1) TYPE c,
        ex_begin TYPE i, ex_end TYPE i, key_safe TYPE vrsdat1000,
        to_ix TYPE i, rc like sy-subrc.
  READ TABLE extract INDEX nextline.
  key_safe = <vim_xextract_key>.
  CLEAR vim_mainkey.
  TRANSLATE vim_no_mainkey_exists USING vim_no_mkey_not_procsd_patt.
  LOOP AT extract.
    ex_ix = sy-tabix.
    IF vim_no_mainkey_exists EQ vim_no_mkey_not_procsd OR
       <vim_ext_mkey_beforex> NE <vim_mkey_beforex> OR
       ( vim_mkey_after_exists NE space AND
         <vim_ext_mkey_afterx> NE <vim_mkey_afterx> ).
*       <vim_ext_mkey_before> NE <vim_mkey_before> OR
*       ( vim_mkey_after_exists NE space AND
*         <vim_ext_mkey_after> NE <vim_mkey_after> ).
      ex_end = sy-tabix - 1.
      IF modif_mode EQ 'C'.
        PERFORM collapse USING ex_begin ex_end.
        modif_mode = 'X'.
      ENDIF.                           "modif_mode eq collapse
      ex_begin = ex_ix.
      <vim_h_mkey> = <vim_xextract_key>.
*      vim_mainkey = <vim_extract_key>.
      TRANSLATE vim_no_mainkey_exists USING vim_no_mkey_procsd_patt.
    ENDIF.                             "new mainkey in extract.
    CHECK <xmark> EQ markiert.
    READ TABLE total WITH KEY <vim_xextract_key> BINARY SEARCH.
    <mark> = nicht_markiert. SUBTRACT 1 FROM mark_total.
    MODIFY total INDEX sy-tabix.
    SUBTRACT 1 FROM mark_extract.
    IF modif_mode CO ' X'.
      rc = 4.
      LOOP AT vim_collapsed_mainkeys.
        check <vim_collapsed_mkey_bfx> = <vim_mkey_beforex>.
*      WHERE mkey_bf EQ <vim_mkey_before>.
        IF vim_mkey_after_exists NE space.
          CHECK <vim_collapsed_key_afx> EQ <vim_mkey_afterx>.
        ENDIF.
        DELETE vim_collapsed_mainkeys.
        clear rc.
        EXIT.
      ENDLOOP.
      IF rc EQ 0.
* entry in collapsed mode -> expand
        modif_mode = 'E'.
      ELSE.
* entry in expanded mode -> collapse
        modif_mode = 'C'.
      ENDIF.
    ENDIF.
    IF modif_mode = 'E'.
      CLEAR vim_delim_entries.
      vim_delim_entries-index3 = ex_ix.
      APPEND vim_delim_entries.
      CLEAR vim_delim_entries-index3.
      vim_delim_entries-index_corr = 'X'.
      LOOP AT total.
        CHECK <vim_tot_mkey_beforex> EQ <vim_mkey_beforex> AND
              ( vim_mkey_after_exists EQ space OR
                <vim_tot_mkey_afterx> EQ <vim_mkey_afterx> ).
*        CHECK <vim_tot_mkey_before> EQ <vim_mkey_before> AND
*              ( vim_mkey_after_exists EQ space OR
*                <vim_tot_mkey_after> EQ <vim_mkey_after> ).
        to_ix = sy-tabix.
        PERFORM select USING <status>-selected.
        CHECK sy-subrc EQ 0.
        vim_delim_entries-index1 = to_ix.
        vim_delim_entries-index2 = ex_ix.
        APPEND vim_delim_entries.
      ENDLOOP.
      modif_mode = 'X'.
    ENDIF.
  ENDLOOP.
  IF modif_mode EQ 'C'.
    CLEAR vim_delim_entries.
    PERFORM collapse USING ex_begin maxlines.
  ENDIF.
  PERFORM after_temporal_delimitation.
  <vim_xextract_key> = key_safe.
  READ TABLE extract WITH KEY <vim_ext_mkey_beforex>.
*  READ TABLE extract WITH KEY <vim_ext_mkey_before>.
  IF sy-subrc EQ 0.
    nextline = sy-tabix.
  ELSE.
    nextline = 1.
  ENDIF.
* ENDIF.
ENDFORM.                               "time_dependent_display_modif

*&--------------------------------------------------------------------*
*&      FORM COLLAPSE                                                 *
*&--------------------------------------------------------------------*
* collapse                                                            *
*&--------------------------------------------------------------------*
FORM collapse USING value(c_begin_ix) TYPE i value(c_end_ix) TYPE i.
  LOCAL: extract.
  DATA: first(1) TYPE c VALUE 'X', hf_ind TYPE i, hf_ind2 TYPE i,
        act_ix TYPE i.

  LOOP AT total.
    act_ix = sy-tabix.
    PERFORM select USING <status>-selected.
    CHECK sy-subrc EQ 0.
    CHECK <vim_tot_mkey_beforeX> EQ <vim_mkey_beforeX> AND
          ( vim_mkey_after_exists EQ space OR
            <vim_tot_mkey_afterx> EQ <vim_mkey_afterx> ).
*    CHECK <vim_tot_mkey_before> EQ <vim_mkey_before> AND
*          ( vim_mkey_after_exists EQ space OR
*            <vim_tot_mkey_after> EQ <vim_mkey_after> ).
    IF first NE space.
* Changed from XB. 12.06.02 BCEK060520/BCEK060521
      <vim_collapsed_keyx> = <vim_xtotal_key>.
*      vim_collapsed_mainkeys-mainkey = <vim_total_key>.
      if <vim_collapsed_mkey_bfx> ne <vim_tot_mkey_beforex>.
        <vim_collapsed_mkey_bfx> = <vim_tot_mkey_beforex>.
*      vim_collapsed_mainkeys-mkey_bf = <vim_tot_mkey_before>.
      endif.
      hf_ind = act_ix.
      CLEAR first.
    ENDIF.
* Changed from XB. 12.06.02 End.

    IF x_header-delmdtflag EQ 'E'.
      CHECK <vim_begdate> LE sy-datum AND
            <vim_enddate> GE sy-datum.
    ELSE.
      CHECK <vim_begdate> GE sy-datum AND
            <vim_enddate> LE sy-datum.
    ENDIF.
    <vim_collapsed_keyx> = <vim_xtotal_key>.
* changed from Xue. End.
    if <vim_collapsed_mkey_bfx> ne <vim_tot_mkey_beforex>.
      <vim_collapsed_mkey_bfx> = <vim_tot_mkey_beforex>.
    endif.
*    vim_collapsed_mainkeys-mainkey = <vim_total_key>.
*    <vim_collapsed_mkey_bfx> = <vim_tot_mkey_beforex>.
*    vim_collapsed_mainkeys-mkey_bf = <vim_tot_mkey_before>.

* Change from Xue. End.
    hf_ind = act_ix.
    EXIT.
  ENDLOOP.
  READ TABLE vim_collapsed_mainkeys
                                with key <vim_collapsed_keyx>
*                                WITH KEY vim_collapsed_mainkeys-mainkey
                                BINARY SEARCH
                                TRANSPORTING NO FIELDS.
  INSERT vim_collapsed_mainkeys INDEX sy-tabix.
  vim_delim_entries-index1 = hf_ind.
  vim_delim_entries-index2 = c_begin_ix.
  vim_delim_entries-index3 = c_begin_ix.
  vim_delim_entries-index_corr = 'X'.
  APPEND vim_delim_entries.
  hf_ind2 = c_begin_ix + 1.
  CLEAR vim_delim_entries.
  LOOP AT extract FROM hf_ind2 TO c_end_ix.
    vim_delim_entries-index3 = sy-tabix.
    APPEND vim_delim_entries.
  ENDLOOP.
  CLEAR vim_old_viewkey.
  TRANSLATE vim_no_mainkey_exists USING vim_no_mkey_not_procsd_patt.
ENDFORM.                               "collapse

*&--------------------------------------------------------------------*
*&      Form  BUILD_MAINKEY_TAB                                       *
*&--------------------------------------------------------------------*
* build mainkey tab for display modification - all parts              *
*&--------------------------------------------------------------------*
FORM BUILD_MAINKEY_TAB.
  PERFORM BUILD_MAINKEY_TAB_0.
  LOOP AT TOTAL.
    PERFORM BUILD_MAINKEY_TAB_1.
  ENDLOOP.
  PERFORM BUILD_MAINKEY_TAB_2.
ENDFORM.                               "build_mainkey_tab

*&--------------------------------------------------------------------*
*&      Form  BUILD_MAINKEY_TAB_0                                     *
*&--------------------------------------------------------------------*
* build mainkey tab for display modification - part one               *
*&--------------------------------------------------------------------*
FORM BUILD_MAINKEY_TAB_0.
  CLEAR: VIM_MAINKEY, VIM_MERGED_ENTRIES, VIM_COLLAPSED_MAINKEYS,
         <TABLE1>, VIM_MERGE_BEGIN, VIM_MERGE_END.
  TRANSLATE VIM_NO_MAINKEY_EXISTS USING VIM_NO_MKEY_NOT_PROCSD_PATT.
  REFRESH: VIM_COLLAPSED_MAINKEYS,
           VIM_MERGED_ENTRIES.
  VIM_COLL_MKEYS_FIRST = 'X'.
ENDFORM.                               "build_mainkey_tab_0

*&--------------------------------------------------------------------*
*&      Form  BUILD_MAINKEY_TAB_1                                     *
*&--------------------------------------------------------------------*
* build mainkey tab for display modification - part one               *
* merge identical entries for same mainkey into one entry
* assumptions: TOTAL is sorted ascending by <VIM_TOTAL_KEY>
*              Now, with unicode: sorted by <VIM_TOTAL_KEYX>
*&--------------------------------------------------------------------*
FORM build_mainkey_tab_1.
  DATA: date_safe TYPE d, date_safe_1 TYPE d, date_safe_2 TYPE d,
        date_safe_3 TYPE d.

  date_safe = <vim_begdate>.           "TOTAL
  date_safe_1 = <vim_enddate>.         "TOTAL
  date_safe_2 = <vim_new_begdate>.                          "<TABLE1>
  date_safe_3 = <vim_enddate_mask>.                         "<TABLE1>
  <vim_begdate> = <vim_enddate> = <vim_new_begdate> =
                  <vim_enddate_mask> = '99999999'.
  IF <vim_xtotal> NE <table1_x>.
    MOVE: date_safe   TO <vim_begdate>,
          date_safe_1 TO <vim_enddate>,
          date_safe_2 TO <vim_new_begdate>,
          date_safe_3 TO <vim_enddate_mask>.
    IF vim_no_mainkey_exists EQ vim_no_mkey_not_procsd OR
       <vim_tot_mkey_beforex> NE <vim_f1_beforex>.
*       <vim_tot_mkey_before> NE <vim_f1_before> OR
*       ( vim_mkey_after_exists NE space AND
*         <vim_tot_mkey_after> NE <vim_f1_after> ).
      IF vim_coll_mkeys_first EQ space.
        APPEND vim_collapsed_mainkeys.
        CLEAR vim_collapsed_mainkeys-log_key.
      ELSE.
        CLEAR vim_coll_mkeys_first.
      ENDIF.
      <vim_collapsed_keyx> = <vim_xtotal_key>.
      <vim_collapsed_mkey_bfx> = <vim_tot_mkey_beforex>.
*      vim_collapsed_mainkeys-mainkey = <vim_total_key>.
*      vim_collapsed_mainkeys-mkey_bf = <vim_tot_mkey_before>.
* If the position <= 0, the <vim_collapsed_mkey_bfx> shouldn't be
* assigned. XB am 27.03.2002 CSN int1332679 2002
    ELSEIF vim_mkey_after_exists NE space AND
         <vim_tot_mkey_afterx> NE <vim_f1_afterx>.
      IF vim_coll_mkeys_first EQ space.
        APPEND vim_collapsed_mainkeys.
        CLEAR vim_collapsed_mainkeys-log_key.
      ELSE.
        CLEAR vim_coll_mkeys_first.
      ENDIF.
      <vim_collapsed_keyx> = <vim_xtotal_key>.
*      <vim_collapsed_mkey_bfx> = <vim_tot_mkey_beforex>.
*      vim_collapsed_mainkeys-mainkey = <vim_total_key>.
*      vim_collapsed_mainkeys-mkey_bf = <vim_tot_mkey_before>.
    ELSE.
      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.
        <vim_collapsed_keyx> = <vim_xtotal_key>.
* change xb 12.06.02 begin--------------------------------------------
        if <vim_collapsed_mkey_bfx> NE <vim_tot_mkey_beforex>.
          <vim_collapsed_mkey_bfx> = <vim_tot_mkey_beforex>.
        endif.
* change xb 12.06.02 ***********************************************
*        vim_collapsed_mainkeys-mainkey = <vim_total_key>.
*        vim_collapsed_mainkeys-mkey_bf = <vim_tot_mkey_before>.
      ENDIF.
    ENDIF.
* end correction XB am 27.03.2002 CSN int1332679 2002
    <table1_x> = <vim_xtotal>.
    TRANSLATE vim_no_mainkey_exists USING vim_no_mkey_procsd_patt.
  ELSE.
    MOVE: date_safe   TO <vim_begdate>,
          date_safe_1 TO <vim_enddate>,
          date_safe_2 TO <vim_new_begdate>,
          date_safe_3 TO <vim_enddate_mask>.
    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.
      <vim_collapsed_keyx> = <vim_xtotal_key>.
* change xb 12.06.02 begin--------------------------------------------
      if <vim_collapsed_mkey_bfx> NE <vim_tot_mkey_beforex>.
        <vim_collapsed_mkey_bfx> = <vim_tot_mkey_beforex>.
      endif.
* change xb 12.06.02 ***********************************************

*      vim_collapsed_mainkeys-mainkey = <vim_total_key>.
*      vim_collapsed_mainkeys-mkey_bf = <vim_tot_mkey_before>.
    ENDIF.
  ENDIF.

ENDFORM.                               "build_mainkey_tab_1

*  INCLUDE LSVIMF0E .  " CHECK_IF_ENTRY_CAN_BE_MERGED

*&--------------------------------------------------------------------*
*&      Form  BUILD_MAINKEY_TAB_2                                     *
*&--------------------------------------------------------------------*
* build mainkey tab for display modification - part two               *
*&--------------------------------------------------------------------*
FORM BUILD_MAINKEY_TAB_2.
  APPEND VIM_COLLAPSED_MAINKEYS.
  MOVE: X_HEADER-VIEWNAME TO VIM_MEMORY_ID_1-VIEWNAME,
        SY-UNAME          TO VIM_MEMORY_ID_1-USER.
  EXPORT VIM_COLLAPSED_MAINKEYS TO MEMORY ID VIM_MEMORY_ID_1.
ENDFORM.                               "build_mainkey_tab_2

*&--------------------------------------------------------------------*
*&      Form  DELETE_FROM_MAINKEY_TAB                                 *
*&--------------------------------------------------------------------*
* delete entry from mainkey_tab.                                      *
*&--------------------------------------------------------------------*
FORM delete_from_mainkey_tab.
  LOOP AT vim_collapsed_mainkeys.
    CHECK <vim_h_coll_mkey>(x_header-keylen) = <f1_x>.
*  LOOP AT VIM_COLLAPSED_MAINKEYS WHERE MAINKEY EQ <F1>.
    DELETE vim_collapsed_mainkeys.
  ENDLOOP.
ENDFORM.                               "delete_from_mainkey_tab

*&--------------------------------------------------------------------*
*&      Form  CHECK_MODIFY_MERGED_ENTRIES                             *
*&--------------------------------------------------------------------*
* check if changed entry is to be merged and if so do it
* merging functionality has never been finished                       *
*&--------------------------------------------------------------------*
* <-- SY-SUBRC: 0 - ok, merge, others: don't merge                    *
*&--------------------------------------------------------------------*
*FORM CHECK_MODIFY_MERGED_ENTRIES USING VALUE(ENTRY_IN).
*  LOCAL: TOTAL, <TABLE1>.
*  DATA: REC TYPE I VALUE 8.
*  <F1> = ENTRY_IN. <VIM_ENDDATE_MASK> = VIM_DATE_MASK.
*  LOOP AT VIM_MERGED_ENTRIES WHERE NEW_KEY CP <F1>. "Achtung !!!!!!
*    READ TABLE TOTAL WITH KEY VIM_MERGED_ENTRIES-MERGED_KEY
*                     BINARY SEARCH.
*    IF SY-SUBRC EQ 0.
*      <TABLE1> = TOTAL.
*      <VIM_BEGDATE_MASK> = VIM_DATE_MASK.
*      <VIM_ENDDATE_MASK> = VIM_DATE_MASK.
*      IF ENTRY_IN CP <TABLE1>. "entry can be merged. "ACHTUNG!!
*        CLEAR REC.
*        TOTAL = ENTRY_IN.
*        VIM_MERGED_ENTRIES-MERGED_KEY = <VIM_TOTAL_KEY>.
*
*
*
*
*      ENDIF.
*    ENDIF.
*  ENDLOOP.
*ENDFORM.                               "check_modify_merged_entries

*---------------------------------------------------------------------*
*       FORM X_REFRESH_TCTRL                                          *
*---------------------------------------------------------------------*
* refresh table control (external call)                               *
*---------------------------------------------------------------------*
* VALUE(XE_NAME)   ---> name of view/table to process                 *
* VALUE(XE_SCREEN) ---> screen to refresh from                        *
*---------------------------------------------------------------------*
FORM X_REFRESH_TCTRL USING VALUE(XRT_NAME) LIKE VIMDESC-VIEWNAME
                           VALUE(XRT_SCREEN) LIKE VIMDESC-LISTE.
  DATA: XRT_CONTROL_NAME(16) TYPE C VALUE 'TCTRL_'.

  XRT_CONTROL_NAME+6 = XRT_NAME.
  REFRESH CONTROL XRT_CONTROL_NAME FROM SCREEN XRT_SCREEN.
ENDFORM.                               "x_refresh_tctrl

*---------------------------------------------------------------------*
*       FORM VIM_PROCESS_MESSAGE                                      *
*---------------------------------------------------------------------*
* process message depending on dialog mode                            *
*---------------------------------------------------------------------*
* VALUE(PM_ID)          ---> ID of message to send                    *
* VALUE(PM_ONLINE_TYPE) ---> message type used for online mode        *
* VALUE(PM_BATCH_TYPE)  ---> message type used for batch mode         *
* VALUE(PM_NBR)         ---> number of message to send                *
* VALUE(PM_V1)          ---> first mesage variable                    *
* VALUE(PM_V2)          ---> second mesage variable                   *
* VALUE(PM_V3)          ---> third mesage variable                    *
* VALUE(PM_V4)          ---> fourth mesage variable                   *
*---------------------------------------------------------------------*
FORM VIM_PROCESS_MESSAGE USING VALUE(PM_ID) LIKE SY-MSGID
                           VALUE(PM_ONLINE_TYPE) LIKE SY-MSGTY
                           VALUE(PM_BATCH_TYPE) LIKE SY-MSGTY
                           VALUE(PM_NBR)  LIKE SY-MSGNO
                           VALUE(PM_V1) LIKE SY-MSGV1
                           VALUE(PM_V2) LIKE SY-MSGV2
                           VALUE(PM_V3) LIKE SY-MSGV3
                           VALUE(PM_V4) LIKE SY-MSGV4.

  DATA: I_TYPE LIKE SPROT_U-SEVERITY, I_MSGTY LIKE SY-MSGTY,
        I_MSGNO LIKE SY-MSGNO,
        objtype TYPE ob_typ.

  IF VIM_NO_DIALOG NE SPACE.           "no dialog - write protocol
    I_TYPE = I_MSGTY = PM_BATCH_TYPE. I_MSGNO = PM_NBR.
    IF VIM_IMPORT_PROFILE = 'X'.        "Profilimport
      IF x_header-bastab EQ space.
        objtype = 'V'.
      ELSE.
        objtype = 'S'.
      ENDIF.
      CALL FUNCTION 'SCPR_PROT_DATA_WRITE'
          EXPORTING
            act_id           = VIM_ACTOPTS-ACT_ID
            bcset_id         = VIM_BCSET_ID
            objectname       = VIM_VIEW_NAME
*           tablename        = object
*           tabletype        = tabtype
            tablekey         = VIM_PROFILE_ERRORKEY
              MSGID            = PM_ID
              MSGTY            = I_TYPE
              MSGNO            = I_MSGNO
            var1             = PM_V1
            var2             = PM_V2
            var3             = PM_V3
            var4             = PM_V4
            objecttype       = objtype.
    ELSE.
      TRANSLATE I_TYPE USING 'I S '.
      CALL FUNCTION 'LCT_MESSAGE'
         EXPORTING
              IV_MSGID  = PM_ID
              IV_MSGTY  = I_TYPE
              IV_MSGNO  = I_MSGNO
              IV_MSGV1  = PM_V1
              IV_MSGV2  = PM_V2
              IV_MSGV3  = PM_V3
              IV_MSGV4  = PM_V4
              IV_DIALOG = SPACE.
    ENDIF.
    VIM_LAST_LOGGED_MESSAGE-ID = PM_ID.
    VIM_LAST_LOGGED_MESSAGE-TYPE = I_MSGTY.
    VIM_LAST_LOGGED_MESSAGE-NBR = PM_NBR.
    VIM_LAST_LOGGED_MESSAGE-V1 = PM_V1.
    VIM_LAST_LOGGED_MESSAGE-V2 = PM_V2.
    VIM_LAST_LOGGED_MESSAGE-V3 = PM_V3.
    VIM_LAST_LOGGED_MESSAGE-V4 = PM_V4.
    IF VIM_IMPORT_NO_MESSAGE EQ SPACE.
      MESSAGE ID PM_ID TYPE I_MSGTY NUMBER PM_NBR "to raise exception
                WITH PM_V1 PM_V2 PM_V3 PM_V4.
    ENDIF.
  ELSE.                                "with dialog - use pm_online_type
    I_MSGTY = PM_ONLINE_TYPE.
    MESSAGE ID PM_ID TYPE I_MSGTY NUMBER PM_NBR
              WITH PM_V1 PM_V2 PM_V3 PM_V4.
  ENDIF.                               "vim_no_dialog eq space
ENDFORM.                               "vim_process_message
*---------------------------------------------------------------------*
*       FORM VIM_BC_PROCESS_MESSAGE
*
*---------------------------------------------------------------------*
* process message depending on dialog mode                            *
*---------------------------------------------------------------------*
* VALUE(PM_ID)          ---> ID of message to send                    *
* VALUE(PM_ONLINE_TYPE) ---> message type used for online mode        *
* VALUE(PM_BATCH_TYPE)  ---> message type used for batch mode         *
* VALUE(PM_NBR)         ---> number of message to send                *
* VALUE(PM_V1)          ---> first mesage variable                    *
* VALUE(PM_V2)          ---> second mesage variable                   *
* VALUE(PM_V3)          ---> third mesage variable                    *
* VALUE(PM_V4)          ---> fourth mesage variable                   *
*---------------------------------------------------------------------*
FORM vim_bc_process_message USING value(pm_id) LIKE sy-msgid
                           value(pm_online_type) LIKE sy-msgty
                           value(pm_batch_type) LIKE sy-msgty
                           value(pm_nbr)  LIKE sy-msgno
                           value(pm_v1) LIKE sy-msgv1
                           value(pm_v2) LIKE sy-msgv2
                           value(pm_v3) LIKE sy-msgv3
                           value(pm_v4) LIKE sy-msgv4
                           value(objtype) TYPE ob_typ.

  DATA: i_type LIKE sprot_u-severity, i_msgty LIKE sy-msgty,
        i_msgno LIKE sy-msgno.

  i_type = i_msgty = pm_batch_type. i_msgno = pm_nbr.

  CALL FUNCTION 'SCPR_PROT_DATA_WRITE'
      EXPORTING
        act_id           = vim_actopts-act_id
        bcset_id         = vim_bcset_id
        objectname       = vim_view_name
*       tablename        = object
*       tabletype        = tabtype
        tablekey         = vim_profile_errorkey
        msgid            = pm_id
        msgty            = i_type
        msgno            = i_msgno
        var1             = pm_v1
        var2             = pm_v2
        var3             = pm_v3
        var4             = pm_v4
        objecttype       = objtype.
  vim_last_logged_message-id = pm_id.
  vim_last_logged_message-type = i_msgty.
  vim_last_logged_message-nbr = pm_nbr.
  vim_last_logged_message-v1 = pm_v1.
  vim_last_logged_message-v2 = pm_v2.
  vim_last_logged_message-v3 = pm_v3.
  vim_last_logged_message-v4 = pm_v4.
  IF vim_import_no_message EQ space.
    MESSAGE ID pm_id TYPE i_msgty NUMBER pm_nbr "to raise exception
              WITH pm_v1 pm_v2 pm_v3 pm_v4.
  ENDIF.
ENDFORM.                               "vim_bc_process_message

*---------------------------------------------------------------------*
*       FORM VIM_SET_IMP_RESULTS                                      *
*---------------------------------------------------------------------*
* (re)set result of import for current entry                          *
*---------------------------------------------------------------------*
* VALUE(VSIR_KEY)    ---> key of current entry                        *
* VALUE(VSIR_ACTION) ---> action happened to current entry            *
*                         - GELOESCHT OR UPDATE_GELOESCHT -> deleted  *
*                         - AENDERN                       -> updated  *
*                         - NEUER_EINTRAG                 -> inserted *
*                         - ORIGINAL                      -> unchanged*
*                         - SLCTR_IMP_ERROR               -> error    *
*---------------------------------------------------------------------*
FORM vim_set_imp_results USING value(vsir_key)
                               value(vsir_action) LIKE tvdir-flag.
  DATA: vsir_xkey TYPE vim_tabkey_c, vsir_xkeylen TYPE i,
        vsir_rc TYPE i,
        vsir_ix TYPE i.

  PERFORM vim_set_impres_header.
  PERFORM vim_convert_tabkey USING vsir_key vsir_xkey vsir_xkeylen.
  imp_results-tabkey = vsir_xkey.
  READ TABLE imp_results WITH KEY objtab = imp_results-objtab
                                  tabkey = imp_results-tabkey.
  vsir_rc = sy-subrc. vsir_ix = sy-tabix.
  CLEAR imp_results-import.
  CASE vsir_action.
    WHEN geloescht OR update_geloescht.
      imp_results-import-deleted = 1.
    WHEN aendern.
      imp_results-import-updated = 1.
    WHEN neuer_eintrag.
      imp_results-import-inserted = 1.
    WHEN original.
      imp_results-import-unchanged = 1.
    WHEN OTHERS.
      imp_results-import-errors = 1.
  ENDCASE.
  IF vsir_rc NE 0.
    APPEND imp_results.
  ELSE.
    MODIFY imp_results INDEX vsir_ix.
  ENDIF.
ENDFORM.                               "vim_set_imp_reults

*---------------------------------------------------------------------*
*       FORM VIM_SINGLE_ENTRY_FILL_SELLIST                            *
*---------------------------------------------------------------------*
* fill sellist in case of single entry maintenance                    *
*---------------------------------------------------------------------*
FORM vim_single_entry_fill_sellist.
  DATA: countx TYPE i, nam_ix TYPE i.
  FIELD-SYMBOLS: <h1>.

  LOOP AT x_namtab WHERE keyflag NE space AND texttabfld EQ space.
    CHECK x_header-clidep EQ space OR sy-tabix GT 1.
    nam_ix = sy-tabix.
    assign component x_namtab-viewfield of structure <table1> to <h1>.
*    ASSIGN <TABLE1>+X_NAMTAB-POSITION(X_NAMTAB-FLENGTH) TO <H1>.
    READ TABLE dpl_sellist WITH KEY viewfield = x_namtab-viewfield
                                    operator  = 'EQ'
                                    negation  = space.
    IF sy-subrc NE 0.
      CLEAR dpl_sellist.
      dpl_sellist-viewfield = x_namtab-viewfield.
      dpl_sellist-operator  = 'EQ'.
      dpl_sellist-and_or    = 'AND'.
      dpl_sellist-tabix     = nam_ix.
      APPEND dpl_sellist.
    ENDIF.
    countx = sy-tabix. CLEAR dpl_sellist-converted.
    dpl_sellist-ddic = 'S'. CLEAR dpl_sellist-value.
    CALL FUNCTION 'VIEW_CONVERSION_OUTPUT'
         EXPORTING
              value_intern = <h1>
              tabname      = x_header-maintview
              fieldname    = x_namtab-viewfield
*              inttype      = x_namtab-inttype
*              datatype     = x_namtab-datatype
*              decimals     = x_namtab-decimals
*              convexit     = x_namtab-convexit
*              sign         = x_namtab-sign
              outputlen    = x_namtab-outputlen
              intlen       = x_namtab-flength
         IMPORTING
              value_extern = dpl_sellist-value.
    IF dpl_sellist-value EQ space.
      dpl_sellist-initial = 'X'.
    ELSE.
      CLEAR dpl_sellist-initial.
    ENDIF.
    MODIFY dpl_sellist INDEX countx.
    x_namtab-readonly = 'S'. MODIFY x_namtab.
  ENDLOOP.
  ASSIGN dpl_sellist[] TO <vim_ck_sellist>.
  x_header-subsetflag = x_header-selection = 'X'.
  MODIFY x_header INDEX 1.
  PERFORM init_subset_keyfields.
ENDFORM.                               "vim_single_entry_fill_sellist

*---------------------------------------------------------------------*
*       FORM UPDATE_STATUS                                            *
*---------------------------------------------------------------------*
FORM UPDATE_STATUS.
  MOVE: STATUS-DATA TO <STATUS>-ST_DATA,
        STATUS-MODE TO <STATUS>-ST_MODE,
        STATUS-DELETE TO <STATUS>-ST_DELETE,
        STATUS-ACTION TO <STATUS>-ST_ACTION,
        TITLE         TO <STATUS>-TITLE,
*       L             TO <STATUS>-CUR_LINE,
        FIRSTLINE     TO <STATUS>-FIRSTLINE,
        MAXLINES      TO <STATUS>-MAXLINES,
        F             TO <STATUS>-CUR_FIELD,
        O             TO <STATUS>-CUR_OFFSET,
        MARK_EXTRACT  TO <STATUS>-MK_XT,
        MARK_TOTAL    TO <STATUS>-MK_TO,
        FUNCTION      TO <STATUS>-FCODE.
  IF L EQ 0.
    MOVE 1 TO <STATUS>-CUR_LINE.
  ELSE.
    MOVE L TO <STATUS>-CUR_LINE.
  ENDIF.
ENDFORM.                               "UPDATE_STATUS

*---------------------------------------------------------------------*
*       FORM SHOW_FUNCTION_DOCU                                       *
*---------------------------------------------------------------------*
FORM SHOW_FUNCTION_DOCU.
  CALL FUNCTION 'IWB_HTML_HELP_OBJECT_SHOW'
       EXPORTING
*         DEVCLASS                    =
*         TCODE                       =
            PROGRAM                     = VIM_DOCU_PROG
*         DYNPRONR                    =
            EXTENSION                   = VIM_DOCU_EXTENSION
*    IMPORTING
*         ACTION                      =
       EXCEPTIONS
            OBJECT_NOT_FOUND            = 1
            RFC_ERROR                   = 2
            NO_PROFIL_PARAMETER         = 3
            IMPORT_PARAMETER_IS_INVALID = 4
            OTHERS                      = 5.

* CALL FUNCTION 'DSYS_SHOW'
*      EXPORTING
**          APPLICATION        = 'SO70'
*           DOKCLASS           = 'WINH'
**          DOKLANGU           = SY-LANGU
*           DOKNAME            = 'CATAB.HLP'
*           DOKTITLE           = ' '
*           HOMETEXT           = ' '
*           OUTLINE            = ' '
*           VIEWNAME           = 'STANDARD'
*           Z_ORIGINAL_OUTLINE = ' '
*           CALLED_FROM_SO70   = ' '
*      IMPORTING
*           APPL               =
*           PF03               =
*           PF15               =
*           PF12               =
*      EXCEPTIONS
*           CLASS_UNKNOWN      = 1
*           OBJECT_NOT_FOUND   = 2
*           OTHERS             = 3.
  IF SY-SUBRC NE 0.
    MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  LOGS_ANALYSE
*&---------------------------------------------------------------------*
*       Analyses table logs concerning the current maintenance view by
*       calling report RSVTPROT
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM LOGS_ANALYSE.

  RANGES: SEL_OBJ FOR OBJH-OBJECTNAME,
          SEL_TYPE FOR OBJH-OBJECTTYPE.

  SEL_OBJ-SIGN = SEL_TYPE-SIGN = 'I'.
  SEL_OBJ-OPTION = SEL_TYPE-OPTION = 'EQ'.
  IF VIM_CALLED_BY_CLUSTER NE SPACE.
    SEL_TYPE-LOW = VIM_CLST.
    SEL_OBJ-LOW = VIM_CALLING_CLUSTER.
  ELSE.
    SEL_OBJ-LOW = X_HEADER-VIEWNAME.
    IF x_header-bastab NE space
     AND x_header-maintview = x_header-viewname.
* table but no table-variant
      sel_type-low = vim_tabl.
    ELSE.
* view, view-variant, or table variant
      SEL_TYPE-LOW = VIM_VIEW.
    ENDIF.
  ENDIF.
  APPEND SEL_OBJ. APPEND SEL_TYPE.
  SUBMIT RSVTPROT VIA SELECTION-SCREEN USING SELECTION-SCREEN 1010
                  WITH CUSOBJ IN SEL_OBJ
                  WITH STYPE IN SEL_TYPE
                  WITH ACC_ARCH = ' ' AND RETURN.
ENDFORM.                               " LOGS_ANALYSE

*----------------------------------------------------------------------*
*   INCLUDE LSVIMF46                                                   *
*----------------------------------------------------------------------*
* <Address_Number> -> <table1> = View-Workarea (= zu übernehmender
*      Eintrag, aber Adreßnummer des akt. Mandant/System;
*      Adreßnummer wurde in VIM_MODIFY_VIEW_ENTRY ausgetauscht)
* <F1>             -> <table1>(keylen)
* VIM_UPGR_ADDRESS_NUMBER -> Adresse des zu übernehmenden Eintrages
* Achtung: in TOTAL steht NICHT(!) mehr der Eintrag aus akt. Mandant/Sys
*          zur Verfügung wegen Zuweisung  'move <table1> to total'
*          in liste_initialisieren im 'Replace_mode'.
*----------------------------------------------------------------------*
FORM vim_address_adjust.
  DATA: addr_comp_tab TYPE szadr_compare_addr1_tab,
        addr_comp_line TYPE szadr_compare_addr1_line,
        handle TYPE ad_handle,
        create_address(1) TYPE c,
        retcode LIKE  szad_field-returncode,
        error_info LIKE addr_error OCCURS 0 WITH HEADER LINE,
        einfo      LIKE addr_error,
        i_msgv1 LIKE sy-msgv1,
        space_msgv LIKE sy-msgv1 VALUE space,
        dum TYPE i, pos_char TYPE i.

  FIELD-SYMBOLS: <handle_x> TYPE x, <field_loc> TYPE ANY.

* nur neue Adreßpflege!
  CHECK x_header-adrnbrflag = 'N' AND adrnbr_roflag = space.
  ASSIGN handle TO <handle_x> CASTING.
  IF vim_import_mode_active = space.             "interaktive Übernahme
    IF vim_upgr_address_number <> '@ADJUSTED@'.   "cmpwl_addr_adjusted
      EXIT.
    ENDIF.
    IF <address_number> = space.
      <handle_x> = <f1_x>.
*      HANDLE = <F1>.
      create_address = 'X'.
    ELSE.
      READ TABLE vim_locked_addresses FROM <address_number>
                                        TRANSPORTING NO FIELDS.
      IF sy-subrc <> 0.                "not yet locked
        CALL FUNCTION 'ADDR_ENQUEUE'
             EXPORTING
                  address_number    = <address_number>
*               MODE_ADRC         = 'E'
             EXCEPTIONS
                  address_not_exist = 1
                  foreign_lock      = 2
                  system_failure    = 3
                  internal_error    = 4.
        CASE sy-subrc.
          WHEN 0.
            INSERT <address_number> INTO TABLE vim_locked_addresses.
          WHEN 1.
            <handle_x> = <f1_x>.
*            HANDLE = <F1>.
            create_address = 'X'.
            CLEAR <address_number>.
          WHEN 2.
            PERFORM vim_process_message
                USING 'SV' 'E' 'E' '049'
                      sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          WHEN OTHERS.
*            i_msgv1 = <table1>.   "HCG Dump when nonchar field in view
            LOOP AT x_namtab.      "HCG write field by field instead
              ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE <table1>
                                              TO <field_loc>.
              dum = ( x_namtab-position + x_namtab-flength ) /
                            cl_abap_char_utilities=>charsize.
              pos_char = x_namtab-position /
                                      cl_abap_char_utilities=>charsize.
              IF dum <= 13.
                WRITE <field_loc> TO i_msgv1+pos_char.
              ELSE.
                dum = 13 - pos_char.
                WRITE <field_loc>(dum) TO i_msgv1+pos_char.
                EXIT.                               "HCG i_msgv1 filled
              ENDIF.
            ENDLOOP.
            PERFORM vim_process_message
              USING 'SV' 'E' 'E' '050'
                  i_msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDCASE.
      ENDIF.  " SY-SUBRC <> 0.
    ENDIF.   "<Address_Number> = SPACE

  ELSE.  "automat. Übernahme
    IF vim_upgr_address_number = space.
*      i_msgv1 = <table1>.   "HCG Dump when nonchar field in view
      LOOP AT x_namtab.      "HCG write field by field instead
        ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE <table1>
                                        TO <field_loc>.
        dum = ( x_namtab-position + x_namtab-flength ) /
                      cl_abap_char_utilities=>charsize.
        pos_char = x_namtab-position /
                                cl_abap_char_utilities=>charsize.
        IF dum <= 13.
          WRITE <field_loc> TO i_msgv1+pos_char.
        ELSE.
          dum = 13 - pos_char.
          WRITE <field_loc>(dum) TO i_msgv1+pos_char.
          EXIT.                               "HCG i_msgv1 filled
        ENDIF.
      ENDLOOP.
      PERFORM vim_process_message
                USING 'SV' 'I' 'I'  '165'
                    i_msgv1 space_msgv space_msgv space_msgv.
      EXIT.                                          "keine Löschung
    ENDIF.

    addr_comp_line-addrnumber = <address_number>.
    IF <address_number> = space.
      <handle_x> = <f1_x>.
      addr_comp_line-addrhandle = handle.
*      ADDR_COMP_LINE-ADDRHANDLE = <F1>.
*      HANDLE = <F1>.
      create_address = 'X'.
    ENDIF.
    addr_comp_line-remote_addrnumber = vim_upgr_address_number.
    APPEND addr_comp_line TO addr_comp_tab.
    CALL FUNCTION 'ADDR_COMPARE'
         EXPORTING
              rfc_destination = vim_default_rfc_dest-rfcdest
         TABLES
              compare_tab     = addr_comp_tab
         EXCEPTIONS
              rfc_error       = 1
              OTHERS          = 2.
    IF sy-subrc <> 0.
      PERFORM vim_process_message
            USING sy-msgid 'E' 'E'  sy-msgno
                  sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      EXIT.
    ENDIF.
    READ TABLE addr_comp_tab INDEX 1 INTO addr_comp_line.
    IF addr_comp_line-parameter_error = 'X' OR
       addr_comp_line-internal_error = 'X'.
      einfo = addr_comp_line-error_table.
      PERFORM vim_process_message
        USING einfo-msg_id 'E' 'E'  einfo-msg_number
            einfo-msg_var1 einfo-msg_var2 einfo-msg_var3 einfo-msg_var4.
*     Adresse kann nicht abgeglichen werden -> Eintrag verwerfen
      EXIT.
    ENDIF.

    IF addr_comp_line-rem_address_not_exist = 'X'.    "keine Löschung!
*      i_msgv1 = <table1>.   "HCG Dump when nonchar field in view
      LOOP AT x_namtab.      "HCG write field by field instead
        ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE <table1>
                                        TO <field_loc>.
        dum = ( x_namtab-position + x_namtab-flength ) /
                      cl_abap_char_utilities=>charsize.
        pos_char = x_namtab-position /
                                cl_abap_char_utilities=>charsize.
        IF dum <= 13.
          WRITE <field_loc> TO i_msgv1+pos_char.
        ELSE.
          dum = 13 - pos_char.
          WRITE <field_loc>(dum) TO i_msgv1+pos_char.
          EXIT.                               "HCG i_msgv1 filled
        ENDIF.
      ENDLOOP.
      PERFORM vim_process_message
              USING 'SV' 'I' 'I'  '165'
                    i_msgv1 space_msgv space_msgv space_msgv.
      EXIT.
    ELSEIF addr_comp_line-address_not_exist = 'X' AND
           create_address = space.
      <handle_x> = <f1_x>.
*      HANDLE = <F1>.
      create_address = 'X'.
      CLEAR: <address_number>, <vim_total_address_number>.
      REFRESH addr_comp_tab. CLEAR addr_comp_line.
      addr_comp_line = handle.
*      ADDR_COMP_LINE-ADDRHANDLE = <F1>.
      addr_comp_line-remote_addrnumber = vim_upgr_address_number.
      APPEND addr_comp_line TO addr_comp_tab.
      CALL FUNCTION 'ADDR_COMPARE'
           EXPORTING
                rfc_destination = vim_default_rfc_dest-rfcdest
           TABLES
                compare_tab     = addr_comp_tab
           EXCEPTIONS
                rfc_error       = 1
                OTHERS          = 2.
      IF sy-subrc <> 0.
        PERFORM vim_process_message
              USING sy-msgid 'E' 'E'  sy-msgno
                    sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        EXIT.
      ENDIF.
      READ TABLE addr_comp_tab INDEX 1 INTO addr_comp_line.
      IF addr_comp_line-parameter_error = 'X' OR
         addr_comp_line-internal_error = 'X'.
        einfo = addr_comp_line-error_table.
        PERFORM vim_process_message
          USING einfo-msg_id 'E' 'E'  einfo-msg_number
            einfo-msg_var1 einfo-msg_var2 einfo-msg_var3 einfo-msg_var4.
*       Adresse kann nicht abgeglichen werden -> Eintrag verwerfen
        EXIT.
      ENDIF.
*     Überprüfung von REM_ADDRESS_NOT_EXIST, .. hier nicht nötig

    ELSEIF addr_comp_line-address_is_equal = 'X'.
      EXIT.
    ELSEIF create_address = space.
      READ TABLE vim_locked_addresses FROM <address_number>
                                        TRANSPORTING NO FIELDS.
      IF sy-subrc <> 0.                "not yet locked
        CALL FUNCTION 'ADDR_ENQUEUE'
             EXPORTING
                  address_number    = <address_number>
*               MODE_ADRC         = 'E'
             EXCEPTIONS
                  address_not_exist = 1
                  foreign_lock      = 2
                  system_failure    = 3
                  internal_error    = 4.
        CASE sy-subrc.
          WHEN 0.
            INSERT <address_number> INTO TABLE vim_locked_addresses.
          WHEN 1.  " würde schon in ADDR_COMPARE auftreten
            PERFORM vim_process_message    "eigentlich überflüssig
                USING 'SV' 'E' 'E' '049'
                      sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          WHEN 2.
            PERFORM vim_process_message
                USING 'SV' 'E' 'E' '049'
                      sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          WHEN OTHERS.
*            i_msgv1 = <table1>.   "HCG Dump when nonchar field in view
            LOOP AT x_namtab.      "HCG write field by field instead
              ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE <table1>
                                              TO <field_loc>.
              dum = ( x_namtab-position + x_namtab-flength ) /
                            cl_abap_char_utilities=>charsize.
              pos_char = x_namtab-position /
                                      cl_abap_char_utilities=>charsize.
              IF dum <= 13.
                WRITE <field_loc> TO i_msgv1+pos_char.
              ELSE.
                dum = 13 - pos_char.
                WRITE <field_loc>(dum) TO i_msgv1+pos_char.
                EXIT.                               "HCG i_msgv1 filled
              ENDIF.
            ENDLOOP.
            PERFORM vim_process_message
              USING 'SV' 'E' 'E' '050'
                  i_msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDCASE.
      ENDIF.   "SY-SUBRC
    ENDIF.
  ENDIF.     " vim_import_mode_active

  CALL FUNCTION 'ADDR_ADJUST'
       EXPORTING
            addrnumber           = <address_number>
            addrhandle           = handle
            address_group        = 'CA01'
       IMPORTING
            returncode           = retcode
       TABLES
            error_table          = error_info
       EXCEPTIONS
            parameter_error      = 1
            address_not_exist    = 2
            handle_exist         = 3
            internal_error       = 4
            address_not_compared = 5
            OTHERS               = 6.
  IF sy-subrc <> 0.
    PERFORM vim_process_message
           USING sy-msgid 'E' 'E' sy-msgno
                 sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    IF retcode = 'E'.
      READ TABLE error_info INDEX 1.
      PERFORM vim_process_message
             USING error_info-msg_id 'E' 'E' error_info-msg_number
                   error_info-msg_var1 error_info-msg_var2
                   error_info-msg_var3 error_info-msg_var4.
    ELSE.    "ok
      IF create_address = 'X'.
        <address_number> = '@NEW'.
        <address_number>+4(6) = <status>-newadrcnt.
        ADD 1 TO <status>-newadrcnt.
        <status>-upd_flag = 'X'.
      ENDIF.
      <vim_total_address_number> = <address_number>.
      READ TABLE vim_addresses_to_save
                              WITH KEY viewname = x_header-viewname
                                       addrnumber = <address_number>
                              BINARY SEARCH TRANSPORTING NO FIELDS.
      IF sy-subrc NE 0.
        vim_addresses_to_save-viewname = x_header-viewname.
        vim_addresses_to_save-addrnumber = <address_number>.
        <vim_addr_handle_x> = <f1_x>.
*        VIM_ADDRESSES_TO_SAVE-HANDLE = <F1>.
        INSERT vim_addresses_to_save INDEX sy-tabix.
      ENDIF.
      IF vim_client_state EQ vim_log AND
        x_header-flag NE vim_transport_denied.
        <status>-upd_flag = 'X'. "nec. for transport of master entry
      ENDIF.
    ENDIF.                                                  "RETCODE
  ENDIF.            "SY-SUBRC
ENDFORM.                    "vim_address_adjust

*----------------------------------------------------------------------*
*   INCLUDE LSVIMF50                                                   *
*----------------------------------------------------------------------*

FORM VIM_VCLDOCKING_CONTROL.
DATA: DISABLE_NAVI(1) TYPE C.

  IF VIM_EXTERNAL_MODE = 'X' OR VIM_SPECIAL_MODE = VIM_DIRECT_UPGRADE
     OR STATUS-ACTION = 'C'.
    DISABLE_NAVI = 'X'.
  ENDIF.
  CALL FUNCTION 'VIEWCLUSTER_NAVI_CONTROL'
       EXPORTING
            OWNER_REPID        = X_HEADER-FPOOLNAME
            OWNER_DYNNR        = SY-DYNNR
            DISABLE_NAVIGATION = DISABLE_NAVI
       EXCEPTIONS
            OTHERS             = 1.
  IF SY-SUBRC = 0.
    MOVE 'ATAB' TO EXCL_CUA_FUNCT-FUNCTION. COLLECT EXCL_CUA_FUNCT.
  ENDIF.
ENDFORM.                                  " VIM_VCLDOCKING_CONTROL

*----------------------------------------------------------------------*
*   INCLUDE LSVIMF51                                                   *
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  VIM_ADD_IMG_NOTICES_PBO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_DYNPRO  Dynpro number
*----------------------------------------------------------------------*
FORM vim_add_img_notices_pbo USING    value(p_dynpro) TYPE list_scr.

  DATA: progname LIKE sy-repid, exit, dynpro TYPE sydynnr.

  CHECK vim_special_mode <> vim_upgrade AND vim_import_profile = space.
  progname = sy-repid.
  dynpro = p_dynpro.
  CALL FUNCTION 'SPROJECT_CONTROL_PBO'
       EXPORTING
            repid = progname
            dynnr = dynpro.
ENDFORM.                               " VIM_ADD_IMG_NOTICES_PBO

*&---------------------------------------------------------------------*
*&      Form  VIM_ADD_IMG_NOTICES_PAI
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_MODE   text
*      <--P_EXIT_OK  text
*----------------------------------------------------------------------*
FORM vim_add_img_notices_pai USING    p_mode TYPE char1
                             CHANGING exit_ok TYPE char1.

  DATA: leave TYPE char1, save TYPE char1.

  CHECK vim_special_mode <> vim_upgrade AND vim_import_profile = space.
  CASE p_mode.
    WHEN 'S'.                          "Save notices
      save = 'X'.
    WHEN 'E'.                          "Exit and eventually save changes
      leave = 'X'.
  ENDCASE.
  CALL FUNCTION 'SPROJECT_CONTROL_PAI'
       EXPORTING
            i_exit    = leave
            save_note = save
       IMPORTING
            e_exit    = exit_ok.
ENDFORM.                               " VIM_ADD_IMG_NOTICES_PAI
*----------------------------------------------------------------------*
***INCLUDE LSVIMF5A .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  VIM_BC_LOGS_PUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_BC_ENTRY_LIST  text
*----------------------------------------------------------------------*
FORM vim_bc_logs_put CHANGING p_bc_entry_list LIKE
                              vim_bc_entry_list.

  DATA: corr_keytab_save LIKE TABLE OF e071k, first,
        dummy LIKE sy-subrc, transport_active LIKE t000-cccoractiv,
        w_tabkey_value TYPE scpractr,
        tabkey_values_n TYPE vim_bc_tab_logs,
        tabkey_values_u TYPE vim_bc_tab_logs,
        tabkey_values_d TYPE vim_bc_tab_logs,
        w_bc_entry TYPE scpr_viewdata, bc_entries TYPE scpr_viewdatas,
        w_bc_entry_list TYPE vimty_bc_entry_list_type,
        bc_keytab TYPE bc_keytab_type,
        bc_keytab_wa LIKE LINE OF bc_keytab,
        p_msgid, p_msgty, p_msgno, bc_key_needed(1) TYPE c,
        foreign_langu TYPE sy-langu,
        rc LIKE sy-subrc, keys_identical TYPE xfeld,
        subrc TYPE sy-subrc, tabix TYPE sy-tabix.

  STATICS: viewname_old TYPE vimdesc-viewname,
           keylen_real TYPE i.

  CONSTANTS: bc_id_length TYPE i VALUE 32,
             bc_recno_length TYPE i VALUE 10.

  FIELD-SYMBOLS: <bc_entry_keyx> TYPE x, <key> TYPE x,
                 <vim_bc_keyx> TYPE x, <w_bc_entry_x> TYPE x,
                 <xlangu> TYPE x, <namtab> type vimnamtab.

  ASSIGN: w_bc_entry_list-keys(x_header-keylen) TO <bc_entry_keyx>.
  ASSIGN: bc_keytab_wa-bc_tabkey TO <vim_bc_keyx> CASTING.
  ASSIGN: w_bc_entry-data TO <w_bc_entry_x> CASTING.

  IF x_header-viewname NE viewname_old. "HCG: has table align gap?
    viewname_old = x_header-viewname.
    CLEAR keylen_real.
    LOOP AT x_namtab ASSIGNING <namtab> WHERE keyflag = 'X' AND
                                                texttabfld IS INITIAL.
      keylen_real = keylen_real + <namtab>-flength.
    ENDLOOP.
  ENDIF.
  LOOP AT p_bc_entry_list INTO w_bc_entry_list WHERE
   viewname = x_header-viewname AND action <> original.
*    IF w_bc_entry_list-action = neuer_geloescht.   Obsolete, was only
*      DELETE p_bc_entry_list. CONTINUE.            possible at bc-set
*    ENDIF.                              activation in dialog via SM30
    IF first = space.
      first = 'X'.
      INSERT LINES OF corr_keytab INTO TABLE corr_keytab_save.
      REFRESH corr_keytab.
      CLEAR <table1>.
      transport_active = vim_client_state.
    ENDIF.
* fill corr_keytab
    IF x_header-keylen = keylen_real.
      READ TABLE total WITH KEY <bc_entry_keyx> BINARY SEARCH.
    ELSE.
      PERFORM vim_read_table_with_gap
                    TABLES   total
                    USING    <bc_entry_keyx>
                             x_namtab[]
                    CHANGING subrc
                             tabix.
      IF subrc = 0.
        READ TABLE total INDEX tabix.
      ENDIF.
    ENDIF.
    IF x_header-bastab EQ space.                            "view
      MOVE <bc_entry_keyx> TO <f1_x>.
      PERFORM (corr_formname) IN PROGRAM (sy-repid) USING
                                            vim_writing_bc_imp_log
                                            dummy.
      REFRESH bc_keytab.
      CLEAR bc_key_needed.
      IF x_header-keylen > vim_max_trsp_keylength. "HCG tabkey up to 255
        bc_key_needed = 'X'.
      ENDIF.
      IF bc_key_needed NE 'X'.           "Look for non-char field in key
        LOOP AT x_namtab WHERE keyflag = 'X'.
          IF 'CNDT' NS x_namtab-inttype. "non charlike field
            bc_key_needed = 'X'.
            EXIT.
          ENDIF.
        ENDLOOP.
      ENDIF.
      IF bc_key_needed NE 'X'.             "Look if viewkey > primtabkey
        CLEAR keys_identical.
        PERFORM vim_comp_roottabkey USING x_header
                                          x_namtab[]
                                 CHANGING keys_identical
                                          rc.
        IF keys_identical EQ space. bc_key_needed = 'X'. ENDIF.
      ENDIF.
      IF bc_key_needed NE space.                 "Tabkeys via new coding
        LOOP AT corr_keytab.
          MOVE-CORRESPONDING corr_keytab TO bc_keytab_wa.
          APPEND bc_keytab_wa TO bc_keytab.
        ENDLOOP.
        PERFORM vim_build_bc_tabkeys USING w_bc_entry_list
                                  CHANGING bc_keytab.
      ELSE.  "Tabkeys as up to now via generated coding (corr_maint_...)
        LOOP AT corr_keytab.
          MOVE-CORRESPONDING corr_keytab TO bc_keytab_wa.
          MOVE corr_keytab-tabkey TO bc_keytab_wa-bc_tabkey.
          APPEND bc_keytab_wa TO bc_keytab.
        ENDLOOP.
*     Look for other languages in bc-set and append to corr_keytab too
        IF x_header-texttbexst NE space.
          READ TABLE bc_keytab into bc_keytab_wa
                               with key objname = x_header-texttab.
          LOOP AT w_bc_entry_list-forlangu INTO foreign_langu.
            ASSIGN foreign_langu TO <xlangu> casting.
            MOVE <xlangu> TO
    <vim_bc_keyx>+x_header-sprasfdpos(cl_abap_char_utilities=>charsize).
            APPEND bc_keytab_wa TO bc_keytab.
          ENDLOOP.
        ENDIF.
      ENDIF.
    ELSE.                                                   "base table
      MOVE <vim_xtotal> TO <table1_x>.
      MOVE-CORRESPONDING e071k TO bc_keytab_wa.
      MOVE e071k-tabkey TO bc_keytab_wa-bc_tabkey.
      bc_keytab_wa-objname = x_header-maintview.
      MOVE <bc_entry_keyx> TO <vim_bc_keyx>(x_header-keylen).
      APPEND bc_keytab_wa TO bc_keytab.
      IF x_header-bastab <> space AND
         x_header-texttbexst NE space AND         "base table with
         <vim_xtotal_text> NE <text_initial_x>.   "text table
        MOVE-CORRESPONDING e071k TO bc_keytab_wa.
        MOVE e071k-tabkey TO bc_keytab_wa-bc_tabkey.
        bc_keytab_wa-objname = x_header-texttab.
        MOVE <vim_xtotal_text> TO <vim_bc_keyx>(x_header-textkeylen).
        APPEND bc_keytab_wa TO bc_keytab.
*       other languages
        READ TABLE x_namtab WITH KEY keyflag = 'X'         "langu field
                               primtabkey = '0000'.
        LOOP AT w_bc_entry_list-forlangu INTO foreign_langu.
          ASSIGN foreign_langu TO <xlangu> CASTING.
          MOVE <xlangu> TO
               <vim_bc_keyx>+x_namtab-texttabpos(x_namtab-flength).
          APPEND bc_keytab_wa TO bc_keytab.
        ENDLOOP.
      ENDIF.
    ENDIF.                             "base table or view
    CASE w_bc_entry_list-action.
      WHEN neuer_eintrag.
* bc-set imported
        PERFORM bc_entry_log_fill USING     x_header
                                            x_namtab[]
                                            bc_keytab[]
                                            w_bc_entry_list
                                      CHANGING tabkey_values_n.
        CLEAR w_bc_entry_list-action.
      WHEN aendern.
* bc-set entry modified
        PERFORM bc_entry_log_fill USING     x_header
                                            x_namtab[]
                                            bc_keytab[]
                                            w_bc_entry_list
                                      CHANGING tabkey_values_u.
        CLEAR w_bc_entry_list-action.
        MOVE: w_bc_entry_list-id TO w_bc_entry-bcset_id,
              w_bc_entry_list-recnumber TO w_bc_entry-recnumber,
              x_header-viewname TO w_bc_entry-viewname,
              <vim_xtotal> TO <w_bc_entry_x>.
        APPEND w_bc_entry TO bc_entries.
      WHEN geloescht.
* bc-set entry deleted.
        PERFORM bc_entry_log_fill USING     x_header
                                            x_namtab[]
                                            bc_keytab[]
                                            w_bc_entry_list
                                      CHANGING tabkey_values_d.
        DELETE p_bc_entry_list.
    ENDCASE.
    REFRESH corr_keytab.   "weg???
    REFRESH bc_keytab.
  ENDLOOP.
  IF NOT tabkey_values_n IS INITIAL.
    DELETE ADJACENT DUPLICATES FROM tabkey_values_n COMPARING ALL
     FIELDS.
    LOOP AT tabkey_values_n INTO w_tabkey_value.
      CALL FUNCTION 'SCPR_EXT_SCPRACTR_FILL'
        EXPORTING
          tablename         = w_tabkey_value-tablename
          profid            = w_tabkey_value-profid
          recnumber         = w_tabkey_value-recnumber
          viewname          = x_header-maintview
          viewvar           = x_header-viewname
          del_record        = ' '
          new_record        = 'X'
          key               = w_tabkey_value-tabkey
        EXCEPTIONS
          wrong_parameters  = 1
          internal_error    = 2
          key_not_supportet = 3
          fielddescr_error  = 4
          OTHERS            = 5.
      IF sy-subrc <> 0.
        p_msgid = 'SCPR'.
        CASE sy-subrc.
          WHEN 1.
            p_msgty = 'E'.
            p_msgno = '273'.
          WHEN 3.
            p_msgty = 'W'.
            p_msgno = '408'.
          WHEN 4.
            p_msgty = 'E'.
            p_msgno = '395'.
          WHEN OTHERS.
            p_msgty = 'E'.
            p_msgno = '320'.
        ENDCASE.
        PERFORM vim_process_message USING sy-msgid sy-msgty sy-msgty
                                  sy-msgno space space space space.
      ENDIF.
    ENDLOOP.
  ENDIF.
  IF NOT tabkey_values_u IS INITIAL.
    DELETE ADJACENT DUPLICATES FROM tabkey_values_u COMPARING ALL
     FIELDS.
    LOOP AT tabkey_values_u INTO w_tabkey_value.
      CALL FUNCTION 'SCPR_EXT_SCPRACTR_FILL'
        EXPORTING
          tablename         = w_tabkey_value-tablename
          profid            = w_tabkey_value-profid
          recnumber         = w_tabkey_value-recnumber
          viewname          = x_header-maintview
          viewvar           = x_header-viewname
          del_record        = ' '
          new_record        = ' '
          key               = w_tabkey_value-tabkey
        EXCEPTIONS
          wrong_parameters  = 1
          internal_error    = 2
          key_not_supportet = 3
          fielddescr_error  = 4
          OTHERS            = 5.
      IF sy-subrc <> 0.
        p_msgid = 'SCPR'.
        CASE sy-subrc.
          WHEN 1.
            p_msgty = 'E'.
            p_msgno = '273'.
          WHEN 3.
            p_msgty = 'W'.
            p_msgno = '408'.
          WHEN 4.
            p_msgty = 'E'.
            p_msgno = '395'.
          WHEN OTHERS.
            p_msgty = 'E'.
            p_msgno = '320'.
        ENDCASE.
        PERFORM vim_process_message USING sy-msgid sy-msgty sy-msgty
                                  sy-msgno space space space space.
      ENDIF.
    ENDLOOP.
  ENDIF.
  IF NOT tabkey_values_d IS INITIAL.
    DELETE ADJACENT DUPLICATES FROM tabkey_values_d COMPARING ALL
     FIELDS.
    LOOP AT tabkey_values_d INTO w_tabkey_value.
      CALL FUNCTION 'SCPR_EXT_SCPRACTR_FILL'
        EXPORTING
          tablename         = w_tabkey_value-tablename
          profid            = w_tabkey_value-profid
          recnumber         = w_tabkey_value-recnumber
          viewname          = x_header-maintview
          viewvar           = x_header-viewname
          del_record        = 'X'
          new_record        = ' '
          key               = w_tabkey_value-tabkey
        EXCEPTIONS
          wrong_parameters  = 1
          internal_error    = 2
          key_not_supportet = 3
          fielddescr_error  = 4
          OTHERS            = 5.
      IF sy-subrc <> 0.
        p_msgid = 'SCPR'.
        CASE sy-subrc.
          WHEN 1.
            p_msgty = 'E'.
            p_msgno = '273'.
          WHEN 3.
            p_msgty = 'W'.
            p_msgno = '408'.
          WHEN 4.
            p_msgty = 'E'.
            p_msgno = '395'.
          WHEN OTHERS.
            p_msgty = 'E'.
            p_msgno = '320'.
        ENDCASE.
        PERFORM vim_process_message USING sy-msgid sy-msgty sy-msgty
                                  sy-msgno space space space space.
      ENDIF.
    ENDLOOP.
  ENDIF.
  IF NOT corr_keytab_save IS INITIAL.
    INSERT LINES OF corr_keytab_save INTO TABLE corr_keytab.
  ENDIF.
ENDFORM.                               " VIM_BC_LOGS_PUT

*&---------------------------------------------------------------------*
*&      Form  bc_entry_log_fill
*&---------------------------------------------------------------------*
*       fills value table for BC-set activation log for every fix entity
*       field
*----------------------------------------------------------------------*
*      -->P_HEADER  text
*      -->P_NAMTAB  text
*      -->P_CORR_KEYTAB  text
*      -->P_BC_ENTRY  text
*      <--P_TABKEY_VALUE  text
*----------------------------------------------------------------------*
FORM bc_entry_log_fill USING        p_header TYPE vimdesc
                                    p_namtab LIKE x_namtab[]
                                    p_bc_keytab TYPE bc_keytab_type
                               p_bc_entry TYPE vimty_bc_entry_list_type
                          CHANGING p_tabkey_values TYPE vim_bc_tab_logs.

  STATICS: dd28j_tab TYPE TABLE OF dd28j.
  DATA: w_dd28j TYPE dd28j, w_tabkey_value TYPE scpractr,
        w_fields TYPE vimty_fields_type.
  FIELD-SYMBOLS: <namtab> TYPE vimnamtab, <dfies> TYPE dfies,
                 <keytab> TYPE bc_key_type.

  IF p_header-bastab = space.
    READ TABLE dd28j_tab INTO w_dd28j INDEX 1.
    IF sy-subrc <> 0 OR p_header-viewname <> w_dd28j-viewname.
* get join-conditions
      REFRESH dd28j_tab.
      CALL FUNCTION 'DDIF_VIEW_GET'
        EXPORTING
          name          = p_header-viewname
        TABLES
          dd28j_tab     = dd28j_tab
        EXCEPTIONS
          illegal_input = 1
          OTHERS        = 2.
      IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDIF.
  ENDIF.
  w_tabkey_value-client = sy-mandt.
  w_tabkey_value-profid = p_bc_entry-id.
  w_tabkey_value-recnumber = p_bc_entry-recnumber.
  w_tabkey_value-viewname = p_header-maintview.             "HCG 6.8.02
  LOOP AT p_namtab ASSIGNING <namtab> WHERE keyflag = space OR
   texttabfld = space.
    READ TABLE p_bc_entry-fields INTO w_fields WITH KEY fieldname =
     <namtab>-viewfield.
    CHECK sy-subrc = 0.
    READ TABLE p_tabkey_values WITH KEY client = sy-mandt
      tablename = <namtab>-bastabname profid = p_bc_entry-id
      recnumber = p_bc_entry-recnumber viewname = p_header-viewname
      TRANSPORTING NO FIELDS.
    IF sy-subrc <> 0.
      LOOP AT p_bc_keytab ASSIGNING <keytab> WHERE
                                pgmid = 'R3TR' AND
                               object = 'TABU' AND
                              objname = <namtab>-bastabname.
        w_tabkey_value-tablename = <namtab>-bastabname.
        w_tabkey_value-tabkey = <keytab>-bc_tabkey.
        APPEND w_tabkey_value TO p_tabkey_values.
      ENDLOOP.
      CHECK sy-subrc = 0.
    ENDIF.
    IF x_header-bastab = space.
* view
      LOOP AT dd28j_tab INTO w_dd28j WHERE viewname = p_header-viewname
       AND ltab = <namtab>-bastabname AND lfield = <namtab>-viewfield.
        READ TABLE p_tabkey_values WITH KEY client = sy-mandt
          tablename = w_dd28j-rtab profid = p_bc_entry-id
          recnumber = p_bc_entry-recnumber viewname = p_header-viewname
          TRANSPORTING NO FIELDS.
        IF sy-subrc <> 0.
          READ TABLE p_bc_keytab WITH KEY pgmid = 'R3TR'
                            object = 'TABU'
                              objname = w_dd28j-rtab ASSIGNING <keytab>.
          CHECK sy-subrc = 0.
          w_tabkey_value-tablename = w_dd28j-rtab.
          w_tabkey_value-tabkey = <keytab>-bc_tabkey.
          APPEND w_tabkey_value TO p_tabkey_values.
        ENDIF.
      ENDLOOP.
      LOOP AT dd28j_tab INTO w_dd28j WHERE viewname = p_header-viewname
       AND rtab = <namtab>-bastabname AND rfield = <namtab>-viewfield.
        READ TABLE p_tabkey_values WITH KEY client = sy-mandt
          tablename = w_dd28j-ltab profid = p_bc_entry-id
          recnumber = p_bc_entry-recnumber viewname = p_header-viewname
          TRANSPORTING NO FIELDS.
        IF sy-subrc <> 0.
          LOOP AT p_bc_keytab ASSIGNING <keytab> WHERE
                                pgmid = 'R3TR' AND
                               object = 'TABU' AND
                              objname = w_dd28j-ltab.
            w_tabkey_value-tablename = w_dd28j-ltab.
            w_tabkey_value-tabkey = <keytab>-bc_tabkey.
            APPEND w_tabkey_value TO p_tabkey_values.
          ENDLOOP.
          CHECK sy-subrc = 0.
        ENDIF.
      ENDLOOP.
    ENDIF.
  ENDLOOP.
ENDFORM.                               " bc_entry_log_fill
*&---------------------------------------------------------------------*
*&      Form  VIM_BC_LOGS_GET
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_C_ENTRY_LIST  text
*      -->P_VIEW_NAME  text
*      -->P_HEADER  text
*      -->P_NAMTAB  text
*----------------------------------------------------------------------*
FORM vim_bc_logs_get USING    p_view_name TYPE tabname
                              p_header TYPE vimdesc
                              p_namtab LIKE x_namtab[]
                CHANGING p_bc_entry_list TYPE vimty_bc_entry_list_ttype.

  STATICS: tablist TYPE TABLE OF scprxtabl, viewname TYPE tabname.

  DATA:    tabkeys TYPE TABLE OF scpractr, w_tablist TYPE scprxtabl,
           bc_entry_list_wa TYPE vimty_bc_entry_list_type, failed(1),
           rc LIKE sy-subrc, keys_identical TYPE xfeld,
           x030l_root TYPE x030l,
           x030l_bastab TYPE x030l,
           root_entry TYPE REF TO data,
           bastab_entry TYPE REF TO data,
           tabflags TYPE scpr_actfs, tabflags_wa TYPE scpr_actf,
*           tabflags_quick TYPE HASHED TABLE OF scpr_actf
*            WITH UNIQUE KEY tablename fieldname bcset_id
           tabflags_quick TYPE SORTED TABLE OF scpr_actf
            WITH NON-UNIQUE KEY tablename fieldname bcset_id
            recnumber tabkey INITIAL SIZE 100,
           fields_wa TYPE vimty_fields_type,
           bc_entry_list TYPE STANDARD TABLE OF
            vimty_bc_entry_list_type WITH KEY viewname keys,
            tabkey_wa TYPE scpractr-tabkey,
            tabkeys_wa TYPE scpractr,
            roottab TYPE tabname,
            tabix TYPE sy-tabix,
            tabkey_struc(1024) TYPE c.
  FIELD-SYMBOLS: <namtab> TYPE vimnamtab, <tabkeys> TYPE scpractr,
                 <tabkeys_main> TYPE scpractr,
                 <bastab> TYPE ANY, <bastab_x> TYPE x,
                 <roottab> TYPE ANY, <roottab_x> TYPE x,
                 <rootfld> TYPE ANY,
                 <tabkey> TYPE x, <viewfld> TYPE ANY,
                 <clnt> TYPE ANY,
                 <tabkey_c> TYPE c.

  DELETE p_bc_entry_list WHERE viewname = p_header-maintview."HCG 6.8.02
  CHECK vim_import_profile = space.
* CHECK 'TS' NS maint_mode.   "HCG Necessary in show and transport mode
*                   too, e.g. for selection show only data from BC-Sets
  IF viewname <> p_header-viewname.
* make table list
    viewname = p_header-viewname.
    REFRESH tablist.
    w_tablist-sign = 'I'. w_tablist-option = 'EQ'.
    IF p_header-bastab EQ 'X'.                              "S-table
      w_tablist-low = viewname.         "HCG only roottab in tablist
      roottab = viewname.
      COLLECT w_tablist INTO tablist.
    ELSE.                                                      "View
      w_tablist-low = p_header-roottab. "HCG only roottab in tablist
      roottab = p_header-roottab.
      COLLECT w_tablist INTO tablist.
    ENDIF.
  ENDIF.
  CALL FUNCTION 'SCPR_BCSET_PROT_GET_TABKEYS'
    EXPORTING
      viewname = viewname
    IMPORTING
      actkeys  = tabkeys
      tabflags = tabflags
    TABLES
      tabnames = tablist
    EXCEPTIONS
      no_data  = 1
      OTHERS   = 2.
  CHECK sy-subrc = 0 AND NOT tabkeys IS INITIAL.
  IF p_header-bastab EQ 'X'.                              "S-table
    roottab = viewname.
  ELSE.                                                      "View
    roottab = p_header-roottab.
  ENDIF.
  LOOP AT tabkeys INTO tabkeys_wa.
    tabkey_wa = tabkeys_wa-tabkey.
    tabix = sy-tabix.
    CALL FUNCTION 'SCPR_EXT_ACTKEY_TO_KEY'
      EXPORTING
        tablename              = roottab
        tablekey               = tabkey_wa
      IMPORTING
        key                    = tabkey_struc
      EXCEPTIONS
        WRONG_PARAMETERS       = 1
        KEY_TOO_LARGE          = 2
        FIELDDESCR_ERROR       = 3
        INTERNAL_ERROR         = 4
        OTHERS                 = 5.
    IF sy-subrc NE 0.
      MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
       WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    ASSIGN tabkey_struc TO <tabkey_c> CASTING.
    tabkeys_wa-tabkey = <tabkey_c>.
    MODIFY tabkeys FROM tabkeys_wa INDEX tabix.
  ENDLOOP.
  bc_entry_list_wa-viewname = p_header-maintview.          "HCG 6.8.02
  IF p_header-clidep <> space.
    READ TABLE p_namtab ASSIGNING <namtab>
     WITH KEY datatype = 'CLNT'.
    ASSIGN COMPONENT <namtab>-viewfield
     OF STRUCTURE <table1_wa> TO <clnt>.
  ENDIF.
  IF p_header-bastab = space.
* build up viewkeys and put'em into entry list
***********************************************************************
* viewkey and roottabkey identical?
    PERFORM vim_comp_roottabkey USING p_header
                                      p_namtab
                                CHANGING keys_identical
                                         rc.
    CHECK rc = 0.
    IF keys_identical = space.
      PERFORM vim_get_x030l USING p_header-roottab
                            CHANGING x030l_root
                                     rc.
      CHECK rc = 0.
      CREATE DATA root_entry TYPE (p_header-roottab).
      ASSIGN: root_entry->* TO <roottab>,
              <roottab> TO <roottab_x> CASTING.
    ENDIF.
    INSERT LINES OF tabflags INTO TABLE tabflags_quick.
    LOOP AT tabkeys ASSIGNING <tabkeys_main> WHERE
     tablename = p_header-roottab.
      CLEAR: failed, <table1_wa>.
* get all primary table entries
      bc_entry_list_wa-id = <tabkeys_main>-profid.
      bc_entry_list_wa-recnumber = <tabkeys_main>-recnumber.
      ASSIGN <tabkeys_main>-tabkey TO <tabkey> CASTING.
      IF keys_identical <> space.
* move complete table key to view key
        MOVE <tabkey>(p_header-keylen) TO <f1_wax>.
      ELSE.
* fill view key field by field
        CLEAR: <roottab>.
        MOVE <tabkey>(x030l_root-keylen)
         TO <roottab_x>(x030l_root-keylen).
        LOOP AT p_namtab ASSIGNING <namtab> WHERE keyflag <> space AND
         texttabfld = space.
* build viewkey...
          CHECK <namtab>-datatype <> 'CLNT' OR p_header-clidep = space.
          ASSIGN COMPONENT <namtab>-viewfield
           OF STRUCTURE <table1_wa> TO <viewfld>.
          IF <namtab>-bastabname = p_header-roottab.
* ... from primary table
            ASSIGN COMPONENT <namtab>-bastabfld OF STRUCTURE <roottab>
             TO <rootfld>.
            MOVE <rootfld> TO <viewfld>.
          ELSE.
* ... from secondary table
            failed = 'X'.
            IF NOT <tabkeys> IS ASSIGNED
             OR <tabkeys>-tablename <> <namtab>-bastabname.
              READ TABLE tabkeys ASSIGNING <tabkeys>
               WITH KEY tablename = <namtab>-bastabname
                        recnumber = <tabkeys_main>-recnumber
                        profid = <tabkeys_main>-profid.
              IF sy-subrc <> 0.
                UNASSIGN <tabkeys>.
                EXIT.
              ENDIF.
              PERFORM vim_get_x030l USING <namtab>-bastabname
                                    CHANGING x030l_bastab
                                             rc.
              CHECK rc = 0.
              CREATE DATA bastab_entry TYPE (<namtab>-bastabname).
              ASSIGN: bastab_entry->* TO <bastab>,
                      <bastab> TO <bastab_x> CASTING.
            ENDIF.
            MOVE <tabkey>(x030l_bastab-keylen)
             TO <bastab_x>(x030l_bastab-keylen).
            ASSIGN COMPONENT <namtab>-bastabfld OF STRUCTURE <bastab>
             TO <rootfld>.
            MOVE <rootfld> TO <viewfld>.
            CLEAR failed.
          ENDIF.
        ENDLOOP.
        CHECK failed IS INITIAL.
      ENDIF.
      IF p_header-clidep <> space.
* fill client-field
        MOVE sy-mandt TO <clnt>.
      ENDIF.
      MOVE <f1_wax> TO bc_entry_list_wa-keys.
      REFRESH bc_entry_list_wa-fields.
      LOOP AT p_namtab ASSIGNING <namtab>.
        CHECK <namtab>-datatype <> 'CLNT' OR p_header-clidep = space.
* get bc-set field attributes
        READ TABLE tabflags_quick INTO tabflags_wa WITH KEY
         tablename = p_header-viewname fieldname = <namtab>-viewfield
         bcset_id = bc_entry_list_wa-id
         recnumber = bc_entry_list_wa-recnumber.
        CHECK sy-subrc = 0.
        fields_wa-fieldname = <namtab>-viewfield.
        fields_wa-flag = tabflags_wa-flag.
        APPEND fields_wa TO bc_entry_list_wa-fields.
      ENDLOOP.
      INSERT bc_entry_list_wa INTO TABLE bc_entry_list.
    ENDLOOP.
  ELSE.
* move table keys into entry list
***********************************************************************
    LOOP AT tabkeys ASSIGNING <tabkeys_main> WHERE
     tablename = p_header-viewname.
      bc_entry_list_wa-id = <tabkeys_main>-profid.
      bc_entry_list_wa-recnumber = <tabkeys_main>-recnumber.
      ASSIGN <tabkeys_main>-tabkey TO <tabkey> CASTING.
      MOVE <tabkey>(p_header-keylen) TO <table1_wax>(p_header-keylen).
      IF p_header-clidep <> space.
* fill client-field
        MOVE sy-mandt TO <clnt>.
      ENDIF.
      MOVE <f1_wax> TO bc_entry_list_wa-keys.
* get bc-set field attributes
      LOOP AT tabflags INTO tabflags_wa WHERE ( tablename =
       p_header-viewname OR tablename = p_header-texttab ) AND
       bcset_id = bc_entry_list_wa-id
       AND recnumber = bc_entry_list_wa-recnumber.
        fields_wa-fieldname = tabflags_wa-fieldname.
        fields_wa-flag = tabflags_wa-flag.
        APPEND fields_wa TO bc_entry_list_wa-fields.
      ENDLOOP.
      INSERT bc_entry_list_wa INTO TABLE bc_entry_list.
    ENDLOOP.
  ENDIF.
  SORT bc_entry_list.
* should normally not be necessary:
  DELETE ADJACENT DUPLICATES FROM bc_entry_list.
  DESCRIBE TABLE bc_entry_list.
* changing of fix BC-set-entries?
  CLEAR <status>-bcfixnochg.
  IF sy-tfill > 0.
    INSERT LINES OF bc_entry_list INTO TABLE p_bc_entry_list.
    CALL FUNCTION 'SCPR_AUTHORITY_CHECK'
      EXPORTING
        task             = 'CHGFIXVAL'
      EXCEPTIONS
        wrong_parameters = 1
        no_authority     = 2
        OTHERS           = 3.
    IF sy-subrc <> 0.
      <status>-bcfixnochg = 'N'.
    ELSE.
      <status>-bcfixnochg = 'Y'.
    ENDIF.
  ENDIF.
ENDFORM.                               " VIM_GET_BC_LOGS
*&---------------------------------------------------------------------*
*&      Form  VIM_BC_LOGS_MAINTAIN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_HEADER         Header info of maintenance dialog
*      -->P_BACKGROUND     Flag: 'X' means BC-set import in background
*                                running.
*      <--P_BC_ENTRY_LIST  List of entries coming from BC-set
*----------------------------------------------------------------------*
FORM vim_bc_logs_maintain USING    p_header TYPE vimdesc
                                   p_background TYPE xfeld
                          CHANGING p_bc_entry_list LIKE
                                   vim_bc_entry_list.

  DATA: fields_wa TYPE vimty_fields_type,
        subrc TYPE sy-subrc, tabix TYPE sy-tabix.
  STATICS:       viewname_old TYPE vimdesc-viewname,
                 keylen_real TYPE i.
  FIELD-SYMBOLS: <bc_entry> TYPE vimty_bc_entry_list_type,
                 <key> TYPE x, <namtab> type vimnamtab.

  IF p_background = space.
* bc import running in dialogue
    LOOP AT total.
      CHECK ' N' NS <action>.
      READ TABLE p_bc_entry_list ASSIGNING <bc_entry> WITH KEY
       viewname = p_header-viewname keys = <vim_xtotal_key>.
      CHECK sy-subrc = 0.
      CASE <action>.
        WHEN aendern.
* Rel. 4.6 only: does entry contain fix values?
*          LOOP AT <bc_entry>-fields INTO fields_wa
*           WHERE flag = vim_profile_fix.
*            TRANSLATE <bc_entry>-action USING ' U'.
*            EXIT.
*          ENDLOOP.
        WHEN geloescht.
* deleting bc-set-entry
          CASE <bc_entry>-action.
            WHEN neuer_eintrag.
              <bc_entry>-action = neuer_geloescht.
            WHEN OTHERS.
              <bc_entry>-action = geloescht.
          ENDCASE.
*      WHEN zurueckholen.
** undeleting BC-set-entry --> maintain table of BC-Set-entries
*        CASE <bc_entry>-action.
*          WHEN neuer_geloescht.
*            <bc_entry>-action = neuer_eintrag.
*          WHEN OTHERS.
*            <bc_entry>-action = original.
      ENDCASE.
    ENDLOOP.
  ELSE.
* bc import running in background
    DELETE vim_bc_entry_list WHERE viewname = p_header-viewname.
    PERFORM vim_get_global_table IN PROGRAM saplsvim
                USING 'VIM_BC_ENTRY_LIST'
                       vim_bc_entry_list
                       sy-subrc.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
    IF p_header-viewname NE viewname_old. "HCG: has table align gap?
      viewname_old = p_header-viewname.
      CLEAR keylen_real.
      LOOP AT x_namtab ASSIGNING <namtab> WHERE keyflag = 'X' AND
                                                texttabfld IS INITIAL.
        keylen_real = keylen_real + <namtab>-flength.
      ENDLOOP.
    ENDIF.
    LOOP AT vim_bc_entry_list ASSIGNING <bc_entry> WHERE
     viewname = p_header-viewname.
      ASSIGN <bc_entry>-keys(x_header-keylen) TO <key>.
      IF p_header-keylen = keylen_real.
        READ TABLE total WITH KEY <key> BINARY SEARCH.
        subrc = sy-subrc.
      ELSE.
        PERFORM vim_read_table_with_gap
                    TABLES   total
                    USING    <key>
                             x_namtab[]
                    CHANGING subrc
                             tabix.
        IF subrc = 0.
          READ TABLE total INDEX tabix.
        ENDIF.
      ENDIF.
* bc-set entry really imported?
      IF subrc <> 0 OR 'NU' NS <action>.
        DELETE vim_bc_entry_list.
      ENDIF.
    ENDLOOP.
  ENDIF.
ENDFORM.                               " VIM_BC_LOGS_MAINTAIN
*&---------------------------------------------------------------------*
*&      Form  VIM_BC_LOGS_USE
*&---------------------------------------------------------------------*
*       delivers field attribute defined in BC-sets
*----------------------------------------------------------------------*
*      -->P_FIELD         text
*      -->P_VIM_BC_ENTRY  text
*      <--P_SCREEN_INPUT  text
*      <--P_MODIFY_SCREEN  text
*----------------------------------------------------------------------*
FORM vim_bc_logs_use USING p_field TYPE fieldname
                           p_vim_bc_entry TYPE vimty_bc_entry_list_type
                     CHANGING p_screen LIKE screen
                              p_modify_screen TYPE xfeld.

  DATA w_field TYPE vimty_fields_type.

  READ TABLE p_vim_bc_entry-fields INTO w_field
   WITH TABLE KEY fieldname = p_field.
  CHECK sy-subrc = 0.
  IF w_field-flag = vim_profile_fix.
    p_screen-input = 0.
    p_modify_screen = 'X'.
  ENDIF.
ENDFORM.                               " VIM_BC_LOGS_USE
*&---------------------------------------------------------------------*
*&      Form  vim_chng_fix_flds
*&---------------------------------------------------------------------*
*       make fix values form bc-sets modifiable
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM vim_chng_fix_flds.
  IF <status>-bcfixnochg = 'Y'.
    vim_bc_chng_allowed = 'X'.
  ELSE.
    MESSAGE e202(sv).
*   Sie haben keine Berechtigung, Felder mit fixen BC-Set-Werten zu ände
  ENDIF.
ENDFORM.                               " vim_chng_fix_flds
*&---------------------------------------------------------------------*
*&      Form  vim_get_x030l
*&---------------------------------------------------------------------*
*       Delivers X030l fron dictionary.
*----------------------------------------------------------------------*
*      -->P_TABNAME     tablename
*      <--P_X030L
*      <--P_RC
*----------------------------------------------------------------------*
FORM vim_get_x030l  USING    p_tabname TYPE tabname
                    CHANGING p_x030l TYPE x030l
                             p_rc LIKE sy-subrc.
  CALL FUNCTION 'DDIF_NAMETAB_GET'
    EXPORTING
      tabname  = p_tabname
    IMPORTING
      x030l_wa = p_x030l
    EXCEPTIONS
      OTHERS   = 1.
  p_rc = sy-subrc.
ENDFORM.                    " vim_get_x030l
*&---------------------------------------------------------------------*
*&      Form  vim_bc_show_fix_flds
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM vim_bc_show_fix_flds.
DATA: p_tabtype TYPE objh-objecttype,
      p_tabname TYPE scpr_tabl.

  p_tabname = x_header-maintview. "HCG 6.8.02 actlinks for maintview
  if x_header-bastab = space.
    p_tabtype = 'V'.
  ELSE.
    p_tabtype = 'S'.
  ENDIF.
  LOOP AT extract.
    IF <xmark> NE markiert.
      CONTINUE.
    ELSE.
      MOVE <vim_extract_struc> TO <table1>.
      CALL FUNCTION 'SCPR_ACTIVATION_INFOS_SHOW'
        EXPORTING
          tablename     = p_tabname
          tabletype     = p_tabtype
          record        = <table1>
        EXCEPTIONS
          FIELDDEFINITION_ERROR  = 1
          NO_TVDIR_ENTRY         = 2
          TABLE_NOT_FOUND        = 3
          TABLE_TO_LARGE         = 4
          DDIF_INTERNAL_ERROR    = 5
          WRONG_PARAMETERS       = 6
          INTERNAL_ERROR         = 7
          NO_ACTLINKS            = 8
          KEY_TOO_LARGE          = 9
          OTHERS                 = 10.
      case sy-subrc.
        when 0.
        when 1.
          message e395(SCPR) raising FIELDDEFINITION_ERROR.
        when 2.
          message e028(SCPR) with p_tabname raising NO_TVDIR_ENTRY.
        when 3.
          message e120(SCPR) with p_tabname raising TABLE_NOT_FOUND.
        when 4.
          message e026(SCPR) with p_tabname raising TABLE_TO_LARGE.
        when 5.
          message e035(SCPR) raising DDIF_INTERNAL_ERROR.
        when 6.
          message e273(SCPR) raising WRONG_PARAMETERS.
        when 8.
          message s399(SCPR) raising NO_ACTLINKS.
        when 9.
          message e408(SCPR) raising KEY_TOO_LARGE.
        when others.
          message e320(SCPR) raising INTERNAL_ERROR.
      endcase.
    ENDIF.
  ENDLOOP.
ENDFORM.                    " vim_bc_show_fix_flds
*&---------------------------------------------------------------------*
*&      Form  vim_build_bc_tabkeys
*&---------------------------------------------------------------------*
*   To build up table keys for views with keylen > 120 up to 256
*   and / or non-character like fields.
*----------------------------------------------------------------------*
*      <--P_BC_KEYTAB  text
*----------------------------------------------------------------------*
FORM vim_build_bc_tabkeys USING bc_entry_list_wa TYPE
                                       vimty_bc_entry_list_type
                       CHANGING p_bc_keytab TYPE bc_keytab_type.

  TYPES: BEGIN OF tablist_type,
           tabname TYPE objs-tabname,
         END OF tablist_type.

  STATICS: cg_dd28j_tab LIKE dd28j OCCURS 30,
           old_viewname LIKE vimdesc-viewname,
           all_dfiestab LIKE dfies OCCURS 40.

  DATA: objstablist TYPE TABLE OF tablist_type,
        namtab_wa TYPE vimnamtab,
        tabname_wa TYPE objs-tabname,
        dd28j_wa LIKE LINE OF cg_dd28j_tab,
        primtab_entry TYPE REF TO data,
        sektab_entry TYPE REF TO data,
        p_bc_keytab_wa LIKE LINE OF p_bc_keytab,
        keytab_index TYPE sy-tabix,
        bc_keylen TYPE i, flag(1) TYPE c,
        cg_langu(1) TYPE c,
        cg_dfiestab LIKE dfies OCCURS 10,
        dfies_wa LIKE LINE OF cg_dfiestab,
        piecelist TYPE TABLE OF objs-tabname,
        foreign_langu LIKE sy-langu,
        langu_fieldname TYPE dfies-fieldname,
        p_bc_keytab_langu TYPE bc_keytab_type,
        w_bc_entry_list TYPE vimty_bc_entry_list_type.

  FIELD-SYMBOLS: <primtab> TYPE ANY, <sektab> TYPE ANY,
                 <viewfld> TYPE ANY,
                 <primtabfld> TYPE ANY, <sektabfld> TYPE ANY,
                 <bc_tabkey> TYPE bc_key_type-bc_tabkey,
                 <tabkey_x> TYPE x, <tabkey_struc_x> TYPE x.

  IF x_header-viewname NE old_viewname.
    old_viewname = x_header-viewname.
    CALL FUNCTION 'DDIF_VIEW_GET'
      EXPORTING
        name          = x_header-viewname
        state         = 'A'
        langu         = sy-langu
      IMPORTING
        gotstate      = flag
      TABLES
        dd28j_tab     = cg_dd28j_tab
      EXCEPTIONS
        illegal_input = 1
        OTHERS        = 2.
    IF sy-subrc <> 0.
      MESSAGE e164(sv) WITH tabname_wa RAISING view_not_found.
    ENDIF.
    IF flag = space.
      MESSAGE e306(sv) WITH tabname_wa RAISING view_not_found.
    ENDIF.
*   Get tables from piecelist
    SELECT tabname FROM objs INTO tabname_wa
                       WHERE objectname = x_header-viewname
                         AND objecttype = 'V'.
      APPEND tabname_wa TO piecelist.
    ENDSELECT.
    REFRESH all_dfiestab.
    LOOP AT piecelist INTO tabname_wa.
      REFRESH cg_dfiestab.
      CALL FUNCTION 'DDIF_NAMETAB_GET'
        EXPORTING
          tabname   = tabname_wa
        TABLES
          dfies_tab = cg_dfiestab[]
        EXCEPTIONS
          not_found = 1
          OTHERS    = 2.
      IF sy-subrc NE 0.
        MESSAGE e028(sv) WITH tabname_wa RAISING view_not_found.
      ENDIF.
      LOOP AT cg_dfiestab INTO dfies_wa.
        APPEND dfies_wa TO all_dfiestab.
      ENDLOOP.
    ENDLOOP.
  ENDIF.
  LOOP AT p_bc_keytab INTO p_bc_keytab_wa.
    keytab_index = sy-tabix.
    IF p_bc_keytab_wa-objname = x_header-roottab.
*-----Build tabkey for root-table from viewkey-------------------------
      CREATE DATA primtab_entry TYPE (x_header-roottab).
      ASSIGN primtab_entry->* TO <primtab>.
      LOOP AT x_namtab WHERE keyflag = 'X' AND
                           bastabname = x_header-roottab.
        ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE
                   <vim_total_struc> TO <viewfld>.
        ASSIGN COMPONENT x_namtab-bastabfld OF STRUCTURE <primtab>
                   TO <primtabfld>.
        MOVE <viewfld> TO <primtabfld>.
      ENDLOOP.                 " Primtabkey completely in <primtab>
      PERFORM vim_get_bc_keylen    "Analog corr_maint_>>viewname<<
              USING x_header-roottab
           CHANGING bc_keylen.
      ASSIGN <primtab> TO <tabkey_struc_x> CASTING.
      ASSIGN p_bc_keytab_wa-bc_tabkey TO <tabkey_x> CASTING.
      MOVE <tabkey_struc_x>(bc_keylen) TO <tabkey_x>(bc_keylen).
      MODIFY p_bc_keytab INDEX keytab_index FROM p_bc_keytab_wa.
    ELSEIF p_bc_keytab_wa-objname EQ x_header-texttab.
*-----Build tabkeys for textable of view from viewkey field by field---
      REFRESH p_bc_keytab_langu.
      tabname_wa = p_bc_keytab_wa-objname.
      CREATE DATA sektab_entry TYPE (tabname_wa).
      ASSIGN sektab_entry->* TO <sektab>.
      PERFORM vim_get_bc_keylen    "Analog corr_maint_>>viewname<<
                  USING tabname_wa
                  CHANGING bc_keylen.
      LOOP AT all_dfiestab INTO dfies_wa WHERE tabname = tabname_wa
                                          AND keyflag = 'X'.
        CLEAR cg_langu.
        READ TABLE cg_dd28j_tab WITH KEY rtab = tabname_wa
                                       rfield = dfies_wa-fieldname
                                    INTO dd28j_wa.
        IF sy-subrc EQ 0.
          READ TABLE x_namtab WITH KEY bastabname = dd28j_wa-ltab
                                        bastabfld = dd28j_wa-lfield.
        ELSE.       "Field not in join -> additional keyfield in view
          READ TABLE x_namtab WITH KEY bastabname = tabname_wa
                                    bastabfld = dfies_wa-fieldname.
          IF sy-subrc NE 0.    "Then it must be langu field of texttab
            cg_langu = 'X'.
          ENDIF.
        ENDIF.
        IF cg_langu EQ space.                 "Field is not langu field
          ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE
                     <vim_total_struc> TO <viewfld>.
          ASSIGN COMPONENT dfies_wa-fieldname OF STRUCTURE
                                           <sektab> TO <sektabfld>.
          MOVE <viewfld> TO <sektabfld>.
        ELSE.                                     "Field is langu field
          langu_fieldname = dfies_wa-fieldname.
          ASSIGN COMPONENT dfies_wa-fieldname OF STRUCTURE
                                           <sektab> TO <sektabfld>.
          MOVE sy-langu TO <sektabfld>.
        ENDIF.
        ASSIGN <sektab> TO <tabkey_struc_x> CASTING.
        ASSIGN p_bc_keytab_wa-bc_tabkey TO <tabkey_x> CASTING.
        MOVE <tabkey_struc_x>(bc_keylen) TO <tabkey_x>(bc_keylen).
      ENDLOOP.
      MODIFY p_bc_keytab INDEX keytab_index FROM p_bc_keytab_wa.
*     Look for other languages in bc-set and append to p_bc_keytab too
      ASSIGN COMPONENT langu_fieldname OF STRUCTURE
                                           <sektab> TO <sektabfld>.
      LOOP AT bc_entry_list_wa-forlangu INTO foreign_langu.
        MOVE foreign_langu TO <sektabfld>.
        MOVE <tabkey_struc_x>(bc_keylen) TO <tabkey_x>(bc_keylen).
        APPEND p_bc_keytab_wa TO p_bc_keytab_langu.
      ENDLOOP.
    ELSE.
*-----Build tabkeys for secondary tabs from viewkey field by field-----
      tabname_wa = p_bc_keytab_wa-objname.
      CREATE DATA sektab_entry TYPE (tabname_wa).
      ASSIGN sektab_entry->* TO <sektab>.
      PERFORM vim_get_bc_keylen    "Analog corr_maint_>>viewname<<
                  USING tabname_wa
                  CHANGING bc_keylen.
      LOOP AT all_dfiestab INTO dfies_wa WHERE tabname = tabname_wa
                                          AND keyflag = 'X'.
        CLEAR cg_langu.
        READ TABLE cg_dd28j_tab WITH KEY rtab = tabname_wa
                                       rfield = dfies_wa-fieldname
                                    INTO dd28j_wa.
        IF sy-subrc EQ 0.
          READ TABLE x_namtab WITH KEY bastabname = dd28j_wa-ltab
                                        bastabfld = dd28j_wa-lfield.
        ELSE.       "Field not in join -> additional keyfield in view
          READ TABLE x_namtab WITH KEY bastabname = tabname_wa
                                    bastabfld = dfies_wa-fieldname.
          IF sy-subrc NE 0.                 "Then it must be an error
*            error.!!!!
          ENDIF.
        ENDIF.
        ASSIGN COMPONENT x_namtab-viewfield OF STRUCTURE
                   <vim_total_struc> TO <viewfld>.
        ASSIGN COMPONENT dfies_wa-fieldname OF STRUCTURE
                                         <sektab> TO <sektabfld>.
        MOVE <viewfld> TO <sektabfld>.
        ASSIGN <sektab> TO <tabkey_struc_x> CASTING.
        ASSIGN p_bc_keytab_wa-bc_tabkey TO <tabkey_x> CASTING.
        MOVE <tabkey_struc_x>(bc_keylen) TO <tabkey_x>(bc_keylen).
      ENDLOOP.
      MODIFY p_bc_keytab INDEX keytab_index FROM p_bc_keytab_wa.
    ENDIF.
  ENDLOOP.
  APPEND LINES OF p_bc_keytab_langu TO p_bc_keytab.
ENDFORM.                    " vim_build_bc_tabkeys
*&---------------------------------------------------------------------*
*&      Form  vim_read_table_with_gap
*&---------------------------------------------------------------------*
*       Implementierung des
*         READ TABLE <it_data> WITH KEY <key> BINARY SEARCH
*       für Tabellen mit Alignment-Lücken (Nicht-Character-Feld wie
*       z.B. ein INT4-Feld im Schlüssel)
*
*       Voraussetzung zum Aufruf: gap_table ist sortiert
*
*       Rückgabewert: SUBRC = 0    1. Datensatz passend zum KEY
*       (analog                    wurde gefunden (wichtig für
*        BINARY                    BC-Sets mit Schlüsselkonflikt)
*        SEARCH)                   Datensatznummer in TABIX
*
*                     SUBRC = 4    Eintrag wurde nicht gefunden
*                                  Datensatznummer + 1 in TABIX
*
*                     SUBRC = 8    Eintrag wurde nicht gefunden
*                                  Letzte Datensatznummer + 1 in TABIX
*----------------------------------------------------------------------*
*     To use function SCPR_CTRL_CT_COMP_TWO_RECORDS table of field
*     description in SCPR format is created and filled partly.
*----------------------------------------------------------------------*
FORM vim_read_table_with_gap TABLES   gap_table
                         USING    key   TYPE x
                                  namtab LIKE x_namtab[]
                         CHANGING subrc TYPE sy-subrc
                                  tabix TYPE sy-tabix.

  TYPES: scpr_x8192(8192) TYPE x.
  DATA: result  TYPE scpr_txt20,
        tab_i   TYPE sy-tabix,
        tab_j   TYPE sy-tabix,
        tab_k   TYPE sy-tabix,
        tab_len TYPE sy-tabix.

  DATA: align TYPE f, wa_8192 TYPE scpr_x8192,
        it_fldnames TYPE STANDARD TABLE OF scpr_flddescr,
        fldnames_wa LIKE LINE OF it_fldnames,
        gap_table_wa(2048) TYPE c.
  FIELD-SYMBOLS: <wa_it_data> TYPE x,
                 <namtab> TYPE vimnamtab.

* Fill necessary fields in it_fieldnames from namtab
  LOOP AT namtab ASSIGNING <namtab> WHERE keyflag = 'X'
                                    AND texttabfld = space.
    fldnames_wa-fieldname = <namtab>-viewfield.
    fldnames_wa-position = <namtab>-position.
    fldnames_wa-intlen = <namtab>-flength.
    fldnames_wa-keyflag = 'X'.
    fldnames_wa-flag = 'FKY'. "KEY would do the same job...
    APPEND fldnames_wa TO it_fldnames.
  ENDLOOP.

  DESCRIBE TABLE gap_table LINES tab_len.
  tab_i = 1.
  tab_j = tab_len.
  subrc = 8.
  tabix = tab_len + 1.
  ASSIGN wa_8192 TO <wa_it_data>.
  ASSIGN gap_table_wa TO <wa_it_data> CASTING.

  DO.
    IF tab_i > tab_j.
*     Datensatz wurde nicht gefunden
      subrc = 4.
      tabix = tab_k + 1.
      EXIT.
    ENDIF.
    tab_k = ( tab_i + tab_j ) / 2.

    READ TABLE gap_table INTO gap_table_wa INDEX tab_k.

    CALL FUNCTION 'SCPR_CTRL_CT_COMP_TWO_RECORDS'
      EXPORTING
        cu_lines    = <wa_it_data>
        bc_lines    = key
        compare_key = 'X'
      IMPORTING
        RESULT      = RESULT
      tables
        it_fldnames = it_fldnames.

    IF result = 'LT'.
      tab_j = tab_k - 1.
    ELSEIF result = 'GT'.
      tab_i = tab_k + 1.
    ELSE.
      subrc = 0.
      tabix = tab_k.
      EXIT.
    ENDIF.
  ENDDO.
ENDFORM.                    " read_table_with_gap
*----------------------------------------------------------------------*
***INCLUDE LSVIMF5B .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  CHECK_LIST_BEFORE_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM check_list_before_alv CHANGING rc LIKE sy-subrc.

  DATA:          counter TYPE i, index type i,
                 variant LIKE disvariant,
                 fcat_var TYPE slis_t_fieldcat_alv.
  FIELD-SYMBOLS: <fcat> TYPE slis_fieldcat_alv.
  CONSTANTS:     alv_maxcols TYPE i VALUE 99.

  CLEAR: counter, rc.
  LOOP AT vim_alv_fcat TRANSPORTING NO FIELDS WHERE no_out <> 'X'.
    ADD 1 TO counter.
  ENDLOOP.
  CHECK counter > alv_maxcols.
* suitable standard variant defined?
  CONCATENATE x_header-viewname sy-repid INTO variant-report.
  CALL FUNCTION 'REUSE_ALV_VARIANT_SELECT'
       EXPORTING
            i_dialog            = space
            i_user_specific     = 'X'
            i_default           = 'X'  "vim_var_default
*         I_TABNAME_HEADER    =
*         I_TABNAME_ITEM      =
            it_default_fieldcat = vim_alv_fcat
            i_layout            = vim_alv_layout
       IMPORTING
*         E_EXIT              =
            et_fieldcat         = fcat_var
*         ET_SORT             =
*         ET_FILTER           =
            es_layout           = vim_alv_layout
       CHANGING
            cs_variant          = variant
       EXCEPTIONS
            wrong_input         = 1
            fc_not_complete     = 2
            not_found           = 3
            program_error       = 4
            OTHERS              = 5.
  IF sy-subrc = 0 AND NOT variant-variant IS INITIAL.
    CLEAR: counter.
    LOOP AT fcat_var TRANSPORTING NO FIELDS WHERE no_out <> 'X'.
      ADD 1 TO counter.
    ENDLOOP.
    CHECK counter > alv_maxcols.
  ENDIF.
* no variant with less than 99 columns exists
*  WHILE counter > alv_maxcols.
*    MESSAGE i807(sv) WITH counter.
**    Bitte wählen Sie max. 99 Felder für die Liste aus.
*    CALL FUNCTION 'REUSE_ALV_VARIANT_MAINTAIN'
*         EXPORTING
**         I_TABNAME_HEADER  =
**         I_TABNAME_ITEM    =
*              i_save            = vim_var_save
**         I_POPUP           = 'X'
*              is_layout         = vim_alv_layout
**         IT_SPECIAL_GROUPS =
**         IT_SORT           =
**    IMPORTING
**         E_SAVE            =
*         CHANGING
*              ct_fieldcat       = vim_alv_fcat
*         EXCEPTIONS
*              no_change         = 1
**         PROGRAM_ERROR     = 2
*              OTHERS            = 3.
*    rc = sy-subrc.
*    IF rc <> 0. EXIT. ENDIF.
*    CLEAR counter.
*    LOOP AT vim_alv_fcat TRANSPORTING NO FIELDS WHERE no_out <> 'X'.
*      ADD 1 TO counter.
*    ENDLOOP.
**    check counter < alv_maxcols.
** field catalogue changed => rearrange value tab
*>>>>Complete field catalogue needs to be rearranged here: too lavish
*>>>>for this rare case. Let's try an easier attempt at first.
*  ENDWHILE.
  MESSAGE i808(sv) with COUNTER.
*   Es können nicht alle Spalten der Tabelle auf der Liste angezeigt wer
  index = alv_maxcols + 1.
  LOOP AT vim_alv_fcat ASSIGNING <fcat> FROM index.
    <fcat>-no_out = 'X'.
  ENDLOOP.
ENDFORM.                               " CHECK_LIST_BEFORE_ALV
*----------------------------------------------------------------------*
***INCLUDE LSVIMF5C .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  VIM_SET_OC
*&---------------------------------------------------------------------*
*       Called from external to create reference to organisation
*       criterion
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM vim_set_oc USING value(p_obj)
                       TYPE REF TO cl_viewfields_org_crit.

  clear vim_oc_inst.
  check not p_obj is initial.
  vim_oc_inst = p_obj.
ENDFORM.                               " VIM_SET_GLOBAL_OBJECT

*----------------------------------------------------------------------*
*   INCLUDE LSVIMF5D                                                   *
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  VIM_MAINT_SELFLAG
*&---------------------------------------------------------------------*
*       Sets or resets X_HEADER-SELECTION and keeps initial value
*       Purpose: additional check vs. sellist in form
*       CHECK_DYNAMIC_SELECT_OPTIONS
*----------------------------------------------------------------------*
*      -->mode   S = set flag to 'X', I = initialize,
*                R = get and reset to initial value
*      <--p_selflag value of X_HEADER-SELECTION
*----------------------------------------------------------------------*
FORM vim_maint_selflag USING    value(p_mode) TYPE sychar01
                   CHANGING p_selflag     TYPE xfeld.

  STATICS: init_val TYPE xfeld.

  CASE p_mode.
    WHEN 'I'.
      init_val = p_selflag.
    WHEN 'S'.
      x_header-selection = 'X'.
    WHEN 'R'.
      p_selflag = x_header-selection.
      x_header-selection = init_val.
  ENDCASE.
ENDFORM.                               " VIM_MAINT_SELFLAG
*----------------------------------------------------------------------*
*   INCLUDE LSVIMF5E                                                   *
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  vim_make_guid
*&---------------------------------------------------------------------*
*       Sets GUID values in a dataset. Only used if a new entry is
*       created. If p_viewfield is set, only one GUID is filled.
*----------------------------------------------------------------------*
*  -->  p_viewfield   Name of GUID field in table/view
*  <--  p2        text
*----------------------------------------------------------------------*
FORM vim_make_guid USING p_viewfield TYPE viewfield.

  DATA: fieldname TYPE fnam_____4,
        old_guid TYPE REF TO data.
  FIELD-SYMBOLS: <x_namtab> TYPE vimnamtab, <guid> TYPE ANY,
                 <old_guid> TYPE ANY, <work_area> TYPE ANY.

  IF p_viewfield = space.
* set all GUIDs in structure
    LOOP AT x_namtab ASSIGNING <x_namtab> WHERE keyflag = space
     AND bastabname <> x_header-texttab AND domname IN vim_guid_domain.
* non-key and non-textfields only
      CONCATENATE x_header-maintview <x_namtab>-viewfield
       INTO fieldname SEPARATED BY '-'.
      ASSIGN (fieldname) TO <guid> CASTING TYPE (fieldname).
      IF <status>-prof_found = vim_pr_into_view
* importing BC-set manually
       OR vim_import_profile <> space
* importing BC-set in background
       OR vim_special_mode = vim_upgrade.
* importing from remote system/client
        CHECK <guid> IS INITIAL.
      ENDIF.
      CREATE DATA old_guid TYPE (fieldname).
      ASSIGN old_guid->* TO <old_guid>.
      CASE <x_namtab>-domname.
        WHEN 'SYSUUID'.
          ASSIGN (fieldname) TO <guid> CASTING TYPE guid_16.
          MOVE <guid> TO <old_guid>.
          CALL FUNCTION 'GUID_CREATE'
               IMPORTING
                    ev_guid_16 = <guid>.
        WHEN 'SYSUUID_C'.
          ASSIGN (fieldname) TO <guid> CASTING TYPE guid_32.
          MOVE <guid> TO <old_guid>.
          CALL FUNCTION 'GUID_CREATE'
               IMPORTING
                    ev_guid_32 = <guid>.
        WHEN 'SYSUUID_22'.
          ASSIGN (fieldname) TO <guid> CASTING TYPE guid_22.
          MOVE <guid> TO <old_guid>.
          CALL FUNCTION 'GUID_CREATE'
               IMPORTING
                    ev_guid_22 = <guid>.
        WHEN 'SYSUUID_25'.
          ASSIGN (fieldname) TO <guid> CASTING TYPE rssguid25.
          MOVE <guid> TO <old_guid>.
          CALL FUNCTION 'RSS_SYSTEM_GET_UNIQUE_ID'
               IMPORTING
                    e_uni_idc25 = <guid>.
      ENDCASE.
      IF x_header-frm_af_uid <> space.
        ASSIGN (x_header-maintview) TO <work_area>
         CASTING TYPE (x_header-maintview).
        PERFORM (x_header-frm_af_uid) IN PROGRAM (x_header-fpoolname)
                                      USING <old_guid>
                                      CHANGING <guid>
                                               <work_area>.
      ENDIF.
    ENDLOOP.
  ELSE.
* set GUID for p_viewfield only
    READ TABLE x_namtab ASSIGNING <x_namtab>
     WITH KEY viewfield = p_viewfield.
    CHECK sy-subrc = 0 AND <x_namtab>-domname IN vim_guid_domain.
* non-key and non-textfields only
    CONCATENATE x_header-maintview <x_namtab>-viewfield
     INTO fieldname SEPARATED BY '-'.
    ASSIGN (fieldname) TO <guid> CASTING TYPE (fieldname).
    IF <status>-prof_found = vim_pr_into_view
* importing BC-set manually
     OR vim_import_profile <> space
* importing BC-set in background
     OR vim_special_mode = vim_upgrade.
* importing from remote system/client
      CHECK <guid> IS INITIAL.
    ENDIF.
    CREATE DATA old_guid TYPE (fieldname).
    ASSIGN old_guid->* TO <old_guid>.
    CASE <x_namtab>-domname.
      WHEN 'SYSUUID'.
        ASSIGN (fieldname) TO <guid> CASTING TYPE guid_16.
        MOVE <guid> TO <old_guid>.
        CALL FUNCTION 'GUID_CREATE'
             IMPORTING
                  ev_guid_16 = <guid>.
      WHEN 'SYSUUID_C'.
        ASSIGN (fieldname) TO <guid> CASTING TYPE guid_32.
        MOVE <guid> TO <old_guid>.
        CALL FUNCTION 'GUID_CREATE'
             IMPORTING
                  ev_guid_32 = <guid>.
      WHEN 'SYSUUID_22'.
        ASSIGN (fieldname) TO <guid> CASTING TYPE guid_22.
        MOVE <guid> TO <old_guid>.
        CALL FUNCTION 'GUID_CREATE'
             IMPORTING
                  ev_guid_22 = <guid>.
      WHEN 'SYSUUID_25'.
        ASSIGN (fieldname) TO <guid> CASTING TYPE rssguid25.
        MOVE <guid> TO <old_guid>.
        CALL FUNCTION 'RSS_SYSTEM_GET_UNIQUE_ID'
             IMPORTING
                  e_uni_idc25 = <guid>.
    ENDCASE.
    IF x_header-frm_af_uid <> space.
      ASSIGN (x_header-maintview) TO <work_area>
       CASTING TYPE (x_header-maintview).
      PERFORM (x_header-frm_af_uid) IN PROGRAM (x_header-fpoolname)
                                    USING <old_guid>
                                    CHANGING <guid>
                                             <work_area>.
    ENDIF.
  ENDIF.
ENDFORM.                               " vim_make_guid
*----------------------------------------------------------------------*
***INCLUDE LSVIMF5F .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&  Include           LSVIMF60                                         *
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  vim_maintain_single_set
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM vim_maintain_single_set.
  Data: msgno like sy-msgno.

  IF vim_single_entry_function EQ space AND
     ( function NE 'DELE' AND function NE 'SAVE' ).       "HWR
      IF vim_oc_inst IS INITIAL.
        msgno = '005'.
      ELSE.
        READ TABLE dpl_sellist WITH KEY from_auth = space
         TRANSPORTING NO FIELDS.
        IF sy-subrc = 0.
          msgno = '005'.
        ELSE.
          msgno = '766'.
*   Eingeschränkte Anzeige von Datensätzen.
        ENDIF.
      ENDIF.
    PERFORM vim_send_sv005_or_sv766 USING msgno
                                          'SENDIT'.
  ENDIF.                                                  "HWR
  IF status-type EQ zweistufig AND function NE 'ABR '
     AND function NE 'KOPF'
     AND function NE 'IGN '."SW: nicht ex. Status ZCDGM (1211787/98)
    <status>-firstline = <status>-cur_line = nextline.
    function = 'DETA'.
    IF x_header-delmdtflag NE space.
      TRANSLATE vim_no_mainkey_exists USING
                                        vim_no_mkey_not_procsd_patt.
    ENDIF.
    PERFORM process_detail_screen USING 'S'.
  ENDIF.
ENDFORM.                    " vim_maintain_single_set
*&---------------------------------------------------------------------*
*&      Form  vim_send_sv005_or_sv766
*&---------------------------------------------------------------------*
*       Send messages only once unless status has not been resetted
*----------------------------------------------------------------------*
*      -->P_MSGNO Message number to be sent as s-message
*      -->P_MODE  SENDIT: Send S-Message if it hasn't been sent before.
*                 RESET:  Reset status.
*----------------------------------------------------------------------*
FORM vim_send_sv005_or_sv766  USING p_msgno like sy-msgno
                                    p_mode TYPE char6.

  STATICS: sent_already TYPE xfeld,
           viewname TYPE viewname.

  IF viewname <> x_header-viewname.
    viewname = x_header-viewname.
    CLEAR sent_already.
  ENDIF.
  CASE p_mode.
    WHEN 'SENDIT'.
      CHECK sent_already = space.
      sent_already = 'X'.
      MESSAGE ID 'SV' TYPE 'S' NUMBER p_msgno.
    WHEN 'RESET'.
      CLEAR sent_already.
  ENDCASE.
ENDFORM.                    " vim_send_sv005_or_sv766
*&---------------------------------------------------------------------*
*&  Include           LSVIMF61
**&---------------------------------------------------------------------
*
*&---------------------------------------------------------------------*
*&      Form  MAP_TEXTTABKEY_TO_VIEWKEY
*&---------------------------------------------------------------------*
* Texttabellen-Schlüssel aus Transportauftrag in zugehörigen
* View-/Primärtabellenschlüssel transformieren
*----------------------------------------------------------------------*
* --> NAMTAB
* --> HEADER
* --> TEXTTABKEY     Importschlüssel der Texttabelle
*$$$ Release 5.0: included in HEADER $$$
* --> SPRASFDPOS     Offset des Sprachenschlüssels
*$$$
* --> TEXTTAB_KEYLEN Länge des zu berücksichtigenden Schlüsselteils
*                    (i.A. tatsächliche Schlüssellänge,
*                    bei generischem Transport: nichtgen. Schlüsselteil)
* --> IS_GENERIC_KEY 'X' => Texttabellen-Schlüssel is generisch
*
* <-- VIEWKEY        View/Primärtabellenschlüssel
* <-- MAP_ERROR      'X' -> Fehler bei der Abb., VIEWKEY nicht gefüllt
*                    (nur bei GENKEY = 'X' relevant)
*----------------------------------------------------------------------*
FORM map_texttabkey_to_viewkey TABLES namtab STRUCTURE vimnamtab
                               USING  header TYPE vimdesc
                                      texttabkey TYPE x
                                      texttab_keylen TYPE syfleng
                                      is_generic_key TYPE xfeld
                               CHANGING viewkey TYPE x
                                        map_error.
  DATA: o1 TYPE i, o2 TYPE i,
        t_keylen TYPE i, l TYPE i, h_viewkey TYPE tabl8000.
  FIELD-SYMBOLS: <namtab> TYPE vimnamtab,
                 <texttab_struc> TYPE ANY,
                 <texttab_fld> TYPE ANY,
                 <txt_struc> TYPE ANY,
                 <viewfld> TYPE ANY.

  CLEAR: map_error, viewkey.

  ASSIGN: texttabkey TO <texttab_struc> CASTING TYPE (header-texttab),
          h_viewkey TO <txt_struc> CASTING TYPE (header-maintview).
  MOVE viewkey TO h_viewkey.
  IF is_generic_key = space.
*  IF is_generic_key = space.
    LOOP AT namtab ASSIGNING <namtab>
      WHERE keyflag <> space AND txttabfldn <> space.
      ASSIGN: COMPONENT <namtab>-viewfield OF STRUCTURE <txt_struc>
               TO <viewfld>,
              COMPONENT <namtab>-txttabfldn
               OF STRUCTURE <texttab_struc> TO <texttab_fld>.
      <viewfld> = <texttab_fld>.
    ENDLOOP.
  ELSE.
    IF header-sprasfdpos < texttab_keylen.
* Sprache im nichtgen. Teil
      t_keylen = texttab_keylen - vim_spras_length.
    ELSE.
      t_keylen = texttab_keylen.
    ENDIF.
    LOOP AT namtab ASSIGNING <namtab>
*      WHERE keyflag = space AND texttabfld = 'X'.
      WHERE keyflag <> space AND txttabfldn <> space.
      o1 = <namtab>-position + <namtab>-flength.
      o2 = <namtab>-texttabpos + <namtab>-flength.
      ASSIGN: COMPONENT <namtab>-viewfield OF STRUCTURE <txt_struc>
               TO <viewfld>,
              COMPONENT <namtab>-txttabfldn
               OF STRUCTURE <texttab_struc> TO <texttab_fld>.
      IF o1 <= t_keylen AND o2 <= texttab_keylen.
        <viewfld> = <texttab_fld>.
      ELSEIF o1 > t_keylen AND o2 > texttab_keylen. "gen. Teil
        IF <namtab>-position < t_keylen
         AND <namtab>-texttabpos < texttab_keylen
         AND 'CNDT' CS <namtab>-inttype.
          l = ( texttab_keylen - <namtab>-texttabpos )
              DIV cl_abap_char_utilities=>charsize.
          <viewfld>(l) = <texttab_fld>(l).
        ENDIF.
      ELSE.
        map_error = 'X'. EXIT.
      ENDIF.
    ENDLOOP.
  ENDIF.
  MOVE h_viewkey TO viewkey.
*  LOOP AT namtab WHERE keyflag = 'X' AND txttabfldn <> space.
*    IF is_generic_key = space.
*      viewkey+namtab-position(namtab-flength) =
*         texttabkey+namtab-texttabpos(namtab-flength).
*    ELSE.
*      IF sprasfdpos < texttab_keylen.   "Sprache im nichtgen. Teil
*        t_keylen = texttab_keylen - vim_spras_length.
*      ELSE.
*        t_keylen = texttab_keylen.
*      ENDIF.
*      o1 = namtab-position + namtab-flength.
*      o2 = namtab-texttabpos + namtab-flength.
*      IF o1 <= t_keylen AND o2 <= texttab_keylen.
*        viewkey+namtab-position(namtab-flength) =
*          texttabkey+namtab-texttabpos(namtab-flength).
*      ELSEIF o1 > t_keylen AND o2 > texttab_keylen. "gen. Teil
*        IF namtab-position < t_keylen AND
*           namtab-texttabpos < texttab_keylen.
*          l = texttab_keylen - namtab-texttabpos.
*          viewkey+namtab-position(l) = texttabkey+namtab-texttabpos(l).
*        ENDIF.
*      ELSE.
*        map_error = 'X'. EXIT.
*      ENDIF.
*    ENDIF.
*  ENDLOOP.
ENDFORM.                    " MAP_TEXTTABKEY_TO_VIEWKEY

*&--------------------------------------------------------------------*
*&      Form  MAP_VIEWKEY_TO_TEXTTABKEY                               *
*&--------------------------------------------------------------------*
* Schlüssel von Texttabelle anhand des View-/Tabellenschlüssels und
* der Sprache zusammensetzen
*&--------------------------------------------------------------------*
* --> X_NAMTAB
* --> VIEW_WA  WA of view                                             *
* --> SPRAS    Sprachschlüssel                                        *
* <-- TEXT_WA  Key of text table                                      *
*&--------------------------------------------------------------------*
FORM map_viewkey_to_texttabkey TABLES namtab STRUCTURE vimnamtab
                                USING header TYPE vimdesc
                                      spras LIKE t002-spras
                                      view_wa TYPE x
                             CHANGING text_wa TYPE x.

  DATA: align type f,
        h_view_wa type tabl8000,
        h_texttab_wa TYPE tabl8000.

  FIELD-SYMBOLS: <namtab> TYPE vimnamtab,
                 <texttab_struc> TYPE ANY,
                 <texttab_fld> TYPE ANY,
                 <view_struc> TYPE ANY,
                 <viewfld> TYPE ANY.

  ASSIGN h_texttab_wa TO <texttab_struc> CASTING TYPE (header-texttab).
  MOVE: text_wa TO h_texttab_wa,
        view_wa to h_view_wa.
* Sprachschlüssel
  ASSIGN COMPONENT header-sprasfield OF STRUCTURE <texttab_struc>
   TO <texttab_fld>.
  <texttab_fld> = spras.
*  text_wa+spras_pos(vim_spras_length) = spras.
* Schlüsselfelder der Text-Tabelle
  ASSIGN: h_view_wa(header-tablen) TO <view_struc>
             CASTING TYPE (header-maintview).
  LOOP AT namtab ASSIGNING <namtab>
    WHERE txttabfldn <> space AND keyflag <> space.
    ASSIGN: COMPONENT <namtab>-viewfield OF STRUCTURE <view_struc>
             TO <viewfld>,
            COMPONENT <namtab>-txttabfldn
             OF STRUCTURE <texttab_struc> TO <texttab_fld>.
    <texttab_fld> = <viewfld>.
  ENDLOOP.
  MOVE h_texttab_wa TO text_wa.
*  LOOP AT namtab WHERE txttabfldn <> space AND keyflag <> space.
*    text_wa+namtab-texttabpos(namtab-flength) =
*         view_wa+namtab-position(namtab-flength).
*  ENDLOOP.
ENDFORM.                               " MAP_VIEWKEY_TO_TEXTTABKEY
*----------------------------------------------------------------------*
***INCLUDE LSVIMF62 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  vim_get_trspkeylen
*&---------------------------------------------------------------------*
*       Delivers key length in bytes of tables whithin a view. Called
*       by generated forms CORR_MAINT_yxz
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM vim_get_trspkeylen USING    p_tabname TYPE tabname
                        CHANGING p_keylength TYPE syfleng.

  TYPES: BEGIN OF tabkeylen_type,
          tabname TYPE tabname,
          keylen TYPE syfleng,
         END OF tabkeylen_type.
  STATICS: tabkeylen_tab TYPE HASHED TABLE OF tabkeylen_type
            WITH UNIQUE KEY tabname.
  DATA: w_tabkeylen TYPE tabkeylen_type,
        x030l_wa TYPE x030l.

  READ TABLE tabkeylen_tab INTO w_tabkeylen
   WITH TABLE KEY tabname = p_tabname.
  IF sy-subrc <> 0.
    CALL FUNCTION 'DDIF_NAMETAB_GET'
      EXPORTING
        tabname   = p_tabname
      IMPORTING
        x030l_wa  = x030l_wa.
    w_tabkeylen-tabname = p_tabname.
    w_tabkeylen-keylen  = x030l_wa-keylen.
    IF p_tabname = x_header-texttab AND x_header-genertxtrp <> space.
      w_tabkeylen-keylen = x_header-maxtrtxkln.
    ELSEIF x_header-generictrp <> space.
      w_tabkeylen-keylen = x_header-maxtrkeyln.
    ENDIF.
    INSERT w_tabkeylen INTO TABLE tabkeylen_tab.
  ENDIF.
  p_keylength = w_tabkeylen-keylen.
ENDFORM.                    " vim_get_trspkeylen

*&---------------------------------------------------------------------*
*&      Form  vim_get_bc_keylen
*&---------------------------------------------------------------------*
*       Delivers key length in bytes of tables whithin a view up to
*       255 char. Necessary for writing activation links
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM vim_get_bc_keylen USING    p_tabname TYPE tabname
                        CHANGING p_keylength TYPE syfleng.

  CONSTANTS max_bc_keylen TYPE i VALUE 255.

  TYPES: BEGIN OF tabkeylen_type,
          tabname TYPE tabname,
          keylen TYPE syfleng,
         END OF tabkeylen_type.
  STATICS: tabkeylen_tab TYPE HASHED TABLE OF tabkeylen_type
            WITH UNIQUE KEY tabname.
  DATA: w_tabkeylen TYPE tabkeylen_type,
        x030l_wa TYPE x030l, max_keylen_byte TYPE i.

  READ TABLE tabkeylen_tab INTO w_tabkeylen
   WITH TABLE KEY tabname = p_tabname.
  IF sy-subrc <> 0.
    CALL FUNCTION 'DDIF_NAMETAB_GET'
      EXPORTING
        tabname  = p_tabname
      IMPORTING
        x030l_wa = x030l_wa.
    w_tabkeylen-tabname = p_tabname.
    w_tabkeylen-keylen  = x030l_wa-keylen.
    max_keylen_byte = max_bc_keylen * cl_abap_char_utilities=>charsize.
    IF w_tabkeylen-keylen > max_keylen_byte.
      w_tabkeylen-keylen = max_keylen_byte.
    ENDIF.
    INSERT w_tabkeylen INTO TABLE tabkeylen_tab.
  ENDIF.
  p_keylength = w_tabkeylen-keylen.
ENDFORM.                    " vim_get_bc_keylen
*----------------------------------------------------------------------*
***INCLUDE LSVIMF63 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  vim_comp_roottabkey
*&---------------------------------------------------------------------*
*       Check if view and root table have identical keys.
*----------------------------------------------------------------------*
*      -->P_HEADER  text
*      -->P_NAMTAB  text
*      <--P_KEYS_IDENTICAL  text
*      <--P_RC  text
*----------------------------------------------------------------------*
FORM vim_comp_roottabkey  USING    p_header TYPE vimdesc
                                   p_namtab TYPE vimnamtab_type
                          CHANGING p_keys_identical TYPE xfeld
                                   p_rc TYPE sy-subrc.
  TYPES: BEGIN OF flagstruc_type,
          viewname TYPE viewname,
          keys_ident,
         END OF flagstruc_type.

  STATICS: flagtab TYPE HASHED TABLE OF flagstruc_type
           WITH UNIQUE KEY viewname.
  DATA: w_flagtab TYPE flagstruc_type,
        x031l_tab TYPE TABLE OF x031l.
  FIELD-SYMBOLS: <namtab> TYPE vimnamtab,
                 <x031l> TYPE x031l.

  CLEAR p_rc.
  READ TABLE flagtab WITH TABLE KEY viewname = p_header-viewname
   INTO w_flagtab.
  IF sy-subrc <> 0.
    w_flagtab-viewname = p_header-viewname.
    w_flagtab-keys_ident = 'X'.
    CALL FUNCTION 'DDIF_NAMETAB_GET'
      EXPORTING
        tabname   = p_header-roottab
      TABLES
        x031l_tab = x031l_tab
      EXCEPTIONS
        OTHERS    = 2.
    IF sy-subrc <> 0.
      p_rc = sy-subrc.
    ENDIF.
    LOOP AT p_namtab ASSIGNING <namtab> WHERE keyflag = 'X'.
      IF <namtab>-bastabname <> p_header-roottab.
        sy-subrc = 4.
      ELSE.
        READ TABLE x031l_tab INDEX sy-tabix ASSIGNING <x031l>.
      ENDIF.
      IF sy-subrc <> 0 OR <x031l>-fieldname <> <namtab>-bastabfld.
        clear w_flagtab-keys_ident.
        exit.
      ENDIF.
    ENDLOOP.
    INSERT w_flagtab INTO TABLE flagtab.
  ENDIF.
  p_keys_identical = w_flagtab-keys_ident.
ENDFORM.                    " vim_comp_roottabkey
*----------------------------------------------------------------------*
***INCLUDE LSVIMF64 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  vim_synchronizer_call
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_CU_KO200_TAB[]  text
*      -->P_CORR_KEYTAB[]  text
*      -->P_SPACE  text
*----------------------------------------------------------------------*
FORM vim_synchronizer_call  USING
                                 p_cu_ko200_tab TYPE vim_ko200_tab_type
                                 p_corr_keytab TYPE tr_keys
                                 p_synchronizer_flag TYPE xfeld.

  STATICS: e071k_loc TYPE TABLE OF e071k,
          e071_loc TYPE TABLE OF e071.
  DATA: e071k_loc_wa TYPE e071k,
        e071_loc_wa TYPE e071.

  IF p_synchronizer_flag = space.
    CLEAR: e071k_loc, e071_loc.
    REFRESH: e071k_loc, e071_loc.
    LOOP AT p_corr_keytab INTO e071k_loc_wa.
      APPEND e071k_loc_wa TO e071k_loc.
    ENDLOOP.
    LOOP AT p_cu_ko200_tab INTO e071_loc_wa.
      APPEND e071_loc_wa TO e071_loc.
    ENDLOOP.
  ELSE.
    READ TABLE e071k_loc INDEX 1 INTO e071k_loc_wa.
*----------------------------------------------------------------------
* Signal for Wulf Kruempelmann's Synchronizer (data written)
      READ TABLE p_corr_keytab INDEX 1 INTO e071k_loc_wa.
        CALL FUNCTION 'SCDC_DISTRIBUTE_TABLE_KEYS'
          EXPORTING
*           PROJECT_ID       =
            trkorr           = e071k_loc_wa-trkorr
          TABLES
            e071_tab         = e071_loc
            e071k_tab        = e071k_loc
         EXCEPTIONS
           no_project       = 1
           OTHERS           = 2
                  .
      IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
*----------------------------------------------------------------------
  ENDIF.
ENDFORM.                    " vim_synchronizer_call
*&---------------------------------------------------------------------*
*&  Include           LSVIMF65                                         *
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  check_nonkey
*&---------------------------------------------------------------------*
*       to check selection condiotions for nonkey fields only
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM check_nonkey.


  FIELD-SYMBOLS: <table1_txt_loc> type any.


     if x_header-bastab <> space and x_header-texttbexst <> space.
      assign <table1_text> to <table1_txt_loc>.
    else.
      assign <table1> to <table1_txt_loc>.
    endif.
    CALL FUNCTION 'TABLE_RANGE_CHECK'
         EXPORTING
              tabname                   = x_header-maintview
              entry                     = <table1>
              entry_text                = <table1_txt_loc>
              ddic                      = 'J'
              key                       = 'F'
              ignore_blank_subsetfields = 'N'
         TABLES
              x_namtab                  = x_namtab
              x_header                  = x_header
              sellist                   = <vim_ck_sellist>
         EXCEPTIONS
              entry_not_fits            = 1.
    IF sy-subrc EQ 1.
      PERFORM set_pf_status USING 'ERROR'.

      MESSAGE e174(sv).
    ENDIF.
  endform.        "check_nonkey
*---------------------------------------------------------------------*
*       MODULE DETAIL_INIT           OUTPUT                           *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE detail_init OUTPUT.
  IF vim_called_by_cluster <> space.                        "SW CTRL ..
    PERFORM vim_vcldocking_control.
  ENDIF.                               ".. SW CTRL
  PERFORM vim_add_img_notices_pbo USING x_header-detail.
  PERFORM detail_init.
  IF ( replace_mode NE space AND
   neuer NE 'X' )         "no error in CHECK_KEY for timedep. objects
   OR vim_pr_activating <> space.                           "UF profile
    SUPPRESS DIALOG.
  ENDIF.
  PERFORM vim_modify_detail_screen.
ENDMODULE.                    "detail_init OUTPUT

*---------------------------------------------------------------------*
*       MODULE VIM_MODIF_DETAIL         OUTPUT                        *
*---------------------------------------------------------------------*
* Modifikation der Screen-Attribute für Tabstrip-Screens              *
*---------------------------------------------------------------------*
MODULE vim_modif_detail OUTPUT.
  PERFORM vim_modify_detail_screen.
ENDMODULE.                    "vim_modif_detail OUTPUT

*---------------------------------------------------------------------*
*       MODULE LISTE_SHOW_LISTE OUTPUT                                *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE liste_show_liste OUTPUT.
** Table-control !!!   "bis der Fehler behoben ist
  IF vim_tabctrl_active NE space.
    IF <vim_tctrl>-current_line GT maxlines AND  "no more entries
       <xact> NE leer.                 "in EXTRACT and no new entry
      EXIT FROM STEP-LOOP.
    ENDIF.
  ENDIF.
** Table-control !!!
  looplines = sy-loopc.
  IF l GT looplines.
    counter = ( l - firstline ) div looplines + 1.
    DO counter TIMES.
      firstline = firstline + looplines - 1.
    ENDDO.
    MOVE firstline TO <status>-firstline.
    <status>-cur_line = l = l - firstline + 1.
    SET CURSOR FIELD f LINE l OFFSET o.
  ENDIF.
  IF vim_special_mode NE vim_upgrade AND
     status-action EQ hinzufuegen AND maxlines EQ 0 AND sy-stepl EQ 1.
    DESCRIBE TABLE extract.
    IF sy-tfill GT looplines.
      sy-tfill = looplines + 1.
      LOOP AT extract FROM sy-tfill.
        DELETE extract.
      ENDLOOP.
      nbr_of_added_dummy_entries = looplines.
    ENDIF.
  ENDIF.
* dataset from BC-set? --> get field parameters
  CLEAR vim_set_from_bc_pbo.
  IF replace_mode = space AND status-action = aendern
   AND vim_bc_chng_allowed = space.  "fix field changeability forced
    READ TABLE vim_bc_entry_list INTO vim_bc_entry_list_wa
     WITH TABLE KEY viewname = x_header-viewname
     keys = <vim_xextract_key>.
    IF sy-subrc = 0.
      vim_set_from_bc_pbo = 'X'.
    ENDIF.
  ENDIF.
  IF replace_mode NE space OR vim_special_mode EQ vim_delete."aro
    IF sy-stepl GT 1.
      EXIT FROM STEP-LOOP.
    ELSE.
      MOVE <vim_xtotal> TO <table2_x>.
    ENDIF.
  ENDIF.                                                    "aro
  index = exind = nextline.
  IF status-action EQ kopieren AND status-type EQ einstufig.
    READ TABLE vim_copied_indices WITH KEY level = vim_copy_call_level
                                           ex_ix = nextline.
    IF sy-subrc EQ 0.                  "entry already copied
      READ TABLE total INDEX vim_copied_indices-ix.
      extract = total. neuer = 'N'.
    ELSE.
      neuer = 'J'.
    ENDIF.
  ENDIF.
  PERFORM move_extract_to_view_wa.
  IF vim_special_mode EQ vim_delimit.
    MOVE vim_sval_tab-value TO <vim_new_begdate>.
  ENDIF.
  IF status-action EQ hinzufuegen AND status-type EQ einstufig AND
     neuer NE 'J' AND <xact> EQ leer.
    neuer = 'J'.
  ENDIF.
  IF <xmark> EQ markiert.
    MOVE 'X' TO vim_marked.
  ENDIF.
  LOOP AT SCREEN.
    CLEAR vim_modify_screen.
    SPLIT screen-name AT '-' INTO vim_object vim_objfield.
   IF ( status-action EQ anzeigen OR status-action EQ transportieren OR
           status-delete EQ geloescht ) AND screen-name NE 'VIM_MARKED'.
      screen-input = '0'. vim_modify_screen = 'X'.
    ELSE.
      IF screen-group1 EQ 'KEY'.
        IF vim_tabctrl_active NE space AND screen-input EQ '0'.
          READ TABLE <vim_tctrl>-cols INTO vim_tc_cols
                                       WITH KEY
                                            screen-name = screen-name
                                       TRANSPORTING screen-required.
          IF sy-subrc EQ 0 AND
             screen-required NE vim_tc_cols-screen-required.
            screen-required = vim_tc_cols-screen-required.
            vim_modify_screen = 'X'.
          ENDIF.
        ENDIF.
        IF screen-required NE 0 AND screen-input NE '0'.
          screen-input = '0'. vim_modify_screen = 'X'.
        ENDIF.
        IF vim_single_entry_function EQ 'INS'.
          screen-request = 1. vim_modify_screen = 'X'.
        ENDIF.
* int. mess. 1757218/1999: no foreign-key check with copy
        IF status-action = kopieren.
          screen-request = 1. vim_modify_screen = 'X'.
        ENDIF.
* int. mess. 1757218/1999: no foreign-key check with copy: end
      ENDIF.
*     IF NEUER EQ 'J' OR STATUS-ACTION EQ KOPIEREN.
      IF neuer EQ 'J'.
        IF vim_special_mode NE vim_delimit AND
           screen-group1 EQ 'KEY' AND
           ( vim_single_entry_function NE 'INS' OR
               vim_single_entry_ins_key_input NE space ) AND
           ( x_header-existency NE 'M' OR
             screen-name EQ vim_enddate_name ).
          ADD 1 TO pos.
          IF pos EQ 1.
            SET CURSOR FIELD screen-name LINE sy-stepl.
          ENDIF.
          screen-input = '1'. vim_modify_screen = 'X'.
        ENDIF.
        IF screen-name EQ 'VIM_MARKED'.
          screen-input = '0'. vim_modify_screen = 'X'.
        ELSE.
          IF <xact> = profil_hinzufuegen.
            READ TABLE vim_pr_fields_wa-fields WITH TABLE KEY
             fieldname = vim_objfield TRANSPORTING NO FIELDS.
            IF sy-subrc = 0.
              screen-request = 1. vim_modify_screen = 'X'.
            ENDIF.
          ENDIF.
          IF vim_special_mode EQ vim_upgrade AND function NE 'DELE'.
            IF <status>-prof_found = vim_pr_into_view "UFprofiles begin
             AND status-action = hinzufuegen AND screen-group1 = 'KEY'.
              PERFORM set_profile_key_attributes USING vim_objfield
                                                 CHANGING screen-input
                                                      vim_modify_screen.
            ENDIF.                     "UFprofiles end
            screen-request = 1. vim_modify_screen = 'X'.
          ENDIF.
        ENDIF.
      ELSE.
        IF x_header-delmdtflag NE space AND
           x_header-existency EQ 'U' AND
           screen-name EQ vim_begdate_name.
          screen-input = '0'. vim_modify_screen = 'X'.
        ENDIF.
        IF f EQ space AND screen-name NE 'VIM_MARKED' AND
           screen-input EQ '1'.
          SET CURSOR FIELD screen-name LINE l.
          f = screen-name.
        ENDIF.
        IF replace_mode NE space.
          CASE vim_special_mode.
            WHEN vim_replace.
              IF screen-name EQ sel_field_for_replace_l.
                screen-request = 1. vim_modify_screen = 'X'.
              ENDIF.
            WHEN vim_upgrade.
              IF NOT function IN exted_functions AND
                 screen-name NE 'VIM_MARKED'.
                screen-request = 1. vim_modify_screen = 'X'.
              ENDIF.
              screen-input = '1'. vim_modify_screen = 'X'.
          ENDCASE.
        ELSE.
          IF vim_special_mode EQ vim_delete.
            screen-input = '0'. vim_modify_screen = 'X'.
          ENDIF.
          IF vim_set_from_bc_pbo <> space AND screen-group1 <> 'KEY'.
* Dataset comes from BC-set -> check field parameter
            PERFORM vim_bc_logs_use USING    vim_objfield
                                             vim_bc_entry_list_wa
                                    CHANGING screen
                                             vim_modify_screen.
          ENDIF.
        ENDIF.                         "replace_mode <> space
      ENDIF.                           "neuer = 'J'
    ENDIF.                             "update mode
    IF <xmark> EQ markiert AND screen-name NE 'VIM_MARKED'.
      screen-intensified = 1. vim_modify_screen = 'X'.
    ENDIF.
    IF vim_special_mode EQ vim_delimit AND
       screen-name EQ vim_begdate_name.
      screen-request = 1. vim_modify_screen = 'X'.
    ENDIF.
*   IF X_HEADER-RDONLYFLAG = 'X' AND                      "Subviews ..
*      X_HEADER-MAINTVIEW <> X_HEADER-VIEWNAME.
    IF vim_objfield <> space AND vim_object = x_header-maintview.
      LOOP AT x_namtab WHERE viewfield = vim_objfield AND
                          ( texttabfld = space OR keyflag = space ).
        IF x_namtab-readonly = vim_hidden.
          screen-active = '0'. vim_modify_screen = 'X'.
        ELSEIF x_namtab-readonly = rdonly.
          screen-input = '0'. vim_modify_screen = 'X'.
        ENDIF.
        EXIT.
      ENDLOOP.
    ENDIF.
*   ENDIF.                                                  ".. Subviews
    IF vim_modify_screen = 'X'.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.
  IF status-action EQ kopieren.
    neuer = 'N'.
  ENDIF.
ENDMODULE.                    "liste_show_liste OUTPUT

*---------------------------------------------------------------------*
*       MODULE LISTE_INITIALISIEREN OUTPUT                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE liste_initialisieren OUTPUT.
  IF vim_called_by_cluster <> space.                        "SW CTRL ..
    PERFORM vim_vcldocking_control.
  ENDIF.                               ".. SW CTRL
  status-mode = list_bild.
  title-mode  = list_bild.
  firstline = nextline.
  aktuell = firstline.
  vim_act_dynp_view = x_header-viewname.
  PERFORM vim_add_img_notices_pbo USING x_header-liste.
  IF vim_special_mode EQ vim_direct_upgrade.
    SUPPRESS DIALOG.
    ok_code = function = 'CMPR'.
    EXIT.
  ENDIF.
  CLEAR <status>-mark_only.                                 "ufdetail
  IF replace_mode NE space OR vim_special_mode EQ vim_delete.
    PERFORM set_title USING title <name>.
    IF vim_special_mode NE vim_delete. SUPPRESS DIALOG. ENDIF.
    PERFORM set_pf_status USING 'REPLACE'.
    MOVE <table1> TO <vim_total_struc>.
*    MOVE <table1> TO total.
    IF x_header-bastab NE space AND x_header-texttbexst NE space.
      MOVE <table1_text> TO <vim_tot_txt_struc>.
    ENDIF.
** Table-control !!!
    IF vim_tabctrl_active NE space.
      IF status-action EQ hinzufuegen.
        <vim_tctrl>-lines = maxlines + nbr_of_added_dummy_entries.
      ELSE.
        <vim_tctrl>-lines = maxlines.
      ENDIF.
      <vim_tctrl>-top_line = firstline.
      LOOP AT <vim_tctrl>-cols INTO vim_tc_cols
                               WHERE screen-active EQ 0.
        vim_tc_cols-vislength = 0.
        MODIFY <vim_tctrl>-cols FROM vim_tc_cols.
      ENDLOOP.
    ENDIF.
    EXIT.
  ENDIF.
  IF mark_extract GT 0.
    status-mark = markiert.
  ELSE.
    status-mark = nicht_markiert.
  ENDIF.
  IF maxlines EQ 0.
    IF status-action NE hinzufuegen
    OR status-type NE einstufig.
      PERFORM fill_extract.
    ELSE.                                                   "aro
      title-data = auswahldaten.                            "aro
    ENDIF.                                                  "aro
    status-delete = nicht_geloescht.
    PERFORM vim_send_sv005_or_sv766 USING '766'
                                          'RESET'.
  ELSEIF maxlines = 1 AND function <> 'UEBE'.
* Viewcluster: jump into single screen also if view is chosen for
* the 2nd time
    PERFORM vim_maintain_single_set.         "UFint2329966/2000
* Notlösung Sortproblem Hinzufügen Anfang
  ELSE.
    PERFORM vim_send_sv005_or_sv766 USING '766'
                                          'RESET'.
    IF status-action EQ hinzufuegen.
      pos = 1.
      LOOP AT extract.
        CHECK <xact> NE leer.
        IF sy-tabix NE pos.
          DELETE extract.
          INSERT extract INDEX pos.
        ENDIF.
        ADD 1 TO pos.
      ENDLOOP.
    ENDIF.
* Notlösung Sortproblem Hinzufügen Ende
  ENDIF.
  maximal = maxlines.
** Table-control !!!
  IF vim_tabctrl_active NE space.
    IF status-action EQ hinzufuegen.
      <vim_tctrl>-lines = maxlines + nbr_of_added_dummy_entries.
    ELSE.
      <vim_tctrl>-lines = maxlines.
    ENDIF.
    <vim_tctrl>-top_line = firstline.
    LOOP AT <vim_tctrl>-cols INTO vim_tc_cols
*                            WHERE SCREEN-INVISIBLE EQ 1
*                              OR  SCREEN-ACTIVE EQ 0.
                             WHERE screen-active EQ 0.
      vim_tc_cols-vislength = 0.
      MODIFY <vim_tctrl>-cols FROM vim_tc_cols.
    ENDLOOP.
* Notlösung Markierbarkeit beim Hinzufügen bzw. Kopieren
*   IF STATUS-ACTION EQ HINZUFUEGEN OR STATUS-ACTION EQ KOPIEREN.
*     <VIM_TCTRL>-LINE_SEL_MODE = 0.
*   ELSE.
**    <VIM_TCTRL>-LINE_SEL_MODE = 2.
*     <VIM_TCTRL>-LINE_SEL_MODE = <STATUS>-L_SEL_MODE.
*   ENDIF.
  ELSE.                                "Subviews ..
    LOOP AT SCREEN.
      SPLIT screen-name AT '-' INTO vim_object vim_objfield.
      IF vim_objfield <> space AND vim_object = x_header-maintview.
        LOOP AT x_namtab WHERE viewfield = vim_objfield AND
                            ( texttabfld = space OR keyflag = space ).
          IF x_namtab-readonly = vim_hidden.
            screen-active = '0'. MODIFY SCREEN.
          ELSEIF x_namtab-readonly = rdonly.
            screen-input = '0'. MODIFY SCREEN.
          ENDIF.
          EXIT.
        ENDLOOP.
      ENDIF.
    ENDLOOP.                           ".. Subviews
  ENDIF.
** Table-control !!!
  PERFORM set_position_info USING firstline maxlines.
  pos = maxlines - firstline + 1.
  IF l GT pos.
    l = 1.
  ENDIF.
  pos = 0.                                                  "aro
  SET CURSOR FIELD f LINE l OFFSET o.
  PERFORM set_pf_status USING status.
  PERFORM set_title USING title <name>.
* Notlösung Batch-Input Anfang
  IF maxlines EQ 0.
    LOOP AT SCREEN.
      CHECK screen-name EQ 'VIM_POSI_PUSH'.
      screen-input = 0.
      MODIFY SCREEN.
      EXIT.
    ENDLOOP.
  ENDIF.
* Notlösung Batch-Input Ende
  IF status-action EQ kopieren OR vim_single_entry_function NE space.
    LOOP AT SCREEN.
      CHECK screen-name EQ 'VIM_POSI_PUSH'.
      screen-active = 0.
      MODIFY SCREEN.
      EXIT.
    ENDLOOP.
  ENDIF.
ENDMODULE.                    "liste_initialisieren OUTPUT

*---------------------------------------------------------------------*
*       MODULE FILL_SUBSTFLDS OUTPUT                                  *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE fill_substflds OUTPUT.
  CHECK x_header-subsetflag NE space.
  PERFORM fill_subsetfields.
ENDMODULE.                    "fill_substflds OUTPUT

*---------------------------------------------------------------------*
*       MODULE LISTE_DEACTIVATE OUTPUT                                *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE liste_deactivate OUTPUT.
  CHECK <xact> NE leer AND status-action NE kopieren.
  LOOP AT SCREEN.
    CHECK screen-group2 EQ 'EZN' .
    IF x_header-ptfrkyexst EQ space.
      MOVE screen-name TO f.
      SHIFT f UP TO '-'. SHIFT f.
      LOOP AT x_namtab WHERE keyflag EQ space  "ignore keyfields
                         AND viewfield EQ f.
        MOVE 'X' TO x_namtab-prtfrkyfld.
        MOVE 'X' TO x_header-ptfrkyexst.
        MODIFY x_namtab.
      ENDLOOP.
    ENDIF.
    CHECK sy-stepl NE 1 AND
    <vim_f1_beforex> EQ <vim_mkey_beforex> AND
    ( vim_mkey_after_exists EQ space OR
      <vim_f1_afterx> EQ <vim_mkey_afterx> ).
*    <vim_f1_before> eq <vim_mkey_before> and
*    ( vim_mkey_after_exists eq space or
*      <vim_f1_after> eq <vim_mkey_after> ).
    screen-active = 0.
    MODIFY SCREEN.
  ENDLOOP.
  MODIFY x_header INDEX 1.
  IF vim_no_mainkey_exists EQ vim_no_mkey_not_procsd OR
    <vim_f1_beforex> NE <vim_mkey_beforex> OR
    ( vim_mkey_after_exists NE space AND
      <vim_f1_afterx> NE <vim_mkey_afterx> ).
*     <vim_f1_before> ne <vim_mkey_before> or
*     ( vim_mkey_after_exists ne space and
*       <vim_f1_after> ne <vim_mkey_after> ).
    <vim_h_mkey>(x_header-keylen) = <f1_x>.
*    vim_mainkey = <f1>.
    TRANSLATE vim_no_mainkey_exists USING vim_no_mkey_procsd_patt.
  ENDIF.
ENDMODULE.                             "liste_deactivate.

*---------------------------------------------------------------------*
*       MODULE VIM_SUPPRESS_LISTE OUTPUT                              *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE vim_suppress_liste OUTPUT.
  CHECK vim_special_mode <> vim_direct_upgrade AND
        function NE space AND function NE 'ANZG' AND
        function NE 'AEND' AND "function NE 'ABR ' AND
        NOT ( vim_called_by_cluster NE space AND
             ( function CP 'DET*' OR  function CP '%_*' ) ).
  SUPPRESS DIALOG.
  ok_code = back.
ENDMODULE.                             "vim_suppres_liste
*---------------------------------------------------------------------*
*       MODULE SET_UPDATE_FLAG                                        *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE set_update_flag.
  CHECK status-action NE anzeigen AND  "ignore wrong setted requestflags
        status-action NE transportieren. "due to individual F4 modules
  IF x_header-delmdtflag NE space AND
     status-type EQ einstufig AND
     status-mode EQ list_bild.         "only on list screen
* check if dates entered properly
    IF ( <vim_new_begdate> EQ vim_init_date OR
       <vim_enddate_mask> EQ vim_init_date ).
      MESSAGE e127(sv)."Bitte den Gültigkeitsbereich eingrenzen
    ENDIF.
    CLEAR sy-subrc.
    IF status-action EQ kopieren AND vim_special_mode NE vim_delimit.
     READ TABLE vim_copied_indices WITH KEY level = vim_copy_call_level
                                               ex_ix = nextline.
    ENDIF.
    IF sy-subrc NE 0 OR       "copy mode and entry not yet processed or
       ( status-action EQ hinzufuegen AND <xact> EQ leer ).  "new entry
      neuer = 'J'.
      IF x_header-guidflag <> space.
        PERFORM vim_make_guid using space.
      ENDIF.
      IF x_header-frm_on_new NE space.
        PERFORM (x_header-frm_on_new) IN PROGRAM.
      ENDIF.
      PERFORM check_key.
      neuer = 'N'.
    ENDIF.
  ENDIF.
  IF x_header-bastab NE space AND x_header-texttbexst NE space.
    TRANSLATE <status>-upd_flag USING ' ETX'.
  ELSE.
    <status>-upd_flag = 'X'.
  ENDIF.
* check in non key field entries violate selection conditions
  PERFORM check_nonkey.

ENDMODULE.

*---------------------------------------------------------------------*
*       MODULE DETAIL_EXIT_COMMAND                                    *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE detail_exit_command.
  PERFORM detail_exit_command.
ENDMODULE.

*---------------------------------------------------------------------*
*       MODULE LISTE_EXIT_COMMAND                                     *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE liste_exit_command.
  PERFORM liste_exit_command.
ENDMODULE.

*---------------------------------------------------------------------*
*       MODULE LISTE_AFTER_LOOP                                       *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE liste_after_loop.
** Table-control !!!
  IF vim_tabctrl_active NE space.
    IF nextline NE <vim_tctrl>-top_line.
      nextline = <vim_tctrl>-top_line.
    ENDIF.
  ENDIF.
** Table-control !!!
  IF destpage NE 0.
    nextline = destpage. CLEAR destpage.
  ENDIF.
* IF TEMPORAL_DELIMITATION_HAPPENED NE SPACE.
  IF vim_special_mode NE vim_upgrade AND
     vim_special_mode NE vim_delimit AND
     temporal_delimitation_happened NE space.
    PERFORM after_temporal_delimitation.
    CLEAR: temporal_delimitation_happened, vim_old_viewkey.
    TRANSLATE vim_no_mainkey_exists USING vim_no_mkey_not_procsd_patt.
  ENDIF.
  IF function IN mark_functions AND mark_extract EQ 0.
    MESSAGE s026(sv).                  "Bitte vorher Einträge markieren
    LEAVE SCREEN.
  ENDIF.
  PERFORM update_status.
  IF vim_single_entry_function EQ 'INS' AND
     vim_single_entry_ins_key_input NE space AND
     status-action EQ hinzufuegen.
    PERFORM vim_single_entry_fill_sellist.
  ENDIF.
  CLEAR: vim_next_screen, vim_leave_screen.
  CASE function.
    WHEN 'ADDR'.
      PERFORM liste_address_maintain.
    WHEN 'AEND'.
      PERFORM anzg_to_aend.
    WHEN 'ALCO'.
      PERFORM selektiere USING transportieren.
    WHEN 'ALMK'.
      PERFORM selektiere USING markiert.
    WHEN 'ALNC'.
      PERFORM selektiere USING space.
    WHEN 'ALOE'.
      PERFORM selektiere USING geloescht.
    WHEN 'ALNW'.
      PERFORM selektiere USING neuer_eintrag.
    WHEN 'ANZG'.
      PERFORM aend_to_anzg.
      vim_next_screen = 0. vim_leave_screen = 'X'.
    WHEN 'ATAB'.
      vim_next_screen = 0. vim_leave_screen = 'X'.
    WHEN 'BACK'.
      IF status-mode EQ list_bild AND status-data EQ gesamtdaten OR
        vim_single_entry_function NE space.
        vim_next_screen = 0. vim_leave_screen = 'X'.
      ELSE.
        PERFORM liste_back.
      ENDIF.
    WHEN 'BCCH'.                       "change fix bc-set fields
      PERFORM vim_chng_fix_flds.
    WHEN 'BCSH'.                        " show fix bc-set fields
      PERFORM vim_bc_show_fix_flds.
    WHEN 'BCON'.
      PERFORM selektiere USING bcset_only. "show only data from bcset
    WHEN 'CMPO'.
      PERFORM upgrade USING 'O'.
    WHEN 'CMPR'.
      PERFORM upgrade USING 'R'.
    WHEN 'COMP'.
      PERFORM upgrade USING space.
    WHEN 'DELE'.
      PERFORM loeschen.
      IF replace_mode NE space.
        <status>-mk_to = mark_total.
        <status>-mk_xt = mark_extract.
        vim_next_screen = 0. vim_leave_screen = 'X'.
      ENDIF.
    WHEN 'DELM'.
      PERFORM delimitation.
    WHEN 'DETM'.                       "UFdetail
      PERFORM detail_markierte.
    WHEN 'DETA'.
      PERFORM detailbild.
    WHEN 'ENDE'.
      vim_next_screen = 0. vim_leave_screen = 'X'.
    WHEN 'EXPA'.
*     PERFORM TIME_DEPENDENT_DISPLAY_MODIF.
      IF x_header-delmdtflag EQ space.
        MESSAGE s001(sv). EXIT.
      ENDIF.
      PERFORM (vim_time_dep_dpl_modif_form) IN PROGRAM.
    WHEN 'FDOC'.                       "HW Functiondocu
      PERFORM show_function_docu.
*    WHEN 'GPRF'.                       "UF Profile
* choose profile
*      CLEAR: <status>-prof_found, vim_pr_records.
*      PERFORM get_profiles USING <status>-prof_found.
    WHEN 'KOPE'.
      counter = 0.
      PERFORM kopiere.
    WHEN 'KOPF'.
      SET SCREEN 0. LEAVE SCREEN.
    WHEN 'LANG'.                       "SW Texttransl
      PERFORM vim_set_languages.
    WHEN 'MKAL'.
      PERFORM markiere_alle USING markiert.
    WHEN 'MKBL'.
      PERFORM markiere_block.
    WHEN 'MKEZ'.
      PERFORM liste_markiere.
    WHEN 'MKLO'.
      PERFORM markiere_alle USING nicht_markiert.
    WHEN 'NEWL'.
      PERFORM hinzufuegen.
    WHEN 'NEXT'.
      PERFORM naechster.
    WHEN 'ORDR'.
      PERFORM order_administration.
    WHEN 'ORGI'.
      PERFORM original_holen.
    WHEN 'POSI'.
      PERFORM popup_positionieren.
    WHEN 'PREV'.
      PERFORM voriger.
    WHEN 'PRMO'.
* 4.6A: obsolete, left for individual status only
      PERFORM list_alv.
    WHEN 'PROT'.
      PERFORM logs_analyse.
    WHEN 'PRST'.
      PERFORM list_alv.
    WHEN 'P+  '.
      PERFORM blaettern.
    WHEN 'P-  '.
      PERFORM blaettern.
    WHEN 'P++ '.
      PERFORM blaettern.
    WHEN 'P-- '.
      PERFORM blaettern.
    WHEN 'REPL'.
      PERFORM replace.
    WHEN 'SAVE'.
      IF status-action EQ hinzufuegen.
*       SORT EXTRACT BY <VIM_EXTRACT_KEY>.  "not nec. anymore
        <status>-firstline = firstline = <status>-cur_line = l = 1.
      ENDIF.
      vim_next_screen = 0. vim_leave_screen = 'X'.
    WHEN 'SCRF'.
      PERFORM vim_sapscript_form_maint.
    WHEN 'SEAR'.
      PERFORM suchen.
    WHEN 'SELU'.
      PERFORM selektiere USING aendern.
*    WHEN 'SPRF'.                       "UF Profile
* show chosen profile
*      PERFORM get_profiles USING <status>-prof_found.
    WHEN 'TEXT'.                       "SW Texttransl
      PERFORM vim_multi_langu_text_maint.
    WHEN 'TREX'.
      MOVE geloescht TO corr_action.
      PERFORM update_corr.
      IF replace_mode NE space.
        <status>-mk_to = mark_total.
        <status>-mk_xt = mark_extract.
        vim_next_screen = 0. vim_leave_screen = 'X'.
      ENDIF.
    WHEN 'TRIN'.
      MOVE hinzufuegen TO corr_action.
      PERFORM update_corr.
      IF replace_mode NE space.
        <status>-mk_to = mark_total.
        <status>-mk_xt = mark_extract.
        vim_next_screen = 0. vim_leave_screen = 'X'.
      ENDIF.
    WHEN 'TRSP'.
      IF x_header-cursetting NE space AND
         x_header-flag EQ vim_transport_denied.
        x_header-flag = x_header-cursetting.
        TRANSLATE x_header-flag USING 'X YX'.
        MODIFY x_header INDEX 1.
      ENDIF.
      vim_next_screen = 0. vim_leave_screen = 'X'.
    WHEN 'UNDO'.
*     PERFORM LISTE_ZURUECKHOLEN.
      PERFORM zurueckholen.
      IF replace_mode NE space.
        <status>-mk_to = mark_total.
        <status>-mk_xt = mark_extract.
        vim_next_screen = 0. vim_leave_screen = 'X'.
      ENDIF.
    WHEN 'UPRF'.                       "UF Profile
* activate chosen profile
*      PERFORM activate_profile CHANGING <status>-prof_found.
      message s175(SV).
    WHEN '    '.
      IF vim_single_entry_function EQ 'INS' AND
         status-action EQ hinzufuegen.
        PERFORM liste_back.
      ENDIF.
      IF replace_mode NE space.
        vim_next_screen = 0. vim_leave_screen = 'X'.
      ENDIF.
    WHEN OTHERS.
      IF vim_called_by_cluster NE space.
        CALL FUNCTION 'VIEWCLUSTER_NEXT_ACTION'
             IMPORTING
                  leave_screen = vim_leave_screen
             CHANGING
                  fcode        = function.
        IF vim_leave_screen NE space.
          vim_next_screen = 0.
        ENDIF.
      ENDIF.
  ENDCASE.
  IF vim_leave_screen NE space.
    CLEAR: vim_leave_screen, vim_act_dynp_view.
    SET SCREEN vim_next_screen. LEAVE SCREEN.
  ENDIF.
ENDMODULE.

*---------------------------------------------------------------------*
*       MODULE LISTE_BEFORE_LOOP                                      *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE liste_before_loop.
  GET CURSOR FIELD f LINE l OFFSET o.
  function = ok_code.
  CLEAR: ok_code, <status>-upd_flag.
  IF vim_special_mode EQ vim_delete.
    SET SCREEN 0. LEAVE SCREEN.
  ENDIF.
* PERFORM READ_TABLE USING FIRSTLINE.
  IF replace_mode EQ space.
*   SET PF-STATUS 'ERRORLIS'.
    PERFORM set_pf_status USING 'ERRORLIS'.
*   CLEAR <STATUS>-UPD_FLAG.
    neuer = 'N'.
    IF vim_called_by_cluster NE space.
      CALL FUNCTION 'VIEWCLUSTER_SET_OKCODE'
           EXPORTING
                ok_code = function.
    ENDIF.
  ENDIF.
ENDMODULE.

*---------------------------------------------------------------------*
*       MODULE DETAIL_PAI                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE detail_pai.
  CLEAR: vim_next_screen, vim_leave_screen.
  function = ok_code.
  PERFORM detail_pai.
  IF vim_leave_screen NE space.
    CLEAR: vim_leave_screen, vim_act_dynp_view.
    SET SCREEN vim_next_screen. LEAVE SCREEN.
  ENDIF.
ENDMODULE.

*---------------------------------------------------------------------*
*       MODULE DETAIL_SET_PFSTATUS                                    *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE detail_set_pfstatus.
  IF replace_mode EQ space.
*   SET PF-STATUS 'ERROR'.
    PERFORM set_pf_status USING 'ERROR'.
  ENDIF.
  IF x_header-delmdtflag NE space.
    EXPORT ok_code TO MEMORY ID vim_memory_id_2.
  ENDIF.
ENDMODULE.

*---------------------------------------------------------------------*
*       MODULE LISTE_MARK_CHECKBOX                                    *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE liste_mark_checkbox.
  CHECK <xact> NE leer.
  CLEAR answer.
  IF vim_marked NE space AND <xmark> NE markiert.
    MOVE: markiert TO <xmark>, markiert TO answer.
    ADD: 1 TO mark_total, 1 TO mark_extract.
  ELSEIF vim_marked EQ space AND <xmark> NE nicht_markiert.
    MOVE: nicht_markiert TO <xmark>, markiert TO answer.
    SUBTRACT: 1 FROM mark_total, 1 FROM mark_extract.
  ENDIF.
  IF <status>-upd_flag EQ space AND answer NE space.  "only mouse mark
    MOVE nextline TO index.
    READ TABLE total WITH KEY <vim_xextract_key> BINARY SEARCH.
    PERFORM vorhanden.
  ENDIF.
  CLEAR answer.
ENDMODULE.

*---------------------------------------------------------------------*
*       MODULE LISTE_INIT_WORKAREA                                    *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE liste_init_workarea.
  IF replace_mode NE space.
    IF vim_special_mode EQ vim_upgrade.
      <table2_x> = <vim_xtotal>.
    ELSEIF vim_special_mode EQ vim_replace.
      CLEAR <replace_field>.
    ENDIF.
  ENDIF.
  PERFORM move_extract_to_view_wa.
  MOVE nextline TO exind.
  CLEAR vim_pr_activating.
  IF <xact> = profil_hinzufuegen.      "UFprofiles begin
* Set update flags
    <table2_x> = <initial_x>.
    <xact> = leer.
    vim_pr_activating = 'X'.
    MODIFY extract INDEX sy-stepl.
    IF x_header-bastab NE space AND x_header-texttbexst NE space.
      <status>-upd_flag = 'E'.
    ELSE.
      <status>-upd_flag = 'X'.
    ENDIF.
  ENDIF.                               "UFprofiles end
  CLEAR: vim_key_alr_checked, vim_keyrange_alr_checked.
ENDMODULE.

*---------------------------------------------------------------------*
*       MODULE LISTE_UPDATE_LISTE                                     *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE liste_update_liste.
  CHECK status-action NE anzeigen.
  CHECK status-action NE transportieren.
  CHECK status-delete NE geloescht.
  IF ok_code NE 'IGN '.
    IF x_header-ptfrkyexst NE space.
      PERFORM consistency_prt_frky_fields
                                   USING vim_show_consistency_alert.
    ENDIF.
    CASE status-action.                "UFprofile
      WHEN kopieren.                   "UFprofile
     READ TABLE vim_copied_indices WITH KEY level = vim_copy_call_level
                                                  ex_ix = nextline.
        IF sy-subrc EQ 0.              "entry alr. processed
          <xact> = neuer_eintrag.
          PERFORM update_tab.
        ELSE.
          PERFORM kopiere_eintrag USING <orig_key>.
        ENDIF.
      WHEN OTHERS.
        PERFORM update_tab.
    ENDCASE.
  ELSE.
    PERFORM set_pf_status USING 'ERRORLIS'.
  ENDIF.
  IF replace_mode EQ space.
    CLEAR ok_code.
  ENDIF.
ENDMODULE.

*---------------------------------------------------------------------*
*       MODULE TEMP_DELIMITATION                                      *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE temp_delimitation.
  DATA: td_addr_safe LIKE adrc-addrnumber.
  CHECK x_header-delmdtflag NE space.
* set update flag (if begdate not in the set_update_flag-chain)
  CHECK status-action NE anzeigen AND  "ignore wrong set requestflags
        status-action NE transportieren. "due to individual F4 modules
  IF x_header-bastab NE space AND x_header-texttbexst NE space.
    <status>-upd_flag = 'E'.
  ELSE.
    <status>-upd_flag = 'X'.
  ENDIF.
* process delimitation
  vim_begdate_entered = 'X'.
  PERFORM temporal_delimitation.
  IF temporal_delimitation_happened EQ 'X' AND
     x_header-delmdtflag EQ 'B'.
    IF x_header-adrnbrflag = space.
      MOVE: <vim_xtotal_key> TO <f1_x>,
            <vim_begdate> TO <vim_new_begdate>.
    ELSE.
      MOVE: <address_number> TO td_addr_safe,
            <vim_xtotal_key> TO <f1_x>,
            td_addr_safe TO <address_number>,
            <vim_begdate> TO <vim_new_begdate>.
    ENDIF.
  ENDIF.
ENDMODULE.

*---------------------------------------------------------------------*
*       MODULE CONSISTENCY                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE consistency.
  EXIT.
* CHECK STATUS-MODE NE DETAIL_BILD.
* PERFORM CONSISTENCY_PRT_FRKY_FIELDS USING 'X'.
ENDMODULE.                             "consistency

*&---------------------------------------------------------------------*
*&      Module  VCL_HELP_VALUES  INPUT
*&---------------------------------------------------------------------*
* Modul zum Ereignis 'Process On Value-Request' innerhalb der          *
* Viewcluster-Pflege:
* Realisierung von F4 auf ein Feld, dessen Prüftabelle im selben
* Viewcluster gepflegt wird.
*----------------------------------------------------------------------*
MODULE vcl_help_values INPUT.
  DATA: vcl_event(3) .
  CLEAR: f, vim_object, vim_objfield.
* POV-Module, die an List-Boxen hängen, werden schon zum Zeitpunkt
* CONTROL OUT gerufen. Hier kann das betroffene Feld nicht über
* die Cursor-Position ermittelt werden.
  CALL 'DY_GET_DYNPRO_EVENT' ID 'EVENT' FIELD vcl_event.
  IF sy-subrc = 0 AND vcl_event = 'OUT'.
*   Aufruf zum Zeitpunkt Control Output
    MESSAGE i538(sv) WITH vim_calling_cluster view_name.
    EXIT.
  ENDIF.

  IF status-mode = 'L'.                " Listbild
    GET CURSOR FIELD f LINE l.
  ELSE.                                " Detailbild
    GET CURSOR FIELD f.
  ENDIF.
  SPLIT f AT '-' INTO vim_object vim_objfield.
  IF vim_objfield IS INITIAL.
    MESSAGE s084(sv).
  ELSE.
    CALL FUNCTION 'VIEWCLUSTER_HELP_VALUES_NEW'
         EXPORTING
              object    = vim_object
              fieldname = vim_objfield
         EXCEPTIONS
              OTHERS    = 1.
    IF sy-subrc <> 0.
      MESSAGE s084(sv).
    ENDIF.
  ENDIF.
ENDMODULE.                             " VCL_HELP_VALUES  INPUT

*******************************************************************
*   User-defined Include-files (if necessary).                    *
*******************************************************************
* INCLUDE LZSOFTCOPY_DBMF...                 " Subprograms
* INCLUDE LZSOFTCOPY_DBMO...                 " PBO-Modules
* INCLUDE LZSOFTCOPY_DBMI...                 " PAI-Modules
