Finding the last record in a transformer

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
venkates.dw
Participant
Posts: 67
Joined: Mon Dec 22, 2008 4:07 am

Finding the last record in a transformer

Post by venkates.dw »

Is there any way to find the last record in a transformer?
laxman.ds
Premium Member
Premium Member
Posts: 66
Joined: Thu Mar 02, 2006 9:00 am

Post by laxman.ds »

Get last record as max valued @INROWNUM (System Variable). But you need to take care about partitions per enabled for that job.
2 B 1 4 ALL
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You can use the LastRecord() function. (I think that's what it's called.)

To use this you need to be running version 8.5.
Last edited by ray.wurlod on Mon Aug 29, 2011 2:07 am, edited 1 time in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Immaculin
Participant
Posts: 5
Joined: Mon Jun 04, 2007 12:33 am

@INROWNUM = 2 is not working in datastage 8.5

Post by Immaculin »

criteria:

data in the file: (has only 2 rows)

ABCDEFGHI
123456789

In the output I want it as :

00000ABCDEFGHI00000123456789


stage variables:

alphabet:@INROWNUM = 1
number:@INROWNUM = 2


The constraint in the transformer to print the second row is not working (@INROWNUM = 2).

Where will we find the partitions per enabled for a job?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Re: @INROWNUM = 2 is not working in datastage 8.5

Post by ray.wurlod »

Immaculin wrote: Where will we find the partitions per enabled for a job?
Everywhere.
Parallel execution is enabled by default in the parallel Transformer stage.

Open up the stage properties. On the Advanced tab you will be able to change the execution mode to Sequential.

Do consider using a server job for this task. It will be finished while the parallel job is still thinking about starting.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Immaculin
Participant
Posts: 5
Joined: Mon Jun 04, 2007 12:33 am

Post by Immaculin »

I will not be able to view the premium content.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Immaculin wrote:I will not be able to view the premium content.
You can if you get yourself a premium membership. By doing so you will be helping to keep this site alive; premium membership is the main way that hosting and bandwidth costs are met.
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

Re: @INROWNUM = 2 is not working in datastage 8.5

Post by chulett »

Immaculin wrote:data in the file: (has only 2 rows)
Server job.
-craig

"You can never have too many knives" -- Logan Nine Fingers
babbu9
Premium Member
Premium Member
Posts: 75
Joined: Tue Jun 01, 2004 9:44 am

use this, it worked for me

Post by babbu9 »

For flat files:
First you need to know the rowcount for your file:
In the job properties use before job subroutine command execsh and type
"cat filename | wc -l > rowcount.txt"

Have a lookup in your job that looksup the file rowcount.txt and gets the rownum value. Generate rownum using @INROWNUM for the source records. Use the rownum as the key for both the source and lookup data. Set lookup condition to continue on condition not met and lookup failure. Add a transformer after the lookup and add condition where src.rownum=lkp.rownum and divert this record. This is your last record in the source.

For database sources your lookup needs to have "select count(1) from src_table" to find the table rowcount and repeat the same logic.
Post Reply