The data that is missing from your "input file" is the column that indicates the hierarchy of the data - you cannot rely on the order that the data appears in the file, you must have an explicit way of expressing who "reports" to whom.
This would work
declare @ctb table (BOM varchar(3), Lvl int, Ref varchar(10), MANAGER varchar(10))
insert into @ctb(BOM, Lvl, Ref, MANAGER) values
('ABC', 0, 'ABC', NULL)
,('ABC', 1, 'WXYZ', 'ABC')
,('ABC', 2, 'b', 'WXYZ')
,('ABC', 2, 'c', 'WXYZ')
,('ABC', 2, 'd', 'WXYZ')
,('ABC', 2, 'e', 'WXYZ')
,('ABC', 2, 'f', 'WXYZ')
,('ABC', 1, 'MNOP', 'ABC')
,('ABC', 2, 'k', 'MNOP')
,('ABC', 2, 'l', 'MNOP')
,('ABC', 2, 'm', 'MNOP')
,('ABC', 2, 'n', 'MNOP')
,('ABC', 2, 'o', 'MNOP')
I.e.
BOM Lvl Ref MANAGER
ABC 0 ABC NULL
ABC 1 WXYZ ABC
ABC 2 b WXYZ
ABC 2 c WXYZ
ABC 2 d WXYZ
ABC 2 e WXYZ
ABC 2 f WXYZ
ABC 1 MNOP ABC
ABC 2 k MNOP
ABC 2 l MNOP
ABC 2 m MNOP
ABC 2 n MNOP
ABC 2 o MNOP
You can then use
PIVOT[
^] to get close to what you need
select * from
(
select BOM, Lvl, Ref, MANAGER
from @ctb
) anch
PIVOT
(
MAX(MANAGER) FOR Lvl in ([0],[1],[2])
) PVT
which produces the results
BOM Ref 0 1 2
ABC ABC NULL NULL NULL
ABC b NULL NULL WXYZ
ABC c NULL NULL WXYZ
ABC d NULL NULL WXYZ
ABC e NULL NULL WXYZ
ABC f NULL NULL WXYZ
ABC k NULL NULL MNOP
ABC l NULL NULL MNOP
ABC m NULL NULL MNOP
ABC MNOP NULL ABC NULL
ABC n NULL NULL MNOP
ABC o NULL NULL MNOP
ABC WXYZ NULL ABC NULL
You can tidy that up a bit by ignoring some of the rows and by repeating one of the columns
select BOM, BOM, [2], Ref
from
(
select * from
(
select BOM, Lvl, Ref, MANAGER
from @ctb
) anch
PIVOT
(
MAX(MANAGER) FOR Lvl in ([0],[1],[2])
) PVT
) as x
WHERE [2] IS NOT NULL
which gives results
BOM BOM 2 Ref
ABC ABC WXYZ b
ABC ABC WXYZ c
ABC ABC WXYZ d
ABC ABC WXYZ e
ABC ABC WXYZ f
ABC ABC MNOP k
ABC ABC MNOP l
ABC ABC MNOP m
ABC ABC MNOP n
ABC ABC MNOP o
The only difference between these results and the ones you posted as your expected results are the missing duplicated rows that you do not explain (i.e. your expected results are probably wrong)