i belive there is error in the relation name at line
IF lr_entity ISBOUND.
lr_entity ?= lr_entity->get_related_entity( iv_relation_name = 'BTOrderDocFlowSet' ). the relation name should be BTHeaderDocFlowSet as in the lr_entity you have BTAdminh. check it once.