Work Files, I can create them but cannot read them

Cant seem to figure this out,
I get NAT1599:Attempt to Read/Write to non-existent file.
Code is simple, probably something in the way work files are setup
possibly in natparm ? ev’s ?
Here’s my nat code:

1 #COMMAND (A100)
1 #WORK-FILE-NAM (A32) INIT <‘test_ip’>

ASSIGN #COMMAND = ‘echo $REMOTEHOST > test_ip’
READ WORK FILE 6 ONCE #WORK-FILE-NAM
**
I can see the file with ls -la and type the file with less test_ip

natparm work files looks like:
nbrs 1-5 $wrkf1 thru $wrkf5
nbr 6 usr/sag/test_ip

I need some enlightening please.
Anyone need help with their cars? :lol:
sometimes I think I might be a better mechanic…
thanks again…
John

Natparms shouldn’t be a problem, to be sure you could use the
Define Work File 6 ‘full-path-file’
statement.
I would be willing to bet that if you stepped through your pgm one line at a time in the debugger it would work fine…
What I have run into before on the windows side was that the OS wasn’t done creating the file before Natural was trying to read it. Since the file creation is really being done outside of Natural it doesn’t know to wait for the I/O, to get around this you could just use USR2027 (or CMROLL) to wait a second before doing the read.
Not the nicest solution, in Windows I have also used a filesystem API to check if the file exists (WSH object), not sure if the same exists for the U*nix side.

The reason for your error is: Natural uses #WORK-FILE-NAM as a target field. The first line of work file 6 is moved into this field. And you didn’t specify a work file name for this number. So Natural takes the settings of your parameter module. Let me guess: This option is set to a file that doesn’t exist. This is why you get the NAT1599.

Please use DEFINE WORK FILE as Chad Scott recommended.

DEFINE WORK FILE 6 #WORK-FILE-NAM TYPE "ASCII"
READ WORK FILE 6 ONCE #TARGET-FIELD
DISPLAY #TARGET-FIELD
...

Thanks Chad and Mathias,
I’m gettin the hang of this stuff, slowly but surely.

1 #TEST-IP-FILE (A32)
1 #WORK-FILE-NAM (A32) INIT <‘/usr/sag/test_ip’>

define work file 6 #WORK-FILE-NAM type ‘ASCII’

READ WORK FILE 6 ONCE #TEST-IP-FILE

display #TEST-IP-FILE

works fine, :smiley:

Just a word on the Natparms. These may be an issue because in the definition of Workfiles we can now specify an “Automatic Close” or a “User Close”. If user close was specified and an actual “Close” command was not issued, the file will remain open and unlikely to be readible.