Line sequential Files contain only characters(DISPLAY) data and instead of having pre- recorded boundaries, records are delimited by newline characters (x’15’).
Things to consider while writing a COBOL-Line Sequential File program
- Select statement
Specify ORGANIZATION IS LINE SEQUENTAL
- You cannot open a line sequential file in I-O mode and you cannot use REWRITE statement.
- On READ, when a newline character is encountered, it will be replaced with the enough space to fill the record as described after FD.
E.g. If the record length in the line sequential file is 10 and in the FD you given the record length as 200 then after READ, FD-variable will contain 10 characters from Line sequential file followed by 190 blank spaces.
- On WRITE trailing spaces are removed and replaced by single newline character .
Things to consider while writing the JCL.
- The ASSIGN TO clause in select statement names an external name
At run time, this external name can have a related DD statement that contains
PATH=’file_path’,FILEDATA=TEXT
Sample Program
Identification Division.
Program-Id. unixfile.
Author . Shibu thannikkunnath.
Environment Division.
Input-Output Section.
FIle-Control.
Select unixfle assign to indd
Organization is line sequential
File status is unixfile-status.
Select zfsfile assign to zfdd
File status is zfsfile-status.
Data division.
File section.
FD unixfle.
01 fs-unix-rec pic x(80).
FD zfsfile.
01 fs-zfs-rec pic x(80).
Working-storage section.
01 unixfile-status pic x(2).
01 zfsfile-status pic x(2).
Eject.
Procedure division.
A00100-MAIN.
Move spaces to unixfile-status.
Perform B00200-WRITE-FILE.
perform C00300-READ-FILE.
stop run.
C00300-READ-FILE.
Open input unixfle.
Display 'Read-Module started'.
If unixfile-status not equal to 00 then
Display 'UNIXFILE-STATUS: ' unixfile-status
Display 'File is not yet ready, Program terminating'
Move 8 to return-code
close unixfle
stop run
else
Perform until unixfile-status = 'en'
read unixfle
at end move 'en'
to unixfile-status
not at end Display fs-unix-rec
end-read
end-perform
close unixfle
end-if.
exit.
B00200-WRITE-FILE.
Open output unixfle.
Open input zfsfile.
Display 'Write-Module Started'.
If unixfile-status not = 00 or zfsfile-status not = 00 then
Display 'UNIXFILE-STATUS: ' unixfile-status
Display 'ZFSFILE-STATUS : ' zfsfile-status
Display 'File is not yet ready, Program terminating'
Move 8 to return-code
close unixfle
close zfsfile
stop run
else
Perform until zfsfile-status = 'en'
read zfsfile
at end move 'en'
to zfsfile-status
not at end
Move fs-zfs-rec
to fs-unix-rec
Write fs-unix-rec
end-read
end-perform
Display 'UNIXFILE-STATUS: ' unixfile-status
Display 'ZFSFILE-STATUS : ' zfsfile-status
close unixfle
close zfsfile
end-if.
exit.
Sample JCL to execute Program
***************************** Top of Data ******************************
//R0318BEJ JOB 'SHIBU THANNIKKUNNATH',REGION=0M,NOTIFY=&SYSUID
//EXECPGM EXEC PGM=UNIXPGM
//INDD DD PATH='/u/workds/helloworld.c',
// FILEDATA=TEXT
//ZFDD DD DSN=TSHRCI.PGMG.C(HLLOWRLD),DISP=SHR
//STEPLIB DD DSN=TSHRCI.LOAD.LIB,DISP=SHR
//SYSIN DD *
/*
//SYSOUT DD SYSOUT=*
//
**************************** Bottom of Data ****************************
No comments:
Post a Comment