.ad 8
.bm 8
.fm 4
.bt $Copyright (c) 2000-2005 SAP AG$$Page %$
.tm 12
.hm 6
.hs 3
.TT 1 $SQL$Project Distributed Database System$VAK91$
.tt 2 $$$
.TT 3 $ElkeZ$Main-Procedure$2001-03-16$
***********************************************************
.nf
 
 .nf
 
    ========== licence begin  GPL
    Copyright (c) 2000-2005 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
 
 
.fo
.nf
.sp
MODULE  : Main-Procedure
=========
.sp
Purpose : This module contains the main procedure of a
          SQL-DB process
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :
 
        FUNCTION
              a91AllocateBuffers (
                    VAR acv : tak_all_command_glob) : boolean;
 
        PROCEDURE
              a91free_mem (
                    VAR acv      : tak_all_command_glob;
                    free_packets : boolean);
 
        PROCEDURE
              a91init_acv (
                    VAR acv : tak_all_command_glob;
                    VAR t : tgg00_TransContext);
 
        PROCEDURE
              a91mainprogram;
 
        PROCEDURE
              a91mainprogam_with_allocator (VAR TransContext : tgg00_TransContext);
 
.CM *-END-* define --------------------------------------
***********************************************************
 
Use     :
 
        FROM
              Scanner : VAK01;
 
        VAR
              a01_il_b_identifier   : tsp00_KnlIdentifier;
 
        PROCEDURE
              a01_parser_init;
 
      ------------------------------ 
 
        FROM
              AK_semantic_scanner_tools : VAk05;
 
        PROCEDURE
              a05init;
 
      ------------------------------ 
 
        FROM
              Systeminfo_cache : VAK10;
 
        PROCEDURE
              a10ak_cache_init;
 
      ------------------------------ 
 
        FROM
              AKDump : VAK102;
 
        FUNCTION
              a102akdump (VAR acv : tak_all_command_glob) : boolean;
 
      ------------------------------ 
 
        FROM
              AK_dialog_tools : VAK260;
 
        PROCEDURE
              a260init;
 
      ------------------------------ 
 
        FROM
              Catalog_Migration_2 : VAK362;
 
        VAR
              a362OnlineTaskId : tsp00_TaskId; (* PTS 1117498 M.Ki. *)
 
      ------------------------------ 
 
        FROM
              AK_universal_show_tools : VAK40;
 
        PROCEDURE
              a40glob_init;
 
      ------------------------------ 
 
        FROM
              AK_show_syntax : VAK41;
 
        PROCEDURE
              a41glob_init;
 
      ------------------------------ 
 
        FROM
              Executing_values : VAK506;
 
        PROCEDURE
              a506_init_numbercheckarray;
 
      ------------------------------ 
 
        FROM
              AK_Connect : VAK51;
 
        PROCEDURE
              a51init_cache_sizes;
 
      ------------------------------ 
 
        FROM
              DML_Help_Procedures : VAK54;
 
        PROCEDURE
              a54_init;
 
      ------------------------------ 
 
        FROM
              Execute_factor_constants : VAK642;
 
        PROCEDURE
              a642colinfo_init;
 
      ------------------------------ 
 
        FROM
              Strategy_Explain : VAK728;
 
        PROCEDURE
              a728_init_strat_texts;
 
      ------------------------------ 
 
        FROM
              Build_Strategy_2 : VAK71;
 
        PROCEDURE
              a71glob_init_accesspath_info;
 
      ------------------------------ 
 
        FROM
              Build_Strategy_Decision : VAK720;
 
        PROCEDURE
              a720glob_init_eval_stat;
 
      ------------------------------ 
 
        FROM
              Deal-With-User-Commands : VAK92;
 
        PROCEDURE
              a92next_pcount (
                    VAR acv   : tak_all_command_glob;
                    VAR parsk : tak_parskey);
 
      ------------------------------ 
 
        FROM
              DBS_Commands : VAK93;
 
        PROCEDURE
              a93_user_commands (
                    VAR acv        : tak_all_command_glob;
                    VAR alloc_ok   : boolean;
                    VAR do_release : boolean);
 
        PROCEDURE
              a93_implicit_commands (
                    VAR acv         : tak_all_command_glob;
                    utility_startup : tsp1_utility_startup);
 
      ------------------------------ 
 
        FROM
              Timeoutprocess : VAK95;
 
        PROCEDURE
              a95_timeout_process (VAR t : tgg00_TransContext);
 
      ------------------------------ 
 
        FROM
              Event-Task : VAK96;
 
        PROCEDURE
              a96eventtask (VAR t : tgg00_TransContext);
&       ifdef SLOW
 
      ------------------------------ 
 
        FROM
              Syntax-Tree-Printer : VAK99;
 
        PROCEDURE
              a99init;
