Kunal Roy
Kunal Roy

Reputation: 787

How to delete a record without actually reading the record in RPGLE

Recently I came across a question that was asked to me in a RPGLE interview. I was asked how to delete a record without actually reading it in RPGLE. My answer was we can use embedded SQL , but he told in SQL we are still reading the data. So in this community if anyone knows "how to delete a record without actually reading it in RPGLE" please let me know, I would be delighted to know the answer.

Thanks in advance

Upvotes: 2

Views: 1025

Answers (1)

Charles
Charles

Reputation: 23803

You simply provide a factor-1 search argument

C     MYKLIST       DELETE    MYFILE

In free form,

delete (key1:key2) myfile;

It's in the manual enter image description here

If a search argument (search-arg) is not specified, the DELETE operation deletes the current record (the last record retrieved). The record must have been locked by a previous input operation (for example, CHAIN or READ).

The search argument, search-arg, must be the key or relative record number used to retrieve the record to be deleted. If access is by key, search-arg can be a single key in the form of a field name, a named constant, a figurative constant, or a literal.

If the file is an externally-described file, search-arg can also be a composite key in the form of a KLIST name, a list of values, or %KDS.

I must admit, I had to look it up, off the top of my head I thought, "you can't". Now that my memory is refreshed, I think I recall doing this once or twice in the 30yrs I've been using RPG.

Note that RPGIII had the same support.

Your answer of "use SQL" would have been correct in my book. Assuming you're talking about the "search" delete

delete from mytable where ....

rather than a "positioned" delete

delete where current of cursor C1

Finally your interviewer is misinformed if he thinks the RPG Searched delete doesn't read the record first but that the SQL one does. Note the highlighted section of the quote used to retrieve the record to be deleted.

A database record has to be read in order to be deleted. The only question is are you reading it explicitly, via READ/CHAIN or an SQL Cursor. Or is the DB doing it for you via "search" delete.

Upvotes: 4

Related Questions