.ad 8
.bm 8
.fm 4
.bt $Copyright by SAP AG, 2002$$Page %$
.tm 12
.hm 6
.hs 3
.TT 1 $SQL$Project Distributed Database System$VAK501$
.tt 2 $$$
.TT 3 $ElkeZ$Executing_dispatcher$2000-04-11$
***********************************************************
.nf
 
 
    ========== licence begin  GPL
    Copyright (C) 2000 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
.nf
.sp
MODULE  : Executing_dispatcher
=========
.sp
Purpose : Main module and distributor for commands that are
          already parsed and only need to be executed
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :
 
        PROCEDURE
              a501exec_with_change_rec (VAR acv : tak_all_command_glob;
                    VAR dmli                : tak_dml_info;
                    VAR parsk               : tak_parskey;
                    VAR change_rec          : tak_changerecord;
                    output_during_execution : boolean);
 
        PROCEDURE
              a501do_execute (VAR acv : tak_all_command_glob;
                    VAR dmli                : tak_dml_info;
                    VAR parsk               : tak_parskey;
                    output_during_execution : boolean);
 
        PROCEDURE
              a501execute (VAR acv : tak_all_command_glob;
                    VAR parsid : tak_parsid);
 
        PROCEDURE
              a501get_resname (VAR acv : tak_all_command_glob;
                    VAR dmli : tak_dml_info);
 
        PROCEDURE
              a501GetResultName (
                    VAR acv : tak_all_command_glob;
                    VAR resultName : tsp00_KnlIdentifier);
 
.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :
 
        FROM
              Scanner : VAK01;
 
        VAR
              a01sysnullkey       : tgg_sysinfokey;
              a01diag_monitor_on  : boolean;
              a01diag_analyze_on  : boolean;
              a01_il_b_identifier : tsp_knl_identifier;
 
        PROCEDURE
              a01_init_command (VAR acv : tak_all_command_glob);
 
        FUNCTION
              a01aligned_cmd_len (len : tsp_int4) : tsp_int4;
 
      ------------------------------ 
 
        FROM
              AK_semantic_scanner_tools : VAK05;
 
        PROCEDURE
              a05_stamp_get (VAR acv : tak_all_command_glob;
                    VAR dest   : tgg_surrogate;
                    destpos    : integer;
                    mv_dest    : integer);
 
      ------------------------------ 
 
        FROM
              AK_universal_semantic_tools : VAK06;
 
        PROCEDURE
              a06reset_retpart (VAR acv : tak_all_command_glob);
 
        PROCEDURE
              a06finish_curr_retpart (VAR acv : tak_all_command_glob;
                    part_kind : tsp1_part_kind;
                    arg_count : tsp_int2);
 
        PROCEDURE
              a06retpart_move (VAR acv : tak_all_command_glob;
                    moveobj_ptr : tsp_moveobj_ptr;
                    move_len    : tsp_int4);
 
      ------------------------------ 
 
        FROM
              AK_error_handling : VAK07;
 
        PROCEDURE
              a07_b_put_error (VAR acv : tak_all_command_glob;
                    b_err   : tgg_basis_error;
                    err_code : tsp_int4);
 
        FUNCTION
              a07_return_code (b_err : tgg_basis_error;
                    sqlmode : tsp_sqlmode) : tsp_int2;
 
      ------------------------------ 
 
        FROM
              Systeminfo_cache : VAK10;
 
        PROCEDURE
              a10get_sysinfo (VAR acv : tak_all_command_glob;
                    VAR syskey   : tgg_sysinfokey;
                    dstate       : tak_directory_state;
                    VAR syspoint : tak_sysbufferaddress;
                    VAR b_err    : tgg_basis_error);
 
        PROCEDURE
              a10_nil_get_sysinfo (VAR acv : tak_all_command_glob;
                    VAR syskey   : tgg_sysinfokey;
                    dstate       : tak_directory_state;
                    syslen       : tsp_int2;
                    VAR syspoint : tak_sysbufferaddress;
                    VAR b_err    : tgg_basis_error);
 
        PROCEDURE
              a10repl_sysinfo (VAR acv : tak_all_command_glob;
                    VAR syspoint  : tak_sysbufferaddress;
                    VAR b_err     : tgg_basis_error);
 
        PROCEDURE
              a10key_del  (VAR acv : tak_all_command_glob;
                    VAR syspointer : tak_sysbufferaddress);
 
      ------------------------------ 
 
        FROM
              AK_Trigger : VAK262;
 
        PROCEDURE
              a262execute_trigger (VAR acv : tak_all_command_glob);
 
      ------------------------------ 
 
        FROM
              AK_data_dictionary : VAK38;
 
        PROCEDURE
              a38ex_usage (VAR acv : tak_all_command_glob;
                    VAR parsk : tak_parskey);
 
      ------------------------------ 
 
        FROM
              AK_Show_statistics : VAK42;
 
        PROCEDURE
              a42_check_database (VAR acv : tak_all_command_glob);
 
        PROCEDURE
              a42put_running_cmds (VAR acv : tak_all_command_glob;
                    VAR parsid : tak_parsid);
 
        PROCEDURE
              a42reset_running_cmds (VAR acv : tak_all_command_glob);
 
      ------------------------------ 
 
        FROM
              Executing_complex : VAK502;
 
        PROCEDURE
              a502complex_execution (VAR acv : tak_all_command_glob;
                    VAR dmli                : tak_dml_info;
                    VAR change_rec          : tak_changerecord;
                    VAR parsk               : tak_parskey;
                    output_during_execution : boolean );
 
      ------------------------------ 
 
        FROM
              Executing_union : VAK503;
 
        PROCEDURE
              a503union_execution (VAR acv : tak_all_command_glob;
                    VAR dmli                : tak_dml_info;
                    VAR change_rec          : tak_changerecord;
                    VAR parsk               : tak_parskey;
                    output_during_execution : boolean );
 
      ------------------------------ 
 
        FROM
              Executing_loop_most : VAK505;
 
        PROCEDURE
              a505fill_mess_buf (VAR acv : tak_all_command_glob;
                    VAR dmli   : tak_dml_info;
                    VAR erec   : tak_exec_rec;
                    VAR frec   : tak_fill_rec;
                    full_part2 : boolean);
 
        PROCEDURE
              a505loop_most_execute (VAR acv : tak_all_command_glob;
                    VAR dmli       : tak_dml_info;
                    VAR change_rec : tak_changerecord;
                    VAR erec       : tak_exec_rec;
                    VAR parsk      : tak_parskey;
                    viewkeybuf     : tak_sysbufferaddress;
                    VAR series     : tak68_sequence;
                    VAR cinfo      : tak_corr_infos;
                    VAR old_cinfo  : tak_corr_infos;
                    inner_loop     : boolean);
 
        PROCEDURE
              a505most_execute (VAR acv : tak_all_command_glob;
                    VAR dmli       : tak_dml_info;
                    VAR change_rec : tak_changerecord;
                    VAR parsk      : tak_parskey;
                    VAR erec       : tak_exec_rec;
                    VAR cinfo      : tak_corr_infos;
                    VAR old_cinfo  : tak_corr_infos;
                    viewkeybuf     : tak_sysbufferaddress;
                    inner_loop     : boolean);
 
        PROCEDURE
              a505next_command (VAR acv : tak_all_command_glob;
                    VAR sparr     : tak_syspointerarr;
                    VAR old_parsk : tak_parskey;
                    ex_plus       : integer);
 
      ------------------------------ 
 
        FROM
              Executing_values : VAK506;
 
        PROCEDURE
              a506fieldvalues (VAR acv : tak_all_command_glob;
                    VAR dmli      : tak_dml_info;
                    VAR frec      : tak_fill_rec;
                    viewkeybuf    : tak_sysbufferaddress;
                    VAR result    : tsp_moveobj;
                    resultBufSize : tsp00_Int4); (* PTS 1115085 *)
 
      ------------------------------ 
 
        FROM
              AK_Connect : VAK51;
 
        PROCEDURE
              a51set_degree (VAR acv : tak_all_command_glob);
 
      ------------------------------ 
 
        FROM
              AK_Lock_Commit_Rollback : VAK52;
 
        PROCEDURE
              a52end_rollback_subtrans (VAR acv : tak_all_command_glob;
                    VAR subtrans_name : tsp_knl_identifier;
                    m_type : tgg_message_type);
 
        PROCEDURE
              a52internal_subtrans (VAR acv : tak_all_command_glob);
 
        PROCEDURE
              a52new_subtrans (VAR acv : tak_all_command_glob;
                    VAR subtrans_name : tsp_knl_identifier);
 
        PROCEDURE
              a52_ex_commit_rollback (VAR acv : tak_all_command_glob;
                    m_type         : tgg_message_type;
                    n_rel          : boolean;
                    normal_release : boolean);
 
      ------------------------------ 
 
        FROM
              DML_Help_Procedures : VAK54;
 
        PROCEDURE
              a54_dml_init (VAR dmli : tak_dml_info;
                    in_union : boolean);
 
      ------------------------------ 
 
        FROM
              DML_Help_Procedures : VAk542;
 
        FUNCTION
              a542initial_mess_code(VAR acv : tak_all_command_glob) : tsp_code_type;
 
      ------------------------------ 
 
        FROM
              diagnose monitor : VAK545;
 
        PROCEDURE
              a545sm_insert (VAR acv : tak_all_command_glob);
 
      ------------------------------ 
 
        FROM
              diagnose analyze : VAK544;
 
        PROCEDURE
              a544get_cmdid(VAR acv : tak_all_command_glob;
                    VAR parskey : tak_parskey;
                    VAR cmdid   : tgg_surrogate);
 
      ------------------------------ 
 
        FROM
              Select_Syntax : VAK60;
 
        PROCEDURE
              a60rescount (VAR acv : tak_all_command_glob;
                    rescount : tsp_int4);
 
      ------------------------------ 
 
        FROM
              Subquery_handling : VAK661;
 
        PROCEDURE
              a661_build_t_fromsel_tableid (
                    VAR syskey_tableid  : tgg_surrogate;
                    VAR fn_tableid      : tgg_surrogate;
                    VAR curr_ex_parskey : tak_parskey;
                    site                : tgg_serverdb_no;
                    session             : tgg91_SessionNo;
                    from_select_no      : tsp_int2);
 
      ------------------------------ 
 
        FROM
              Resultname_handling : VAK663;
 
        PROCEDURE
              a663_del_result (VAR acv : tak_all_command_glob;
                    VAR resname_rec  : tak_resname_record;
                    do_cdel          : boolean;
                    del_resname_rec  : boolean);
 
        PROCEDURE
              a663_resname (VAR acv : tak_all_command_glob;
                    VAR res_name     : tsp_knl_identifier;
                    VAR modul_name   : tsp_knl_identifier;
                    VAR resname_addr : tak_sysbufferaddress;
                    dstate           : tak_directory_state;
                    errorpos         : integer);
 
      ------------------------------ 
 
        FROM
              Resulttable : VAK73;
 
        PROCEDURE
              a73_one_fetch (VAR acv : tak_all_command_glob;
                    VAR sparr    : tak_syspointerarr;
                    mtype        : tgg_message2_type;
                    position     : tsp_int4);
 
        PROCEDURE
              a73_more_fetch (VAR acv : tak_all_command_glob;
                    VAR sparr    : tak_syspointerarr;
                    mtype        : tgg_message2_type;
                    pos          : tsp_int4;
                    mfetch_count : integer);
 
        PROCEDURE
              a73_close_execute (VAR acv : tak_all_command_glob;
                    VAR sparr      : tak_syspointerarr;
                    VAR resn       : tsp_knl_identifier;
                    VAR modul_name : tsp_knl_identifier);
 
        PROCEDURE
              a73_describe_execute (VAR acv : tak_all_command_glob;
                    VAR sparr      : tak_syspointerarr;
                    VAR resn       : tsp_knl_identifier;
                    VAR modul_name : tsp_knl_identifier);
 
      ------------------------------ 
 
        FROM
              Fetch_Without_Resulttable : VAK74;
 
        PROCEDURE
              a74_search_fetch (VAR acv : tak_all_command_glob;
                    VAR sparr      : tak_syspointerarr;
                    mtype          : tgg_message2_type;
                    pos            : tsp_int4;
                    VAR resnamerec : tak_sysbufferaddress;
                    single_fetch   : boolean;
                    mfetch_count   : integer);
 
      ------------------------------ 
 
        FROM
              execute_string_opns: VAK76;
 
        PROCEDURE
              a76ex_string_opns (VAR acv : tak_all_command_glob;
                    VAR dmli : tak_dml_info);
 
      ------------------------------ 
 
        FROM
              Deal-With-User-Commands : VAK92;
 
        PROCEDURE
              a92_map_into_upper (VAR acv : tak_all_command_glob;
                    VAR buf  : tsp_moveobj;
                    startpos : tsp_int4;
                    endpos   : tsp_int4;
                    uni_map  : boolean);
 
        PROCEDURE
              a92find_return_part (VAR acv : tak_all_command_glob;
                    part_kind    : tsp1_part_kind;
                    VAR part_ptr : tsp1_part_ptr);
 
        PROCEDURE
              a92parse_again (VAR acv : tak_all_command_glob;
                    VAR parsk     : tak_parskey;
                    dropStoredCmd : boolean); (* PTS 1106286 *)
 
      ------------------------------ 
 
        FROM
              KB_Logging : VKB560;
 
        PROCEDURE
              kb560StartSavepointAndWait (VAR Trans : tgg00_TransContext;
                    MessType2 : tgg00_MessType2);
 
      ------------------------------ 
 
        FROM
              filesysteminterface_1 : VBD01;
 
        VAR
              b01niltree_id : tgg00_FileId;
 
        PROCEDURE
              b01prefix_destroy_files (VAR t : tgg00_TransContext;
                    VAR prefix_fn : tgg00_Filename;
                    prefix_len    : integer);
 
      ------------------------------ 
 
        FROM
              task_temp_data_cache : VBD21;
 
        PROCEDURE
              b21m_reset_monitor (temp_cache_ptr : tgg00_TempDataCachePtr;
                    reset_sum : boolean);
 
        PROCEDURE
              b21m_parseid (temp_cache_ptr : tgg00_TempDataCachePtr;
                    VAR parseid : tak_parsid);
 
        PROCEDURE
              b21mp_parseid_put (temp_cache_ptr : tgg00_TempDataCachePtr;
                    VAR parseid : tak_parsid);
 
        PROCEDURE
              b21mp_cmdid_put (temp_cache_ptr : tgg00_TempDataCachePtr;
                    VAR cmdid : tgg00_Surrogate);
 
        PROCEDURE
              b21m_parse_again (temp_cache_ptr : tgg00_TempDataCachePtr;
                    VAR parse_again : tsp00_C3);
 
        PROCEDURE
              b21mp_fetch_calls_put (temp_cache_ptr : tgg00_TempDataCachePtr);
 
        PROCEDURE
              b21mp_rows_fetched_put (temp_cache_ptr : tgg00_TempDataCachePtr;
                    rows_fetched : tsp00_Int4);
 
        PROCEDURE
              b21mp_value_put (temp_cache_ptr : tgg00_TempDataCachePtr;
                    curr_value_addr : tsp00_MoveObjPtr;
                    curr_value_len  : tsp00_Int4);
 
        PROCEDURE
              b21mp_is_select (temp_cache_ptr : tgg00_TempDataCachePtr;
                    is_select : boolean);
 
      ------------------------------ 
 
        FROM
              object_garbage_collection : VBD91;
 
        PROCEDURE
              bd91StartOMSGarbageCollection (VAR Trans : tgg00_TransContext;
                    bStartOnlyIfDataCacheIsFull : boolean);
 
      ------------------------------ 
 
        FROM
              Configuration_Parameter : VGG01;
 
        VAR
              g01unicode             : boolean;
              g01diag_moni_parse_on  : boolean;
 
      ------------------------------ 
 
        FROM
              Codetransformation_and_Coding : VGG02;
 
        PROCEDURE
              g02fromtermchar (
                    messcode   : tsp_code_type;
                    VAR object : tsp_moveobj;
                    pos        : tsp_int4;
                    length     : tsp_int4);
 
      ------------------------------ 
 
        FROM
              Select_Help_Procedures : VGG04;
 
        PROCEDURE
              g04build_temp_tree_id (VAR curr : tgg00_FileId;
                    VAR t : tgg00_TransContext);
 
      ------------------------------ 
 
        FROM
              Kernel_move_and_fill : VGG10;
 
        PROCEDURE
              g10mv (mod_id        : tsp_c6;
                    mod_intern_num : tsp_int4;
                    size1          : tsp_int4;
                    size2          : tsp_int4;
                    VAR val1       : tsp_moveobj;
                    p1             : tsp_int4;
                    VAR val2       : tsp_moveobj;
                    p2             : tsp_int4;
                    cnt            : tsp_int4;
                    VAR e          : tgg_basis_error);
 
        PROCEDURE
              g10mv2  (mod_id      : tsp_c6;
                    mod_intern_num : tsp_int4;
                    size1          : tsp_int4;
                    size2          : tsp_int4;
                    VAR val1       : tsp_moveobj;
                    p1             : tsp_int4;
                    VAR val2       : tsp_key;
                    p2             : tsp_int4;
                    cnt            : tsp_int4;
                    VAR e          : tgg_basis_error);
 
        PROCEDURE
              g10mv3  (mod_id      : tsp_c6;
                    mod_intern_num : tsp_int4;
                    size1          : tsp_int4;
                    size2          : tsp_int4;
                    VAR val1       : tsp_moveobj;
                    p1             : tsp_int4;
                    VAR val2       : tsp_buf;
                    p2             : tsp_int4;
                    cnt            : tsp_int4;
                    VAR e          : tgg_basis_error);
 
        PROCEDURE
              g10mv4  (mod_id      : tsp_c6;
                    mod_intern_num : tsp_int4;
                    size1          : tsp_int4;
                    size2          : tsp_int4;
                    VAR val1       : tsp_moveobj;
                    p1             : tsp_int4;
                    VAR val2       : tsp_knl_identifier;
                    p2             : tsp_int4;
                    cnt            : tsp_int4;
                    VAR e          : tgg_basis_error);
 
      ------------------------------ 
 
        FROM
              GG_allocator_interface : VGG941;
 
        PROCEDURE
              gg941Deallocate(VAR TransContext : tgg00_TransContext;
                    VAR p : tgg00_DataPartPtr);
 
      ------------------------------ 
 
        FROM
              RTE-Extension-10 : VSP10;
 
        PROCEDURE
              s10mv1  (size1 : tsp_int4;
                    size2    : tsp_int4;
                    VAR val1 : tak_field_pars;
                    p1       : tsp_int4;
                    VAR val2 : tak_parskey;
                    p2       : tsp_int4;
                    cnt      : tsp_int4);
 
        PROCEDURE
              s10fil  (size  : tsp_int4;
                    VAR m    : tak_parsid;
                    pos      : tsp_int4;
                    len      : tsp_int4;
                    fillchar : char);
 
      ------------------------------ 
 
        FROM
              Packet_handling: VSP26;
 
        PROCEDURE
              s26find_part (VAR segm : tsp1_segment;
                    part_kind        : tsp1_part_kind;
                    VAR part_ptr     : tsp1_part_ptr);
 
      ------------------------------ 
 
        FROM
              GET-Conversions : VSP40;
 
        PROCEDURE
              s40gsint (
                    VAR buf  : tsp_moveobj;
                    pos      : tsp_int4;
                    len      : integer;
                    VAR dest : tsp_int2;
                    VAR res  : tsp_num_error);
 
        PROCEDURE
              s40g4int (VAR buf : tsp_moveobj;
                    pos      : tsp_int4;
                    VAR dest : tsp_int4;
                    VAR res  : tsp_num_error);
 
      ------------------------------ 
 
        FROM
              RTE-Extension-80 : VSP80;
 
        PROCEDURE
              s80uni_trans
                    (src_ptr        : tsp_moveobj_ptr;
                    src_len         : tsp_int4;
                    src_codeset     : tsp_int2;
                    dest_ptr        : tsp_moveobj_ptr;
                    VAR dest_len    : tsp_int4;
                    dest_codeset    : tsp_int2;
                    trans_options   : tsp8_uni_opt_set;
                    VAR rc          : tsp8_uni_error;
                    VAR err_char_no : tsp_int4);
