Issue

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
rsunny
Participant
Posts: 223
Joined: Sat Jul 03, 2010 10:22 pm

Issue

Post by rsunny »

Hi everyone,

I have one more problem, I need to add one more field as row in my task and i have to get the row number based on the group i.e.
If i have three columns say company code, product code, amt.
I need to add another column for the rows. the output should come in this way.
abc,coke,120,1
abc,coke,140,2
abc,pepsi,30,1
abc,pepsi,40,2
abc,pepsi,240,3
cdf,coke,60,1
cdf,pepsi,50,1

I tried to compare with the previous record and if they are same i tried to increment but i could able to solve it for two rows but if there are more than two rows its not working ,can any one suggest me the code for this problem.

Thanks in advance
arunkumarmm
Participant
Posts: 246
Joined: Mon Jun 30, 2008 3:22 am
Location: New York
Contact:

Post by arunkumarmm »

How you tried this? Can you post your approach?


Also, did you sort your rows before that? And did you include both company code and product code to validate?
Arun
rsunny
Participant
Posts: 223
Joined: Sat Jul 03, 2010 10:22 pm

issue

Post by rsunny »

i first sorted and grouped based on sort and aggregator function.after that i used stage variables to compare with the previous and current record .but initially i asigned the row column as a constant variable.
asorrell
Posts: 1707
Joined: Fri Apr 04, 2003 2:00 pm
Location: Colleyville, Texas

Post by asorrell »

Please post your actual code. We can't fix it if we can't see it.
Andy Sorrell
Certified DataStage Consultant
IBM Analytics Champion 2009 - 2020
arunkumarmm
Participant
Posts: 246
Joined: Mon Jun 30, 2008 3:22 am
Location: New York
Contact:

Post by arunkumarmm »

I dont have a clear understanding on your approach but If i'm doing this I will try something like this:

Code: Select all

Sort rows using company code and product code.
Assign the initial values for all stage variables as empty ( '' )
 svOldComp = svNewComp
svNewComp = Link1.CompCd Column
 svOldPrd = svNewPrd
svNewPrd = Link1.PrdCd Column

svSeqNum = If svNewComp <> svOldComp And svNewPrd <> svOldPrd Then 1 Else If svNewComp = svOldComp And svNewPrd <> svOldPrd Then 1 Else If svNewComp = svOldComp And svNewPrd = svOldPrd Then svSeqNum +1 Else 1
I have not tested this but this should work.
Arun
rsunny
Participant
Posts: 223
Joined: Sat Jul 03, 2010 10:22 pm

Post by rsunny »

arunkumarmm wrote:I dont have a clear understanding on your approach but If i'm doing this I will try something like this:

Code: Select all

Sort rows using company code and product code.
Assign the initial values for all stage variables as empty ( '' )
 svOldComp = svNewComp
svNewComp = Link1.CompCd Column
 svOldPrd = svNewPrd
svNewPrd = Link1.PrdCd Column

svSeqNum = If svNewComp <> svOldComp And svNewPrd <> svOldPrd Then 1 Else If svNewComp = svOldComp And svNewPrd <> svOldPrd Then 1 Else If svNewComp = svOldComp And svNewPrd = svOldPrd Then svSeqNum +1 Else 1
I have not tested this but this should work.
Do we need to initialize the svseqnum or is it not required as ther will be empty value in svseqnum if we dont initialize
rsunny
Participant
Posts: 223
Joined: Sat Jul 03, 2010 10:22 pm

Post by rsunny »

my code is

i had taken rowcount as a seperate column and initialized to 1
then i had written
crc32(Nulltoempty(comcode):nulltoempty(procode))=stagevar1
if stagevar1=stagevar2 then rowcount+1 else 1=stagvar
crc32(Nulltoempty(comcode):nulltoempty(procode))=stagevar2
Post Reply