&       endif
 
      ------------------------------ 
 
        FROM
              KB_functions         : VKB05;
 
        PROCEDURE
              k05init;
 
      ------------------------------ 
 
        FROM
              KB_get : vkb71;
 
        PROCEDURE
              k71init;
 
      ------------------------------ 
 
        FROM
              KB_headmaster : VKB38;
 
        PROCEDURE
              k38allocate (
                    pid        : tsp00_TaskId;
                    VAR b_err  : tgg00_BasisError);
 
      ------------------------------ 
 
        FROM
              KB_LogSaveIterator : VKB391;
 
        PROCEDURE
              kb391InitializeWaitLists;
 
      ------------------------------ 
 
        FROM
              KB_Logging : VKB560;
 
        PROCEDURE
              kb560DetermineLocalRedoBufferSizeForTransactions;
 
        PROCEDURE
              kb560LogWriter;
 
      ------------------------------ 
 
        FROM
              KB_restart_record : VKB57;
 
        PROCEDURE
              k57allocate (VAR t : tgg00_TransContext);
 
      ------------------------------ 
 
        FROM
              KB_RefreshSurrogSeq_interface : VKB571;
 
        PROCEDURE
              kb571InitializeWaitList;
 
      ------------------------------ 
 
        FROM
              KB_sender_receiver : VKB90;
 
        PROCEDURE
              k90allocate_netserver (VAR t : tgg00_TransContext);
 
      ------------------------------ 
 
        FROM
              KB_server_task : VKB92;
 
        PROCEDURE
              k92server_process (VAR t : tgg00_TransContext);
 
      ------------------------------ 
 
        FROM
              KernelAdministration_Interface : VGG999;
 
        PROCEDURE
              gg999allocate;
 
      ------------------------------ 
 
        FROM
              filesysteminterface_1 : VBD01;
 
        VAR
              b01niltree_id : tgg00_FileId;
 
        PROCEDURE
              b01setto_zero_full_and_null;
&       ifdef TRACE
 
      ------------------------------ 
 
        FROM
              error_text_handling : VBD06;
 
        VAR
              b06check_rec : boolean;
