Reverse the records in DataStage

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
fahad
Participant
Posts: 15
Joined: Sat Aug 07, 2004 7:48 am

Reverse the records in DataStage

Post by fahad »

dear all,
i have set of records and i want to reverse them.. for example,

01 John IBM
02 George MSN
03 Peter Oracle

required to be

03 Peter Oracle
02 George MSN
01 John IBM

is that possible in DataStage??? :roll:
thank you all and i will appreciate any reply
andru
Participant
Posts: 21
Joined: Tue Mar 02, 2004 12:25 am
Location: Chennai

Post by andru »

Is ur input a file or a ODBC/DRS stage?? If the data is fetched using a SQL query in the ODBC/DRS stage then use ORDER BY DESC to get the data in the reverse order.
If your inpt is a file then I doubt if we can do it in DS.
fahad
Participant
Posts: 15
Joined: Sat Aug 07, 2004 7:48 am

Post by fahad »

thank you for the reply.. however,
the source table is not sorted in asc or desc base order. my main problem is the duplicates in the source table and using hash file stage i can remove the duplicates by keeping the last record while i need the first one.. so i thought of reversing the records order by some mechanism to get through this problem..

your post opened my mind to new techniques i might use.. thanks a lot
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

If you do end up using a hash file to remove the duplicates in your file, you could store the record number (@INROWNUM) along with your data. Then, by accessing the hash file with a UV stage, you could pull them back out in reverse order.
-craig

"You can never have too many knives" -- Logan Nine Fingers
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

You could send it through a sort stage sorting in ascending order. With this sorted data you can remove duplicates with an aggregation stage or a hash file or stage variables. See the deduplicing FAQ for details of each.

With a hash file you will find records overwriting each other leaving you with the last record for each combination.

With the aggregation stage you can use the "Last" aggregate function on non group by fields. Make sure you populate the Sort information on your input columns to speed up the performance of the aggregation stage.

Stage variables will probably be the fastest method but also the trickiest to code.
badri
Participant
Posts: 19
Joined: Mon Jul 12, 2004 2:58 am

Post by badri »

Hi,

You can avoid duplicate records by following the below steps

Sort the records and in the transformer call a routine that contains basic code as below

DupFlag="N";
if trim(prNo)=trim(Field1) then
DupFlag="Y";
end
prNo= Field1;

Ans=DupFlag;

Filter out DupFlag = "Y" in the transformer stage

- :lol:
gh_amitava
Participant
Posts: 75
Joined: Tue May 13, 2003 4:14 am
Location: California
Contact:

Post by gh_amitava »

Hi,

You can do it very easily. Put your source of data first then put a sequence generator stage, generate sequence from 1 for each of the records. Then sort the records in decending order. You will get the desire result.

Thanks
Amitava
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Version 7.1 server jobs (this IS the server-job forum) don't have the sequence generator stage to which you refer.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Exactly. The OP specified "Server" as the job type, so it doesn't really help to give PX specific answers. Besides, there's a different forum for Parallel jobs.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply