.nf
 
 
    ========== licence begin  GPL
    Copyright (c) 2000-2004 SAP AG
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    ========== licence end
 
.fo
*****************************************************
Copyright (c) 2000-2004 SAP AG
SAP Database Technology
 
Release :      Date : 2000-09-11
*****************************************************
modname : VAK503
changed : 2000-09-11
module  : Executing_union
 
Author  : ElkeZ
Created : 1985-10-16
*****************************************************
 
Purpose : Module to execute union-commands.
 
Define  :
 
        PROCEDURE
              a503build_union_buffer (
                    VAR acv : tak_all_command_glob;
                    in_join : boolean);
 
        PROCEDURE
              a503union_execution (
                    VAR acv                 : tak_all_command_glob;
                    VAR dmli                : tak_dml_info;
                    VAR change_rec          : tak_changerecord;
                    VAR parsk               : tak_parskey;
                    output_during_execution : boolean);
 
.CM *-END-* define --------------------------------------
***********************************************************
 
Use     :
 
        FROM
              Scanner : VAK01;
 
        VAR
              a01sysnullkey         : tgg00_SysInfoKey;
              a01_il_b_identifier   : tsp00_KnlIdentifier;
              a01_union_fill_resname: tsp00_KnlIdentifier;
              a01_zero_res_name     : tsp00_KnlIdentifier;
 
      ------------------------------ 
 
        FROM
              AK_universal_semantic_tools : VAK06;
 
        PROCEDURE
              a06dml_send_mess_buf (
                    VAR acv    : tak_all_command_glob;
                    VAR mblock : tgg00_MessBlock;
                    VAR dmli   : tak_dml_info;
                    VAR b_err  : tgg00_BasisError);
 
        PROCEDURE
              a06a_mblock_init (
                    VAR acv      : tak_all_command_glob;
                    mtype        : tgg00_MessType;
                    m2type       : tgg00_MessType2;
                    VAR tree     : tgg00_FileId);
 
        PROCEDURE
              a06destroy_temp (
                    VAR acv     : tak_all_command_glob;
                    VAR temp_id : tgg00_FileId;
                    VAR b_err   : tgg00_BasisError);
 
        PROCEDURE
              a06move_file_content (
                    VAR acv    : tak_all_command_glob;
                    VAR old_id : tgg00_FileId;
                    VAR new_id : tgg00_FileId;
                    VAR b_err  : tgg00_BasisError);
 
        PROCEDURE
              a06rsend_mess_buf (
                    VAR acv      : tak_all_command_glob;
                    VAR mblock   : tgg00_MessBlock;
                    result_req   : boolean;
                    VAR e        : tgg00_BasisError);
 
        PROCEDURE
              a06tempfile_empty (
                    VAR acv     : tak_all_command_glob;
                    VAR temp_id : tgg00_FileId;
                    VAR b_err   : tgg00_BasisError);
 
        PROCEDURE
              a06subquery_del_result (
                    VAR acv           : tak_all_command_glob;
                    VAR dmli          : tak_dml_info;
                    VAR subquery_tree : tgg00_FileId;
                    prefix_len        : integer);
 
      ------------------------------ 
 
        FROM
              AK_error_handling : VAK07;
 
        PROCEDURE
              a07_b_put_error (
                    VAR acv : tak_all_command_glob;
                    b_err   : tgg00_BasisError;
                    err_code : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              AK_error_handling : VAK071;
 
        FUNCTION
              a07_return_code (
                    b_err   : tgg00_BasisError;
                    sqlmode : tsp00_SqlMode) : tsp00_Int2;
 
      ------------------------------ 
 
        FROM
              Systeminfo_cache : VAK10;
 
        PROCEDURE
              a10_copy_catalog_rec (
                    VAR acv         : tak_all_command_glob;
                    VAR old_key     : tgg00_SysInfoKey;
                    del_old_rec     : boolean;
                    VAR new_key     : tgg00_SysInfoKey;
                    new_segment_id  : tsp00_C2;
                    add_new_rec     : boolean;
                    VAR b_err       : tgg00_BasisError);
 
        PROCEDURE
              a10get_sysinfo (
                    VAR acv      : tak_all_command_glob;
                    VAR syskey   : tgg00_SysInfoKey;
                    dstate       : tak_directory_state;
                    VAR syspoint : tak_sysbufferaddress;
                    VAR b_err    : tgg00_BasisError);
 
        PROCEDURE
              a10rel_sysinfo (syspointer : tak_sysbufferaddress);
 
      ------------------------------ 
 
        FROM
              Executing_dispatcher : VAK501;
 
        PROCEDURE
              a501exec_with_change_rec (
                    VAR acv                 : tak_all_command_glob;
                    VAR dmli                : tak_dml_info;
                    VAR parsk               : tak_parskey;
                    VAR change_rec          : tak_changerecord;
                    output_during_execution : boolean);
 
      ------------------------------ 
 
        FROM
              Executing_finish : VAk507;
 
        PROCEDURE
              a507select_part (
                    VAR acv        : tak_all_command_glob;
                    pos            : integer;
                    qbufp          : tak_sysbufferaddress;
                    VAR parsk      : tak_parskey;
                    VAR dmli       : tak_dml_info;
                    VAR ssr_rec    : tak70_select_strat_rec);
 
      ------------------------------ 
 
        FROM
              Select_Syntax : VAK60;
 
        PROCEDURE
              a60rescount (
                    VAR acv  : tak_all_command_glob;
                    rescount : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              Resultname_handling : VAK663;
 
        PROCEDURE
              a663_get_result_info (
                    VAR acv          : tak_all_command_glob;
                    VAR resname      : tsp00_KnlIdentifier;
                    VAR modul_name   : tsp00_KnlIdentifier;
                    VAR resname_addr : tak_sysbufferaddress;
                    make_new_res     : boolean;
                    ftemptype        : tgg00_TfnTemp;
                    dstate           : tak_directory_state;
                    VAR f_ok         : boolean);
 
      ------------------------------ 
 
        FROM
              Select_Help_Procedures : VGG04;
 
        PROCEDURE
              g04build_temp_tree_id (
                    VAR curr : tgg00_FileId;
                    VAR t : tgg00_TransContext);
 
      ------------------------------ 
 
        FROM
              Kernel_move_and_fill : VGG101;
 
        PROCEDURE
              SAPDB_PascalFill (
                    mod_id      : tsp00_C6;
                    mod_num     : tsp00_Int4;
                    obj_upb     : tsp00_Int4;
                    obj         : tsp00_MoveObjPtr;
                    obj_pos     : tsp00_Int4;
                    length      : tsp00_Int4;
                    fillchar    : char;
                    VAR e       : tgg00_BasisError);
 
        PROCEDURE
              SAPDB_PascalUnicodeFill (
                    mod_id      : tsp00_C6;
                    mod_num     : tsp00_Int4;
                    obj_upb     : tsp00_Int4;
                    obj         : tsp00_MoveObjPtr;
                    obj_pos     : tsp00_Int4;
                    length      : tsp00_Int4;
                    fillchar    : tsp00_C2;
                    VAR e       : tgg00_BasisError);
 
        PROCEDURE
              SAPDB_PascalForcedUnicodeFill (
                    obj_upb     : tsp00_Int4;
                    obj         : tsp00_MoveObjPtr;
                    obj_pos     : tsp00_Int4;
                    length      : tsp00_Int4;
                    fillchar    : tsp00_C2 );
 
        PROCEDURE
              SAPDB_PascalMove (
                    mod_id      : tsp00_C6;
                    mod_num     : tsp00_Int4;
                    source_upb  : tsp00_Int4;
                    dest_upb    : tsp00_Int4;
                    source      : tsp00_MoveObjPtr;
                    src_pos     : tsp00_Int4;
                    destin      : tsp00_MoveObjPtr;
                    dest_pos    : tsp00_Int4;
                    length      : tsp00_Int4;
                    VAR e       : tgg00_BasisError);
 
        PROCEDURE
              SAPDB_PascalOverlappingMove (
                    mod_id      : tsp00_C6;
                    mod_num     : tsp00_Int4;
                    source_upb  : tsp00_Int4;
                    dest_upb    : tsp00_Int4;
                    source      : tsp00_MoveObjPtr;
                    src_pos     : tsp00_Int4;
                    destin      : tsp00_MoveObjPtr;
                    dest_pos    : tsp00_Int4;
                    length      : tsp00_Int4;
                    VAR e       : tgg00_BasisError);
 
        PROCEDURE
              SAPDB_PascalForcedFill (
                    size        : tsp00_Int4;
                    m           : tsp00_MoveObjPtr;
                    pos         : tsp00_Int4;
                    len         : tsp00_Int4;
                    fillchar    : char);
 
        PROCEDURE
              SAPDB_PascalForcedMove (
                    source_upb  : tsp00_Int4;
                    destin_upb  : tsp00_Int4;
                    source      : tsp00_MoveObjPtr;
                    source_pos  : tsp00_Int4;
                    destin      : tsp00_MoveObjPtr;
                    destin_pos  : tsp00_Int4;
                    length      : tsp00_Int4);
 
        PROCEDURE
              SAPDB_PascalForcedOverlappingMove (
                    source_upb  : tsp00_Int4;
                    destin_upb  : tsp00_Int4;
                    source      : tsp00_MoveObjPtr;
                    source_pos  : tsp00_Int4;
                    destin      : tsp00_MoveObjPtr;
                    destin_pos  : tsp00_Int4;
                    length      : tsp00_Int4);
 
        PROCEDURE
              g10mv (
                    mod_id      : tsp00_C6;            
                    mod_num     : tsp00_Int4;
                    source_upb  : tsp00_Int4;          
                    dest_upb    : tsp00_Int4;
                    source      : tsp00_MoveObjPtr;       
                    src_pos     : tsp00_Int4;
                    destin      : tsp00_MoveObjPtr;       
                    dest_pos    : tsp00_Int4;
                    length      : tsp00_Int4;
                    VAR e       : tgg00_BasisError);
 
        PROCEDURE
              s10mv (
                    source_upb  : tsp00_Int4;       
                    destin_upb  : tsp00_Int4;
                    source      : tsp00_MoveObjPtr;    
                    source_pos  : tsp00_Int4;
                    destin      : tsp00_MoveObjPtr;    
                    destin_pos  : tsp00_Int4;
                    length      : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              RTE-Extension-20 : VSP20;
 
        PROCEDURE
              s20ch4a (
                    val      : tsp00_Int4;
                    VAR dest : tsp00_Buf;
                    di       : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              GET-Conversions : VSP40;
 
        PROCEDURE
              s40g4int (
                    VAR buf  : tsp00_ResNum;
                    pos      : tsp00_Int4;
                    VAR dest : tsp00_Int4;
                    VAR res  : tsp00_NumError);
 
      ------------------------------ 
 
        FROM
              PUT-Conversions : VSP41;
 
        PROCEDURE
              s41p4int (
                    VAR buf : tsp00_ResNum;
                    pos     : tsp00_Int4;
                    source  : tsp00_Int4;
                    VAR res : tsp00_NumError);
&       IFDEF TRACE
 
      ------------------------------ 
 
        FROM
              Test_Procedures : VTA01;
 
        PROCEDURE
              t01sname (
                    debug   : tgg00_Debug;
                    nam     : tsp00_Sname);
 
        PROCEDURE
              t01bool (
                    debug    : tgg00_Debug;
                    nam      : tsp00_Sname;
                    curr_bool: boolean);
 
        PROCEDURE
              t01lidentifier (
                    debug      : tgg00_Debug;
                    identifier : tsp00_KnlIdentifier);
 
        PROCEDURE
              t01messblock (
                    debug         : tgg00_Debug;
                    nam           : tsp00_Sname;
                    VAR m         : tgg00_MessBlock);
 
        PROCEDURE
              t01int4 (
                    level : tgg00_Debug;
                    nam : tsp00_Sname;
                    int : tsp00_Int4);
 
        PROCEDURE
              t01buf  (
                    level     : tgg00_Debug;
                    VAR buf   : tak_systembuffer;
                    pos_start : integer;
                    pos_end   : integer);
 
        PROCEDURE
              t01name (
                    level : tgg00_Debug;
                    nam : tsp00_Name);
 
        PROCEDURE
              t01treeid (
                    level      : tgg00_Debug;
                    nam        : tsp00_Sname;
                    VAR treeid : tgg00_FileId);
&       ENDIF
 
.CM *-END-* use -----------------------------------------
***********************************************************
 
Synonym :
 
        PROCEDURE
              s20ch4a;
 
              tsp00_MoveObj tsp00_Buf
 
        PROCEDURE
              s40g4int;
 
              tsp00_MoveObj tsp00_ResNum
 
        PROCEDURE
              s41p4int;
 
              tsp00_MoveObj tsp00_ResNum
 
        PROCEDURE
              t01buf;
 
              tsp00_Buf tak_systembuffer
 
.CM *-END-* synonym -------------------------------------
***********************************************************
.CM -lll-
Code    :
 
 
CONST
      c_del_old_rec      = true (* a10_copy_catalog_rec *);
      c_add_new_rec      = true (* a10_copy_catalog_rec *);
      c_first            = true (* ak503loop_union *);
      c_make_new_res     = true (* a663_get_result_info *);
 
 
(*------------------------------*) 
 
PROCEDURE
      a503build_union_buffer (
            VAR acv : tak_all_command_glob;
            in_join : boolean);
 
VAR
      _keylen     : tsp_int_map_c2;
      _reclen     : tsp_int_map_c2;
      _i          : integer;
      _key_offset : integer;
      _strat_pos  : integer;
      _keylenpos  : integer;
      _reclenpos  : integer;
      _gg_strategy_ptr : ^tgg07_StrategyInfo;
      _union_kind : tsp00_Uint1;
 
BEGIN
_gg_strategy_ptr := @acv.a_mblock.
      mb_strat^[ acv.a_mblock.mb_st^[ acv.a_mblock.mb_qual^.mstrat_pos ].epos ];
acv.a_union_append := acv.a_unionrec_ptr^.sunionrec.uappend_all;
_strat_pos := acv.a_mblock.mb_st^[ acv.a_mblock.mb_qual^.mstrat_pos ].epos;
acv.a_send_messbuf := ( acv.a_send_messbuf OR acv.a_first_union );
&IFDEF TRACE
t01bool( ak_sem, 'a_send_messb', acv.a_send_messbuf );
&ENDIF
IF  in_join
THEN
    BEGIN
    (* get tgg07_JoinResInfo.n_key_len and tgg07_JoinResInfo.n_res_rec_len length *)
    _keylenpos := _strat_pos +
          acv.a_mblock.mb_st^[ acv.a_mblock.mb_qual^.mstrat_pos ].elen_var +
          FILE_ID_MXGG00 + 6;
    _reclenpos := _strat_pos +
          acv.a_mblock.mb_st^[ acv.a_mblock.mb_qual^.mstrat_pos ].elen_var +
          FILE_ID_MXGG00 + 8;
    IF  ( acv.a_mblock.mb_qual^.mresqual_cnt > 0 )
    THEN
        _keylen.map_int := acv.a_mblock.
              mb_st^[ acv.a_mblock.mb_qual^.mstrat_pos + 1 ].ecol_pos
    ELSE
        BEGIN
        _keylen.map_c2[ 1 ] := acv.a_mblock.mb_strat^[ _keylenpos ];
        _keylen.map_c2[ 2 ] := acv.a_mblock.mb_strat^[ _keylenpos + 1 ];
        END;
    (*ENDIF*) 
    _reclen.map_c2[ 1 ] := acv.a_mblock.mb_strat^[ _reclenpos ];
    _reclen.map_c2[ 2 ] := acv.a_mblock.mb_strat^[ _reclenpos + 1 ];
    END
ELSE
    BEGIN
    _keylen.map_int := _gg_strategy_ptr^.str_key_len;
    _reclen.map_int := _gg_strategy_ptr^.str_rec_len;
    END;
(*ENDIF*) 
&IFDEF TRACE
t01bool( ak_sem, 'a_send_messb', acv.a_send_messbuf );
t01bool( ak_sem, 'in_join     ', in_join );
t01int4 (ak_sem, 'old reclen  ', _reclen.map_int);
t01int4 (ak_sem, 'old keylen  ', _keylen.map_int);
&ENDIF
IF   acv.a_unionrec_ptr^.sunionrec.uappend_all
THEN
    BEGIN
    _union_kind     := acv.a_union_kind + cgg04_union_append;
    acv.a_send_messbuf := acv.a_first_union;
&   IFDEF TRACE
    t01bool( ak_sem, 'a_send_messb', acv.a_send_messbuf );
&   ENDIF
    END
ELSE
    _union_kind := acv.a_union_kind;
(*ENDIF*) 
_gg_strategy_ptr^.str_union_kind := _union_kind;
&ifdef trace
t01int4( ak_join, 'str_union_ki', _union_kind );
&endif
IF  ( _keylen.map_int < acv.a_unionrec_ptr^.sunionrec.ukeylen )
THEN
    BEGIN
    (* shift columns forward *)
    _key_offset := acv.a_unionrec_ptr^.sunionrec.ukeylen - _keylen.map_int;
    IF  ( acv.a_mblock.mb_type2 = mm_with_join ) OR
        ( acv.a_mblock.mb_type2 = mm_join_with_last_tab )
    THEN
        BEGIN
        FOR _i := acv.a_mblock.mb_qual^.mqual_pos TO
              ( acv.a_mblock.mb_qual^.mfirst_free - 1 ) DO
            WITH acv.a_mblock.mb_st^ [_i] DO
                IF  (( etype = st_output_join ) AND
                    ( ecol_pos > _keylen.map_int + cgg_rec_key_offset ))
                THEN
                    ecol_pos := ecol_pos + _key_offset;
                (*ENDIF*) 
            (*ENDWITH*) 
        (*ENDFOR*) 
        END
    ELSE
        BEGIN
        FOR _i := acv.a_mblock.mb_qual^.mqual_pos TO
              acv.a_mblock.mb_st^[ acv.a_mblock.mb_qual^.mqual_pos ].epos DO
            WITH acv.a_mblock.mb_st^[ _i ] DO
                IF  (( etype = st_output ) AND
                    ( epos > _keylen.map_int + cgg_rec_key_offset ))
                THEN
                    epos := epos + _key_offset;
                (*ENDIF*) 
            (*ENDWITH*) 
        (*ENDFOR*) 
        END;
    (*ENDIF*) 
    _keylen.map_int := acv.a_unionrec_ptr^.sunionrec.ukeylen;
    _reclen.map_int := _reclen.map_int + _key_offset;
    IF  in_join
    THEN
        BEGIN
        IF  ( acv.a_mblock.mb_qual^.mresqual_cnt > 0 )
        THEN
            acv.a_mblock.mb_st^[ acv.a_mblock.mb_qual^.mstrat_pos + 1 ].
                  ecol_pos := _keylen.map_int
        ELSE
            BEGIN
            acv.a_mblock.mb_strat^[ _keylenpos ]     := _keylen.map_c2[ 1 ];
            acv.a_mblock.mb_strat^[ _keylenpos + 1 ] := _keylen.map_c2[ 2 ];
            END;
        (*ENDIF*) 
        acv.a_mblock.mb_strat^[ _reclenpos ]     := _reclen.map_c2[ 1 ];
        acv.a_mblock.mb_strat^[ _reclenpos + 1 ] := _reclen.map_c2[ 2 ];
        END
    ELSE
        BEGIN
        _gg_strategy_ptr^.str_key_len := _keylen.map_int;
        _gg_strategy_ptr^.str_rec_len := _reclen.map_int;
        END;
    (*ENDIF*) 
&   ifdef trace
    t01int4 (ak_sem, 'new reclen  ', _reclen.map_int);
    t01int4 (ak_sem, 'new keylen  ', _keylen.map_int);
&   endif
    END
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a503union_execution (
            VAR acv                 : tak_all_command_glob;
            VAR dmli                : tak_dml_info;
            VAR change_rec          : tak_changerecord;
            VAR parsk               : tak_parskey;
            output_during_execution : boolean);
 
VAR
      _b_err            : tgg00_BasisError;
      _res              : tsp00_NumError;
      _i                : integer;
      _pos              : integer;
      _key_cnt_offs     : tsp00_Int4;
      _res_cnt          : tsp00_Int4;
      _ke               : tgg00_SysInfoKey;
      _dummybuf         : tak_sysbufferaddress;
      _munionbuf        : tak_sysbufferaddress;
      _union_id         : tgg00_FileId;
      _is_insert_select : boolean;
      _f_ok             : boolean;
      _resname          : tsp00_KnlIdentifier;
      _modul_name       : tsp00_KnlIdentifier;
      _rep_res          : boolean;
      _ssr_rec          : tak70_select_strat_rec;
 
BEGIN
&IFDEF TRACE
t01int4 (ak_sem,  'parsk.p_id  ', ord(parsk.p_id[ 1 ]));
t01int4 (ak_sem,  'parsk.p_kind', ord(parsk.p_kind));
t01int4 (ak_sem,  'parsk.p_no  ', ord(parsk.p_no));
&ENDIF
_pos            := cak_intern_pos;
_munionbuf      := acv.a_unionrec_ptr;
_ke             := a01sysnullkey;
_ke.sauthid[ 1 ] := cak_tempinfo_byte;
s10mv (sizeof(parsk), sizeof(_ke.sauthid), @parsk, 1,
      @_ke.sauthid, 2, mxak_parskey );
_ke.sentrytyp := cak_eunionrec;
a10get_sysinfo ( acv, _ke, d_fix, acv.a_unionrec_ptr, _b_err);
IF  _b_err <> e_ok
THEN
    a07_b_put_error (acv, _b_err, 1)
ELSE
    BEGIN
&   IFDEF TRACE
    t01buf (ak_sem, acv.a_unionrec_ptr^, 1, acv.a_unionrec_ptr^.b_sl);
    WITH acv.a_unionrec_ptr^.sunionrec DO
        FOR _i := 1 TO uselect_cnt - 1 DO
            WITH uselect_arr [ _i ] DO
                BEGIN
                t01int4 (ak_sem, 'index       ', _i);
                t01int4 (ak_sem, 'ufirstsel   ', ufirstsel);
                t01int4 (ak_sem, 'usecondsel  ', usecondsel);
                t01int4 (ak_sem, 'uis_kind    ', ord(uis_kind));
                t01int4 (ak_sem, 'uis_all     ', ord(uis_all));
                t01sname( ak_sem, '+----------+' );
                END;
            (*ENDWITH*) 
        (*ENDFOR*) 
    (*ENDWITH*) 
&   ENDIF
    acv.a_union_cnt  := 0;
    acv.a_next_upos  := cak_is_undefined; (* Sequence of unions *)
&   IFDEF TRACE
    t01int4 (ak_sem, 'max_intern_s', acv.a_max_intern_select);
    t01int4 (ak_sem, 'intern_selec', acv.a_intern_select_cnt);
    t01int4 (ak_sem, 'command_kind', ord(acv.a_command_kind));
    t01lidentifier (ak_syn, acv.a_modul_name);
    t01lidentifier (ak_syn, acv.a_unionrec_ptr^.sunionrec.umodul_name);
&   ENDIF
    IF  acv.a_unionrec_ptr^.sunionrec.ures_name <> a01_union_fill_resname
    THEN
        BEGIN
        WITH acv.a_unionrec_ptr^.sunionrec.ures_tree DO
            IF  (fileTfnTemp_gg00 = ttfnUserResult_egg00)
            THEN
                BEGIN
                IF  dmli.d_resname <> a01_zero_res_name
                THEN
                    IF  (acv.a_unionrec_ptr^.sunionrec.ures_name <>
                        a01_il_b_identifier) AND
                        (acv.a_unionrec_ptr^.sunionrec.ures_name <>
                        dmli.d_resname)
                    THEN
                        a07_b_put_error (acv,
                              e_no_resulttable_allowed, 1)
                    ELSE
                        BEGIN
                        _resname    := dmli.d_resname;
                        _modul_name := acv.a_unionrec_ptr^.
                              sunionrec.umodul_name;
                        END
                    (*ENDIF*) 
                ELSE
                    BEGIN
                    _resname    := acv.a_unionrec_ptr^.sunionrec.ures_name;
                    _modul_name := acv.a_unionrec_ptr^.sunionrec.umodul_name;
                    END;
                (*ENDIF*) 
                _pos := cak_extern_pos
                END
            ELSE
                BEGIN
                _resname    := acv.a_unionrec_ptr^.sunionrec.ures_name;
                _modul_name := acv.a_unionrec_ptr^.sunionrec.umodul_name;
                _pos        := cak_intern_pos
                END;
            (*ENDIF*) 
        (*ENDWITH*) 
        a663_get_result_info (acv, _resname, _modul_name,
              acv.a_resname_addr[ _pos ], c_make_new_res,
              acv.a_unionrec_ptr^.sunionrec.ures_tree.fileTfnTemp_gg00,
              d_fix, _f_ok);
        END;
    (*ENDIF*) 
    acv.a_union_kind     := cgg04_union_byte;
    _union_id         := acv.a_unionrec_ptr^.sunionrec.ures_tree;
    _is_insert_select := acv.a_unionrec_ptr^.sunionrec.uinsertselect;
    _key_cnt_offs     := 0;
    _res_cnt          := 0;
    ak503loop_union (acv, dmli, change_rec, 1(*top*), output_during_execution,
          c_first, _union_id, _res_cnt, _key_cnt_offs);
&   IFDEF TRACE
    t01int4(ak_sem, 'RES_CNT 5031', _res_cnt);
    t01int4(ak_sem, 'KEY_CNT_OFFS', _key_cnt_offs);
    t01int4 (ak_sem, ' return_code', acv.a_returncode);
    t01int4 (ak_sem, 'command_kind', ord(acv.a_command_kind));
&   ENDIF
    END;
(*ENDIF*) 
IF  ( acv.a_returncode = 0 )
    AND
    ( acv.a_max_intern_select = acv.a_intern_select_cnt )
    AND
    (( acv.a_command_kind = single_command ) OR
    ( acv.a_command_kind = last_command ))
    AND
    (NOT _is_insert_select)
THEN
    BEGIN
    _dummybuf := NIL;
    IF  (_pos = cak_extern_pos)
    THEN
        BEGIN
        (* PTS 1119981 E.Z. *)
        IF  (dmli.d_resname_found AND
            (dmli.d_resname <> a01_zero_res_name) AND
            (dmli.d_resname <> acv.a_resname_addr[ _pos ]^.sresname.reskey_name))
        THEN
            BEGIN
            _ke := acv.a_resname_addr[ _pos ]^.syskey;
            _ke.srestablen := dmli.d_resname;
            a10_copy_catalog_rec (acv, acv.a_resname_addr[ _pos ]^.syskey,
                  c_del_old_rec, _ke, cak00_local_segment_id,
                  NOT c_add_new_rec, _b_err);
            IF  _b_err <> e_ok
            THEN
                a07_b_put_error (acv, _b_err, 1)
            ELSE
                a10get_sysinfo ( acv, _ke, d_fix, acv.a_resname_addr[ _pos ], _b_err);
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        _rep_res            := dmli.d_repl_reskey;
        dmli.d_repl_reskey := false;
        _ssr_rec.ssr_old_strategynum := strat_inv_in;
        _ssr_rec.ssr_new_strategynum := strat_inv_in;
        _ssr_rec.ssr_invlen := 0;
        _ssr_rec.ssr_reverse_access := false;
        _ssr_rec.ssr_filler         := false;
        (* PTS 1001532 E.Z. *)
        acv.a_mblock.mb_qual^.mr_resnum[1] := csp_defined_byte;
        s41p4int (acv.a_mblock.mb_qual^.mr_resnum, 2, _res_cnt, _res);
        a507select_part( acv, _pos, _dummybuf, parsk, dmli, _ssr_rec);
        dmli.d_repl_reskey := _rep_res;
        END;
    (*ENDIF*) 
    acv.a_union_cnt   := 0;
    acv.a_result_name := _resname;
    IF  _res_cnt = 0
    THEN
        BEGIN
        a07_b_put_error (acv, e_row_not_found, 1)
        END
    ELSE
        IF  acv.a_sqlmode = sqlm_oracle
        THEN
            a60rescount (acv, 0)
        ELSE
            a60rescount (acv, _res_cnt)
        (*ENDIF*) 
    (*ENDIF*) 
    END
ELSE
    acv.a_union_cnt := 0;
(*ENDIF*) 
IF  _b_err <> e_ok
THEN
    a07_b_put_error (acv, _b_err, 1);
(*ENDIF*) 
IF  (acv.a_returncode = 0)  OR
    (acv.a_returncode = 100)
THEN
    a10rel_sysinfo (acv.a_unionrec_ptr);
(*ENDIF*) 
acv.a_unionrec_ptr := _munionbuf;
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak503build_union_result (
            VAR acv              : tak_all_command_glob;
            VAR dmli              : tak_dml_info;
            VAR first_tree        : tgg00_FileId;
            VAR second_tree       : tgg00_FileId;
            VAR res_cnt           : tsp00_Int4;
            VAR key_cnt_offs      : tsp00_Int4;
            second_res_cnt        : tsp00_Int4;
            first                 : boolean;
            one_union_select_call : boolean);
 
VAR
      _send_mess_buf     : boolean;
      _e                 : tgg00_BasisError;
      _res               : tsp00_NumError;
      _ic2               : tsp_int_map_c2;
      _uinv1_id          : tgg00_FileId;
      _uinv2_id          : tgg00_FileId;
      _sub_del_help_tree : tgg00_FileId;
      _union_kind        : tsp00_Uint1;
      _strat_len         : integer;
      _strat            : tgg07_StrategyInfo;
 
BEGIN
&IFDEF TRACE
t01bool (ak_sem, 'one_union_se', one_union_select_call);
t01int4 (ak_sem, 'first       ', ord (first));
t01int4 (ak_sem, 'res_cnt     ', res_cnt);
t01int4 (ak_sem, 'res_cnt 2   ', second_res_cnt);
t01treeid (ak_sem, 'first_tree  ', first_tree);
t01treeid (ak_sem, 'second_tree ', second_tree);
&ENDIF
g04build_temp_tree_id (_sub_del_help_tree, acv.a_transinf.tri_trans);
_sub_del_help_tree.fileTfnTemp_gg00 := ttfnSubquery_egg00;
_sub_del_help_tree.fileLevel_gg00[ 1 ] := chr(acv.a_unionrec_ptr^.sunionrec.usubcount);
IF  acv.a_unionrec_ptr^.sunionrec.usubcount > 0
THEN
    a06subquery_del_result (acv,
          dmli, _sub_del_help_tree, TEMP_PREFIX_MXGG00 + 3);
&IFDEF TRACE
(*ENDIF*) 
t01treeid (ak_sem, 'sub_del_help', _sub_del_help_tree);
&ENDIF
_e             := e_ok;
_send_mess_buf := true;
&IFDEF TRACE
WITH acv.a_unionrec_ptr^.sunionrec DO
    IF  first
        AND
        (( urowno = cgg04_at_least_one_record ) OR ( urowno = cgg04_subquery_one_record ))
        AND
        (( acv.a_union_kind = 1 ) OR ( acv.a_union_kind = 4 ))
    THEN
        t01int4 (ak_sem, '$urowno     ', urowno);
&   ENDIF
    (*ENDIF*) 
(*ENDWITH*) 
IF  first AND
    ((acv.a_unionrec_ptr^.sunionrec.urowno = cgg04_at_least_one_record) OR
    (acv.a_unionrec_ptr^.sunionrec.urowno = cgg04_subquery_one_record)) AND
    ((acv.a_union_kind = 1) OR (acv.a_union_kind = 4))
THEN
    CASE acv.a_unionrec_ptr^.sunionrec.urowno OF
        cgg04_at_least_one_record :
            IF  (res_cnt = 0) AND (second_res_cnt <> 0)
            THEN
                BEGIN
                res_cnt       := second_res_cnt;
                _send_mess_buf := false;
                a06move_file_content (acv, second_tree,
                      first_tree, _e);
                IF  _e <> e_ok
                THEN
                    a07_b_put_error (acv, _e, 1)
                ELSE
                    BEGIN
                    acv.a_mblock.mb_qual^.mr_resnum[ 1 ] := csp_defined_byte;
                    acv.a_mblock.mb_qual^.mr_restree     := first_tree;
                    acv.a_mblock.mb_qual_len  := MB_PART1_HEAD_MXGG00 +
                          sizeof(tsp00_ResNum) + 1 + FILE_ID_MXGG00;
                    acv.a_mblock.mb_data_len           := 0;
                    acv.a_mblock.mb_type    := m_return_result;
                    acv.a_mblock.mb_type2              := mm_file
                    END;
                (*ENDIF*) 
                END
            ELSE
                BEGIN
                _send_mess_buf := false;
                a06destroy_temp (acv, second_tree, _e);
                END;
            (*ENDIF*) 
        cgg04_subquery_one_record :
            IF  (acv.a_max_intern_select = acv.a_intern_select_cnt) AND
                ((acv.a_union_kind = 4) AND (res_cnt + second_res_cnt >= 2)) OR
                ((acv.a_union_kind = 1) AND (res_cnt >= 2))
            THEN
                BEGIN
                _send_mess_buf := false;
                a06destroy_temp (acv, first_tree, _e);
                a06destroy_temp (acv, second_tree, _e);
                a07_b_put_error (acv, e_too_many_resultsets, 1);
                END;
            (*ENDIF*) 
        OTHERWISE : ;
        END;
    (*ENDCASE*) 
(*ENDIF*) 
IF  (( res_cnt = 0 ) OR ( second_res_cnt = 0 ) AND _send_mess_buf )
    AND (NOT one_union_select_call)
THEN
    BEGIN
&   IFDEF TRACE
    t01int4 (ak_sem, '$acv_union_k', acv.a_union_kind);
&   ENDIF
    CASE acv.a_union_kind OF
        cgg04_union_byte, cgg04_union_byte + 3 : (* union, union all *)
            IF  ( res_cnt = 0 ) AND ( second_res_cnt <> 0 )
            THEN
                BEGIN
                _uinv2_id                  := second_tree;
                _uinv2_id.fileTfnTemp_gg00 := ttfnUnionIndex_egg00;
                _uinv2_id.fileRoot_gg00    := NIL_PAGE_NO_GG00;
                _uinv1_id                  := first_tree;
                _uinv1_id.fileTfnTemp_gg00 := ttfnUnionIndex_egg00;
                _uinv1_id.fileRoot_gg00    := NIL_PAGE_NO_GG00;
&               IFDEF TRACE
                t01treeid (ak_sem, '$uinv2_id   ', _uinv2_id);
&               ENDIF
                res_cnt := second_res_cnt;
                a06move_file_content(acv, second_tree,
                      first_tree, _e);
                IF  _e <> e_ok
                THEN
                    a07_b_put_error (acv, _e, 1)
                (*ENDIF*) 
                END
            ELSE
                IF  second_res_cnt = 0
                THEN
                    a06destroy_temp (acv, second_tree, _e);
                (*ENDIF*) 
            (*ENDIF*) 
        cgg04_except_byte, cgg04_except_byte + 3 : (* except, except all *)
            a06destroy_temp (acv, second_tree, _e);
        cgg04_intersect_byte, cgg04_intersect_byte + 3 : (* intersect, intersect all *)
            BEGIN
            IF  res_cnt <> 0
            THEN
                BEGIN
                res_cnt := 0;
                _uinv1_id                  := first_tree;
                _uinv1_id.fileTfnTemp_gg00 := ttfnUnionIndex_egg00;
                _uinv1_id.fileRoot_gg00    := NIL_PAGE_NO_GG00;
                a06tempfile_empty (acv, first_tree, _e);
                a06tempfile_empty (acv, _uinv1_id, _e);
                END;
            (*ENDIF*) 
            a06destroy_temp (acv, second_tree, _e);
            END;
        END;
    (*ENDCASE*) 
    _send_mess_buf           := false;
    acv.a_mblock.mb_qual^.mr_resnum[ 1 ] := csp_defined_byte;
    acv.a_mblock.mb_qual^.mr_restree     := first_tree;
    acv.a_mblock.mb_qual_len  := MB_PART1_HEAD_MXGG00 +
          sizeof(tsp00_ResNum) + 1 + FILE_ID_MXGG00;
    acv.a_mblock.mb_data_len           := 0;
    acv.a_mblock.mb_type    := m_return_result;
    acv.a_mblock.mb_type2              := mm_file
    END;
(*ENDIF*) 
IF  _e <> e_ok
THEN
    a07_b_put_error (acv, _e, 1);
(*ENDIF*) 
IF  _send_mess_buf AND ( acv.a_returncode = 0 )
THEN
    BEGIN
    IF  one_union_select_call
    THEN
        (* *** kb is called with a combinied union-select-call,         *)
        (*     that means, that union-call and select-call will be      *)
        (*     executed at one time.                                *** *)
        BEGIN
&       IFDEF TRACE
        t01messblock (ak_sem, 'MBLOCK 503bu', acv.a_mblock);
&       ENDIF
        _strat_len := acv.a_mblock.mb_st^ [acv.a_mblock.mb_qual^.mstrat_pos].elen_var;
        IF  _strat_len > sizeof(_strat)
        THEN
            _strat_len := sizeof(_strat);
        (*ENDIF*) 
        g10mv ('VAK503',   1,    
              acv.a_mblock.mb_strat_size, sizeof( _strat ),
              @acv.a_mblock.mb_strat^, acv.a_mblock.mb_st^[ acv.a_mblock.mb_qual^.mstrat_pos ].epos,
              @_strat, 1, _strat_len,
              acv.a_returncode);
        _strat.str_foundresults       := res_cnt;
        _strat.str_union_key_cnt_offs := key_cnt_offs;
        (* PTS 1122903 E.Z. *)
&       IFDEF TRACE
        t01treeid (ak_sem, 'first_tree  ', first_tree);
        t01treeid (ak_sem, 'qual.mtree  ', acv.a_mblock.mb_qual^.mtree);
&       ENDIF
        _strat.str_result_id := first_tree;
        _strat.str_result_id.fileHandling_gg00 := _strat.str_result_id.fileHandling_gg00 -
              [hsCreateFile_egg00];
        IF  res_cnt > 0
        THEN
            IF   acv.a_unionrec_ptr^.sunionrec.uappend_all
            THEN
                _strat.str_union_kind := acv.a_union_kind + cgg04_union_select +
                      cgg04_union_append
            ELSE
                _strat.str_union_kind := acv.a_union_kind + cgg04_union_select;
            (*ENDIF*) 
&       IFDEF TRACE
        (*ENDIF*) 
        t01int4 (ak_sem, 'str_union_ki', _strat.str_union_kind);
&       ENDIF
        g10mv ('VAK503',   2,    
              sizeof( _strat ), acv.a_mblock.mb_strat_size,
              @_strat, 1,
              @acv.a_mblock.mb_strat^, acv.a_mblock.mb_st^[ acv.a_mblock.mb_qual^.mstrat_pos ].epos,
              _strat_len, acv.a_returncode);
        a06dml_send_mess_buf (acv, acv.a_mblock, dmli, _e);
        IF  acv.a_sub_found
        THEN
            WITH acv.a_unionrec_ptr^.sunionrec DO
                BEGIN
                acv.a_sub_found := false;
                g04build_temp_tree_id (_sub_del_help_tree,
                      acv.a_transinf.tri_trans);
                _sub_del_help_tree.fileTfnTemp_gg00   := ttfnSubquery_egg00;
                IF  (dmli.d_sparr.px[ 1 ]^.sparsinfo.p_subcntlevel
                    >= 0)
                THEN
                    _sub_del_help_tree.fileLevel_gg00[ 1 ] :=
                          chr(dmli.d_sparr.px[ 1 ]^.sparsinfo.p_subcntlevel);
                (*ENDIF*) 
                a06subquery_del_result (acv,
                      dmli, _sub_del_help_tree,
                      TEMP_PREFIX_MXGG00 + 3);
                END;
            (*ENDWITH*) 
        (*ENDIF*) 
        END
    ELSE
        BEGIN
        a06a_mblock_init (acv, m_union, mm_nil, first_tree);
        g10mv ('VAK503',   3,    
              sizeof(second_tree), acv.a_mblock.mb_qual_size,
              @second_tree, 1, @acv.a_mblock.mb_qual^.buf, MB_PART1_HEAD_MXGG00 + 1,
              sizeof(second_tree), acv.a_returncode);
        IF   acv.a_unionrec_ptr^.sunionrec.uappend_all
        THEN
            _union_kind := ord (acv.a_union_kind) + cgg04_union_append
        ELSE
            _union_kind := acv.a_union_kind;
        (*ENDIF*) 
&       IFDEF TRACE
        t01int4 (ak_sem, 'str_union_ki', _union_kind);
&       ENDIF
        acv.a_mblock.mb_qual^.buf [ MB_PART1_HEAD_MXGG00 + FILE_ID_MXGG00 + 1 ] :=
              chr (_union_kind);
        s20ch4a (res_cnt, acv.a_mblock.mb_qual^.buf,
              MB_PART1_HEAD_MXGG00 + FILE_ID_MXGG00 + 2);
        s20ch4a (key_cnt_offs, acv.a_mblock.mb_qual^.buf,
              MB_PART1_HEAD_MXGG00 + FILE_ID_MXGG00 + 6);
        acv.a_mblock.mb_qual_len  := acv.a_mblock.mb_qual_len  + FILE_ID_MXGG00 + 9;
        WITH acv.a_unionrec_ptr^.sunionrec DO
            BEGIN
            IF  first
            THEN
                _ic2.map_int := urowno
            ELSE
                _ic2.map_int := cgg04_no_rowno_predicate;
            (*ENDIF*) 
            acv.a_mblock.mb_qual^.buf[ acv.a_mblock.mb_qual_len  + 1 ] := _ic2.map_c2[ 1 ];
            acv.a_mblock.mb_qual^.buf[ acv.a_mblock.mb_qual_len  + 2 ] := _ic2.map_c2[ 2 ];
            END;
        (*ENDWITH*) 
        acv.a_mblock.mb_qual_len  := acv.a_mblock.mb_qual_len  + 2;
        a06rsend_mess_buf (acv, acv.a_mblock, cak_return_req, _e);
        END;
    (*ENDIF*) 
    IF  _e <> e_ok
    THEN
        a07_b_put_error (acv, _e, 1);
    (*ENDIF*) 
    IF  acv.a_returncode = 0
    THEN
        s40g4int (acv.a_mblock.mb_qual^.mr_resnum, 2, res_cnt, _res);
    (*ENDIF*) 
    IF  (acv.a_returncode = 0) OR
        (acv.a_returncode =
        a07_return_code(e_row_not_found, acv.a_sqlmode))
    THEN
        s40g4int (acv.a_mblock.mb_qual^.mr_keycnt, 2, key_cnt_offs, _res);
    (*ENDIF*) 
    END
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak503loop_union (
            VAR acv                : tak_all_command_glob;
            VAR dmli                : tak_dml_info;
            VAR change_rec          : tak_changerecord;
            upos                    : tsp00_Int2;
            output_during_execution : boolean;
            first                   : boolean;
            VAR res_tree            : tgg00_FileId;
            VAR res_cnt             : tsp00_Int4;
            VAR key_cnt_offs        : tsp00_Int4);
 
VAR
      _one_union_select_call : boolean;
      _res                   : tsp00_NumError;
      _second_res_cnt        : tsp00_Int4;
      _second_tree           : tgg00_FileId;
      _i                     : integer;
 
BEGIN
&IFDEF TRACE
t01int4 (ak_sem, 'upos        ', upos);
t01int4 (ak_sem, 'ufirstsel   ', acv.a_unionrec_ptr^.sunionrec.uselect_arr[ upos ].ufirstsel);
t01int4 (ak_sem, 'usecondsel  ', acv.a_unionrec_ptr^.sunionrec.uselect_arr[ upos ].usecondsel);
t01bool (ak_sem, 'uis_all     ', acv.a_unionrec_ptr^.sunionrec.uselect_arr[ upos ].uis_all);
IF  acv.a_unionrec_ptr^.sunionrec.uselect_arr[ upos ].uis_kind = uis_none
THEN
    t01name (ak_sem, 'IS NONE           ');
(*ENDIF*) 
IF  acv.a_unionrec_ptr^.sunionrec.uselect_arr[ upos ].uis_kind = uis_union
THEN
    t01name (ak_sem, 'IS UNION          ');
(*ENDIF*) 
IF  acv.a_unionrec_ptr^.sunionrec.uselect_arr[ upos ].uis_kind = uis_except
THEN
    t01name (ak_sem, 'IS EXCEPT         ');
(*ENDIF*) 
IF  acv.a_unionrec_ptr^.sunionrec.uselect_arr[ upos ].uis_kind = uis_intersect
THEN
    t01name (ak_sem, 'IS INTERSECT      ');
&ENDIF
(*ENDIF*) 
IF  (acv.a_unionrec_ptr^.sunionrec.uselect_arr[ upos ].uis_kind = uis_union)
    OR
    (acv.a_unionrec_ptr^.sunionrec.uselect_arr[ upos ].uis_kind = uis_except)
    OR
    (acv.a_unionrec_ptr^.sunionrec.uselect_arr[ upos ].uis_kind = uis_intersect)
THEN
    BEGIN
    acv.a_union_kind := cgg04_union_byte;
    ak503loop_union (acv, dmli, change_rec,
          acv.a_unionrec_ptr^.sunionrec.uselect_arr[ upos ].ufirstsel,
          output_during_execution, NOT c_first, res_tree,
          res_cnt(*out*), key_cnt_offs(*out*));
&   IFDEF TRACE
    t01int4 (ak_sem, 'RES_CNT 5032', res_cnt );
    t01int4 (ak_sem, 'KEY_CNT_OFFS', key_cnt_offs);
    t01int4 (ak_sem, ' return_code', acv.a_returncode);
&   ENDIF
    IF  acv.a_returncode = 0
    THEN
        BEGIN
        acv.a_union_kind   := 0;
        _second_res_cnt := 0;
&       IFDEF TRACE
        t01int4 (ak_sem, 'return_loop:', 1);
&       ENDIF
        ak503loop_union (acv, dmli, change_rec,
              acv.a_unionrec_ptr^.sunionrec.uselect_arr[ upos ].usecondsel,
              output_during_execution, NOT c_first, _second_tree,
              _second_res_cnt, key_cnt_offs);
        CASE  acv.a_unionrec_ptr^.sunionrec.uselect_arr[ upos ].uis_kind OF
            uis_union     :
                acv.a_union_kind := cgg04_union_byte;
            uis_except    :
                acv.a_union_kind := cgg04_except_byte;
            uis_intersect :
                acv.a_union_kind := cgg04_intersect_byte;
            END;
        (*ENDCASE*) 
        IF  acv.a_unionrec_ptr^.sunionrec.uselect_arr[ upos ].uis_all
        THEN
            acv.a_union_kind := acv.a_union_kind + 3;
        (*ENDIF*) 
        _i := acv.a_unionrec_ptr^.sunionrec.uselect_arr[ upos ].usecondsel;
        _one_union_select_call :=
              ( NOT acv.a_send_messbuf )
              AND
              ( acv.a_union_cnt > 1 )
              AND
              (
              ( acv.a_unionrec_ptr^.sunionrec.uappend_all
              (**) AND (NOT acv.a_first_union) AND ( NOT first ))
              OR
              ( _i > acv.a_unionrec_ptr^.sunionrec.uselect_arr[ _i ].usecondsel )
              );
        IF  acv.a_returncode = 0
        THEN
            ak503build_union_result (acv, dmli, res_tree,
                  _second_tree, res_cnt, key_cnt_offs,
                  _second_res_cnt, first, _one_union_select_call);
&       IFDEF TRACE
        (*ENDIF*) 
        t01int4 (ak_sem, 'RES_CNT 5033', res_cnt);
        t01int4 (ak_sem, 'SEC_RES_CNT ', _second_res_cnt);
        t01int4 (ak_sem, 'KEY_CNT_OFFS', key_cnt_offs);
        t01int4 (ak_sem, ' return_code', acv.a_returncode);
&       ENDIF
        END
    (*ENDIF*) 
    END
ELSE
    BEGIN
    (* *** Paranthesesis may cause executing of an "inner"-            *)
    (*     union-select as first select. In this case it is            *)
    (*     necessary to execute the union and the select with two      *)
    (*     different kb-calls. "a_first_union" indicates that such     *)
    (*     a union exists at this time.                            *** *)
    acv.a_first_union := (upos > acv.a_next_upos);
&   IFDEF TRACE
    t01int4 (ak_sem, 'a_first_unio', ord (acv.a_first_union));
    t01int4 (ak_sem, 'upos        ', upos);
    t01int4 (ak_sem, 'a_next_upos ', acv.a_next_upos);
&   ENDIF
    acv.a_next_upos   := succ (upos);
    acv.a_union_cnt   := succ (acv.a_union_cnt);
    a501exec_with_change_rec (acv, dmli,
          acv.a_unionrec_ptr^.sunionrec.uselect_arr[ upos ].uparsid,
          change_rec, output_during_execution);
&   IFDEF TRACE
    t01int4(ak_sem, 'RES_CNT     ', res_cnt);
&   ENDIF
    IF  (acv.a_returncode = 0)     AND
        (acv.a_first_union     OR
        (acv.a_union_cnt <= 1) OR
        acv.a_send_messbuf           )
    THEN
        BEGIN
        s40g4int (acv.a_mblock.mb_qual^.mr_resnum, 2, res_cnt, _res);
        res_tree     := acv.a_mblock.mb_qual^.mr_restree;
        key_cnt_offs := key_cnt_offs + res_cnt;
        END;
&   IFDEF TRACE
    (*ENDIF*) 
    t01int4 (ak_sem, 'RES_CNT 5034', res_cnt);
    t01int4 (ak_sem, 'KEY_CNT_OFFS', key_cnt_offs);
    t01int4 (ak_sem, ' return_code', acv.a_returncode);
&   ENDIF
    END;
(*ENDIF*) 
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
.PA 
