IF is used to define conditions for when groups of operation should be performed or not.
ENDIF or END is used to close an IF statement.
ELSEIF can be used in combination with IF to avoid nested IF statements.
ELSE is used in combination with IF to define what should be done if the previous conditions have not been met.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
dcl-s Name varchar(128); dcl-s Message varchar(52); Name = 'Mats'; if Name = 'Mats'; Message = Name + ' is living on the Swedish East Cost'; elseif Name = 'Christoffer'; Message = Name + ' is living on the Swedish West Cost'; else; Message = 'I do not know where ' + Name + ' is living'; endif; dsply Message; |
Example RPGIV Fixed Format
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
D Name 128A D Message 52A * C Eval Name = 'Mats' * C If Name = 'Mats' C Eval Message = %Trim(Name) + C ' is living on the Swedish East Cost' C ElseIf Name = 'Christoffer' C Eval Message = %Trim(Name) + C ' is living on the Swedish West Cost' C Else C Eval Message = 'I do not know where ' + C %Trim(Name) + ' is living' C EndIf * C Message Dsply |