.nf
 
 
    ========== licence begin  GPL
    Copyright (c) 1999-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) 1999-2004 SAP AG
SAP Database Technology
 
Release :      Date : 2000-08-29
*****************************************************
modname : VAK61
changed : 2000-08-29
module  : Select_List
 
Author  : ElkeZ
Created : 1985-02-21
*****************************************************
 
Purpose : Processing of the select-list, an ORDER BY- or
          FOR UPDATE-clause
 
Define  :
 
        PROCEDURE
              a61_check_val_params (
                    VAR acv  : tak_all_command_glob;
                    VAR dmli : tak_dml_info;
                    sel_node : integer;
                    par_node : integer);
 
        PROCEDURE
              a61_search_table (
                    VAR acv  : tak_all_command_glob;
                    VAR dmli : tak_dml_info);
 
        PROCEDURE
              a61_set_jump (
                    VAR mess_block : tgg00_MessBlock;
                    stentrynr : integer;
                    operator  : tgg00_StackEntryType);
 
        PROCEDURE
              a61_p_short_info (
                    VAR acv    : tak_all_command_glob;
                    VAR sparr  : tak_syspointerarr;
                    VAR colinf : tak00_columninfo;
                    i          : integer;
                    fix_bufpos : integer);
 
        PROCEDURE
              a61_rel_old_table (
                    VAR acv  : tak_all_command_glob;
                    VAR dmli : tak_dml_info;
                    i        : integer);
 
        PROCEDURE
              a61_is_orderfield (
                    VAR acv       : tak_all_command_glob;
                    VAR dmli      : tak_dml_info;
                    VAR colinf    : tak00_columninfo;
                    order_ptr     : tak00_ord_fields_ptr;
                    single_column : boolean;
                    e_convert_t   : tak_convert_type;
                    curr_n        : tsp00_Int2;
                    VAR col       : tsp00_KnlIdentifier);
 
        PROCEDURE
              a61_update_column (
                    VAR acv        : tak_all_command_glob;
                    VAR dmli       : tak_dml_info;
                    VAR minkeylen  : integer;
                    curr_n         : integer);
 
        PROCEDURE
              a61_put_last_func (VAR acv : tak_all_command_glob);
 
        PROCEDURE
              a61_is_group_field (
                    VAR acv       : tak_all_command_glob;
                    VAR dmli      : tak_dml_info;
                    VAR fieldname : tsp00_KnlIdentifier;
                    extcolno      : tsp00_Int2;
                    is_expression : boolean;
                    expression_n  : tsp00_Int2;
                    errorpos      : integer);
 
        PROCEDURE
              a61_p_long_info (
                    VAR acv    : tak_all_command_glob;
                    VAR dmli   : tak_dml_info;
                    VAR colinf : tak00_columninfo);
 
        PROCEDURE
              a61columnnames (
                    VAR acv     : tak_all_command_glob;
                    VAR sparr   : tak_syspointerarr;
                    VAR refname : tsp00_KnlIdentifier;
                    VAR colinf  : tak00_columninfo);
 
        PROCEDURE
              a61get_column_expression (
                    VAR acv    : tak_all_command_glob;
                    VAR dmli   : tak_dml_info;
                    VAR colinf : tak00_columninfo;
                    errpos     : integer);
 
        PROCEDURE
              a61_new_expr_no (
                    VAR colinf : tak00_columninfo;
                    VAR exprno : tsp00_Int2);
 
        PROCEDURE
              a61_var_col_stackentry (
                    VAR acv          : tak_all_command_glob;
                    VAR dmli         : tak_dml_info;
                    VAR colinf       : tak00_columninfo;
                    may_be_together  : boolean;
                    VAR put_together : boolean;
                    VAR output_len   : integer;
                    is_corr_column   : boolean;
                    convert_t        : tak_convert_type;
                    convert_type     : tsp00_DataType);
 
        PROCEDURE
              a61_format_change (
                    VAR acv     : tak_all_command_glob;
                    VAR dmli    : tak_dml_info;
                    stackpos    : integer;
                    cdatatyp    : tsp00_DataType;
                    VAR datalen : tsp00_Int2);
 
.CM *-END-* define --------------------------------------
***********************************************************
 
Use     :
 
        FROM
              Scanner : VAK01;
 
        VAR
              a01sysnullkey        : tgg00_SysInfoKey;
              a01defaultkey        : tgg00_SysInfoKey;
              a01_i_public         : tsp00_KnlIdentifier;
              a01_i_temp           : tsp00_KnlIdentifier;
              a01_il_b_identifier  : tsp00_KnlIdentifier;
              a01_i_expression     : tsp00_KnlIdentifier;
              a01_l_expression     : tsp00_Int2;
              a01_i_internal       : tsp00_KnlIdentifier;
              a01_i_rowno          : tsp00_KnlIdentifier;
 
        PROCEDURE
              a01_dt_put_datatype_node (
                    VAR acv    : tak_all_command_glob;
                    VAR curr_n : tsp00_Int2;
                    data_type  : tsp00_DataType;
                    datalen    : tsp00_Int2;
                    datafrac   : tsp00_Int2;
                    inoutlen   : integer);
 
      ------------------------------ 
 
        FROM
              AK_semantic_scanner_tools : VAK05;
 
        PROCEDURE
              a05identifier_get (
                    VAR acv     : tak_all_command_glob;
                    tree_index  : integer;
                    obj_len     : integer;
                    VAR moveobj : tsp00_KnlIdentifier);
 
      ------------------------------ 
 
        FROM
              AK_universal_semantic_tools : VAK06;
 
        PROCEDURE
              a06extcolno (
                    VAR baserec  : tak_baserecord;
                    extcolno     : integer;
                    VAR col_ptr  : tak00_colinfo_ptr);
 
        PROCEDURE
              a06get_username (
                    VAR acv        : tak_all_command_glob;
                    VAR tree_index : integer;
                    VAR username   : tsp00_KnlIdentifier);
 
        PROCEDURE
              a06inc_linkage (VAR linkage : tsp00_C2);
 
        PROCEDURE
              a06_systable_get (
                    VAR acv      : tak_all_command_glob;
                    dstate       : tak_directory_state;
                    VAR tableid  : tgg00_Surrogate;
                    VAR base_ptr : tak_sysbufferaddress;
                    all          : boolean;
                    VAR ok       : boolean);
 
      ------------------------------ 
 
        FROM
              AK_Identifier_Handling : VAK061;
 
        PROCEDURE
              a061app_columnname (
                    VAR acv               : tak_all_command_glob;
                    VAR base_rec          : tak_baserecord;
                    VAR column            : tsp00_KnlIdentifier;
                    VAR index             : integer);
 
        PROCEDURE
              a061colinfo_to_var (
                    VAR src : tak00_columninfo;
                    VAR dst : tak00_columninfo);
 
        PROCEDURE
              a061eval_colname_len (VAR src : tak00_columninfo);
 
        FUNCTION
              a061exist_columnname (
                    VAR base_rec : tak_baserecord;
                    VAR column  : tsp00_KnlIdentifier;
                    VAR colptr  : tak00_colinfo_ptr) : boolean;
 
        PROCEDURE
              a061copy_colinfo (
                    VAR src : tak00_columninfo;
                    VAR dst : tak00_columninfo);
 
        PROCEDURE
              a061get_colname (
                    VAR col_info : tak00_columninfo;
                    VAR colname  : tsp00_KnlIdentifier);
 
        FUNCTION
              a061identifier_len (VAR id : tsp00_KnlIdentifier) : integer;
 
        PROCEDURE
              a061sort (
                    VAR acv               : tak_all_command_glob;
                    VAR base_rec          : tak_baserecord;
                    last_used_expr_no     : integer;
                    VAR duplicate_column  : boolean;
                    VAR duplicate_colname : tsp00_KnlIdentifier);
&       ifdef trace
 
        PROCEDURE
              a061td_colinfo (
                    VAR colinfo : tak00_columninfo;
                    index : integer);
&       endif
 
      ------------------------------ 
 
        FROM
              AK_error_handling : VAK07;
 
        PROCEDURE
              a07_hex_uni_error (
                    VAR acv     : tak_all_command_glob;
                    uni_err     : tsp8_uni_error;
                    err_code    : tsp00_Int4;
                    to_unicode  : boolean;
                    bytestr     : tsp00_MoveObjPtr;
                    len         : tsp00_Int4 );
 
        PROCEDURE
              a07_b_put_error (
                    VAR acv : tak_all_command_glob;
                    b_err   : tgg00_BasisError;
                    err_code : tsp00_Int4);
 
        PROCEDURE
              a07_nb_put_error (
                    VAR acv  : tak_all_command_glob;
                    b_err    : tgg00_BasisError;
                    err_code : tsp00_Int4;
                    VAR n    : tsp00_KnlIdentifier);
 
        PROCEDURE
              a07_tb_put_error (
                    VAR acv    : tak_all_command_glob;
                    b_err      : tgg00_BasisError;
                    err_code   : tsp00_Int4;
                    VAR tab_id : tgg00_Surrogate);
 
        PROCEDURE
              a07put_error_pos (
                    VAR acv : tak_all_command_glob;
                    err_pos : tsp00_Int4);
 
        PROCEDURE
              a07ak_system_error (
                    VAR acv  : tak_all_command_glob;
                    modul_no : integer;
                    id       : integer);
 
      ------------------------------ 
 
        FROM
              Systeminfo_cache : VAK10;
 
        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
              a10new (
                    VAR acv  : tak_all_command_glob;
                    obj_size : tsp00_Int4;
                    VAR p    : tak_sysbufferaddress);
 
        PROCEDURE
              a10rel_sysinfo (syspointer : tak_sysbufferaddress);
 
      ------------------------------ 
 
        FROM
              AK_View_semantic : VAK16;
 
        PROCEDURE
              a16col_to_view_description (
                    VAR acv      : tak_all_command_glob;
                    VAR dmli     : tak_dml_info;
                    VAR col_info : tak00_columninfo;
                    use_extcolno : boolean);
 
      ------------------------------ 
 
        FROM
              DML_Help_Procedures : VAK54;
 
        PROCEDURE
              a54_internal_function (
                    VAR acv : tak_all_command_glob;
                    VAR m : tgg00_MessBlock;
                    st_no : integer);
 
        FUNCTION
              a54_optim_select_fetch (VAR acv : tak_all_command_glob) : boolean;
 
        PROCEDURE
              a54_fixedpos (
                    VAR acv  : tak_all_command_glob;
                    VAR dmli : tak_dml_info);
 
        PROCEDURE
              a54datetime_parsinfo (
                    VAR acv  : tak_all_command_glob;
                    VAR dmli : tak_dml_info;
                    stackpos : integer);
 
      ------------------------------ 
 
        FROM
              Execute_factor_col_function: VAK641;
 
        PROCEDURE
              a641add_mapchar (
                    VAR acv            : tak_all_command_glob;
                    VAR dmli           : tak_dml_info;
                    VAR colin          : tak00_scolinf;
                    VAR setname        : tsp00_KnlIdentifier;
                    curr_n             : integer;
                    first_int          : integer);
 
        PROCEDURE
              a641get_mapcharset (
                    VAR acv            : tak_all_command_glob;
                    VAR mapcharsetname : tsp00_KnlIdentifier;
                    error_pos          : integer;
                    VAR max_maplen     : integer;
                    VAR sysbuf         : tak_sysbufferaddress);
 
        PROCEDURE
              a641string_set_operator (
                    VAR acv      : tak_all_command_glob;
                    operator     : tgg00_StackOpBuildIn;
                    destlength   : integer;
                    sourcelength : integer;
                    tab1         : char;
                    tab2         : char);
 
        PROCEDURE
              a641l_push_language (
                    VAR acv  : tak_all_command_glob;
                    VAR dmli : tak_dml_info);
 
        PROCEDURE
              a641f_push_format (
                    VAR acv  : tak_all_command_glob;
                    VAR dmli : tak_dml_info);
 
      ------------------------------ 
 
        FROM
              Execute_Where_Part : VAK65;
 
        PROCEDURE
              a65ch_format (
                    VAR acv        : tak_all_command_glob;
                    VAR dmli       : tak_dml_info;
                    VAR startstack : integer;
                    VAR colin      : tak00_scolinf;
                    left_type      : tsp00_DataType;
                    d_type         : tsp00_DataType);
 
        PROCEDURE
              a65_val_expr (
                    VAR acv    : tak_all_command_glob;
                    VAR dmli   : tak_dml_info;
                    VAR colin  : tak00_scolinf;
                    first_node : integer);
 
        PROCEDURE
              a65_look_for_datatypes (
                    VAR acv    : tak_all_command_glob;
                    VAR dmli   : tak_dml_info;
                    first_node : integer);
 
        FUNCTION
              a65_datatypes_ok (
                    VAR acv        : tak_all_command_glob;
                    VAR dmli       : tak_dml_info;
                    VAR dm_type    : tsp00_DataType;
                    VAR dm_iolen   : tsp00_Int2;
                    ctype          : tsp00_DataType;
                    is_subquery    : boolean;
                    first_node     : integer;
                    error_pos      : tsp00_Int4;
                    convert        : boolean;
                    VAR convert_t  : tak_convert_type) : boolean;
 
        PROCEDURE
              a65_convert (
                    VAR acv   : tak_all_command_glob;
                    operator  : tak_convert_type;
                    maxlength : integer);
 
        PROCEDURE
              a65subq_get_val (
                    VAR acv    : tak_all_command_glob;
                    first_node : integer;
                    iolen      : integer);
 
      ------------------------------ 
 
        FROM
              Execute_Select_Expression : VAK660;
 
        FUNCTION
              a660pos_pred (
                    VAR acv  : tak_all_command_glob;
                    pos_node : integer) : integer;
 
      ------------------------------ 
 
        FROM
              Subquery_handling : VAK661;
 
        PROCEDURE
              a661_get_from_select_table (
                    VAR acv     : tak_all_command_glob;
                    VAR tableid : tgg00_Surrogate;
                    VAR pbasep  : tak_sysbufferaddress;
                    dstate      : tak_directory_state;
                    all         : boolean;
                    VAR f_ok    : boolean);
 
        FUNCTION
              a661_is_fromsel_table (
                    VAR acv     : tak_all_command_glob;
                    VAR ftreeid : tgg00_FileId) : boolean;
 
      ------------------------------ 
 
        FROM
              Resultname_handling : VAK663;
 
        PROCEDURE
              a663get_result_records (
                    VAR acv    : tak_all_command_glob;
                    dstate     : tak_directory_state;
                    VAR resid  : tsp00_Int4;
                    VAR pbasep : tak_sysbufferaddress;
                    VAR ok     : boolean);
 
        PROCEDURE
              a663restable_get (
                    VAR acv    : tak_all_command_glob;
                    dstate     : tak_directory_state;
                    VAR tablen : tsp00_KnlIdentifier;
                    VAR sparr  : tak_syspointerarr;
                    VAR ok     : boolean);
 
      ------------------------------ 
 
        FROM
              Configuration_Parameter : VGG01;
 
        VAR
              g01code           : tgg04_CodeGlobals;
              g01unicode        : boolean;
              g01glob           : tgg00_KernelGlobals;
 
      ------------------------------ 
 
        FROM
              Kernel_move_and_fill : VGG101;
 
        PROCEDURE
              SAPDB_PascalMove   (
                    mod_id         : tsp00_C6;
                    mod_intern_num : tsp00_Int4;
                    size1          : tsp00_Int4;
                    size2          : tsp00_Int4;
                    val1           : tsp00_MoveObjPtr;
                    p1             : tsp00_Int4;
                    val2           : tsp00_MoveObjPtr;
                    p2             : tsp00_Int4;
                    cnt            : tsp00_Int4;
                    VAR e          : tgg00_BasisError);
 
        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);
&       ifdef MAXCOLS
 
      ------------------------------ 
 
        FROM
              GG_edit_routines : VGG17;
 
        PROCEDURE
              g17int4to_line (
                    int       : tsp00_Int4;
                    with_zero : boolean;
                    int_len   : integer;
                    ln_pos    : integer;
                    VAR ln    : tsp00_KnlIdentifier);
&       endif
 
      ------------------------------ 
 
        FROM
              RTE-Extension-30 : VSP30;
 
        FUNCTION
              s30unilnr (
                    str       : tsp00_MoveObjPtr;
                    skip_val  : tsp00_C2;
                    start_pos : tsp00_Int4;
                    length    : tsp00_Int4) : tsp00_Int4;
 
        PROCEDURE
              s30cmp (
                    VAR buf1     : tsp00_MoveObj;
                    fieldpos1    : tsp00_Int4;
                    fieldlength1 : tsp00_Int4;
                    VAR buf2     : tsp00_MoveObj;
                    fieldpos2    : tsp00_Int4;
                    fieldlength2 : tsp00_Int4;
                    VAR l_result : tsp00_LcompResult);
 
        PROCEDURE
              s30cmp1 (
                    VAR buf1     : tsp00_MoveObj;
                    fieldpos1    : tsp00_Int4;
                    fieldlength1 : tsp00_Int4;
                    VAR buf2     : tsp00_LongDescriptor;
                    fieldpos2    : tsp00_Int4;
                    fieldlength2 : tsp00_Int4;
                    VAR l_result : tsp00_LcompResult);
 
        PROCEDURE
              s30cmp2 (
                    VAR buf1     : tsp00_KnlIdentifier;
                    fieldpos1    : tsp00_Int4;
                    fieldlength1 : tsp00_Int4;
                    VAR buf2     : tsp00_KnlIdentifier;
                    fieldpos2    : tsp00_Int4;
                    fieldlength2 : tsp00_Int4;
                    VAR l_result : tsp00_LcompResult);
 
        FUNCTION
              s30eq (
                    VAR a, b: tsp00_KnlIdentifier;
                    bi, cnt : tsp00_Int4): boolean;
 
        FUNCTION
              s30klen (
                    VAR str : tsp00_KnlIdentifier;
                    val : char;
                    cnt : integer) : integer;
 
      ------------------------------ 
 
        FROM
              RTE-Extension-80 : VSP80;
 
        PROCEDURE
              s80uni_trans (
                    src_ptr         : tsp00_MoveObjPtr;
                    src_len         : tsp00_Int4;
                    src_codeset     : tsp00_Int2;
                    dest_ptr        : tsp00_MoveObjPtr;
                    VAR dest_len    : tsp00_Int4;
                    dest_codeset    : tsp00_Int2;
                    trans_options   : tsp8_uni_opt_set;
                    VAR rc          : tsp8_uni_error;
                    VAR err_char_no : tsp00_Int4);
&       IFDEF TRACE
 
      ------------------------------ 
 
        FROM
              Test_Procedures : VTA01;
 
        PROCEDURE
              t01moveobj (
                    debug       : tgg00_Debug;
                    VAR moveobj : tsp00_MoveObj;
                    startpos    : tsp00_Int4;
                    endpos      : tsp00_Int4);
 
        PROCEDURE
              t01bool (
                    debug    : tgg00_Debug;
                    nam      : tsp00_Sname;
                    curr_bool: boolean);
 
        PROCEDURE
              t01buf (
                    debug   : tgg00_Debug;
                    VAR buf : tak_systembuffer;
                    pos     : integer;
                    endpos  : integer);
 
        PROCEDURE
              t01buf1 (
                    debug   : tgg00_Debug;
                    VAR buf : tsp00_KnlIdentifier;
                    pos     : integer;
                    endpos  : integer);
 
        PROCEDURE
              t01stackentry (
                    debug          : tgg00_Debug;
                    VAR st         : tgg00_StackEntry;
                    entry_index    : integer);
 
        PROCEDURE
              t01surrogate (
                    debug     : tgg00_Debug;
                    nam       : tsp00_Sname;
                    VAR tabid : tgg00_Surrogate);
 
        PROCEDURE
              t01name (
                    level : tgg00_Debug;
                    nam : tsp00_Name);
 
        PROCEDURE
              t01lidentifier (
                    level      : tgg00_Debug;
                    identifier : tsp00_KnlIdentifier);
 
        PROCEDURE
              t01int4 (
                    debug    : tgg00_Debug;
                    nam      : tsp00_Sname;
                    int      : tsp00_Int4);
 
        PROCEDURE
              t01messblock (
                    debug         : tgg00_Debug;
                    nam           : tsp00_Sname;
                    VAR m         : tgg00_MessBlock);
 
        PROCEDURE
              t01aptree (
                    layer         : tgg00_Debug;
                    VAR a_ap_tree : tak_ap_max_tree;
                    node_cnt      : integer;
                    hint_node     : tsp00_Int2);
&       ENDIF
 
.CM *-END-* use -----------------------------------------
***********************************************************
 
Synonym :
 
        PROCEDURE
              a05identifier_get;
 
              tsp00_MoveObj tsp00_KnlIdentifier
 
        PROCEDURE
              s30cmp1;
 
              tsp00_MoveObj tsp00_LongDescriptor
 
        PROCEDURE
              s30cmp2;
 
              tsp00_MoveObj tsp00_KnlIdentifier
              tsp00_MoveObj tsp00_KnlIdentifier
 
        FUNCTION
              s30eq;
 
              tsp00_MoveObj tsp00_KnlIdentifier
 
        FUNCTION
              s30klen;
 
              tsp00_MoveObj tsp00_KnlIdentifier
 
        PROCEDURE
              t01buf;
 
              tsp00_Buf tak_systembuffer
 
        PROCEDURE
              t01buf1;
 
              tsp00_Buf tsp00_KnlIdentifier
 
        PROCEDURE
              t01aptree;
 
              tsp00_MoveObj tak_ap_max_tree
 
.CM *-END-* synonym -------------------------------------
***********************************************************
.CM -lll-
Code    :
 
 
CONST
      c_all             = true (* a06_systable_get   *);
      (*                          a661_get_from_select_table *)
      c_use_extcolno    = true (* a16col_to_view_description *);
      c_subquery_get    = true (* ak61sel_val_expr   *);
      c_join            = true (* ak61_comp_part_tree *);
      c_is_expression   = true (* a61_is_group_field *);
      c_single_column   = true (* a61_is_orderfield  *);
      c_is_corr_column  = true (* a61_var_col_stackentry *);
      c_convert         = true (* a65_datatypes_ok   *);
      c_is_subquery     = true (* a65_datatypes_ok   *);
      (*                                             *)
      c_trans_to_uni    = true (* a07_hex_uni_error  *);
      c_unicode_wid     = 2    (* a07_hex_uni_error  *);
 
TYPE
      ak61_group = ARRAY [ 0.. cak00_maxordercolumns ] OF boolean;
 
 
(*------------------------------*) 
 
PROCEDURE
      ak61all_columns (
            VAR acv       : tak_all_command_glob;
            VAR dmli      : tak_dml_info;
            VAR col_index : integer);
 
VAR
      is_output_column     : boolean;
      long_column_found    : boolean;
      newlong_column_found : boolean;
      extdatetime          : boolean;
      is_corr_subq         : boolean;
      is_io                : boolean;
      oflw_op              : tgg00_StackOpOutput;
      put_together         : boolean;
      together_allowed     : boolean;
      cntpar               : integer;
      dummy_len            : integer;
      fieldno              : integer;
      output_index         : integer;
      new_col_ptr          : tak00_colinfo_ptr;
      st_index             : integer;
      colname              : tsp00_KnlIdentifier;
      colinf               : tak00_columninfo;
      convert_t            : tak_convert_type;
 
BEGIN
WITH dmli, acv, a_mblock, mb_qual^ DO
    BEGIN
&   IFDEF TRACE
    t01int4 (ak_sem, 'init_ex_kind', ord (a_init_ex_kind));
&   ENDIF
    fieldno              := 1;
    output_index         := 0;
    st_index             := mfirst_free;
    a_long_desc_pos      := 0;
    is_corr_subq         := d_subquery AND (d_corr <> no_correlation);
    WHILE ((fieldno <= d_sparr.pbasep^.sbase.bmaxcol)
          AND (a_returncode = 0)) DO
        BEGIN
        convert_t := conv_none;
        extdatetime := false;
&       IFDEF TRACE
        t01int4 (ak_sem, 'output_pos  ', a_output_data_pos);
        t01int4 (ak_sem, 'fieldno     ', fieldno);
        t01int4 (ak_sem, 'd_cntpar    ', d_cntpar);
        t01int4 (ak_sem, 'a_outer_join', ord(a_outer_join));
        t01int4 (ak_sem, 'd_outer_join', ord(d_outer_join));
        t01int4 (ak_sem, 'a_internalsq', ord(a_internal_sql));
