Little code snippet as provided below can help you get the number of children associated with a particular worker.
public static void getEmployeeTotalChildren(Args _args)
{
DirPartyRelationship partyRelationship;
DirRelationshipTypeTable relationshipTypeTable;
DirPerson dirPerson;
HcmWorker worker;
DirPartyTable partyTable;
///get the worker by personnel number
worker = HcmWorker::findByPersonnelNumber('NNNNN');
select firstonly dirPerson
where dirPerson.RecId == worker.Person
join partyTable
where partyTable.PartyNumber == dirPerson.PartyNumber;
select count(RecId) from partyRelationship
join RelationshipTypeId, SystemType from relationshipTypeTable
where partyRelationship.ParentParty == partyTable.RecId
&& relationshipTypeTable.RelationshipTypeId == partyRelationship.RelationshipTypeId
&& relationshipTypeTable.SystemType == DirSystemRelationshipType::Child;
info(strFmt("Total Children of Worker %1, are %2", worker.name(), partyRelationship.RecId));
}