[...]
UNION ALL
SELECT CHILD.functional_reporting_to, CHILD.empcode
FROM RPL PARENT, db2admin.employee_details CHILD
WHERE PARENT.empcode = CHILD.functional_reporting_to
and child.functional_reporting_to = 'emp500'
[...]
This condition is erroneous.
employees, which are added in the recursion do not report to emp500. They report to employees which report to employees which report to employees which ... report to emp500.
Just omit this condition.
You might want to include an counter to limit the number of iterations ( to avoid infinite loops ):
WITH RPL (empcode, functional_reporting_to, level) AS
(
SELECT ROOT.functional_reporting_to, ROOT.empcode , 1 as level
FROM db2admin.employee_details ROOT
WHERE ROOT.functional_reporting_to = 'emp500'
UNION ALL
SELECT CHILD.functional_reporting_to, CHILD.empcode, parent.level + 1 as level
FROM RPL PARENT, db2admin.employee_details CHILD
WHERE PARENT.empcode = CHILD.functional_reporting_to
and parent.level < 10
)
SELECT DISTINCT functional_reporting_to, empcode, level
FROM RPL
ORDER BY functional_reporting_to, empcode ;