Create Dynamic file

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
bkumar103
Participant
Posts: 214
Joined: Wed Jul 25, 2007 2:29 am
Location: Chennai

Create Dynamic file

Post by bkumar103 »

Sorry By mistake i posted into wrong forum. hence i am posting it again
-----------------------------------------------------------------------------------
Is it possible to create files dynamically based on the some input column value. For example

suppose the the input consist of two columns country_cd and city_cd.
and the input stores the information abt 5 distinct country and their respective city as follow

Country_cd city_cd
===========================
cntry1 city1
cntry1 city2
cntry2 city2
cntry2 city3
cntry3 city4
cntry4 city5
cntry5 city5

what i require here is one seperate file should be created for each county and respective country records should go to the corresponding file.
like the file cntry1.txt should have folllowing records:

Country_cd city_cd
===========================
cntry1 city1
cntry1 city2

Pease let me know if this is possible to do in parallel jobs.
Birendra
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Of course it's possible. Use a Switch, Filter or Transformer stage with five outputs to Sequential File stages.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
bkumar103
Participant
Posts: 214
Joined: Wed Jul 25, 2007 2:29 am
Location: Chennai

Post by bkumar103 »

But there is two problem:

1. The no of country code is not constant. Next day there might be 6 distinct country code.

2. The country_cd is not known. I am expaecting the file should be created with the coutryname.txt
Birendra
Madhavan VM
Participant
Posts: 33
Joined: Sat Jul 02, 2005 2:27 am
Location: Bangalore

Post by Madhavan VM »

Hi,

This can be done using a DataStage job and a script which can be called as an after job routine.

Steps:

1. Create a column Srrgt_Dist_Ctry_Cd. This value should be same for the country and should increment for the next country. Hence, use a transformer to create the below output:

Country_cd city_cd Srrgt_Dist_Ctry_Cd
===========================
cntry1 city1 1
cntry1 city2 1
cntry2 city2 2
cntry2 city3 2
cntry3 city4 3
cntry4 city5 4
cntry5 city5 5

2. Write a script and read the Srrgt_Dist_Ctry_Cd in the last line of the file to know the number of distinct records.

3. Read the column values into variables in the script and use a for loop to achieve what you desire.

CAUTION: The script would take long if the number of records are high.
warm regards,
Ajith GK
just4geeks
Premium Member
Premium Member
Posts: 644
Joined: Sat Aug 26, 2006 3:59 pm
Location: Mclean, VA

Post by just4geeks »

bkumar103 wrote:But there is two problem:

1. The no of country code is not constant. Next day there might be 6 distinct country code.

2. The country_cd is not known. I am expaecting the file should be created with the coutryname.txt
Here is the screenshot.
Image

In the Transformer, declare 2 stage variables called

Code: Select all

If (PrecountryCd<> countryCd) Then 'N' Else 'Y'     :    Var1
Country_Cd                                          : Precountrycd
Depending upon the variable Var1, channel records to either output or input_next_round.

Specify all file names as parameters. When run for the first time, the output file contains the following records.

Code: Select all

cntry1 city1 1
cntry1 city2 1 
And the file Input_next_round is left the following records.

Code: Select all

cntry2 city2 2
cntry2 city3 2
cntry3 city4 3
cntry4 city5 4
cntry5 city5 5
In a UNIX script, run this DS job again with input file being the input_next_round file. Run as many times as the file is non-empty. You can specify the output file name in UNIX by parsing the first column of the first record.
Attitude is everything....
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Your original question specified five. I answered for five.

Adapt to suit the maximum possible number.
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