I have a flat file of 10 byte with unknown total record count.
Requirement is [using CLIST]:
1. get the record count of the file
2. read first 5 records in 5 different variable



I have a flat file of 10 byte with unknown total record count. Requirement is [using CLIST]: 1. ge..

Answer / sysprog

ALLOC DD(IN1) DS('SYS2.FILE01.DATA') SHR REU /* allocate input file */
/* set error handler (for EOF) */
ERROR DO
IF &LASTCC=400 THEN DO /* EOF condition raised */
SET EOF EQ Y /* set flag for EOF having occurred */
CLOSFILE IN1 /* close the file */
FREE DD(IN1) /* free the file */
RETURN /* return to the statement following the read that encountered EOF */
END
ELSE EXIT /* some other error so exit */
END
OPENFILE IN1 INPUT /* open the allocated file for input */
SET RECCOUNT EQ 0 /* initialize record count variable */
SET EOF EQ /* initialize EOF flag to empty/blank */
DO WHILE &EOF NE Y /* do until EOF */
READ IN1 /* read a record */
/* use of SET SYSSCAN to handle ampersands that might be present in the record */
/* is not implemented in this example */
IF &EOF NE Y THEN DO /* if a record was read handle it */
SET RECOUNT EQ &RECCOUNT + 1 /* increment record count */
/* set variables REC1 through REC5 to content of first 5 records */
IF & RECOUNT LE 5 THEN SET REC&RECCOUNT EQ &STR(&IN1)
END
END
WRITE RECORD COUNT: &RECCOUNT
SET A EQ 0 /* initialize counter to be used as record array subscript */
/* write out the first 5 records */
DO WHILE &A LT 5
SET A EQ &A + 1
/* set record variable to current record using nested variable */
SET RECORD EQ &STR(&&REC&A )
/* prepend variable name and write record to terminal */
WRITE RECORD&A: &RECORD
END

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More CLIST Interview Questions

What is Time Sharing Option (TSO)?

1 Answers  


How to Execute CLIST?

1 Answers  


What is OS/390?

1 Answers  


What is IBM CLIST (Command List)?

1 Answers  


What is Multiple Virtual Storage (MVS)?

1 Answers  






I have a flat file of 10 byte with unknown total record count. Requirement is [using CLIST]: 1. get the record count of the file 2. read first 5 records in 5 different variable

1 Answers  


Categories