hexagon logo

FILE/EXISTS strange behaviour

Hello guys, I had encountered strange FILE/EXISTS command behaviour. I want to load some data from text file, if this file exists. Quite simple:

SUBROUTINE/DATUMOVKA_LOADER,
                PARTNAME =  : JMÉNO PROGRAMU,
                PRODDATE =  : DATUMOVKA DÍLU,
                COILBATCH =  : ŠARŽE COILU,
                COILNO =  : ČÍSLO COILU,
                MSG = 0 : VÝSTUPNÍ ZPRÁVA V PŘÍPADĚ NENALEZENÍ SOUBORU S DATUMOVKOU,
                 =
            ASSIGN/DATUMOVKA_FILE="X:\\Datumovky\\"+PARTNAME+".txt"
FILEOK     =FILE/EXISTS,DATUMOVKA_FILE
            IF/FILEOK==0
              ASSIGN/MSG="File does not exist! " + DATUMOVKA_FILE
              GOTO/HANDLER_DATUMOVKA_LOADER
            END_IF/
FPTR       =FILE/OPEN,DATUMOVKA_FILE,READ
            ASSIGN/ENDF=0
            ASSIGN/PRODDATE=-1
            ASSIGN/COILBATCH=-1
            ASSIGN/COILNO=-1
ENDF       =FILE/READLINE,FPTR,{PRODDATE}+";"+{COILBATCH}+";"+{COILNO}
            FILE/CLOSE,FPTR,KEEP
            ASSIGN/HODNOTY=ARRAY(PRODDATE,COILBATCH,COILNO)
            ASSIGN/TESTHODNOT=MIN(HODNOTY)
            IF/TESTHODNOT<0
              ASSIGN/MSG="Improper values loaded, check file " + DATUMOVKA_FILE
            END_IF/
HANDLER_DATUMOVKA_LOADER=LABEL/
            ENDSUB/
DATELOAD   =GROUP/SHOWALLPARAMS=YES
              ASSIGN/PD=0
              ASSIGN/CB=0
              ASSIGN/CN=0
              ASSIGN/MG=0
              ASSIGN/ADD="atest"
CS1          =CALLSUB/DATUMOVKA_LOADER,X:\_CMM_Programy\_Subroutines\subroutines_002.PRG:ADD,PD,CB,CN,MG,,
              IF/MG<>0
                COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,OVC=NO,
                MG
              END_IF/
              ELSE/
                COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,OVC=NO,
                PD
                CB
                CN
              END_ELSE/
            ENDGROUP/ID=DATELOAD​


The problem is that FILEOK returns "1" even if the file does not exist and than instead of quitting the routine the program tries to read the data from file which lead to error, because the file is not there obviously Slight smile After hours of trying everything the code started to work after this modification:
FILEOK     =FILE/EXISTS,DATUMOVKA_FILE
            ASSIGN/FILEOK=FILEOK
            IF/FILEOK==0​
.
.
.

Everything else is exactly the same. You know, I can live with that, even if it does not make sense to me. But does anyone have an idea HOW IS THIS F...ING POSSIBLE? AngrySlight smile
Parents
  • The thing is that the code is part of a subroutine which will be called by many routines and for each I'll have to use different file, so variable seems to be the only way. Nevertheless the address itself is evaluated correctly, problem is when you ask about the variable which holds the true/false value.
    FILEOK =FILE/EXISTS,DATUMOVKA_FILE
    IF/FILEOK==0​

    returns 1 even if the file does not exist while
    FILEOK =FILE/EXISTS,DATUMOVKA_FILE
    ASSIGN/FILEOK=FILEOK
    IF/FILEOK==0​​

    works correctly...Confused
Reply
  • The thing is that the code is part of a subroutine which will be called by many routines and for each I'll have to use different file, so variable seems to be the only way. Nevertheless the address itself is evaluated correctly, problem is when you ask about the variable which holds the true/false value.
    FILEOK =FILE/EXISTS,DATUMOVKA_FILE
    IF/FILEOK==0​

    returns 1 even if the file does not exist while
    FILEOK =FILE/EXISTS,DATUMOVKA_FILE
    ASSIGN/FILEOK=FILEOK
    IF/FILEOK==0​​

    works correctly...Confused
Children
No Data