How to check size of work file before accessing it?

We regularly have to process xml input in batch processes. I’ve seen examples of more than 80 MB which we cannot process, and I’d like to avoid error situations due to such file sizes.
I have read the thread “How to check the external files?” in which it was recommended to check out SYSEXT for keyword WORKFILE, so I came across USR2011N which I’m presently using to get the workfile path and name as well as workfile type for a certain wf number.
However, so far I haven’t found any way to check the file size of a certain external file except to issue a shell command to find the file in question,
then to write the result of the shell command into another file, and later on reading this small file to extract the size in bytes.
The result, i.e. the content of this small file, is something like that:
29999 24829 -rw-r----- 1 uuuuu gggggg 25423890 Nov 5 08:34 /xxxx/yyyy/zzz/xml_input.xml
If the size (here 25423890) exceeds a certain level which in our experience cannot be processed, I reject that file and invoke an error that I can handle, instead of running into a ‘out of memory’ situation.
Below pls find the coding. It works, but I’m sure there is a better way!
I’d like to avoid having to write a work file just for the sake of getting the result of a shell command back into my Natural process.
Do any of you have a suggestion?


...
 1 #DATEIINFO (A253)
 1 REDEFINE #DATEIINFO
   2 #DI_FILLER (A44)
   2 #DI_SIZE_BYTES (A10)
 1 #SIZE_BYTES (N10)
....
    RESET L-SHCMD-COMMAND
    COMPRESS  #C-SONDER1 #FILENAME  #C-SONDER1
      INTO L-SHCMD-NAME LEAVING NO
    COMPRESS 'find' #PATH
      '-type f -name' #FILENAME
 '-ls'  '>' #TARGET-DATEIINFO
      INTO  L-SHCMD-COMMAND
    PRINT ' '  L-SHCMD-COMMAND
    CALL 'SHCMD' L-SHCMD-COMMAND
...
*
  CLOSE WORK 32
    CALLNAT 'AXWFTYPN' 32 'ASCII' #TARGET-DATEIINFO
    RESET
      #DATEIINFO
    READ WORK 32 #DATEIINFO
      write '#DATEIINFO:'  '='  #DI_SIZE_BYTES
      IF #DI_SIZE_BYTES IS (N10)
        #SIZE_BYTES := VAL (#DI_SIZE_BYTES)
      END-IF
    END-WORK
    CLOSE WORK 32
* ... Deletion of info file
    IF #SIZE_BYTES > 100000
    write 'Datei ist zu groß!' '=' #SIZE_BYTES
* ... Error handling
END-IF
* ... processing of xml input file
define data local
01 #filename (A) dynamic const <'/tmp/testfile.txt'>
01 #size     (I4)
01 #i2       (I2)
01 #b1000    (B1000)
end-define
define work file 30 #filename type 'unformatted'
read work file 30 #b1000 giving length #i2
add #i2 to #size
end-work
close work file 30
display #size
end

… I know, that’s not really proper, but it’s pure Natural. :wink:

Hello Matthias,

thanks a lot for the hint :slight_smile:
I tried it with my 88 MB file, it worked fine and rather quickly gave me the file size without having to read the complete XML into a dynamic string.

The disadvantage is: You have to read the file completely. Actually, a quick access to the file system table (like ls/dir does) would be enough… But it seems there is no USR-Module for that …