Basis question about "DEFINE/WRITE WORK FILE"

Hi all!

I’ve two questions about DEFINEing WORK FILEs.

I saw a program without a DEFINE WORK FILE statement to a special file. Instead of it there is a CLOSE WORK FILE statement.

The accurate coding is:


Next to the CLOSE WORK FILE is a statement which says: “To assure that a empty file is generated”

1.q - HOW is it possible that Natural know, which FILE in the affected JCL is to be closed??? Because in the job JCL there are two DD defined.
*) first is the ‘TESTFILE’ DD
*) second is the ‘TRASH’ DD

So you see, the ‘TRASH’ DD isn’t the first WORK FILE what is defined.

2.q - IS the use of a work file possible without a DEFINE statement?

Can anybody give me an answer??

Steve aka ‘Nax’

p.s.: Please forgive if my english isn’t very well. I am still learning :slight_smile:

DEFINE WORK FILE is optional. If there isn’t a DEFINE WORK statement, the DDNAME is determined from the file number. For example READ WORK 1 will access the file with DDNAME CMWKF01, WRITE WORK 7 will access DDNAME CMWKF07, and CLOSE WORK 12 will access DDNAME CMWKF12.

The DEFINE WORK statement allows you to override the default DDNAME, as with your TESTFILE example. It also allows you to specify a fully-qualified dataset name, such that no DD statement is needed in the JCL stream.

Work file DDs are named CMWKFnn, i.e. CMWKF01 for Work file 1, CMWKF02 for Work file 2, and so on.

But these can be changed with the DEST subparameter of the Natural parameter WORK, so if you suspect the “TESTFILE” or “TRASH” DDs relate to these workfiles, look for a WORK=((n),DEST=“TESTFILE”) etc. in your Natural batch JCL. There are a number of other ways of specifying parameters, but that should give you an idea :wink:

Thanks a lot! Got the idea!

But one question is still not answered!

I’ve understand the help doc and your answers, the CLOSE WORK FILE statement doesn’t affect the DD TRASH because to do so, it should be named as “CMWKFnn”.



Look again for a DEFINE WORK FILE 1 to verify that it doesn’t point to DDNAME TRASH.

If there is no DEFINE WORK FILE 1, the the CLOSE WORK 1 will point to DDNAME CMWKF01.

If there is a WORK=((1),DEST=“TRASH”), a CLOSE WORK FILE 1 will close “TRASH” rather than CMWKF01 :wink: