条件:RPG中的正数和负数
Condition: positive and negative number in RPG
当我在我的控制台中输入一个负数时,我没有得到显示!
例如,如果输入值“-2”,我不会收到消息“negative”
在积极和无效的情况下都可以
H
D Number S 2S 0
*
/Free
dsply 'Enter your number please : ' '' Number;
If (Number > 0);
dsply 'Positive';
ElseIf (Number = 0);
dsply 'Null';
Else;
dsply 'Negative';
ENDIF;
*inlr = *on;
/End-Free
在 DSPLY 操作码的 RPGLE 参考中,我找到了这个摘录:
If a non-float numeric field is entered with a length greater than the number of digits in the result field
and the rightmost character is not a minus sign (-), an error is detected and a second wait occurs. The
user must key in the field again.
DSPLY 操作码似乎希望减号在尾部而不是前导。
如果您在 DSPLY 消息上执行 F1(帮助),它会显示:
Message ID . . . . . . : RNQ5337 Severity . . . . . . . : 00
Message type . . . . . : Sender copy
Date sent . . . . . . : 12/18/20 Time sent . . . . . . : 12:42:16
Message . . . . : DSPLY Enter your number please : 0
Cause . . . . . : This is an inquiry message originated from RPG procedure
MY_PGM in program MY_LIB/MY_PGM. The program is expecting a numeric
input field with a maximum length of 2 digits with 0 decimal positions. Do
not type in a decimal point when entering data. When entering negative data,
type a negative sign ('-') immediately after the last digit of the data.
您可以使用 %dec() to convert a numeric value in a string to a numeric variable. That will allow your users to place the negative sign on the left or the right. This might be a friendlier way of using the DSPLY 操作码。
**FREE
//simple demo, not worrying about exceptions
dcl-s myStr varchar(5);
dcl-s myNum packed(3:0);
dsply 'Enter your number please : ' '' myStr;
myNum = %dec(myStr:3:0);
Select;
When (myNum > 0);
dsply 'Positive';
When (myNum = 0);
dsply 'Zero'; // not the same a null ;-)
Other;
dsply 'Negative';
EndSl;
*inlr = *on;
RETURN;
当我在我的控制台中输入一个负数时,我没有得到显示! 例如,如果输入值“-2”,我不会收到消息“negative”
在积极和无效的情况下都可以
H
D Number S 2S 0
*
/Free
dsply 'Enter your number please : ' '' Number;
If (Number > 0);
dsply 'Positive';
ElseIf (Number = 0);
dsply 'Null';
Else;
dsply 'Negative';
ENDIF;
*inlr = *on;
/End-Free
在 DSPLY 操作码的 RPGLE 参考中,我找到了这个摘录:
If a non-float numeric field is entered with a length greater than the number of digits in the result field and the rightmost character is not a minus sign (-), an error is detected and a second wait occurs. The user must key in the field again.
DSPLY 操作码似乎希望减号在尾部而不是前导。
如果您在 DSPLY 消息上执行 F1(帮助),它会显示:
Message ID . . . . . . : RNQ5337 Severity . . . . . . . : 00
Message type . . . . . : Sender copy
Date sent . . . . . . : 12/18/20 Time sent . . . . . . : 12:42:16
Message . . . . : DSPLY Enter your number please : 0
Cause . . . . . : This is an inquiry message originated from RPG procedure
MY_PGM in program MY_LIB/MY_PGM. The program is expecting a numeric
input field with a maximum length of 2 digits with 0 decimal positions. Do
not type in a decimal point when entering data. When entering negative data,
type a negative sign ('-') immediately after the last digit of the data.
您可以使用 %dec() to convert a numeric value in a string to a numeric variable. That will allow your users to place the negative sign on the left or the right. This might be a friendlier way of using the DSPLY 操作码。
**FREE
//simple demo, not worrying about exceptions
dcl-s myStr varchar(5);
dcl-s myNum packed(3:0);
dsply 'Enter your number please : ' '' myStr;
myNum = %dec(myStr:3:0);
Select;
When (myNum > 0);
dsply 'Positive';
When (myNum = 0);
dsply 'Zero'; // not the same a null ;-)
Other;
dsply 'Negative';
EndSl;
*inlr = *on;
RETURN;