Reading a work file in Natural under CICS

Perhaps someone can help me with my problem/situation.

At my installation, we run Natural under both TSO and CICS but all online applications run under CICS. I have a Natural process (under CICS) where a user can initiate a batch process (Natural running under TSO) where they can optionally specify a TSO dataset as job input.

What I want to do in my Natural online program is to dynamically allocate this dataset as a work file (e.g. CMWKF01) only for the duration of this process. I want to ensure that the dataset exists (obviously the allocation fails if it does not exist) and trap allocation failure this to send an appropriate message to the screen via REINPUT.

If the dataset does exist, I want to determine the number of records in the file and take some action, depending on the number of records. In my case, if there are more than 200 records the batch job will be submitted for overnight processing, otherwise it will be submitted for immediate processing.

Anyone here done something similar and would be willing to share?

Check out the API USR2021N to see if it will work for you.

Douglas, thanks for the pointer.

I’ve managed to use USR2021N as a method to verify the existence of the specified file. Now I’m playing around trying to read that file to count the records. Halfway there!

I’m still having problems reading the allocated work file. Here’s the essentials of the code:

CALLNAT ‘ABC123’ /* routine to allocate dataset to CMWKF01
IF “allocation worked”
INPUT (AD=O) #I #REC (AL=40)

I consistently get the error “NAT1500 Open for WORK file 1 failed”.


I’ve tried putting a DEFINE WORK FILE 1 ‘CMWKF01’ statement before the READ WORK statement and still get the NAT1500 error.

Any suggestions?

I believe that under CICS, WORK files are implemented as Transient Data Queues (TDQ) only (i.e. temporary storage). The following example works under TSO, but not under CICS.

To read a flat file, you’ll need to run your program under TSO (or in batch).

DEFINE DATA LOCAL                               
1 #W (A75)                                     
READ WORK 1 #W                                  


I have gotten it to run under TSO and in batch but had hoped that there was some way to do this work file read under CICS (i.e. in an online CICS session).

I’ll have to give up on this functionality and be satisfied that I now know how to do the dynamic allocation of a file using USR2021N. Being able to read the file would have been gravy.

Thanks to all.

If you really want to do all this, look into getting Entire System Server. You can check the catalog, read and write work files online, read SPOOL, and much, much more.

You might yet be able to do this. See the documentation on the DEFINE WORKFILE statement (

"For TYPE=TD, only the first 4 characters of operand1 are honored and the transient data destination must be predefined to CICS. "

You will need to use an extra-partition transient data queue and the 4 character TD identifier are what you specify in the DEFINE WORK FILE 1 ‘tdqn’ statement.

You need a TDQ defined in your CICS definitions (DCT/CEDC) to use that is not included in the CICS JCL. CMWKF01 is not a TDQ name, but is mapped to the DEST= subparameter. The actual DD name used is specified by the TDQ entry corresponding to the DEST= subparameter. This is the DDNAME your USR2021N would need to be allocated to (not CMWKF01).

I second the Entire System Server recommendation. Your programs would not have to change whether it is running under CICS, batch, or TSO.