#Depending on the value for a field in one segment, it makes
#another segment further down the segment grammar a required segment.
message_grammar_iterator.move_to_parentgrammar(); #move from PER to Loop2310A
message_grammar_iterator.move_to_subgrammar("REF"); #move to the REF
#get the grammar
the_grammar = message_grammar_iterator.message_grammar();
#set situationally required.
the_grammar.set_situationally_required();
# if the REF segment does not exist, this code will be run.
# An exception should be raised here
Error = chmexception.errorobject
Error.description = "REF segment is missing when PRV segment in Loop2310A is present"
raise chmexception
Error Code: 0x80002006
Description: REF segment is missing when PRV segment in Loop2310A is present
FieldName: Provider Code
MessageSegmentName: PRV
SegmentRepeatIndex: 0
GrammarSegmentName: REF
ValidationRuleClassId: 4
FieldIndex: 1
ValidationRuleClassName: Situational Python Validation Rule
ValidationRuleName: Segment makes REF mandatory
MessageSegmentIndex: 26