/*!***************************************************************************
 
  module      : vkb44
  author      : JuergenA
  responsible : UweH
  special area: KB_stringcol_open_close
  last changed: 2001-05-03
  Copyright (c) 2000-2005 SAP AG
  see also    :
  description :
 
 
 .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
 
 
*****************************************************************************/
 
.tt 1 $SAP$LiveCache$VKB44$
.tt 3 $UweH$KB_stringcol_open_close$$$1999-11-08$
 
Module  : KB_stringcol_open_close
 
Define  :
 
        PROCEDURE
              k44cdelete_column_content (
                    VAR m      : tgg00_MessBlock;
                    VAR shc_id : tgg00_Surrogate);
 
        PROCEDURE
              k44copy_move_shrt_to_bstr_file (
                    VAR mtrans     : tgg00_TransContextPtr;
                    VAR mheader    : tgg00_MessBufHeader;
                    VAR src_tabid  : tgg00_Surrogate;
                    VAR dest_tabid : tgg00_Surrogate;
                    VAR src_tree   : tgg00_FileId;
                    VAR dst_tree   : tgg00_FileId;
                    VAR shc_buf    : tgg00_Rec;
                    use_shc_buf    : boolean;
                    move_shc_entry : boolean);
 
        PROCEDURE
              k44get_shrt_col_rec (
                    mtrans         : tgg00_TransContextPtr;
                    VAR mtree      : tgg00_FileId;
                    VAR shc_buf    : tgg00_Rec;
                    VAR prim_tabid : tgg00_Surrogate;
                    VAR shc_id     : tgg00_Surrogate);
 
        PROCEDURE
              k44get_short_col_rec (
                    VAR m          : tgg00_MessBlock;
                    VAR shc_buf    : tgg00_Rec;
                    VAR prim_tabid : tgg00_Surrogate;
                    VAR shc_id     : tgg00_Surrogate);
 
        PROCEDURE
              k44insdelupdshort_col_rec (
                    VAR mtrans     : tgg00_TransContextPtr;
                    VAR mheader    : tgg00_MessBufHeader;
                    VAR mtree      : tgg00_FileId;
                    VAR shc_buf    : tgg00_Rec;
                    VAR prim_tabid : tgg00_Surrogate;
                    VAR shc_id     : tgg00_Surrogate;
                    mess_type      : tgg00_MessType;
                    use_shc_buf    : boolean);
 
        PROCEDURE
              k44ins_del_upd_short_col_rec (
                    VAR m          : tgg00_MessBlock;
                    VAR shc_buf    : tgg00_Rec;
                    VAR prim_tabid : tgg00_Surrogate;
                    VAR shc_id     : tgg00_Surrogate;
                    mess_type      : tgg00_MessType;
                    use_shc_buf    : boolean);
 
        PROCEDURE
              k44upgrade_to_bstr_file (
                    VAR m          : tgg00_MessBlock;
                    VAR prim_tabid : tgg00_Surrogate;
                    VAR shc_buf    : tgg00_Rec;
                    use_shc_buf    : boolean);
 