&       IFDEF TRACE
 
      ------------------------------ 
 
        FROM
              Test_Procedures : VTA01;
 
        PROCEDURE
              t01int4 (debug : tgg00_Debug;
                    nam      : tsp00_Sname;
                    int      : tsp00_Int4);
 
        PROCEDURE
              t01buf (level : tgg00_Debug;
                    VAR buf   : tak_parskey;
                    pos_start : integer;
                    pos_end   : integer);
&       ENDIF
 
.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :
 
        PROCEDURE
              gg941Deallocate;
 
              tsp00_Addr tgg00_DataPartPtr
 
        PROCEDURE
              a05_stamp_get;
 
              tsp_moveobj tgg_surrogate
 
        PROCEDURE
              a42put_running_cmds;
 
              tsp_c12 tak_parsid
 
        PROCEDURE
              b21mp_parseid_put;
 
              tsp00_C12 tak_parsid
 
        PROCEDURE
              b21m_parseid;
 
              tsp00_C12 tak_parsid
 
        PROCEDURE
              g10mv2;
 
              tsp_moveobj tsp_key
 
        PROCEDURE
              g10mv3;
 
              tsp_moveobj tsp_buf
 
        PROCEDURE
              g10mv4;
 
              tsp_moveobj tsp_knl_identifier
 
        PROCEDURE
              s10mv1;
 
              tsp_moveobj tak_field_pars
              tsp_moveobj tak_parskey
 
        PROCEDURE
              s10fil;
 
              tsp_moveobj tak_parsid
 
        PROCEDURE
              t01buf;
 
              tsp00_Buf tak_parskey
 
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : ElkeZ
.sp
.cp 3
Created : 1985-04-15
.sp
.cp 3
Version : 2002-12-13
.sp
.cp 3
Release :      Date : 2000-04-11
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:
.sp 2
Together with VAK502 - VAK507,
this module is responsible for processing commands
that are only to be executed, i.e. the parse information that must be
used is already present.
.sp 2
A501EXECUTE
.sp
This procedure is called directly by VAK92 if the user (precompiler)
sends only the parse id and the data for a command in the
SQL_PACKET to the kernel.
.sp 2
A501DO_EXECUTE
.sp
This procedure is called if the user has requested a normal command
execution but the kernel has made an internal separation between parsing
and execution.  This is the case for subqueries.  In order to prevent
individual parts of the subquery from already being executed before the
semantic check has been run for other parts of the command, all parts
are first parsed, the parse information is stored and then the command
is executed.
.br
Output_during_execution indicates that the result count and a result
(SELECT..INTO) within VAK50/53 are to be transferred to the SQL_PACKET.
If the value is false, it is an internal call of
A50_DO_EXECUTE (internal separation into parsing and execution, no call
of A50_EXECUTE) and the calling routine must still write long infos
before the result, if applicable.  Exception: VAK54 A54_SUBQUERY.
In that case, the value = true so that the result count is output.
.sp 2
A501exec_with_change_rec
.sp
The same applies as for A501DO_EXECUTE.  The only difference is that,
in the case of A501exec_with_change_rec, atch is passed upwards.  It contains
information which fields are to be converted from ASCII to EBCDIC,
the starting position of the conversion and the length.  This is, of
course, relevant for SELECT .. INTO only.  Since, in the case of
correlated subqueries, the outermost SELECT is not analyzed last,
the correct atch for the final result is not available to the caller. It
must again be fetched from the parse information
during the processing and passed outward.
.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:
.sp 2
The parse id that is always used within VAK50x has the following layout:
.br;.nf
       p_id      : int4;  (* number of intern commands *)
       p_kind    : message_type;
       p_no      : int1;  (* highest parse-information number *)
