Four Stars

Load Half records to one target another half to another target

Hi, 
Anyone ever got a scenerio to load first half of source records irrespective of count(i mean sourcecount can change dynamically) into one target and remaining half of source records into another target? 
Like for eg:suppose i have source say srce:which is having total number of records as 100 
i want 50 to be loaded into one target tgt1 and next 50 to be loaded into another target tgt2. 
Please let me know if anybody knows the solution for this scenerio 
‌Thanks in advance....
2 ACCEPTED SOLUTIONS

Accepted Solutions
Twelve Stars

Re: Load Half records to one target another half to another target

You can use the modulus operator to do this quite easily. You would pass your source to a tMap with two outputs. Use a tMap variable to generate a sequence number. In the output filters, use a modulus operation to decide which way the data should flow. This will work irrespective of how many rows are returned.

 

An example of the sort of output filter you will need is below....

 

//First output
intSequenceNum%2==0

 

//Second output
intSequenceNum%2!=0

Rilhia Solutions
Twelve Stars TRF
Twelve Stars

Re: Load Half records to one target another half to another target

Hi,

 

Here is a simple solution.

Connect your input to a tMap in which you define a local variable (count for example) associated to a sequence(s1 for example).

Now, define 2 output in the tMap, drag and drop the desired fields for each and (the solution), add a filter for each outpout to filter odd and even values for the sequence.

Here is the tMap:Capture.PNG

Hope this helps.

 


TRF
4 REPLIES
Twelve Stars

Re: Load Half records to one target another half to another target

You can use the modulus operator to do this quite easily. You would pass your source to a tMap with two outputs. Use a tMap variable to generate a sequence number. In the output filters, use a modulus operation to decide which way the data should flow. This will work irrespective of how many rows are returned.

 

An example of the sort of output filter you will need is below....

 

//First output
intSequenceNum%2==0

 

//Second output
intSequenceNum%2!=0

Rilhia Solutions
Twelve Stars TRF
Twelve Stars

Re: Load Half records to one target another half to another target

Hi,

 

Here is a simple solution.

Connect your input to a tMap in which you define a local variable (count for example) associated to a sequence(s1 for example).

Now, define 2 output in the tMap, drag and drop the desired fields for each and (the solution), add a filter for each outpout to filter odd and even values for the sequence.

Here is the tMap:Capture.PNG

Hope this helps.

 


TRF
Twelve Stars

Re: Load Half records to one target another half to another target

Great minds think alike @TRF :-)

Rilhia Solutions
Employee

Re: Load Half records to one target another half to another target

In addition to what TRF and ahall mentioned: you can also go for another approach as below

1. Find out the number of records in input file using 'tfileinputrowcount' , devide the count by 2 (not modulo) , the division is your split boundary between files.
2. in tMap just calculate if seq num is less than or greater than the division . If less flag it as 'L' if more flag it as 'M'
3. Use tflowtoiterate and then in tfileoutputdelimited filename use the 'flag' variable (use append mode).
Dynamicaly this will create two target files.

This will also work fine if you want to scale up tomorrow to 2 , 3 4 target files , you dont have to create targets manually in tMap.

Regards
Nayak