StageVar

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
randy
Participant
Posts: 30
Joined: Tue Sep 13, 2005 11:17 am

StageVar

Post by randy »

My test file looks like this

123
234
07 "IMPORTANT LABEL 1' some totals
345
456
07 "IMPORTANT LABEL 2' some totals

What I need to do, is put the IMPORTANT LABEL on each line of the data I load. The Label is always at the end of the data. The line with IMPORTANT LABEL always starts with '07'.

so my hash file should be
123 IMPORTANT LABEL 1
234 IMPORTANT LABEL 1
345 IMPORTANT LABEL 2
456 IMPORTANT LABEL 2
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

In server jobs this can be done in several ways, I would do it with a transform stage followed by a named pipe. The stage variables would be

IsLabel = IF In.ColumnData[1,2]='07' THEN FIELD(FIELD(In.ColumnData,'"',2),"'",1) ELSE ''

OutputString = IF IsLabel THEN EREPLACE(CollectionString,@FM,',"':IsLabel:'"':CHAR(10))

CollectionString = IF IsLabel THEN '' ELSE CollectionString:@FM:In.ColumnData

Output Constraint "IsLabel"

This generates the data in the format

Code: Select all

123,"IMPORTANT LABEL 1"
234,"IMPORTANT LABEL 1"
etc...
Then output of the transform goes to a named pipe declared with just one column as input. The output would have 2 columns, the data then the label as varchar with normal UNIX line terminators and the label column having surrounding quotes.
randy
Participant
Posts: 30
Joined: Tue Sep 13, 2005 11:17 am

Post by randy »

I only saw the first 2 lines of your response, but I was having problems with the fact that the line the StageVar was reading was coming after the data.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I don't see how you would do something like this without making two passes through the data. :? But with two passes it wouldn't be all that hard.
-craig

"You can never have too many knives" -- Logan Nine Fingers
randy
Participant
Posts: 30
Joined: Tue Sep 13, 2005 11:17 am

Post by randy »

I agree about the 2 passes, but could not see the complete response.
randy
Participant
Posts: 30
Joined: Tue Sep 13, 2005 11:17 am

Post by randy »

Although I could still use a hint or two.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Assign a number to each "group" of input records. Build a hashed file with the group number and "Label" for each 07. Run back through the data and use the group number to get the label for the group.
-craig

"You can never have too many knives" -- Logan Nine Fingers
randy
Participant
Posts: 30
Joined: Tue Sep 13, 2005 11:17 am

Post by randy »

If I have a stage variable like this:

If(lnkFTP.line_data[1,2]='70') Then lnkFTP.line_data[4,11] Else StageVar1

then some lines get the Label1, but the rest get 0's
shepli
Participant
Posts: 79
Joined: Fri Dec 17, 2004 9:56 am

Post by shepli »

Assign line number to each line (@INROWNUM) and sort the records by line number (descendent). You will see 07 "IMPORTANT LABEL 1' (save this as a stage variable) before you see 234 and 123

shepli
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

That would work, too, since the output is a hashed file where order isn't an issue. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
randy
Participant
Posts: 30
Joined: Tue Sep 13, 2005 11:17 am

Post by randy »

chulett, shepli,

thanks so much for the help. I was really stuck.

Randy
Post Reply