AS400开发入门-By adan(6)

2019-04-16 19:17

C P RETNONE RETURN E

D*返回一个参数 D RETFIELD D PARM ?????? P RETFIELD D RETFIELD D PARM D FLD ??

C P RETFIELD D* 返回数组 D RETARRAY ?????? P RETARRAY

PR 5P 2 5I 2 B

PI 5P 2 5I 2

S 12S 1 INZ(13.8)

RETURN 7(RETURN FLD*3 / RETURN FLD) E

PR B

D DIM(3)DATFMT(*YMD/)

D RETARRAY PI D DIM(3)

D SMALLARR S DIM(2)DATFMT(*ISO) D BIGARR S DIM(4)DATFMT(*USA)

C* 如果使用下面的方法返回参数,那么接口数组中所有元素都含有相同的值 C RETURN D’1995-06-27’

C*如果使用比接口定义的数组元素个数少的数组,那么接口数组的第三个元素将 C*被赋予默认值

C RETURN SMALLARR

C*如果使用比接口定义的数组元素个数多的数组,那么多余的数组元素将被忽略 C RETURN BIGARR P RETARRAY E

WHEN

例子:

C C

C C C C

SELECT WHEN

*INKA

?????? WHEN NOT(*IN10) AND (DAY=’FRIDAY’) ??????

WHEN %SUB(A:4:3)=’ABC’ ?????? OTHER

C C

C C ?????? ENDSL

61676237.doc – 第 26 页 共 39 页

3.内嵌式函数及新增、改变的操作 内嵌式函数

?S(numeric expression)返回表达式的绝对值 -DR(variable name)返回表达式的地址

%CHAR(graphic,date,time,timestamp expression)返回字符类型的值 TC(numeric expression(:digits:decimal position)按照参数指定的数据长度和精度返回返回P类型的值 Tcpos(numeric expression)按照参数指定的小数位返回P类型的数值

%ELEM(array,table,multiple occurrence data structure name)返回元素个数

%EOF(filename)当最近一次input操作或向一个SUBFILE写操作遇到文件头或文件尾,就返回‘1’,否则返回‘0’

%EQUAL(filename)如果最近一次SETLL(for a particular file ,if specified)或者LOOKUP遇到了一个完全一致的匹配,就返回‘1’,否则返回‘0’ %ERROR无参数,如果最近一次(在EXTENDER字段填有‘E’的)操作码产生了一个错误,就返回‘1’,否则返回‘0’ %float(numeric expression)返回float类型的值 %FOUND(filename)如果最近一次对文件的操作(CHAIN、DELETE、SETGT、SETLL)、对数组的操作(LOOKUP)、对字符串的操作(CHECK、CHECKR、SCAN)成功的话,就返回‘1’,否则返回‘0’

%INT(numeric expression)返回整形的值

%LEN(any expression)返回数字或字符串的长度

%OPEN(filename)如果指定的文件的状态为打开,就返回‘1’,否则返回‘0’ %PADDR(procedure name)返回函数的指针 %PARMS无参数,返回传递给函数的参数个数

%REPLACE(替代串:被替代的串(:开始位(:替代的长度)))用‘替代串’替代‘被替代串中’的一部分

%SCAN(search argument:string to be searched(:start position))当找到STRING TO BE SEARCHED时,返回位置数,否则返回‘0’

%SIZE(variable,array,literal(:* all))返回变量或者是数组的大小 %STR(pointer(:maximum length))返回由pointer指定的字符串去掉前导空格之后的串

%SUBSTR(string:start(:length))取子串 %TRIM(string)去掉字符串的前导和末尾空格 %TRIML(string)去掉字符串的前导空格 %TRIMR(string)去掉字符串的末尾空格 %UNS(numeric expression)返回无符号数

61676237.doc – 第 27 页 共 39 页

新增操作码

新增CAT, CHECK,XLATE, CHECKR,DOU, DOW, EVAL, CALLB,CALLP等操作码。

CAT

连接字符串 C string1 CAT string2(:n) result 如果没有定义n,那么string1的后续空格和string2的前导空格都将会被作为有效字符放入result中。否则的话,string1的后续空格将被删除,但result的前导空格不会被删除。 例:

* The following example shows leading blanks in factor 2. After * the CAT, the RESULT contains 'MR. SMITH'.

C MOVE 'MR.' NAME 3 C MOVE ' SMITH' FIRST 6 C NAME CAT FIRST RESULT 9 * The following example shows the use of CAT without factor 1. * FLD2 is a 9 character string. Prior to the concatenation, it * contains 'ABC'; FLD1 contains 'XYZ

* After the concatenation, FLD2 contains 'ABC XYZ'. C MOVEL(P) 'ABC' FLD2 9 C MOVE 'XYZ' FLD1 3 C CAT FLD1:2 FLD2 * CAT concatenates LAST to NAME and inserts one blank as specified * in factor 2. TEMP contains 'Mr. Smith'.

C MOVE 'Mr. ' NAME 6 C MOVE 'Smith ' LAST 6 C NAME CAT LAST:1 TEMP 9 * CAT concatenates 'RPG' to STRING and places 'RPG/400' in TEMP. C MOVE '/400' STRING 4 C 'RPG' CAT STRING TEMP 7 *

* The following example is the same as the previous example except

* that TEMP is defined as a 10 byte field. P operation extender * specifies that blanks will be used in the rightmost positions * of the result field that the concatenation result, 'RPG/400', * does not fill. As a result, TEMP contains 'RPG/400' * after concatenation.

C MOVE *ALL'*' TEMP 10 C MOVE '/400' STRING 4 C 'RPG' CAT(P) STRING TEMP

* After this CAT operation, the field TEMP contains 'RPG/4'. * Because the field TEMP was not large enough, truncation occurred. C MOVE '/400' STRING 4

61676237.doc – 第 28 页 共 39 页

C 'RPG' CAT STRING TEMP 5 * Note that the trailing blanks of NAME are not included because * NUM=0. The field TEMP contains 'RPGIV'.

C MOVE 'RPG ' NAME 5 C MOVE 'IV ' LAST 5 C Z-ADD 0 NUM 1 0 C NAME CAT(P) LAST:NUM TEMP 10

CHECK

检查String2中是否含有不属于String1的字符。

C

N2

ER

string1

CHECK(E) string2(:N)

result

如果没有N就从string2的第一位开始检查,否则从第N位开始检查 result中会返回第一个不符合条件的字符在string2中所处的位置

如果result是一个变量,那么此指令会在遇到第一个不符合条件的字母时停止检查;如果

result是一个数组,那么此指令会持续检查直到遇到string2的结尾或者是string2中不符合条件的字母个数超过数组的元素个数。

检查完成后,我们可以使用%FOUND检查是否有不匹配的字符。 例:

* In this example, the result will be N=6, because the start * position is 2 and the first nonnumeric character found is the '.'. * The %FOUND built-in function is set to return '1', because some * nonnumeric characters were found.

D Digits C '0123456789' C

C MOVE '$2000.' Salary C Digits CHECK Salary:2 N 2 0 C IF %FOUND C EXSR NonNumeric C ENDIF

* Because factor 1 is a blank, CHECK indicates the position * of the first nonblank character. If STRING contains 'th * NUM will contain the value 4.

C ' ' CHECK String Num 2 0 * The following example checks that FIELD contains only the letters * A to J. As a result, ARRAY=(136000) after the CHECK operation. * Indicator 90 turns on.

D Array S 1P 0 DIM(7)

D Letter C 'ABCDEFGHIJ' C MOVE '1A=BC*' Field 6 C Letter CHECK Field Array 90 * In the following example, because FIELD contains only the

61676237.doc – 第 29 页 共 39 页

* letters F to G, ARRAY=(000000). Indicator 90 turns off. C MOVE 'FGFGFG' Field 6 C Letter CHECK Field Array 90

CHECKR

与CHECK功能基本相同,只是CHECK是从左边开始检查,CHECKR是从右边开始。用法完全相同。

XLATE:

N2

C FROM:TO XLATE(E) STRING:START_POS TARGET ER

从START_POS开始,将字符串STRING中的符合条件(存在于FROM中)的字符替换成相应的(TO中)另外一个字符 例:

* The following translates the blank in NUMBER to '-'. The result * in RESULT will be '999-9999'.

C MOVE '999 9999' Number 8 C ' ':'-' XLATE Number Result 8 例:

D Up C 'ABCDEFGHIJKLMNOPQRS-

D 'TUVWXYZ' D Lo C 'abcdefghijklmnopqrs- D 'tuvwxyz' * In the following example, all values in STRING are translated to * uppercase. As a result, RESULT='RPG DEPT'. C MOVE 'rpg dept' String 8 C Lo:Up XLATE String Result * In the following example only part of the string is translated to lowercase. As a result, RESULT='RPG Dept'.

C Up:Lo XLATE String:6 Result

新增位操作

新增位操作有TESTB

TESTB:

使用方法如下: indicators C TESTB bit_numbers Character_field N1 N2 N3 当factor2中指定的所有位都为off时,N1=*on 当factor2中指定的位中至少有一个为on时,N2=*on;但是,当factor2中只指定了一个位时,N2无效

61676237.doc – 第 30 页 共 39 页


AS400开发入门-By adan(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:如何提升谈判能力?

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: