Chinaunix首页 | 论坛 | 博客
  • 博客访问: 55986
  • 博文数量: 18
  • 博客积分: 161
  • 博客等级: 入伍新兵
  • 技术积分: 135
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-14 21:52
文章分类
文章存档

2012年(18)

分类: LINUX

2012-04-16 22:01:15

        ADD:            RESULT = FACTOR1/RESULT + FACTOR2

        SUB:            RESULT = FACTOR1/RESULT + FACTOR2

        Z-ADD:  RESULT = 0 + FACTOR2

        Z-SUB:  RESULT = 0 - FACTOR2

        MULT:   RESULT = FACTOR1/RESULT * FACTOR2

        DIV:            RESULT = FACTOR1/RESULT / FACTOR2

        MVR   RESULT = 上一个DIV操作的余数

        SQRT  RESULT = FACTOR2的平方根

        XFOOT RESULT = FACTOR2数组的和

2.赋值操作

MOVE:RESULT = FACTOR2右靠齐字符型变量和P形变量可以互相赋值

                如果FACTOR2的长度小于RESULT的长度RESULT的其余部分保持不便

                如果FACTOR2的长度大于RESULT的长度FACTOR2种的多余部分将被忽略

MOVEL:      RESULT = FACTOR2左靠齐字符型变量和P形变量可以互相赋值

                如果FACTOR2的长度小于RESULT的长度RESULT的其余部分保持不便

                如果FACTOR2的长度大于RESULT的长度FACTOR2种的多余部分将被忽略

MOVEA:      RESULT = FACTOR2 (RESULT必须是个使用DIM定义的数组FACTOR2可以是数      变量常量*BLANKS, *ZEROS, *ALL'XXX'。详细图解清参考RPG FOR AS/400 REFERENCE)

 

3. 比较操作:

COMP:       FACTOR1与FACTOR2比较的结果由指示器表示

                VAR1        COMP                VAR2                            99

    *IN99   IFEQ    1

。。。

ENDIF

CABXX:      FACTOR1FACTOR2比较如果结果为真的话就转移到RESULT指示的TAG

    VAR1            CABXX           VAR2            TAG1

                VAR1            CABXX           VAR3            TAG2

                                ……..

    TAG1            TAG

                                ……..

    TAG2            TAG

                                …….

CASXX:      FACTOR1FACTOR2比较如果结果为真的话就执行RESULT指示的子程序

VAR1            CASXX   VAR2/CONST                      SUBROUTINE1

VAR3            CASXX   VAR4/CONST                      SUBROUTINE2

VAR5            CASXX   VAR6/CONST                      SUBROUTINE3

                                CAS                                                     SUBROUTINE4    

                                ENDCS

:

DA1               S              2  0 INZ(50)        

DA2               S              2  0 INZ(20)        

C     A1            DSPLY                            

C     A2            DSPLY                            

C     A1            CASGT     A2            S#001    

C     A1            CASLT     A2            S#002    

C                   ENDCS                            

C     ENDPGM        TAG                              

C                   EVAL      *INLR = '1'            

C                   RETURN                           

C     S#001         BEGSR                             

C     'A1>A2'       DSPLY                            

C                   GOTO      ENDPGM                 

C                   ENDSR                            

C     S#002         BEGSR                            

4程序操作

BEGSR:      子程序开始

ENDSR:      子程序结束

EXSR:       执行子程序

       

SUB0001             BEGSR

    EXSR            SUB0001

                                ……….

                                ENDSR

注释每一个程序中都可以有一个特殊的子程序*INZR它无论被放在程序的什么部分都会被首先执行

*INZR               BEGSR

                                ………

                                ENDSR

程序例外出错检测子程序,当程序发现例外出错时,自动执行该子程序,做出下一步处理

*PSSR                        BEGSR

                                                        。。。

                                                        ENDSR

DABC              S              3  0 DIM(10)      

DX                 S              2  0              

C                                                    

C                   MOVEA     1             ABC(X)   

C     ABC(1)        DSPLY                             

C                                                    

C     ENDPGM        TAG                              

C                   EVAL      *INLR = '1'            

C                   RETURN                           

C                                                     

C     *PSSR         BEGSR                            

C     'SYS ERR'     DSPLY                            

C                   GOTO      ENDPGM                 

C                   ENDSR                            

5.        调用和转移操作

CALL:       调用一个外部程序该程序可以是RPGCLC程序等

                        CALL            'COUNT'

                        PARM                            P1

                        PARM                            P2

RETRN/RETURN: 返回上一层程序

6.        文件操作

              A        CHAIN:  用纪录号或键值从一个文件查找,如果文件是使用I方式打开的话,此操作不会在记录上加锁;如果使用U方式打开的话,就会。

                                MOVE     ABCD                 WWACNO

                                                                                                        N1N2N3

        WWACNO          CHAIN   FACNO(记录格式名)                    8899

        *IN88           IFEQ            1    

RPG IV)或            IF              *IN88 = 1

RPG IV)或            IF              *IN88

RPG IV)或            IF       NOT    %FOUND

                                MOVE            FER0001                       WWMGID

                                GOTO            ENDPGM

                                ENDIF

        *IN99           IFEQ            '1'                                                                     纪录被锁

                                MOVE            'FER0002'                       WWMGID

                                GOTO            ENDPGM

                                ENDIF

                                ……

        ENDPGM  TAG

                                MOVE            '1'                                     *INLR

                                RETRN

 

        ACKEY           KLIST

                                KFLD                                                    WWACNO

                                KFLD                                                    WWSBNO

                                MOVE            ABC                          WWACNO

                                Z-ADD     10                                    WWSBNO

        ACKEY           CHAINN FACNO(记录格式名)                  8899    仅查找不锁记录

        *IN88           IFEQ            '1'

                                MOVE            'FER0001'                      WWMGID

                                GOTO         ENDPGM

                                ENDIF

        *IN99           IFEQ            '1'

                                MOVE            'FER0002'                       WWMGID

                                GOTO            ENDPGM

                                ENDIF

                                ……..

        ENDPGM  TAG

                                MOVE            '1'                                     *INLR

                                RETRN

B. CLOSE:  关闭文件(通常情况下,如果是注明用户打开的文件,在程序结束之前要CLOSE将文件关闭,如果是系统自动打开的文件,在程序结束时会自动关闭)

                                CLOSE           ACNOA文件名

C. OPEN:  打开文件,在程序对多成员文件进行操作时一般需要由用户自行打开和关闭数据文件

                                OPEN                    ACNOA文件名

D COMIT/COMMIT: 文件修改落实在文件定义F中指明文件要由落实机制控制COMMIT参数

E ROLBK/ROLBK :   文件修改回滚在文件定义F中指明文件要由落实机制控制COMMIT参数

F DELET/DELETE:   删除记录

                                DELET           FACNO(记录格式名)

G EXFMT:  显示输出一个显示记录并从标准输入读取数据

                                EXFMT           CHOICE(一般文件显示记录格式名)

H READ:   读一条记录     

                                                                                                                    N1N2N3

                                READ            FACNO(记录格式名)                                             99

        *IN99           IFEQ            '1'

RPG IV)或     IF      %EOF(到文件末)

                                MOVE            'FRD0001'                       WWMGID

                                GOTO            ENDPGM

                                ENDIF

I READE:  从当前记录位置开始寻找一个等于键字的记录,并读取

                    MOVE    A124                          WWACNO

                                                                                                                           N2N3

WWACNO          READE       FACNO                                                              8899

        *IN88           IFEQ            '1'                                                                                     纪录被锁

                                MOVE            'FER0002'                       WWMGID

                                GOTO            ENDPGM

                                ENDIF

        *IN99           IFEQ            '1'                                                                                     无匹配记录

RPG IV)或            IF              *IN99 = 1

RPG IV)或            IF              *IN99

RPG IV)或            IF       NOT    %FOUND

                                MOVE            'FER0003'                       WWMGID

                                GOTO            ENDPGM

                                ENDIF

J.  READP:  读取当前记录位置的上一条记录

                                                                                                                                        N2N3

                                READP           FACNO                                                                   8899

        *IN88           IFEQ            '1'                                                                                     纪录被锁

                                MOVE            'FER0002'                       WWMGID

                                GOTO            ENDPGM

                                ENDIF

        *IN99           IFEQ            '1'                                                                                     遇到文件头

RPG IV)或     IF      %BOF(到文件末)

                                MOVE            'FER0003'                       WWMGID

                                GOTO            ENDPGM

                                ENDIF

K.  SETLL:  从文件第一条记录开始逐条查询直到找到第一条符合条件的记录此记录的键字大于或等于FACTOR1指定的键值。但只是将文件指针指向此记录的上方,并不读出(可以使用READ读下一记录)。

