Semantic parsing in KBQA aims to parse natural language questions intological forms, whose execution against a knowledge base produces answers.Learning semantic parsers from question-answer pairs requires searching over ahuge space of logical forms for ones consistent with answers. Current methodsutilize various prior knowlege or entity-level KB constraints to reduce thesearch space. In this paper, we investigate for the first time prior knowledgefrom external logical form annotations and ontology-level constraints. Wedesign a hierarchical architecture for program transfer, and propose anontology-guided pruning algorithm to reduce the search space. The experimentson ComplexWebQuestions show that our method improves the state-of-the-art F1score from 44.0% to 58.7%, with an absolute gain of 14.7%, which demonstratesthe effectiveness of program transfer and ontology awareness.