In this week I will show you a piece of code I typically use for scanning the PARM area used on the EXEC-card. Generally it is a big task to code a scanner for interpretation of a long text as for instance a program. How big a task highly depends on how advanced a syntax you want to scan. This scanner can interpret a syntax where each parameter in the PARM area is separated by a comma. You can use any other character as separator if you like. A parameter may be numeric or just a character string. A numeric parameter is translated into an integer variable (BINARY or DECIMAL).
I have implemented the code itself as a procedure in PLI without parameters. Therefore I hope it is easy to tranlate to COBOL if you need that instead. In the following example the first parameter is called maxRecords which is the maximum number of records I want the program to process. The second parameter is dlmChar which is a delimiter one character long (CHAR(1)) to be present in the records read by the program. The third parameter is fmtMethod which is a character string (CHAR(8) VAR) which controls the formatting of the records read depending on its value. These parameters are declared as a part of the sorrounding program and therefore not part of the tip. The input containing the values for the described parameters is the variable parm which is declared as a CHAR(100) VAR. The scanner code looks like this:
The most complicated part is of course the interpretation of a numeric variable. Using the variable digitCount I control the largest number of digits the parameter must contain. There is no error handling in the scanner. When the first non-numeric digit is encountered the following characters are simply skipped until a comma occurs and changes the interpretation to the next parameter. If more than one character is present for the second parameter the last character is used. For the last parameter characters following the eighth digit are simply ignored. If more than two commas occurs in parm the remaining characters are also ignored.
The good thing about this scanner is that it is easy to add interpretation of new parameters and it is also easy to change the interpretation of each parameter. Default values for a CHAR(1) or a FIXED BIN(n) should be assigned before entering the WHILE loop. I will recommend that character strings more than one character long are declared as CHAR(n) VAR, initialised using '' and if the character string is still '' after the loop, you can assign the parameter a default value at this point.