TechTalk: Read Physical File in CL

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

Read Physical File in CL

Q. I have a physical file that I want to read sequentially. When a record is read, I need to perform a function, then read another record. I need to know how to read a file sequentially in CL without using an RPG program. In addition, after I read it, how do I determine if a record contains "AB" in columns 75-76?

A. First, you need to declare the file to the CL program, using the Declare File (DCLF) command. Don't bother with any parameters except FILE.

Then, issue a Receive File (RCVF) command within a loop. After the RCVF, be sure to monitor for CPF0864 (type *ESCAPE), which is sent at end of file. When CPF0864 arrives, exit the loop. The program skeleton in 3 illustrates the process.

Then, issue a Receive File (RCVF) command within a loop. After the RCVF, be sure to monitor for CPF0864 (type *ESCAPE), which is sent at end of file. When CPF0864 arrives, exit the loop. The program skeleton in Figure 3 illustrates the process.

Notice that the RCVF command requires no parameters when processing a physical file since there is only one record format.

When you declare the file with DCLF, the CL compiler creates a separate variable for each field in the record if there's an external definition for the file (DDS). If there isn't, the CL compiler creates a single variable (of type *CHAR) for the entire record.

To determine if a record contains "AB" in columns 75-76, you must follow one of the two methods shown below, depending on whether or not the file is externally defined.

1. With External File Definition: Determine which field contains the "AB" in columns 75 and 76, and manipulate the field in whatever form is necessary to extract these two bytes. For instance, %SST (&field_name 75 2) and compare that against "AB".

2. Without External File Definition: This is the simplest case. When you DCLF FILE(MASTER), the CL compiler creates a character variable named &MASTER (the same name as the file). Then you can do:

IF COND(%SST(&MASTER 75 2) *EQ + 'AB') THEN(...)
TechTalk: Read Physical File in CL

Figure 3 Reading a file in CL

 Figure 3: Reading a File in CL PGM DCLF FILE(MASTER) LOOP: RCVF MONMSG MSGID(CPF0864) 
EXEC(GOTO CMDLBL(END_LOOP)) : : GOTO CMDLBL(LOOP) END_LOOP:
(program continues here after all records are read)
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: