Increment Values based on two columns (Looping)

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
kmsekhar
Premium Member
Premium Member
Posts: 58
Joined: Fri Apr 16, 2010 12:58 pm
Location: Chn

Increment Values based on two columns (Looping)

Post by kmsekhar »

Hi,

DS: 8.0.1v, Server Job

My Input File is:

Code: Select all

C|CB|OTH|0001000|0001005
C|CB|OTH|0022222|0022222
C|CB|OTH|0000001|0000003
My desired output should be:

Code: Select all

0001000
0001001
0001002
0001003
0001004
0001005
0022222
0000001
0000002
0000003
I have achieved using script:

Code: Select all

BEGIN {
            FS = "|" 
            OFS = "\n"
        }
{
        diff = $5 - $4
        while ( diff >= 0 ) { 
        printf "%07d\n", $5 - (diff--) 
} 
}
I am trying the same logic to implement in datastage using server routinue, but i am getting only one incremented value could you please help me out in this..

Code: Select all


temp = Arg1

Ans = Arg1

if Arg2<>Arg1 then


LOOP

WHILE temp < Arg2 DO

Ans = Arg1 + 1

temp = temp+1

if Arg1 = Arg2 then EXIT

 REPEAT

END

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

Post by ray.wurlod »

You're overwriting Ans each iteration of the loop. You need to accumulate perhaps a delimited list of values in Ans. Use a different variable to test the comparison between Arg2 and Arg1.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kmsekhar
Premium Member
Premium Member
Posts: 58
Joined: Fri Apr 16, 2010 12:58 pm
Location: Chn

Post by kmsekhar »

Thanks Ray, Now able to generate output as desired

Code: Select all

temp = Arg1

Ans = Arg1

if Arg2<>Arg1 then

LOOP

UNTIL temp > Arg2 DO

Ans = Ans :"|": temp

temp = temp+1


 REPEAT

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

Post by ray.wurlod »

You probably should check that Arg2 > Arg1 at the beginning so that you don't generate an infinite loop.
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