| United States-English |
|
|
|
![]() |
Using KSAM XL and KSAM 64: 900 Series HP 3000 Computer Systems > Appendix A COBOL IntrinsicsCKWRITE |
|
Procedure CKWRITE copies a logical record from the program's data area to an output or an input/output KSAM file.
A call to procedure CKWRITE may be used to write records to a KSAM file either in sequential order or randomly by key value. The file must have been opened for output or for input/output, but not for input only.
The file to which the content of record is written must be open for output only if sequential mode is specified. It may be opened for output or input/output if the access mode at open is random or dynamic. When the file is opened for sequential access (access mode = 0) and for output only (I-O type = 1), then records must be written to the file in ascending sequential order by primary key value. The value of the primary key in the record to be written must be greater than the value of the primary key in any record previously written to the file. This ensures that the records written to the file are initially in ascending order physically as well as logically. When I-O type = 1, CKWRITE writes records starting at the beginning of the file, thereby effectively clearing any records previously written to the file. In a file opened for random or dynamic access (access mode = 1 or 2) and for output only or for input/output (I-O type = 1 or 2), records can be written in any order. The value of the primary key need not be in any particular relation to the primary key values of previously written records. If you want to preserve existing records in the file, you should open the file with the input/output type equal to 2; when input/output type = 1, all existing records are cleared prior to the write. If the file was opened for shared access with CKOPENSHR, then you must lock the file with a call to CKLOCK before writing any records. After the records are written, you should unlock the file with a call to CKUNLOCK. The invalid key condition (left byte of status=2) can occur as a result of the following circumstances:
Assume a KSAM file called KSAMFILE with records containing 74 characters, one primary key containing a name, and an alternate key containing a phone number. The data is read from an input file called DATA-FILE. (Refer to Figure A-2 “Representation of KSAMFILE Used in COBOL Examples” for a diagram of the structure of this file.) The first example writes data to KSAMFILE in sequential order by the primary key.
The second example, using the same DATA DIVISION and the same FINISH procedure, writes one record to the file containing "ADAMSON JOHN" as its primary key value.
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||