HPlogo Using KSAM XL and KSAM 64 > Appendix B BASIC/V Intrinsics

BKWRITE

MPE documents

Complete PDF
Table of Contents
Index

E0300 Edition 4 ♥
E0394 Edition 3

Writes data from a BASIC program to a KSAM file.

  CALL BKWRITE (filenum,status,parameterlist)

A call to procedure BKWRITE writes a record to a KSAM file from a BASIC program. This call provides the only way to create a KSAM record from a BASIC program. The file must have been opened with an access mode that allows writing. If access is shared, the file also must be opened for dynamic locking (lock = 1), and the file locked with BKLOCK before any records are written.

Parameters


filenum

A numeric variable containing the file number value that identifies the file. This number was returned by the last call to BKOPEN. It should not be altered unless the file is closed by a successful call to BKCLOSE. (Required parameter)

status

A four-character string variable to which is returned a code that indicates whether or not the call to BKWRITE was successful and if not, why not. The first character is set to zero when the call succeeds, to another value if not. (Required parameter)

parameterlist

A list of variables or constants, separated by commas, that contain the data to be written to the file as a record. The total length of the record contents is derived from the total number, the type, and the length in characters of the items in parameterlist. The parameterlist must contain a value for each location defined as a key location in the record. (Required parameter)

Operation Notes


After calling BKWRITE, you should always check the status parameter to ensure that the write was successful. Upon successful completion of BKWRITE, one record containing the values specified in parameterlist is written to the opened KSAM file.

Two parameters that are set when the file is opened affect how BKWRITE operates. These are the access and sequence parameters.

In order to write to a file, the file must be opened with access greater than 0. If the access parameter is set to 1, all existing data in the file is cleared before the first record is written to the file. If access is set to 2 or greater, the first record written by BKWRITE immediately follows any existing records; the file is not cleared.

The sequence parameter determines whether records must be written in primary key sequence, or not. If sequence is 0, records can be written in any order; no check is made on the sequence of the primary key field. If sequence is set to 1, you must write each record with a value in the primary key field that is greater than the primary key value in the previous record. Primary key values may equal the previous primary key value only if the file was created with duplicate key values permitted.


NOTE: Items written to a KSAM file from a BASIC program are concatenated; rounding to halfword boundaries does not occur.

Figure B-13 "Writing to a KSAM File with BKWRITE" is an example of writing one string and one integer array to each record of the KSAM file.

Figure B-13 Writing to a KSAM File with BKWRITE

  10 DIM S$[4]
  20 DIM N$[26]
  30 DIM M$[72]
  40 INTEGER A[10]
  50 DIM B$[12]
  55 INTEGER J
  60 DIM B1$[1]
  65 DIM B2$[2]
  70 INTEGER A2[2],A3[3],A5[5]
  80 REM
  90 REM THE KSAM/3000 FILE WAS BUILT WITH:
 100 REM REC=-80,16,F,ASCII
 110 REM KEY=B,2,2,,DUP
 120 REM SO, RECORD LENGTH IS 2 BYTES, FIXED, TYPE ASCII,
 121 REM   16 REC/BLOCK.
 130 REM THE KEY IS 2 CHARACTERS LONG,STARTING IN CHARACTER 2 OF
 131 REM   RECORD
 135 REM
 .
 .
 .
 430 REM ********************************************************
 440 REM * WRITE TO A KSAM FILE *
 450 REM ********************************************************
 460 REM
 470 REM ASSIGN VALUES TO OUTPUT VARIABLES
 480 REM
 490 FOR I=1 TO 5
 500 A[I]=I
 510 NEXT I
 520 R$="123"
 530 REM
 540 REM F IS THE FILE NUMBER OF A KSAM FILE
 550 REM OPENED BY A CALL TO BKOPEN
 560 REM
 570 REM NOTE THAT ONLY THREE BYTES "123" ARE WRITTEN FROM B$
 580 REM WHEREAS TEN WORDS ARE WRITTEN FROM NUMERIC ARRAY A.
 620 REM
 630 REM THREE IDENTICAL RECORDS ARE BEING OUTPUT SO THAT
 640 REM SUBSEQUENT EXAMPLES OF THIS PROGRAM WILL EXECUTE
 650 REM .
 660 FOR I=1 TO 3
 670 CALL BKWRITE(F,S$,B$,A[*])
 680 REM
 690 REM NOW DETERMINE WHETHER THIS CALL SUCCEEDED
 700 REM
 710 IF S$[1;1]<>"0" THEN DO
 720 REM N$ CONTAINS THE NAME OF THE KSAM FILE
 730 REM S$ CONTAINS THE STATUS CODE SET BY THE PRECEDING CODE
 740 PRINT "UNABLE TO WRITE TO ";N$;"ERROR ";S$[1;1];" DETAIL ";S$[2]
 750 CALL BKERROR(S$,M$)
 760 PRINT M$
 770 GOTO 3620
 780 DOEND
 790 NEXT I
 800 REM
 810 REM THE PROGRAM CONTINUES




BKUNLOCK


Appendix C HP C/iX Example Program