S Search and Write the Results

S ....=W [file [, C|E|O|Q|BLK] [, file-par|?] [ /[:col:] [ len] [, NS] ] ]

The records flagged as search hits are written to a specified file, or to the last Write file to have been opened.

S .... represents a single/multiple search argument as described in the previous section "Search for Character Strings (Simple/Multiple Search Argument)".

C The output file is closed after the last record is written.

E The output file is opened with Open=Extend.

O An existing output file is overwritten (Open=Output).

Standard: see Notes.

Q Query: For each record that meets the search criteria, the user is asked whether or not that record should be written to the output file. Pressing the DUE1 (ENTER) key will write the record to the output file and continue the search. Pressing the K3 key will prevent the record being written to the file, and the next search result will be offered. Overwriting the predefined S command in the command field will cause the search process to be aborted.

Standard: no Query mode. All records flagged as search hits will be written to the output file without the user being asked.

The E/O and Q options may be combined, separated by a comma.

BLK Write Block: This option is only meaningful if the current Display file is a PAM file, and the Pamkey mode is set (PK command). Specifying this BLK option will cause the blocks belonging to the Pam keys to be written to the output file. Standard: Only the Pam keys are written to a SAM file in Pamkey mode.

file-par File attributes for the output file, using the File or ADD-FILE-LINK command syntax.

Standard: The attributes of the output file are taken from the Display file, with the exception of LOGLEN, VALLEN, VALPROP, DSPACE. If attributes are specified with file-par, then only these are used for the output file. If this case, no attributes from the Display file are taken over to the output file.

Example (parameter using FILE command syntax):

FCBTYPE=SAM,RECFORM=F,RECSIZE=80,BLKSIZE=(STD,16),SPACE=(120,30),VOLUME=PVT001,DEVICE=D3480

Example (parameter using ADD-FILE-LINK command syntax):

ACCESS=*SAM,REC-F=*FIX,REC-S=80,BUFFER-L=*STD(16)

? The SDF dialog facility of the /ADD-FILE-LINK (ADFL) command will be displayed.

The predefined values of the first two parameters (LINK-NAME=WFCB and FILE-NAME=...) may not be modified or deleted.

col Only that section of the record from column :col: is written (:1: represents the beginning of the record). Standard: The entire record is written ( :1: ).

len Starting from the specified column, or the beginning of the record, only len number of bytes will be written. Standard: The maximum record length (up to the end of the record) will be written.

NS No Skip. If the column :col: lies outside of the range to be written, then setting this option will force the relevant records to be written to the Write file. A 4 byte record will be written to the file which will consist of a record length field, but no data.

Standard: Records for which the :col: column range lies outside of the range to be written will not be output to the Write file.

Notes:

ISAM file records with duplicate keys can be written away to the Write file if DUPKEY mode has been set (DUPK command). If DUPKEY mode is not set (standard), then only the last such duplicate key record will be saved in the Write file. If the first of the duplicate key records is the one needed, then the search can be performed from the end of the file to the beginning: S-,...=W... .

The DUPKEY mode that was in force at the time the Write file was opened (the first W / S..=W command) will remain valid. Subsequently changing the DUPKEY mode will have no effect on the Write file until the Display mode is terminated with the K1 key, and then re-activated.

If neither the E nor O option (Extend/Overwrite) is specified after the Write file name, then the following rules are valid:

If the Write file is being accessed for the first time in this current CFS run, then it will always be opened in Overwrite mode, i.e. the file will be created, or overwritten.

If the same Write file is accessed by a succession of W / S...=W commands, then it will be opened as standard in Open=Extend mode.

The E/O option gives the user the chance of setting a different Open mode of operation to the standard.

Examples:

S,:1:>X'0054'=W CFS.REC80

To determine records of a particular length, an Offset command, O-4, can be given to display the record length field as well as the data. Using the Search command above (description of syntax on page 8-), all records of a RECFORM= V file whose data component is longer than 80 bytes will be found. The resulting records will be copied to a file CFS.REC80.

S,L'a',>L'a'+<L'z',L'z'=W CFS.LOWER

All records containing lowercase letters are copied to a file CFS.LOWER. A description of the syntax is on page 8-.

S,'ABC'=W SAVE.ABC,FCBTYPE=SAM/:9:100

A search is made for the string 'ABC' in the Display file, from the first record displayed to the end of the file. 100 bytes of each record containing at least one occurrence of this string will be copied from column 9 to the output file, SAVE.ABC. The output file SAVE.ABC will be created with FCBTYPE=SAM, irrespective of the format of the Display file. Normally, if no file parameters have been specified, the Write file will inherit the file and record formats from the Display file.

Search and Write the Results to a CFS Procedure Variable

S ....=W, (&var) [ /[:col:] [ len] ]

The Display file record that is flagged as a search hit will be written in full or in part to a CFS procedure variable with the specified name.

:col: Only that part of the Display record from column :col: will be copied to the CFS procedure variable (the record begins at :1:).

Standard: The record is copied in full.

len Only len number of bytes are tranfered from the specified column/beginning of record.

Standard: The full length will be written i.e. up to the end of the record. In this case, though, the maximum length is restricted to 80 bytes.

Note:

If multiple records result from the search, only the record last found will be transfered to the CFS procedure variable. If the search proceeds from the end of the file to the beginning (S-), then the first resulting record in the file will be transfered.