record.ID in DELETE

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
Gokul
Participant
Posts: 74
Joined: Wed Feb 23, 2005 10:58 pm
Location: Mumbai

record.ID in DELETE

Post by Gokul »

Hi,

In the Delete statement given in the supporting PDF

DELETE [file.variable,] record.ID [ON ERROR statements]
[LOCKED statements]
[THEN statements] [ELSE statements].

What is record.ID?

I tried with a file abc.txt containing one record having value "Hello".

The Delete statement used to delete the record is

Code: Select all

OPENSEQ "/home/w951/temp/abc.txt" TO fwrote 
THEN
     DELETE fwrote,"Hello" 
     Then 
        Ans = status()
        CLOSESEQ fwrote
     End
END.
It gave me error "Line 8, Improper data type".

I even tried with

Code: Select all

DELETE fwrote,1
,but the same error.

What should be the value for the record.ID in the above case?

Thanks,
Gokul



[/code]
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Gokul,

the DELETE statement only works on hashed files; sequential files can only be read sequentially, so DELETEing a row using this statement cannot work. The only way to delete a line from a sequential file is to make a copy - meaning you can't update the file, but need to read and then write rows from 1 to {your row to be deleted-1} to the copy file, skip the row, and then copy the rest.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You can not use DELETE on a file opened with OPENSEQ.

You can only use DELETE on a file opened with OPEN or OPENPATH, which the documentation tells you; the file variable is assigned "in a previous OPEN statement".

If you are seeking a way to delete a line from a text file, you have essentially two choices.
  • One is to read the file a line at a time and write a copy, skipping the line in question. You could also do this with grep -v command.

    The other is to open the file's parent directory, read the file as if it were a record in a database table (the file name is the record "key"), LOCATE the line you want to delete, use a DELETE() function (or DEL statement) to remove that field, then write the "record" back to the "table".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply