Problems with STAGE VARIABLE DERIVATION

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
kumarjit
Participant
Posts: 99
Joined: Fri Oct 12, 2012 7:47 am
Location: Kolkata

Problems with STAGE VARIABLE DERIVATION

Post by kumarjit »

I am having a source table named PRODUCT .
Its schema is given below.

Code: Select all

PROD_ID            VARCHAR2(11 CHAR)
NAME               VARCHAR2(50 CHAR)
PRICE              VARCHAR2(5 CHAR)
GROUP_CODE         VARCHAR2(4 CHAR)
Examples of data in column PRICE are 80, 70, 170, 90, 70

My intention is to use the looping feature of tranformer stage and create a sub total of the column PRICE for each DISTINCT value of GROUP_CODE column.

I created two stage variables and used the following experssions for them :

PRICESUM=If LastRowInGroup(DSLink4.GROUP_CODE) Then 0 Else PRICESUM + DSLink4.PRICE
PRICETOTAL=If LastRowInGroup(DSLink4.GROUP_CODE) Then PRICESUM + DSLink4.PRICE Else 0

The datatypes for the above stage variables are Varchar.

The problem I am facing is that the values of these stage variables are not getting evaluated properly.


Can anyone please help me on this ?

Thanks
Kumarjit.
Pain is the best teacher, but very few attend his class..
zulfi123786
Premium Member
Premium Member
Posts: 730
Joined: Tue Nov 04, 2008 10:14 am
Location: Bangalore

Post by zulfi123786 »

Arithmetic operations on varchars is not right approach. convert them into integers using AsInteger() and even before that, check if they can be converted into integers using num() .
- Zulfi
BI-RMA
Premium Member
Premium Member
Posts: 463
Joined: Sun Nov 01, 2009 3:55 pm
Location: Hamburg

Post by BI-RMA »

Hi Kumarjit,

ad 1: you are not using the looping-feature of the transformer stage, but the key-break-detection feature, which is not the same.

ad2: datatype Varchar for the stage variables is false. DataStage can't do arithmetic operations using Varchar. Use decimal-datatype and correct conversion-functions.

ad3: you initialize PRICESUM with 0 on LastRowInGroup and then you calculate PRICETOTAL as PRICESUM + DSLink4.PRICE. This is wrong.
You need to change order of execution and initialize PRICESUM with 0 on the outset.

PRICETOTAL = PRICESUM + DSLink4.PRICE
PRICESUM: If LastRowInGroup(DSLink4.GROUP_CODE) Then 0 Else PRICETOTAL

The LastRowInGroup-function on PRICETOTAL can be omitted.
Instead you should use the function on the transformers link-constraint, so that only the last row per group is output to the link.
"It is not the lucky ones are grateful.
There are the grateful those are happy." Francis Bacon
FranklinE
Premium Member
Premium Member
Posts: 739
Joined: Tue Nov 25, 2008 2:19 pm
Location: Malvern, PA

Post by FranklinE »

Perhaps I'm missing something, but why not use Aggregator stage? With Zulfi's warning about converting to numbers, Aggregator will do what you need.
Franklin Evans
"Shared pain is lessened, shared joy increased. Thus do we refute entropy." -- Spider Robinson

Using mainframe data FAQ: viewtopic.php?t=143596 Using CFF FAQ: viewtopic.php?t=157872
Post Reply