分类: 系统运维
2012-08-03 14:05:38
RPGLE的分支语句有If- ElseIf- Else-EndIf, Select-When-Other-EndSl。 还有几个只能用在RPGLE固定格式中的分支语句:CABxx,CABxx和TAG结合使用;CASxx,CASxx和子程序(Subroutine)一起使用。
RPGLE的循环语句有Do-EndDo(free格式不支持Do循环,使用For来代替),DoW(xx)-EndDo,DoU(xx)-EndDo,For-EndFor。跳出循环的语句有Leave和Iter。Leave就是跳出整个循环,而Iter是跳出本次循环。EX10
0001.00 D True S N Inz('1')
0002.00 D i S 5U 0 Inz(1)
0003.00 D Result S 10A Inz
0004.00 D Wait S 1A
0005.00 C*
0006.00 C DoW True
0007.00 C If i = 1
0008.00 C 'One' Dsply
0009.00 C ElseIf i = 2
0010.00 C 'Two' Dsply
0011.00 C else
0012.00 C Eval Result = %char(i) + ' leave'
0013.00 C Result Dsply
0014.00 C Leave
0015.00 C EndIf
0016.00 C Eval i = i + 1
0017.00 C EndDo
0018.00 C*
0019.00 C For i = 1 to 5
0020.00 C Select
0021.00 C When i = 3
0022.00 C 'Three' Dsply
0023.00 C When i = 4
0024.00 C 'Four' Dsply
0025.00 C Other
0026.00 C Eval Result = %char(i) + ' iter'
0027.00 C Result Dsply
0028.00 C Iter
0029.00 C EndSl
0030.00 C EndFor
0031.00 C*
0032.00 C 'Complete' Dsply Wait
0033.00 C*
0034.00 C Eval *inlr = *on
0035.00 C ReturnEX10F
0001.00 D True S N Inz('1')
0002.00 D i S 5U 0 Inz(1)
0003.00 D Result S 10A Inz
0004.00 D Wait S 1A
0005.00 /free
0006.00 DoW True;
0007.00 If i = 1;
0008.00 Dsply 'One';
0009.00 ElseIf i = 2;
0010.00 Dsply 'Two';
0011.00 Else;
0012.00 Result = %char(i) + ' leave';
0013.00 Dsply Result;
0014.00 Leave;
0015.00 EndIf;
0016.00 i = i + 1;
0017.00 EndDo;
0018.00
0019.00 For i = 1 to 5;
0020.00 Select;
0021.00 When i = 3;
0022.00 Dsply 'Three';
0023.00 When i = 4;
0024.00 Dsply 'Four';
0025.00 Other;
0026.00 Result = %char(i) + ' iter';
0027.00 Dsply Result;
0028.00 Iter;
0029.00 EndSl;
0030.00 EndFor;
0031.00
0032.00 Dsply 'Complete' '' Wait;
0033.00
0034.00 *inlr = *on;
0035.00 return;
0036.00 /end-free你应该看到的内容
1. 在分支语句中如何测试多个判断子句,试一试And(xx), Or(xx)
2. 验证一下CABxx,CASxx,DoU(xx)的用法