Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to delete all of record in RPG?

1,929 views
Skip to first unread message

Yanti

unread,
Sep 10, 2001, 10:15:44 PM9/10/01
to
Hello, I am Yanti and just learning RPG, I want to ask the command to delete
all of records in a file.
Thanx in advanced for helping :)

--
Yanti Budiman
IT-Security Review
Lippo Bank
www.lippobank.co.id


Anthony Chilton

unread,
Sep 11, 2001, 5:33:21 AM9/11/01
to
"Yanti" <yanti....@lippo.net.id> wrote in message
news:oYrn7.2277$96.18730@news...

> Hello, I am Yanti and just learning RPG, I want to ask the command to
delete
> all of records in a file.
> Thanx in advanced for helping :)
>

Hi Yanti

The following shows how a physical file can be cleared with a call to the
QCMDEXC api from within an RPG program.

In the CL program the file TMPACC is overridden to another file.

OVRDBF TMPACC TOFILE(QS36F/&TMPACC) OVRSCOPE(*JOB)

The following code is included in the RPG program.

By referencing the file information data structure, you can retrieve the
name of the file
that TMPACC has been overridden to.

F TMPACC UF E K DISK KINFDS ACC

By defining the data structure for the INFDS you can place the file name
into variable #TACC

I ACC DS
I 83 92 #TACC

Define 'CLRPFM myLibrary/' as a constant (obviously you substitute myLibrary
for whichever library is needed).

I 'CLRPFM myLibrary/' C #CMD


Then its just a case of concatenating the file name with the command you
wish to execute, in
this case #CMD, and call QCMDEXC.

You will also need to close the file you are going to clear so the CLRPFM
command will
execute without causing an exception.

The parameter PCMD must be defined as a charater field, with its length
defined as the same length
as the string passed into it. In this case the length is 23 Alpha.

PLEN must be defined as 15 5. The length of the string passed in PCMD must
be passed in this parameter.

Finally you will need to open the file so any further processing in the RPG
program can be completed.

C CLOSE TMPACC
C #CMD CAT #TACC PCMD
C CALL 'QCMDEXC'
C PARM PCMD 23
C PARM 23 PLEN 15 5
C OPEN TMPACC

Bear in mind that there are other ways to clear a physical file from within
an RPG program, such as reading the entire file and deleting each record.

If you would like anymore help, feel free to email me.

Anthony Chilton

Jay R. Winans

unread,
Sep 11, 2001, 6:54:07 AM9/11/01
to
"Yanti" <yanti....@lippo.net.id> wrote in message news:<oYrn7.2277$96.18730@news>...
> Hello, I am Yanti and just learning RPG, I want to ask the command to delete
> all of records in a file.
> Thanx in advanced for helping :)
Yanti:

The command to delete all records in a file is a CL Command for the
AS/400. It is CLRPFM Y/X, where Y is the name of the library and X is
the name of the file. CLRPFM stands for Clear a Physical File Member.

If your working with a multi-member file you have the option of
specifing which member you wish to clear. The keyword for this option
is MBR. The default for this keyword is *FIRST, meaning it will clear
the oldest member first. You could also clear the newest member by
using *LAST.

Note:
1. Be aware that when you execute this command there is no message
asking you to confirm your clearing the file. You may want to copy a
file and try this on the copied file to test it out.
2. Suggest that you always include the library name so that you don't
accidently clear the wrong file. A lesson that I learned the hard way.

Good luck.

Bruce Bardini

unread,
Sep 12, 2001, 9:41:35 PM9/12/01
to
Reminds me of a lesson that I learned the hard way too; a CLRPFM doesn't
care about an OVRDBF!

Bruce E. Bardini

"Jay R. Winans" <Jayan...@Earthlink.Net> wrote in message
news:93787e9f.01091...@posting.google.com...

Rick Price

unread,
Sep 13, 2001, 3:47:24 AM9/13/01
to
Doesn't open output clear a file (and it will take into account any OVRDBF)?

Bruce Bardini <bruc...@home.com> wrote in message
news:j9Un7.60778$xb.31...@news1.mntp1.il.home.com...

Drew Dekreon

unread,
Sep 13, 2001, 3:31:07 PM9/13/01
to
you could embed sql in the rpg
c/exec sql delete * from library/file
c/end-exec
Source code type must be SQLRPG or SQLRPGLE

"Yanti" <yanti....@lippo.net.id> wrote in message
news:oYrn7.2277$96.18730@news...

Bruce Bardini

unread,
Sep 13, 2001, 10:24:30 PM9/13/01
to
I know that in BASIC, if a file is opened for OUTPUT, it will be cleared.
If you want to add records to it, you open it for APPEND.

Opening a file for output on an AS/400 doesn't clear it. Also, if the file
doesn't exist, opening it for output does NOT create it, as might happen on
some systems.

--


Bruce E. Bardini
"Rick Price" <ri...@hpdsoftware.com> wrote in message
news:9npo3l$8t6hp$1...@ID-39799.news.dfncis.de...

Matthias Martin

unread,
Sep 14, 2001, 8:37:57 AM9/14/01
to
Try this if you will delete by key:

C DOU *IN87 = '1'
C DOU *IN88 = '0'
C KEYLIST DELETE YOURFILE 8788
C ENDDO
C ENDDO
C*

Matthias


"Drew Dekreon" <drew_dekreon@chugachelectric.!com!> wrote in message news:<tq22bvt...@corp.supernews.com>...

Rick Price

unread,
Sep 14, 2001, 11:23:05 AM9/14/01
to
If you want to clear a file then by definition it exists. I'm pretty sure
that I found to my cost that open output does take into account OVRDBF and
does clear a file member. Mind you this was back in 1990 and was in COBOL.

I've just looked and it still happens in ILE COBOL. I guess the same thing
doesn't happen in RPG.

Bruce Bardini <bruc...@home.com> wrote in message

news:yTdo7.62822$xb.33...@news1.mntp1.il.home.com...

elb...@cmfurniture.com

unread,
Sep 17, 2001, 8:20:23 AM9/17/01
to
This requires is a little less coding.


**************************************************************************

FFILE UF E K DISK

*


**************************************************************************

C *LOVAL SETLL FILE
C *IN60 DOUEQ*ON

C DELETFILE 60

C ENDDO


or by key


**************************************************************************

FFILE UF E K DISK

*


**************************************************************************

C *IN60 DOUEQ*ON

C KEY DELETFILE 60

C ENDDO

On 14 Sep 2001 05:37:57 -0700, m...@matthias-martin.com (Matthias

bcsksun...@gmail.com

unread,
Jun 4, 2014, 12:36:13 PM6/4/14
to

dgome...@gmail.com

unread,
Jun 5, 2014, 8:08:14 AM6/5/14
to
I am curious as to why people are insisting the file needs to be opened somewhere in the program to do this.

The only thing that is needed is to run the CLRPFM command through the QCMDEXC or System Api's. Using the delete command or SQL to delete the records individually will take longer than just running the CL command.


dgome...@gmail.com

unread,
Jun 5, 2014, 8:21:34 AM6/5/14
to
This can actually be done even simpler:

FFILE UP E DISK
C DELETE FILE

One of the few cases were the cycle can still be relevant.

jse...@yahoo.co.nz

unread,
Jun 5, 2014, 6:04:14 PM6/5/14
to
On Friday, 6 June 2014 00:08:14 UTC+12, dgome...@gmail.com wrote:
> I am curious as to why people are insisting the file needs to be opened somewhere in the program to do this.

The OP did ask how to do it in RPG.
One can just type CLRPFM on a command line, that does however require an exclusive lock, maybe this isn't possible? An RPG program to clear each record doesn't require an exclusive lock on the file (just each record).

I'm also surprised at the ancient coding techniques people have posted. I mean, indicators guys? Are we still in the 80s or something???

CRPence

unread,
Jun 5, 2014, 9:30:16 PM6/5/14
to
I am surprised that anyone had responded to what appears to be an
accidental necro-posting made in reply-to a message posted some 13 years
ago; i.e. no new text was added, only the full text of an ancient
message was re-posted:
<https://groups.google.com/d/msg/comp.sys.ibm.as400.misc/xOzMMJgisQA/5qz09fA3CcEJ>

--
Regards, Chuck

A. Perry Nelson

unread,
Jul 7, 2014, 5:51:00 PM7/7/14
to
Its these young sql programmers, who don't know any better!, save the file, then clrpfm afterwards. Just hope this is a play/test file, and not production. P
0 new messages