.CM  SCRIPT , Version - 1.1 , last edited by MANUELA
.ad 8
.bm 8
.fm 4
.bt $Copyright (c) 1998-2004 SAP AG$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $SQL$Project Distributed Database System$VSP20$
.tt 2 $$$
.tt 3 $$RTE-Extension-20$1998-10-28$
***********************************************************
.nf

.nf


    ========== licence begin  GPL
    Copyright (c) 1998-2004 SAP AG

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    ========== licence end

.fo


.fo
.nf
.sp
Module  : RTE-Extension-20
=========
.sp
Purpose : Routines for changing types
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :
 
        PROCEDURE
              s20ch4 (val      : tsp00_Int4;
                    VAR destin : tsp00_MoveObj;
                    destin_pos : tsp00_Int4);
 
        PROCEDURE
              s20ch4a (val     : tsp00_Int4;
                    VAR destin : tsp00_MoveObj;
                    destin_pos : tsp00_Int4);
 
        PROCEDURE
              s20ch4b (val     : tsp00_Int4;
                    VAR destin : tsp00_MoveObj;
                    destin_pos : tsp00_Int4);
 
        PROCEDURE
              s20ch4l (val     : tsp00_Int4;
                    VAR destin : tsp00_MoveObj;
                    destin_pos : tsp00_Int4);
 
        PROCEDURE
              s20ch4sw (val     : tsp00_Int4;
                    source_swap : tsp00_SwapKind;
                    VAR destin  : tsp00_MoveObj;
                    destin_pos  : tsp00_Int4;
                    destin_swap : tsp00_SwapKind);
 
        PROCEDURE
              s20ch4s1 (val     : tsp00_Int4;
                    source_swap : tsp00_SwapKind;
                    VAR destin  : tsp00_MoveObj;
                    destin_pos  : tsp00_Int4;
                    destin_swap : tsp00_SwapKind);
 
        FUNCTION
              s20or4a (VAR source : tsp00_MoveObj;
                    source_pos    : tsp00_Int4) : tsp00_Int4;
 
        FUNCTION
              s20or4b (VAR source : tsp00_MoveObj;
                    source_pos    : tsp00_Int4) : tsp00_Int4;
 
        FUNCTION
              s20or4l (VAR source : tsp00_MoveObj;
                    source_pos    : tsp00_Int4) : tsp00_Int4;
 
        FUNCTION
              s20or4sw (VAR source : tsp00_MoveObj;
                    source_pos     : tsp00_Int4;
                    source_swap    : tsp00_SwapKind;
                    destin_swap    : tsp00_SwapKind) : tsp00_Int4;
 
        FUNCTION
              s204to2 (i4 : tsp00_Int4) : tsp00_Int2;
 
        PROCEDURE
              s20sw_int4 (VAR val  : tsp00_Int4;
                    source_swap    : tsp00_SwapKind;
                    destin_swap    : tsp00_SwapKind);
 
.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :
 
.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :
 
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : 
.sp
.cp 3
Created : 1979-06-07
.sp
.cp 3
Version : 1998-10-28
.sp
.cp 3
Release :      Date : 1998-10-28
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:
 
FUNCTION  LO:
.sp
Stores the second byte of a two-byte integer in a
character byte.
.sp 4
FUNCTION  HI:
.sp
Stores the first byte of a two-byte integer in a
character byte.
.sp 4
FUNCTION  ORD2:
.sp
Forms a two-byte integer from two characters ch1 and ch2
(integer = ch1,ch2);
.sp 4
PROCEDURE CHR2:
.sp
Stores a two-byte integer in a buffer at the position di.
.sp 4
PROCEDURE S20CH4:
.sp
Stores a four-byte integer in a buffer at position di.
.sp 4
PROCEDURE S20CH4A:
.sp
Stores a four-byte integer in a buffer at position di.
.sp 4
PROCEDURE CHR4l:
.sp
Stores a four-byte integer in a buffer at position di
(4 bytes long).
.sp 4
FUNCTION  S20OR4B:
.sp
Fetches a four-byte integer from position si in a buffer.
.sp 4
FUNCTION  S20OR4A:
.sp
Fetches a four-byte integer from position si in a buffer.
.sp 4
FUNCTION  ORD4l:
.sp
Fetches a four-byte integer from position si (4 bytes long)
in a buffer.
.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:
 
 
.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    :
 
 
(*------------------------------*) 
 