.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :
 
        FROM
              KB_stringcol_copy_trunc_expand : VKB43;
 
        PROCEDURE
              k43ttwrite_string (
                    VAR t              : tgg00_TransContext;
                    VAR prim_tabid     : tgg00_Surrogate;
                    VAR curr_file      : tgg00_FileId;
                    VAR curr_long_qual : tgg00_LongQual;
                    buf_size           : tsp00_Int4;
                    buf_addr           : tsp00_MoveObjPtr;
                    inpos              : tsp00_Int4;
                    inlen              : tsp00_Int4;
                    VAR str_vers       : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              KB_ins_del_upd : VKB61;
 
        PROCEDURE
              k61ins_del_upd (VAR m : tgg00_MessBlock);
 
      ------------------------------ 
 
        FROM
              KB_file_table_handling : VKB64;
 
        PROCEDURE
              k64create_bd_file (
                    VAR t          : tgg00_TransContext;
                    VAR tree_id    : tgg00_FileId;
                    mess_type      : tgg00_MessType;
                    mess2_type     : tgg00_MessType2;
                    eFiletypeSet   : tgg00_ExtendedFiletypeSet;
                    str_col_cnt    : tsp00_Int2);
 
        PROCEDURE
              k64drop_lob_tree (
                    VAR t          : tgg00_TransContext;
                    VAR tableid   : tgg00_Surrogate (*ptocSynonym const tgg00_Surrogate&*);
                    VAR file_id    : tgg00_FileId);
&       ifdef TRACE
 
      ------------------------------ 
 
        FROM
              Test_Procedures : VTA01;
 
        PROCEDURE
              t01messblock (
                    debug         : tgg00_Debug;
                    nam           : tsp00_Sname;
                    VAR m         : tgg00_MessBlock);
 
        PROCEDURE
              t01treeid (
                    debug      : tgg00_Debug;
                    nam        : tsp00_Sname;
                    VAR treeid : tgg00_FileId);
&       endif
 
      ------------------------------ 
 
        FROM
              filesysteminterface_1 : VBD01;
 
        VAR
              b01niltree_id : tgg00_FileId;
 
      ------------------------------ 
 
        FROM
              filesysteminterface_2 : VBD02;
 
        PROCEDURE
              b02get_record (
                    VAR t       : tgg00_TransContext;
                    VAR file_id : tgg00_FileId;
                    VAR rk      : tgg00_Lkey;
                    VAR b       : tgg00_Rec);
 
      ------------------------------ 
 
        FROM
              Kernel_move_and_fill : VGG101;
 
        PROCEDURE
              SAPDB_PascalMove (
                    mod_id     : tsp00_C6;
                    mod_num    : tsp00_Int4;
                    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;
                    VAR err    : tgg00_BasisError);
 
      ------------------------------ 
 
        FROM
              Configuration_Parameter : VGG01;
 
        VAR
              g01nil_long_qual  : tgg00_LongQual;
              g01nil_stack_desc : tgg00_StackDesc;
 
        PROCEDURE
              g01mblock_init (
                    VAR source_trans : tgg00_TransContext;
                    mess_type  : tgg00_MessType;
                    mess2_type : tgg00_MessType2;
                    VAR mblock : tgg00_MessBlock);
 
      ------------------------------ 
 
        FROM
              Select_Help_Procedures : VGG04;
 
        PROCEDURE
              g04short_col_tree_build (
                    VAR table_surrogate : tgg00_Surrogate (*ptocConst*);
                    VAR short_col_tree  : tgg00_FileId;
                    VAR b_err           : tgg00_BasisError);
 
.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :
 
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  :
.sp
.cp 3
Created : 1985-02-04
.sp
.cp 3
.sp
.cp 3
Release :      Date : 1999-11-08
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:
.sp 2
.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:
.sp 2
.cm  hier input description
.nf
.fo
.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_use_shc_buf    = true;
      c_move_shc_entry = true;
      (* PTS 1120287 E.Z. *)
 
 
(*------------------------------*) 
 
PROCEDURE
      k44get_short_col_rec (
            VAR m          : tgg00_MessBlock;
            VAR shc_buf    : tgg00_Rec;
            VAR prim_tabid : tgg00_Surrogate;
            VAR shc_id     : tgg00_Surrogate);
 
BEGIN
k44get_shrt_col_rec (m.mb_trns, m.mb_qual^.mtree,
      shc_buf, prim_tabid, shc_id);
END;
 
(*------------------------------*) 
 
PROCEDURE
      k44get_shrt_col_rec (
            mtrans         : tgg00_TransContextPtr;
            VAR mtree      : tgg00_FileId;
            VAR shc_buf    : tgg00_Rec;
            VAR prim_tabid : tgg00_Surrogate;
            VAR shc_id     : tgg00_Surrogate);
 
VAR
      shc_treeid : tgg00_FileId;
      shc_key    : tgg00_Lkey;
 
BEGIN
kb44build_short_col_file_id (mtree, shc_treeid, prim_tabid,
      mtrans^.trError_gg00);
shc_key.len := SURROGATE_MXGG00;
SAPDB_PascalMove ('VKB44 ',   1,    
      sizeof (shc_id), sizeof (shc_key.k),
      @shc_id, 1, @shc_key.k, 1, sizeof (shc_id), mtrans^.trError_gg00);
IF  mtrans^.trError_gg00 = e_ok
THEN
    b02get_record (mtrans^, shc_treeid, shc_key, shc_buf)
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      k44ins_del_upd_short_col_rec (
            VAR m          : tgg00_MessBlock;
            VAR shc_buf    : tgg00_Rec;
            VAR prim_tabid : tgg00_Surrogate;
            VAR shc_id     : tgg00_Surrogate;
            mess_type      : tgg00_MessType;
            use_shc_buf    : boolean);
 
BEGIN
k44insdelupdshort_col_rec(m.mb_trns, m.mb_header, m.mb_qual^.mtree,
      shc_buf, prim_tabid, shc_id, mess_type, use_shc_buf);
END;
 
(*------------------------------*) 
 
PROCEDURE
      k44insdelupdshort_col_rec (
            VAR mtrans     : tgg00_TransContextPtr;
            VAR mheader    : tgg00_MessBufHeader;
            VAR mtree      : tgg00_FileId;
            VAR shc_buf    : tgg00_Rec;
            VAR prim_tabid : tgg00_Surrogate;
            VAR shc_id     : tgg00_Surrogate;
            mess_type      : tgg00_MessType;
            use_shc_buf    : boolean);
 
VAR
      lcl_mbuf        : tgg00_MessBlock;
      mess_datapart   : tgg00_Rec;
      mess_qualpart   : tgg00_QualBuf;
 
BEGIN
g01mblock_init (mtrans^, mess_type, mm_nil, lcl_mbuf);
WITH lcl_mbuf DO
    BEGIN
    mb_header            := mheader;
    mb_data              := @mess_datapart;
    mb_data_size         := sizeof (mess_datapart);
    mb_qual              := @mess_qualpart;
    mb_qual_size         := sizeof (mess_qualpart);
    mb_st                := NIL;
    mb_st_size           := 0;
    mb_st_max            := 0;
    mb_struct            := mbs_stack_addr;
    mb_qual_len          := MB_PART1_HEAD_MXGG00;
    mb_qual^.mstack_desc := g01nil_stack_desc;
    mb_qual^.mfirst_free := 1;
    kb44build_short_col_file_id (mtree, mb_qual^.mtree, prim_tabid,
          mtrans^.trError_gg00);
    mb_type              := mess_type;
    mb_type2             := mm_nil;
    END;
(*ENDWITH*) 
IF  NOT use_shc_buf
THEN
    BEGIN
    SAPDB_PascalMove ('VKB44 ',   2,    
          sizeof (shc_id), lcl_mbuf.mb_data_size,
          @shc_id, 1, @lcl_mbuf.mb_data^.mbp_buf,
          cgg_rec_key_offset + 1, sizeof (shc_id), mtrans^.trError_gg00);
    lcl_mbuf.mb_data^.mbp_keylen := SURROGATE_MXGG00;
    lcl_mbuf.mb_data^.mbp_reclen := cgg_rec_key_offset + SURROGATE_MXGG00;
    END
ELSE
    SAPDB_PascalMove ('VKB44 ',   3,    
          sizeof (shc_buf.buf), lcl_mbuf.mb_data_size,
          @shc_buf.buf, 1,
          @lcl_mbuf.mb_data^.mbp_buf, 1, shc_buf.len, mtrans^.trError_gg00);
(*ENDIF*) 
(* PTS 1104430 E.Z *)
lcl_mbuf.mb_data^.mbp_varcol_offset := 0;
lcl_mbuf.mb_data^.mbp_varcol_cnt    := 0;
lcl_mbuf.mb_data_len := lcl_mbuf.mb_data^.mbp_reclen;
&ifdef TRACE
t01messblock (fs_kb, 'K44INS_DEL_U', lcl_mbuf);
&endif
IF  mtrans^.trError_gg00 = e_ok
THEN
    k61ins_del_upd (lcl_mbuf);
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      k44upgrade_to_bstr_file (
            VAR m          : tgg00_MessBlock;
            VAR prim_tabid : tgg00_Surrogate;
            VAR shc_buf    : tgg00_Rec;
            use_shc_buf    : boolean);
 
BEGIN
k44copy_move_shrt_to_bstr_file (m.mb_trns, m.mb_header, prim_tabid, prim_tabid,
      m.mb_qual^.mtree, m.mb_qual^.mtree, shc_buf, use_shc_buf,
      c_move_shc_entry);
END;
 
(*------------------------------*) 
 
PROCEDURE
      k44copy_move_shrt_to_bstr_file (
            VAR mtrans     : tgg00_TransContextPtr;
            VAR mheader    : tgg00_MessBufHeader;
            VAR src_tabid  : tgg00_Surrogate;
            VAR dest_tabid : tgg00_Surrogate;
            VAR src_tree   : tgg00_FileId;
            VAR dst_tree   : tgg00_FileId;
            VAR shc_buf    : tgg00_Rec;
            use_shc_buf    : boolean;
            move_shc_entry : boolean);
 
VAR
      eFiletypeSet  : tgg00_ExtendedFiletypeSet;
      str_vers      : tsp00_Int4;
      lc_treeid     : tgg00_FileId;
      aux_long_qual : tgg00_LongQual;
 
BEGIN
&ifdef TRACE
t01treeid    (fs_kb, 'src_tree    ', src_tree);
t01treeid    (fs_kb, 'dst_tree    ', dst_tree);
&endif
lc_treeid               := dst_tree;
lc_treeid.fileType_gg00 := [ ftsByteStr_egg00, ftsConcurrent_egg00 ];
lc_treeid.fileVersion_gg00.ci2_gg00 := cgg_dummy_file_version;
lc_treeid.fileTfn_gg00  := tfnColumn_egg00;
eFiletypeSet            := [];
IF  NOT use_shc_buf
THEN
    k44get_shrt_col_rec (mtrans, src_tree, shc_buf, src_tabid,
          src_tree.fileTabId_gg00);
(*ENDIF*) 
IF  mtrans^.trError_gg00 = e_ok
THEN
    k64create_bd_file (mtrans^, lc_treeid, m_create_file, mm_nil,
          eFiletypeSet, 0);
(*ENDIF*) 
IF  (mtrans^.trError_gg00 = e_ok)
    AND (shc_buf.len > cgg_rec_key_offset + SURROGATE_MXGG00)
THEN
    BEGIN
    aux_long_qual := g01nil_long_qual;
    WITH aux_long_qual DO
        BEGIN
        lq_len   := shc_buf.len - cgg_rec_key_offset - SURROGATE_MXGG00;
        lq_pos   := 1;
        str_vers := -MAX_INT4_SP00 + 1;
        k43ttwrite_string  (mtrans^, dest_tabid, lc_treeid,
              aux_long_qual, sizeof (shc_buf.buf), @shc_buf.buf,
              cgg_rec_key_offset + SURROGATE_MXGG00 + 1, lq_len, str_vers);
        END;
    (*ENDWITH*) 
    END;
(*ENDIF*) 
IF  move_shc_entry AND (mtrans^.trError_gg00 = e_ok)
THEN
    k44insdelupdshort_col_rec (mtrans, mheader, src_tree, shc_buf, src_tabid,
          src_tree.fileTabId_gg00, m_delete, NOT c_use_shc_buf);
(*ENDIF*) 
IF  mtrans^.trError_gg00 = e_ok
THEN
    dst_tree := lc_treeid;
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      kb44build_column_file_id (
            VAR m    : tgg00_MessBlock;
            VAR cfd  : tgg04_StringFileDescr);
 
BEGIN
WITH cfd DO
    BEGIN
    str_treeid                   := b01niltree_id;
    str_treeid.fileUserRef_gg00  := m.mb_qual^.mtree.fileUserRef_gg00;
    str_treeid.fileHandling_gg00 := m.mb_qual^.mtree.fileHandling_gg00;
    str_treeid.fileBdUse_gg00    := [];
    str_treeid.fileType_gg00     := [ftsByteStr_egg00, ftsConcurrent_egg00];
    str_treeid.fileTfn_gg00      := tfnColumn_egg00;
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      kb44build_short_col_file_id (
            VAR mtree      : tgg00_FileId;
            VAR shc_treeid : tgg00_FileId;
            VAR shc_tabid  : tgg00_Surrogate;
            VAR b_err      : tgg00_BasisError);
 
BEGIN
shc_treeid                := mtree;
g04short_col_tree_build (shc_tabid, shc_treeid, b_err);
shc_treeid.fileBdUse_gg00 := [];
END;
 
(*------------------------------*) 
 
PROCEDURE
      k44cdelete_column_content (
            VAR m      : tgg00_MessBlock;
            VAR shc_id : tgg00_Surrogate);
 
VAR
      cfd : tgg04_StringFileDescr;
 
BEGIN
kb44build_column_file_id (m, cfd);
cfd.str_treeid.fileTabId_gg00 := shc_id;
IF  m.mb_trns^.trError_gg00 = e_ok
THEN
    k64drop_lob_tree (m.mb_trns^, m.mb_qual^.mtree.fileTabId_gg00, cfd.str_treeid);
(*ENDIF*) 
IF  m.mb_trns^.trError_gg00 = e_file_not_found
THEN
    BEGIN
    m.mb_trns^.trError_gg00 := e_ok;
    IF  m.mb_trns^.trError_gg00 = e_ok
    THEN
        (* mb_data will not be changed - just dummy supply *)
        k44ins_del_upd_short_col_rec (m, m.mb_data^.mbp_rec,
              m.mb_qual^.mtree.fileTabId_gg00,
              shc_id, m_delete, NOT c_use_shc_buf);
    (*ENDIF*) 
    END;
(*ENDIF*) 
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
.PA 