&       ENDIF
        WITH d_sparr.pbasep^.sbase DO
            BEGIN
            a06extcolno (d_sparr.pbasep^.sbase,
                  fieldno, d_colbuf);
            oflw_op    := op_o_none;
            (* PTS 1111576 E.Z. *)
            IF  btablekind in [ tonebase, tview, tresult, tcomplexview  ]
            THEN
                IF  acv.a_ap_tree^[ acv.a_ap_tree^[ 0 ].n_lo_level ].
                    n_proc in [ a62, a63, a16 ]
                THEN
                    oflw_op := op_o_output_oflw;
                (*ENDIF*) 
            (*ENDIF*) 
            END;
        (*ENDWITH*) 
        a061colinfo_to_var (d_colbuf^, colinf);
        WITH colinf DO
            BEGIN
            (* PTS 1106508 E.Z. *)
            long_column_found :=
                  (cdatatyp in [ dstra, dstrb, dstruni ]);
            newlong_column_found :=
                  (cdatatyp in [ dlonga, dlongb, dlonguni ]);
            is_output_column := NOT (ctdropped in ccolpropset)
                  AND
                  NOT (ctinvisible in ccolpropset)
                  AND (* PTS 1105795 M.Ki. *)
                  (* PTS 112080 E.Z. *)
                  (
                  NOT (
                  (d_sparr.pbasep^.sbase.btablekind = tonebase)         AND
                  (d_sparr.pbasep^.sbase.bv_tablekind = tcatalog_table) AND
                  (cdatatyp in [ dlonga, dlongb, dlongdb,
                  dlonguni, dstruni, dstra, dstrb, dstrdb ])     AND
                  (a_insert_select OR (a_init_ddl = ddl_create_as_select))  )
                  )
                  AND
                  (((ccolpropset <> [ ctkey, ctopt ]) (* column isn't SYSKEY *)
                  AND
                  (ccolpropset <> [ ctkey, ctopt, ctmulti ]))
                  (* PTS 1111576 E.Z. *)
                  );
            cntpar := d_cntpar;
            IF  cntpar <= 0
            THEN
                BEGIN
                IF  is_output_column
                THEN
                    IF  (d_subquery OR NOT d_single) AND
                        (NOT a_from_select)
                    THEN
                        a07_b_put_error (acv,
                              e_select_col_list_too_long, d_vppos)
                    ELSE
                        WITH a_transinf.tri_trans DO
                            trWarning_gg00 := trWarning_gg00 + [ warn0_exist,
                                  warn3_output_not_into_columns ];
                        (*ENDWITH*) 
                    (*ENDIF*) 
                (*ENDIF*) 
                END
            ELSE
                ak61iolen_get (acv, dmli, extdatetime, is_io,
                      cdatatyp, cdatalen, cinoutlen);
            (*ENDIF*) 
            IF   is_output_column AND (cntpar > 0)
            THEN
                BEGIN
                a061get_colname (colinf, d_column);
                ak61col_long_shortinfo (acv, dmli, colinf);
                IF  ((a_returncode = 0) AND NOT d_single)
                THEN
                    BEGIN
                    a16col_to_view_description (acv, dmli,
                          colinf, c_use_extcolno);
                    ak61build_colinfo (acv, dmli, colinf,
                          new_col_ptr, convert_t, col_index);
                    END;
                (*ENDIF*) 
                END;
&           IFDEF TRACE
            (*ENDIF*) 
            t01int4  (ak_sem, 'cntpar@@@@@@', cntpar);
            t01int4  (ak_sem, 'is_output_co', ord (is_output_column));
            t01int4  (ak_sem, 'long_column_', ord (long_column_found));
            t01int4  (ak_sem, 'newlong_col ', ord (newlong_column_found));
            t01int4  (ak_sem, 'cdatatyp    ', ord (cdatatyp));
            t01messblock (ak_sem, 'all_columns1', a_mblock);
&           ENDIF
            IF  (a_returncode = 0) AND
                (long_column_found OR newlong_column_found) AND
                (d_distinct <> no_distinct)
            THEN
                a07_nb_put_error (acv,
                      e_command_for_string_not_allow,
                      d_vppos, d_column);
            (*ENDIF*) 
            IF  (a_returncode = 0) AND
                (cntpar > 0)      AND
                is_output_column
            THEN
                BEGIN
                (* PTS 1000985/1001162 E.Z. *)
                together_allowed := false;
                IF  ((ccolstack.etype = st_fixkey) OR
                    ( ccolstack.etype = st_fixcol))
                THEN (* output column of fixed length *)
                    BEGIN
                    (* PTS 1107681 E.Z. *)
                    st_index := mfirst_free;
                    a61_var_col_stackentry (acv, dmli, colinf,
                          together_allowed, put_together,
                          dummy_len, NOT c_is_corr_column, convert_t, dunknown);
                    (* END OF PTS 1000985/1001162 E.Z. *)
                    (* PTS 1106343 E.Z. *)
                    (* always true, may be the next column *)
                    (* will be appended                    *)
                    put_together := true;
&                   ifdef TRACE
                    t01int4 (ak_sem, 'd_inoutpos 1', d_inoutpos);
                    t01int4 (ak_sem, 'cdatalen    ', cdatalen);
&                   endif
                    END
                ELSE (* etype = st_varkey, st_varcol, st_longvarchar *)
                    (* or first column of (later) concatenated ones *)
                    BEGIN
                    (* PTS 1111575 E.Z. *)
                    (* PTS 1106343 E.Z. *)
                    a61_var_col_stackentry (acv, dmli, colinf,
                          together_allowed, put_together,
                          dummy_len, NOT c_is_corr_column,
                          (* PTS 1000985/1001162 E.Z. *)
                          convert_t, dunknown);
                    END;
                (*ENDIF*) 
&               ifdef TRACE
                t01messblock (ak_sem, 'all_columns2', a_mblock);
&               endif
                IF  (a_returncode = 0) AND
                    (cntpar > 0)      AND
                    is_output_column
                THEN
                    BEGIN
                    IF  (a_returncode = 0) AND
                        d_use_order                          AND
                        NOT is_corr_subq
                    THEN
                        a61_is_orderfield (acv, dmli, colinf, @d_order_cols,
                              NOT put_together, convert_t, 0, d_column);
                    (*ENDIF*) 
                    IF  ((a_returncode = 0) AND d_group)
                    THEN
                        BEGIN
                        a061get_colname (d_colbuf^, colname);
                        a61_is_group_field (acv, dmli, colname,
                              d_colbuf^.cextcolno,
                              NOT c_is_expression, 0, d_vppos)
                        END;
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
                IF  d_use_order AND is_corr_subq
                THEN
                    a61_is_orderfield (acv, dmli, colinf, @d_order_cols,
                          c_single_column, convert_t, 0, d_column);
&               ifdef TRACE
                (*ENDIF*) 
                t01messblock (ak_sem, 'all_columns3', a_mblock);
&               endif
                END;
            (*ENDIF*) 
            IF  is_output_column
            THEN
                col_index := succ (col_index);
            (*ENDIF*) 
            IF  extdatetime OR NOT (is_output_column)
            THEN (* restrict concatenation with next column *)
                colinf.ccolstack.etype := st_varcol;
            (*ENDIF*) 
            END;
        (*ENDWITH*) 
        fieldno := succ(fieldno);
        END;
    (*ENDWHILE*) 
    END
(*ENDWITH*) 
END;
 
(* PTS 1111576 E.Z. *)
(*------------------------------*) 
 
PROCEDURE
      ak61build_colinfo (
            VAR acv        : tak_all_command_glob;
            VAR dmli       : tak_dml_info;
            VAR colinf     : tak00_columninfo;
            VAR col_ptr    : tak00_colinfo_ptr;
            VAR convert_t  : tak_convert_type;
            col_index      : integer);
 
VAR
      col        : tsp00_KnlIdentifier;
      index      : integer;
      colno      : integer;
      dtype_n    : integer;
      types_ok   : boolean;
      level_node : tsp00_Int2;
 
BEGIN
WITH acv, dmli DO
    BEGIN
&   ifdef TRACE
    t01int4 (ak_sem, 'd_subquery  ', ord(d_subquery));
    t01int4 (ak_sem, 'd_use_sub   ', ord(d_use_sub ));
    t01int4 (ak_sem, 'a_union_cnt ', a_union_cnt);
    t01int4 (ak_sem, 'command_kind', ord(a_command_kind));
    t01int4 (ak_sem, 'act_node    ', d_act_node);
&   endif
    col_ptr := NIL;
    IF  (NOT d_subquery) OR
        d_first_union    OR
        a_from_select
    THEN
        BEGIN
        IF  (a_intern_select_cnt = a_max_intern_select) OR
            (a_union_cnt         > 0)                   OR
            (a_fromsel_n         > 0)                   OR
            (a_recursive_state = rs_first_select)
        THEN
            BEGIN
&           ifdef trace
            t01int4 (ak_sem, 'd_union     ', ord (d_union));
            t01int4 (ak_sem, 'd_first_unio', ord (d_first_union));
            t01int4 (ak_sem, 'a_union_cnt ', a_union_cnt);
&           endif
            IF  (d_view                   OR
                (a_recursive_state = rs_check_select_list)) AND
                d_view_col_list                             AND
                NOT d_subquery
            THEN
                IF  d_view_col_node > 0
                THEN
                    BEGIN
                    a05identifier_get (acv,
                          d_view_col_node, sizeof (col), col);
                    d_view_col_node := a_ap_tree^[d_view_col_node].n_sa_level
                    END
                ELSE
                    a07_b_put_error (acv, e_select_col_list_too_long, d_vppos)
                (*ENDIF*) 
            ELSE
                IF  NOT d_view_col_list AND (d_refname <> a01_il_b_identifier)
                THEN
                    col := d_refname
                ELSE (* no expression *)
                    col := colinf.ccolumnn;
                (*ENDIF*) 
            (*ENDIF*) 
            IF  a_returncode = 0 (* purify *)
            THEN
                IF  d_esparr.pbasep^.sbase.bmaxcol >= MAX_COL_PER_TAB_GG00
                THEN
                    a07_b_put_error (acv, e_select_col_list_too_long, 1)
                ELSE
                    a061app_columnname (acv, d_esparr.pbasep^.sbase,
                          col, index);
                (*ENDIF*) 
            (*ENDIF*) 
            IF  a_returncode = 0
            THEN
                BEGIN
                col_ptr := d_esparr.pbasep^.sbase.bcolumn[index];
                WITH col_ptr^, ccolstack DO
                    BEGIN
                    IF  d_refname <> a01_il_b_identifier
                    THEN
                        ccolpropset := ccolpropset +
                              [ ctviewname ];
                    (*ENDIF*) 
                    IF  (d_view) AND (d_phase_cnt < 4)
                    THEN
                        BEGIN
                        a061copy_colinfo (colinf, col_ptr^);
                        cextcolno := d_esparr.pbasep^.sbase.bmaxcol;
                        ctabno   := ctabno +
                              d_tabarr[ d_acttabindex ].ocounttabs;
                        ecol_tab[ 2 ] := chr(ctabno);
                        END
                    ELSE
                        BEGIN
                        IF  ctopt in colinf.ccolpropset
                        THEN
                            ccolpropset := [ ctopt ]
                        ELSE
                            ccolpropset := [  ];
                        (*ENDIF*) 
                        etype         := st_fixcol;
                        eop           := op_none;
                        ecol_tab[ 1 ] := chr(0);
                        cextcolno     := d_outcolno;
                        creccolno     := cextcolno;
                        ctabno        := 1;
                        cdatatyp      := colinf.cdatatyp;
                        cdatalen      := colinf.cdatalen;
                        cdatafrac     := colinf.cdatafrac;
                        cinoutlen     := colinf.cinoutlen;
                        cshiftoutchar := colinf.cshiftoutchar;
                        epos          := d_inoutpos - cgg_rec_key_offset - d_keylen;
                        elen_var      := cinoutlen;
                        ecol_tab[ 2 ] := chr(ctabno);
                        (* PTS 1116837 E.Z. *)
                        cnextind     := 0;
                        cudtdatatype := cak_edummy;
                        cfiller02    := chr(0);
                        END
                    (*ENDIF*) 
                    END
                (*ENDWITH*) 
                END
            (*ENDIF*) 
            END
        (*ENDIF*) 
        END
    ELSE
        IF  a_union_cnt <= 1
        THEN
            IF  (d_use_sub OR (a_command_kind = union_in_sub_command))
            THEN
                BEGIN
                (* PTS 1000985/1001162 E.Z. *)
                (* look if there is a corresponding datatype_node *)
                (* if, then check, else insert one *)
                colno := 1;
                dtype_n := d_act_node;
&               ifdef TRACE
                t01int4 (ak_sem, 'd_outcolno  ', d_outcolno);
                t01int4 (ak_sem, 'colno       ', colno);
                t01int4 (ak_sem, 'dtype_n     ', dtype_n);
&               endif
                WHILE (colno < d_outcolno) AND
                      (a_ap_tree^[ dtype_n ].n_sa_level <> 0) DO
                    BEGIN
                    colno := succ(colno);
                    dtype_n := a_ap_tree^[ dtype_n ].n_sa_level;
&                   ifdef TRACE
                    t01int4 (ak_sem, 'colno       ', colno);
                    t01int4 (ak_sem, 'dtype_n     ', dtype_n);
&                   endif
                    END;
                (*ENDWHILE*) 
                IF  (colno = d_outcolno) AND
                    (dtype_n <> 0)
                THEN
                    BEGIN
                    types_ok := a65_datatypes_ok (acv, dmli,
                          a_ap_tree^[ dtype_n ].n_datatype,
                          a_ap_tree^[ dtype_n ].n_length,
                          colinf.cdatatyp, c_is_subquery,
                          d_act_node, a_ap_tree^[ d_act_node ].n_pos,
                          NOT c_convert, convert_t);
                    END
                ELSE
                    BEGIN
                    WITH colinf DO
                        (* Create a node with datatype and length... *)
                        a01_dt_put_datatype_node (acv,
                              level_node, cdatatyp, cdatalen, cdatafrac, cinoutlen);
                    (*ENDWITH*) 
                    a_ap_tree^[ dtype_n ].n_sa_level := level_node
                    END
                (*ENDIF*) 
                END
            ELSE
                BEGIN (* try to go to 'col_index'th node; be aware that *)
                (*       there can be only one dtype node (e.g. exists) *)
                dtype_n  := a_ap_tree^[ d_act_node ].n_sa_level;
&               ifdef TRACE
                t01int4 (ak_sem, 'col_index   ', col_index);
                t01int4 (ak_sem, 'dtype_n     ', dtype_n);
&               endif
                index := col_index;
                WHILE (index > 1) AND
                      (a_ap_tree^[ dtype_n ].n_sa_level <> 0) DO
                    BEGIN
                    index   := pred (index);
                    dtype_n := a_ap_tree^[ dtype_n ].n_sa_level
                    END;
                (*ENDWHILE*) 
&               ifdef TRACE
                t01int4 (ak_sem, 'col_index   ', index);
                t01int4 (ak_sem, 'dtype_n     ', dtype_n);
&               endif
                (* PTS 1000985/1001162 E.Z. *)
                types_ok := a65_datatypes_ok (acv, dmli,
                      a_ap_tree^[ dtype_n ].n_datatype,
                      a_ap_tree^[ dtype_n ].n_length,
                      colinf.cdatatyp, c_is_subquery,
                      d_act_node, a_ap_tree^[ d_act_node ].n_pos,
                      NOT c_convert, convert_t);
                IF  convert_t = conv_ascii_to_unicode
                THEN
                    WITH colinf DO
                        BEGIN
                        cdatatyp := dunicode;
                        cinoutlen := (2*cdatalen) + 1
                        END
                    (*ENDWITH*) 
                (*ENDIF*) 
                END
            (*ENDIF*) 
        (*ENDIF*) 
    (*ENDIF*) 
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
FUNCTION
      ak61exist_columnname (
            VAR base_rec    : tak_baserecord;
            VAR column      : tsp00_KnlIdentifier;
            VAR colinfo_ptr : tak00_colinfo_ptr) : boolean;
 
VAR
      found        : boolean;
      res          : tsp00_LcompResult;
      i            : integer;
      colname_len  : integer;
      col_ptr      : tak00_colinfo_ptr;
 
BEGIN
&ifdef trace
t01lidentifier (ak_sem, column);
t01int4 (ak_sem, 'firstindex  ', base_rec.bfirstindex);
t01int4 (ak_sem, ' lastindex  ', base_rec.blastindex);
&endif
colname_len := a061identifier_len (column);
found       := false;
colinfo_ptr := NIL;
i := base_rec.bfirstindex;
WHILE NOT found AND (i <= base_rec.blastindex) DO
    BEGIN
    col_ptr := base_rec.bcolumn[i];
&   IFDEF TRACE
    a061td_colinfo (col_ptr^, i);
&   endif
    s30cmp2 (col_ptr^.ccolumnn, 1, ord (col_ptr^.ccolumnn_len),
          column, 1, colname_len, res);
    IF  res = l_equal
    THEN
        found := true
    ELSE
        i := succ(i)
    (*ENDIF*) 
    END;
(*ENDWHILE*) 
&IFDEF TRACE
IF  found
THEN
    a061td_colinfo (col_ptr^, i);
&endif
(*ENDIF*) 
colinfo_ptr := col_ptr;
ak61exist_columnname := found
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61iolen_get (
            VAR acv         : tak_all_command_glob;
            VAR dmli        : tak_dml_info;
            VAR extdatetime : boolean;
            VAR is_io       : boolean;
            d_typ           : tsp00_DataType;
            VAR d_len       : tsp00_Int2;
            VAR d_iolen     : tsp00_Int2);
 
BEGIN
extdatetime := false;
is_io       := false;
WITH acv, dmli DO
    IF  (
        ((a_ap_tree^[ a_ap_tree^[ 0 ].n_lo_level ].n_proc in [ a63, a62 ]) OR
        (( a_ap_tree^[ a_ap_tree^[ 0 ].n_lo_level ].n_proc    = a43) AND
        (  a_ap_tree^[ a_ap_tree^[ 0 ].n_lo_level ].n_subproc = cak_x_explain)))
        AND
        NOT d_subquery
        AND
        (NOT a_from_select OR
        ( d_typ in  [ dstra, dstrb, dstruni, dlonga, dlongb, dlonguni ]))
        AND
        NOT (a_is_ddl = ddl_create_as_select)
        (* PTS 1106654 E.Z. *)
        AND
        ((a_intern_select_cnt = a_max_intern_select) OR
        ( d_typ in  [ dstra, dstrb, dstruni,
        dlonga, dlongb, dlonguni ]))
        )
        OR
        d_first_union
    THEN
        BEGIN
        is_io := true;
        CASE d_typ OF
            ddate, dtimestamp :
                BEGIN
                (* PTS 1111575 E.Z. *)
                extdatetime := true;
                IF  d_typ = ddate
                THEN
                    BEGIN
                    IF  d_len < mxsp_extdate
                    THEN
                        d_len := mxsp_extdate
                    (*ENDIF*) 
                    END
                ELSE
                    BEGIN
                    IF  d_len < mxsp_exttimestamp
                    THEN
                        d_len := mxsp_exttimestamp;
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
                IF  (a_out_packet^.sp1_header.sp1h_mess_code in
                    [ csp_unicode_swap, csp_unicode ])
                    (* PTS 1113800 E.Z. *)
                    AND
                    NOT d_view
                    AND
                    NOT d_subquery
                    AND
                    (a_intern_select_cnt = a_max_intern_select)
                THEN
                    d_iolen := succ(2*d_len)
                ELSE
                    d_iolen := d_len + 1
                (*ENDIF*) 
                END;
            dtime :
                BEGIN
                IF  (a_out_packet^.sp1_header.sp1h_mess_code in
                    [ csp_unicode_swap, csp_unicode ])
                    (* PTS 1113800 E.Z. *)
                    AND
                    NOT d_view
                    AND
                    NOT d_subquery
                    AND
                    (a_intern_select_cnt = a_max_intern_select)
                THEN
                    d_iolen := succ(2*d_len);
                (* PTS 1111575 E.Z. *)
                (*ENDIF*) 
                END;
            dunicode :
                BEGIN
                (* even with a_max_codewidth > 2 *)
                (* the inoutlen has to be odd    *)
                (* to allow g20unifill for the   *)
                (* output before uni_transing it *)
                IF  a_max_codewidth > 2
                THEN
                    d_iolen := ((((((d_iolen-1) DIV 2) *
                          a_max_codewidth)+1) DIV 2) * 2) + 1;
                (* PTS 1111575 E.Z. *)
                (*ENDIF*) 
                END;
            dcha, dvarchara :
                IF  (a_out_packet^.sp1_header.sp1h_mess_code in
                    [ csp_unicode_swap, csp_unicode ])
                    (* PTS 1113800 E.Z. *)
                    AND
                    NOT d_view
                    AND
                    NOT d_subquery
                    AND
                    (a_intern_select_cnt = a_max_intern_select)
                    AND
                    (a_qualified_jv_upd = no_jv_upd)
                THEN
                    d_iolen := succ(2*d_len);
                (*ENDIF*) 
            OTHERWISE
                IF  (NOT d_view) OR (d_phase_cnt >= 4)
                THEN
                    BEGIN
                    IF  (d_typ in [ dstra, dstrb, dstruni,
                        dlonga, dlongb, dlonguni ])
                    THEN
                        BEGIN
                        (* PTS 1116801 E.Z. *)
                        d_len := mxsp_long_desc;
                        d_iolen   := d_len + 1;
                        (* PTS 1111575 E.Z. *)
                        IF  a_return_segm^.sp1r_function_code = csp1_mselect_into_fc
                        THEN
                            BEGIN
                            a_return_segm^.sp1r_function_code := csp1_select_into_fc;
                            a_precomp_info_byte := csp1_p_none
                            END;
                        (*ENDIF*) 
                        END
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
            END;
        (*ENDCASE*) 
        END
    ELSE (* PTS 1105795 M.Ki. *)
        IF  ((a_ap_tree^[ a_ap_tree^[ 0 ].n_lo_level ].n_proc = a56)
            AND
            NOT (d_subquery OR a_from_select)
            AND
            NOT (a_is_ddl = ddl_create_as_select)
            AND
            NOT dmli.d_pseudo_ins_select
            AND
            ((a_intern_select_cnt = a_max_intern_select) OR
            ( d_typ in  [ dstra, dstrb, dstruni,
            dlonga, dlongb, dlonguni ]))
            )
        THEN
            BEGIN
&           IFDEF TRACE
            t01int4  (ak_sem, 'we are in   ', 1);
&           ENDIF
            IF  (NOT d_view) OR (d_phase_cnt >= 4)
            THEN
                BEGIN
                IF  (d_typ in [ dstra, dstrb, dstruni,
                    dlonga, dlongb, dlonguni ])
                    (* PTS 1120890 E.Z. *)
                    AND (d_len < 2 * SURROGATE_MXGG00)
                THEN
                    BEGIN
                    (* in case of insert/select we need to store both the *)
                    (* file surrogate and the table surrogate to be able  *)
                    (* to copy the LONG value later                       *)
                    d_len     := 2 * SURROGATE_MXGG00;
                    d_iolen   := d_len + 1;
                    (* PTS 1111575 E.Z. *)
                    IF  a_return_segm^.sp1r_function_code = csp1_mselect_into_fc
                    THEN
                        BEGIN
                        a_return_segm^.sp1r_function_code := csp1_select_into_fc;
                        a_precomp_info_byte := csp1_p_none
                        END;
                    (*ENDIF*) 
                    END
                (*ENDIF*) 
                END
            (*ENDIF*) 
            END;
        (*ENDIF*) 
    (*ENDIF*) 
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61long_ins_sel_st_entries (
            VAR acv          : tak_all_command_glob;
            VAR dmli         : tak_dml_info;
            VAR colinf       : tak00_columninfo;
            VAR st_pos       : integer);
 
VAR
      tabid  : tgg00_Surrogate;
      (* PTS 1105795 M.Ki. *)
 
BEGIN
(* put table id for this LONG in stack entry *)
WITH acv, a_mblock, mb_qual^, mb_data^, dmli, colinf DO
    IF  st_pos + 4 > mb_st_max
    THEN
        a07_b_put_error (acv, e_too_many_mb_stackentries, -mb_st_max)
    ELSE
        BEGIN
        st_pos  := st_pos + 2;
        WITH mb_st^ [st_pos] DO
            BEGIN
            etype           := st_value;
            eop             := op_none;
            epos            := mb_data_len + 1;
            elen_var        := SURROGATE_MXGG00 + 1;
            ecol_tab[ 1 ]   := chr(0);
            ecol_tab[ 2 ]   := chr(0);
            mqual_cnt   := mqual_cnt   + 2;
            mfirst_free := mfirst_free + 2;
            END;
        (*ENDWITH*) 
&       IFDEF TRACE
        t01surrogate (ak_sem, 'btreeidtabid',
              d_sparr.pbasep^.sbase.btreeid.fileTabId_gg00);
&       ENDIF
        WITH d_sparr.pbasep^.sbase DO
            BEGIN
            IF  mb_data_len + mb_st^ [st_pos].elen_var > mb_data_size
            THEN
                a07_b_put_error (acv, e_too_many_mb_data, 1)
            ELSE
                BEGIN (* *** filling part2 *** *)
                IF  (d_sparr.pbasep^.sbase.btablekind = tview)
                THEN
                    ak61get_long_tabid (acv, dmli,
                          ord(mb_st^ [st_pos - 1].ecol_tab[2]),
                          tabid)
                ELSE
                    tabid := btreeid.fileTabId_gg00;
                (*ENDIF*) 
                mbp_buf [mb_data_len+1] := csp_defined_byte;
                g10mv ('VAK61 ',   1,    
                      SURROGATE_MXGG00, mb_data_size,
                      @tabid, 1,
                      @mbp_buf, mb_data_len+2,
                      SURROGATE_MXGG00,
                      a_returncode);
                mb_data_len := mb_data_len + mb_st^ [st_pos].elen_var;
                a_long_desc_pos := st_pos;
                END;
            (*ENDIF*) 
            END;
        (*ENDWITH*) 
        a641string_set_operator (acv, op_b_concat,
              2 * SURROGATE_MXGG00 + 1,
              mxsp_c8 + mb_st^ [st_pos].elen_var - 1,
              chr(3), chr(0));
        mqual_cnt   := pred (mqual_cnt);
        mfirst_free := pred (mfirst_free);
        END;
    (*ENDIF*) 
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61long_desc_st_entries (
            VAR acv          : tak_all_command_glob;
            VAR dmli         : tak_dml_info;
            VAR colinf       : tak00_columninfo;
            VAR st_pos       : integer);
 
VAR
      ld         : tsp00_LongDescriptor;
      cmp_result : tsp00_LcompResult;
 
BEGIN
WITH acv, a_mblock, mb_qual^, mb_data^, dmli, colinf DO
    BEGIN
    (* PTS 1116801 E.Z. *)
    IF  mb_st^ [st_pos + 1].elen_var < mxsp_long_desc + 1
    THEN
        BEGIN
&       IFDEF TRACE
        t01int4  (ak_sem, 'st_pos      ', st_pos);
&       ENDIF
        (* 1123504 E.Z. *)
        IF  ((mb_st^ [st_pos+1].etype = st_value) AND
            ( mb_st^ [st_pos+1].elen_var = 2) (* null-value *)
            )
            OR
            ((ccolstack.elen_var > 0) AND
            ( ccolstack.etype = st_func))
        THEN
            BEGIN
            mfirst_free := pred(mfirst_free);
            mqual_cnt := pred(mqual_cnt)
            END;
        (*ENDIF*) 
        IF  st_pos + 4 > mb_st_max
        THEN
            a07_b_put_error (acv, e_too_many_mb_stackentries, -mb_st_max)
        ELSE
            BEGIN
            st_pos               := st_pos + 2;
            WITH mb_st^ [st_pos] DO
                BEGIN
                etype           := st_value;
                eop             := op_none;
                epos            := mb_data_len + 1;
                (* PTS 1116801 E.Z. *)
                elen_var        := mxsp_long_desc - SURROGATE_MXGG00 + 1;
                ecol_tab[ 1 ]   := chr(0);
                ecol_tab[ 2 ]   := chr(0);
                END;
            (*ENDWITH*) 
            mqual_cnt   := mqual_cnt   + 2;
            mfirst_free := mfirst_free + 2;
&           IFDEF TRACE
            t01surrogate (ak_sem, 'btreeidtabid',
                  d_sparr.pbasep^.sbase.btreeid.fileTabId_gg00);
&           ENDIF
            WITH d_sparr.pbasep^.sbase DO
                BEGIN
                IF  mb_data_len + mb_st^ [st_pos].elen_var > mb_data_size
                THEN
                    a07_b_put_error (acv, e_too_many_mb_data, 1)
                ELSE
                    BEGIN (* *** filling part2 *** *)
                    ld.ld_descriptor := cgg_zero_id;
                    ld.ld_used_in_ak := ' ';
                    IF  (d_sparr.pbasep^.sbase.btablekind = tview)
                    THEN
                        ak61get_long_tabid (acv, dmli,
                              ord(mb_st^ [st_pos - 1].ecol_tab[2]),
                              ld.ld_tabid)
                    ELSE
                        ld.ld_tabid := btreeid.fileTabId_gg00;
                    (*ENDIF*) 
                    (* PTS 1105838 E.Z. *)
                    ld.ld_maxlen         := 0;
                    IF  cdatatyp in [ dstra, dstrb, dstruni ]
                    THEN
                        BEGIN
                        ld.ld_state      := [ ld_short_scol ];
                        ld.ld_infoset    := [ ];
                        END
                    ELSE
                        BEGIN
                        ld.ld_state      := [ ];
                        ld.ld_infoset    := [ ld_without_shortcol ];
                        END;
                    (*ENDIF*) 
                    ld.ld_state      := ld.ld_state + [ ld_first_call ];
                    IF  (cdatatyp in [ dstra, dlonga ]) AND
                        (a_out_packet^.sp1_header.sp1h_mess_code
                        in [csp_unicode, csp_unicode_swap])
                    THEN
                        ld.ld_state := ld.ld_state +
                              [ ld_use_toascii ];
                    (*ENDIF*) 
                    IF  (cdatatyp in [ dstruni, dlonguni ]) AND
                        (a_out_packet^.sp1_header.sp1h_mess_swap <>
                        sw_normal)
                    THEN
                        ld.ld_state := ld.ld_state +
                              [ ld_use_ucs_2_swap ];
                    (*ENDIF*) 
                    ld.ld_intern_pos :=  1;
                    IF  cdatatyp in [dstruni, dlonguni]
                    THEN
                        ld.ld_infoset := ld.ld_infoset + [ld_unicode];
                    (*ENDIF*) 
                    ld.ld_valmode    := vm_nodata;
                    ld.ld_valind     := 0;
                    ld.ld_unused_2   := 0;
                    ld.ld_valpos     := -1;
                    ld.ld_vallen     := -1;
                    cmp_result       := l_less;
                    IF  a_long_desc_pos > 0
                    THEN
                        s30cmp1 (mbp_buf,
                              mb_st^ [st_pos].epos+cgg_rec_key_offset,
                              mb_st^ [st_pos].elen_var,
                              ld, 1, mb_st^ [st_pos].elen_var,
                              cmp_result);
                    (*ENDIF*) 
                    IF  (cmp_result <> l_equal)
                    THEN
                        BEGIN
                        mbp_buf [mb_data_len+1] := csp_defined_byte;
                        g10mv ('VAK61 ',   2,    
                              sizeof(ld), mb_data_size,
                              @ld, SURROGATE_MXGG00 + 1,
                              @mbp_buf, mb_data_len+2,
                              mb_st^ [st_pos].elen_var - 1,
                              a_returncode);
                        mb_data_len := mb_data_len + mb_st^ [st_pos].elen_var;
                        a_long_desc_pos := st_pos;
                        END
                    ELSE
                        mb_st^[ st_pos ] := mb_st^ [a_long_desc_pos];
                    (*ENDIF*) 
&                   ifdef trace
                    IF  ld_use_ucs_2_swap IN ld.ld_state
                    THEN
                        t01int4 (ak_sem, 'ld_swap_ucs2', ord (ld_use_ucs_2_swap));
&                   endif
                    (*ENDIF*) 
                    END
                (*ENDIF*) 
                END;
            (*ENDWITH*) 
            (* PTS 1116801 E.Z. *)
            a641string_set_operator (acv, op_b_concat,
                  mxsp_long_desc + 1,
                  mxsp_c8 + mb_st^ [st_pos].elen_var - 1,
                  chr(3), chr(0));
            mqual_cnt   := pred (mqual_cnt);
            mfirst_free := pred (mfirst_free);
            END;
        (*ENDIF*) 
        END
    (* PTS 1116801 E.Z. *)
    (*ENDIF*) 
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61one_star_table_check (
            VAR acv       : tak_all_command_glob;
            VAR dmli      : tak_dml_info;
            curr_n        : integer;
            VAR col_index : integer);
 
VAR
      fieldno    : integer;
      new_col_ptr: tak00_colinfo_ptr;
 
BEGIN
IF  acv.a_returncode = 0
THEN
    WITH acv, dmli, d_tabarr[ d_acttabindex ] DO
        IF  oall_priv                                 AND
            NOT (d_sparr.pbasep^.sbase.btablekind in
            [ tonebase, tview ])                      AND
            NOT (d_view)                              AND
            NOT (d_union)                             AND
            NOT (d_first_union)                       AND
            NOT (a_recursive_state in
            [ rs_first_select, rs_recursive_select ]) AND
            ((NOT a_insert_select) OR
            a_from_select          OR
            d_subquery)
        THEN
            BEGIN
            ak61all_columns (acv, dmli, col_index)
            END
        ELSE
            BEGIN
            fieldno   := 1;
            WITH d_sparr.pbasep^.sbase DO
                IF  (btablekind in [twithoutkey, tcomplexview])
                THEN
                    fieldno := 2
                ELSE
                    IF  btablekind = tresult
                    THEN
                        IF  NOT (
                            (acv.a_recursive_state = rs_check_select_list) AND
                            (btablen^ = acv.a_result_name)
                            )
                        THEN
                            fieldno := 2;
                        (*ENDIF*) 
                    (*ENDIF*) 
                (*ENDIF*) 
            (*ENDWITH*) 
            WHILE ((fieldno <= d_sparr.pbasep^.sbase.bmaxcol) AND
                  (a_returncode = 0)) DO
                BEGIN
&               IFDEF TRACE
                t01int4 (ak_sem, 'fieldno     ', fieldno);
                t01int4 (ak_sem, 'd_cntpar    ', d_cntpar);
&               ENDIF
                IF  ((fieldno in oprivset) OR oall_priv)
                THEN
                    WITH  d_sparr.pbasep^.sbase DO
                        BEGIN
                        a06extcolno (d_sparr.pbasep^.sbase,
                              fieldno, d_colbuf);
                        WITH d_colbuf^ DO
                            IF  (NOT (ctdropped   in ccolpropset)) AND
                                (NOT (ctinvisible in ccolpropset))
                            THEN
                                (* PTS 1105795 M.Ki. *)
                                (* PTS 1120891 E.Z. *)
                                IF  (NOT ((cdatatyp in
                                    [ dlonga, dlongb, dlongdb,
                                    dlonguni, dstruni,
                                    dstra, dstrb, dstrdb ])  AND
                                    (btablekind = tonebase)         AND
                                    (bv_tablekind = tcatalog_table) AND
                                    (a_insert_select OR
                                    ( a_init_ddl     = ddl_create_as_select))))
                                THEN
                                    IF  (cdatatyp in
                                        [ dlonga, dlongb, dlonguni,
                                        dstruni, dstra, dstrb ])  AND
                                        (d_distinct <> no_distinct)
                                    THEN
                                        a07_nb_put_error (acv,
                                              e_command_for_string_not_allow,
                                              d_vppos, d_column)
                                    ELSE
                                        BEGIN
                                        a061get_colname (d_colbuf^, d_column);
                                        ak61one_select_column (acv, dmli,
                                              d_colbuf^, new_col_ptr, curr_n,
                                              col_index);
                                        d_n_pos := 0
                                        END
                                    (*ENDIF*) 
                                (*ENDIF*) 
                            (*ENDIF*) 
                        (*ENDWITH*) 
                        END;
                    (*ENDWITH*) 
                (*ENDIF*) 
                fieldno   := succ (fieldno);
                END
            (*ENDWHILE*) 
            END
        (*ENDIF*) 
    (*ENDWITH*) 
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61put_checknull_func (
            VAR acv  : tak_all_command_glob;
            VAR dmli : tak_dml_info);
 
VAR
      j : integer;
 
BEGIN
(* this procedure describes a 1-byte column, in which *)
(* defined byte or undef byte will be written to show *)
(* if null-values were eliminated during set function *)
WITH acv, a_mblock, mb_qual^ DO
    IF  a_returncode = 0
    THEN
        BEGIN
        IF  mfirst_free >= mb_st_max
        THEN
            a07_b_put_error (acv, e_too_many_mb_stackentries, -mb_st_max)
        ELSE
            BEGIN
            mqual_cnt := mqual_cnt + 2;
            WITH mb_st^ [mfirst_free] DO
                BEGIN
                etype    := st_func;
                eop_func := op_f_check_null;
                j := mfirst_free - 1;
                WHILE ((j > 1) AND (mb_st^ [j].etype <> st_func)) DO
                    j := pred(j);
                (*ENDWHILE*) 
                epos := mfirst_free - j;
                elen_var := 1;
                ecol_tab[ 1 ] := chr(0);
                ecol_tab[ 2 ] := chr(1)
                END;
            (*ENDWITH*) 
            WITH mb_st^ [mfirst_free + 1] DO
                BEGIN
                etype := st_output;
                eop   := op_none;
                epos  := dmli.d_inoutpos;
                elen_var := 1;
                ecol_pos := 0;
                END;
            (*ENDWITH*) 
            mfirst_free := mfirst_free + 2;
            WITH dmli.d_change DO
                IF  cr_colcount = MAX_COL_PER_TAB_GG00
                THEN
                    a07_b_put_error (acv, e_select_col_list_too_long,
                          dmli.d_vppos)
                ELSE
                    BEGIN
                    cr_colcount := succ(cr_colcount);
                    WITH cr_columns[ cr_colcount ] DO
                        BEGIN
                        ch_startpos := dmli.d_inoutpos;
                        ch_length   := chr(1);
                        ch_type  := [ ch_to_warn2 ];
                        END
                    (*ENDWITH*) 
                    END;
                (*ENDIF*) 
            (*ENDWITH*) 
            dmli.d_inoutpos := succ(dmli.d_inoutpos);
            dmli.d_check_null_byte := true;
            IF  dmli.d_distinct = full_distinct
            THEN
                dmli.d_distinct := distinct_without_warning_byte;
            (*ENDIF*) 
            END
        (*ENDIF*) 
        END
    (*ENDIF*) 
(*ENDWITH*) 
END;
 
(* PTS 1118056 E.Z. *)
(*------------------------------*) 
 
FUNCTION
      ak61static_value (
            VAR acv     : tak_all_command_glob;
            old_stackcnt : integer) : boolean;
 
VAR
      index        : integer;
      static_value : boolean;
 
BEGIN
static_value := true;
WITH acv.a_mblock, mb_qual^ DO
    FOR index := old_stackcnt TO mfirst_free - 1 DO
        IF  mb_st^ [index].etype <= st_column
        THEN
            static_value := false;
        (*ENDIF*) 
    (*ENDFOR*) 
(*ENDWITH*) 
ak61static_value := static_value
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61select_column_check (
            VAR acv       : tak_all_command_glob;
            VAR dmli      : tak_dml_info;
            curr_col      : integer;
            VAR col_index : integer);
 
VAR
      curr_n      : integer;
      node        : integer;
      m_cntpar    : integer;
      old_stackcnt: integer;
      new_col_ptr : tak00_colinfo_ptr;
 
BEGIN
IF  ( acv.a_returncode = 0 )
THEN
    BEGIN
    curr_n := acv.a_ap_tree^[ curr_col ].n_lo_level;
    node   := curr_n;
    dmli.d_user   := a01_il_b_identifier;
    dmli.d_table  := a01_il_b_identifier;
    dmli.d_column := a01_il_b_identifier;
    dmli.d_vppos := acv.a_ap_tree^[ curr_n ].n_pos;
    CASE acv.a_ap_tree^[ curr_n ].n_symb OF
        s_authid, s_tablename, s_columnname :
            BEGIN
            dmli.d_n_pos := acv.a_ap_tree^[ curr_n ].n_pos;
            a06get_username( acv, curr_n, dmli.d_user );
            WITH acv.a_ap_tree^[ curr_n ] DO
                IF  n_symb = s_tablename
                THEN
                    BEGIN
                    a05identifier_get( acv,
                          curr_n, sizeof( dmli.d_table ), dmli.d_table );
                    curr_n := n_sa_level;
                    END;
                (*ENDIF*) 
            (*ENDWITH*) 
            WITH acv.a_ap_tree^[ curr_n ] DO
                IF  ( n_symb = s_columnname )
                THEN
                    BEGIN
                    a05identifier_get( acv,
                          curr_n, sizeof ( dmli.d_column ), dmli.d_column );
                    a61_search_table (acv, dmli);
                    IF  ( acv.a_returncode <> 0 )
                    THEN
                        a07put_error_pos( acv, n_pos )
                    ELSE
                        ak61one_select_column( acv, dmli, dmli.d_colbuf^,
                              new_col_ptr, curr_n, col_index );
                    (*ENDIF*) 
                    END
                ELSE
                    BEGIN
                    a61_search_table( acv, dmli );
                    IF  ( acv.a_returncode <> 0 )
                    THEN
                        a07put_error_pos( acv, n_pos )
                    ELSE
                        BEGIN
                        m_cntpar := dmli.d_cntpar;
                        dmli.d_n_pos  := - dmli.d_n_pos;
                        ak61one_star_table_check( acv, dmli, curr_n, col_index );
                        IF  ((dmli.d_cntpar = m_cntpar) AND
                            (m_cntpar > 0))
                        THEN
                            BEGIN
                            acv.a_error_tableid := dmli.d_sparr.pbasep^.syskey.stableid;
                            a07_b_put_error( acv,
                                  e_missing_privilege, dmli.d_vppos );
                            END
                        (*ENDIF*) 
                        END
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
            (*ENDWITH*) 
            END;
        s_asterisk :
            ak61check_star_tables( acv, dmli, curr_n, col_index );
        s_reference_name :
            BEGIN
            a05identifier_get( acv,
                  curr_n, sizeof( dmli.d_refname ), dmli.d_refname );
            IF  ( acv.a_returncode = 0 )
            THEN
                BEGIN
                curr_n  := acv.a_ap_tree^[ curr_n ].n_sa_level;
                node    := curr_n;
                dmli.d_n_pos := acv.a_ap_tree^[ curr_n ].n_pos;
                a06get_username( acv, curr_n, dmli.d_user );
                WITH acv.a_ap_tree^[ curr_n ] DO
                    IF  n_symb = s_tablename
                    THEN
                        BEGIN
                        a05identifier_get (acv,
                              curr_n, sizeof (dmli.d_table), dmli.d_table);
                        curr_n := n_sa_level;
                        END;
                    (*ENDIF*) 
                (*ENDWITH*) 
                WITH acv.a_ap_tree^[ curr_n ] DO
                    BEGIN
                    IF  n_symb = s_columnname
                    THEN
                        BEGIN
                        a05identifier_get (acv,
                              curr_n, sizeof (dmli.d_column), dmli.d_column);
                        a61_search_table (acv, dmli);
                        IF  acv.a_returncode <> 0
                        THEN
                            a07put_error_pos (acv, n_pos)
                        ELSE
                            ak61one_select_column (acv, dmli, dmli.d_colbuf^,
                                  new_col_ptr, curr_n, col_index);
                        (*ENDIF*) 
                        IF  acv.a_returncode <> 0
                        THEN
                            a07put_error_pos (acv, n_pos)
                        (*ENDIF*) 
                        END
                    ELSE
                        BEGIN
                        (* PTS 1118056 E.Z. *)
                        old_stackcnt := acv.a_mblock.mb_qual^.mfirst_free;
                        ak61sel_val_expr (acv, dmli, curr_n, col_index,
                              NOT c_subquery_get);
                        IF  (acv.a_returncode = 0)            AND
                            dmli.d_group                                        AND
                            NOT (acv.a_ap_tree^ [ curr_n ].n_symb in
                            [ s_sum, s_min, s_max, s_count, s_all_count, s_avg,
                            s_stddev, s_variance, s_dis_sum, s_dis_count,
                            s_dis_avg, s_dis_stddev, s_dis_variance ])          AND
                            NOT ak61static_value (acv, old_stackcnt)
                        THEN
                            BEGIN
                            dmli.d_column := a01_il_b_identifier;
                            a61_is_group_field (acv, dmli, dmli.d_column, 0,
                                  c_is_expression, curr_n, dmli.d_vppos);
                            END
                        (*ENDIF*) 
                        END;
                    (*ENDIF*) 
                    dmli.d_refname := a01_il_b_identifier
                    END
                (*ENDWITH*) 
                END;
            (*ENDIF*) 
            END;
        s_point : (* select without select list in case *)
            (* of qualified delete orders for     *)
            (* updatable join views               *)
            BEGIN
            END;
        s_unknown :
            BEGIN
&           ifdef TRACE
            t01int4 (ak_sem, 'curr_n      ', curr_n);
            t01aptree (ak_sem, acv.a_ap_tree^, acv.a_scv_index,
                  acv.a_first_hint_node);
&           endif
            IF  ((acv.a_ap_tree^[ curr_n ].n_proc = a63query_spec) AND
                ( acv.a_ap_tree^[ curr_n ].n_subproc = cak_is_undefined))
                OR
                ((acv.a_ap_tree^[ curr_n ].n_proc = a63) AND
                ( acv.a_ap_tree^[ curr_n ].n_subproc = cak_x_start_union))
            THEN
                BEGIN
                ak61sel_val_expr (acv, dmli, curr_n, col_index,
                      c_subquery_get);
                IF  (acv.a_returncode = 0) AND dmli.d_group
                THEN
                    a61_is_group_field (acv, dmli, dmli.d_column, 0,
                          c_is_expression, curr_n, dmli.d_vppos);
                (*ENDIF*) 
                END
            ELSE
                IF  acv.a_ap_tree^[ curr_n ].n_proc = a67
                THEN
                    ak61sel_val_expr (acv, dmli, curr_n, col_index, NOT c_subquery_get)
                ELSE
                    a07_b_put_error (acv, e_not_implemented, dmli.d_vppos);
                (*ENDIF*) 
            (*ENDIF*) 
            END;
        OTHERWISE
            BEGIN
            (* PTS 1118056 E.Z. *)
            old_stackcnt := acv.a_mblock.mb_qual^.mfirst_free;
            ak61sel_val_expr (acv, dmli, curr_n, col_index, NOT c_subquery_get);
            IF  (acv.a_returncode = 0)            AND
                dmli.d_group                                        AND
                NOT (acv.a_ap_tree^ [ curr_n ].n_symb in
                [ s_sum, s_min, s_max, s_count, s_all_count, s_avg,
                s_stddev, s_variance, s_dis_sum, s_dis_count,
                s_dis_avg, s_dis_stddev, s_dis_variance ])          AND
                NOT ak61static_value (acv, old_stackcnt)
            THEN
                a61_is_group_field (acv, dmli, dmli.d_column, 0,
                      c_is_expression, curr_n, dmli.d_vppos);
            (*ENDIF*) 
            END
        END
    (*ENDCASE*) 
    END;
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61check_star_tables (
            VAR acv       : tak_all_command_glob;
            VAR dmli      : tak_dml_info;
            curr_n        : integer;
            VAR col_index : integer);
 
VAR
      i        : integer;
      m_cntpar : integer;
 
BEGIN
WITH acv, dmli DO
    IF  a_returncode = 0
    THEN
        BEGIN
        d_n_pos := 0;
        i        := 0;
        WHILE ((i < d_cntfromtab) AND (a_returncode = 0)) DO
            BEGIN
            m_cntpar := d_cntpar;
            i := succ(i);
            IF  d_acttabindex <> i
            THEN
                a61_rel_old_table (acv, dmli, i);
            (*ENDIF*) 
            IF  a_returncode = 0
            THEN
                ak61one_star_table_check (acv, dmli, curr_n, col_index);
            (*ENDIF*) 
            IF  (a_returncode = 0) AND
                ((m_cntpar = d_cntpar) AND (m_cntpar > 0))
            THEN
                BEGIN
                a_error_tableid := d_sparr.pbasep^.syskey.stableid;
                a07_b_put_error (acv, e_missing_privilege, d_vppos);
                END
            (*ENDIF*) 
            END
        (*ENDWHILE*) 
        END
    (*ENDIF*) 
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61col_long_shortinfo (
            VAR acv    : tak_all_command_glob;
            VAR dmli   : tak_dml_info;
            VAR colinf : tak00_columninfo);
 
BEGIN
WITH acv, dmli DO
    BEGIN
    IF  NOT d_subquery
    THEN
        (* PTS 1115646 E.Z. *)
        IF  (acv.a_mblock.mb_type <> m_insert_select)
            AND (NOT a_insert_select)
        THEN
            BEGIN
            IF  (d_single AND (a_ex_kind = only_parsing))
            THEN
                BEGIN
                IF  a_info_output
                THEN
                    a61_p_long_info (acv, dmli, colinf)
                ELSE
                    IF  d_parnum <= a_count_variab
                    THEN
                        a61_p_short_info (acv, dmli.d_sparr, colinf,
                              d_parnum, 0);
                    (* PTS 1111575 E.Z. *)
                    (*ENDIF*) 
                (*ENDIF*) 
                END
            ELSE
                IF  a_info_output
                THEN
                    a61_p_long_info (acv, dmli, colinf)
                ELSE
                    IF  a54_optim_select_fetch (acv)
                    THEN
                        a61_p_short_info (acv, d_sparr, colinf, d_parnum,
                              d_inoutpos - cgg_rec_key_offset - d_keylen);
                    (* PTS 1111575 E.Z. *)
                    (*ENDIF*) 
                (*ENDIF*) 
            (*ENDIF*) 
            d_parnum := succ(d_parnum)
            END;
        (*ENDIF*) 
    (*ENDIF*) 
    d_cntpar := pred(d_cntpar);
&   ifdef trace
    t01int4 (ak_sem, 'd_cntpar--  ', d_cntpar);
&   endif
    d_outcolno := succ(d_outcolno);
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61fill_change_info (
            VAR acv       : tak_all_command_glob;
            VAR dmli      : tak_dml_info;
            VAR colinf    : tak00_columninfo;
            num_changeset : tak_number_changetype_set);
 
CONST
      maxonebytelen = 255;
 
VAR
      restlen : integer;
      startpos : integer;
 
BEGIN
WITH acv, dmli, d_change, colinf DO
    BEGIN
    restlen  := cinoutlen;
    startpos := d_inoutpos;
    IF  (cdatatyp = dunicode)
        OR
        ((a_out_packet^.sp1_header.sp1h_mess_code in
        [ csp_unicode_swap, csp_unicode ]) AND
        (cdatatyp in [ dcha, dvarchara,
        ddate, dtime, dtimestamp ]))
    THEN
        BEGIN
        (* to make a distinction between one loooong unicode and *)
        (* two following each other (don't translate def-byte !!)*)
        (* startpos is 1 real byte before !! compare vak61       *)
        startpos := startpos + 1;
        restlen := restlen - 1
        END;
&   ifdef TRACE
    (*ENDIF*) 
    IF  (cdatatyp in [ dlonga, dlongb, dlonguni,
        dstra, dstrb, dstruni ])
    THEN
        t01int4 (ak_sem, 'slongs@@@@@@', cinoutlen);
&   endif
    (*ENDIF*) 
    WHILE ((restlen > 0) AND (a_returncode = 0)) DO
        IF  cr_colcount = MAX_COL_PER_TAB_GG00
        THEN
            a07_b_put_error (acv, e_select_col_list_too_long, d_vppos)
        ELSE
            BEGIN
            cr_colcount := succ(cr_colcount);
            WITH cr_columns[ cr_colcount ] DO
                BEGIN
                ch_type  := [  ];
                IF  ((a_out_packet^.sp1_header.sp1h_mess_code in
                    [ csp_unicode_swap, csp_unicode ]) AND
                    (cdatatyp in [ dcha, dvarchara,
                    ddate, dtime, dtimestamp ]))
                THEN
                    ch_type := [ ch_to_multibyte_set ]
                ELSE
                    IF  cdatatyp = dunicode
                    THEN
                        ch_type := [ ch_to_multibyte_set ];
                    (*ENDIF*) 
                (*ENDIF*) 
                ch_startpos := startpos;
                IF  restlen <= maxonebytelen
                THEN
                    ch_length   := chr(restlen)
                ELSE
                    ch_length   := chr(maxonebytelen);
                (*ENDIF*) 
                restlen  := restlen - ord(ch_length);
                startpos := startpos + ord(ch_length);
                CASE cdatatyp OF
                    ddate :
                        ch_type := ch_type + [ ch_date ];
                    dtime :
                        ch_type := ch_type + [ ch_time_or_timestamp ];
                    dtimestamp :
                        ch_type := ch_type + [ ch_time_or_timestamp ];
                    dlonga, dlongb, dlonguni,
                    dstra, dstrb, dstruni :
                        ch_type := ch_type + [ ch_to_longsupport ];
                    dfixed, dfloat, dvfloat,
                    dsmallint, dinteger :
                        BEGIN
                        IF  dmli.d_optimize_setfunction
                        THEN
                            ch_type := ch_type + [ ch_number_change_in_next_entry ];
                        (*ENDIF*) 
                        END;
                    OTHERWISE
                        BEGIN
                        END;
                    END;
                (*ENDCASE*) 
&               IFDEF TRACE
                t01int4 (ak_sem, 'ch_startpos ', ch_startpos);
                t01int4 (ak_sem, 'ch_length   ', ord(ch_length));
                IF  ch_date in ch_type
                THEN
                    t01name (ak_sem, 'change date       ');
                (*ENDIF*) 
                IF  ch_time_or_timestamp in ch_type
                THEN
                    t01name (ak_sem, 'change time(stamp)');
                (*ENDIF*) 
                IF  ch_to_ascii in ch_type
                THEN
                    t01name (ak_sem, 'change to ascii   ');
                (*ENDIF*) 
                IF  ch_to_multibyte_set in ch_type
                THEN
                    t01name (ak_sem, 'change to swap uni');
                (*ENDIF*) 
                IF  ch_to_longsupport in ch_type
                THEN
                    t01name (ak_sem, 'ch_to_longsupport ');
                (*ENDIF*) 
                IF  ch_number_change_in_next_entry in ch_type
                THEN
                    t01name (ak_sem, 'ch_number         ');
&               ENDIF
                (*ENDIF*) 
                IF  ((cr_colcount > 1) AND
                    (restlen = 0) AND
                    NOT cr_was_opt AND
                    NOT(ctopt in colinf.ccolpropset))
                    AND (NOT a_outer_join)
                    AND (NOT d_outer_join)
                    AND NOT (ch_number_change_in_next_entry in ch_type)
                THEN
                    IF  (
                        (ch_type = [ ch_to_ascii ])                                 AND
                        (cr_columns[ cr_colcount - 1 ].ch_type = ch_type)           AND
                        (cr_columns[ cr_colcount - 1 ].ch_startpos +
                        ord(cr_columns[ cr_colcount - 1 ].ch_length) = ch_startpos) AND
                        (ord(cr_columns[ cr_colcount - 1 ].ch_length) +
                        ord(ch_length) <= maxonebytelen)
                        )
                    THEN
                        BEGIN
                        cr_columns[ cr_colcount - 1 ].ch_length :=
                              chr(ord(cr_columns[ cr_colcount - 1 ].ch_length) +
                              ord(ch_length));
                        cr_colcount := pred(cr_colcount)
                        END;
                    (*ENDIF*) 
                (*ENDIF*) 
                IF  ch_number_change_in_next_entry in ch_type
                THEN
                    IF  cr_colcount = MAX_COL_PER_TAB_GG00
                    THEN
                        a07_b_put_error (acv, e_select_col_list_too_long, d_vppos)
                    ELSE
                        BEGIN
                        IF  (dmli.d_pos_result = cak_extern_pos) OR
                            (dmli.d_pos_result = cak_intern_pos)
                        THEN
                            WITH acv.a_resname_addr[ dmli.d_pos_result ]^.sresname DO
                                resstate := resstate - [rs_reuseable];
                            (*ENDWITH*) 
                        (*ENDIF*) 
                        cr_colcount := succ(cr_colcount);
                        WITH cr_columns[ cr_colcount ] DO
                            BEGIN
                            ch_number_type := num_changeset;
                            ch_startpos    := 0;
                            ch_length      := chr(0);
                            END
                        (*ENDWITH*) 
                        END;
                    (*ENDIF*) 
                (*ENDIF*) 
                cr_was_opt := ctopt in colinf.ccolpropset
                END
            (*ENDWITH*) 
            END
        (*ENDIF*) 
    (*ENDWHILE*) 
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61one_select_column (
            VAR acv         : tak_all_command_glob;
            VAR dmli        : tak_dml_info;
            VAR colinf      : tak00_columninfo;
            VAR new_col_ptr : tak00_colinfo_ptr;
            curr_n          : integer;
            VAR col_index   : integer);
 
VAR
      put_together     : boolean;
      together_allowed : boolean;
      is_io            : boolean;
      convert_type     : tsp00_DataType;
      hdatatyp         : tsp00_DataType;
      hetype           : tgg00_StackEntryType;
      convert_t        : tak_convert_type;
      uconvert_t       : tak_convert_type;
      aux_name         : tsp00_KnlIdentifier;
      i                : integer;
      oldmfirst_free   : integer;
      oldinoutpos      : integer;
      output_len       : integer;
      col_no           : integer;
      extdatetime      : boolean;
      curr_union_col   : tak00_colinfo_ptr;
      hcolinf          : tak00_columninfo;
 
BEGIN
WITH acv, dmli, d_tabarr[ d_acttabindex ],
     a_mblock, mb_qual^ DO
    BEGIN
    a061colinfo_to_var (colinf, hcolinf);
    WITH hcolinf DO
        ak61iolen_get (acv, dmli, extdatetime, is_io,
              cdatatyp, cdatalen, cinoutlen);
    (*ENDWITH*) 
&   IFDEF TRACE
    a061td_colinfo (hcolinf, 1);
&   endif
    convert_t    := conv_none;
    uconvert_t   := conv_none;
    hdatatyp     := dunknown;
    convert_type := dunknown;
    IF  (d_union OR
        (a_recursive_state in [ rs_first_select, rs_recursive_select ]))
    THEN
        WITH a_unionrec_ptr^.sunionrec DO
            BEGIN
            col_no                  := ucolpos;
            curr_union_col          := a_p_arr1.pbasep^.sbase.bcolumn[col_no];
            hdatatyp                := hcolinf.cdatatyp;
            hcolinf.cdatatyp        := curr_union_col^.cdatatyp;
            hcolinf.cdatalen        := curr_union_col^.cdatalen;
            hcolinf.cdatafrac       := curr_union_col^.cdatafrac;
            hcolinf.cinoutlen       := curr_union_col^.cinoutlen;
            hcolinf.ccolumnn        := curr_union_col^.ccolumnn;
            hcolinf.ccolpropset     := curr_union_col^.ccolpropset;
            hcolinf.cbinary         := curr_union_col^.cbinary;
            hcolinf.ccolumnn_len    := curr_union_col^.ccolumnn_len;
            a061get_colname (curr_union_col^, hcolinf.ccolumnn);
            hetype                  := hcolinf.ccolstack.etype;
            hcolinf.ccolstack.etype := curr_union_col^.ccolstack.etype;
            ak61get_convert_type (hdatatyp, hcolinf.cdatatyp, uconvert_t);
&           IFDEF TRACE
            t01int4 (ak_sem, 'colstacketyp', ord (hcolinf.ccolstack.etype));
            t01int4 (ak_sem, 'hetype      ', ord (hetype));
            t01int4 (ak_sem, 'cdatatyp 613', ord (hcolinf.cdatatyp));
            t01int4 (ak_sem, 'hdatatyp    ', ord (hdatatyp));
            t01int4 (ak_sem, 'ucolpos     ', ucolpos);
            t01int4 (ak_sem, 'col_no      ', col_no);
            t01int4 (ak_sem, 'hcol_iolen  ', hcolinf.cinoutlen);
&           ENDIF
            IF  (hdatatyp in [ ddate, dtime, dtimestamp ]) AND
                (hcolinf.cdatatyp <> hdatatyp)
            THEN
                convert_type := hdatatyp;
            (*ENDIF*) 
            ucolpos := succ(ucolpos)
            END ;
        (*ENDWITH*) 
    (*ENDIF*) 
    IF  a_returncode = 0
    THEN
        IF  d_cntpar > 0
        THEN
            ak61col_long_shortinfo (acv, dmli, hcolinf)
        ELSE
            IF  d_refname[ 1 ] <> '@'
                (*for update *)
            THEN
                IF  (d_subquery OR NOT d_single) AND (NOT a_from_select)
                THEN
                    a07_b_put_error (acv, e_select_col_list_too_long,
                          d_vppos)
                ELSE
                    WITH a_transinf.tri_trans DO
                        trWarning_gg00 := trWarning_gg00 + [ warn0_exist,
                              warn3_output_not_into_columns ];
                    (*ENDWITH*) 
                (*ENDIF*) 
            (*ENDIF*) 
        (*ENDIF*) 
    (*ENDIF*) 
    IF  ((colinf.ctabno > cak00_maxsources) AND
        (d_allowed <> tabs_with_arith))
    THEN (* expression-column, prepare two_phase-SELECT *)
        d_allowed := are_more_tabs;
    (*ENDIF*) 
    IF  colinf.ccolstack.etype = st_func
    THEN
        BEGIN
        i := 0;
        WITH a_ap_tree^[ curr_n ] DO
            BEGIN
            n_proc := no_proc;
            REPEAT
                n_proc := succ(n_proc);
                i      := succ(i);
            UNTIL
                i = d_acttabindex;
            (*ENDREPEAT*) 
            END;
        (*ENDWITH*) 
        END;
    (*ENDIF*) 
    IF  ((a_returncode = 0) AND NOT d_single)
    THEN
        BEGIN
        a16col_to_view_description (acv,
              dmli, hcolinf, NOT(d_subquery));
&       IFDEF TRACE
        a061td_colinfo (hcolinf, 2);
&       endif
        ak61build_colinfo (acv, dmli, hcolinf, new_col_ptr,
              convert_t, col_index);
&       IFDEF TRACE
        a061td_colinfo (hcolinf, 3);
&       endif
        END;
    (* PTS 1111575 E.Z. *)
&   IFDEF TRACE
    (*ENDIF*) 
    t01name (ak_sem, 'AK61: FSD false   ');
&   ENDIF
    (* PTS 1107681 E.Z. *)
    together_allowed := false;
    IF  (d_union OR
        (a_recursive_state in [ rs_first_select, rs_recursive_select ]))
    THEN
        BEGIN
        hcolinf.ccolstack.etype := hetype;
        IF  (convert_t <> conv_none)
        THEN
            BEGIN
            a65_convert (acv, convert_t, hcolinf.cinoutlen);
            convert_t := conv_none;
            END
        ELSE
            convert_t := uconvert_t;
        (*ENDIF*) 
        (* ?????
              IF  (hcolinf.cdatatyp = dunicode) AND
              (hdatatyp <> dunicode)
              THEN
              convert_type := dunicode;
              *)
        END;
    (*ENDIF*) 
    oldinoutpos := d_inoutpos;
    (* PTS 1106343 E.Z. *)
    put_together := false;
    a61_var_col_stackentry (acv, dmli, hcolinf,
          together_allowed, put_together,
          output_len, NOT c_is_corr_column, convert_t, convert_type);
    IF  ((a_returncode = 0)     AND
        (a_union_cnt > 0)                         AND
        (NOT d_union)                             AND
        NOT (a_recursive_state in
        [ rs_first_select, rs_recursive_select ]) AND
        (output_len <> 0))
    THEN
        IF  mb_st^ [mfirst_free - 2].etype = st_func
        THEN
            new_col_ptr^.ccolstack.ecol_tab[ 1 ] :=
                  chr(output_len);
        (*ENDIF*) 
    (*ENDIF*) 
    IF  ((a_returncode = 0) AND
        (a_union_cnt > 0)                     AND
        (d_union OR
        (a_recursive_state in
        [ rs_first_select, rs_recursive_select ])))
    THEN
        IF  mb_st^ [mfirst_free - 2].etype = st_func
        THEN
            WITH a_p_arr1.pbasep^.sresult DO
                BEGIN
&               ifdef TRACE
                t01int4 (ak_sem, 'bcol ecol[1]',
                      ord(bcolumn[ col_no ]^.ccolstack.ecol_tab[ 1 ]));
                t01int4 (ak_sem, 'hcol cinoutl', hcolinf.cinoutlen);
                t01int4 (ak_sem, 'd_inoutpos  ', d_inoutpos);
                t01int4 (ak_sem, 'oldinoutpos ', oldinoutpos);
&               endif
                IF  ((bcolumn[col_no]^.ccolstack.ecol_tab[ 1 ] <> chr(0)) AND
                    (d_inoutpos - oldinoutpos <>
                    ord(bcolumn[col_no]^.ccolstack.ecol_tab[ 1 ])) AND
                    (ord(bcolumn[col_no]^.ccolstack.ecol_tab[ 1 ]) >
                    hcolinf.cinoutlen))
                THEN
                    BEGIN
&                   ifdef TRACE
                    t01int4 (ak_sem, 'd_inoutpos 1', d_inoutpos);
&                   endif
                    d_inoutpos :=
                          ord(bcolumn[col_no]^.ccolstack.ecol_tab[ 1 ])
                          + oldinoutpos;
                    WITH mb_st^ [mfirst_free - 1] DO
                        elen_var :=
                              ord(bcolumn[col_no]^.ccolstack.ecol_tab[ 1 ])
                              (*-
                              hcolinf.cinoutlen
                              *)
                              ;
                    (*ENDWITH*) 
                    hcolinf.cinoutlen :=
                          ord(bcolumn[col_no]^.ccolstack.ecol_tab[ 1 ]) ;
&                   ifdef TRACE
                    t01int4 (ak_sem, 'd_inoutpos 2', d_inoutpos);
                    t01int4 (ak_sem, 'elen_var    ',
                          mb_st^ [mfirst_free - 1].elen_var);
&                   endif
                    END;
                (*ENDIF*) 
                END;
            (*ENDWITH*) 
        (*ENDIF*) 
    (*ENDIF*) 
    oldmfirst_free := mfirst_free;
    IF  (d_union OR
        (a_recursive_state in [ rs_first_select, rs_recursive_select ]))
        AND d_subquery
    THEN
        put_together := false;
    (*ENDIF*) 
    IF  ((a_returncode = 0) AND d_use_order)
    THEN
        a61_is_orderfield (acv, dmli, hcolinf, @d_order_cols,
              NOT put_together, convert_t, curr_n, d_column);
    (*ENDIF*) 
    IF  ((a_returncode = 0) AND d_group)
    THEN
        BEGIN
        a061get_colname (colinf, aux_name);
        a61_is_group_field (acv, dmli, aux_name,
              colinf.cextcolno, NOT c_is_expression, 0, d_vppos)
        END;
    (*ENDIF*) 
    IF  ( a_ap_tree^[ a_ap_tree^[ 0 ].n_lo_level ].n_proc
        in [ a63, a62, a16 ] ) AND
        ( oview OR (oresfile in ospecialname) ) AND
        NOT (d_subquery OR a_from_select) AND
        NOT put_together
    THEN
        WITH a_mblock, mb_qual^ DO
            IF  ( mb_st^ [mfirst_free - 1].etype = st_output )
            THEN
                IF  ( mb_st^ [mfirst_free - 1].eop = op_none )
                THEN
                    mb_st^ [mfirst_free - 1].eop_out := op_o_output_oflw;
                (*ENDIF*) 
            (*ENDIF*) 
        (*ENDWITH*) 
    (*ENDIF*) 
    col_index := succ (col_index);
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61sel_val_expr (
            VAR acv       : tak_all_command_glob;
            VAR dmli      : tak_dml_info;
            curr_n        : tsp00_Int2;
            VAR col_index : integer;
            subquery_get  : boolean);
 
VAR
      overflow_allow   : boolean;
      put_together     : boolean;
      together_allowed : boolean;
      extdatetime      : boolean;
      is_io            : boolean;
      convert_type     : tsp00_DataType;
      hdatatyp         : tsp00_DataType;
      col_no           : integer;
      oldinoutpos      : integer;
      output_len       : integer;
      datatype_n       : integer;
      colinf           : tak00_columninfo;
      colin            : tak00_scolinf;
      new_col_ptr      : tak00_colinfo_ptr;
      convert_t        : tak_convert_type;
      uconvert_t       : tak_convert_type;
 
BEGIN
WITH acv, dmli DO
    BEGIN
    (* select_list contains other expr. than 'single columns' or '*' *)
    (* PTS 1111575 E.Z. *)
&   IFDEF TRACE
    t01name (ak_sem, 'AK61: FSD false   ');
&   ENDIF
    d_const_value_expr  := true;
    d_param_st_begin    := 0;
    d_param_st_index    := 0;
    d_is_parameter_only := false;
    colin.sci_len       := 0;
    colin.sci_cprops    := []; (* h.b. PTS 1105136 *)
    d_datatype          := dunknown;
    d_colptr            := NIL;
    d_first_tab         := 0;
    d_pars_kind         := fp_val_all_without_l;
    d_change_date_time  := false;
    IF  subquery_get
    THEN
        BEGIN
        datatype_n := a_ap_tree^[curr_n].n_sa_level;
        (* PTS 1121191 E.Z. *)
        IF  datatype_n = 0
        THEN
            a07_b_put_error (acv, e_corelated_subquery_not_allowe,
                  a_ap_tree^[ curr_n ].n_pos)
        ELSE
            WITH a_ap_tree^[datatype_n], colin DO
                BEGIN
                sci_typ      := n_datatype;
                d_datatype := n_datatype;
                IF  sci_typ = dfixed
                THEN
                    BEGIN
                    sci_len      := n_pos DIV 100;
                    (* PTS 1122972 E.Z. *)
                    sci_frac     := (n_pos MOD 100) - cak_frac_offset;
                    END
                ELSE
                    BEGIN
                    sci_len      := n_pos;
                    IF  sci_typ = dfloat
                    THEN
                        sci_frac := csp_float_frac
                    ELSE
                        sci_frac     := 0
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
                sci_iolen    := n_length;
                sci_cprops   := [ ctopt ];
                (*
                      sci_dttyp    :=
                      sci_com_type :=
                      sci_udt_id   :=
                      *)
                a65subq_get_val (acv, curr_n, sci_iolen);
                END
            (*ENDWITH*) 
        (*ENDIF*) 
        END
    ELSE
        BEGIN
        a65_val_expr (acv, dmli, colin, curr_n);
        IF  a_returncode = cak_e_parameter
        THEN
            BEGIN
            a_returncode := 0;
            d_is_parameter_only := true;
            a65_look_for_datatypes (acv, dmli, curr_n);
            IF  d_datatype = dunknown
            THEN
                a07_b_put_error (acv, e_without_datatypes,
                      a_ap_tree^[ curr_n ].n_pos)
            ELSE
                IF  a_returncode = 0
                THEN
                    BEGIN
                    colin.sci_len := 0;
                    a65_val_expr (acv, dmli, colin, curr_n)
                    END
                (*ENDIF*) 
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    d_change_date_time := true;
    convert_t          := conv_none;
    uconvert_t         := conv_none;
    hdatatyp           := dunknown;
    IF  a_returncode = 0
    THEN
        BEGIN
        WITH colinf, colin DO
            BEGIN
            cbinary := false;
            (* PTS 1116837 E.Z. *)
            IF  NOT (d_union OR
                (a_recursive_state in [ rs_first_select, rs_recursive_select ]))
            THEN
                BEGIN
                IF  (a_union_cnt < 1) AND (sci_typ = dunknown) AND
                    (NOT d_subquery) AND (NOT a_insert_select)
                THEN
                    BEGIN
                    (* NULL in select_list *)
                    sci_typ := dchb
                    END;
                (*ENDIF*) 
                IF  d_refname = a01_il_b_identifier
                THEN
                    IF  a_ap_tree^[ curr_n ].n_symb = s_rowno
                    THEN
                        ccolumnn := a01_i_rowno
                    ELSE
                        a61_new_expr_no (colinf, d_exprno)
                    (*ENDIF*) 
                ELSE
                    ccolumnn := d_refname;
                (*ENDIF*) 
                ccolpropset := sci_cprops;
                END
            ELSE
                WITH a_unionrec_ptr^.sunionrec DO
                    BEGIN
                    col_no := ucolpos;
                    WITH a_p_arr1.pbasep^.sresult DO
                        BEGIN
                        ccolpropset := bcolumn[col_no]^.ccolpropset;
                        a061get_colname (bcolumn[col_no]^, ccolumnn);
&                       IFDEF TRACE
                        ;
                        t01int4 (ak_sem, 'cdatatyp r  ', ord (cdatatyp));
                        t01int4 (ak_sem, 'ucolpos     ', ucolpos);
                        t01int4 (ak_sem, 'col_no      ', col_no);
&                       ENDIF
                        END
                    (*ENDWITH*) 
                    END;
                (*ENDWITH*) 
            (*ENDIF*) 
            a061eval_colname_len (colinf);
            overflow_allow := false;
            ak61iolen_get (acv, dmli, extdatetime, is_io,
                  sci_typ, sci_len, sci_iolen);
            IF  is_io
            THEN
                IF  ( a_ap_tree^[ curr_n ].n_symb in
                    [ s_mult, s_div, s_divide,
                    s_mod, s_plus, s_minus,
                    s_abs, s_fixed, s_num, s_noround,
                    s_round, s_trunc, s_length, s_float,
                    s_ceil, s_floor, s_sign, s_sqrt, s_power,
                    s_min, s_max, s_avg, s_dis_avg, s_dis_sum,
                    s_sum, s_count, s_dis_count, s_all_count,
                    s_stddev, s_dis_stddev, s_variance, s_dis_variance,
                    s_value, s_greatest, s_least, s_decode,
                    s_cos, s_sin, s_tan, s_acos, s_asin, s_atan,
                    s_atan2, s_exp, s_log, s_log10, s_ln ] ) AND
                    (a_sqlmode in [ sqlm_internal, sqlm_db2 ])
                THEN
                    BEGIN
                    overflow_allow := true;
                    IF  NOT ( a_ap_tree^[ curr_n ].n_symb in
                        [ s_count, s_dis_count, s_all_count ] )
                    THEN
                        ccolpropset := ccolpropset + [ ctopt ];
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
            (*ENDIF*) 
            a061get_colname (colinf, d_column);
            cextcolno   := 0;
            creccolno   := 1;
            IF  subquery_get
            THEN
                ctabno := 0
            ELSE
                ctabno := d_acttabindex;
            (*ENDIF*) 
            IF  (d_union OR
                (a_recursive_state in [ rs_first_select, rs_recursive_select ]))
            THEN
                WITH a_unionrec_ptr^.sunionrec DO
                    BEGIN
                    WITH a_p_arr1.pbasep^.sresult DO
                        BEGIN
                        hdatatyp  := sci_typ;
                        cdatatyp  := bcolumn[col_no]^.cdatatyp;
                        cdatalen  := bcolumn[col_no]^.cdatalen;
                        cdatafrac := bcolumn[col_no]^.cdatafrac;
                        cinoutlen := bcolumn[col_no]^.cinoutlen;
                        ak61get_convert_type (hdatatyp, cdatatyp, uconvert_t);
                        END;
                    (*ENDWITH*) 
                    ucolpos := succ(ucolpos)
                    END
                (*ENDWITH*) 
            ELSE
                BEGIN
&               IFDEF TRACE
                t01int4 (ak_sem, 'cdatatyp   1', ord (cdatatyp));
                t01int4 (ak_sem, 'typ        1', ord (sci_typ));
&               ENDIF
                cdatatyp  := sci_typ;
                cdatalen  := sci_len;
                cdatafrac := sci_frac + cak_frac_offset;
                cinoutlen := sci_iolen;
                END;
            (*ENDIF*) 
&           IFDEF TRACE
            t01int4 (ak_sem, 'colin   len ', sci_len);
            t01int4 (ak_sem, 'colin   frac', sci_frac);
            t01int4 (ak_sem, 'colin   iole', sci_iolen);
            t01int4 (ak_sem, 'colinf cdlen', cdatalen);
            t01int4 (ak_sem, 'colinf cdfra', cdatafrac - cak_frac_offset);
            t01int4 (ak_sem, 'colinf ciole', cinoutlen);
&           ENDIF
            WITH ccolstack DO
                BEGIN
                etype    := st_fixcol;
                eop      := op_none;
                epos     := 0;
                elen_var := 0;
                ecol_tab[ 1 ] := chr(0);
                ecol_tab[ 2 ] := chr(0)
                END
            (*ENDWITH*) 
            END;
        (*ENDWITH*) 
        IF  (d_union OR
            (a_recursive_state in
            [ rs_first_select, rs_recursive_select ])) AND
            (hdatatyp in [ ddate, dtime, dtimestamp ]) AND
            (colinf.cdatatyp <> hdatatyp)
        THEN
            convert_type := hdatatyp
        ELSE
            (* ???
                  IF  d_union AND
                  (colinf.cdatatyp = dunicode) AND
                  (hdatatyp <> dunicode)
                  THEN
                  convert_type := dunicode
                  ELSE
                  *)
            convert_type := dunknown;
        (*ENDIF*) 
        IF  a_returncode = 0
        THEN
            IF  d_cntpar > 0
            THEN
                ak61col_long_shortinfo (acv, dmli, colinf)
            ELSE
                IF  (d_subquery OR NOT d_single) AND (NOT a_from_select)
                THEN
                    a07_b_put_error (acv, e_select_col_list_too_long,
                          a_ap_tree^[ curr_n ].n_pos)
                ELSE
                    WITH a_transinf.tri_trans DO
                        trWarning_gg00 := trWarning_gg00 + [ warn0_exist,
                              warn3_output_not_into_columns ];
                    (*ENDWITH*) 
                (*ENDIF*) 
            (*ENDIF*) 
        (*ENDIF*) 
        IF  ((a_returncode = 0) AND NOT d_single)
        THEN
            ak61build_colinfo (acv, dmli, colinf, new_col_ptr,
                  convert_t, col_index);
        (*ENDIF*) 
        together_allowed := false;
        IF  (d_union OR
            (a_recursive_state in [ rs_first_select, rs_recursive_select ]))
        THEN
            IF  (convert_t <> conv_none)
            THEN
                BEGIN
                a65_convert (acv, convert_t, colinf.cinoutlen);
                convert_t := conv_none;
                END
            ELSE
                convert_t := uconvert_t;
            (*ENDIF*) 
        (*ENDIF*) 
        oldinoutpos := d_inoutpos;
        (* PTS 1106343 E.Z. *)
        a61_var_col_stackentry (acv, dmli, colinf, together_allowed, put_together,
              output_len, NOT c_is_corr_column, convert_t, convert_type);
        IF  ((a_returncode = 0)     AND
            (a_union_cnt > 0)                         AND
            (NOT d_union)                             AND
            NOT (a_recursive_state in
            [ rs_first_select, rs_recursive_select ]) AND
            (output_len <> 0))
        THEN
            new_col_ptr^.ccolstack.ecol_tab[ 1 ] :=
                  chr(output_len);
&       ifdef TRACE
        (*ENDIF*) 
        t01int4 (ak_sem, 'a_union_cnt ', a_union_cnt);
        t01int4 (ak_sem, 'd_union     ', ord(d_union));
        t01messblock (ak_sem, 'sel_val_expr', a_mblock);
&       endif
        IF  ((a_returncode = 0) AND
            (a_union_cnt > 0)  AND
            (d_union OR
            (a_recursive_state in [ rs_first_select, rs_recursive_select ])))
        THEN
            WITH a_p_arr1.pbasep^.sresult DO
                BEGIN
&               ifdef TRACE
                t01int4 (ak_sem, 'bcol ecol[1]',
                      ord(bcolumn[col_no]^.ccolstack.ecol_tab[ 1 ]));
                t01int4 (ak_sem, ' col cinoutl', colinf.cinoutlen);
                t01int4 (ak_sem, 'd_inoutpos  ', d_inoutpos);
                t01int4 (ak_sem, 'oldinoutpos ', oldinoutpos);
&               endif
                IF  ((bcolumn[col_no]^.ccolstack.ecol_tab[ 1 ] <> chr(0)) AND
                    (d_inoutpos - oldinoutpos <>
                    ord(bcolumn[col_no]^.ccolstack.ecol_tab[ 1 ])) AND
                    (ord(bcolumn[col_no]^.ccolstack.ecol_tab[ 1 ]) >
                    colinf.cinoutlen))
                THEN
                    BEGIN
&                   ifdef TRACE
                    t01int4 (ak_sem, 'd_inoutpos 1', d_inoutpos);
&                   endif
                    d_inoutpos :=
                          ord(bcolumn[col_no]^.ccolstack.ecol_tab[ 1 ])
                          + oldinoutpos;
                    WITH a_mblock, mb_qual^,
                         mb_st^ [mfirst_free - 1] DO
                        elen_var :=
                              ord(bcolumn[col_no]^.ccolstack.ecol_tab[ 1 ])
                              (*-
                              colinf.cinoutlen
                              *)
                              ;
                    (*ENDWITH*) 
                    colinf.cinoutlen :=
                          ord(bcolumn[col_no]^.ccolstack.ecol_tab[ 1 ]) ;
                    (*
                          elen_var :=
                          ord(bcolumn[col_no]^.ccolstack.ecol_tab[ 1 ]) -
                          colinf.cinoutlen;
                          *)
&                   ifdef TRACE
                    t01int4 (ak_sem, 'd_inoutpos 2', d_inoutpos);
                    WITH a_mblock, mb_qual^ DO
                        t01int4 (ak_sem, 'elen_var    ',
                              mb_st^ [mfirst_free - 1].elen_var);
                    (*ENDWITH*) 
&                   endif
                    END;
                (*ENDIF*) 
                END;
            (*ENDWITH*) 
        (*ENDIF*) 
        IF  ((a_returncode = 0) AND d_use_order)
        THEN
            a61_is_orderfield (acv, dmli, colinf, @d_order_cols,
                  c_single_column, convert_t, curr_n, d_column);
        (*ENDIF*) 
        IF  overflow_allow
        THEN
            WITH a_mblock, mb_qual^ DO
                IF  ( mb_st^ [mfirst_free - 1].etype = st_output )
                THEN
                    IF  ( mb_st^ [mfirst_free - 1].eop_out in
                        [ op_o_none, op_o_output ] )
                    THEN
                        mb_st^ [mfirst_free - 1].eop_out := op_o_output_oflw
                    (*ENDIF*) 
                (*ENDIF*) 
            (*ENDWITH*) 
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    col_index := succ(col_index)
    END
(*ENDWITH*) 
END;
 
&ifdef LONGREC
(*------------------------------*) 
 
PROCEDURE
      ak61my_special_column (
            VAR acv       : tak_all_command_glob;
            VAR dmli      : tak_dml_info;
            VAR col_index : integer);
 
VAR
      col_found     : boolean;
      is_corr_subq  : boolean;
      i             : integer;
      new_col_ptr   : tak00_colinfo_ptr;
 
BEGIN
WITH acv, dmli DO
    BEGIN
    a61_rel_old_table (acv, dmli, 1);
    d_column := a01_i_internal;
    col_found := a061exist_columnname (d_sparr.pbasep^.sbase,
          d_column, d_colbuf);
    IF  col_found
    THEN
        BEGIN
        is_corr_subq    := d_subquery AND (d_corr <> no_correlation);
        t01int4 (ak_sem, 'is_corr_subq', ord(is_corr_subq));
        t01int4 (ak_sem, 'd_use_order ', ord(d_use_order));
        IF  (a_returncode = 0) AND
            d_use_order                          AND
            NOT is_corr_subq
        THEN
            WITH d_order_cols DO
                BEGIN
                t01int4 (ak_sem, 'ocntord     ', ocntord);
                FOR i := 1 TO ocntord DO
                    BEGIN
                    t01int4 (ak_sem, 'i           ', i);
                    t01int4 (ak_sem, 'ofno        ', ofield[ i ].ofno);
                    IF  ofield[ i ].ofno > 0
                    THEN
                        ofield[ i ].ofno := succ(ofield[ i ].ofno);
                    (*ENDIF*) 
                    END;
                (*ENDFOR*) 
                END;
            (*ENDWITH*) 
        (*ENDIF*) 
        d_colbuf^.ccolpropset := d_colbuf^.ccolpropset - [ ctdropped ];
        ak61one_select_column (acv, dmli, d_colbuf^,
              new_col_ptr, 1, col_index);
        d_colbuf^.ccolpropset := d_colbuf^.ccolpropset + [ ctdropped ];
        END
    (*ENDIF*) 
    END
(*ENDWITH*) 
END;
 
&endif
&ifdef MAXCOLS
(*------------------------------*) 
 
PROCEDURE
      ak61many_special_columns (
            VAR acv       : tak_all_command_glob;
            VAR dmli      : tak_dml_info;
            VAR col_index : integer);
 
VAR
      i             : integer;
 
BEGIN
WITH acv, dmli DO
    BEGIN
    a61_rel_old_table (acv, dmli, 1);
    d_column := a01_i_internal;
    g17int4to_line (1, true, 3, 9, d_column);
    IF  a061exist_columnname (d_sparr.pbasep^.sbase,
        d_column, d_colbuf)
    THEN
        FOR i := 1 TO 490 DO
            ak61one_special_column (acv, dmli, col_index, i);
        (*ENDFOR*) 
    (*ENDIF*) 
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61one_special_column (
            VAR acv       : tak_all_command_glob;
            VAR dmli      : tak_dml_info;
            VAR col_index : integer;
            colno         : integer);
 
VAR
      col_found     : boolean;
      is_corr_subq  : boolean;
      i             : integer;
      new_col_ptr   : tak00_colinfo_ptr;
 
BEGIN
WITH acv, dmli DO
    BEGIN
    d_column := a01_i_internal;
    g17int4to_line (colno, true, 3, 9, d_column);
    col_found := a061exist_columnname (d_sparr.pbasep^.sbase,
          d_column, d_colbuf);
    IF  col_found
    THEN
        BEGIN
        is_corr_subq    := d_subquery AND (d_corr <> no_correlation);
        t01int4 (ak_sem, 'is_corr_subq', ord(is_corr_subq));
        t01int4 (ak_sem, 'd_use_order ', ord(d_use_order));
        IF  (a_returncode = 0) AND
            d_use_order                          AND
            NOT is_corr_subq
        THEN
            WITH d_order_cols DO
                BEGIN
                t01int4 (ak_sem, 'ocntord     ', ocntord);
                FOR i := 1 TO ocntord DO
                    BEGIN
                    t01int4 (ak_sem, 'i           ', i);
                    t01int4 (ak_sem, 'ofno        ', ofield[ i ].ofno);
                    IF  ofield[ i ].ofno > 0
                    THEN
                        ofield[ i ].ofno := succ(ofield[ i ].ofno);
                    (*ENDIF*) 
                    END;
                (*ENDFOR*) 
                END;
            (*ENDWITH*) 
        (*ENDIF*) 
        d_colbuf^.ccolpropset := d_colbuf^.ccolpropset - [ ctdropped ];
        ak61one_select_column (acv, dmli, d_colbuf^,
              new_col_ptr, 1, col_index);
        d_colbuf^.ccolpropset := d_colbuf^.ccolpropset + [ ctdropped ];
        END
    (*ENDIF*) 
    END
(*ENDWITH*) 
END;
 
&endif
(*------------------------------*) 
 
PROCEDURE
      a61_check_val_params (
            VAR acv  : tak_all_command_glob;
            VAR dmli : tak_dml_info;
            sel_node : integer;
            par_node : integer);
 
VAR
      double_col      : boolean;
      curr_col        : integer;
      curr_par        : integer;
      col_index       : integer;
      i               : integer;
      jumpstackentry  : integer;
      m_qual_desc     : integer;
      double_col_name : tsp00_KnlIdentifier;
 
BEGIN
IF  ( acv.a_returncode = 0 )
THEN
    BEGIN
&   ifdef TRACE
    t01int4 (ak_sem, 'sel_node    ', sel_node);
&   endif
    dmli.d_allowed         := may_more_tabs;
    dmli.d_wherepart       := false;
    dmli.d_having          := false;
    dmli.d_expand          := 0;
    acv.a_long_desc_pos   := 0;
    acv.a_output_data_pos := 1;
    acv.a_allow_functions := tf_no_func;
    col_index := 1;
    IF  ( acv.a_mblock.mb_qual^.mqual_pos = 0 )
    THEN
        acv.a_mblock.mb_qual^.mqual_pos := acv.a_mblock.mb_qual^.mfirst_free;
    (*ENDIF*) 
    acv.a_mblock.mb_qual^.mqual_cnt := succ( acv.a_mblock.mb_qual^.mqual_cnt );
    m_qual_desc    := acv.a_mblock.mb_qual^.mqual_cnt;
    jumpstackentry := acv.a_mblock.mb_qual^.mfirst_free;
    acv.a_mblock.mb_qual^.mfirst_free :=
          succ( acv.a_mblock.mb_qual^.mfirst_free );
    IF  ( NOT dmli.d_subquery )
    THEN
        WITH acv.a_ap_tree^[ par_node ] DO
            IF  ((n_proc = a60) AND (n_subproc = cak_x_single_select))
            THEN
                BEGIN
                dmli.d_cntpar := 1;
                curr_par := acv.a_ap_tree^[ par_node ].n_lo_level;
                dmli.d_parnum := acv.a_ap_tree^[ curr_par ].n_length;
                WHILE acv.a_ap_tree^[ curr_par ].n_sa_level <> 0 DO
                    BEGIN
                    curr_par := acv.a_ap_tree^[ curr_par ].n_sa_level;
                    dmli.d_cntpar := succ(dmli.d_cntpar)
                    END;
                (*ENDWHILE*) 
                (* PTS 1103681 E.Z. *)
                IF  (acv.a_precomp_info_byte >= csp1_p_mass_command) AND
                    (acv.a_return_segm^.sp1r_function_code >= csp1_masscmd_fc_offset) AND
                    (dmli.d_cntpar = acv.a_count_variab)
                THEN
                    BEGIN
                    acv.a_precomp_info_byte := acv.a_precomp_info_byte - csp1_p_mass_command;
                    acv.a_return_segm^.sp1r_function_code :=
                          acv.a_return_segm^.sp1r_function_code - csp1_masscmd_fc_offset
                    END;
                (*ENDIF*) 
                END
            ELSE
                BEGIN
                dmli.d_parnum := acv.a_count_variab + 1;
                dmli.d_cntpar := acv.a_count_variab + MAX_COL_PER_TAB_GG00;
&               ifdef LONGREC
                IF  NOT(acv.a_ap_tree^[ sel_node ].n_symb in
                    [ s_count, s_sum ])                          AND
                    (NOT dmli.d_view)                                 AND
                    (acv.a_recursive_state = rs_no_recursive_select) AND
                    (NOT dmli.d_group)                                AND
                    (acv.a_fromsel_n = 0)                            AND
                    (acv.a_union_cnt = 0)                            AND
                    (acv.a_max_intern_select = 0)                    AND
                    ((acv.a_ap_tree^[ acv.a_ap_tree^[0].n_lo_level ].n_proc <> a56) OR
                    ( acv.a_ap_tree^[ acv.a_ap_tree^[0].n_lo_level ].n_subproc
                    <> cak_x_insert_select))                     AND
                    NOT (acv.a_is_ddl = ddl_create_as_select)
                THEN
                    ak61my_special_column (acv, dmli, col_index);
&               endif
&               ifdef MAXCOLS
                (*ENDIF*) 
                IF  NOT(acv.a_ap_tree^[ sel_node ].n_symb in
                    [ s_count, s_sum ])                          AND
                    (NOT dmli.d_view)                                 AND
                    (acv.a_recursive_state = rs_no_recursive_select) AND
                    (NOT dmli.d_group)                                AND
                    (acv.a_fromsel_n = 0)                            AND
                    (acv.a_union_cnt = 0)                            AND
                    (acv.a_max_intern_select = 0)                    AND
                    ((acv.a_ap_tree^[ acv.a_ap_tree^[0].n_lo_level ].n_proc <> a56) OR
                    ( acv.a_ap_tree^[ acv.a_ap_tree^[0].n_lo_level ].n_subproc
                    <> cak_x_insert_select))                     AND
                    NOT (acv.a_is_ddl = ddl_create_as_select)
                THEN
                    ak61many_special_columns (acv, dmli, col_index);
&               endif
                (*ENDIF*) 
                END;
            (*ENDIF*) 
        (*ENDWITH*) 
    (*ENDIF*) 
    IF  acv.a_ap_tree^[ sel_node ].n_symb = s_count
    THEN
        acv.a_mblock.mb_type2 := mm_with_functions;
    (*ENDIF*) 
    curr_col := acv.a_ap_tree^[ sel_node ].n_lo_level;
    dmli.d_exprno := 0;
    dmli.d_refname := a01_il_b_identifier;
    REPEAT
&       IFDEF TRACE
        t01int4 (ak_sem, 'output_pos  ', acv.a_output_data_pos);
        t01int4 (ak_sem, 'd_cntpar    ', dmli.d_cntpar);
        t01int4 (ak_sem, 'curr_col    ', curr_col);
&       ENDIF
        ak61select_column_check( acv, dmli, curr_col, col_index );
        curr_col  := acv.a_ap_tree^[ curr_col ].n_sa_level
    UNTIL
        ((curr_col = 0) OR (dmli.d_cntpar <= 0) OR
        (acv.a_returncode <> 0));
    (*ENDREPEAT*) 
    (* PTS 1111576 E.Z. *)
    IF  (acv.a_returncode = 0)
    THEN
        IF  ((dmli.d_cntpar <= 0) AND (curr_col <> 0))
        THEN
            IF  (dmli.d_subquery OR NOT dmli.d_single) AND (NOT acv.a_from_select)
            THEN
                a07_b_put_error (acv, e_select_col_list_too_long,
                      acv.a_ap_tree^[ curr_col ].n_pos)
            ELSE
                WITH acv.a_transinf.tri_trans DO
                    trWarning_gg00 := trWarning_gg00 + [ warn0_exist,
                          warn3_output_not_into_columns ]
                (*ENDWITH*) 
            (*ENDIF*) 
        ELSE
            WITH acv.a_ap_tree^[ par_node ] DO
                IF  ((n_proc = a60) AND (n_subproc = cak_x_single_select) AND
                    (dmli.d_cntpar > 0))
                THEN
                    BEGIN
                    WITH acv.a_transinf.tri_trans DO
                        trWarning_gg00 := trWarning_gg00 + [ warn0_exist,
                              warn3_output_not_into_columns ];
                    (*ENDWITH*) 
                    IF  acv.a_ex_kind = only_parsing
                    THEN
                        FOR i := 0 TO dmli.d_cntpar - 1 DO
                            WITH dmli.d_sparr.pinfop^.sshortinfo.
                                 siinfo[ dmli.d_parnum + i ] DO
                                BEGIN (* superfluous out_parameter *)
                                sp1i_mode       := [ sp1ot_optional ];
                                sp1i_io_type    := sp1io_output;
                                sp1i_data_type  := dunknown;
                                sp1i_frac       := 0;
                                sp1i_length     := 1;
                                sp1i_in_out_len := 1;
                                sp1i_bufpos     := 1
                                END
                            (*ENDWITH*) 
                        (*ENDFOR*) 
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
            (*ENDWITH*) 
        (*ENDIF*) 
    (*ENDIF*) 
    IF  ((acv.a_mblock.mb_type2 = mm_with_functions) AND
        ( acv.a_union_cnt = 0) AND
        NOT dmli.d_view         AND
        NOT dmli.d_subquery)
    THEN
        ak61put_checknull_func (acv, dmli);
    (*ENDIF*) 
    IF  acv.a_mblock.mb_type2 = mm_with_functions
    THEN
        a61_put_last_func (acv);
    (*ENDIF*) 
    a61_set_jump( acv.a_mblock, jumpstackentry, st_jump_output );
    acv.a_mblock.mb_st^[ jumpstackentry ].epos :=
          acv.a_mblock.mb_st^[ jumpstackentry ].epos + m_qual_desc;
    double_col := false;
    double_col_name := a01_il_b_identifier;
    IF  (dmli.d_view                   OR
        (acv.a_recursive_state = rs_check_select_list)) AND
        dmli.d_view_col_list                             AND
        NOT dmli.d_subquery
    THEN
        BEGIN
        IF  dmli.d_view_col_node > 0
        THEN
            a07_b_put_error (acv, e_view_col_list_too_long,
                  acv.a_ap_tree^[dmli.d_view_col_node].n_pos);
        (*ENDIF*) 
        dmli.d_view_col_list := false
        END;
    (*ENDIF*) 
    IF  (NOT dmli.d_single AND NOT dmli.d_subquery) AND
        ( NOT dmli.d_first_union ) AND
        ((acv.a_intern_select_cnt = acv.a_max_intern_select)
        OR (acv.a_fromsel_n > 0)
        OR (acv.a_recursive_state = rs_first_select))
    THEN
        BEGIN
        a061sort (acv, dmli.d_esparr.pbasep^.sbase,
              dmli.d_exprno, double_col, double_col_name);
        IF  (dmli.d_pos_result = cak_extern_pos) OR
            (dmli.d_pos_result = cak_intern_pos)
        THEN
            acv.a_resname_addr[ dmli.d_pos_result ]^.sresname.resmaxlinkage := 1
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  double_col                 AND
        (* PTS 1115986 E.Z. *)
        NOT acv.a_intern_explain       AND
        (
        dmli.d_resname_found   OR
        (acv.a_fromsel_n > 0) OR
        (* PTS 1105363 E.Z. *)
        dmli.d_view
        )
    THEN
        a07_nb_put_error (acv, e_duplicate_columnname,
              acv.a_ap_tree^[ sel_node ].n_pos, double_col_name);
    (*ENDIF*) 
    IF  dmli.d_allowed = are_more_tabs
    THEN
        BEGIN
        IF  acv.a_ap_tree^[ sel_node ].n_symb <> s_sum
        THEN
            acv.a_ap_tree^[ sel_node ].n_symb := s_count;
        (*ENDIF*) 
        END
    ELSE
        IF  dmli.d_allowed = tabs_with_arith
        THEN
            acv.a_ap_tree^[ sel_node ].n_symb := s_sum;
        (*ENDIF*) 
    (*ENDIF*) 
    IF  acv.a_allow_functions = tf_no_func
    THEN
        acv.a_allow_functions := tf_unknown;
    (*ENDIF*) 
    END
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a61_format_change (
            VAR acv     : tak_all_command_glob;
            VAR dmli    : tak_dml_info;
            stackpos    : integer;
            cdatatyp    : tsp00_DataType;
            VAR datalen : tsp00_Int2);
 
VAR
      init_first_free : tsp00_Int4;
 
BEGIN
WITH acv, a_mblock, mb_qual^, dmli DO
    IF  (a_dt_format <> dtf_oracle_date) OR (cdatatyp <> dtimestamp)
    THEN
        BEGIN
        IF  stackpos <= mb_st_max
        THEN
            BEGIN
            acv.a_date_time_used := true;
            WITH mb_st^ [stackpos] DO
                BEGIN
                etype        := st_build_in_func;
                eop_build_in := op_b_format_change;
                eformat      := a_dt_format;
                edatatype    := cdatatyp;
                elanguage    := a_ak_language;
                CASE cdatatyp OF
                    ddate :
                        elength := mxsp_extdate + 1;
                    dtime :
                        elength := mxsp_exttime + 1;
                    dtimestamp :
                        BEGIN
                        elength := mxsp_exttimestamp + 1;
                        IF  a_dt_format = dtf_oracle_date
                        THEN
                            eformat := dtf_oracle_date
                        ELSE
                            IF  a_dt_format = dtf_ts_eur
                            THEN
                                eformat := a_dt_format
                            ELSE
                                (* PTS 1112472 E.Z. *)
                                IF  a_dt_format = dtf_iso
                                THEN
                                    eformat := a_dt_format
                                ELSE
                                    eformat := dtf_eur
                                (*ENDIF*) 
                            (*ENDIF*) 
                        (*ENDIF*) 
                        END
                    END;
                (*ENDCASE*) 
                datalen := elength - 1
                END;
            (*ENDWITH*) 
            mfirst_free := succ(mfirst_free);
            mqual_cnt   := succ(mqual_cnt);
            END
        (*ENDIF*) 
        END
    ELSE
        BEGIN (* Conversion to oracle date is done by TO_DATE build in *)
        IF  stackpos+2 <= mb_st_max
        THEN
            BEGIN
&           ifdef trace
            t01int4 (ak_sem, 'stackpos    ', stackpos);
            t01int4 (ak_sem, 'mfirst_free ', mfirst_free);
&           endif
            IF  stackpos <> mfirst_free
            THEN      (* stackpos isn't always at the end of the stack, *)
                BEGIN (* but the push procedure work only there...      *)
                init_first_free := mfirst_free;
                mfirst_free     := stackpos
                END
            ELSE
                init_first_free := 0;
            (*ENDIF*) 
            a641f_push_format   (acv, dmli); (* Push nls_date_format and *)
            a641l_push_language (acv, dmli); (* a_ak_language on stack.  *)
            a641string_set_operator (acv, op_b_to_char,
                  mxsp_exttimestamp+1, 0, chr (0), chr(0));
            IF  init_first_free > 0
            THEN
                mfirst_free := init_first_free+3;
            (*ENDIF*) 
            datalen := mxsp_exttimestamp
            END
        (*ENDIF*) 
        END
    (*ENDIF*) 
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61get_convert_type (
            sourcetyp     : tsp00_DataType;
            desttyp       : tsp00_DataType;
            VAR convert_t : tak_convert_type);
 
BEGIN
CASE sourcetyp OF
    dcha, ddate, dtime, dtimestamp:
        IF  desttyp = dunicode
        THEN
            convert_t := conv_ascii_to_unicode
        ELSE
            IF  desttyp in [ dfixed, dfloat, dvfloat ]
            THEN
                convert_t := conv_ascii_to_num;
            (*ENDIF*) 
        (*ENDIF*) 
    dunicode:
        IF  desttyp in [ dcha, ddate, dtime, dtimestamp ]
        THEN
            convert_t := conv_unicode_to_ascii
        ELSE
            IF  desttyp in [ dfixed, dfloat, dvfloat ]
            THEN
                convert_t := conv_unicode_to_num;
            (*ENDIF*) 
        (*ENDIF*) 
    dfixed, dfloat, dvfloat :
        IF  desttyp = dcha
        THEN
            convert_t := conv_num_to_ascii
        ELSE
            IF  desttyp = dunicode
            THEN
                convert_t := conv_num_to_unicode;
            (*ENDIF*) 
        (*ENDIF*) 
    OTHERWISE
        BEGIN
        END
    END
(*ENDCASE*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a61_is_group_field (
            VAR acv       : tak_all_command_glob;
            VAR dmli      : tak_dml_info;
            VAR fieldname : tsp00_KnlIdentifier;
            extcolno      : tsp00_Int2;
            is_expression : boolean;
            expression_n  : tsp00_Int2;
            errorpos      : integer);
 
VAR
      found      : boolean;
      i          : integer;
      err_pos    : integer;
      group_used : ak61_group;
 
BEGIN
&ifdef TRACE
t01int4 (ak_sem, 'is_expressio', ord(is_expression));
t01lidentifier (ak_sem, fieldname);
t01int4 (ak_sem, 'expression_n', expression_n);
&endif
WITH acv, dmli, d_group_cols DO
    BEGIN
    err_pos := errorpos;
    found   := false;
    IF  NOT is_expression
    THEN
        BEGIN
        i := 1;
        WHILE ((i <= ocntord) AND NOT found) DO
            BEGIN
&           ifdef TRACE
            t01int4 (ak_sem, 'acttabindex ', d_acttabindex);
            t01int4 (ak_sem, 'tabno       ', ofield[ i ].oftabno);
            t01lidentifier (ak_sem, ofield[ i ].ofname);
            t01bool (ak_sem, 'expression  ',
                  is_val_expression in ofield[ i ].ofasc);
&           endif
            found := (
                  ((d_acttabindex = ofield[ i ].oftabno) OR
                  (             0 = ofield[ i ].oftabno))
                  AND
                  (fieldname = ofield[ i ].ofname)
                  AND
                  NOT (is_val_expression in ofield[ i ].ofasc)
                  );
            IF  found
            THEN
                BEGIN
                ofield[ i ].oftabno := d_acttabindex;
                ofield[ i ].offill  := extcolno;
                END;
            (*ENDIF*) 
            i     := succ(i);
            END;
        (*ENDWHILE*) 
        END
    ELSE
        WITH a_ap_tree^[ expression_n ] DO
            IF  ((n_proc = no_proc) AND
                (n_symb in [s_null, s_true, s_false, s_rowno]))
            THEN
                found := true
            ELSE
                BEGIN
                FOR i := 0 TO ocntord DO
                    group_used [ i ] := false;
                (*ENDFOR*) 
                IF  ocntord = 0
                THEN
                    ak61_search_node (acv, dmli, group_used, 0, expression_n,
                          0, err_pos, found)
                ELSE
                    BEGIN
                    i := 1;
                    WHILE ((i <= ocntord) AND NOT found) DO
                        BEGIN
&                       ifdef TRACE
                        t01int4 (ak_sem, 'cntord      ', ocntord);
                        t01int4 (ak_sem, 'i           ', i);
                        t01int4 (ak_sem, 'return_code ', a_returncode);
&                       endif
                        ak61_search_node ( acv, dmli, group_used, ofield[ i ].ofnode,
                              expression_n, i, err_pos, found);
                        i := succ(i);
                        IF  (NOT found AND (i <= ocntord))
                        THEN
                            a_returncode := 0
                        (*ENDIF*) 
                        END;
                    (*ENDWHILE*) 
                    END;
                (*ENDIF*) 
                END;
            (*ENDIF*) 
        (*ENDWITH*) 
    (*ENDIF*) 
    IF  NOT found
    THEN
        a07_nb_put_error (acv, e_output_field_must_be_group,
              err_pos, fieldname);
    (*ENDIF*) 
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
FUNCTION
      ak61node_compare (
            VAR acv   : tak_all_command_glob;
            tree1_node : tsp00_Int2;
            tree2_node : tsp00_Int2): boolean;
 
VAR
      cmp_result : tsp00_LcompResult;
      result     : boolean;
 
BEGIN
WITH acv, a_ap_tree^[ tree1_node ] DO
    BEGIN
    IF  (n_proc = a_ap_tree^[ tree2_node].n_proc) AND
        (n_symb = a_ap_tree^[ tree2_node].n_symb)
    THEN
        BEGIN
        IF  n_symb in
            [ s_authid, s_tablename, s_columnname, s_unsigned_integer,
            s_string_literal, s_byte_string, s_fixed_point_literal,
            s_floating_point_literal, s_identifier,
            s_special_identifier, s_sequence,
            s_reference_name, s_hostfilename]
        THEN
            BEGIN
            s30cmp ( a_cmd_part^.sp1p_buf, n_pos, n_length,
                  a_cmd_part^.sp1p_buf,
                  a_ap_tree^[ tree2_node ].n_pos,
                  a_ap_tree^[ tree2_node ].n_length, cmp_result);
            result := cmp_result = l_equal;
            END
        ELSE
            result := true;
        (*ENDIF*) 
        END
    ELSE
        result := false;
    (*ENDIF*) 
    END;
(*ENDWITH*) 
ak61node_compare := result;
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61comp_part_tree (
            VAR acv   : tak_all_command_glob;
            tree1_node : tsp00_Int2;
            tree2_node : tsp00_Int2;
            join       : boolean;
            VAR equal  : boolean);
 
BEGIN
equal := true;
WITH acv DO
    IF  (tree1_node <> 0) AND (tree2_node <> 0)
    THEN
        IF   ak61node_compare ( acv, tree1_node, tree2_node)
        THEN
            BEGIN
            IF  (a_ap_tree^[ tree1_node ].n_sa_level <> 0) AND
                (a_ap_tree^[ tree2_node ].n_sa_level <> 0)
            THEN
                ak61comp_part_tree (acv,
                      a_ap_tree^[ tree1_node ].n_sa_level,
                      a_ap_tree^[ tree2_node ].n_sa_level, join, equal);
            (*ENDIF*) 
            IF  equal AND
                (a_ap_tree^[ tree1_node ].n_lo_level <> 0) AND
                (a_ap_tree^[ tree2_node ].n_lo_level <> 0)
            THEN
                ak61comp_part_tree (acv,
                      a_ap_tree^[ tree1_node ].n_lo_level,
                      a_ap_tree^[ tree2_node ].n_lo_level, join, equal);
            (*ENDIF*) 
            END
        ELSE
            WITH a_ap_tree^[ tree1_node ] DO
                IF  NOT((n_symb in [ s_authid, s_tablename,
                    s_columnname ]) AND
                    (a_ap_tree^[ tree2_node ].n_symb in
                    [ s_authid, s_tablename, s_columnname ]) AND
                    (n_symb <> a_ap_tree^ [ tree2_node ].n_symb)
                    AND NOT join)
                THEN
                    equal := false
                ELSE
                    CASE n_symb OF
                        s_authid:
                            IF  a_ap_tree^[ tree2_node ].n_symb = s_tablename
                            THEN
                                ak61comp_part_tree (acv, n_sa_level,
                                      tree2_node, join, equal)
                            ELSE
                                ak61comp_part_tree (acv,
                                      a_ap_tree^[ n_sa_level ].n_sa_level,
                                      tree2_node, join, equal);
                            (*ENDIF*) 
                        s_tablename:
                            IF  a_ap_tree^[ tree2_node ].n_symb = s_authid
                            THEN
                                ak61comp_part_tree (acv, tree1_node,
                                      a_ap_tree^[ tree2_node ].n_sa_level,
                                      join, equal)
                            ELSE
                                ak61comp_part_tree (acv, n_sa_level,
                                      tree2_node, join, equal);
                            (*ENDIF*) 
                        s_columnname:
                            IF  a_ap_tree^[ tree2_node ].n_symb = s_tablename
                            THEN
                                ak61comp_part_tree (acv, tree1_node,
                                      a_ap_tree^[ tree2_node ].n_sa_level,
                                      join, equal)
                            ELSE
                                ak61comp_part_tree (acv, tree1_node,
                                      a_ap_tree^[ a_ap_tree^[ tree2_node ].n_sa_level ].n_sa_level,
                                      join, equal);
                            (*ENDIF*) 
                        END;
                    (*ENDCASE*) 
                (*ENDIF*) 
            (*ENDWITH*) 
        (*ENDIF*) 
    (*ENDIF*) 
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61_search_node (
            VAR acv        : tak_all_command_glob;
            VAR dmli       : tak_dml_info;
            VAR group_used : ak61_group;
            search_n       : integer;
            tree_n         : integer;
            group_index    : integer;
            VAR errorpos   : integer;
            VAR found      : boolean);
 
VAR
      i         : integer;
      node      : integer;
      fieldname : tsp00_KnlIdentifier;
 
BEGIN
&ifdef TRACE
t01int4(ak_sem,'search_n    ',search_n);
t01int4(ak_sem,'tree_n      ',tree_n);
&endif
group_used [ group_index ] := true;
fieldname := a01_il_b_identifier;
WITH acv, dmli DO
    IF  ((search_n <> 0) OR (group_index = 0)) AND (tree_n <> 0)
    THEN
        BEGIN
        IF   a_ap_tree^ [ tree_n ].n_symb in
            [ s_sum, s_min, s_max, s_count, s_all_count, s_avg,
            s_stddev, s_variance, s_dis_sum, s_dis_count,
            s_dis_avg, s_dis_stddev, s_dis_variance ]
        THEN
            BEGIN
            IF  a_ap_tree^ [ tree_n ].n_sa_level <> 0
            THEN
                ak61_search_node ( acv, dmli, group_used, search_n,
                      a_ap_tree^ [ tree_n ].n_sa_level,
                      group_index, errorpos, found);
            (*ENDIF*) 
            found := a_returncode = 0;
            END
        ELSE
            BEGIN
            found := false;
            IF   (group_index <> 0) AND
                ak61node_compare ( acv, search_n, tree_n)
            THEN
                BEGIN
                ak61comp_part_tree ( acv,
                      a_ap_tree^ [ search_n ].n_lo_level,
                      a_ap_tree^ [ tree_n ].n_lo_level, NOT c_join,
                      found);
                IF  (a_ap_tree^ [ tree_n ].n_sa_level <> 0) AND
                    found
                THEN
                    ak61_search_node ( acv, dmli, group_used, search_n,
                          a_ap_tree^ [ tree_n ].n_sa_level,
                          group_index, errorpos, found);
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            IF  NOT found
            THEN
                BEGIN
                IF  a_ap_tree^ [ tree_n ].n_symb in
                    [ s_authid, s_tablename, s_columnname ]
                THEN
                    BEGIN
                    node := tree_n;
                    WITH a_ap_tree^[ tree_n ] DO
                        BEGIN
                        d_user  := a01_il_b_identifier;
                        d_vppos := n_pos;
                        d_n_pos := n_pos;
                        a06get_username (acv, tree_n, d_user);
                        END;
                    (*ENDWITH*) 
                    WITH a_ap_tree^[ tree_n ] DO
                        IF  n_symb = s_tablename
                        THEN
                            BEGIN
                            a05identifier_get (acv,
                                  tree_n, sizeof (d_table), d_table);
                            tree_n := n_sa_level;
                            END;
                        (*ENDIF*) 
                    (*ENDWITH*) 
                    a05identifier_get (acv,
                          tree_n, sizeof (d_column), d_column);
                    a61_search_table ( acv, dmli);
                    fieldname := d_column;
                    IF  a_returncode = 0
                    THEN
                        a61_is_group_field ( acv, dmli, fieldname,
                              d_colbuf^.cextcolno,
                              NOT c_is_expression, 0,
                              a_ap_tree^ [ tree_n ].n_pos);
                    (*ENDIF*) 
                    found := a_returncode = 0;
                    END
                ELSE
                    IF  (a_ap_tree^ [ tree_n ].n_symb in
                        [ s_unsigned_integer, s_string_literal,
                        s_byte_string, s_fixed_point_literal,
                        s_floating_point_literal,
                        s_parameter_name,
                        s_null (* PTS 1122892 E.Z. *)
                        ]) OR
                        (a_ap_tree^ [tree_n].n_proc = a63query_spec)
                    THEN
                        found := true;
                    (*ENDIF*) 
                (*ENDIF*) 
                IF  a_ap_tree^ [ tree_n ].n_symb in
                    [ s_mult, s_plus, s_minus, s_div, s_mod, s_divide,
                    s_concat ]
                THEN
                    BEGIN
                    ak61_search_node ( acv, dmli, group_used, search_n,
                          a_ap_tree^ [ tree_n ].n_lo_level,
                          group_index, errorpos, found);
&                   ifdef TRACE
                    t01int4 (ak_sem, 'found x     ', ord(found));
                    t01int4 (ak_sem, 'tree_n      ', tree_n);
                    t01int4 (ak_sem, 'und rechts ?',
                          a_ap_tree^ [ tree_n ].n_sa_level);
&                   endif
                    IF  found
                    THEN
                        BEGIN
                        node := a_ap_tree^ [ tree_n ].n_lo_level;
                        IF  a_ap_tree^[ node ].n_symb = s_authid
                        THEN
                            node := a_ap_tree^[ node ].n_sa_level;
                        (*ENDIF*) 
                        IF  a_ap_tree^[ node ].n_symb = s_tablename
                        THEN
                            node := a_ap_tree^[ node ].n_sa_level;
                        (*ENDIF*) 
                        node := a_ap_tree^[ node ].n_sa_level;
                        ak61_search_node ( acv, dmli, group_used, search_n, node,
                              group_index, errorpos, found);
                        END;
                    (* PTS 1117523 E.Z. *)
                    (*ENDIF*) 
                    IF  (a_ap_tree^ [ tree_n ].n_sa_level <> 0) AND found
                    THEN
                        ak61_search_node ( acv, dmli, group_used,
                              search_n, a_ap_tree^ [ tree_n ].n_sa_level,
                              group_index, errorpos, found);
                    (*ENDIF*) 
                    END
                ELSE
                    BEGIN
                    i := 1;
                    WHILE ((i <= d_group_cols.ocntord) AND NOT found) DO
                        BEGIN
                        IF  (i <> group_index) AND
                            NOT group_used [ i ] AND
                            (is_val_expression in d_group_cols.ofield[ i ].ofasc)
                        THEN
                            ak61_search_node ( acv, dmli, group_used,
                                  d_group_cols.ofield[ i ].ofnode,
                                  tree_n, i, errorpos, found);
                        (*ENDIF*) 
                        i := succ(i);
                        END;
                    (*ENDWHILE*) 
                    IF  NOT found
                    THEN
                        BEGIN
                        WITH a_ap_tree^ [ tree_n ] DO
                            BEGIN
                            IF  (n_lo_level <> 0)
                            THEN
                                ak61_search_node ( acv, dmli, group_used,
                                      search_n, n_lo_level,
                                      group_index, errorpos, found)
                                      (*ELSE
                                      found := true*)
                                      ;
                            (*ENDIF*) 
                            IF  (n_sa_level <> 0) AND found
                            THEN
                                ak61_search_node ( acv, dmli, group_used,
                                      search_n, n_sa_level,
                                      group_index, errorpos, found);
                            (*ENDIF*) 
                            END;
                        (*ENDWITH*) 
                        END;
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        IF  NOT found
        THEN
            errorpos := a_ap_tree^ [ tree_n ].n_pos;
        (*ENDIF*) 
        END;
    (*ENDIF*) 
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a61_is_orderfield (
            VAR acv       : tak_all_command_glob;
            VAR dmli      : tak_dml_info;
            VAR colinf    : tak00_columninfo;
            order_ptr     : tak00_ord_fields_ptr;
            single_column : boolean;
            e_convert_t   : tak_convert_type;
            curr_n        : tsp00_Int2;
            VAR col       : tsp00_KnlIdentifier);
 
CONST
      c_to_upper = true;
 
VAR
      do_more      : boolean;
      found        : boolean;
      equal        : boolean;
      types_ok     : boolean;
      change_type  : boolean;
      is_corr_subq : boolean;
      aux_d_join   : boolean;
      convert_t    : tak_convert_type;
      i            : integer;
      pos          : integer;
      startstack   : integer;
      col_index    : integer;
      store_jcnt   : tsp00_Int2;
      st_pos       : tsp00_Int2;
      start_st_pos : tsp00_Int2;
      dtype_n      : tsp00_Int2;
      hmqual_cnt   : tsp00_Int2;
      hmfirst_free : tsp00_Int2;
      out_len      : integer;
      max_map_len  : integer;
      dummy_buf    : tak_sysbufferaddress;
      out_entry    : tgg00_StackEntry;
      colin        : tak00_scolinf;
      expression   : tsp00_KnlIdentifier;
      this_is_ok   : boolean;
      this_len     : integer;
      is_expr_list : boolean;
 
BEGIN
WITH acv, dmli, order_ptr^, a_mblock, mb_qual^, colinf DO
    BEGIN
&   ifdef trace
    t01int4 (ak_sem, 'single_colum', ord (single_column));
    t01int4 (ak_sem, 'curr_n      ', curr_n);
    t01lidentifier (ak_sem, col);
    t01int4 (ak_sem, 'd_subquery  ', ord(d_subquery));
    t01int4 (ak_sem, 'd_corr      ', ord(d_corr    ));
    t01int4 (ak_sem, 'd_act_node  ', d_act_node);
    t01int4 (ak_sem, 'convert_type', ord(e_convert_t));
    t01int4 (ak_sem, 'cdatatyp    ', ord(cdatatyp));
    t01int4 (ak_sem, 'cdatalen    ', cdatalen);
    t01int4 (ak_sem, 'cinoutlen   ', cinoutlen);
&   endif
    is_corr_subq    := d_subquery AND (d_corr <> no_correlation);
    colin.sci_len   := cdatalen;
    colin.sci_iolen := cinoutlen;
    colin.sci_typ   := cdatatyp;
    pos          := 1;
    do_more      := true;
    found        := false;
    is_expr_list := false;
    IF  d_subquery AND (d_corr <> no_correlation) AND (d_act_node <> 0)
    THEN (* Is this a corelated subquery for an expression list? *)
        WITH a_ap_tree^[ d_act_node ] DO
            IF  n_sa_level <> 0
            THEN (* there must be at least two datatype nodes. *)
                WITH a_ap_tree^[ n_sa_level ] DO
                    is_expr_list := (n_sa_level <> 0) AND
                          (n_proc = no_proc) AND (n_symb = s_unknown);
                (*ENDWITH*) 
            (*ENDIF*) 
        (*ENDWITH*) 
    (*ENDIF*) 
    WHILE do_more DO
        WITH ofield[ pos ] DO
            BEGIN
&           ifdef trace
            t01lidentifier (ak_sem, ofname);
            t01int4 (ak_sem, 'ofno        ', ofno);
            t01int4 (ak_sem, 'ofstno      ', ofstno);
            IF  is_order_asc in ofasc
            THEN
                t01name (ak_sem, 'ASCENDING         ');
            (*ENDIF*) 
            IF  is_opt in ofasc
            THEN
                t01name (ak_sem, 'OPTIONAL          ');
            (*ENDIF*) 
            IF  is_possible_oflw_field in ofasc
            THEN
                t01name (ak_sem, 'POSSIBLE OVERFLOW ');
            (*ENDIF*) 
            IF  is_val_expression in ofasc
            THEN
                t01name (ak_sem, 'VALUE EXPRESSION  ');
            (*ENDIF*) 
            IF  is_not_definite in ofasc
            THEN
                t01name (ak_sem, 'MISSING DEFINITE  ');
            (* PTS 1112977 E.Z. *)
            (*ENDIF*) 
            IF  is_col_only_specified in ofasc
            THEN
                t01name (ak_sem, 'COL ONLY SPECIFIED');
            (*ENDIF*) 
            t01int4 (ak_sem, 'oftabno     ', oftabno);
            t01int4 (ak_sem, 'ofapos      ', ofapos);
            t01int4 (ak_sem, 'offno       ', offno);
            t01int4 (ak_sem, 'ofnode      ', ofnode);
&           endif
            IF  (curr_n <> 0) AND (is_val_expression in ofasc) AND
                NOT (is_nls_column in ofasc)
            THEN
                BEGIN
                equal := false;
                ak61comp_part_tree ( acv, curr_n, ofnode, d_join,
                      equal );
                IF  equal
                THEN
                    BEGIN
                    ofno   := d_outcolno;
                    ofname := d_column;
                    ofasc  := ofasc - [ is_val_expression ];
                    END;
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            this_is_ok := false;
            (* PTS 1112977 E.Z. *)
            (* a refname is used which is the same as a column name *)
            (* the columnname was found during a66_order_by.        *)
            (* But now the reference name wins                      *)
            IF  (d_refname = ofname)               AND
                (d_refname <> a01_il_b_identifier) AND
                (is_col_only_specified in ofasc)
            THEN
                IF  ofstno = 0
                THEN
                    (* PTS 1113255 E.Z. *)
                    IF  (d_union AND
                        (dmli.d_order_or_group_cols <> @dmli.d_group_cols))
                    THEN
                        BEGIN
                        ofasc  := ofasc - [ is_col_only_specified ];
                        ofname := a01_il_b_identifier;
                        ofno   := d_outcolno;
                        a_ap_tree^[ofnode].n_symb := s_fixed;
                        a_ap_tree^[ofnode].n_pos  := pred(d_outcolno);
                        END
                    ELSE
                        BEGIN
                        ofasc    := ofasc - [ is_opt, is_val_expression,
                              is_nls_column ];
                        oftabno  := d_acttabindex;
                        offno    := 0;
                        END
                    (*ENDIF*) 
                ELSE
                    a07_b_put_error (acv, e_missing_column_definite, ofapos);
                (*ENDIF*) 
            (*ENDIF*) 
            IF  (col = ofname)             AND
                (is_not_definite in ofasc) AND
                (d_acttabindex <> oftabno) AND
                (0 <> oftabno)
            THEN
                a07_b_put_error (acv, e_missing_column_definite, ofapos)
            ELSE
                (* PTS 1112977 E.Z. *)
                IF  (
                    ((
                    (* PTS 1113255 E.Z. *)
                    (
                    (col = ofname) AND
                    ( NOT d_union OR (dmli.d_order_or_group_cols = @dmli.d_group_cols))
                    )
                    OR
                    ((is_col_only_specified in ofasc) AND
                    ( d_refname = ofname)             AND
                    ( d_refname <> a01_il_b_identifier))
                    )
                    AND
                    ((d_acttabindex = oftabno) OR (0 = oftabno))
                    )
                    OR
                    (d_outcolno = ofno)
                    )
                THEN
                    IF  ((col = a01_i_rowno)
                        (* PTS 1104857 E.Z. *)
                        AND (a_sqlmode = sqlm_internal)
                        AND NOT d_subquery)
                    THEN
                        a07_b_put_error (acv, e_rowno_not_allowed, ofapos)
                    ELSE
                        IF  found
                        THEN
                            BEGIN
                            FOR i := pos + 1 TO ocntord DO
                                ofield[ i-1 ] := ofield[ i ];
                            (*ENDFOR*) 
                            pos     := pred(pos);
                            ocntord := pred(ocntord)
                            END
                        ELSE
                            IF  ofstno = 0
                            THEN
                                this_is_ok := true
                                      (* PTS 1112977 E.Z. *)
                            ELSE
                                IF  is_col_only_specified in ofasc
                                THEN
                                    (* PTS 1119114 E.Z. *)
                                    IF  (d_acttabindex <> oftabno) OR
                                        ((d_acttabindex = oftabno) AND (offno = 0))
                                    THEN
                                        a07_b_put_error (acv, e_missing_column_definite, ofapos);
                                    (*ENDIF*) 
                                (*ENDIF*) 
                            (*ENDIF*) 
                        (*ENDIF*) 
                    (*ENDIF*) 
                (*ENDIF*) 
            (*ENDIF*) 
            IF  this_is_ok
            THEN
                BEGIN
                expression := a01_i_expression;
                IF  (ofno > 0)                                 AND
                    (d_outcolno = ofno)                        AND
                    (col <> a01_i_rowno)                       AND
                    (d_refname = a01_il_b_identifier)          AND
                    NOT s30eq( col, expression, 1,
                    a01_l_expression)    AND
                    (ofname = a01_il_b_identifier)             AND
                    (d_colbuf <> NIL)                          AND
                    (offno = 0)                                AND
                    NOT d_union                                AND
                    NOT (a_recursive_state in [ rs_first_select, rs_recursive_select ])
                THEN
                    WITH d_colbuf^,
                         d_tabarr[ d_acttabindex ] DO
                        BEGIN
                        oftabno := d_acttabindex;
                        IF  ((ccolstack.etype <> st_func) OR
                            ((ccolstack.etype = st_func) AND
                            (ccolstack.eop = op_none)))
                        THEN
                            IF  (oview) AND (oisjoinview in ospecialname)
                            THEN
                                offno := cextcolno
                            ELSE
                                offno := creccolno
                            (*ENDIF*) 
                        ELSE
                            a07_nb_put_error (acv, e_invalid_view_column,
                                  pos, d_column);
                        (*ENDIF*) 
                        IF  ctopt in ccolpropset
                        THEN
                            ofasc := ofasc + [ is_opt ];
                        (*ENDIF*) 
                        ofname := d_column;
                        END;
                    (*ENDWITH*) 
                (*ENDIF*) 
                found  := true;
                i      := mfirst_free - 1;
                st_pos := i;
                start_st_pos := st_pos;
                IF  single_column
                THEN
                    mb_st^ [i].eop_out := op_o_output_hold;
                (*ENDIF*) 
                IF  ((single_column AND (i >= mb_st_max)) OR
                    ((NOT single_column) AND (i >= mb_st_max - 1)))
                THEN
                    a07_b_put_error (acv, e_too_many_mb_stackentries, -mb_st_max)
                ELSE
                    BEGIN
                    IF  is_not_definite in ofasc
                    THEN
                        oftabno := d_acttabindex;
                    (*ENDIF*) 
                    out_len := cinoutlen;
                    IF  NOT single_column
                    THEN
                        BEGIN
                        IF  ccolstack.etype = st_func
                        THEN
                            BEGIN
                            a61get_column_expression (acv, dmli, colinf, ofapos);
                            offno := -offno;
                            i := mfirst_free - 1
                            END
                        ELSE
                            IF  is_val_expression in ofasc
                            THEN
                                BEGIN
                                colin.sci_len      := 0;
                                colin.sci_iolen    := 0;
                                d_datatype         := dunknown;
                                d_colptr           := NIL;
                                d_first_tab        := 0;
                                d_pars_kind        := fp_val_all_without_l;
                                change_type        := d_change_date_time;
                                d_change_date_time := false;
                                store_jcnt         := d_joins.jrc_cnt;
                                d_joins.jrc_cnt    := 0;
                                aux_d_join         := d_join;
                                d_join             := false;
                                a65_val_expr (acv, dmli, colin, ofnode);
                                out_len            := colin.sci_iolen;
                                d_joins.jrc_cnt    := store_jcnt;
                                d_join             := aux_d_join;
                                oftabno            := d_acttabindex;
                                do_more            := false;
                                i                  := pred(mfirst_free);
                                d_change_date_time := change_type;
                                offno              := -offno;
                                END
                            ELSE
                                BEGIN
                                i                  := succ(i);
                                st_pos             := i;
                                start_st_pos       := i;
                                mqual_cnt          := succ(mqual_cnt);
                                mfirst_free        := succ(mfirst_free);
                                mb_st^ [i]     := ccolstack;
                                mb_st^ [i].ecol_tab [2] :=
                                      chr(d_tabarr[ d_acttabindex ].ocounttabs
                                      + ctabno);
                                END;
                            (*ENDIF*) 
                        (*ENDIF*) 
                        st_pos := i;
                        IF  (d_subquery) AND
                            NOT (d_view) AND
                            (NOT a_outer_join) AND
                            ( a_union_cnt = 0 ) AND
                            (cdatatyp in [ ddate, dtime, dtimestamp ]) AND
                            NOT a_insert_select
                        THEN
                            BEGIN
                            startstack := mfirst_free;
                            a65ch_format (acv, dmli, startstack, colin,
                                  dunknown, cdatatyp);
                            cinoutlen := colin.sci_len + 1;
                            ak61upd_dtype_node (acv, dmli, colinf, pos);
                            out_len   := cinoutlen;
                            i := pred(mfirst_free);
                            END;
                        (*ENDIF*) 
                        IF  e_convert_t <> conv_none
                        THEN
                            BEGIN
                            hmfirst_free := mfirst_free;
                            a65_convert (acv, e_convert_t, cinoutlen);
                            i := i + mfirst_free - hmfirst_free;
                            END;
                        (*ENDIF*) 
                        END;
                    (*ENDIF*) 
                    IF  is_expr_list
                    THEN
                        BEGIN
                        dtype_n   := a_ap_tree^[ d_act_node ].n_sa_level;
                        col_index := pos;
                        WHILE (col_index > 1) AND
                              (a_ap_tree^[ dtype_n ].n_sa_level <> 0) DO
                            BEGIN (* go to 'pos'th dtype node. *)
                            dtype_n   := a_ap_tree^[ dtype_n ].n_sa_level;
                            col_index := pred (col_index)
                            END;
                        (*ENDWHILE*) 
                        this_len := a_ap_tree^[ dtype_n ].n_length;
&                       ifdef trace
                        t01int4 (ak_sem, 'this_len    ', this_len);
&                       endif
                        IF  this_len > 0
                        THEN
                            BEGIN
                            IF  single_column
                            THEN      (* A single column was pushed on the  *)
                                BEGIN (* stack and the last entry is an OUT.*)
                                (* We must operate the expand entry before  *)
                                (* the out, since everyone expect the out   *)
                                (* entry on top of stack.                   *)
                                out_entry   := mb_st^ [i];
                                i           := pred (i);
                                mqual_cnt   := pred (mqual_cnt);
                                mfirst_free := pred (mfirst_free)
                                END;
                            (*ENDIF*) 
                            hmqual_cnt := mqual_cnt;
                            types_ok := a65_datatypes_ok (acv, dmli,
                                  a_ap_tree^[ dtype_n ].n_datatype,
                                  a_ap_tree^[ dtype_n ].n_length,
                                  cdatatyp, c_is_subquery, ofnode,
                                  a_ap_tree^[ ofnode ].n_pos,
                                  c_convert, convert_t);
                            IF  convert_t <> conv_none
                            THEN
                                BEGIN
                                CASE convert_t OF
                                    conv_unicode_to_ascii :
                                        d_datatype := dcha;
                                    conv_ascii_to_unicode :
                                        d_datatype := dunicode;
                                    OTHERWISE
                                        BEGIN
                                        END
                                    END;
                                (*ENDCASE*) 
                                IF  d_datatype = dunicode
                                THEN
                                    colin.sci_iolen := (2*colin.sci_len)+1
                                ELSE
                                    colin.sci_iolen := colin.sci_len+1;
                                (*ENDIF*) 
                                colin.sci_typ := d_datatype;
                                END;
                            (* Expand operand to width of corresp. value. *)
                            (*ENDIF*) 
                            a641string_set_operator (acv, op_b_expand,
                                  this_len, out_len, chr(1), chr(0));
                            out_len := this_len;
                            i := i + mqual_cnt - hmqual_cnt;
                            IF  single_column
                            THEN      (* A single column is on top of stack *)
                                BEGIN (* so push the OUT HOLD on that one.  *)
                                i             := succ (i);
                                mb_st^ [i]    := out_entry;
                                mqual_cnt     := succ (mqual_cnt);
                                mfirst_free   := succ (mfirst_free);
                                (* PTS 1107400 E.Z. *)
                                d_inoutpos := d_inoutpos - mb_st^ [i].elen_var + out_len;
                                mb_st^ [i].elen_var := out_len
                                END
                            (*ENDIF*) 
                            END
                        (*ENDIF*) 
                        END
                    ELSE
                        IF  cdatatyp = dunicode
                        THEN
                            BEGIN
                            IF  a_max_codewidth > 2
                            THEN
                                BEGIN
                                (* out_len has external length,     *)
                                (* in case of euc it will be longer *)
                                (* than internal length needed now  *)
                                out_len := (out_len-1) DIV a_max_codewidth;
                                out_len := out_len * 2 + 1;
                                END;
&                           ifdef TRACE
                            (*ENDIF*) 
                            t01int4 (ak_sem, 'out_len 3   ', out_len);
&                           endif
                            END;
                        (*ENDIF*) 
                    (*ENDIF*) 
                    IF  NOT (a_nls_params.nls_binary) AND
                        (colin.sci_typ = dcha) AND
                        NOT d_subquery         AND
                        NOT is_corr_subq
                    THEN
                        BEGIN (* order by with nls support *)
                        a641get_mapcharset (acv, a_nls_params.nls_sort,
                              1, max_map_len, dummy_buf);
                        hmqual_cnt := mqual_cnt;
                        IF  max_map_len = 2
                        THEN
                            IF  colin.sci_len <= 10
                            THEN
                                colin.sci_len := colin.sci_len * 2
                            ELSE
                                colin.sci_len := colin.sci_len + 10;
                            (*ENDIF*) 
                        (*ENDIF*) 
                        out_len := colin.sci_len + 1;
                        a641add_mapchar (acv,
                              dmli, colin, a_nls_params.nls_sort,
                              1, colin.sci_len);
                        mb_st^[i+1].ecol_tab[1] := chr (c_to_upper);
                        i      := i + mqual_cnt - hmqual_cnt;
                        st_pos := i
                        END;
                    (*ENDIF*) 
                    i           := succ(i);
                    mqual_cnt   := succ(mqual_cnt);
                    mfirst_free := succ(mfirst_free);
                    WITH mb_st^ [i] DO
                        BEGIN
                        etype := st_output;
                        IF  is_order_asc in ofasc
                        THEN
                            IF  d_subquery
                            THEN
                                eop_out := op_o_output_no_oflw
                            ELSE
                                eop_out := op_o_output
                            (*ENDIF*) 
                        ELSE
                            eop_out := op_o_output_order;
                        (*ENDIF*) 
                        epos     := 0;
&                       ifdef trace
                        t01int4 (ak_sem, 'curr_stack_i', i);
                        t01int4 (ak_sem, 'out_len     ', out_len);
&                       endif
                        IF  single_column AND
                            NOT is_expr_list AND
                            (cdatatyp = dcha) AND
                            (succ(colin.sci_len * 2) = out_len) (* unicode-output *)
                        THEN
                            elen_var := succ(colin.sci_len)
                        ELSE
                            elen_var := out_len;
                        (*ENDIF*) 
                        IF  (d_union OR
                            (a_recursive_state in [ rs_first_select, rs_recursive_select ]))
                        THEN
                            ak61_upd_union_column (acv, st_pos, elen_var);
                        (*ENDIF*) 
                        cinoutlen := out_len;
                        ecol_pos  := 0;
                        ofstno    := i;
                        IF  (a_ap_tree^[ a_ap_tree^[ 0 ].n_lo_level ].n_proc
                            in [ a63, a62, a16 ])
                            AND
                            ( d_tabarr[ d_acttabindex ].oview OR
                            (oresfile in d_tabarr[ d_acttabindex ].ospecialname)) AND
                            NOT (d_subquery OR a_from_select)
                        THEN
                            ofasc := ofasc + [ is_possible_oflw_field ]
                        (*ENDIF*) 
                        END
                    (*ENDWITH*) 
                    END;
                (*ENDIF*) 
                IF  (offno > 0) AND
                    (
                    (start_st_pos + 1 <> ofstno)
                    (* there are stackentries between          *)
                    (* the column- and the output-stackentries *)
                    OR
                    ((mb_st^ [ start_st_pos   ].etype = st_output) AND
                    ( mb_st^ [ start_st_pos-1 ].etype > st_filler4))
                    OR
                    ((mb_st^ [ start_st_pos ].etype > st_filler4) AND
                    ( mb_st^ [ start_st_pos ].etype <> st_output))
                    (* no column-stackentry, no output-hold *)
                    )
                THEN
                    offno := -offno (* used column but with internal expressions *);
                (*ENDIF*) 
                END;
&           ifdef trace
            (*ENDIF*) 
            t01int4 (ak_sem, 'end offno   ',offno);
&           endif
            pos := succ(pos);
            IF  pos > ocntord
            THEN
                do_more := false;
            (*ENDIF*) 
            END;
        (*ENDWITH*) 
    (*ENDWHILE*) 
&   ifdef TRACE
    t01messblock (ak_sem, 'is_orderfiel', a_mblock);
&   endif
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a61_new_expr_no (
            VAR colinf : tak00_columninfo;
            VAR exprno : tsp00_Int2);
 
VAR
      chardiff        : integer;
      len             : integer;
 
BEGIN
WITH colinf DO
    BEGIN
    ccolumnn := a01_i_expression;
    IF  g01unicode
    THEN
        chardiff := 2
    ELSE
        chardiff := 1;
    (*ENDIF*) 
    len := a01_l_expression * chardiff;
    ccolpropset :=  ccolpropset + [ ctexpression ];
    exprno := succ(exprno);
    IF  exprno > 99
    THEN
        BEGIN
        ccolumnn[ len+  chardiff ] := chr(exprno DIV 100 + ord('0'));
        ccolumnn[ len+2*chardiff ] := chr((exprno MOD 100) DIV 10 + ord('0'));
        ccolumnn[ len+3*chardiff ] := chr(exprno MOD 10 + ord('0'))
        END
    ELSE
        IF  exprno > 9
        THEN
            BEGIN
            ccolumnn[ len+  chardiff ] := chr(exprno DIV 10 + ord('0'));
            ccolumnn[ len+2*chardiff ] := chr(exprno MOD 10 + ord('0'))
            END
        ELSE
            ccolumnn[ len+chardiff ] := chr(exprno + ord('0'));
        (*ENDIF*) 
    (*ENDIF*) 
    a061eval_colname_len (colinf)
    END
(*ENDWITH*) 
END;
 
(* PTS 1111575 E.Z. *)
(*------------------------------*) 
 
PROCEDURE
      a61_p_long_info (
            VAR acv    : tak_all_command_glob;
            VAR dmli   : tak_dml_info;
            VAR colinf : tak00_columninfo);
 
VAR
      error       : tsp8_uni_error;
      namelen     : integer;
      buf_pos     : integer;
      length      : tsp00_Int4;
      err_char_no : tsp00_Int4;
      name_ptr    : tsp00_KnlIdentifierPtr;
      name        : tsp00_KnlIdentifier;
      aux         : tsp00_C256;
 
BEGIN
WITH acv, dmli, d_sparr, pcolnamep^.scolnames DO
    BEGIN
    a61columnnames (acv, d_sparr, d_refname, colinf);
    IF  a_returncode = 0
    THEN
        IF  a_ex_kind = only_parsing
        THEN
            IF  d_single
                (* PTS 1112770 E.Z. *)
                OR
                (* a73 for 'where pos of <restablename> *)
                (a_ap_tree^[a_ap_tree^[0].n_lo_level].n_proc in [a62, a73])
            THEN
                a61_p_short_info (acv, d_sparr, colinf, d_parnum,
                      d_inoutpos - cgg_rec_key_offset - d_keylen)
            ELSE
                a61_p_short_info (acv, d_sparr, colinf,
                      a_count_variab+cncount,
                      d_inoutpos - cgg_rec_key_offset - d_keylen)
            (*ENDIF*) 
        ELSE
            a61_p_short_info (acv, d_sparr, colinf, cncount,
                  d_inoutpos - cgg_rec_key_offset - d_keylen);
        (*ENDIF*) 
    (*ENDIF*) 
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a61columnnames (
            VAR acv     : tak_all_command_glob;
            VAR sparr   : tak_syspointerarr;
            VAR refname : tsp00_KnlIdentifier;
            VAR colinf  : tak00_columninfo);
 
VAR
      error       : tsp8_uni_error;
      namelen     : integer;
      buf_pos     : integer;
      length      : tsp00_Int4;
      err_char_no : tsp00_Int4;
      name_ptr    : tsp00_KnlIdentifierPtr;
      name        : tsp00_KnlIdentifier;
      aux         : tsp00_C256;
 
BEGIN
WITH acv, sparr, pcolnamep^.scolnames DO
    IF  cncount >= MAX_COL_PER_TAB_GG00
    THEN
        a07_b_put_error (acv, e_select_col_list_too_long, 1)
    ELSE
        BEGIN
        IF  refname = a01_il_b_identifier
        THEN
            a061get_colname (colinf, name)
        ELSE
            name := refname;
        (*ENDIF*) 
        IF  g01unicode
        THEN
            BEGIN
            namelen := s30unilnr (@name, csp_unicode_blank,
                  1, sizeof(name));
            length := (namelen DIV 2) * a_max_codewidth;
            s80uni_trans (@name, namelen, csp_unicode, @aux, length,
                  a_out_packet^.sp1_header.sp1h_mess_code,
                  [ ], error, err_char_no);
            IF  error <> uni_ok
            THEN
                a07_hex_uni_error (acv, error, 1, NOT c_trans_to_uni,
                      @name [err_char_no], c_unicode_wid);
            (*ENDIF*) 
            namelen  := length;
            name_ptr := @aux
            END
        ELSE
            BEGIN
            namelen  := s30klen (name, bsp_c1, sizeof(name));
            name_ptr := @name;
            END;
        (*ENDIF*) 
        cnfullen := cnfullen + 1 + namelen;
        buf_pos  := cnlast^.b_sl - cak_sysbufferoffset -
              sizeof (cnlast^.scolnames.cnbit64fill) + 1;
        IF  cnlast^.b_sl + 1 + namelen > MAX_RECLEN_GG00
        THEN
            BEGIN
            a10new (acv, sizeof (tak_columnnamesrecord),
                  cnlast^.scolnames.cnnext);
            IF  cnlast^.scolnames.cnnext = NIL
            THEN
                a07_b_put_error (acv, e_no_more_memory, 1)
            ELSE
                BEGIN
                g10mv ('VAK61 ',   3,    
                      sizeof (cnlast^.scolnames),
                      sizeof (cnlast^.scolnames),
                      @cnlast^.scolnames, 1,
                      @cnlast^.scolnames.cnnext^.scolnames, 1,
                      cgg_rec_key_offset + cnlast^.b_kl,
                      a_returncode);
                a06inc_linkage (cnlast^.scolnames.cnnext^.
                      syskey.slinkage);
                IF  buf_pos <= sizeof (cnlast^.scolnames.cnbuf)
                THEN
                    BEGIN
                    cnlast^.scolnames.cnbuf[buf_pos] := chr(namelen);
                    length := sizeof (cnlast^.scolnames.cnbuf) - buf_pos;
                    g10mv ('VAK61 ',   4,    
                          sizeof(name), sizeof(cnlast^.scolnames.cnbuf),
                          @name_ptr^, 1, @cnlast^.scolnames.cnbuf,
                          buf_pos + 1, length,
                          a_returncode);
                    name_ptr     := @name_ptr^[length+1];
                    namelen      := namelen - length;
                    cnlast^.b_sl := MAX_RECLEN_GG00;
                    cnlast       := cnlast^.scolnames.cnnext;
                    buf_pos      := 0
                    END
                ELSE
                    BEGIN
                    cnlast  := cnlast^.scolnames.cnnext;
                    buf_pos := 1;
                    cnlast^.scolnames.cnbuf[buf_pos] := chr(namelen)
                    END;
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            END
        ELSE
            cnlast^.scolnames.cnbuf[buf_pos] := chr(namelen);
        (*ENDIF*) 
        g10mv ('VAK61 ',   5,    
              sizeof(name_ptr^), sizeof(cnbuf),
              @name_ptr^, 1, @cnlast^.scolnames.cnbuf, buf_pos + 1,
              namelen, a_returncode);
        cnlast^.b_sl := cgg_rec_key_offset + cnlast^.b_kl +
              sizeof (cnlast^.scolnames.cnbit64fill) +
              buf_pos + namelen;
&       ifdef trace
        t01buf (ak_sem, cnlast^, 1, cnlast^.b_sl);
&       endif
        cncount      := succ(cncount);
        END
    (*ENDIF*) 
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a61_p_short_info (
            VAR acv    : tak_all_command_glob;
            VAR sparr  : tak_syspointerarr;
            VAR colinf : tak00_columninfo;
            i          : integer;
            fix_bufpos : integer);
 
BEGIN
IF  i > cak_maxparams
THEN
    a07_b_put_error (acv, e_too_many_variables, 1)
ELSE
    WITH acv, colinf, sparr.pinfop^.sshortinfo, siinfo[ i ] DO
        BEGIN
        IF  i > sicount
        THEN
            sicount := i;
        (*ENDIF*) 
        IF  NOT (ctopt in ccolpropset)
        THEN
            sp1i_mode := [ sp1ot_mandatory ]
        ELSE
            sp1i_mode := [ sp1ot_optional ];
        (*ENDIF*) 
        sp1i_io_type := sp1io_output;
        IF  cdatatyp in [ dfloat, dvfloat ]
        THEN
            sp1i_frac := 0
        ELSE
            sp1i_frac := cdatafrac - cak_frac_offset;
        (*ENDIF*) 
        sp1i_length     := cdatalen;
        sp1i_in_out_len := cinoutlen;
        IF  fix_bufpos > 0
        THEN
            sp1i_bufpos := fix_bufpos
        ELSE
            WITH acv DO
                BEGIN
                sp1i_bufpos       := a_output_data_pos;
                a_output_data_pos := a_output_data_pos + cinoutlen;
                END;
            (*ENDWITH*) 
        (*ENDIF*) 
        CASE cdatatyp OF
            dfloat, dvfloat,
            dstra, dstrb, dstruni,
            drowid :
                sp1i_data_type := cdatatyp;
            ddate, dtime, dtimestamp :
                BEGIN
                sp1i_data_type := cdatatyp;
                IF  (sp1i_in_out_len > succ(sp1i_length)) AND
                    (a_out_packet^.sp1_header.sp1h_mess_code < csp_unicode_swap)
                THEN
                    BEGIN
                    sp1i_in_out_len := succ(sp1i_length);
                    sp1i_bufpos := sp1i_bufpos + sp1i_length;
                    END;
                (*ENDIF*) 
                END;
            dlonga :
                sp1i_data_type := dstra;
            dlongb :
                sp1i_data_type := dstrb;
            dlonguni :
                sp1i_data_type := dstruni;
            dboolean :
                IF  a_comp_type <> at_unknown
                THEN
                    sp1i_data_type := cdatatyp
                ELSE
                    sp1i_data_type := dchb;
                (*ENDIF*) 
            dfixed :
                IF  (cbinary AND (a_comp_type <> at_unknown))
                THEN
                    BEGIN
                    IF  cdatalen = 5
                    THEN
                        sp1i_data_type := dsmallint
                    ELSE
                        IF  cdatalen = 10
                        THEN
                            sp1i_data_type := dinteger
                        ELSE
                            sp1i_data_type := dfixed;
                        (*ENDIF*) 
                    (*ENDIF*) 
                    END
                ELSE
                    sp1i_data_type := dfixed;
                (*ENDIF*) 
            dcha :
                (* PTS 1121482 E.Z. *)
                BEGIN
                IF  (sp1i_in_out_len > succ(sp1i_length)) AND
                    (a_out_packet^.sp1_header.sp1h_mess_code < csp_unicode_swap)
                THEN
                    BEGIN
                    sp1i_in_out_len := succ(sp1i_length);
                    sp1i_bufpos := sp1i_bufpos + sp1i_length;
                    END;
                (*ENDIF*) 
                IF  ((cshiftoutchar = cgg04_truechar)
                    AND (a_comp_type <> at_unknown))
                THEN
                    sp1i_data_type := dvarchara
                ELSE
                    sp1i_data_type := dcha;
                (*ENDIF*) 
                END;
            dchb :
                IF  ((cshiftoutchar = cgg04_truechar)
                    AND (a_comp_type <> at_unknown))
                THEN
                    sp1i_data_type := dvarcharb
                ELSE
                    sp1i_data_type := dchb;
                (*ENDIF*) 
            dudt :
                sp1i_data_type := dchb;
            dunicode : (* PTS 1107651 *)
                IF  ((cshiftoutchar = cgg04_truechar)
                    AND (a_comp_type <> at_unknown))
                THEN
                    sp1i_data_type := dvarcharuni
                ELSE
                    sp1i_data_type := dunicode;
                (*ENDIF*) 
            OTHERWISE
                sp1i_data_type := dunknown
            END;
        (*ENDCASE*) 
        END
    (*ENDWITH*) 
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a61_put_last_func (VAR acv : tak_all_command_glob);
 
VAR
      j : integer;
 
BEGIN
WITH acv, a_mblock, mb_qual^ DO
    BEGIN
    IF  mfirst_free > mb_st_max
    THEN
        a07_b_put_error (acv, e_too_many_mb_stackentries, -mb_st_max)
    ELSE
        BEGIN
        mqual_cnt := succ(mqual_cnt);
        WITH mb_st^ [mfirst_free] DO
            BEGIN
            etype := st_func;
            eop := op_none;
            j := mfirst_free - 1;
            WHILE ((j > 1) AND (mb_st^ [j].etype <> st_func)) DO
                j := pred(j);
            (*ENDWHILE*) 
            epos := mfirst_free - j;
            elen_var := 0;
            ecol_tab[ 1 ] := chr(0);
            ecol_tab[ 2 ] := chr(0)
            END;
        (*ENDWITH*) 
        mfirst_free := succ(mfirst_free)
        END
    (*ENDIF*) 
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a61_rel_old_table (
            VAR acv  : tak_all_command_glob;
            VAR dmli : tak_dml_info;
            i        : integer);
 
VAR
      f_ok : boolean;
 
BEGIN
acv.a_long_desc_pos := 0;
WITH dmli, d_tabarr[ i ] DO
    IF  d_acttabindex <> i
    THEN
        BEGIN
        IF  d_acttabindex > 0
        THEN
            a10rel_sysinfo (d_sparr.pbasep);
        (*ENDIF*) 
        ;
        (* !!! changes within following command flow have to *)
        (*     take over in a684get_relation_info()      !!! *)
        IF  a661_is_fromsel_table (acv, otreeid)
        THEN
            BEGIN
            d_sparr.psynfound := false;
            d_sparr.pcount    := 0;
            a661_get_from_select_table (acv,
                  otreeid.fileTabId_gg00, d_sparr.pbasep, d_fix, c_all, f_ok);
            END
        ELSE
            IF  oresfile in ospecialname
            THEN
                BEGIN
                a663restable_get (acv, d_fix, otable, d_sparr, f_ok);
                END
            ELSE
                IF  oview
                THEN
                    a06_systable_get (acv, d_fix, ofromtableid,
                          d_sparr.pbasep, c_all, f_ok)
                ELSE
                    IF  ouser = a01_i_temp
                    THEN
                        a06_systable_get (acv, d_fix, ofromtableid,
                              d_sparr.pbasep, c_all, f_ok)
                    ELSE
                        IF  (otreeid.fileTfn_gg00 = tfnTemp_egg00) AND
                            (otreeid.fileTfnTemp_gg00 = ttfnGatewayResult_egg00)
                        THEN
                            BEGIN
                            d_sparr.psynfound := false;
                            a663get_result_records (acv, d_fix, otreeid.fileTempCnt_gg00,
                                  d_sparr.pbasep, f_ok)
                            END
                        ELSE
                            a06_systable_get (acv, d_fix,
                                  otreeid.fileTabId_gg00,
                                  d_sparr.pbasep, c_all, f_ok);
                        (*ENDIF*) 
                    (*ENDIF*) 
                (*ENDIF*) 
            (*ENDIF*) 
        (*ENDIF*) 
        IF  NOT f_ok
        THEN
            BEGIN
            IF  oview
            THEN
                BEGIN
                a07_tb_put_error (acv, e_unknown_tablename, 1, ofromtableid);
                acv.a_error_tableid := ofromtableid;
                END
            ELSE
                BEGIN
                a07_tb_put_error (acv, e_unknown_tablename, 1,
                      otreeid.fileTabId_gg00);
                acv.a_error_tableid := otreeid.fileTabId_gg00
                END
            (*ENDIF*) 
            END
        ELSE
            d_acttabindex := i
        (*ENDIF*) 
        END
    (*ENDIF*) 
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
FUNCTION
      ak61maybe_cor_column (
            VAR acv  : tak_all_command_glob;
            VAR dmli : tak_dml_info) : boolean;
 
BEGIN
WITH acv, dmli DO
    IF  (d_subcount > 0)
        AND (d_corr = no_correlation)
    THEN
        BEGIN
        CASE a_precomp_info_byte OF
            csp1_p_mass_command :
                BEGIN
                IF  a_return_segm^.sp1r_function_code <>
                    csp1_mselect_into_fc
                THEN
                    a_precomp_info_byte := csp1_p_none;
                (*ENDIF*) 
                IF  a_ap_tree^[ a_ap_tree^[ 0 ].n_lo_level ].n_subproc = cak_x_mupdate
                THEN
                    a_ap_tree^[ a_ap_tree^[ 0 ].n_lo_level ].n_subproc := cak_x_update
                ELSE
                    IF  a_ap_tree^[ a_ap_tree^[ 0 ].n_lo_level ].n_subproc = cak_x_mdelete
                    THEN
                        a_ap_tree^[ a_ap_tree^[ 0 ].n_lo_level ].n_subproc := cak_x_delete
                    (*ENDIF*) 
                (*ENDIF*) 
                END;
            csp1_p_mselect_found :
                a_precomp_info_byte := csp1_p_mass_select_found;
            csp1_p_for_upd_mselect_found :
                a_precomp_info_byte := csp1_p_select_for_update_found;
            csp1_p_reuse_mselect_found :
                a_precomp_info_byte := csp1_p_reuse_mass_select_found;
            csp1_p_reuse_upd_mselect_found :
                a_precomp_info_byte := csp1_p_reuse_update_sel_found;
            OTHERWISE
                BEGIN
                END
            END;
        (*ENDCASE*) 
        a07_b_put_error (acv, e_corelated_subquery_not_allowe, d_vppos);
        ak61maybe_cor_column := true;
        END
    ELSE
        ak61maybe_cor_column := false;
    (*ENDIF*) 
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a61_search_table (
            VAR acv  : tak_all_command_glob;
            VAR dmli : tak_dml_info);
 
VAR
      all_ok        : boolean;
      col_found     : boolean;
      colname_found : boolean;
      i             : integer;
      i_ok          : integer;
      tab_index     : integer;
      start         : integer;
      itab          : tgg00_Surrogate;
 
BEGIN
WITH acv, dmli DO
    BEGIN
    all_ok          := false;
    i               := d_acttabindex;
    i_ok            := 0;
    start           := d_acttabindex;
    a_long_desc_pos := 0;
    IF  (d_table <> a01_il_b_identifier) AND
        (a_returncode = 0)
    THEN
        BEGIN
        REPEAT
&           IFDEF TRACE
            WITH d_tabarr[ i ] DO
                BEGIN
                t01lidentifier (ak_sem, d_user);
                t01lidentifier (ak_sem, ouser);
                t01lidentifier (ak_sem, a_curr_user_name);
                t01lidentifier (ak_sem, d_table);
                t01lidentifier (ak_sem, oreference);
                t01lidentifier (ak_sem, otable);
                t01int4       (ak_sem, 'i           ', i)
                END;
            (*ENDWITH*) 
&           ENDIF
            WITH d_tabarr[ i ] DO
                IF  ((d_table = oreference)
                    AND
                    ((d_user = a01_il_b_identifier) OR
                    (d_user = a_curr_user_name)))
                THEN
                    all_ok := true
                ELSE
                    IF  NOT (oisreference in ospecialname)
                    THEN
                        IF  ((d_table = otable)
                            AND
                            ((d_user = ouser)                   OR
                            ((d_user = a01_il_b_identifier)   AND
                            (ospecs_needed = ons_only_tablename))))
                        THEN
                            all_ok := true
                        ELSE
                            IF  ((d_table = otable)
                                AND
                                (d_user = a01_il_b_identifier)
                                AND
                                ((ouser = a_curr_user_name)     OR
                                ( ouser = a_acc_dbaname)        OR
                                ( ouser = g01glob.sysuser_name) OR
                                ( ouser = a01_i_public )))
                            THEN
                                IF  i_ok = 0
                                THEN
                                    i_ok := i
                                ELSE
                                    BEGIN
                                    a07_b_put_error (acv,
                                          e_missing_tablename_definite,
                                          d_vppos);
                                    i_ok := 0;
                                    start := (i MOD d_cntfromtab) + 1
                                    END;
                                (*ENDIF*) 
                            (*ENDIF*) 
                        (*ENDIF*) 
                    (*ENDIF*) 
                (*ENDIF*) 
            (*ENDWITH*) 
            IF  NOT all_ok
            THEN
                IF  i = d_cntfromtab
                THEN
                    i := 1
                ELSE
                    i := succ(i);
                (*ENDIF*) 
            (*ENDIF*) 
        UNTIL
            (all_ok OR (i = start) OR (a_returncode <> 0));
        (*ENDREPEAT*) 
        IF  NOT all_ok
        THEN
            IF  i_ok <> 0
            THEN
                a61_rel_old_table (acv, dmli, i_ok)
            ELSE
                BEGIN
                IF  NOT ak61maybe_cor_column (acv, dmli)
                THEN
                    a07_b_put_error (acv,
                          e_table_not_in_from_list, d_vppos);
                (*ENDIF*) 
                END
            (*ENDIF*) 
        ELSE
            IF  i <> start
            THEN
                a61_rel_old_table (acv, dmli, i)
            (*ENDIF*) 
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    all_ok := false;
    IF  d_table <> a01_il_b_identifier
    THEN
        (* only 1 table has to be inspected *)
        IF  d_acttabindex = d_cntfromtab
        THEN
            start := 1
        ELSE
            start := succ(d_acttabindex)
                  (* PTS 1107348 E.Z. *)
        (*ENDIF*) 
    ELSE
        IF  d_column = a01_il_b_identifier
        THEN
            a07_b_put_error (acv, e_unknown_columnname, d_vppos);
        (*ENDIF*) 
    (*ENDIF*) 
    d_basetabno := 1;
    i := dmli.d_acttabindex;
    IF  (d_column <> a01_il_b_identifier) AND
        (a_returncode = 0)
    THEN
        BEGIN
        colname_found := false;
        REPEAT
            col_found := a061exist_columnname (d_sparr.pbasep^.sbase,
                  d_column, d_colbuf);
            IF  (NOT col_found) AND
                NOT (a_recursive_state in
                [ rs_no_recursive_select, rs_first_select]) AND
                (d_sparr.pbasep^.sbase.bentrytype = cak_eresult)
            THEN
                (* the recursive table is not and *)
                (* may not be sorted in alphabetically order *)
                col_found := ak61exist_columnname ( d_sparr.pbasep^.sbase,
                      d_column, d_colbuf);
            (*ENDIF*) 
            IF  col_found
            THEN
                BEGIN
                col_found := false;
                IF  NOT (ctinvisible in d_colbuf^.ccolpropset)
                THEN
                    IF  d_tabarr[ d_acttabindex ].oall_priv
                    THEN
                        col_found := true
                    ELSE
                        BEGIN
                        IF  d_colbuf^.cextcolno in
                            d_tabarr[d_acttabindex].osetallpriv
                        THEN
                            BEGIN
                            colname_found := true;
                            itab := d_sparr.pbasep^.syskey.stableid
                            END;
                        (*ENDIF*) 
                        IF  d_colbuf^.cextcolno in
                            d_tabarr[d_acttabindex].oprivset
                        THEN
                            col_found := true
                        (*ENDIF*) 
                        END
                    (*ENDIF*) 
                ELSE
                    IF  NOT colname_found
                    THEN
                        itab := d_sparr.pbasep^.syskey.stableid
                    (*ENDIF*) 
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            IF  col_found
            THEN
                IF  all_ok
                THEN
                    a07_nb_put_error (acv,
                          e_missing_column_definite,
                          d_vppos, d_column)
                ELSE
                    BEGIN
                    all_ok    := true;
                    tab_index := d_acttabindex
                    END;
                (*ENDIF*) 
            (*ENDIF*) 
            IF  a_returncode = 0
            THEN
                BEGIN
                IF  i = d_cntfromtab
                THEN
                    i := 1
                ELSE
                    i := succ(i);
                (*ENDIF*) 
                IF  i <> start
                THEN
                    a61_rel_old_table (acv, dmli, i)
                (*ENDIF*) 
                END;
            (*ENDIF*) 
        UNTIL
            (i = start) OR (a_returncode <> 0);
        (*ENDREPEAT*) 
        IF  NOT all_ok
        THEN
            BEGIN
            a_error_tableid := itab;
            (* PTS 1122898 E.Z. *)
            IF  (d_table <> a01_il_b_identifier)
            THEN
                a07_nb_put_error (acv, e_unknown_columnname,
                      d_vppos, d_column)
            ELSE
                IF  NOT ak61maybe_cor_column (acv, dmli)
                THEN
                    IF  colname_found
                    THEN
                        a07_nb_put_error (acv, e_missing_privilege,
                              d_vppos, d_column)
                    ELSE
                        a07_nb_put_error (acv, e_unknown_columnname,
                              d_vppos, d_column)
                    (*ENDIF*) 
                (*ENDIF*) 
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        IF  a_returncode = 0
        THEN
            a61_rel_old_table (acv, dmli, tab_index);
        (*ENDIF*) 
        IF  a_returncode = 0
        THEN
            BEGIN
            col_found := a061exist_columnname (d_sparr.pbasep^.sbase,
                  d_column, d_colbuf);
            IF  (NOT col_found) AND
                (a_recursive_state = rs_check_select_list) AND
                (d_sparr.pbasep^.sbase.bentrytype = cak_eresult)
            THEN
                (* the recursive table is not and *)
                (* may not be sorted in alphabetically order *)
                col_found := ak61exist_columnname ( d_sparr.pbasep^.sbase,
                      d_column, d_colbuf);
            (*ENDIF*) 
            IF  col_found
            THEN
                BEGIN
                WITH d_colbuf^ DO
                    IF  (cdatatyp in [dlonga, dlongb,
                        dlonguni, dstruni, dstra, dstrb])
                        AND
                        NOT d_view
                        AND
                        (* PTS 1123715 E.Z. *)
                        NOT d_wherepart
                        AND
                        NOT d_having
                        AND
                        ((a_sqlmode = sqlm_ansi)                                OR
                        (* *** no subquery with exists *** *)
                        (d_subquery AND (d_rowno <> cgg04_at_least_one_record)) OR
                        (d_distinct <> no_distinct))
                    THEN
                        a07_nb_put_error (acv,
                              e_command_for_string_not_allow,
                              d_vppos, d_column)
                    ELSE
                        BEGIN
&                       ifdef trace
                        t01int4(ak_sem, 'ctabno      ', ctabno);
                        t01int4(ak_sem, '[]ocounttabs',
                              dmli.d_tabarr[dmli.d_acttabindex].ocounttabs);
&                       endif
                        d_basetabno := ctabno +
                              d_tabarr[d_acttabindex].ocounttabs;
                        IF  ( ctabno = 0 )
                        THEN
                            (* constant expression *)
                            dmli.d_basetabno := succ(dmli.d_basetabno);
                        (*ENDIF*) 
                        END;
                    (*ENDIF*) 
                (*ENDWITH*) 
                END;
            (*ENDIF*) 
            END
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a61_set_jump (
            VAR mess_block : tgg00_MessBlock;
            stentrynr : integer;
            operator  : tgg00_StackEntryType);
 
BEGIN
WITH mess_block, mb_qual^, mb_st^ [stentrynr] DO
    BEGIN
    etype := operator;
    eop := op_none;
    epos := mqual_pos + mqual_cnt - stentrynr;
    elen_var := 0;
    ecol_tab[ 1 ] := chr(0);
    ecol_tab[ 2 ] := chr(0)
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a61_update_column (
            VAR acv        : tak_all_command_glob;
            VAR dmli       : tak_dml_info;
            VAR minkeylen  : integer;
            curr_n         : integer);
 
VAR
      double_col       : boolean;
      muse_order       : boolean;
      put_together     : boolean;
      together_allowed : boolean;
      md_changecollen  : char;
      convert_t        : tak_convert_type;
      dummy_len        : integer;
      fieldno          : integer;
      m_cntpar         : integer;
      md_colcount      : integer;
      md_outcolno      : integer;
      hcolinf          : tak00_columninfo;
      double_col_name  : tsp00_KnlIdentifier;
 
BEGIN
WITH dmli DO
    BEGIN
    md_outcolno := d_outcolno;
    md_colcount := d_change.cr_colcount;
    IF  md_colcount > 0
    THEN
        md_changecollen := d_change.cr_columns[ md_colcount ].ch_length
    ELSE
        md_changecollen := chr(0);
    (*ENDIF*) 
    m_cntpar    := d_cntpar;
    d_cntpar    := 0;
    double_col  := false;
&   ifdef trace
    t01int4 (ak_sem, 'd_cntpar:=0 ', d_cntpar);
&   endif
    muse_order  := d_use_order;
    d_use_order := false;
    fieldno     := 1;
    minkeylen   := 0;
    d_colbuf := d_sparr.pbasep^.sbase.bcolumn[
          d_sparr.pbasep^.sbase.bfirstcolind];
    WITH hcolinf, ccolstack DO
        BEGIN
        ccolumnn      := a01_il_b_identifier;
        ccolumnn[1]   := '@';
        ccolumnn[2]   := '@';
        ccolumnn[3]   := '@';
        ccolumnn[4]   := chr(1);
        ccolumnn_len  := chr(4);
        ccolpropset   := [ ctinvisible ];
        cextcolno     := 1;
        creccolno     := 1;
        ctabno        := 1;
        cdatatyp      := dchb;
        cdatalen      := 0;
        cinoutlen     := 0;
        cdatafrac     := 0;
        cnextind      := 0;
        cbinary       := false;
        etype         := st_fixkey;
        eop           := op_none;
        epos          := 1;
        elen_var      := 0;
        ecol_pos      := 0
        END;
    (*ENDWITH*) 
    convert_t := conv_none;
    together_allowed  := false;
    IF  d_sparr.pbasep^.sbase.bkeycolcount > 1
    THEN
        BEGIN
        WHILE (fieldno < d_sparr.pbasep^.sbase.bkeycolcount) DO
            BEGIN
            WITH d_colbuf^ DO
                BEGIN
                hcolinf.cinoutlen :=  hcolinf.cinoutlen + cinoutlen;
                IF  cnextind > 0
                THEN
                    d_colbuf := d_sparr.pbasep^.sbase.bcolumn[cnextind]
                (*ENDIF*) 
                END;
            (*ENDWITH*) 
            fieldno := succ(fieldno)
            END;
        (*ENDWHILE*) 
        hcolinf.cdatalen :=  hcolinf.cinoutlen - 1;
        hcolinf.ccolstack.elen_var :=  hcolinf.cinoutlen;
        a61_var_col_stackentry (acv, dmli, hcolinf, together_allowed, put_together,
              dummy_len, NOT c_is_corr_column, convert_t, dunknown);
        END;
    (*ENDIF*) 
    IF  acv.a_returncode = 0
    THEN
        BEGIN
        a061colinfo_to_var (d_colbuf^, hcolinf);
        WITH hcolinf DO
            BEGIN
            minkeylen    := ccolstack.epos;
            ccolumnn     := a01_il_b_identifier;
            ccolumnn[1]  := '@';
            ccolumnn[2]  := '@';
            ccolumnn[3]  := '@';
            ccolumnn[4]  := chr(2);
            ccolumnn_len := chr(4);
            ccolpropset  := [ ctinvisible ];
            END;
        (*ENDWITH*) 
        a61_var_col_stackentry (acv, dmli, hcolinf, together_allowed, put_together,
              dummy_len, NOT c_is_corr_column, convert_t, dunknown);
        END;
    (*ENDIF*) 
    d_cntpar        := m_cntpar;
&   ifdef trace
    t01int4 (ak_sem, 'd_cntpar:=mc', d_cntpar);
&   endif
    d_use_order     := muse_order;
    d_outcolno      := md_outcolno;
    d_change.cr_colcount := md_colcount;
    IF  md_colcount > 0
    THEN
        d_change.cr_columns[ md_colcount ].ch_length := md_changecollen;
    (*ENDIF*) 
    WITH acv.a_mblock, mb_qual^ DO
        mb_st^ [mqual_pos].epos := mqual_cnt + 1;
    (*ENDWITH*) 
    IF  (NOT d_single AND NOT d_subquery) AND
        (acv.a_intern_select_cnt = acv.a_max_intern_select)
        OR acv.a_from_select
    THEN
        BEGIN
        a061sort (acv, d_esparr.pbasep^.sbase,
              d_exprno, double_col, double_col_name);
        IF  ((d_pos_result > 0) AND (d_pos_result <= cak_maxresulttables))
        THEN
            acv.a_resname_addr[ d_pos_result ]^.sresname.resmaxlinkage := 1
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  (double_col AND (acv.a_fromsel_n > 0))
    THEN
        a07_nb_put_error (acv, e_duplicate_columnname,
              acv.a_ap_tree^[ curr_n ].n_pos, double_col_name);
    (* double_col will not come except for join-views *)
    (*ENDIF*) 
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61upd_dtype_node (
            VAR acv    : tak_all_command_glob;
            VAR dmli   : tak_dml_info;
            VAR colinf : tak00_columninfo;
            fieldno    : integer);
 
VAR
      dtype_n    : integer; (* Current datatype node. *)
      curr_index : integer; (* Index of dtype_n.      *)
 
BEGIN
IF  dmli.d_act_node <> 0
THEN
    WITH acv, dmli, colinf, a_ap_tree^[ d_act_node ] DO
        IF  (n_proc = a63query_spec) AND (n_sa_level <> 0)
        THEN      (* We must store the new length in n_length of    *)
            BEGIN (* the corresponding ('fieldno'th) datatype node. *)
            IF  fieldno = MAX_COL_PER_TAB_GG00
            THEN      (* We don't know the current position in node *)
                BEGIN (* list, so we set it to <list_length>, if we *)
                (*       have not a corelated subquery (we are just *)
                (*       constructing the list), otherwise to       *)
                (*       <list_length-dmli.d_cntpar>                *)
                dtype_n    := a_ap_tree^[ d_act_node ].n_sa_level;
                curr_index := 0;
                WHILE dtype_n <> 0 DO
                    BEGIN
                    dtype_n    := a_ap_tree^[ dtype_n ].n_sa_level;
                    curr_index := succ (curr_index)
                    END;
                (*ENDWHILE*) 
                IF  a_corr_select
                THEN
                    fieldno := curr_index - d_cntpar
                ELSE
                    fieldno := curr_index
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            dtype_n    := a_ap_tree^[ d_act_node ].n_sa_level;
            curr_index := 1;
            WHILE (a_ap_tree^[ dtype_n ].n_sa_level <> 0) AND
                  (curr_index < fieldno) DO
                BEGIN
                dtype_n    := a_ap_tree^[ dtype_n ].n_sa_level;
                curr_index := succ (curr_index)
                END;
            (*ENDWHILE*) 
            a_ap_tree^[ dtype_n ].n_length := cinoutlen;
&           ifdef trace
            t01int4 (ak_sem, 'fieldno     ', fieldno);
            t01int4 (ak_sem, 'd_cntpar    ', d_cntpar);
            t01int4 (ak_sem, 'changed_len ', cinoutlen);
            t01int4 (ak_sem, 'dtype_n     ', dtype_n);
&           endif
            END
        (*ENDIF*) 
    (*ENDWITH*) 
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a61_var_col_stackentry (
            VAR acv          : tak_all_command_glob;
            VAR dmli         : tak_dml_info;
            VAR colinf       : tak00_columninfo;
            may_be_together  : boolean;
            VAR put_together : boolean;
            VAR output_len   : integer;
            (* PTS 1001088 E.Z. *)
            is_corr_column   : boolean;
            convert_t        : tak_convert_type;
            convert_type     : tsp00_DataType);
 
VAR
      expr_col_found       : boolean;
      change_union_types   : boolean;
      long_column_found    : boolean;
      newlong_column_found : boolean;
      oflw_op              : tgg00_StackOpOutput;
      add                  : integer;
      codewidth            : integer;
      hmfirst_free         : integer;
      index                : integer;
      columnstackindex     : integer;  (* PTS 1116474 E.Z. *)
      i                    : tsp00_Int2;
      pred_node            : tsp00_Int2;
      ccolin               : tak00_scolinf;
      startstack           : integer;
      stst                 : integer;
      num_change_set       : tak_number_changetype_set;
 
BEGIN
WITH acv.a_mblock, mb_qual^, colinf DO
    IF  acv.a_returncode = 0
    THEN
        BEGIN
&       ifdef TRACE
        t01int4 (ak_sem, 'may_be_toget', ord(may_be_together));
&       endif
        put_together      := false;
        add               := 0;
        index             := mfirst_free - 1;
        expr_col_found    := false;
        (* PTS 1106508 E.Z. *)
        long_column_found :=
              (cdatatyp in [ dstra, dstrb, dstruni ]);
        newlong_column_found :=
              (cdatatyp in [ dlonga, dlongb, dlonguni ]);
        IF  index + 2 > mb_st_max
        THEN
            a07_b_put_error (acv, e_too_many_mb_stackentries, -mb_st_max)
        ELSE
            BEGIN
&           ifdef trace
            t01stackentry (ak_sem, ccolstack, 1);
&           endif
            num_change_set := [];
            (* PTS 1116474 E.Z. *)
            columnstackindex := 0;
            IF  (ccolstack.elen_var > 0) AND
                (ccolstack.etype <> st_func)
            THEN
                BEGIN
                columnstackindex := index + 1;
                mb_st^ [index + 1] := ccolstack;
                mb_st^ [index + 1].ecol_tab [2] :=
                      chr(dmli.d_tabarr[ dmli.d_acttabindex ].ocounttabs +
                      ctabno)
                END
            ELSE
                BEGIN
                IF  ccolstack.elen_var > 0
                THEN
                    BEGIN
                    a61get_column_expression (acv, dmli, colinf, dmli.d_vppos);
                    index := mfirst_free - 1;
                    IF  ((ccolstack.eop_func in [ op_f_sum, op_f_avg ])
                        AND
                        (mb_st^ [index].etype <> st_func))
                    THEN
                        dmli.d_allowed := tabs_with_arith;
                    (*ENDIF*) 
                    expr_col_found := true;
                    IF  cdatatyp in [ dfloat, dfixed, dvfloat ]
                    THEN
                        dmli.d_datatype := dnumber
                    ELSE
                        dmli.d_datatype := dunknown;
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
                IF  ((cdatatyp in [ dfloat, dfixed, dvfloat ])      AND
                    (mb_st^ [index].etype <> st_result)             AND
                    (mb_st^ [index].etype <> st_sum_length)         AND
                    (mb_st^ [index].eop <> op_fixed)                AND
                    ((mb_st^ [index].etype <> st_build_in_func) OR
                    (mb_st^ [index].eop_build_in <> op_b_decode))   AND
                    (mb_st^ [index].eop_build_in <> op_b_datetime)  AND
                    (mb_st^ [index].eop <> op_days)                 AND
                    ((mb_st^ [index].etype <> st_func) OR
                    (mb_st^ [index].eop_func in  [op_f_min, op_f_max])))
                THEN
                    IF  mb_st^ [index].etype = st_noround
                    THEN
                        WITH mb_st^ [index] DO
                            BEGIN
                            epos          := cdatalen;
                            elen_var      := cdatafrac - cak_frac_offset;
                            index := pred(index)
                            END
                        (*ENDWITH*) 
                    ELSE
                        WITH mb_st^ [index + 1] DO
                            BEGIN
                            etype         := st_result;
                            eop           := op_none;
                            epos          := cdatalen;
                            elen_var      := cdatafrac - cak_frac_offset;
                            ecol_tab[ 1 ] := chr(0);
                            ecol_tab[ 2 ] := chr(0)
                            END
                        (*ENDWITH*) 
                    (*ENDIF*) 
                ELSE
                    BEGIN
                    dmli.d_datatype := dunknown;
                    index      := pred(index)
                    END
                (*ENDIF*) 
                END;
            (*ENDIF*) 
&           IFDEF TRACE
            t01int4 (ak_sem, 'convert_type', ord(convert_type));
            t01int4 (ak_sem, 'convert_t   ', ord(convert_t));
            t01int4 (ak_sem, 'cdatatyp    ', ord(cdatatyp));
            t01int4 (ak_sem, 'd_datatype  ', ord(dmli.d_datatype));
            t01int4 (ak_sem, 'd_subquery  ', ord(dmli.d_subquery));
            t01int4 (ak_sem, 'd_use_sub   ', ord(dmli.d_use_sub));
            t01int4 (ak_sem, 'cdatalen    ', cdatalen);
            t01int4 (ak_sem, 'reclen      ', mb_data^.mbp_reclen);
            t01int4 (ak_sem, 'datalen     ', mb_data_len);
            t01int4 (ak_sem, 'd_inoutpos  ', dmli.d_inoutpos);
&           ENDIF
            IF  (cdatatyp in [ ddate, dtime, dtimestamp ]) AND
                dmli.d_subquery         AND
                (* PTS 1001088 E.Z. *)
                NOT is_corr_column AND
                NOT dmli.d_view         AND
                NOT acv.a_outer_join    AND
                (acv.a_union_cnt = 0)
                (* PTS 1123040 E.Z. *)
            THEN
                BEGIN
                pred_node := a660pos_pred (acv, acv.a_select_node);
                IF  (NOT acv.a_insert_select )
                    OR
                    (acv.a_insert_select               AND
                    (dmli.d_subcount <> 0)             AND      (* not the upper select *)
                    ((dmli.d_subcount DIV 100 <> 1) OR
                    ( acv.a_ap_tree^[pred_node].n_symb <> s_select)))
                THEN
                    BEGIN
                    startstack := index + 2;
                    stst       := startstack;
                    a65ch_format (acv, dmli, startstack , ccolin,
                          dunknown, cdatatyp);
                    expr_col_found := true;
                    cinoutlen      := succ (ccolin.sci_len);
                    ak61upd_dtype_node (acv, dmli, colinf, MAX_COL_PER_TAB_GG00);
                    IF  (startstack - stst) > 0
                    THEN
                        index := index + startstack - stst;
                    (*ENDIF*) 
                    END
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            IF  (dmli.d_union OR
                (acv.a_recursive_state in
                [ rs_first_select, rs_recursive_select ]))     AND
                NOT (cdatatyp in [ ddate, dtime, dtimestamp ]) AND
                (convert_type in [ ddate, dtime, dtimestamp ])
            THEN
                BEGIN
                IF  acv.a_dt_format <> dtf_normal
                THEN
                    BEGIN
                    index    := succ (index);
                    a61_format_change (acv, dmli, index + 1, convert_type, i);
                    (* PTS 1001092 E.Z. *)
                    IF  (acv.a_dt_format = dtf_oracle_date) AND
                        (convert_type = dtimestamp)
                    THEN
                        index := index + 2;
                    (*ENDIF*) 
                    END;
&               ifdef TRACE
                (*ENDIF*) 
                t01int4 (ak_sem, 'datalen     ', colinf.cdatalen);
                t01int4  (ak_sem, 'cinoutlen u!', colinf.cinoutlen);
&               endif
                convert_type   := cdatatyp;
                expr_col_found := true;
                END;
            (*ENDIF*) 
            IF  convert_t <> conv_none
            THEN
                BEGIN
                (* PTS 1113800 E.Z. new: codewidth *)
                IF  (dmli.d_view OR
                    (acv.a_intern_select_cnt < acv.a_max_intern_select))
                THEN
                    codewidth := 1
                ELSE
                    codewidth := acv.a_max_codewidth;
                (*ENDIF*) 
                WITH colinf DO
                    CASE convert_t OF
                        conv_ascii_to_unicode :
                            BEGIN
                            cdatatyp  := dunicode;
                            cinoutlen := (2*cdatalen) + 1
                            END;
                        conv_unicode_to_ascii :
                            BEGIN
                            cdatatyp := dcha;
                            cinoutlen := cdatalen * codewidth + 1
                            END;
                        (* PTS 1000985/1001162 E.Z. *)
                        conv_ascii_to_num,
                        conv_unicode_to_num :
                            BEGIN
                            cdatatyp := dfloat;
                            cdatalen := csp_fixed;
                            cdatafrac := csp_float_frac;
                            cinoutlen := succ(mxsp_number)
                            END;
                        conv_num_to_ascii,
                        conv_num_to_unicode :
                            BEGIN
                            IF  cdatatyp in [ dfloat, dvfloat ]
                            THEN
                                IF  (cdatalen = 1)
                                THEN
                                    cdatalen := 6
                                ELSE
                                    cdatalen := cdatalen + 6
                                (*ENDIF*) 
                            ELSE
                                IF  cdatatyp = dfixed
                                THEN
                                    IF  (cdatalen = cdatafrac)
                                    THEN
                                        cdatalen := cdatalen + 3
                                    ELSE
                                        IF  (cdatafrac <> 0)
                                        THEN
                                            cdatalen := cdatalen + 2
                                        ELSE
                                            cdatalen := succ (cdatalen);
                                        (*ENDIF*) 
                                    (*ENDIF*) 
                                (*ENDIF*) 
                            (*ENDIF*) 
                            IF  convert_t = conv_num_to_unicode
                            THEN
                                BEGIN
                                cdatatyp := dunicode;
                                cinoutlen := 2 * cdatalen + 1
                                END
                            ELSE
                                BEGIN
                                cinoutlen := succ(cdatalen);
                                cdatatyp := dcha
                                END
                            (*ENDIF*) 
                            END;
                        OTHERWISE
                            BEGIN
                            END
                        END;
                    (*ENDCASE*) 
                (*ENDWITH*) 
                IF  (acv.a_out_packet^.sp1_header.sp1h_mess_code in
                    [ csp_unicode_swap, csp_unicode ])
                    (* PTS 1113800 E.Z. *)
                    AND
                    NOT dmli.d_view
                    AND
                    (acv.a_intern_select_cnt = acv.a_max_intern_select)
                    AND
                    (acv.a_qualified_jv_upd = no_jv_upd)
                    AND
                    (cdatatyp = dcha)
                THEN
                    colinf.cinoutlen := succ(2*colinf.cdatalen);
                (*ENDIF*) 
                hmfirst_free := mfirst_free;
                mfirst_free  := index + 2;
                a65_convert (acv, convert_t, colinf.cinoutlen);
                mfirst_free := hmfirst_free + mfirst_free - index - 2;
                index       := index + mfirst_free - hmfirst_free;
                expr_col_found := true;
                END;
            (* ????
                  IF  convert_type = dunicode
                  THEN
                  BEGIN
                  hmfirst_free := mfirst_free;
                  mfirst_free  := index + 2;
                  a641string_set_operator (acv,
                  op_b_uni_trans, colinf.cinoutlen, 0,
                  chr(acv.a_out_packet^.sp1_header.sp1h_mess_code),
                  chr(csp_unicode));
                  mfirst_free := hmfirst_free + 1;
                  index       := succ(index);
                  expr_col_found := true;
                  END;
                  *)
&           ifdef TRACE
            (*ENDIF*) 
            t01messblock (ak_sem, 'var_col_st 1', acv.a_mblock);
            t01int4 (ak_sem, 'datalen     ', colinf.cdatalen);
            t01int4  (ak_sem, 'cinoutlen   ', colinf.cinoutlen);
            t01int4 (ak_sem, 'ecol_tab[1] ', ord(colinf.ccolstack.ecol_tab[ 1 ]));
&           endif
            IF  (long_column_found OR newlong_column_found) AND
                (* PTS 1106508 E.Z. *)
                NOT (dmli.d_view) AND
                (* PTS 1105795 M.Ki. *)
                NOT ((acv.a_ap_tree^[ acv.a_ap_tree^[ 0 ].n_lo_level ].n_subproc
                = cak_x_insert_select) AND dmli.d_pseudo_ins_select)    AND
                (dmli.d_sparr.pbasep^.sbase.btablekind <> tresult)      AND
                (NOT dmli.d_subquery)
            THEN
                IF  (acv.a_ap_tree^[ acv.a_ap_tree^[ 0 ].n_lo_level ].n_subproc
                    <> cak_x_insert_select) OR
                    dmli.d_pseudo_ins_select
                THEN
                    (* PTS 1116474 E.Z. *)
                    IF  dmli.d_sparr.pbasep^.sbase.btablekind = tcomplexview
                    THEN
                        BEGIN
                        colinf.cdatalen  := mxsp_long_desc;
                        colinf.cinoutlen := succ(colinf.cdatalen);
                        colinf.ccolstack.elen_var          := colinf.cinoutlen;
                        mb_st^ [columnstackindex].elen_var := colinf.cinoutlen;
                        END
                    ELSE
                        ak61long_desc_st_entries (acv, dmli, colinf, index)
                    (*ENDIF*) 
                ELSE (* PTS 1105795 M.Ki. *)
                    (* PTS 1116474 E.Z. *)
                    IF  dmli.d_sparr.pbasep^.sbase.btablekind = tcomplexview
                    THEN
                        BEGIN
                        colinf.cdatalen  := 2 * SURROGATE_MXGG00;
                        colinf.cinoutlen := succ(colinf.cdatalen);
                        colinf.ccolstack.elen_var          := colinf.cinoutlen;
                        mb_st^ [columnstackindex].elen_var := colinf.cinoutlen;
                        END
                    ELSE
                        BEGIN
                        IF  (ccolstack.elen_var = 0 (* value, no column *)
                            ) AND
                            (acv.a_ap_tree^[ acv.a_ap_tree^[ 0 ].n_lo_level ].n_subproc
                            = cak_x_insert_select)
                        THEN
                            BEGIN
                            a07_b_put_error (acv, e_command_for_string_not_allow, dmli.d_vppos);
                            mqual_cnt   := pred(mqual_cnt);
                            mfirst_free := pred(mfirst_free);
                            END
                        ELSE
                            ak61long_ins_sel_st_entries (acv, dmli, colinf, index);
                        (*ENDIF*) 
                        END;
                    (*ENDIF*) 
                (*ENDIF*) 
&           ifdef TRACE
            (*ENDIF*) 
            t01messblock (ak_sem, 'var_col_st 2', acv.a_mblock);
&           endif
            WITH mb_st^ [index + 2] DO
                BEGIN
                IF  ctcatalog in ccolpropset (* h.b. PTS 1105136 *)
                THEN
                    BEGIN
                    (* select catalog *)
                    etype := st_output_catalog;
                    eop   := op_none;
                    END
                ELSE
                    BEGIN
                    etype   := st_output;
                    (* PTS 1000985/1001162 E.Z. *)
                    WITH dmli.d_sparr.pbasep^.sbase DO
                        BEGIN
                        oflw_op    := op_o_none;
                        (* PTS 1111576 E.Z. *)
                        IF  btablekind in [ tonebase, tview, tresult,
                            tcomplexview  ]
                        THEN
                            IF  acv.a_ap_tree^[ acv.a_ap_tree^[ 0 ].n_lo_level ].
                                n_proc in [ a62, a63, a16 ]
                            THEN
                                oflw_op := op_o_output_oflw;
                            (*ENDIF*) 
                        (*ENDIF*) 
                        END;
                    (*ENDWITH*) 
                    eop_out := oflw_op;
                    END;
                (*ENDIF*) 
                epos  := dmli.d_inoutpos + add;
                IF  ((mb_st^ [index + 1].etype = st_func)
                    AND
                    ((mb_st^ [index + 1].eop_func = op_f_count) OR
                    (mb_st^ [index + 1].eop_func = op_f_dis_count))
                    AND
                    (NOT dmli.d_union OR dmli.d_first_union))
                THEN
                    elen_var := mb_st^ [index + 1].elen_var
                ELSE
                    elen_var := cinoutlen;
                (*ENDIF*) 
                ecol_pos := 0;
                IF  dmli.d_union AND (NOT dmli.d_first_union)
                THEN
                    change_union_types := (acv.a_union_cnt = 1)
                ELSE
                    change_union_types := false;
                (*ENDIF*) 
&               IFDEF TRACE
                t01int4 (ak_sem, 'a61_fill 2  ', ord(change_union_types));
                t01int4 (ak_sem, 'd_first_unio', ord(dmli.d_first_union));
                t01int4 (ak_sem, 'dm_union    ', ord(dmli.d_union));
                t01int4 (ak_sem, 'acv_unioncnt', acv.a_union_cnt);
&               ENDIF
                output_len := 0;
                IF  mb_st^ [index + 1].etype = st_func
                THEN
                    BEGIN
                    add := 0;
                    CASE  mb_st^ [index + 1].eop_func OF
                        op_f_min, op_f_max :
                            BEGIN
                            add := 0;
                            output_len := elen_var
                            END;
                        op_f_count, op_f_dis_count :
                            IF  elen_var >= mxsp_resnum
                            THEN
                                BEGIN
                                output_len := elen_var;
                                IF  ((acv.a_mblock.mb_type <> m_insert_select) AND
                                    (dmli.d_single AND (acv.a_ex_kind = only_parsing)))
                                THEN
                                    acv.a_output_data_pos := acv.a_output_data_pos +
                                          elen_var - mxsp_resnum;
                                (*ENDIF*) 
                                END
                            ELSE
                                BEGIN
                                add := mxsp_resnum - elen_var;
                                output_len := mxsp_resnum
                                END;
                            (*ENDIF*) 
                        op_f_sum, op_f_dis_sum :
                            BEGIN
                            END;
                        op_f_avg, op_f_dis_avg :
                            BEGIN
                            add := mxsp_resnum;
                            output_len := NUMBER_MXGG04+add;
                            IF  dmli.d_optimize_setfunction
                            THEN
                                num_change_set := num_change_set +
                                      [ nch_div_by_count ]
                            ELSE
                                mb_st^ [index + 1].ecol_tab[1] := chr(true);
                            (*ENDIF*) 
                            END;
                        op_f_stddev, op_f_dis_stddev,
                        op_f_variance, op_f_dis_variance  :
                            BEGIN
                            add := mxsp_resnum;
                            output_len := NUMBER_MXGG04+add;
                            END;
                        OTHERWISE
                            BEGIN
                            END;
                        END;
                    (*ENDCASE*) 
                    IF  ((acv.a_mblock.mb_type <> m_insert_select) AND
                        (dmli.d_single AND (acv.a_ex_kind = only_parsing)))
                    THEN
                        acv.a_output_data_pos := acv.a_output_data_pos + add;
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
                IF  (
                    (cdatatyp in [ ddate, dtime, dtimestamp, dunicode,
                    dlonga, dlongb, dlonguni,
                    dstra, dstrb, dstruni ])
                    OR
                    ((acv.a_out_packet^.sp1_header.sp1h_mess_code in
                    [ csp_unicode_swap, csp_unicode ]) AND
                    (cdatatyp in [ dcha, dvarchara ]))
                    OR
                    long_column_found
                    OR
                    newlong_column_found
                    OR
                    (num_change_set <> [])
                    )
                    AND NOT dmli.d_subquery
                    (* PTS 1103004 E.Z. *)
                    AND NOT acv.a_insert_select
                    AND ((acv.a_union_cnt = 0) OR change_union_types)
                    AND (acv.a_intern_select_cnt = acv.a_max_intern_select)
                THEN
                    ak61fill_change_info (acv, dmli, colinf, num_change_set);
                (*ENDIF*) 
                dmli.d_inoutpos := dmli.d_inoutpos + elen_var + add;
&               ifdef TRACE
                t01int4 (ak_sem, 'd_inoutpos 2', dmli.d_inoutpos);
                t01int4 (ak_sem, '     add    ',       add);
                t01int4 (ak_sem, 'cdatalen    ', cdatalen);
                t01int4 (ak_sem, 'output_len  ', output_len);
&               endif
                IF  (dmli.d_inoutpos > MAX_RECLEN_GG00+1) AND
                    (mb_st^ [index+2].etype <> st_output_catalog)
                THEN
                    a07_b_put_error (acv,
                          e_output_columns_too_long, dmli.d_vppos);
                (*ENDIF*) 
                IF  acv.a_returncode = 0
                THEN
                    BEGIN
                    (* PTS 1107681 E.Z. *)
&                   IFDEF TRACE
                    t01int4 (ak_sem, 'cdatatyp 61 ', ord (cdatatyp));
&                   ENDIF
                    ecol_pos := 0;
                    mfirst_free := index+3;
                    mqual_cnt   := mfirst_free - mqual_pos;
                    END;
                (*ENDIF*) 
                END
            (*ENDWITH*) 
            END;
        (*ENDIF*) 
&       ifdef TRACE
        t01int4 (ak_sem, 'put_together', ord(put_together));
&       endif
        END
    (*ENDIF*) 
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a61get_column_expression (
            VAR acv    : tak_all_command_glob;
            VAR dmli   : tak_dml_info;
            VAR colinf : tak00_columninfo;
            errpos     : integer);
 
VAR
      _b_err         : tgg00_BasisError;
      _first_data    : boolean;
      _intern_func   : boolean;
      _aux_len       : integer;
      _i             : integer;
      _move_len      : integer;
      _rest_len      : integer;
      _firstdataoffs : integer;
      _tab_offset    : integer;
      _start         : integer;
      _read_idx      : integer;
      _rel_pos       : integer;
      _exprbuf       : tak_sysbufferaddress;
      _colname       : tsp00_KnlIdentifier;
      _exprkey       : tgg00_SysInfoKey;
 
BEGIN
&ifdef trace
t01buf1( ak_sem, colinf.ccolumnn, 1, ord( colinf.ccolumnn_len ) );
t01int4 (ak_sem, 'ocounttabs  ',
      dmli.d_tabarr[ dmli.d_acttabindex ].ocounttabs );
&endif
_tab_offset := dmli.d_tabarr[ dmli.d_acttabindex ].ocounttabs;
IF  (( dmli.d_wherepart OR dmli.d_is_function_column OR
    ( dmli.d_cntfromtab > 1 ) ) AND
    ( colinf.ccolstack.eop_func in [ op_f_sum, op_f_avg ] ))
THEN
    BEGIN
    a061get_colname (colinf, _colname);
    a07_nb_put_error (acv, e_invalid_view_column, errpos, _colname);
    END
ELSE
    IF  acv.a_mblock.mb_qual^.mfirst_free + colinf.ccolstack.elen_var -
        colinf.ccolstack.epos > acv.a_mblock.mb_st_max
    THEN
        a07_b_put_error (acv, e_too_many_mb_stackentries,
              -acv.a_mblock.mb_st_max)
    ELSE
        BEGIN
        IF  (( colinf.ccolstack.eop_func in [ op_f_sum, op_f_avg ] ) AND
            ( acv.a_ap_tree^[ acv.a_ap_tree^[ 0 ].n_lo_level ].n_proc
            in [ a63, a56 ] ))
        THEN
            acv.a_mblock.mb_type2 := mm_with_functions;
        (*ENDIF*) 
        _exprkey           := a01sysnullkey;
        _exprkey.stableid  := dmli.d_tabarr[ dmli.d_acttabindex ].ofromtableid;
        _exprkey.sentrytyp := cak_eviewqual_expcol;
        _exprkey.slinkage[ 2 ] := colinf.ccolstack.ecol_tab[ 1 ];
        a10get_sysinfo (acv, _exprkey, d_release, _exprbuf, _b_err);
        IF  _b_err <> e_ok
        THEN
            a07_b_put_error (acv, _b_err, 1)
        ELSE
            WITH acv.a_mblock, mb_qual^ DO
                BEGIN
                _move_len    := 0;
                _first_data  := true;
                _intern_func := false;
                _start       := mfirst_free;
                _read_idx    := colinf.ccolstack.epos;
&               ifdef trace
                t01int4( ak_sem, 'epos        ', colinf.ccolstack.epos );
                t01int4( ak_sem, 'elen_var    ', colinf.ccolstack.elen_var );
&               endif
                FOR _i := colinf.ccolstack.epos TO colinf.ccolstack.epos +
                      ( colinf.ccolstack.elen_var - 1 ) DO
                    BEGIN
                    IF  _read_idx > cak_max_viewqual_stack
                    THEN
                        (* record overflow handling *)
                        BEGIN
                        a06inc_linkage( _exprkey.slinkage );
                        a10get_sysinfo( acv, _exprkey, d_release,
                              _exprbuf, _b_err );
                        _read_idx := 1;
                        END;
                    (*ENDIF*) 
                    IF  _b_err = e_ok
                    THEN
                        BEGIN
                        mb_st^[ mfirst_free ] := _exprbuf^.sviewqual_stack.
                              vstack[ _read_idx ];
                        IF  ( mb_st^[ mfirst_free ].etype in
                            [ st_value, st_language, st_format,
                            st_date, st_time, st_timestamp,
                            (* PTS 1116175 E.Z. *)
                            st_utcdate,
                            (* PTS 1109925 E.Z. *)
                            st_utcdiff,
                            st_user, st_usergroup, st_uid,
                            st_sysdba, st_localsysdba, st_transaction,
                            st_timezone (* PTS 1122262 E.Z. *)
                            ] )
                        THEN
                            BEGIN
                            IF  NOT dmli.d_view AND
                                ( mb_st^[ mfirst_free ].etype <> st_value )
                            THEN
                                _intern_func := true;
                            (*ENDIF*) 
                            IF  _first_data
                            THEN
                                BEGIN
                                _firstdataoffs := mb_st^[ mfirst_free ].epos;
&                               ifdef trace
                                t01int4( ak_sem, '_firstdataof',
                                      _firstdataoffs );
&                               endif
                                _first_data   := false;
                                IF  ( _exprbuf^.sviewqual_stack.vdatapos = 0 ) OR
                                    ( _exprbuf^.sviewqual_stack.vdatalen = 0 )
                                THEN
                                    a07ak_system_error( acv, 61, 1 );
                                (*ENDIF*) 
                                END;
                            (*ENDIF*) 
                            ;
                            (* calculate relative position to first data *)
                            mb_st^[ mfirst_free ].epos :=
                                  mb_st^[ mfirst_free ].epos + mb_data_len + 1
                                  - _firstdataoffs;
                            _move_len := _move_len +
                                  mb_st^[ mfirst_free ].elen_var;
                            END
                        ELSE
                            IF  mb_st^[ mfirst_free ].etype in
                                [ st_fixkey, st_varkey,
                                st_fixcol, st_varcol,
                                st_varlongchar ]
                            THEN
                                mb_st^[ mfirst_free ].ecol_tab[ 2 ] :=
                                      chr( ord( mb_st^[ mfirst_free ].
                                      ecol_tab[ 2 ] ) + _tab_offset );
&                           ifdef trace
                            (*ENDIF*) 
                        (*ENDIF*) 
                        t01stackentry( ak_sem, mb_st^[ mfirst_free ], mfirst_free );
&                       endif
                        mfirst_free := succ( mfirst_free );
                        mqual_cnt   := succ( mqual_cnt );
                        _read_idx   := succ( _read_idx );
                        END;
                    (*ENDIF*) 
                    END;
                (*ENDFOR*) 
                IF  _move_len > 0
                THEN
                    IF  mb_data_len + _move_len > mb_data_size
                    THEN
                        a07_b_put_error( acv, e_too_many_mb_data, 1 )
                    ELSE
                        BEGIN
                        (* get catalog record with data for expressions *)
                        _rel_pos := _exprbuf^.sviewqual_stack.vdatapos +
                              _firstdataoffs;
                        _exprkey.slinkage := cak_init_linkage;
&                       ifdef trace
                        t01int4( ak_sem, 'data length ', _move_len );
                        t01int4( ak_sem, 'vdatapos    ',
                              _exprbuf^.sviewqual_stack.vdatapos );
                        t01int4( ak_sem, '_rel_pos    ', _rel_pos );
&                       endif
                        WHILE _rel_pos > cak_max_viewqual_data DO
                            BEGIN
                            a06inc_linkage( _exprkey.slinkage );
                            _rel_pos := _rel_pos - cak_max_viewqual_data;
                            END;
                        (*ENDWHILE*) 
                        a10get_sysinfo( acv, _exprkey, d_release,
                              _exprbuf, _b_err );
                        _rest_len := _move_len;
                        WHILE ( _rest_len > 0 ) AND ( _b_err = e_ok ) DO
                            BEGIN
                            IF  _rest_len >
                                sizeof( _exprbuf^.sviewqual_stack.vdata ) -
                                ( _rel_pos - 1 )
                            THEN
                                _move_len   :=
                                      sizeof( _exprbuf^.sviewqual_stack.vdata ) -
                                      ( _rel_pos - 1 )
                            ELSE
                                _move_len := _rest_len;
                            (*ENDIF*) 
&                           ifdef trace
                            t01int4( ak_sem, '_rest_len   ', _rest_len );
                            t01int4( ak_sem, '_rel_pos    ', _rel_pos );
                            t01int4( ak_sem, '_move_len   ', _move_len );
&                           endif
                            g10mv ('VAK61 ',   6,    
                                  sizeof( _exprbuf^.sviewqual_stack.vdata ),
                                  mb_data_size,
                                  @_exprbuf^.sviewqual_stack.vdata, _rel_pos,
                                  @mb_data^.mbp_buf, mb_data_len + 1,
                                  _move_len, _b_err );
&                           ifdef trace
                            t01moveobj( ak_sem, mb_data^.mbp_buf,
                                  mb_data_len + 1, mb_data_len + 1 +
                                  ( _move_len - 1 ) );
&                           endif
                            mb_data_len := mb_data_len + _move_len;
                            _rest_len   := _rest_len - _move_len;
                            IF  _rest_len > 0
                            THEN
                                (* record overflow handling *)
                                BEGIN
                                _rel_pos := 1;
                                a06inc_linkage( _exprkey.slinkage );
                                a10get_sysinfo( acv, _exprkey, d_release,
                                      _exprbuf, _b_err );
                                END;
                            (*ENDIF*) 
                            END;
                        (*ENDWHILE*) 
                        IF  _b_err <> e_ok
                        THEN
                            a07_b_put_error( acv, _b_err, 1 )
                        (*ENDIF*) 
                        END;
                    (*ENDIF*) 
                (*ENDIF*) 
                IF  ( _intern_func AND
                    ( acv.a_returncode = 0 ) )
                THEN
                    FOR _i := _start TO mfirst_free - 1 DO
                        IF  ( mb_st^[ _i ].etype in
                            [ st_format, st_language,
                            st_date, st_time, st_timestamp,
                            (* PTS 1116175 E.Z. *)
                            st_utcdate,
                            (* PTS 1109925 E.Z. *)
                            st_utcdiff,
                            st_user, st_usergroup, st_uid,
                            st_sysdba, st_localsysdba,
                            st_transaction,
                            st_timezone (* PTS 1122262 E.Z. *)
                            ] )
                        THEN
                            IF  (( acv.a_cmd_segment_header.sp1c_mess_type = sp1m_parse ) AND
                                (
                                (* PTS 1122262 E.Z. *)
                                ( mb_st^[ _i ].etype = st_date )       OR
                                ( mb_st^[ _i ].etype = st_time )       OR
                                ( mb_st^[ _i ].etype = st_timestamp)   OR
                                ( mb_st^[ _i ].etype = st_utcdate )    OR
                                ( mb_st^[ _i ].etype = st_utcdiff )    OR
                                ( mb_st^[ _i ].etype = st_transaction) OR
                                ( mb_st^[ _i ].etype = st_timezone)
                                ))
                            THEN (* PTS 1117563 *)
                                BEGIN
                                _aux_len := acv.a_mblock.mb_data_len;
                                acv.a_mblock.mb_data_len := mb_st^[ _i ].epos - 1;
                                a54_fixedpos( acv, dmli );
                                acv.a_mblock.mb_data_len := _aux_len;
                                a54datetime_parsinfo( acv, dmli, _i );
                                END
                            ELSE
                                a54_internal_function( acv, acv.a_mblock, _i );
                            (*ENDIF*) 
                        (*ENDIF*) 
                    (*ENDFOR*) 
                (*ENDIF*) 
                END;
            (*ENDWITH*) 
        (*ENDIF*) 
        END;
    (*ENDIF*) 
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61_upd_union_column (
            VAR acv      : tak_all_command_glob;
            st_pos       : tsp00_Int2;
            VAR inoutlen : tsp00_Int2);
 
VAR
      i           : integer;
      oldi        : integer;
 
BEGIN
WITH acv, a_mblock, mb_qual^, mb_st^ [st_pos] DO
    BEGIN
&   ifdef trace
    t01messblock (ak_sem, 'upd_union   ', a_mblock);
    t01int4 (ak_sem, 'mfirst_free ', mfirst_free);
    t01stackentry (ak_sem, mb_st^[st_pos], st_pos);
&   endif
    i := pred (mfirst_free);
    oldi := 1;
    WHILE (i > mqual_pos) DO
        BEGIN
        IF  oldi = i
        THEN
            i := 0
        ELSE
            BEGIN
            oldi := i;
            IF  (mb_st^ [i].etype         = etype)    AND
                (mb_st^ [i].epos          = epos)     AND
                (mb_st^ [i].elen_var      = elen_var) AND
                (mb_st^ [i].ecol_tab[ 2 ] = ecol_tab [2])
            THEN
                BEGIN
                i := succ (i);
                WHILE (i             <  st_pos) AND
                      (mb_st^ [i].etype <> st_output) DO
                    i := succ (i);
                (*ENDWHILE*) 
&               ifdef trace
                t01stackentry (ak_sem, mb_st^[i], i);
&               endif
                IF  (mb_st^ [i].etype = st_output)
                THEN
                    BEGIN
                    IF  (mb_st^ [i].elen_var > elen_var)
                    THEN
                        inoutlen := mb_st^ [i].elen_var;
                    (*ENDIF*) 
                    i := 0; (* exit while *)
                    END;
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            i := pred (i);
            END
        (*ENDIF*) 
        END;
    (*ENDWHILE*) 
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak61get_long_tabid (
            VAR acv   : tak_all_command_glob;
            VAR dmli  : tak_dml_info;
            tabno     : integer;
            VAR ltabid : tgg00_Surrogate);
 
VAR
      e         : tgg00_BasisError;
      viewp     : tak_sysbufferaddress;
      ke        : tgg00_SysInfoKey;
 
BEGIN
ke           := a01defaultkey;
ke.stableid  := dmli.d_tabarr[ dmli.d_acttabindex ].ofromtableid;
ke.sentrytyp := cak_eviewqual_basis;
a10get_sysinfo (acv, ke, d_fix, viewp, e);
IF  e = e_ok
THEN
    WITH viewp^.sviewqual_basis, vtable[ tabno ] DO
        BEGIN
        ltabid := vttableid;
&       ifdef trace
        t01surrogate (ak_sem, 'base tabid  ', vttableid);
&       endif
        a10rel_sysinfo( viewp );
        END
    (*ENDWITH*) 
ELSE
    a07_b_put_error (acv, e, 1);
(*ENDIF*) 
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
.PA 
