PRMSTO.PAS/-AU=
{$E+ External procedure}
{$C
	.TITLE	PRMSTO
	.IDENT	"810708"
}
{
Change Status:

  DATE     BY      DESCRIPTION

08-JUL-81  KGT     Check to see if file has been opened properly before 
                   executing the record operation.  A field in the FAB
                   (CTX) that is available for the user is set by the
                   PrmOpe or PRMCre to +1 if the open/create and connect 
                   were successful.
}
@[300,47]prmconst.pas
CONST
@RMSCONST.PAS
TYPE
@RMSTYPE.PAS
@FAB.PAS
@RAB.PAS
@PrmType.Pas

PROCEDURE PrmSto ( Operation   : RecOps ;	{ specify PPUT or PUPDATE }
                   VAR FileBuf : RmsFileDesc ;	{ file desc. to store into }
                   VAR StoData : StoRecord ;	{ store data specifications }
                   VAR RecBuf  : RecDef ;	{ record buffer to be stored }
                   VAR Status  : RmsStatus);	{ STS & STV returned }
VAR
  RelRan	: BOOLEAN ;
BEGIN
WITH FileBuf DO
WITH StoData DO
BEGIN
IF Fab.Ctx <> 1 
   { Fab.Ctx loaded by PRMOpe or PRMCre, -1 if failure of either call }
  THEN Status[1] := PrIni 	{ file not properly initialized }
  ELSE
    BEGIN
      IF ( (Org = REL ) AND 		{ chk for key value and REL }
           ((Key.Rnum[1]>0) OR (Key.Rnum[2]>0)) 	
         )
        THEN RelRan := TRUE 
        ELSE RelRan := FALSE ;

      IF ( (Fab.Org=chr(FbIdx)) OR (RelRan) )
        THEN Rab.Rac := chr(RbKey) 
        ELSE Rab.Rac := chr(RbSeq) ;	{ seq. file or rel store with no key }

      Rab.Rbf := @RecBuf ;
      Rab.Rsz := Fab.Mrs ;	    	{ set to max. size, may chg. below }
      IF ( (Fab.Rfm=chr(FbVar)) AND 	{ variable format and not REL }
           (Org <> REL) AND
           (RecSize > 0)         )	{ and a record size is specified }
        THEN Rab.Rsz := RecSize ;	{ variable rec. for Org = SEQ or IDX }

      Rab.Kbf := @StoData.Key ;  		{ rec. num for the PUT }

      IF Operation = PPUT
        THEN 
          BEGIN
            {$C
              .mcall $put
              MOV filebuf(sp), r0		; r0 <-- addr of filebuf
              ADD #Rab, r0			; want addr of rab
              $put r0			; Put the record
            }
          END
        ELSE 
          BEGIN
            {$C
              .mcall $update
              MOV filebuf(sp) , r0	; r0 <-- addr. of filebuf 
              ADD #rab, r0		; calc addr. of rab in filebuf
              $update r0			; Update the record
            }
          END ;

      RFAOut[1] := Rab.Rfa.low ;
      RFAOut[2] := Rab.Rfa.middle ;
      RFAOut[3] := Rab.Rfa.high ;
      Status[1] := Rab.Sts ;
      Status[2] := Rab.Stv ;
    END ;  	{ ELSE }
END ;	{ WITH }
END ;
/
