TechTalk: Files in CL

CL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

From: John McKee To: All

I had this all figured out. I had in mind using DSPAUT-USR OUTPUT(*PRINT) to generate a list of users and then using CRTPF and CPYSPLF to get the list into a file. The purpose was to read the user names, do RTVUSRPRF of various things, then use TAATOOL/PRINT to generate a report. But how can a CL program read the file? Only way I know of is to use DCLF and RCVF. But these won't work if the CL program itself has to create the file. A while back I tried doing something like this. CRTCLPGM objected to the lack of an existing file to resolve to DCLF command. Is there another way to do this? I looked at OPNDBF but don't think that works either. What I want is a self-contained CL program that doesn't rely on the previous existence of other files. Can OVRDBF be of any help?

From: Ernie Malaga To: John McKee

To solve your problem, do the following:

1. Manually create the file your CL program is going to use. You can use DDS if you want to refer to fields within your program, but I suspect that in your case you won't want to-since you'll use it for a spool file. Use the CRTPF command as follows:

 CRTPF FILE(lib/file) RCDLEN(132) + TEXT('text-description') 

The record length of 132 assures that every column of the spooled report will be included in the file.

2. Compile your program. Since the file exists now, the compile will be successful. If you created the file in QTEMP (you probably should), the compile should be performed interactively. This is because a compile submitted to batch processing won't be able to reference your interactive job's QTEMP.

3. Delete the file you created in Step 1 once the compile is done.

On a different note...

If you use outfiles, the process is different because IBM already provides the outfiles in QSYS. You shouldn't use the files in QSYS in your programs, but you can reference them to create your own. For example, suppose you've coded a CL program that performs a DSPOBJD to an outfile. Rather than coming up with your own outfile, use IBM's: QADSPOBJ. Automatically, you gain complete field descriptions for the file (since IBM created it with DDS). 3 illustrates the process.

If you use outfiles, the process is different because IBM already provides the outfiles in QSYS. You shouldn't use the files in QSYS in your programs, but you can reference them to create your own. For example, suppose you've coded a CL program that performs a DSPOBJD to an outfile. Rather than coming up with your own outfile, use IBM's: QADSPOBJ. Automatically, you gain complete field descriptions for the file (since IBM created it with DDS). Figure 3 illustrates the process.

Then simply compile the program. You don't have to do anything special.

From: John McKee To: Ernie Malaga

Thanks. I think you've turned the light on for me. The method is beginning to make sense-it seems almost easy.


TechTalk: Files in CL

Figure 3 Program skeleton

 Figure 3: Program Skeleton PGM DCLF FILE(QADSPOBJ) /* No library referenced */ /* This step produces the outfile in QTEMP */ DSPOBJD OBJ(*ALL/*ALL) OBJTYPE(*ALL) + OUTPUT(*OUTFILE) OUTFILE(QTEMP/QADSPOBJ) /* All future references to QADSPOBJ point to + the *copy* in QTEMP, so the QSYS file is not used */ OVRDBF FILE(QADSPOBJ) TOFILE(QTEMP/QADSPOBJ) /* Read a record from QTEMP/QADSPOBJ */ LOOP: RCVF MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(ENDLOOP)) /* Do whatever processing is necessary */ ENDLOOP: * * ENDPGM 
BLOG COMMENTS POWERED BY DISQUS