I need to deal with a series of FILEs sequentially. To write less code and consolidate into a ROUTINE requires using a variable for the FILE names.
Is there a way to accomplish this? StringTheory has a FileNameOnly method, but OPEN(), ADD(), etc. seem to require a FILE label only.
Alternatively, I have attempted to consolidate the files into a single file and create a dimensioned GROUP - the data has the same structure in all files - but it is unclear to me how a FILE structure handles a dimensioned GROUP.
The StringTheory methods you referenced are used for physical files like:
SomeFile.txt
You’re talking about FILES like TPS “files.”
If you need to pass parameters and return values, you can use local procedures instead of routines. It’s very easy, the only extra work is to add a MAP
.
Let’s say you have this:
!Data section
LOC:File &FILE
LOC:Result LONG
!Procedure routines
CheckFile ROUTINE
LOC:Result = 0
OPEN(LOC:File)
LOC:Result = ERRORCODE()
CLOSE(LOC:File)
!Some embed
LOC:File &= FileA
DO CheckFile
IF LOC:Result
..
END
LOC:File &= FileB
DO CheckFile
IF LOC:Result
..
END
You can write it like this:
!Data section
MAP
CheckFile PROCEDURE(FILE pFile),LONG
END
!Local procedures (or at the end of Local routines)
CheckFile PROCEDURE(FILE pFile)!,LONG
LOC:Result LONG
CODE
OPEN(pFile)
LOC:Result = ERRORCODE()
CLOSE(pFile)
RETURN LOC:Result
!Some embed
IF CheckFile(FileA)
..
END
IF CheckFile(FileB)
..
END
Just like routines, local procedures have access to the procedure’s local variables, window structure, etc.
1 Like
Thanks, Carlos. That looks very promising, and I will give it a try.