Bill of materials (BOM) is the term used to describe the "parts list" of components needed to complete a saleable end-item.

BOMs are hierarchical in nature with the top level representing the sub-assembly or end-item. For example the end-item BOM for a Personal computer would list the computer, its major sub-assemblies (board, chassis, modem, keyboard, display, etc.) as well as additional materials needed for a complete saleable product -- shipping box, user manual, packaging, packaging labels, etc.

For my case, DB2 Table loks like below.

Major Part Minor part

P1 P2
P1 P5
P2 P3
P3 P6
P3 P7
P5 P2
... ...
... ...

Both columns together form a composite Primary Key.

Here, I want to find out What are the Minor Parts needed for building a Major part?

If you take P1 as Major part, it needs P2 and P5 as minor parts. And P2 needs P3. And P3 needs P6 and P7. And so on.

P2, P5, P3, P6, P7 are the Minor parts of Major part P1.

How to form a query to this requirement?
Here Major part will be given as input and Minor parts are expected as a result.

I Feel that The db2 version is irrelevant in this case...
the design must choose the logic flow,
the DB2 facilities might help to write less code...

Nobody with a reasonable understanding of BOM processing
would base the application development on forum replies,
that' s why I asked if it was homework or not...

Usually ( at least were I was involved in building the teams ) the DB design was done with the help and APPROUVAL of DB support,
and all the relevant queries were modeled and tested by db support before being deployed to the programmers

in this case ( forget about the right syntax, it' s just the concept )
select lev0.pn, lev1.pn, lev2.pn,.... for the number of hardcoded levels from (pn_mastr lev0 ( pn_mast lev1
( I HAD A MODEL TESTED AND WORKING A LOONG TIME AGO, BUT THREW AWAY EVERITHING :-( )

will give the bom exploded view for n levels ...
but this will be only a theoretical query.. even if correct one from a sql point of view
and I would never dream to approach a BOM application in this way

BOM has too many nuances
for the relevant queries to solved by db2 advanced query techniques only