Validating a path and file name from inside of a Natural program runinng under AIX 6.1.0.0

Hello all,

We’re running Natural / ADABAS under UNIX AIX 6.1.0.0.

I was wondering how could I gracefully verify that a given AIX path followed by a file name can actually be validated from inside my Natural program, before issuing a READ WORK FILE #… command that would result in a “hard” abend with the message:
"NAT1599 Attempt to execute READ/WRITE WORK to non-existent file. " …if the file didn’t exist!

I know how to verify the existence of a file from the AIX prompt, or from inside of a bash script… so I guess the question becomes: how do I issue native AIX commands and have access to their return codes, from inside of a Natural program?

e.g.: I can issue the following in a bsh/ksh script

MySampleFileName=$1

if [ ! -f $MySampleFileName ];
then
echo “File $MySampleFileName does not exist”
exit 1
fi

…and get an answer as to whether or not my MySampleFileName (which was passed from outside into the script executing the code snippet above), contains a string consisting of path/filename that results in a real file name, out there, in the UNIX file system. I’m looking for a way of accomplishing this from inside of a Natural program.

Thanks so much!
Lawrence

USR1052N in library SYSEXT will let you send an arbitrary command to
the operating system.

Hth, best regards,

   Wolfgang

I recently created the following function for our environment (HP-UX 11i v3/NAT 6.3.11). It appears to be working as expected.

DEFINE FUNCTION F#FILEEXISTS
RETURNS (L)
DEFINE DATA PARAMETER
1 #FILE (A) DYNAMIC BY VALUE /* File path and name
LOCAL
1 #CMD  (A) DYNAMIC
END-DEFINE

COMPRESS '[ -f' #FILE ']' INTO #CMD
CALL 'SHCMD' #CMD 'NOSCREENIO'
IF RET('SHCMD') = 0
  F#FILEEXISTS := TRUE
ELSE
  F#FILEEXISTS := FALSE
END-IF
END-FUNCTION
END

The function is called as shown.

if F#FILEEXISTS(<#image-name>)
  perform some-code
end-if

The path can also be hardcoded if needed.

if F#FILEEXISTS(<'/SAG/temp/file.dat'>)
  perform some-code
end-if

I went with SHCMD over USR1052N because of the A253 input limit on the user exit.

USR1052N wraps SHCMD, while there’s nothing wrong with using it directly
for the time being it’s always safer to use the interfaces provided in SYSEXT
to shield from possible future changes to the “lower level” functions.

Re. the A253 limit, I think USR1052N has been there before dynamic alpha
variables were introduced into Natural, it might be worthwhile to ask for
a new USR routine with a dynamic alpha parameter.

Here’s a pure natural solution:

* Subprogram FILEXIST
define data parameter
01 #in-filename (A) dynamic by value
01 #out-result (N7) by value result
local
01 #a1 (A1)
end-define
on error
  #out-result := *ERROR-NR
  escape module
end-error
define work file 30 #in-filename
read work file 30 once #a1
close work file 30
end

Sample program:

define data local
01 #rc (N7)
end-define
callnat 'FILEXIST' '/home/myfile.txt' #rc
write '=' #rc
decide on first value of #rc
  value 1599 write 'does not exist'
  value 0    write 'does exist and is readable'
  none value write 'some other error'
end-decide
end