如何解决如何从 AS/400 中的字段拆分值?
我有一个具有不同代码的字段,例如:52、53、5253、54、5354 和 52,54。我需要将 4 位数字拆分为前两位和后两位。我不知道如何在 as/400 中做到这一点。任何帮助将不胜感激。
解决方法
在 RPG 中使用 %subst
操作码来访问较大字符字段中的字符。
d ch4 s 4a
d ch2a s 2a
d ch2b s 2a
/free
ch4 = '5253' ;
ch2a = %subst(ch4:1:2) ;
ch2b = %subst(ch4:3:2) ;
/end-free
如果您要查找的数据以逗号分隔,请使用 %scan 查找分隔符,然后使用 %subst 根据分隔符的位置提取子字段。
d ch5 s 5a
d ch2a s 2a
d ch2b s 2a
d fx s 10i 0
/free
ch5 = '52,53' ;
ch2a = %subst(ch5:1:2) ;
fx = %scan( ',': ch5 ) ;
if fx > 0 ;
ch2b = %subst(ch5:fx+1:2) ;
endif ;
/end-free
在固定格式的 RPG 中执行此操作:
d ch5 s 5a
d ch2a s 2a
d ch2b s 2a
d ch3 s 3a
d arr5 s 1a dim(5)
** original RPG. the MOVE,MOVEL,MOVEA opcodes.
c* MOVE - move from the right. MOVEL - move from the left.
c move '52,53' ch5
c move ch5 ch2b
c movel ch5 ch2a
** MOVEA - move to or from array
c movea ch5 ar5
c movea ar5(4) ch2b
** before free form in RPG there was the EVAL opcode.
c eval ch5 = '52,53'
c eval ch2a = %subst(ch5:1:2)
c eval fx = %scan(',':ch5)
c if fx > 0
c eval ch2b = %subst(ch5:fx+1:2)
c endif
,
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。