Five Stars

## duplicate row based on number value

Hello,

please could you help me with below query. I want to duplicate row based on a stock value.  my input will be from excel file

input :

Item   Description   stock  Location

Tea     Drink            350    shelf1

I want to divide stock with 100 so I can make 4 rows like output below.

output if stock less than 100

Item   Description   stock  Location

Tea     Drink            100    shelf1

output if stock more than 100

Item   Description   stock  Location

Tea     Drink            100    shelf1

Tea     Drink            100    shelf1

Tea     Drink            100    shelf1

Tea     Drink             50    shelf1

Thanks.

Tags (1)

Accepted Solutions
Eight Stars

## Re: duplicate row based on number value

Hi,

I got a solution, probably is not optimized but it's work.

Result for a row with 450 stock

TJavaflex_2 Code :

int Loop = Mathematical.SDIV(((Integer)globalMap.get("row5.stock")) , 100);
if(((Integer)globalMap.get("row5.stock")) % 100 > 0)
{
Loop = Loop + 1 ;
}
globalMap.put("LOOP", Loop);

tLoop Parameter

tJavaFlex_3 Code :

row7.item = ((String)globalMap.get("row5.item"));
row7.desc = ((String)globalMap.get("row5.desc"));
row7.location = ((String)globalMap.get("row5.location"));

if
(((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION"))==((Integer)globalMap.get("LOOP")))
{
if(((Integer)globalMap.get("row5.stock")) % 100!=0)
{
row7.stock = ((Integer)globalMap.get("row5.stock")) % 100;
}
else
{
row7.stock = 100;
}
}
else
{
row7.stock = 100;
}

Good luck ,

SGV

All Replies
Eight Stars

## Re: duplicate row based on number value

Hi,

I got a solution, probably is not optimized but it's work.

Result for a row with 450 stock

TJavaflex_2 Code :

int Loop = Mathematical.SDIV(((Integer)globalMap.get("row5.stock")) , 100);
if(((Integer)globalMap.get("row5.stock")) % 100 > 0)
{
Loop = Loop + 1 ;
}
globalMap.put("LOOP", Loop);

tLoop Parameter

tJavaFlex_3 Code :

row7.item = ((String)globalMap.get("row5.item"));
row7.desc = ((String)globalMap.get("row5.desc"));
row7.location = ((String)globalMap.get("row5.location"));

if
(((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION"))==((Integer)globalMap.get("LOOP")))
{
if(((Integer)globalMap.get("row5.stock")) % 100!=0)
{
row7.stock = ((Integer)globalMap.get("row5.stock")) % 100;
}
else
{
row7.stock = 100;
}
}
else
{
row7.stock = 100;
}

Good luck ,

SGV

## Tutorial

Introduction to Talend Open Studio for Data Integration.

## Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

## Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.