&       endif
 
      ------------------------------ 
 
        FROM
              pagestore : vbd10;
 
        PROCEDURE
              bd10CreateConverterSingleton;
 
      ------------------------------ 
 
        FROM
              object_garbage_collection : VBD91;
 
        PROCEDURE
              bd91InitOMSGarbageCollection;
 
        PROCEDURE
              bd91StartOMSGarbageCollector (VAR Trans : tgg00_TransContext);
 
      ------------------------------ 
 
        FROM
              Trace : VBD120;
 
        PROCEDURE
              b120CreateTrace( TaskId : tsp00_TaskId );
 
        PROCEDURE
              b120TraceWriter( askId : tsp00_TaskId );
 
      ------------------------------ 
 
        FROM
              systemkeycache : VBD190;
 
        PROCEDURE
              bd190CreateSysKeyCache;
 
      ------------------------------ 
 
        FROM
              IndexMemoryManagementUnit : VBD499;
 
        PROCEDURE
              bd499InitIndexMemory (VAR Trans : tgg00_TransContext);
 
      ------------------------------ 
 
        FROM
              BD_Wrapper : VBD999;
 
        PROCEDURE
              bd999CreatePagerController;
 
        PROCEDURE
              bd999CreatePagerWriter (VAR t : tgg00_TransContext);
 
        PROCEDURE
              bd999CreateFrameControl;
 
        PROCEDURE
              bd999CreateIOManager( TaskId : tsp00_TaskId );
 
      ------------------------------ 
 
        FROM
              RTE_kernel : VEN101;
 
        PROCEDURE
              vconnect (
                    pid                : tsp00_TaskId;
                    VAR net_packet_len : tsp00_Int4;
                    VAR sql_comm_err   : tsp1_comm_error);
 
        PROCEDURE
              vdcom_init_sink (VAR sink_info : tsp_dcom_init_sink_parms);
 
        PROCEDURE
              vfinish;
 
        PROCEDURE
              vgetuktid (VAR uktId : tsp00_Int4);
 
        PROCEDURE
              vinit (
                    VAR rte_comm : tsp00_RteCommAddr;
                    len : tsp00_Int2);
 
        PROCEDURE
              vinitok;
 
        PROCEDURE
              vptype (
                    pid           : tsp00_TaskId;
                    VAR proc_type : tsp2_process_type);
 
        PROCEDURE
              vrelease (pid : tsp00_TaskId);
 
        FUNCTION
              vutil_startup : tsp1_utility_startup;
 
        PROCEDURE
              vversion (
                    VAR kernelversion  : tsp00_Version;
                    VAR runtimeversion : tsp00_Version);
 
        PROCEDURE
              vinit_akdump_ptr(
                    acv_pointer : tsp00_MoveObjPtr;
                    ak_dump_proc: tsp00_MoveObjPtr );
 
      ------------------------------ 
 
        FROM
              Configuration_Parameter : VGG01;
 
        VAR
              g01code    : tgg04_CodeGlobals;
              g01timeout : tgg00_TimeoutGlobals;
 
        PROCEDURE
              g01default_configuration;
 
        PROCEDURE
              g01inittabid;
 
        FUNCTION
              g01kb_work_st_size : tsp00_Int4;
 
        FUNCTION
              g01kb_workbuf_size : tsp00_Int4;
 
        FUNCTION
              g01mb_data_size : tsp00_Int4;
 
        FUNCTION
              g01mb_qual_size : tsp00_Int4;
 
        FUNCTION
              g01mb_stack_size : tsp00_Int4;
 
        FUNCTION
              g01mb_strat_size : tsp00_Int4;
 
        PROCEDURE
              g01transid_init (VAR t : tgg00_TransContext);
 
      ------------------------------ 
 
        FROM
              Codetransformation_and_Coding : VGG02;
 
        PROCEDURE
              g02inittranslate_tables;
 
      ------------------------------ 
 
        FROM
              Check-Date-Time : VGG03;
 
        PROCEDURE
              g03init;
 
      ------------------------------ 
 
        FROM
              GG_cpp_auxiliary_functions : VGG06;
 
        PROCEDURE
              gg06BuildTaskSession (
                    VAR Session : tgg91_SessionNo;
                    TaskType : tsp2_process_type);
 
      ------------------------------ 
 
        FROM
              Regions_and_Longwaits : VGG08;
 
        PROCEDURE
              g08region_ids;
 
      ------------------------------ 
 
        FROM
              Kernel-Version : VGG11;
 
        PROCEDURE
              g11kernel_version  (VAR vers : tsp00_Version);
 
      ------------------------------ 
 
        FROM
              GG_allocator_interface : VGG941;
 
        FUNCTION
              gg941Allocate(
                    VAR TransContext : tgg00_TransContext;
                    wantedBytes : integer) : tsp00_Addr;
 
        PROCEDURE
              gg941CreateAllocatorAndCallMainprog (VAR TransContext : tgg00_TransContext);
 
        PROCEDURE
              gg941Deallocate(
                    VAR TransContext : tgg00_TransContext;
                    VAR p : tsp00_Addr);
 
        PROCEDURE
              Kernel_InitTrace;
 
      ------------------------------ 
 
        FROM
              Kernel_move_and_fill : VGG101;
 
        PROCEDURE
              SAPDB_PascalForcedFill (
                    size     : tsp00_Int4;
                    m        : tsp00_MoveObjPtr;
                    pos      : tsp00_Int4;
                    len      : tsp00_Int4;
                    fillchar : char);
 
        PROCEDURE
              g10mv (
                    mod_id      : tsp00_C6;
                    mod_num     : tsp00_Int4;
                    source_upb  : tsp00_Int4;
                    dest_upb    : tsp00_Int4;
                    source      : tsp00_MoveObjPtr;
                    src_pos     : tsp00_Int4;
                    destin      : tsp00_MoveObjPtr;
                    dest_pos    : tsp00_Int4;
                    length      : tsp00_Int4;
                    VAR e       : tgg00_BasisError);
 
        PROCEDURE
              s10mv (
                    source_upb  : tsp00_Int4;
                    destin_upb  : tsp00_Int4;
                    source      : tsp00_MoveObjPtr;
                    source_pos  : tsp00_Int4;
                    destin      : tsp00_MoveObjPtr;
                    destin_pos  : tsp00_Int4;
                    length      : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              SQLManager : VAK101;
 
        PROCEDURE
              a101_CreateErrorHandler;
 
        PROCEDURE
              a101_InitContextMembers(
                    VAR acv : tak_all_command_glob);
&       ifdef SLOW
 
      ------------------------------ 
 
        FROM
              Test_Procedures : VTA01;
 
        PROCEDURE
              t01sinit;
&       endif
 
.CM *-END-* use -----------------------------------------
***********************************************************
 
Synonym :
 
        PROCEDURE
              gg06BuildTaskSession;
 
              tsp00_Uint1 tsp2_process_type
 
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : ElkeZ
.sp
.cp 3
Created : 1983-07-29
.sp
.cp 3
.sp
.cp 3
Release :      Date : 2000-11-08
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:
 
 
.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:
 
A91MAINPROGRAM
------------------------
 
This is the main procedure of the kernel of SQL-DB.
It is called each time a kernel process is started.
Likewise it is
also used if, after the stack relocation of a user process (e.g. VAX), work is
to be continued after the VRECEIVE.
The RTE procedure VRELOCAT is called, which makes an entry in the pointer
(relocate_info) to a record containing information for the relocation. This
process-specific record contains the information as to whether A91MAINPROGRAM
was called because of the new start of a process or after a stack relocation.
If the stack of the process if relocated, only the ACV_POINTER has the
correct entry in it; all other pointers (Cache, Cachedirectory, Cancel_Byte)
must be altered in A10_STACK_SWAP by the relocation value that has been passed.
Then, it is possible to continue with the processing of user commands
(relocation can happen only to normal user processes).
If, on the other hand, it is the first call of A91MAINPROGRAM,
NOT_RELOCATED_MAIN_PROGRAM is used.
 
NOT_RELOCATED_MAIN_PROGRAM
------------------------
 
The RTE procedure for initialization (VINIT) is called, which, in CANCEL (part
of the Trans_no), returns the address of the boolean to_cancel and stores it
itself. This boolean is set to true by the operator-console command Cancel and
is frequently interrogated in the kernel, so that, if necessary, the processing
of commands can be quickly stopped if so desired by the user.
The Trans_No required by the user processes and by the service process is
completely initialized (the procid is needed for the VPTYPE) and it is asked
from the run-time environment what sort of role this process has to play:
Timeout-, Bufwriter-, Logwriter-, Service- or normal user process (VPTYPE).
If it is a command-processing process (service- or user process),
initializations are performed in RUN_USER_PROCESS, otherwise in
RUN_NON_USER_PROCESS.
 
RUN_USER_PROCESS
------------------------
 
The process-specific variable ACV, which exists through all commands, and the
CACHE are anchored here.
After A91MAINPROGRAM has been first called, the ACV_POINTER must be
initialized with the current address of the ACV. It must have been recorded in
the process that no user has yet connected (current_auth_id); a
default timeout is set, and the cache is initialized.
If it is the service process, it is given an invalid Cancel_Byte, since the
service process must not be cancelled and this is the simplest method of
preventing that. In A94_SERVICE_COMMANDS, the service process waits in an
endless loop for a command, executes it, waits for the next one etc.
If it is a user process, A93_USER_COMMANDS is called in a loop; it executes
a command or is interrupted by the stack relocation and has to be re-started by
A91MAINPROGRAM.
 
RUN_NON_USER_PROCESS
------------------------
 
The 4 different types of processes that do not process commands (2 Logwriter-,
1 Bufwriter-, 1 Timeout processes) are subdivided here and, in VKB55
(Logwriter), VBD999/Pager_Controller ( NOCCPRINT (Bufwriter) and
VAK95 (Timeout), call procedures that
consist of endless loops within which the process is continually re-awoken,
does something and is then sent to sleep again by run-time-environment
mechanisms.
Worthy of particular emphasis is the timeout process, which is the first
process to be created and which starts all initializations that are necessary
for the entire kernel of the SQL-DB system. Only after VINITOK has been called
are other processes also allowed to continue and to process commands.
 
.CM *-END-* description ---------------------------------
***********************************************************
.CM -lll-
Code    :
 
 
CONST
      c_free_packets          = true;
      c_without_communication = true;
 
 
(*------------------------------*) 
 
FUNCTION
      a91AllocateBuffers (
            VAR acv : tak_all_command_glob) : boolean;
 
VAR
      alloc_ok  : boolean;
      _aux_addr : tsp00_Addr;
 
BEGIN
alloc_ok := true;
IF  acv.a_mb_data_addr = NIL
THEN
    BEGIN
    acv.a_mb_data_size := g01mb_data_size;
    _aux_addr := gg941Allocate (acv.a_transinf.tri_trans, acv.a_mb_data_size);
    IF  _aux_addr = NIL
    THEN
        alloc_ok := false
    ELSE
        acv.a_mb_data_addr := @_aux_addr^
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  alloc_ok
THEN
    BEGIN
    IF  acv.a_mb_qual_addr = NIL
    THEN
        BEGIN
        acv.a_mb_qual_size := g01mb_qual_size;
        _aux_addr := gg941Allocate (acv.a_transinf.tri_trans,
              acv.a_mb_qual_size);
        IF  _aux_addr = NIL
        THEN
            alloc_ok := false
        ELSE
            acv.a_mb_qual_addr := @_aux_addr^
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  alloc_ok
    THEN
        BEGIN
        IF  acv.a_stack_addr = NIL
        THEN
            BEGIN
            acv.a_stack_size := g01mb_stack_size;
            _aux_addr := gg941Allocate (acv.a_transinf.tri_trans,
                  acv.a_stack_size);
            IF  _aux_addr = NIL
            THEN
                alloc_ok := false
            ELSE
                acv.a_stack_addr := @_aux_addr^
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        IF  alloc_ok
        THEN
            BEGIN
            IF  acv.a_work_st_addr = NIL
            THEN
                BEGIN
                acv.a_work_st_max := g01kb_work_st_size DIV
                      sizeof (tgg00_StackEntry);
                _aux_addr := gg941Allocate (acv.a_transinf.tri_trans,
                      g01kb_work_st_size);
                IF  _aux_addr = NIL
                THEN
                    alloc_ok := false
                ELSE
                    acv.a_work_st_addr := @_aux_addr^
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            IF  alloc_ok
            THEN
                BEGIN
                IF  acv.a_work_buf_addr = NIL
                THEN
                    BEGIN
                    acv.a_work_buf_size := g01kb_workbuf_size;
                    _aux_addr := gg941Allocate (acv.a_transinf.tri_trans,
                          acv.a_work_buf_size);
                    IF  _aux_addr = NIL
                    THEN
                        acv.a_work_buf_size := 0
                    ELSE
                        acv.a_work_buf_addr := @_aux_addr^;
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
                IF  alloc_ok
                THEN
                    BEGIN
                    IF  acv.a_mb_strat_addr = NIL
                    THEN
                        BEGIN
                        acv.a_mb_strat_size := g01mb_strat_size;
                        _aux_addr := gg941Allocate (acv.a_transinf.tri_trans,
                              acv.a_mb_strat_size);
                        IF  _aux_addr = NIL
                        THEN
                            acv.a_mb_strat_size := 0
                        ELSE
                            acv.a_mb_strat_addr := @_aux_addr^
                        (*ENDIF*) 
                        END;
                    (*ENDIF*) 
                    IF  alloc_ok
                    THEN
                        BEGIN
                        IF  acv.a_mb_value_array = NIL
                        THEN
                            BEGIN
                            acv.a_mb_validx_max := MB_VALIDX_MAX_MXGG00;
                            _aux_addr := gg941Allocate (acv.a_transinf.tri_trans,
                                  acv.a_mb_validx_max * sizeof(tsp00_Int4));
                            IF  _aux_addr = NIL
                            THEN
                                acv.a_mb_validx_max := 0
                            ELSE
                                acv.a_mb_value_array := @_aux_addr^
                            (*ENDIF*) 
                            END;
                        (*ENDIF*) 
                        END
                    ELSE
                        acv.a_mb_validx_max := 0
                    (*ENDIF*) 
                    END
                ELSE
                    acv.a_mb_strat_size := 0;
                (*ENDIF*) 
                END
            ELSE
                acv.a_work_st_max := 0
            (*ENDIF*) 
            END
        ELSE
            acv.a_stack_size := 0
        (*ENDIF*) 
        END
    ELSE
        acv.a_mb_qual_size := 0
    (*ENDIF*) 
    END
ELSE
    acv.a_mb_data_size := 0;
(*ENDIF*) 
IF  alloc_ok
THEN
    BEGIN
    acv.a_mblock.mb_data       := acv.a_mb_data_addr;
    acv.a_mblock.mb_data_size  := acv.a_mb_data_size;
    acv.a_mblock.mb_qual       := acv.a_mb_qual_addr;
    acv.a_mblock.mb_qual_size  := acv.a_mb_qual_size;
    acv.a_mblock.mb_strat      := acv.a_mb_strat_addr;
    acv.a_mblock.mb_strat_size := acv.a_mb_strat_size;
    acv.a_mblock.mb_valuearr   := acv.a_mb_value_array;
    acv.a_mblock.mb_validx_max := acv.a_mb_validx_max;
    END;
(*ENDIF*) 
a91AllocateBuffers := alloc_ok;
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak91connect (
            VAR acv               : tak_all_command_glob;
            without_communication : boolean;
            VAR alloc_ok          : boolean;
            VAR sql_comm_err : tsp1_comm_error);
 
VAR
      _net_packet_size : tsp00_Int4;
      _aux_addr        : tsp00_Addr;
 
BEGIN
WITH acv.a_transinf.tri_trans DO
    BEGIN
    (* PTS 1117012 E.Z. *)
    alloc_ok     := true;
    sql_comm_err := sp1ce_ok;
    IF  without_communication
    THEN
        BEGIN
        (* the utility session will not be supplied with a packet,    *)
        (* if an implicit RESTART or SHUTDOWN is requested by the RTE *)
        _aux_addr := gg941Allocate (acv.a_transinf.tri_trans, 4 * sizeof (tsp00_Buf));
        IF  _aux_addr = NIL
        THEN
            alloc_ok := false
        ELSE
            BEGIN
            acv.a_in_packet := @_aux_addr^;
            WITH acv.a_in_packet^, sp1_header DO
                sp1h_varpart_size := 4 * sizeof (tsp00_Buf) - sizeof (sp1_header)
            (*ENDWITH*) 
            END
        (*ENDIF*) 
        END
    ELSE
        vconnect (trTaskId_gg00, _net_packet_size, sql_comm_err);
    (*ENDIF*) 
    IF  (sql_comm_err = sp1ce_ok) AND (alloc_ok)
    THEN
        alloc_ok := a91AllocateBuffers(acv);
    (*ENDIF*) 
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a91free_mem (
            VAR acv      : tak_all_command_glob;
            free_packets : boolean);
 
VAR
      _aux_addr        : tsp00_Addr;
 
BEGIN
WITH acv.a_transinf.tri_trans DO
    BEGIN
    IF  acv.a_mb_data_addr <> NIL
    THEN
        BEGIN
        _aux_addr := @acv.a_mb_data_addr^;
        gg941Deallocate  (acv.a_transinf.tri_trans, _aux_addr);
        acv.a_mb_data_addr := NIL
        END;
    (*ENDIF*) 
    IF  acv.a_mb_strat_addr <> NIL
    THEN
        BEGIN
        _aux_addr := @acv.a_mb_strat_addr^;
        gg941Deallocate  (acv.a_transinf.tri_trans, _aux_addr);
        acv.a_mb_strat_addr := NIL
        END;
    (*ENDIF*) 
    IF  acv.a_mb_qual_addr <> NIL
    THEN
        BEGIN
        _aux_addr := @acv.a_mb_qual_addr^;
        gg941Deallocate  (acv.a_transinf.tri_trans, _aux_addr);
        acv.a_mb_qual_addr := NIL
        END;
    (*ENDIF*) 
    IF  acv.a_stack_addr <> NIL
    THEN
        BEGIN
        _aux_addr := @acv.a_stack_addr^;
        gg941Deallocate  (acv.a_transinf.tri_trans, _aux_addr);
        acv.a_stack_addr := NIL
        END;
    (*ENDIF*) 
    IF  acv.a_work_st_addr <> NIL
    THEN
        BEGIN
        _aux_addr := @acv.a_work_st_addr^;
        gg941Deallocate  (acv.a_transinf.tri_trans, _aux_addr);
        acv.a_work_st_addr := NIL
        END;
    (*ENDIF*) 
    IF  acv.a_work_buf_addr <> NIL
    THEN
        BEGIN
        _aux_addr := @acv.a_work_buf_addr^;
        gg941Deallocate  (acv.a_transinf.tri_trans, _aux_addr);
        acv.a_work_buf_addr := NIL
        END;
    (*ENDIF*) 
    IF  acv.a_old_packet_p <> NIL
    THEN
        BEGIN
        _aux_addr := @acv.a_old_packet_p^;
        gg941Deallocate  (acv.a_transinf.tri_trans, _aux_addr);
        acv.a_old_packet_p := NIL
        END;
    (*ENDIF*) 
    IF  free_packets
    THEN
        IF  acv.a_in_packet <> NIL
        THEN
            BEGIN
            _aux_addr := @acv.a_in_packet^;
            gg941Deallocate  (acv.a_transinf.tri_trans, _aux_addr);
            acv.a_in_packet := NIL
            END
        (*ENDIF*) 
    (*ENDIF*) 
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a91init_acv (
            VAR acv : tak_all_command_glob;
            VAR t : tgg00_TransContext);
 
VAR
      ix        : integer;
      sink_info : tsp_dcom_init_sink_parms;
      parsk     : tak_parskey;
 
BEGIN
WITH acv DO
    BEGIN
    SAPDB_PascalForcedFill (sizeof(acv), @acv, 1, sizeof(acv), chr (ord (false)));
    a_in_packet             := NIL;
    a_out_packet            := NIL;
    a_cmd_segm              := NIL;
    a_cmd_part              := NIL;
    a_data_part             := NIL;
    a_data_ptr              := NIL;
    a_data_length           := 0;
    a_resname_part          := NIL;
    a_rescount_part         := NIL;
    a_return_segm           := NIL;
    a_ap_tree               := NIL;
    a_mb_data_addr          := NIL;
    a_mb_strat_addr         := NIL;
    a_mb_qual_addr          := NIL;
    a_stack_addr            := NIL;
    a_work_st_addr          := NIL;
    a_work_buf_addr         := NIL;
    a_err_parm_cnt          := 0;
    a_rollback_info         := [];
    a_viewname              := a01_il_b_identifier;
    a_result_name           := a01_il_b_identifier;
    a_init_ex_kind          := only_syntax;
    a_longdemand_data       := NIL;  (* PTS 1122546 D.T. *)
    FOR ix := 1 TO sizeof (a_modul_name) DO
        a_modul_name[ix] := bsp_c1;
    (*ENDFOR*) 
    (* bsp_identifier is correct for modul_name *)
    a_comp_type             := at_unknown;
    a_connected_name        := a01_il_b_identifier;
    a_curr_user_name        := a01_il_b_identifier;
    a_is_exclusive          := true;
    (* PTS 1115978 E.Z. *)
    a_acc_user              := a01_il_b_identifier;
    a_acc_groupname         := a01_il_b_identifier;
    a_acc_dbaname           := a01_il_b_identifier;
    a_trigger_tree          := b01niltree_id;
    a_internalConnection    := false;
    FOR ix := cak_extern_pos TO cak_aux_pos DO
        a_resname_addr[ix] := NIL;
    (*ENDFOR*) 
    a_expl_resname          := a01_il_b_identifier;
    a_show_curr             := b01niltree_id;
    a_pars_curr             := b01niltree_id;
    a_usage_curr            := b01niltree_id;
    a_into_tree             := b01niltree_id;
    a_intern_tree           := b01niltree_id;
    a_intern_res_tree       := b01niltree_id;
    a_intern_cmd_tree       := b01niltree_id;
    a_transinf.tri_trans  := t;
    (* PTS 1111797 E.Z. *)
    a_sqlmode               := sqlm_internal;
    a_user_timeout          := g01timeout.timeCmd_gg00;
    a_use_timeout           := true;
    a_dt_format             := g01code.date_time;
    a_sysdir.ci_cache_p     := NIL;
    a_scv.sc_missing_kw_pos := cak_is_undefined;
    a_len_row_not_found_text:= 0;
    a_old_packet_p          := NIL;
    a_max_codewidth         := 1;
    a_session_max_codewidth := 1;
    a_mess_code             := csp_ascii;
    a_session_mess_code     := csp_ascii;
    a_ak_language           := cak_nls_date_language;
    a_cmd_stack.cst_top     := 0;
    a_explain_kind          := ex_default;
    (* PTS 1114071 E.Z. *)
    a_max_used_pcount[1]    := csp_defined_byte;
    a_max_used_pcount[2]    := csp_defined_byte;
    a_max_used_pcount[3]    := csp_defined_byte;
    a_first_free_pcount     := 0;
    a_last_free_pcount      := cak_max_pcounts;
    FOR ix := 1 TO cak_max_pcounts DO
        BEGIN
        a92next_pcount (acv, parsk);
        a_free_pcounts[ix] := parsk.p_count;
        END;
    (*ENDFOR*) 
    a_planHandle            := NIL;
    a_challenge             := cgg_zero_id;
    a_first_free_pcount     := 1;
    sink_info.acv_addr      := @acv;
    sink_info.sink_addr     := @acv.a_kernel_sink;
    sink_info.sink_size     := sizeof (acv.a_kernel_sink);
    vdcom_init_sink (sink_info);
    a_isInCppDBProcedure    := false; (* PTS 1110148 *)
    vgetuktid(a_allocatorInfo.ai_uktId);
    a_allocatorInfo.ai_alloc_sys.ami_Allocated := 0;
    a_allocatorInfo.ai_alloc_usr.ami_Allocated := 0;
    a_space_option := false; (* PTS 1121403 E.Z. *)
    (* PTS 1121841 E.Z. *)
    a_isReplicationUser     := false;
    a_isReplicationSession  := false;
    FOR ix := 1 TO sizeof(a_replication_check_id) DO
        a_replication_check_id[ix] := chr(0);
    (*ENDFOR*) 
    a_withInternalTriggers  := false;
    a_release_instances     := false;
    a_purgeSharedSqlCache   := false;
    a_purgeAtRollback       := false;
    a101_InitContextMembers(acv);
    a_cmd_id                := 0;
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak91run_non_user_process (
            VAR t     : tgg00_TransContext;
            proc_type : tsp2_process_type);
 
VAR
      hn : tsp00_Version;
      ln : tsp00_Version;
 
BEGIN
gg06BuildTaskSession (t.trSessionId_gg00, proc_type);
CASE proc_type OF
    sp2pt_log_writer:
        kb560LogWriter;
    sp2pt_trace_writer  :
        b120TraceWriter( t.trTaskId_gg00 );
    sp2pt_timeout :
        BEGIN
&       ifdef trace
        b06check_rec := true;
&       endif
&       ifdef SLOW
        a99init;
        t01sinit;
&       endif
        g01default_configuration;
        g08region_ids;
        bd999CreateFrameControl;
        b120CreateTrace( t.trTaskId_gg00 );
        bd999CreateIOManager(t.trTaskId_gg00);
        bd10CreateConverterSingleton;
        bd190CreateSysKeyCache;
        gg999allocate;
        bd999CreatePagerController;
        Kernel_InitTrace;
        a01_parser_init;
        a10ak_cache_init;
        a101_CreateErrorHandler;
        (* PTS 1104572 E.Z. *)
        a40glob_init;
        a41glob_init;
        a260init;
        a51init_cache_sizes;
        a506_init_numbercheckarray;
        k05init;
        k71init;
        b01setto_zero_full_and_null;
        bd91InitOMSGarbageCollection;
        bd499InitIndexMemory (t);
        g02inittranslate_tables;
        g03init;
        g01inittabid;
        a05init;      (* PTS 1121403 E.Z. *)
        a642colinfo_init;
        a54_init;
        a728_init_strat_texts;
        a71glob_init_accesspath_info;
        a720glob_init_eval_stat;
        a362OnlineTaskId := UNDEF_SP00; (* PTS 1117498, 1120287 M.Ki. *)
        g11kernel_version(hn);
        vversion (hn, ln);
        kb391InitializeWaitLists;
        kb560DetermineLocalRedoBufferSizeForTransactions;
        kb571InitializeWaitList;
        k57allocate (t);
        k38allocate (t.trTaskId_gg00, t.trError_gg00);
        k90allocate_netserver (t);
        (* PTS 1003033 E.Z. *)
        (* PTS 1105614 E.Z. *)
        (**********)
        vinitok;
        (**********)
        a95_timeout_process (t)
        END;
    sp2pt_server :
        k92server_process (t);
    sp2pt_data_writer  :
        bd999CreatePagerWriter (t);
    (* PTS 1102365 E.Z. *)
    sp2pt_event :
        a96eventtask (t);
    sp2pt_garbage_collector :
        bd91StartOMSGarbageCollector (t);
    END
(*ENDCASE*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak91run_non_sql_process (VAR acv : tak_all_command_glob);
 
VAR
      alloc_ok            : boolean;
      utility_startup     : tsp1_utility_startup;
      sql_comm_err        : tsp1_comm_error;
      internal_packet_ptr : tsp1_packet_ptr;
 
BEGIN
utility_startup := vutil_startup;
ak91connect (acv, utility_startup <> sp1us_connect, alloc_ok,
      sql_comm_err);
IF  sql_comm_err = sp1ce_ok
THEN
    BEGIN
    IF  utility_startup = sp1us_connect
    THEN
        ak91run_sql_process (acv, false, alloc_ok)
    ELSE
        BEGIN
        internal_packet_ptr := acv.a_in_packet;
        a93_implicit_commands (acv, utility_startup);
        acv.a_in_packet := internal_packet_ptr;
        END;
    (*ENDIF*) 
    a91free_mem (acv, utility_startup <> sp1us_connect)
    END
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak91run_sql_process (
            VAR acv        : tak_all_command_glob;
            connect_needed : boolean;
            old_alloc_ok   : boolean);
 
VAR
      do_release   : boolean;
      alloc_ok     : boolean;
      sql_comm_err : tsp1_comm_error;
      seq_info     : tgg00_CurrSeqInfo;
 
BEGIN
WITH acv, a_transinf, tri_trans DO
    BEGIN
    do_release := false;
    IF  connect_needed
    THEN
        ak91connect (acv, NOT c_without_communication, alloc_ok, sql_comm_err)
    ELSE
        BEGIN
        alloc_ok := old_alloc_ok;
        sql_comm_err := sp1ce_ok;
        END;
    (*ENDIF*) 
    (* PTS 1110096 E.Z. *)
    seq_info.csi_cnt  := 0;
    trSeqInfoPtr_gg00 := @seq_info;
    trAcvPtr_gg00     := @acv;
    IF  sql_comm_err = sp1ce_ok
    THEN
        BEGIN
        WHILE NOT do_release DO
            a93_user_commands (acv, alloc_ok, do_release);
        (*ENDWHILE*) 
        vrelease (trTaskId_gg00);
        a91free_mem (acv, NOT c_free_packets)
        END
    (*ENDIF*) 
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak91run_user_process (
            VAR t     : tgg00_TransContext;
            proc_type : tsp2_process_type);
 
VAR
      acv              : tak_all_command_glob;
 
BEGIN
WITH acv, a_transinf, tri_trans DO
    BEGIN
    (* h.b. CR 1103950 *)
    vinit_akdump_ptr (@acv, @a102akdump(acv));
    a91init_acv (acv, t);
    IF  proc_type = sp2pt_utility
    THEN
        ak91run_non_sql_process (acv)
    ELSE
        BEGIN
        a_in_session := false;
        ak91run_sql_process (acv, true, true);
        END
    (*ENDIF*) 
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      a91mainprogram;
 
VAR
      TransContext : tgg00_TransContext;
 
BEGIN
(* PTS 1108234 JA 2000-11-08 *)
g01transid_init (TransContext);
vinit (TransContext.trRteCommPtr_gg00, RTE_COMM_MXSP00);
gg941CreateAllocatorAndCallMainprog (TransContext);
ak91call_vfinish_if_necessary (TransContext.trTaskId_gg00)
END;
 
(*------------------------------*) 
 
PROCEDURE
      a91mainprogam_with_allocator (VAR TransContext : tgg00_TransContext);
 
VAR
      proc_type : tsp2_process_type;
 
BEGIN
(* PTS 1108234 JA 2000-11-08 *)
vptype (TransContext.trTaskId_gg00, proc_type);
IF  proc_type in [ sp2pt_utility, sp2pt_user ]
THEN
    ak91run_user_process (TransContext, proc_type)
ELSE
    ak91run_non_user_process (TransContext, proc_type)
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak91call_vfinish_if_necessary (task_id : tsp00_TaskId);
 
VAR
      proc_type : tsp2_process_type;
 
BEGIN
vptype (task_id, proc_type);
IF  proc_type in [ sp2pt_user, sp2pt_event ]
THEN
    vfinish
(*ENDIF*) 
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
.PA 
