Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
Viswa560
Contributor
Contributor

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....
Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable

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

View solution in original post

6 Replies
Anonymous
Not applicable

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

TRF
Champion II
Champion II

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:0683p000009LwQb.png

Hope this helps.

 

Anonymous
Not applicable

Great minds think alike @TRF 🙂

Anonymous
Not applicable

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
Anonymous
Not applicable

Hi , 

your approach approach is splitting the table in EVEN & ODD number of  sequence .

But ,what if I need first 3 records to one table and last 3 into another ?

not like Seq. 1,3,5 in Table A and Seq 2,4,6 in Table B ..Not Like that.

 

Thanks in advance.

 

Regards 

Subhadeep

 

Anonymous
Not applicable

Thanks, you helped me too!