Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
sdtfll
Contributor III
Contributor III

how to do a recursion for BOM

itemraw_materialusage
FG1raw14
FG1raw21
FG1semi16
FG2semi210
FG2raw25
semi1raw37
semi2raw410

I have a table about the bill of materials, as shown above, 

for item FG1, it uses raw1 4pcs, raw2 1pcs, raw3 7pcs, semi1 6pcs,

and semi1 uses raw3 7pcs, so FG1 uses raw3 6*7=42pcs, and raw3 should be at level2,

 

for item FG2, it uses raw2 5pcs, semi2 10pcs, 

and semi2 uses raw4 10pcs, therefore the FG2 uses raw4 10*10=100pcs. and raw4 should be at level2

 

I want to make a new table as shown in below picture, to re-organize the BOM table,

firstly define each item,

FG: finished goods, FG1, FG2,

M: manufactured, semi1, semi2,

P:purchase, the other raw materials,

itemraw_materialtype_of_raw_materialusagelevel
FG1raw1P41
FG1raw2P11
FG1semi1M61
FG1raw3P422
FG2raw2P51
FG2semi2M101
FG2raw4P1002

this is just simple example, in my situation, the level reaches even bigger such as level 5, or level 6, a recursion is must, but I don't know how to deal with it using Qlik sense.

I need your help, thanks advanced,

 

my scripts as below, the recursion part is blank:

BOM:
load * inline [
Parent,son,qty
FG1,raw1,4
FG1,raw2,1
FG1,semi1,6
FG2,semi2,10
FG2,raw2,5
semi1,raw3,7
semi2,raw4,10
];

//STEP1, define FG, M, AND P, create the item list maste table
ItemList:
load Parent as item,If(not Exists(son,Parent),'FG','M') as type Resident BOM;
Concatenate(ItemList)
load son as item, If(not Exists(Parent, son),'P','M') as type Resident BOM
where not Exists(item, son);

 

step2, recursion

//sub call

sub expand_BOM(item,level,qty)
Temp:
load Parent as subParent,son as subSon,qty*$(qty) as subQty Resident BOM where Parent=$(item);
//have no idea how
end sub

 

//main loop

for each fgItem in FieldValueList('Parent')
temp:
NoConcatenate load FGNo as tempFG, rawItem as tempItem,type,qty Resident FGBOM WHERE FGNo='$(fgItem)';
for each tempRow in FieldValueList('tempItem')
//have no idea
next
next

does anyone can provide some useful information or solution for this, thanks 

4 Replies
sdtfll
Contributor III
Contributor III
Author

I seached some articles from here and did some study, but still have no idea how to solve it,

it's easy in SQL side but I have no right to create a recursion procedure in sql server database side,

 

 

wgonzalez
Partner - Creator
Partner - Creator

@sdtfll  if you could share the SQL script, it might help anyway.  Thanks.

wgonzalez
Partner - Creator
Partner - Creator

Have  you been able to solve it?  I have the same need.  Thanks.

sdtfll
Contributor III
Contributor III
Author

sorry to reply you so late,

I did the recursion outside qlik, and then put the data into qlik to display.