L.  SETGL:  从文件第一条记录开始逐条查询,直到找到第一条符合条件的记录,此记录的键字大于FACTOR1指定的键值。但只是将文件指针指向此记录的下方,并不读出(可以使用READP将上一条记录读出)。

        例如

有一物理文件:学生成绩表,记录格式名为RSTT,字段属性是,成绩GRADE3S0)、姓名NAME10 O),成绩是键值,储存数据如下:

成绩(K           姓名

80                          张一

85                          张二

88                          张三

88                          李一

92                          李二

显示将成绩大等于90的学生姓名(结果只有显示李二)

                                MOVE                    90                      CJ              3       0

    CJ              SETLL           RSTT记录格式名

                    READ                    RSTT            

                    DO                      1

                    IF                      %EOF

                    LEAVE

                    ENDIF

    GRADE   DSPLY

                    READ                    RSTT

                    ENDDO

显示将成绩小等于85的学生姓名(结果显示张二和张一)

                                MOVE                    85                      CJ              3       0

    CJ              SETGT           RSTT记录格式名

                    READ    P               RSTT                         

                    DO                      1

                    IF                      %BOF

                    LEAVE

                    ENDIF

    GRADE   DSPLY

                    READP           RSTT

                    ENDDO

 

        注意SETLL与SETGT只是对文件记录进行定位,并没有读记录,必须结合使用READ或READP等读记录语句一起使用,使用的文件必须带键值

M. UNLCK:  解除记录锁

                                UNLCK           FIDNO(记录格式名)

N. UPDATE: 更新数据库记录

                                EVAL        ACKEY = 10

    ACKEY   CHAIN           FACNO

                                EVAL            ACNM ='Leon Davis'

                                UPDATE          FACNO记录格式名                             99(N2)

                *IN99   IFEQ                    '1'                    更新文件失败

        RPG IV IF                         %ERROR

                                EVAL                    'UDR0001'               WWMGID

                                GOTO                    ENGPGM

                                ENDIF

O WRITE:  写文件记录

                    EVAL           

                                WRITE           FACNO记录格式名                             99(N2)

                *IN99   IFEQ                    '1'                                                             写文件失败

        RPG IV IF                         %ERROR

                                EVAL                    'WTR0001'               WWMGID

                                GOTO                    ENGPGM

                                ENDIF

注意RPG中使用文件操作一定要注意控制好文件定位操作和锁表问题,不要在一个程序链中同时打开某一个表进行修改。

7.信息操作:

1.  DEBUG:  用来在有问题的程序中显示所有状态为'1'的指示器

2.  DUMP:   在调试程序的时候,可以将程序运行到当前位置时所有变量和指示器的值打印在一个spool file 中。

3.  TIME:   取系统时间

                TIME                                            TM_VAR612位数字的数字型字段名)

4 DSPLY:  允许程序与系统控制台之间或和程序要求的显示工作站之间进行通讯。

                VAR1            DSPLY

                VAR1            DSPLY           *QSYSOPR                RESP_VAR

                VAR1            DSPLY                                   RESP_VAR

        注释如果是个批作业那么因子2的默认值是QSYSOPR(系统操作员),如果是个交互式作业那么作业2的默认值是*EXT(信息发往请求者)

8.说明操作:

1. DEFN/DEFINE:数据区(data area):在因子2说明一个数据区的外部名或*LDA说明为一个局部数据区,如果在因子2为空,则结果字段上登记的是该数据区的外部名

*LIKE           DEFN                    WWACNO          XXACNO(字段名)

    *NAMVAR         DEFN                    TOTAL           TATNET(可以是字段名、数据结构名、

数据结构子字段等)

    *NAMVAR         DEFN                                            TOTAL(外部定义数据区)

 

2. KLIST & KFLD:   定义复合键字,用于复合键字逻辑文件。

                ACKEY           KLIST

                                        KFLD                                    ACNO

                                        KFLD                                    ACSN

3 PLIST :表示一个参数列表,如果参数列表是一个被调用的输入参数列表,因子1必须是*ENTRY    

PARM  : 定义组成一个参数列表的参数,可以随在一个PLISTCALL之后

    WWPARM          PLIST

                                        PARM                                    ACNO

                                        PARM                                    ACSN

                                        CALL            PGMA

                                        PARM                                            P1

                                        PARM                                            P2

阅读(2091) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~