Question on Custom Build Stage

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
derekchu
Participant
Posts: 23
Joined: Sun Sep 24, 2006 10:09 pm

Question on Custom Build Stage

Post by derekchu »

Hi,

I am writing a custom build stage which read a reference input into memory.

I wrote the following in the "Definition Tab"
#include <apt_util/date.h>
APT_Date Lower_Bound [500];
APT_Date Upper_Bound [500];
APT_String Value [500];
int NumLabels=0;
and I wrote the following in the "Pre-Loop" to read all records from the reference stream to memory:

readRecord(1);
while (!inputDone(1))
{
if (NumLabels <= 499)
{
Lower_Bound[NumLabels] = RefRec.Min;
Upper_Bound[NumLabels] = RefRec.Max;
Value[NumLabels] = RefRec.Value;
NumLabels++;
}
readRecord(1);
}


However as the size of the arrays are fixed (e.g. 500), I cannot read a reference stream with all records. Is there any way to due to dynamic array in custom build stage?

Regards,
Derek
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

You can very much add locations by obtaining from new.
derekchu
Participant
Posts: 23
Joined: Sun Sep 24, 2006 10:09 pm

Post by derekchu »

Can you elaborate more on this?

Thanks.

Regards,
Derek
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

There are many ways to allocate more locations to your variables.

One method is malloc(). Another is new.

Alternatively you can work in stacks and linked lists or create your own structure.

If it is from a file, you can use file pointers to access locations without loading into memory.
mavrick21
Premium Member
Premium Member
Posts: 335
Joined: Sun Apr 23, 2006 11:25 pm

Post by mavrick21 »

Sainath/Derek,

I'm a beginner to Custom Build Stage and I'm interested to learn more about it. Can you please tell me how do I go about it?

Thanks for your time.
derekchu
Participant
Posts: 23
Joined: Sun Sep 24, 2006 10:09 pm

Post by derekchu »

Sainath,

Yes, I managed with the malloc for declaring a dynamic array, and realloc when growing the array.

However I hit another problem.

If the Input field is a "null", then if I simply assign this to the variable, Datastage fails to run:

APT_String x;

x=InRec.Field1;
// where InRec is the input and Field1 contains "null"


How can we handle null value for the input?

Regards,
Derek CHU
Post Reply