.fo
.sp
The individual parts have the following meanings:
.in +10;.un 10;p_session The last 2 bytes of the 4-bytes session id
are stored here to make it possible to check whether the user
(precompiler) and the kernel associate the same command with this
parse id.  Otherwise it would be a critical case when a user parsed
some commands and had also already executed them and then came to an
implicit (command timeout) or explicit session end, was reconnected,
again parsed some commands (again receiving the command numbers
beginning with 1) and then sent an old parse id (before the session end) to
the kernel.  If the session number did not exist, the kernel might
recognize the command number and, if possible, perform an update/delete
or the like on a table that the user had not addressed with this
old parse id.
.un 10;p_id
This is a current number that begins at 1 for each session and,
therefore, is unambiguous and differs from all commands within
this session.
.un 10;p_kind The message type of the command (update, select,
fetch, commit, etc ] is designated here, so that some commands can be
separated from others in good time because they are simpler/more complicated.
.br;p_kind = m_nil (0) means that an attempt is made to execute a command
that must not be executed (DDL command or SHOW).  For these commands,
there is a parse id consisting of 0 only or filled with '00'h and 1
'01'h.
.un 10;p_no  The highest number of a parse-information record that belongs
to this command is stored here.  Currently, there can be values from
0 (1 information record) to 127.  However, P_NO = 8 does not necessarily
mean that there must be 9 parse-information records.  Several message
buffers can be sent to KB within one command.  For each message buffer to
be built, there can be a maximum of 4 parse-information records.  In
order to simplify processing, the first parse-information record for each
message buffer receives a number evenly divisible by 4.  If there is only
this one information record for the message buffer, three numbers remain
free.
.in -10;.sp 2
A501EXECUTE
.sp
The parse id only is retrieved from the SQL_PACKET and a check is
run to determine whether a session is in progress.  The execution itself
is performed via A501exec_with_change_rec.
.sp 2
A501DO_EXECUTE
.sp
Only the parameter atch required for A501exec_with_change_rec
is allocated as a
local variable and A501exec_with_change_rec is called.
.sp 2
A501exec_with_change_rec
.sp
All_rescnt indicates how many results have already been found for
the current select (if one is pending).  The value is passed to the
message buffer again and again in, for example, correlated subqueries.
.br
Cinfo is a record that is relevant for correlated subqueries only due
to the recursiveness of LOOP_MOST_EXECUTE but that must at this point
already be created and initialized (no correlation found).
.sp
A check is run to determine whether it is an executable command
(p_kind <> m_nil, session number is correct).
.br
For COMMIT and ROLLBACK, under normal circumstances (no KEEP LOCK),
there is no parse information.  P_NO = maxint1 indicates RELEASE;
maxint1-1 shows that no RELEASE was specified. P_NO = maxint1-2
indicates that adbsparse was done with another sqlmode than
the session sqlmode. VAK52, which executes
the command, can be called directly.  If P_NO is neither
maxint1 nor maxint1-1 not maxint1-2,
KEEP LOCK was specified and 1-4 parse-information
records exist that must be processed normally.
.br
The message types m_check_database (CHECK DATABASE) and
m_outcopy (LOAD requests the description of the range conditions of
a column for the quick load) represent special commands that do not need
to hold to the conventions for the parse information and are processed
directly in VAK42 or VAK11 (see the particular section).
.br
Nor does the message type m_stamp (NEXT STAMP)
need any parse information;
instead, it must simply use A05_STAMP_GET to fetch the next system key
from VKB and transfer it to part2 of the SQL_PACKET or
construct the next long_desc_block for those LONG columns
which are inserted before the record they belong to is inserted.
.br
In all other cases, NEXT_COMMAND is used to fetch the maximum of 4
parse-information records in SPARR required to build a
message buffer (array of pointers to the cache).
.br;PLUS specifies the
number of the first parse-information record to be fetched (0 at the
start). Maxbufs designates the highest parse-information number that
can belong to this (sub)command (normally = old_parsk.p_no).
.br
All the following procedures assume that the parse information is
contained in sparr.
.br
No message-buffer needs to be built for CLOSE or DESCRIBE; the
parse information contains data on the result-table names, etc.
For FETCH and MFETCH, there is a message-buffer layout that is
different from the one for the other commands.
Column commands have practically nothing in common with DML commands.
For this reason, they must all branch to special procedures (see
that section).
.br
Inserts, updates, deletes and selects can require several message
buffers due to subqueries, inserts applied to a join view, etc.  Therefore
a loop is initiated (LOOP_MOST_EXECUTE) that processes all message
buffers one after the other.
.br
The message type m_key is for change operations applied to join views for
which the key values for the individual base tables must first be determined
and then the series of insert/update/deletes must be applied to the
base tables.  This occurs in KEY_EXECUTE.
.br
Other commands (LOCK, COMMIT KEEP LOCK, UNLOCK, etc ] are handled via
a simple A53_MOST_EXECUTE.
.sp 2
FETCH_EXECUTE
.sp
This procedure is called if a FETCH is to be performed for an individual
record.
.br
FETCH_PART is used to identify the information records (result-set name,
'POS' value and parse buffer containing the key values up to which the
fetch has already been performed).
.br
If the result set has already been built, A73_ONE_FETCH can be used to
fetch the record; if it has not been built, the record must first be
identified via A74_SEARCH_FETCH.
.sp 2
MFETCH_EXECUTE
.sp
The number of results to be fetched (specified as int2) must be
retrieved from the SQL_PACKET from the first 2 bytes of part2.
Since int2 is specified as low byte, high byte for some computers and
as high byte, low byte for others, it might be necessary for a byte
swap to take place.
.br
FETCH_PART is used to again assemble some information records as in
FETCH_EXECUTE.
.br
If the result set has been built, A73_MORE_FETCH is used to fetch
the desired number of result records.  If the result set has not been
built, A74_SEARCH_FETCH is called with single_fetch = false.
.sp 2
FETCH_PART
.sp
P_RESN contains the name of the result set from which the next
result records are to be fetched.
P_MODUL_NAME contains the name of the modul.
.br
In the case of the unnamed result set, cntbuf = -1 indicates either
that the select has not yet been executed or a close has again been
performed, i.e. the result set is unknown.
.br
In the case of the other special result set (SHOW), this is indicated via
'executed/closed'.
.br
For all other names, a check must be run via A66_RESNAME_SEARCH to
determine whether the result set exists
and whether the SELECT has already been
executed.
.br
In the case of a set fetch (fetch of more than one result record)
that is to be executed, the parse id of
the associated SELECT is stored in a part with
part~kind parsid_of_select in the SQL_PACKET in
order to allow the precompiler to identify the result buffer responsible
for the MFETCH.  If the SELECT was not separately parsed and then
executed, binary zeros are returned.
.br
There is never more than one parse-information record for a FETCH.
For this reason, the system-information record that specifies for the
result set the point to which fetch has already been performed in it
(entrytyp = ereskey) can be fetched to sparr[ 2 ].
.br
P_POSNO contains the position information for (M)FETCH POS [  ]. If
P_POSNO = -1, this means that the command has contained a parameter
as a position.  Its value must now be read from part2 of the SQL_PACKET.
In the case of FETCH, plus contains the value 2; in the
case of MFETCH, it contains the value 4, i.e. for MFETCHs, the position
is located (as a number) after the MFETCH number (2 bytes long).
.sp 2
KEY_EXECUTE
.sp
This procedure is called if a modification is to take place for a
join view. The key values must be determined for the individual base
tables and, afterwards, the change operations are performed on the
base tables.
.br
The variable 'series' is used to ensure (in LOOP_MOST_EXECUTE,
in the join part) that the message-buffer information records created
for the join is processed in the sequence in which they were built (in the
sequence of the FROM clause in the case of create view).  On the other
hand, in the case of a join select, the sequence in which they must
be processed can have been changed (via the strategic decision for the
processing sequence).
.br
Viewkeybuf contains the keys of all base tables participating in the
join view (one record per table since join-view modifications are allowed
only for such unambiguous records).  Space is supplied in the cache
for this purpose.
.br
One message-buffer information record is processed in a loop for each of
the tables involved.  This information record contains only the parts of
the particular key value that are already known from parsing
(A53_FILL_MESS_BUF).  The parameter values are also added via
A53_FIELDVALUES.  The rest of the key is appended on the end.  Afterwards,
the key that is thus built is moved to viewkeybuf.  The passage via the
message buffer is taken because the procedures used to fetch data from
the SQL_PACKET all operate on the message buffer.
.br
For each loop run, one message-buffer information record (one
system-information record) is processed.
.br
Via LOOP_MOST_EXECUTE, the actual command (with join for qualification
before and/or after the change operations) is then executed.
.br
After the join condition has been checked following the change operation,
the number of view records for which the change operation was performed
(always 1 since unambiguous keys are specified)
must still be recorded in the
SQL_PACKET.
.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:
 
