Five 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

Accepted Solutions
Sixteen 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

Forteen 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:

Hope this helps.

TRF

All Replies
Sixteen 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

Forteen 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:

Hope this helps.

TRF
Sixteen Stars

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

Great minds think alike @TRF :-)

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
Five Stars

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

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.

Regards