Help in flow script

Hi Gurus,

I was trying below script test to do a calculation and not able to do , need your help.

I have a flow table WHINVTBL which below data

PArtID PartDesc InvQty Intransit
123 itm1 10 2
456 itm2 6 1

Now calculating SOH by doing InvQty - Intransit and want to return a new table from script with below value

PArtID PartDesc SOH
123 itm1 8
456 itm2 5

------- using below -----------

let SOH =0;
let NEWWHINVTBL = WHINVTBL ;

FOR k in WhINVTBL {

set SOH = k.InvQty - k.Intransit;

NEWWHINVTBL =NEWWHINVTBL & [ITMID: k.PartId ,ITEMDESC: k.PartDesc, SOH: SOH];

}

return NEWWHINVTBL;

It’s not happening, please help me in this what wrong I’m doing in script.

Hi, I think you should use the Empty statement to initialize the NEWWHIINVTBL.

Even easier is probably to use MAP AS:

/Roel

Hi,

above you are saying let NEWWHINVTBL = WHINVTBL ; which means that the columns of NEWWHINVTBL should be the same 4 columns as WHINVTBL too. (PArtID, PartDesc, InvQty, Intransit)

But then in the loop you want to add record with 3 columns (ITMID, ITEMDESC, SOH) to NEWWHINVTBL which is defined as 4 column table.

So just define
let NEWWHINVTBL = table(ITMID, ITEMDESC, SOH);

and it should work.

Hope this helps!

B R
Ivan

Thanks Ivan,
It helps me as I did a small mistake there.

Also, for performance reasons, I would NOT do “for k in WhINVTBL”. Instead try:

let SOH = 0;
let NEWWHINVTBL = map WHINVTBL as [ITMID: PartID, ITEMDESC: PartDesc, SOH: InvQty - Intransit];
return NEWWHINVTBL;