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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Eight Stars sgv
Eight Stars

Re: duplicate row based on number value

Hi,

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

Capture.PNG

Result for a row with 450 stock

Capture.PNG

 

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

Capture.PNG

 

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

1 REPLY
Eight Stars sgv
Eight Stars

Re: duplicate row based on number value

Hi,

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

Capture.PNG

Result for a row with 450 stock

Capture.PNG

 

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

Capture.PNG

 

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