MainframeSupports
tip week 51/2006:

Jeg vil starte med at ønske alle mine læsere en god jul og et godt nytår. Det næste tip udkommer den 1. januar.

Merry Christmas and a happy new year to all of you. The next tip will be published on the 1st of january.

In many utility programs it is possible to specify which DD name to use for input or output or other sorts of files if you do not want to use the defaults. I have often wanted to use the same functionality in some of my programs. It is of course possible to code in assembler, but it is time consuming to code and requires skills in assembler.

One day I wondered what the TITLE option on the OPEN statement in PL/I was there for. I had noticed it many times before, but did not pay it any attention. This time I understood. The TITLE option simply specifies the name of the DD name to assign to the internal PL/I file definition if you want to use a different name than the file variable name. Now it is very easy to code a demo program:

demo: PROC(parm) OPTIONS(MAIN);

DCL anyfile FILE RECORD SEQUENTIAL;
DCL anyfile_data CHAR(32767) VAR;
DCL anyfile_eof CHAR(1);
DCL parm CHAR(100) VAR;

ON ENDFILE(anyfile) anyfile_eof = 'Y';
anyfile_eof = 'N';
OPEN FILE(anyfile) TITLE(parm);
READ FILE(anyfile) INTO(anyfile_data);
DO WHILE(anyfile_eof = 'N');
  /* Code your own file processing here */
  READ FILE(anyfile) INTO(anyfile_data);
END;
CLOSE FILE(anyfile);

END demo;

This program reads all records in a file. The special thing about the program is that the DD name to read from must be specified in the PARM option for the program. If you use //MYSTEP EXEC PGM=DEMO,PARM='/CURT' the program will read data from DD name CURT. The variable or the expression you specify in option TITLE will be translated to a CHAR(8) with trailing blanks if necessary. If you use PARM='/MAINFRAMESUPPORT' PL/I will open the file allocated to DD name MAINFRAM, if it is present. Otherwise it will fail, of course.

Previous tip in english        Sidste danske tip        Tip list