TechTalk: Use the CLEAR operation against files opened for input.

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

In RPG, you can use the CLEAR operation to clear all fields in a record format. However, this works only if the file is opened for output, update, or input with add (A in column 66). If the file is opened for input only, you can use the CLEAR operation against the file's record format, but it won't do anything.

I found a way to use the CLEAR operation to clear all the fields in a record format even when the file is opened for input only. You'll find an example of this technique in 7. The trick is to define an externally described data structure using the name of the file that contains the fields you want to clear, then use the CLEAR operation on the data structure name. This technique can be useful when you want to clear all fields in a file after an unsuccessful CHAIN operation.

I found a way to use the CLEAR operation to clear all the fields in a record format even when the file is opened for input only. You'll find an example of this technique in Figure 7. The trick is to define an externally described data structure using the name of the file that contains the fields you want to clear, then use the CLEAR operation on the data structure name. This technique can be useful when you want to clear all fields in a file after an unsuccessful CHAIN operation.

In the example code, you can see that the file IIML01 has been defined as input only. An externally described data structure called IIMDS has also been defined using the IIML01 file. In the C-specs, the program CHAINs to the IIML01 file. If a record is not found, the program uses the CLEAR operation against the IIMDS data structure. This clears all of the fields in the IIML01 file even though the file was opened for input only.

- Andrew Nortje


TechTalk: Use the CLEAR operation against files opened for input.

Figure 7: Using CLEAR with an Input File

 *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 FIIML01 IF E K DISK * IIIMDS E DSIIML01 * * Get IIML01 record C PROD CHAINIIML01 99 * * If not found then clear all fields C *IN99 IFEQ *ON C CLEARIIMDS C ENDIF 
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: