Page 1 of 1

Input File Missing? Create it!

PostPosted: Thu Feb 14, 2013 2:11 am
by Eagle
Hello,

I'd like to know if I can use SyncSORT to check if a file exists. If the file does not exist, create it. If it already exists, copy it to a new dataset name. The purpose of doing this would be to generate in input file for my COBOL program in the next job step regardless if the input file exists or not. I can do this in multiple job steps using IDCAMS, but I was hoping to see if SyncSORT had similar functionality that can accomplish this in one step.

Input file attributes:
Record length = 500 bytes
Fixed length

I attempted to do something like this, but I received the following error:
"SORTIN - DATA SET NOT FOUND".

Any information you can provide would be greatly appreciated.

Re: Input File Missing? Create it!

PostPosted: Thu Feb 14, 2013 2:19 am
by Robert Sample
Would COBOL's SELECT OPTIONAL help you?

Re: Input File Missing? Create it!

PostPosted: Thu Feb 14, 2013 2:28 am
by Akatsukami
Note that allocation is done for data sets specified in JCL by JES before the job begins to execute. However, you can do what I think you want to by referencing the data set in a step with a status of MOD.

Re: Input File Missing? Create it!

PostPosted: Thu Feb 14, 2013 9:07 pm
by Alissa Margulies
Hello Eagle.

Akatsukami is on the right track. Here is a sample Sort job that will not modify an existing data set, but will create it if it does not yet exist:
//STEP1 EXEC PGM=SORT                           
//SORTIN  DD DUMMY,DCB=(RECFM=FB,LRECL=500)     
//SYSOUT  DD SYSOUT=*                           
//SORTOUT DD DSN=DATA.SET.NAME,DISP=(MOD,CATLG),
//  SPACE=(CYL,(5,1),RLSE),UNIT=SYSDA       
//SYSIN   DD *                                 
  SORT FIELDS=COPY                           
/*

Hope this helps.

Regards,

Re: Input File Missing? Create it!

PostPosted: Thu Feb 14, 2013 9:30 pm
by Akatsukami
Welcome back, Ms. Margulies :)

Re: Input File Missing? Create it!

PostPosted: Thu Feb 14, 2013 10:07 pm
by Eagle
Thank you ALL for your input.

Perhaps there is another way using SyncSort to check if File A exists. If it exists, copy File A (LRECL=500) to new File B (LRECL=500). If File A does not exist, create File B as a blank file with LRECL=500.

I tried using Rober'ts recommended COBOL SELECT OPTIONAL feature because of security reasons. I am writing code under one system that reads a file from another system. I do not have authority to write a file that does not exist from the other system. In my JCL, I changed my input file disposition to DISP=MOD. Now, when my program executes, I receive a file attribute mismatch error. The input file fromt he other system does not exist, so COBOL throws a File Status 39 error:

IGZ0201W A file attribute mismatch was detected. File SLS-ORDRS-LOAD-FILE in program XMSXAC01 had a record length of
500 and the file specified in the ASSIGN clause had a record length of 80.

How would I change the record length from 80 to 500 of a file that does not exist? I posted this here because Robert Sample had replied with this solution, however, I realize this is no longer a SyncSort issue. I will post this to a different forum, if necessary, however, I welcome a SyncSort solution as well!

Again, I appreciate your time.

Thanks!

Re: Input File Missing? Create it!

PostPosted: Fri Feb 15, 2013 2:06 am
by Eagle
I was able to resolve the file mismatch error by coding DISP=MOD,LRECL=500

However, I was hoping to be able to distinguish between an 'empty' input file and a non-existent input file. That way I could inform the end user which scenario actually occurred. Since I coded the MOD above, I believe the file is temporarily created with an LRECL of 500, which allows the COBOL to obtain a successful file open (Status Code '00') and a successful read (Status Code '00'). I was expecting to get a Status Code '05' since the file did not exist before the step ran, which would allow me to definitively notify the user that the input did not exist. But alas, I'll simply notify the user that the input file either did not exist or was empty. If I don't use MOD, I get a JCL error. Catch 22, I guess.

Thanks again!

Re: Input File Missing? Create it!

PostPosted: Fri Feb 15, 2013 2:56 am
by Robert Sample
A file status 05 code in COBOL will occur if -- and only if -- the file does not have a DD statement in the JCL, and it is coded as SELECT OPTIONAL in COBOL. Once you define the file in the JCL with DISP=MOD, the file exists as far as COBOL is concerned since it was allocated by JES before the COBOL program executed.

Re: Input File Missing? Create it!

PostPosted: Fri Feb 15, 2013 5:11 am
by BillyBoyo
What starts off your job? The arrival of the file from the other system?

If you want to know whether a dataset is catalogued, you can use IDCAMS LISTCAT, and set a return-code so that you can establish the outcome for step(s) in a JOB. Using IDCAMS PRINT you can, if the file exists, "print" one record, which will tell you if the dataset contains data or not, and set a return-code...

Sort can also do the "counting-and-return-code", but if you are using IDCAMS you could do them both at the same time.

I hope that the file contains a header, with at least the business/data date, and hopefuly a "logical filename". A trailer, with record count, hash counts for key fields. Then when the file is processed, all of this can be verified. An "empty" file coming from your other system should contain a header/trailer but no data. Then you know that if you receive an actual empty file, something has "gone up the swanee...".