.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.oc _/1
.CM -lll-
Code    :
 
 
CONST
      c_output_during_execution = true  (* a501do_execute *);
      c_single                  = true  (* ak501fetch_rest*);
      c_full_part2              = true  (* a505fill_mess_buf *);
      c_inner_loop              = true  (* a505loop_most_execute *);
      (*                                  a505_most_execute     *)
      c_n_rel                   = true  (* a52_ex_commit_rollback *);
      c_normal_release          = true  (* a52_ex_commit_rollback *);
      c_in_union                = true  (* a54_dml_init *);
      c_do_cdel                 = true  (* a663_del_result *);
      c_del_resname_rec         = true  (* a663_del_result *);
      c_single_fetch            = true  (* a74_search_fetch *);
      c_uni_map                 = true  (* a92_map_into_upper *);
      c_reset_sum               = true  (* b21m_reset_monitor *);
      c_is_select               = true  (* b21mp_is_select *);
 
 
(*------------------------------*) 
 
PROCEDURE
      a501exec_with_change_rec (VAR acv : tak_all_command_glob;
            VAR dmli                : tak_dml_info;
            VAR parsk               : tak_parskey;
            VAR change_rec          : tak_changerecord;
            output_during_execution : boolean);
 
CONST
      c_StartAlways = false;
 
VAR
      cinfo        : tak_corr_infos;
      old_cinfo    : tak_corr_infos;
      erec         : tak_exec_rec;
      frec         : tak_fill_rec;
      defined_byte : tsp_c1;
      next_stamp   : tgg_surrogate;
      dummyser     : tak68_sequence;
      dummybuf     : tak_sysbufferaddress;
 
BEGIN
WITH acv, dmli, erec DO
    (* PTS 1000985/1001162 E.Z. *)
    IF  NOT a_subq_datatype_problem
    THEN
        BEGIN
&       IFDEF TRACE
        t01int4 (ak_sem, 'cmd_length  ', a_cmd_part^.sp1p_buf_len);
        t01int4 (ak_sem, 'data_length ', a_data_length);
        t01buf (ak_sem, parsk, 1, sizeof(parsk));
&       ENDIF
        ex_output_wanted   := output_during_execution AND
              (acv.a_qualified_jv_upd = no_jv_upd);
        ex_with_link       := false;
        ex_command_needed  := true;
        ex_maxbufs         := parsk.p_no;
        ex_all_rescnt      := 0;
        ex_act_treeid      := b01niltree_id;
        ex_updjv_ptr       := NIL;
        ex_mb_data         := NIL; (* PTS 1112612 *)
        cinfo.co_use_cinfo := false;
        cinfo.co_corr_buf      := NIL;
        old_cinfo.co_corr_buf  := NIL;
        dummybuf           := NIL;
        IF  parsk.p_kind = m_nil
        THEN
            a07_b_put_error (acv, e_invalid_command, a_cmd_part^.sp1p_buf_len);
        (* PTS 1111510 E.Z. *)
        (*ENDIF*) 
        a_curr_ex_parskey  := parsk;
        IF  a_return_segm^.sp1r_returncode = 0
        THEN
            IF  ((parsk.p_kind = m_commit) OR (parsk.p_kind =  m_rollback))
                AND
                ((parsk.p_no = csp_maxint1)   OR
                ( parsk.p_no = csp_maxint1-1) OR
                ( parsk.p_no = csp_maxint1-2))
            THEN
                BEGIN
                IF  a_statement_kind = isql_commands
                THEN
                    IF  parsk.p_kind = m_commit
                    THEN
                        a_statement_kind := icommits
                    ELSE
                        a_statement_kind := irollbacks;
                    (*ENDIF*) 
                (* PTS 1102895 E.Z. *)
                (*ENDIF*) 
                IF  parsk.p_kind = m_commit
                THEN
                    IF  parsk.p_no = csp_maxint1
                    THEN
                        a_return_segm^.sp1r_function_code := csp1_commit_release_fc
                    ELSE
                        a_return_segm^.sp1r_function_code := csp1_commit_fc
                    (*ENDIF*) 
                ELSE
                    IF  parsk.p_no = csp_maxint1
                    THEN
                        a_return_segm^.sp1r_function_code := csp1_rollback_release_fc
                    ELSE
                        a_return_segm^.sp1r_function_code := csp1_rollback_fc;
                    (*ENDIF*) 
                (*ENDIF*) 
                IF  parsk.p_no = csp_maxint1-2
                THEN
                    BEGIN
                    a505next_command (acv, d_sparr, parsk, 0);
                    IF  a_return_segm^.sp1r_returncode = 0
                    THEN
                        a_sqlmode := d_sparr.px[ 1 ]^.sparsinfo.p_sqlmode;
                    (*ENDIF*) 
                    parsk.p_no := csp_maxint1-1;
                    END;
                (*ENDIF*) 
                IF  a_return_segm^.sp1r_returncode = 0
                THEN
                    IF  parsk.p_no = csp_maxint1
                    THEN
                        a52_ex_commit_rollback (acv, parsk.p_kind, c_n_rel,
                              c_normal_release)
                    ELSE
                        IF  parsk.p_no = csp_maxint1-1
                        THEN
                            a52_ex_commit_rollback (acv, parsk.p_kind,
                                  NOT c_n_rel, c_normal_release);
                        (*ENDIF*) 
                    (*ENDIF*) 
                (*ENDIF*) 
                END
            ELSE
                CASE parsk.p_kind OF
                    m_begin, m_end, m_partial_rollback :
                        ak501subtrans (acv, parsk);
                    m_check_database :
                        BEGIN
                        a42_check_database (acv);
                        a_return_segm^.sp1r_function_code := csp1_select_fc;
                        END;
                    m_create_table :
                        a92parse_again (acv, parsk, false); (* PTS 1106286 *)
                    (* CR 1000134 E.Z. *)
                    m_destroy_temp :
                        bd91StartOMSGarbageCollection (a_transinf.tri_trans, c_StartAlways);
                    (* PTS 1102256 E.Z. *)
                    (* PTS 1110053 E.Z. *)
                    m_flush :
                        BEGIN
                        a505next_command (acv, d_sparr, parsk, 0);
                        IF  a_return_segm^.sp1r_returncode = 0
                        THEN
                            BEGIN
                            a_transinf.tri_trans.trError_gg00 := e_ok;
                            kb560StartSavepointAndWait (a_transinf.tri_trans, mm_user);
                            IF  a_transinf.tri_trans.trError_gg00 <> e_ok
                            THEN
                                a07_b_put_error (acv, a_transinf.tri_trans.trError_gg00, 1);
                            (*ENDIF*) 
                            END
                        (*ENDIF*) 
                        END;
                    m_set :
                        a51set_degree (acv);
                    m_stamp :
                        BEGIN
                        a505next_command (acv, d_sparr, parsk, 0);
                        IF  a_return_segm^.sp1r_returncode = 0
                        THEN
                            BEGIN
                            defined_byte := csp_defined_byte;
                            a05_stamp_get (acv, next_stamp, 1, sizeof (next_stamp));
                            a06retpart_move (acv, @defined_byte, 1);
                            a06retpart_move (acv, @next_stamp,
                                  sizeof (next_stamp));
                            a06finish_curr_retpart (acv, sp1pk_data, 1)
                            END
                        (*ENDIF*) 
                        END;
                    m_union :
                        BEGIN
                        a52internal_subtrans (acv);
                        a503union_execution (acv, dmli, change_rec, parsk,
                              output_during_execution)
                        END;
                    m_complex :
                        BEGIN
                        a52internal_subtrans (acv);
                        a502complex_execution (acv, dmli, change_rec, parsk,
                              output_during_execution)
                        END;
                    OTHERWISE
                        BEGIN
                        ex_plus := 0;
                        a505next_command (acv, d_sparr, parsk, ex_plus);
                        IF  a_return_segm^.sp1r_returncode = 0
                        THEN
                            BEGIN
                            CASE parsk.p_kind OF
                                m_close :
                                    BEGIN
                                    a52internal_subtrans (acv);
                                    WITH d_sparr.px[ 1 ]^.sparsinfo DO
                                        a73_close_execute (acv, d_sparr,
                                              p_resn, p_modul_name);
                                    (*ENDWITH*) 
                                    END;
                                m_describe :
                                    WITH d_sparr.px[ 1 ]^.sparsinfo DO
                                        a73_describe_execute (acv, d_sparr,
                                              p_resn, p_modul_name);
                                    (*ENDWITH*) 
                                m_fetch :
                                    ak501fetch_execute (acv, d_sparr);
                                m_mfetch :
                                    ak501mfetch_execute (acv, d_sparr);
                                m_column (*m_fs_dml *) :
                                    BEGIN
                                    d_pos_in_parsbuf := 1;
&                                   IFDEF TRACE
                                    t01int4 (ak_sem, 'pos_in_parsb',
                                          d_pos_in_parsbuf);
                                    t01int4 (ak_sem, 'data_len    ',
                                          acv.a_mblock.mb_data_len );
                                    t01int4 (ak_sem, 'mbp_reclen  ',
                                          acv.a_mblock.mb_data^.mbp_reclen);
&                                   ENDIF
                                    a505fill_mess_buf (acv, dmli, erec, frec,
                                          NOT c_full_part2);
&                                   IFDEF TRACE
                                    t01int4 (ak_sem, 'pos_in_parsb',
                                          d_pos_in_parsbuf);
                                    t01int4 (ak_sem, 'data_len    ',
                                          acv.a_mblock.mb_data_len );
                                    t01int4 (ak_sem, 'mbp_reclen  ',
                                          acv.a_mblock.mb_data^.mbp_reclen);
&                                   ENDIF
                                    a76ex_string_opns (acv, dmli)
                                    END;
                                m_insert, m_insert_select,
                                m_select, m_select_row,
                                m_update, m_delete :
                                    BEGIN
                                    IF  NOT a_stored_proc_call
                                    THEN
                                        a52internal_subtrans (acv);
                                    (*ENDIF*) 
                                    ex_command_needed := false;
                                    ex_plus := ex_plus - 1;
                                    a505loop_most_execute (acv, dmli,
                                          change_rec, erec, parsk,
                                          dummybuf, dummyser,
                                          cinfo, old_cinfo,
                                          NOT c_inner_loop);
                                    END;
                                m_key :
                                    BEGIN
                                    a52internal_subtrans (acv);
                                    ak501key_execute (acv, dmli, change_rec,
                                          parsk, cinfo, old_cinfo, erec)
                                    END;
                                m_usage :
                                    a38ex_usage (acv, parsk);
                                m_drda :
                                    BEGIN
                                    a07_b_put_error (acv, e_not_implemented, 1);
                                    END;
                                OTHERWISE
                                    BEGIN
                                    a52internal_subtrans (acv);
                                    a505most_execute (acv, dmli,
                                          change_rec, parsk, erec, cinfo,
                                          old_cinfo, dummybuf,
                                          NOT c_inner_loop);
                                    END
                                END;
                            (*ENDCASE*) 
                            END
                        (*ENDIF*) 
                        END
                    END;
                (*ENDCASE*) 
            (*ENDIF*) 
        (*ENDIF*) 
        IF  acv.a_return_segm^.sp1r_returncode <> 0 (* PTS 1112612 *)
        THEN
            IF  acv.a_return_segm^.sp1r_returncode = cak_e_dbproc_call
            THEN
                acv.a_return_segm^.sp1r_returncode := 0
            ELSE
                IF  erec.ex_mb_data <> NIL
                THEN
                    BEGIN
                    gg941Deallocate (acv.a_transinf.tri_trans, erec.ex_mb_data);
                    acv.a_mblock.mb_data      := acv.a_mb_data_addr;
                    acv.a_mblock.mb_data_size := acv.a_mb_data_size
                    END;
                (*ENDIF*) 
            (*ENDIF*) 
        (*ENDIF*) 
        END
    (*ENDIF*) 
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a501do_execute (VAR acv : tak_all_command_glob;
            VAR dmli                : tak_dml_info;
            VAR parsk               : tak_parskey;
            output_during_execution : boolean);
 