PROCEDURE
      s20ch4 (val      : tsp00_Int4;
            VAR destin : tsp00_MoveObj;
            destin_pos : tsp00_Int4);
 
VAR
      i : integer;
 
      help : RECORD
            CASE boolean OF
                TRUE :
                    ( val : tsp00_Int4 ) ;
                FALSE :
                    ( dest : tsp00_C4 ) ;
                END ;
            (*ENDCASE*) 
 
 
BEGIN
help.val := val;
FOR i := 1 TO 4 DO
    destin [destin_pos + i - 1] := help.dest [i]
(*ENDFOR*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      s20ch4a (val     : tsp00_Int4;
            VAR destin : tsp00_MoveObj;
            destin_pos : tsp00_Int4);
 
BEGIN
s20ch4 (val, destin, destin_pos)
END;
 
(*------------------------------*) 
 
PROCEDURE
      s20ch4b (val     : tsp00_Int4;
            VAR destin : tsp00_MoveObj;
            destin_pos : tsp00_Int4);
 
BEGIN
s20ch4 (val, destin, destin_pos)
END;
 
(*------------------------------*) 
 
PROCEDURE
      s20ch4l (val     : tsp00_Int4;
            VAR destin : tsp00_MoveObj;
            destin_pos : tsp00_Int4);
 
VAR
      i : integer;
 
      help : RECORD
            CASE boolean OF
                TRUE :
                    ( val : tsp00_Int4 ) ;
                FALSE :
                    ( dest : tsp00_C4 ) ;
                END ;
            (*ENDCASE*) 
 
 
BEGIN
help.val := val;
FOR i := 1 TO 4 DO
    destin [destin_pos + i - 1] := help.dest [i]
(*ENDFOR*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      s20ch4sw (val     : tsp00_Int4;
            source_swap : tsp00_SwapKind;
            VAR destin  : tsp00_MoveObj;
            destin_pos  : tsp00_Int4;
            destin_swap : tsp00_SwapKind);
 
VAR
      i : integer;
 
      help : RECORD
            CASE boolean OF
                TRUE :
                    ( val : tsp00_Int4 ) ;
                FALSE :
                    ( dest : tsp00_C4 ) ;
                END ;
            (*ENDCASE*) 
 
 
BEGIN
help.val := val;
IF  source_swap = destin_swap
THEN
    FOR i := 1 TO 4 DO
        destin [destin_pos+i-1] := help.dest [i]
    (*ENDFOR*) 
ELSE
    IF  ((source_swap = sw_normal      ) AND
        ( destin_swap = sw_full_swapped))
        OR
        ((source_swap = sw_full_swapped) AND
        ( destin_swap = sw_normal      ))
    THEN
        FOR i := 0 TO 3 DO
            destin [destin_pos+i] := help.dest [4-i]
        (*ENDFOR*) 
    ELSE
        IF  ((source_swap = sw_normal      ) AND
            ( destin_swap = sw_part_swapped))
            OR
            ((source_swap = sw_part_swapped) AND
            ( destin_swap = sw_normal      ))
        THEN
            BEGIN
            destin [destin_pos  ] := help.dest [3];
            destin [destin_pos+1] := help.dest [4];
            destin [destin_pos+2] := help.dest [1];
            destin [destin_pos+3] := help.dest [2]
            END
        ELSE
            BEGIN
            destin [destin_pos  ] := help.dest [2];
            destin [destin_pos+1] := help.dest [1];
            destin [destin_pos+2] := help.dest [4];
            destin [destin_pos+3] := help.dest [3]
            END
        (*ENDIF*) 
    (*ENDIF*) 
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      s20ch4s1 (val     : tsp00_Int4;
            source_swap : tsp00_SwapKind;
            VAR destin  : tsp00_MoveObj;
            destin_pos  : tsp00_Int4;
            destin_swap : tsp00_SwapKind);
 
VAR
      i : integer;
 
      help : RECORD
            CASE boolean OF
                TRUE :
                    ( val : tsp00_Int4 ) ;
                FALSE :
                    ( dest : tsp00_C4 ) ;
                END ;
            (*ENDCASE*) 
 
 
BEGIN
help.val := val;
IF  source_swap = destin_swap
THEN
    FOR i := 1 TO 4 DO
        destin [destin_pos+i-1] := help.dest [i]
    (*ENDFOR*) 
ELSE
    IF  ((source_swap = sw_normal      ) AND
        ( destin_swap = sw_full_swapped))
        OR
        ((source_swap = sw_full_swapped) AND
        ( destin_swap = sw_normal      ))
    THEN
        FOR i := 0 TO 3 DO
            destin [destin_pos+i] := help.dest [4-i]
        (*ENDFOR*) 
    ELSE
        IF  ((source_swap = sw_normal      ) AND
            ( destin_swap = sw_part_swapped))
            OR
            ((source_swap = sw_part_swapped) AND
            ( destin_swap = sw_normal      ))
        THEN
            BEGIN
            destin [destin_pos  ] := help.dest [3];
            destin [destin_pos+1] := help.dest [4];
            destin [destin_pos+2] := help.dest [1];
            destin [destin_pos+3] := help.dest [2]
            END
        ELSE
            BEGIN
            destin [destin_pos  ] := help.dest [2];
            destin [destin_pos+1] := help.dest [1];
            destin [destin_pos+2] := help.dest [4];
            destin [destin_pos+3] := help.dest [3]
            END
        (*ENDIF*) 
    (*ENDIF*) 
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
FUNCTION
      s20or4a (VAR source : tsp00_MoveObj;
            source_pos    : tsp00_Int4) : tsp00_Int4;
 
BEGIN
s20or4a := s20or4b (source, source_pos)
END;
 
(*------------------------------*) 
 
FUNCTION
      s20or4b (VAR source : tsp00_MoveObj;
            source_pos    : tsp00_Int4) : tsp00_Int4;
 
VAR
      i : integer;
 
      help : RECORD
            CASE boolean OF
                TRUE :
                    ( str : PACKED ARRAY [ 1..4 ] OF char ) ;
                FALSE:
                    ( i : tsp00_Int4 ) ;
                END ;
            (*ENDCASE*) 
 
 
BEGIN
FOR i := 1 TO 4 DO
    help.str [i] := source [source_pos+i-1];
(*ENDFOR*) 
s20or4b := help.i
END;
 
(*------------------------------*) 
 
FUNCTION
      s20or4l (VAR source : tsp00_MoveObj;
            source_pos    : tsp00_Int4) : tsp00_Int4;
 
VAR
      i : integer;
 
      help : RECORD
            CASE boolean OF
                TRUE :
                    ( str : PACKED ARRAY [ 1..4 ] OF char ) ;
                FALSE:
                    ( i : tsp00_Int4 ) ;
                END ;
            (*ENDCASE*) 
 
 
BEGIN
FOR i := 1 TO 4 DO
    help.str [i] := source [source_pos+i-1];
(*ENDFOR*) 
s20or4l := help.i
END;
 
(*------------------------------*) 
 
FUNCTION
      s20or4sw (VAR source : tsp00_MoveObj;
            source_pos     : tsp00_Int4;
            source_swap    : tsp00_SwapKind;
            destin_swap    : tsp00_SwapKind) : tsp00_Int4;
 
VAR
      i : integer;
 
      help : RECORD
            CASE boolean OF
                TRUE :
                    ( str : PACKED ARRAY [ 1..4 ] OF char ) ;
                FALSE:
                    ( i : tsp00_Int4 ) ;
                END ;
            (*ENDCASE*) 
 
 
BEGIN
IF  source_swap = destin_swap
THEN
    FOR i := 1 TO 4 DO
        help.str [i] := source [source_pos+i-1]
    (*ENDFOR*) 
ELSE
    IF  ((source_swap = sw_normal      ) AND
        ( destin_swap = sw_full_swapped))
        OR
        ((source_swap = sw_full_swapped) AND
        ( destin_swap = sw_normal      ))
    THEN
        FOR i:= 0 TO 3 DO
            help.str [4-i] := source [source_pos+i]
        (*ENDFOR*) 
    ELSE
        IF  ((source_swap = sw_normal      ) AND
            ( destin_swap = sw_part_swapped))
            OR
            ((source_swap = sw_part_swapped) AND
            ( destin_swap = sw_normal      ))
        THEN
            BEGIN
            help.str [3] := source [source_pos  ];
            help.str [4] := source [source_pos+1];
            help.str [1] := source [source_pos+2];
            help.str [2] := source [source_pos+3]
            END
        ELSE
            BEGIN
            help.str [2] := source [source_pos  ];
            help.str [1] := source [source_pos+1];
            help.str [4] := source [source_pos+2];
            help.str [3] := source [source_pos+3]
            END;
        (*ENDIF*) 
    (*ENDIF*) 
(*ENDIF*) 
s20or4sw:= help.i
END;
 
&IF $OS = MSDOS
(*------------------------------*) 
 
FUNCTION
      s204to2 (i4 : tsp00_Int4) : tsp00_Int2;
 
VAR
 
      help4 : RECORD
            CASE boolean OF
                TRUE :
                    ( val : tsp00_Int4 ) ;
                FALSE :
                    ( dest : tsp00_C4 ) ;
                END ;
            (*ENDCASE*) 
 
 
      help2 : RECORD
            CASE boolean OF
                TRUE :
                    ( val : tsp00_Int2 ) ;
                FALSE :
                    ( dest : tsp00_C2 ) ;
                END ;
            (*ENDCASE*) 
 
 
BEGIN
help4.val := 1;
IF  (help4.dest [ 3 ] = chr (1))
    OR  (help4.dest [ 4 ] = chr (1))
THEN
    BEGIN
    help4.val := i4;
    help2.dest [ 1 ] := help4.dest [ 3 ];
    help2.dest [ 2 ] := help4.dest [ 4 ];
    END
ELSE
    BEGIN
    help4.val := i4;
    help2.dest [ 1 ] := help4.dest [ 1 ];
    help2.dest [ 2 ] := help4.dest [ 2 ];
    END;
(*ENDIF*) 
s204to2 := help2.val;
END; (* int4to2 *)
 
&ELSE
(*------------------------------*) 
 
FUNCTION
      s204to2 (i4 : tsp00_Int4) : tsp00_Int2;
 
BEGIN
s204to2 := i4;
END; (* int4to2 *)
 
&ENDIF
(*------------------------------*) 
 
PROCEDURE
      s20sw_int4 (VAR val  : tsp00_Int4;
            source_swap    : tsp00_SwapKind;
            destin_swap    : tsp00_SwapKind);
 
VAR
      i : integer;
 
      help, res : RECORD
            CASE boolean OF
                TRUE :
                    ( val : tsp00_Int4 ) ;
                FALSE :
                    ( dest : tsp00_C4 ) ;
                END ;
            (*ENDCASE*) 
 
 
BEGIN
IF  source_swap <> destin_swap
THEN
    BEGIN
    help.val := val;
    IF  ((source_swap = sw_normal      ) AND
        ( destin_swap = sw_full_swapped))
        OR
        ((source_swap = sw_full_swapped) AND
        ( destin_swap = sw_normal      ))
    THEN
        FOR i := 0 TO 3 DO
            res.dest [i+1] := help.dest [4-i]
        (*ENDFOR*) 
    ELSE
        IF  ((source_swap = sw_normal      ) AND
            ( destin_swap = sw_part_swapped))
            OR
            ((source_swap = sw_part_swapped) AND
            ( destin_swap = sw_normal      ))
        THEN
            BEGIN
            res.dest [1] := help.dest [3];
            res.dest [2] := help.dest [4];
            res.dest [3] := help.dest [1];
            res.dest [4] := help.dest [2]
            END
        ELSE
            BEGIN
            res.dest [1] := help.dest [2];
            res.dest [2] := help.dest [1];
            res.dest [3] := help.dest [4];
            res.dest [4] := help.dest [3]
            END;
        (*ENDIF*) 
    (*ENDIF*) 
    val := res.val
    END;
(*ENDIF*) 
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
*-PRETTY-*  statements    :         88
*-PRETTY-*  lines of code :        428        PRETTYX 3.10 
*-PRETTY-*  lines in file :        641         1997-12-10 
.PA 
