Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

clear a workfile 1

Status
Not open for further replies.

LUEBBKEVIN

Programmer
Apr 30, 2002
35
US
How do I clear a workfile in an RPG program? I know that CLRPFM will work in CL but cannot remember for the life of me how to do it in RPG.
 
Just out of curiousity, why do you need to clear a file from within the RPG program? Generally, you'd want to call a CL that does any file preparation & cleanup, etc., as well as call your RPG program.

If you have no other choice, another alternative (not necessarily better), is to call a CL program from within the RPG program that clears the files.

K.Hood
 
There can be reasons, mostly you wouldn't though. Many times it might be the not wanting another program to maintain. Mike Wills
AS400 Programmer
[pc2]

Please, if you find my post useful, let me know. [thumbsup2]
 
i am a bit rusty, but doesn't opening a file for output do the clearing? as opposed to opening it to extend which keeps existing records.
 
pipk,

Opening a file as OUTPUT does NOT clear a file in RPG. In COBOL, opening a file as output does indeed clear the file (at least in earlier versions of COBOL/400).

K.Hood
 
KOLDARK,

I agree that there are special situations that require unique approaches. That's why I was asking WHY they needed to clear the workfile within the RPG program. Generally, you want to use the "usually accepted" methods of programming in order to make the programs easier to maintain. If this simply a workfile that needs to be cleared before updating, then it should be handled in a CL program because other programmers maintaining the software will expect to see it there. If some logic is required before the decision to clear the file is made, then it is a different situation.

Executing an AS/400 command directly from an RPG program, especially a CLRPFM command, without a MONMSG to handle error conditions (empty file, file in use, etc.) is asking for problems.

Don't misunderstand, I'm not trying to start a debate on "best practices". I feel the the "right way" is something that works efficiently and perhaps just as important - easy to maintain. There is no ONE correct way to do most programming tasks. I am just giving my opinion as a consultant who has to maintain programs written using many different techniques. If you use an unusual technique, then it can take more time to understand the process.

K.Hood
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top