VAR
      change_rec : tak_changerecord;
 
BEGIN
change_rec.cr_colcount := 0;
change_rec.cr_was_opt  := false;
acv.a_send_messbuf     := true;
acv.a_union_cnt        := 0;
acv.a_command_kind     := single_command;
acv.a_input_data_pos   := 1;
a501exec_with_change_rec (acv, dmli, parsk, change_rec,
      output_during_execution);
acv.a_command_kind     := single_command;
END;
 
(* PTS 1114109, T.A. *)
(*------------------------------*) 
 
PROCEDURE
      a501GetResultName (
            VAR acv : tak_all_command_glob;
            VAR resultName : tsp00_KnlIdentifier);
 
VAR
      movelen    : integer;
      err_char_no: tsp_int4;
      uni_err    : tsp8_uni_error;
 
BEGIN
WITH acv.a_resname_part^ DO
    BEGIN
    resultName := a01_il_b_identifier;
    IF  g01unicode
    THEN
        BEGIN
        movelen := sizeof (resultName);
        s80uni_trans (@sp1p_buf[ 1 ], sp1p_buf_len,
              a542initial_mess_code(acv),  (* PTS 1119569 E.Z. *)
              @resultName, movelen, csp_unicode, [ ],
              uni_err, err_char_no);
        IF  (uni_err <> uni_ok) AND
            (uni_err <> uni_dest_too_short)
        THEN
            a07_b_put_error (acv, e_invalid_tablename, 1)
        (*ENDIF*) 
        END
    ELSE
        BEGIN
        IF  (acv.a_comp_type = at_unknown) OR
            (acv.a_comp_vers < '61100')
        THEN
            a92_map_into_upper (acv, sp1p_buf, 1,
                  sp1p_buf_len, NOT c_uni_map);
        (*ENDIF*) 
        g02fromtermchar (acv.a_mess_code,
              sp1p_buf, 1, sp1p_buf_len);
        IF  sp1p_buf_len > sizeof (resultName)
        THEN
            movelen := sizeof (resultName)
        ELSE
            movelen := sp1p_buf_len;
        (*ENDIF*) 
        g10mv4 ('VAK501',   1,    
              sp1p_buf_size, sizeof (resultName),
              sp1p_buf, 1, resultName, 1, movelen,
              acv.a_return_segm^.sp1r_returncode)
        END
    (*ENDIF*) 
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a501get_resname (VAR acv : tak_all_command_glob;
            VAR dmli : tak_dml_info);
 
BEGIN
dmli.d_resname_found := true;
(* PTS 1114109, T.A. *)
a501GetResultName (acv, dmli.d_resname)
END;
 
(*------------------------------*) 
 
PROCEDURE
      a501execute (VAR acv : tak_all_command_glob;
            VAR parsid : tak_parsid);
 
VAR
      i          : integer;
      appl_info  : integer;
      m_ret      : tsp_int2;
      pp         : tak_parsid;
      fs_tree    : tgg00_FileId;
      dmli       : tak_dml_info;
      change_rec : tak_changerecord;
      cmdid      : tgg_surrogate;
 
BEGIN
IF  g01diag_moni_parse_on
THEN
    a42put_running_cmds(acv, parsid);
(*ENDIF*) 
a01_init_command (acv);
acv.a_send_messbuf   := true;
acv.a_part_rollback  := false;
acv.a_rowno_allowed  := true;
acv.a_union_cnt      := 0;
acv.a_input_data_pos := 1;
acv.a_recursive_state := rs_no_recursive_select;
(* There are two or three parts in a cmd segment:             *)
(* 1.: sp1pk_parseid                                          *)
(* 2.: sp1pk_data                                             *)
(* 3.: sp1pk_resulttablename (optional; note that there is    *)
(*                            no! map into upper name         *)
(*                            (exclusive for 3.1.2. Programs) *)
(*                            because of special identifier)  *)
IF  acv.a_curr_user_name = a01_il_b_identifier
THEN
    a07_b_put_error (acv, e_user_not_connected, 1)
ELSE
    BEGIN
    a54_dml_init (dmli, NOT c_in_union);
    IF  acv.a_resname_part <> NIL
    THEN
        a501get_resname (acv, dmli);
    (*ENDIF*) 
    IF  (parsid.pid_dtime_info[ 1 ] <> chr(ord(dtf_none))) AND
        (parsid.pid_dtime_info[ 1 ] <> chr(ord(acv.a_dt_format)))
    THEN
        a07_b_put_error (acv, e_old_fileversion, 1)
    ELSE
        BEGIN
        acv.a_precomp_info_byte := ord (parsid.pid_appl_info[ 1 ]);
        IF  acv.a_precomp_info_byte >= csp1_p_mass_command
        THEN
            appl_info := acv.a_precomp_info_byte - csp1_p_mass_command
        ELSE
            appl_info := acv.a_precomp_info_byte;
        (*ENDIF*) 
        IF  a01diag_monitor_on OR a01diag_analyze_on
        THEN
            BEGIN
            b21m_parse_again (acv.a_transinf.tri_trans.trBdTcachePtr_gg00,
                  pp.pid_parsk.p_count);
            IF  parsid.pid_parsk.p_count < pp.pid_parsk.p_count
            THEN
                (* parsid was parsed before sys_monitor was installed   *)
                (* therefore the command was NOT stored in parseid-file *)
                (* therefore we have to parse again (see vak92)         *)
                a07_b_put_error (acv, e_old_parsid, 1)
            ELSE
                IF  ( appl_info <> csp1_p_fetch_found ) AND
                    ( appl_info <> csp1_p_describe_found )
                THEN
                    BEGIN
                    b21m_parseid (acv.a_transinf.tri_trans.trBdTcachePtr_gg00, pp);
                    IF  (pp.pid_session.ci4_gg00 <> '    ') AND
                        (ord(pp.pid_parsk.p_kind) <> ord(bsp_c1))
                        (* not counted values stored in b21 *)
                    THEN
                        a545sm_insert(acv);
                    (*ENDIF*) 
                    b21m_reset_monitor (acv.a_transinf.tri_trans.trBdTcachePtr_gg00,
                          c_reset_sum);
                    b21mp_parseid_put (acv.a_transinf.tri_trans.trBdTcachePtr_gg00,
                          parsid);
                    a544get_cmdid (acv, parsid.pid_parsk, cmdid);
                    b21mp_cmdid_put (acv.a_transinf.tri_trans.trBdTcachePtr_gg00,
                          cmdid);
                    IF  acv.a_data_length > 0
                    THEN
                        b21mp_value_put (acv.a_transinf.tri_trans.trBdTcachePtr_gg00,
                              acv.a_data_ptr, acv.a_data_length);
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        IF  acv.a_return_segm^.sp1r_returncode = 0
        THEN
            IF  acv.a_precomp_info_byte >= csp1_p_mass_command
            THEN
                ak501mass_do_execute (acv, dmli,
                      parsid.pid_parsk, change_rec,
                      (acv.a_precomp_info_byte >= csp1_p_mselect_found))
            ELSE
                BEGIN
                (* PTS 1114426 E.Z.*)
                acv.a_mass_all_rescount := 0;
                IF  appl_info = csp1_p_fetch_found
                THEN
                    BEGIN
                    IF  parsid.pid_parsk.p_kind = m_mfetch
                    THEN (* precompiler changed it PREPARE MFETCH --> EXECUTE FETCH *)
                        parsid.pid_parsk.p_kind := m_fetch;
                    (*ENDIF*) 
                    END
                ELSE
                    IF  appl_info = csp1_p_dialog_call
                    THEN (* Stored Procedure execute, call in VAK93 *)
                        acv.a_stored_proc_call := true;
                    (*ENDIF*) 
                (*ENDIF*) 
                a501exec_with_change_rec (acv, dmli,
                      parsid.pid_parsk, change_rec,
                      c_output_during_execution)
                END;
            (*ENDIF*) 
        (*ENDIF*) 
        IF  a01diag_monitor_on OR a01diag_analyze_on
        THEN
            BEGIN
            IF  ((appl_info = csp1_p_mass_select_found)        OR
                ( appl_info = csp1_p_select_for_update_found))
            THEN
                b21mp_is_select (
                      acv.a_transinf.tri_trans.trBdTcachePtr_gg00,
                      c_is_select)
            ELSE
                IF  (acv.a_return_segm^.sp1r_returncode <>
                    a07_return_code (e_old_fileversion, acv.a_sqlmode)) AND
                    (appl_info <> csp1_p_fetch_found)
                    OR
                    (acv.a_return_segm^.sp1r_returncode =
                    a07_return_code (e_row_not_found, acv.a_sqlmode))
                THEN
                    BEGIN
                    b21m_parseid (acv.a_transinf.tri_trans.trBdTcachePtr_gg00, pp);
                    IF  (pp.pid_session.ci4_gg00 <> '    ') AND
                        (ord(pp.pid_parsk.p_kind) <> ord(bsp_c1))
                        (* not counted values stored in b21 *)
                    THEN
                        a545sm_insert(acv);
                    (*ENDIF*) 
                    b21m_reset_monitor (
                          acv.a_transinf.tri_trans.trBdTcachePtr_gg00,
                          c_reset_sum)
                    END
                (*ENDIF*) 
            (*ENDIF*) 
            END
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  acv.a_return_segm^.sp1r_returncode <> 0
THEN
    IF  acv.a_return_segm^.sp1r_returncode <>
        a07_return_code (e_row_not_found, acv.a_sqlmode)
    THEN
        acv.a_part_rollback := acv.a_part_rollback OR
              (acv.a_long_desc_pos = 0);
    (*ENDIF*) 
(*ENDIF*) 
IF  acv.a_from_select
THEN
    BEGIN
    g04build_temp_tree_id (fs_tree, acv.a_transinf.tri_trans);
    (* PTS 1111510 E.Z. *)
    a661_build_t_fromsel_tableid (cmdid, fs_tree.fileTabId_gg00,
          acv.a_curr_ex_parskey, cak_fromseltab_site,
          acv.a_transinf.tri_trans.trSessionId_gg00, 0);
    m_ret                  := acv.a_return_segm^.sp1r_returncode;
    acv.a_return_segm^.sp1r_returncode := 0;
    FOR i := mxak_parskey + 4 TO mxgg_fn DO
        fs_tree.fileName_gg00[ i ] := chr(0);
    (*ENDFOR*) 
    fs_tree.fileZeroSite_gg00 := 0;
    b01prefix_destroy_files (acv.a_transinf.tri_trans,
          fs_tree.fileName_gg00, mxak_parskey + 3);
    acv.a_return_segm^.sp1r_returncode := m_ret;
    END;
(*ENDIF*) 
IF  g01diag_moni_parse_on
THEN
    a42reset_running_cmds(acv);
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak501fetch_execute (VAR acv : tak_all_command_glob;
            VAR sparr : tak_syspointerarr);
 
VAR
      position : tsp_int4;
 
BEGIN
ak501fetch_part (acv, sparr, position);
IF  acv.a_return_segm^.sp1r_returncode = 0
THEN
    BEGIN
    WITH sparr.px[ 1 ]^.sparsinfo DO
        IF  sparr.px[ 2 ]^.sreskey.res_build
        THEN
            a73_one_fetch (acv, sparr, p_mtyp2, position)
        ELSE
            (* PTS 1111576 E.Z. *)
            a74_search_fetch (acv, sparr, p_mtyp2, position,
                  acv.a_resname_addr[ cak_extern_pos ],
                  c_single_fetch, 0);
        (*ENDIF*) 
    (*ENDWITH*) 
    ak501fetch_rest (acv, sparr, c_single)
    END;
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak501fetch_part (VAR acv : tak_all_command_glob;
            VAR sparr         : tak_syspointerarr;
            VAR position      : tsp_int4);
 
VAR
      fill_ret_segm : boolean;
      e             : tgg_basis_error;
      res           : tsp_num_error;
      func_code     : integer;
      p             : tak_parskey;
      pp            : tak_parsid;
      ke            : tgg_sysinfokey;
      nil_parsid    : tak_parsid;
      cmdid         : tgg_surrogate;
 
BEGIN
WITH acv DO
    BEGIN
    IF  a_statement_kind = isql_commands
    THEN
        a_statement_kind := iselects;
    (*ENDIF*) 
    WITH sparr.px[ 1 ]^.sparsinfo DO
        a663_resname (acv, p_resn, p_modul_name,
              a_resname_addr[ cak_extern_pos ], d_fix, 1);
    (*ENDWITH*) 
&   ifdef TRACE
    t01int4 (ak_sem, 'returncode  ', a_return_segm^.sp1r_returncode);
&   endif
    IF  a_return_segm^.sp1r_returncode = 0
    THEN
        BEGIN
        WITH a_resname_addr[ cak_extern_pos ]^.sresname DO
            IF  resselect_fetch = sft_select_all_results
            THEN
                a07_b_put_error (acv, e_invalid_command, 1)
            ELSE
                BEGIN
                fill_ret_segm := true;
                WITH sparr.px[ 1 ]^.sparsinfo DO
                    BEGIN
                    IF  p_function_code > csp1_min_masscmd_fc
                    THEN
                        func_code := p_function_code - csp1_min_masscmd_fc
                    ELSE
                        func_code := p_function_code;
                    (*ENDIF*) 
                    IF  (func_code <> csp1_fetch_relative_fc) AND
                        ((func_code < csp1_fetch_first_fc) OR
                        ( func_code > csp1_fetch_same_fc))
                    THEN (* where pos of *)
                        fill_ret_segm := false;
                    (*ENDIF*) 
                    END;
                (*ENDWITH*) 
                IF  reseparsk.p_kind <> m_nil
                THEN
                    BEGIN
                    (* SELECT was parsed *)
                    s10mv1 (sizeof(sparr.px[1]^.sparsinfo.p_pars_infos[1]),
                          sizeof(p), sparr.px[1]^.sparsinfo.p_pars_infos[1],
                          sizeof(tsp_c4)+1, p, 1, mxak_parskey);
&                   ifdef TRACE
                    t01buf (ak_sem, reseparsk, 1, sizeof(reseparsk));
                    t01buf (ak_sem, p, 1, sizeof(p));
&                   endif
                    IF  ((reseparsk.p_count  <> p.p_count)   OR
                        (reseparsk.p_id[ 1 ] <> p.p_id[ 1 ]) OR
                        (reseparsk.p_kind    <> p.p_kind)    OR
                        (reseparsk.p_no      <> p.p_no))
                    THEN
                        a07_b_put_error (acv, e_old_fileversion, 1)
                    ELSE
                        BEGIN
                        IF  a01diag_monitor_on OR a01diag_analyze_on
                        THEN
                            BEGIN
                            b21m_parseid (acv.a_transinf.tri_trans.trBdTcachePtr_gg00, pp);
                            IF  ((pp.pid_parsk.p_count  <> reseparsk.p_count)   OR
                                (pp.pid_parsk.p_id[ 1 ] <> reseparsk.p_id[ 1 ]) OR
                                (pp.pid_parsk.p_kind    <> reseparsk.p_kind)    OR
                                (pp.pid_parsk.p_no      <> reseparsk.p_no))
                            THEN
                                BEGIN
                                (* other FETCH than that belonging to last executed SELECT *)
                                IF  (pp.pid_session.ci4_gg00 <> '    ') AND
                                    (ord(pp.pid_parsk.p_kind) <> ord(bsp_c1))
                                    (* not counted values stored in b21 *)
                                THEN
                                    a545sm_insert(acv);
                                (*ENDIF*) 
                                b21m_reset_monitor (acv.a_transinf.tri_trans.trBdTcachePtr_gg00,
                                      c_reset_sum);
                                pp.pid_parsk := reseparsk;
                                (* try to build real SELECT parsid this FETCH belongs to *)
                                b21mp_parseid_put (acv.a_transinf.tri_trans.trBdTcachePtr_gg00,
                                      pp);
                                a544get_cmdid (acv, reseparsk, cmdid);
                                b21mp_cmdid_put (acv.a_transinf.tri_trans.trBdTcachePtr_gg00,
                                      cmdid);
                                END;
                            (*ENDIF*) 
                            b21mp_fetch_calls_put (acv.a_transinf.tri_trans.trBdTcachePtr_gg00)
                            END;
                        (*ENDIF*) 
                        IF  fill_ret_segm
                        THEN
                            BEGIN
                            a06retpart_move (acv,
                                  @sparr.px[ 1 ]^.sparsinfo.p_pars_infos[ 1 ],
                                  mxak_parsid);
                            a06finish_curr_retpart (acv, sp1pk_parsid_of_select, 1)
                            END
                        (*ENDIF*) 
                        END
                    (*ENDIF*) 
                    END
                ELSE
                    IF  fill_ret_segm
                    THEN
                        BEGIN
                        s10fil (sizeof(nil_parsid), nil_parsid, 1,
                              sizeof(nil_parsid), chr(0));
                        a06retpart_move (acv, @nil_parsid, mxak_parsid);
                        a06finish_curr_retpart (acv, sp1pk_parsid_of_select, 1)
                        END
                    (*ENDIF*) 
                (*ENDIF*) 
                END
            (*ENDIF*) 
        (*ENDWITH*) 
        END;
&   ifdef TRACE
    (*ENDIF*) 
    t01int4 (ak_sem, 'nach kritisc', 1);
&   endif
    IF  a_return_segm^.sp1r_returncode = 0
    THEN
        BEGIN
        ke := a01sysnullkey;
        WITH ke DO
            BEGIN
            stempid   := a_resname_addr[ cak_extern_pos ]^.sresname.
                  restreeid.fileTempCnt_gg00;
            sentrytyp := cak_ereskey;
            END;
        (*ENDWITH*) 
        a10get_sysinfo (acv, ke, d_fix, sparr.px[ 2 ], e);
        IF  e <> e_ok
        THEN
            a07_b_put_error (acv, e, 1)
        ELSE
            WITH sparr.px[ 2 ]^.sreskey DO
                BEGIN
                WITH sparr.px[ 1 ]^.sparsinfo DO
                    BEGIN
                    position := p_posno;
                    IF  position = csp_maxint2
                    THEN
                        (* PTS 1103929 E.Z. *)
                        IF  a_data_ptr = NIL
                        THEN
                            a07_b_put_error (acv,
                                  e_num_invalid, 1)
                        ELSE
                            BEGIN
                            s40g4int (a_data_ptr^, p_p_no+1, position, res);
                            IF  res <> num_ok
                            THEN
                                CASE res OF
                                    num_invalid :
                                        a07_b_put_error (acv,
                                              e_num_invalid, 1);
                                    num_trunc :
                                        a07_b_put_error (acv,
                                              e_num_truncated, 1);
                                    num_overflow :
                                        a07_b_put_error (acv,
                                              e_num_overflow, 1);
                                    END
                                (*ENDCASE*) 
                            (*ENDIF*) 
                            END;
                        (*ENDIF*) 
                    (*ENDIF*) 
                    END
                (*ENDWITH*) 
                END
            (*ENDWITH*) 
        (*ENDIF*) 
        END
    (*ENDIF*) 
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak501fetch_rest (VAR acv : tak_all_command_glob;
            VAR sparr : tak_syspointerarr;
            single    : boolean);
 
VAR
      e       : tgg_basis_error;
      merror  : tsp_int4;
      mreturn : integer;
      part_ptr: tsp1_part_ptr;
      deleted : boolean;
 
BEGIN
IF  a01diag_monitor_on OR a01diag_analyze_on
THEN
    b21mp_rows_fetched_put (acv.a_transinf.tri_trans.trBdTcachePtr_gg00,
          sparr.px[ 2 ]^.sreskey.res_nextpos);
(*ENDIF*) 
mreturn     := acv.a_return_segm^.sp1r_returncode;
merror      := acv.a_return_segm^.sp1r_errorpos;
deleted     := false;
acv.a_return_segm^.sp1r_returncode := 0;
IF  acv.a_sqlmode = sqlm_oracle
THEN
    BEGIN
    IF  mreturn = a07_return_code (e_row_not_found, acv.a_sqlmode)
    THEN
        BEGIN
        a663_del_result (acv, acv.a_resname_addr[ cak_extern_pos ]^.sresname,
              c_do_cdel, c_del_resname_rec);
        acv.a_resname_addr[ cak_extern_pos ] := NIL;
        deleted := true;
        END
    ELSE
        IF  (NOT single)
            (* PTS 1116801 E.Z. *)
        THEN
            WITH acv DO
                BEGIN
                s26find_part (a_return_segm^, sp1pk_data, part_ptr);
                IF  part_ptr <> NIL
                THEN
                    IF  sp1pa_last_packet in part_ptr^.sp1p_attributes
                    THEN
                        BEGIN
                        a663_del_result (acv,
                              acv.a_resname_addr[ cak_extern_pos ]^.sresname,
                              c_do_cdel, c_del_resname_rec);
                        acv.a_resname_addr[ cak_extern_pos ] := NIL;
                        deleted := true;
                        END
                    (*ENDIF*) 
                (*ENDIF*) 
                END
            (*ENDWITH*) 
        (*ENDIF*) 
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  NOT deleted
THEN
    BEGIN
    a10repl_sysinfo (acv, sparr.px[ 2 ], e);
    IF  e <> e_ok
    THEN
        a07_b_put_error (acv, e, 1)
    ELSE
        acv.a_resname_addr[cak_extern_pos] := NIL;
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  mreturn <> 0
THEN
    BEGIN
    acv.a_return_segm^.sp1r_returncode := mreturn;
    acv.a_return_segm^.sp1r_errorpos   := merror
    END
(*ENDIF*) 
END;
 
(* PTS 1102256 E.Z. *)
(* PTS 1110053 E.Z. *)
(* PTS 1110021 E.Z. *)
(*------------------------------*) 
 
PROCEDURE
      ak501key_execute (VAR acv : tak_all_command_glob;
            VAR dmli       : tak_dml_info;
            VAR change_rec : tak_changerecord;
            VAR parsk      : tak_parskey;
            VAR cinfo      : tak_corr_infos;
            VAR old_cinfo  : tak_corr_infos;
            VAR erec       : tak_exec_rec);
 
VAR
      e             : tgg_basis_error;
      old_erec      : tak_exec_rec;
      frec          : tak_fill_rec;
      i             : integer;
      length        : integer;
      series        : tak68_sequence;
      viewkeybuf    : tak_sysbufferaddress;
      ke            : tgg_sysinfokey;
      result_buffer : tsp_buf;
      pmbp          : tgg_mess_block_ptr;
      pdbp          : tgg_datapart_ptr;
 
BEGIN
IF  acv.a_return_segm^.sp1r_returncode = 0
THEN
    WITH acv, erec, cinfo DO
        BEGIN
        erec.ex_updjv_ptr := @result_buffer;
        IF  acv.a_qualified_jv_upd <> no_jv_upd
        THEN
            g10mv3  ('VAK501',   2,    
                  a_mblock.mb_data_size, sizeof(result_buffer),
                  a_mblock.mb_data^.mbp_buf, 1, result_buffer, 1,
                  a_mblock.mb_data_len, a_return_segm^.sp1r_returncode);
        (*ENDIF*) 
        FOR i := 1 TO cak_maxsources DO
            BEGIN
            series[ i ].jos_source  := i;
            series[ i ].jos_joinno  := csp_maxint1;
            series[ i ].jos_const_param_expr := false;
            END;
        (*ENDFOR*) 
        viewkeybuf       := NIL;
        ke               := dmli.d_sparr.px[ 1 ]^.syskey;
        ke.sentrytyp     := cak_eviewkey;
        ke.slinkage[ 2 ] := chr(1);
        a10_nil_get_sysinfo (acv, ke, d_fix, cak_sysbufferoffset +
              4 + mxsp_key, viewkeybuf, e);
        IF  e <> e_ok
        THEN
            a07_b_put_error (acv, e, 1)
        ELSE
            BEGIN
            ex_with_link           := false;
            old_erec               := erec;
            dmli.d_pos_in_parsbuf  := 1;
            change_rec.cr_colcount := 0;
            frec.fr_f_no                      := 1;
            a505fill_mess_buf (acv, dmli, erec, frec, NOT c_full_part2);
            frec.fr_last_fno := dmli.d_sparr.px[ 1 ]^.sparsinfo.p_cnt_infos;
            a506fieldvalues (acv, dmli, frec, viewkeybuf,
                  a_mblock.mb_data^.mbp_buf, a_mblock.mb_data_size (* PTS 1115085 *));
            IF  a_return_segm^.sp1r_returncode = 0
            THEN
                WITH a_mblock, mb_data^ DO
                    BEGIN
                    pmbp := @dmli.d_sparr.px[ dmli.d_sparr.pcount ]^.
                          smessblock.mbr_mess_block;
                    pdbp := pmbp^.mb_data;
&                   IFDEF TRACE
                    t01int4 (ak_sem, 'pos_in_parsb', dmli.d_pos_in_parsbuf);
                    t01int4 (ak_sem, 'len         ', mb_data_len);
                    t01int4 (ak_sem, 'keylen      ', mbp_keylen);
&                   ENDIF
                    IF  pmbp^.mb_data_len > dmli.d_pos_in_parsbuf
                    THEN
                        BEGIN
                        length := pmbp^.mb_data_len - dmli.d_pos_in_parsbuf + 1;
&                       IFDEF TRACE
                        t01int4 (ak_sem, 'pos_in_parsb', dmli.d_pos_in_parsbuf);
                        t01int4 (ak_sem, 'length      ', length);
                        t01int4 (ak_sem, 'len         ', mb_data_len);
                        t01int4 (ak_sem, 'keylen      ', mbp_keylen);
&                       ENDIF
                        g10mv ('VAK501',   3,    
                              pmbp^.mb_data_size, a_mblock.mb_data_size,
                              pdbp^.mbp_buf, dmli.d_pos_in_parsbuf,
                              a_mblock.mb_data^.mbp_buf, mb_data_len+1,
                              length, a_return_segm^.sp1r_returncode);
                        mb_data_len := mb_data_len + length;
                        dmli.d_pos_in_parsbuf := dmli.d_pos_in_parsbuf +
                              length;
                        END
                    (*ENDIF*) 
                    END;
                (*ENDWITH*) 
            (*ENDIF*) 
            IF  a_return_segm^.sp1r_returncode = 0
            THEN
                BEGIN
                WITH viewkeybuf^.sviewkey DO
                    BEGIN
                    vkjvkeylen := a_mblock.mb_data_len-cgg_rec_key_offset;
                    g10mv2 ('VAK501',   4,    
                          a_mblock.mb_data_size, sizeof(vkjvkey),
                          a_mblock.mb_data^.mbp_buf, cgg_rec_key_offset + 1,
                          vkjvkey, 1, a_mblock.mb_data_len,
                          a_return_segm^.sp1r_returncode);
                    END;
                (*ENDWITH*) 
                END;
            (*ENDIF*) 
            erec := old_erec;
            a505loop_most_execute (acv, dmli, change_rec, erec, parsk,
                  viewkeybuf, series, cinfo, old_cinfo,
                  NOT c_inner_loop);
            IF  a_return_segm^.sp1r_returncode = 0
            THEN
                a60rescount (acv, 1);
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        IF  viewkeybuf <> NIL
        THEN
            a10key_del (acv, viewkeybuf)
        (*ENDIF*) 
        END;
    (*ENDWITH*) 
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak501mass_do_execute (VAR acv : tak_all_command_glob;
            VAR dmli                : tak_dml_info;
            VAR parsk               : tak_parskey;
            VAR change_rec          : tak_changerecord;
            is_mass_select          : boolean);
 
CONST
      c_first_and_only_of_all  =  0;
      c_first_and_only_of_this = -3;
      c_first_of_all           = -2;
      c_last_of_all            = -1;
      c_last_of_this           =  1;
      (* d_mselect_loop_cnt =  0 ==> 1. + only data-packet            *)
      (* d_mselect_loop_cnt = -3 ==> 1. + only data-packet of this msg*)
      (* d_mselect_loop_cnt = -2 ==> 1.        data-packet            *)
      (* d_mselect_loop_cnt = -1 ==> last data-packet                 *)
      (* d_mselect_loop_cnt =  1 ==> last data-packet of this message *)
      (* d_mselect_loop_cnt = >1 ==> any other data-packet            *)
 
VAR
      e                  : tgg_basis_error;
      last_data_packets  : boolean;
      first_data_packets : boolean;
      cmd_count          : tsp_int2;
      command_no         : integer;
      longdescpos        : integer;
      cnt                : integer;
      max_res_id         : tsp_int4;
      save_input_pos     : tsp_int4;
      save_cmd_segm_len  : tsp_int4;
      max_trigger_res_id : tsp_int4;
      save_all_rescnt    : tsp_int4;
      part_desc_ptr      : tsp1_part_ptr;
      one_rescount       : tsp_int4;
      num_err            : tsp_num_error;
      m_parsk            : tak_parskey;
      save_data_ptr      : tsp_moveobj_ptr;
      aux_data_length    : tsp_int4;
      save_data_length   : tsp_int4;
      oldp               : tak_sysbufferaddress;
      ke1                : tgg_sysinfokey;
 
BEGIN
WITH acv DO
    BEGIN
    IF  (a_data_part = NIL) OR (a_rescount_part = NIL)
    THEN
        a07_b_put_error (acv, e_too_short_datapart, 1)
    ELSE
        IF  (a_rescount_part^.sp1p_buf_len < mxsp_resnum)
            OR
            ((a_rescount_part^.sp1p_buf_len < 11) AND
            (a_comp_vers < '62080'))
        THEN
            a07_b_put_error (acv, e_too_short_datapart, 1)
        ELSE
            BEGIN
            (* h.b. CR 1000072 *)
            cmd_count         := a_data_part^.sp1p_arg_count;
            last_data_packets :=
                  (sp1pa_last_packet in a_data_part^.sp1p_attributes);
            first_data_packets :=
                  ((a_comp_vers >= '62090') AND
                  (sp1pa_first_packet in a_data_part^.sp1p_attributes))
                  OR
                  ((a_comp_vers < '62090') AND
                  (a_rescount_part^.sp1p_buf [ 1 ]  = csp_undef_byte));
            IF  first_data_packets
            THEN
                BEGIN
                dmli.d_repl_reskey  := false;
                a_mass_all_rescount := 0;
                END
            ELSE
                BEGIN
                dmli.d_repl_reskey  := true;
                dmli.d_mselect_rescnt := a_mass_all_rescount;
                END;
            (*ENDIF*) 
            command_no        := 0;
            IF  cmd_count = 0
            THEN
                IF  last_data_packets
                THEN
                    BEGIN
                    IF  (a_precomp_info_byte in [
                        csp1_p_mselect_found,
                        csp1_p_for_upd_mselect_found,
                        csp1_p_reuse_mselect_found,
                        csp1_p_reuse_upd_mselect_found])
                        AND
                        (a_mass_all_rescount <> 0)
                    THEN
                        BEGIN
                        ke1 := a01sysnullkey;
                        WITH  a_resname_addr[ cak_extern_pos ]^.sresname.restreeid DO
                            BEGIN
                            ke1.stempid := fileTempCnt_gg00
                            END;
                        (*ENDWITH*) 
                        ke1.sentrytyp := cak_ereskey;
                        a10get_sysinfo (acv, ke1, d_fix, oldp, e);
                        IF  e <> e_ok
                        THEN
                            a07_b_put_error (acv, e, 1);
                        (*ENDIF*) 
                        END
                    (*ENDIF*) 
                    END
                ELSE
                    a07_b_put_error (acv, e_too_short_datapart, 1)
                (*ENDIF*) 
            ELSE
                BEGIN
                a_input_data_pos        := 1;
                (* PTS 1001078 E.Z. *)
                IF  a_data_length = 0
                THEN
                    cmd_count := 1;
                (*ENDIF*) 
                m_parsk                 := parsk;
                dmli.d_mselect_loop_cnt := c_first_of_all;
                IF  cmd_count = 1
                THEN
                    IF  last_data_packets
                    THEN
                        IF  NOT dmli.d_repl_reskey
                        THEN
                            dmli.d_mselect_loop_cnt := c_first_and_only_of_all
                        ELSE
                            dmli.d_mselect_loop_cnt := c_last_of_all
                        (*ENDIF*) 
                    ELSE
                        dmli.d_mselect_loop_cnt := c_first_and_only_of_this;
                    (*ENDIF*) 
                (*ENDIF*) 
                max_res_id              := a_max_res_id;
                max_trigger_res_id      := -1;
                longdescpos             := 1;
                save_data_ptr           := a_data_ptr;
                save_data_length        := a_data_length;
                save_cmd_segm_len       :=
                      a_in_packet^.sp1_segm.sp1s_segm_len;
                REPEAT
                    a_timestamp := bsp_c20;
                    a52internal_subtrans (acv);
                    a_data_ptr       := @a_data_ptr^[a_input_data_pos];
                    a_data_length    := a_data_length - a_input_data_pos + 1;
                    a_input_data_pos := 1;
                    command_no       := succ(command_no);
                    parsk            := m_parsk;
                    a_max_res_id     := max_res_id;
                    (* same result id must be used for all select's *)
                    a501exec_with_change_rec (acv, dmli, parsk, change_rec,
                          c_output_during_execution);
                    IF  command_no < cmd_count
                    THEN
                        IF  dmli.d_mselect_loop_cnt = c_first_of_all
                        THEN
                            BEGIN
                            dmli.d_mselect_loop_cnt := cmd_count - 1;
                            IF  (a_return_segm^.sp1r_function_code
                                = csp1_mselect_into_fc) AND
                                (a_return_segm^.sp1r_returncode = 0) AND
                                (a_curr_retpart^.sp1p_part_kind = sp1pk_data)
                            THEN
                                BEGIN
                                (* cnt results of MSELECT INTO *)
                                (* plus resultcount have to fit *)
                                cnt := (a_curr_retpart^.sp1p_buf_size -
                                      a01aligned_cmd_len (sizeof(tsp_resnum))) DIV
                                      a_curr_retpart^.sp1p_buf_len;
                                IF  cnt < cmd_count
                                THEN
                                    dmli.d_mselect_loop_cnt := cnt - 1;
                                (*ENDIF*) 
                                END;
                            (*ENDIF*) 
                            END
                        ELSE
                            dmli.d_mselect_loop_cnt := pred(dmli.d_mselect_loop_cnt);
                        (*ENDIF*) 
                    (*ENDIF*) 
                    IF  dmli.d_mselect_loop_cnt = c_last_of_this
                    THEN
                        IF  last_data_packets
                        THEN
                            dmli.d_mselect_loop_cnt := c_last_of_all;
                        (*ENDIF*) 
                    (*ENDIF*) 
                    IF  a_return_segm^.sp1r_returncode = 0
                    THEN
                        BEGIN
                        IF  dmli.d_mselect_rescnt = cak_is_undefined
                        THEN
                            BEGIN
                            (* although M-cmd only one data-packet *)
                            (* insert/update/delete *)
                            part_desc_ptr := NIL;
                            a92find_return_part (acv, sp1pk_resultcount,
                                  part_desc_ptr );
                            IF  part_desc_ptr <> NIL
                            THEN
                                BEGIN
                                one_rescount := 0;
                                s40g4int (part_desc_ptr^.sp1p_buf, 2,
                                      one_rescount, num_err);
                                a_mass_all_rescount :=
                                      a_mass_all_rescount + one_rescount;
                                END;
                            (*ENDIF*) 
                            END
                        (*ENDIF*) 
                        END
                    ELSE
                        IF  a_return_segm^.sp1r_returncode =
                            a07_return_code (e_row_not_found, a_sqlmode)
                        THEN
                            BEGIN
                            a_return_segm^.sp1r_returncode := 0;
                            a_part_rollback := false;
                            END;
                        (*ENDIF*) 
                    (*ENDIF*) 
                    part_desc_ptr := NIL;
                    IF  (a_return_segm^.sp1r_function_code = csp1_insert_fc) OR
                        (a_return_segm^.sp1r_function_code = csp1_minsert_fc) OR
                        (a_return_segm^.sp1r_function_code = csp1_update_fc) OR
                        (a_return_segm^.sp1r_function_code = csp1_mupdate_fc)
                    THEN
                        a92find_return_part (acv, sp1pk_longdata,
                              part_desc_ptr );
                    (*ENDIF*) 
                    IF  part_desc_ptr = NIL
                    THEN
                        IF  a_execute_trigger
                        THEN
                            BEGIN
                            (* PTS 1117182 E.Z. *)
                            save_all_rescnt  := a_mass_all_rescount;
                            IF  max_trigger_res_id <> -1
                            THEN
                                a_max_res_id := max_trigger_res_id;
                            (*ENDIF*) 
                            save_input_pos   := a_input_data_pos;
                            aux_data_length  := a_data_length;
                            IF  a_return_segm^.sp1r_returncode = 0
                            THEN
                                a262execute_trigger (acv);
                            (*ENDIF*) 
                            a_input_data_pos := save_input_pos;
                            a_data_length    := aux_data_length;
                            a_execute_trigger := false;
                            a_mass_all_rescount := save_all_rescnt;
                            max_trigger_res_id  := a_max_res_id;
                            END
                        ELSE
                            a52end_rollback_subtrans (acv,
                                  a01_il_b_identifier, m_end);
                        (*ENDIF*) 
                    (*ENDIF*) 
                UNTIL
                    (command_no = cmd_count) OR
                    (a_input_data_pos >= a_data_length) OR
                    (a_return_segm^.sp1r_returncode <> 0);
                (*ENDREPEAT*) 
                a_data_ptr    := save_data_ptr;
                a_data_length := save_data_length;
                a_part_rollback := false;
                IF  ((dmli.d_mselect_loop_cnt = c_last_of_all) OR
                    ( dmli.d_mselect_loop_cnt = c_first_and_only_of_all))
                    AND
                    ((dmli.d_mselect_rescnt = 0) OR
                    ((dmli.d_mselect_rescnt = cak_is_undefined) AND
                    (a_mass_all_rescount = 0)))
                THEN
                    a07_b_put_error (acv, e_row_not_found, -a_input_data_pos);
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            (* do it in any case to have a_resnum filled correctly *)
            IF  ((a_sqlmode = sqlm_oracle) AND is_mass_select)
            THEN
                a60rescount (acv, 0)
            ELSE
                IF  dmli.d_mselect_rescnt = cak_is_undefined
                THEN
                    a60rescount (acv, a_mass_all_rescount)
                ELSE
                    a60rescount (acv, dmli.d_mselect_rescnt);
                (*ENDIF*) 
            (*ENDIF*) 
            IF  dmli.d_mselect_rescnt <> cak_is_undefined
            THEN
                a_mass_all_rescount := dmli.d_mselect_rescnt;
            (*ENDIF*) 
            IF  a_return_segm^.sp1r_returncode = 0
            THEN
                BEGIN
                IF  a_execute_trigger
                THEN
                    a52internal_subtrans (acv);
                (*ENDIF*) 
                IF  dmli.d_repl_reskey
                THEN
                    acv.a_resname_addr[cak_extern_pos] := NIL;
                (*ENDIF*) 
                END
            ELSE
                BEGIN
                a06reset_retpart (acv);
                a_return_segm^.sp1r_errorpos := command_no
                END;
            (*ENDIF*) 
            IF  last_data_packets
            THEN
                a_mass_all_rescount := 0;
            (*ENDIF*) 
            END
        (*ENDIF*) 
    (*ENDIF*) 
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak501mfetch_execute (VAR acv : tak_all_command_glob;
            VAR sparr : tak_syspointerarr);
 
VAR
      position     : tsp_int4;
      res          : tsp_num_error;
      mfetch_count : tsp_int2;
 
BEGIN
WITH acv DO
    BEGIN
    ak501fetch_part (acv, sparr, position);
    IF  a_return_segm^.sp1r_returncode = 0
    THEN
        BEGIN
        IF  (a_rescount_part = NIL)
        THEN
            a07_b_put_error (acv, e_too_short_datapart, 1)
        ELSE
            IF  (a_rescount_part^.sp1p_buf_len < mxsp_resnum)
                OR
                ((a_rescount_part^.sp1p_buf_len < 11) AND
                (a_comp_vers < '62080'))
            THEN
                a07_b_put_error (acv, e_too_short_datapart, 1)
            ELSE
                BEGIN
                s40gsint (a_rescount_part^.sp1p_buf, 2, 10,
                      mfetch_count, res);
                IF  (res <> num_ok) OR
                    (a_rescount_part^.sp1p_buf [ 1 ] <> csp_defined_byte)
                THEN
                    a07_b_put_error (acv, e_too_short_datapart, 1);
                (*ENDIF*) 
                END;
            (*ENDIF*) 
        (*ENDIF*) 
        IF  a_return_segm^.sp1r_returncode = 0
        THEN
            WITH sparr.px[ 1 ]^.sparsinfo DO
                BEGIN
                IF  sparr.px[ 2 ]^.sreskey.res_build
                THEN
                    (* PTS 1111576 E.Z. *)
                    a73_more_fetch (acv, sparr, p_mtyp2,
                          position, mfetch_count)
                ELSE
                    (* PTS 1111576 E.Z. *)
                    a74_search_fetch (acv, sparr, p_mtyp2, position,
                          a_resname_addr[ cak_extern_pos ],
                          NOT c_single_fetch, mfetch_count);
                (*ENDIF*) 
                ak501fetch_rest (acv, sparr, NOT c_single)
                END;
            (*ENDWITH*) 
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak501subtrans (VAR acv : tak_all_command_glob;
            VAR parsk : tak_parskey);
 
VAR
      dummy         : integer;
      subtrans_name : tsp_knl_identifier;
 
BEGIN
WITH acv DO
    BEGIN
    IF  parsk.p_no = csp_maxint1 - 1
    THEN (* no named subtrans *)
        subtrans_name := a01_il_b_identifier
    ELSE
        BEGIN (* savepoint *)
        dummy := 0;
        a505next_command (acv, a_p_arr1, parsk, dummy);
        IF  a_return_segm^.sp1r_returncode = 0
        THEN
            subtrans_name := a_p_arr1.pparsp^.sparsinfo.p_resn
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  a_statement_kind = isql_commands
    THEN
        CASE parsk.p_kind OF
            m_begin :
                a_statement_kind := ibegin_subtrans;
            m_end :
                a_statement_kind := iend_subtrans;
            m_partial_rollback :
                a_statement_kind := irollback_subtrans
            END;
        (*ENDCASE*) 
    (*ENDIF*) 
    CASE parsk.p_kind OF
        m_begin :
            a52new_subtrans (acv, subtrans_name);
        m_end :
            a52end_rollback_subtrans (acv, subtrans_name, m_end);
        m_partial_rollback :
            a52end_rollback_subtrans (acv, subtrans_name, m_rollback);
        END;
    (*ENDCASE*) 
    END;
(*ENDWITH*) 
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
*-PRETTY-*  statements    :        487
*-PRETTY-*  lines of code :       1487        PRETTYX 3.10 
*-PRETTY-*  lines in file :       2576         1997-12-10 
.PA 
