免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2375 | 回复: 3
打印 上一主题 下一主题

rpg怎么取得一个变量的位数 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-02-01 08:06 |只看该作者 |倒序浏览
rt

论坛徽章:
0
2 [报告]
发表于 2008-02-01 09:01 |只看该作者
*..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
D*Name++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++
D num1 S 7P 2
D NUM1_LEN C %len(num1)
D NUM1_DECPOS C %decpos(num1)
D num2 S 5S 1
D num3 S 5I 0 inz(2)
D chr1 S 10A inz(’Toronto ’)
D chr2 S 10A inz(’Munich ’)
D ptr S *
* Numeric expressions:
/FREE
num1 = %len(num1); // 7
num1 = %decpos(num2); // 1
num1 = %len(num1*num2); // 12
num1 = %decpos(num1*num2); // 3
// Character expressions:
num1 = %len(chr1); // 10
num1 = %len(chr1+chr2); // 20
num1 = %len(%trim(chr1)); // 7
num1 = %len(%subst(chr1:1:num3) + ’ ’ + %trim(chr2));// 9
// %len and %decpos can be useful with other built-in functions:
// Although this division is performed in float, the result is
// converted to the same precision as the result of the eval:
// Note: %LEN and %DECPOS cannot be used directly with %DEC
// and %DECH, but they can be used as named constants
num1 = 27 + %dec (%float(num1)/num3 : NUM1_LEN : NUM1_DECPOS);
// Allocate sufficient space to hold the result of the catenation
// (plus an extra byte for a trailing null character):
num3 = %len (chr1 + chr2) + 1;
ptr = %alloc (num3);
%str (ptr: num3) = chr1 + chr2;
/END-FREE


COPY FROM "ILE RPG Reference"  自己去下载

论坛徽章:
0
3 [报告]
发表于 2008-02-01 09:03 |只看该作者
谢谢
我想问的是在RPG里

论坛徽章:
0
4 [报告]
发表于 2008-02-01 13:56 |只看该作者
1.确定变量类型;
2.如果是字符型,要确定是左对齐,还是右对齐;
3.使用CHECK
(1)如果是数字型,先赋给一个字符变量W#CHAR
        '0'        CHECK         W#CHAR            I      
  I为数字型,是第一个非0的位置(从左到右)
(2)如果是字符型,右对齐
        ' '        CHECK         W#CHAR            I      
  I为数字型,是第一个非空的位置(从左到右)
   如果是字符型,左对齐
        ' '        CHECKR         W#CHAR            I      
  I为数字型,是第一个非空的位置(从右到左)
4.剩下的很好计算了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP