I have a tricky statement to built and could not find a solution yet - maybe one of you have a nice idea!

In our company we have so-called local customer hierarchy which is used on the one hand for grouping of customers and have settings on higher level than customer number. On the other hand used for reporting on different levels. This hierarchy is our a-level-hierarchy and it is usually used by the local affiliates. Technically the assignment can be found in entries from KNVH, where KNVH-HITYP = A.
When reporting in headquarters a-level-hierarchy-numbers are grouped into f-level-hierarchy (also called GCN=GlobalCustomerNumber) and reporting is based on f-level. Technically the assignment can be found in entries from KNVH, where KNVH-HITYP = F.
Basically as not always the lowest level of a-level-hierarchy is assigned to the lowest level of f-level-hierarchy, I have to check every a-level-value against the lowest level of f-level-hierarchy.
I built a statment that will give me the result of this screenshot (VBELN and KUNNR have the same values for both result lines):
CustomerHierachy.jpg871194 43.2 KB
The relevant condition from a to f-level-hierarchy is:
AND KNVH_GCN.KUNNR in (KNVH_1A.HKUNNR,
KNVH_1B.HKUNNR,KNVH_1C.HKUNNR,KNVH_1D.HKUNNR,
KNVH_1E.HKUNNR,KNVH_1F.HKUNNR,KNVH_1G.HKUNNR)
In the end I only need the match of the join, that was from the lowest a-level-hierarchy match with the GCN_AHierarchy level in the screenshot - otherwise (as this is part of my VBAK-View for Celonis i have 2 entries for 1 order in VBAK). In this case would be the match of KUNNR_1B column. There is also a match on higher level (KUNNR_1C) but this i do not need, if a lower level found a match.
Do you have any idea on how to check? I am free to explain further, as this is really a heavy topic

Thank you in advance for your hints!!
BR,
Marcel