Hi, attached is a program, that has no restrictions on the product sturcture (Of course do avoid cycles! ). Sorry, it is not very well documented, and maybe it is easyer to write this program, than to understand. Important: You will need one additional pass through the results, because if a component is included on multiple products paths, it will appeare multiple times in the result. (You have no such cases in the attached product stucture.) I think you can easily aggregate them. (I didn't want to complicate this program any further.) Also in my program BOM_id is simply a number. If you have multiple levels in the product tree, it makes no more sense to include this info in an ID field. Is it? Anyway, you can consturct a (very long) character variable that can include the "path" of the product decomposition. Look at this formula in my program: bom_quant*Percentage_Quantity Similarly you can constuct a variable like this: bom_path || Parent || Alternative I have changed your input data a bit: I included more levels. Currently this program reads a dataset called Parts. The program could be easily exteded to handle more parts, but right now it expands only 1 row (=1 Part). Be carefull with big product trees. The result can become quickly huge. (I guess you know that.) Algorithm: We maintain a list of BOMs in an internal table (bom_list). We initialize this table with one row: the unexpanded part list (unexpanded BOM). We go through this list again and again and when we find a Part, that can be expanded (i.e. it is in the productStucture table as Parent), we expand it. Expanding means simply copying all the entries (rows) of a BOM numAlternatives times. While copying, we keep all entries as they are, except the entry, that should be expanded. That entry is replaced and sometimes also doubled/tripled/etc., depenting how many Children (Components) the Parent has. The rest is just technical (not algorithmical) thing: I am dynamically adding and removing from this internal (hash) table. I am using an iterator to "walk" through it. Also I am using some more hash tables, and iterators to make my life easier. See inline comments in the code. Technically I don't re-read the bom_list table, I am reading it only once. But while reading I am appending new entries to the end of the list(table).
... View more