Page 1 of 1

StageVar

Posted: Tue Aug 05, 2008 9:57 am
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

Posted: Tue Aug 05, 2008 10:11 am
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.

Posted: Tue Aug 05, 2008 12:02 pm
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.

Posted: Tue Aug 05, 2008 12:19 pm
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.

Posted: Tue Aug 05, 2008 12:26 pm
by randy
I agree about the 2 passes, but could not see the complete response.

Posted: Tue Aug 05, 2008 1:07 pm
by randy
Although I could still use a hint or two.

Posted: Tue Aug 05, 2008 1:15 pm
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.

Posted: Tue Aug 05, 2008 1:27 pm
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

Posted: Wed Aug 06, 2008 3:02 pm
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

Posted: Wed Aug 06, 2008 3:16 pm
by chulett
That would work, too, since the output is a hashed file where order isn't an issue. :wink:

Posted: Thu Aug 07, 2008 7:58 am
by randy
chulett, shepli,

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

Randy