免费注册 查看新帖 |

Chinaunix

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

请问RPG里OCUR这个操作码是怎么应用的 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-12-22 10:12 |只看该作者 |倒序浏览
5可用积分
如题:
E                    AR6        12 13 0  
......
ITOTD11      DS                          3 156     
I                                                1 156 AR6
......
C                      DO       3              II
C           II        OCUR   TOTD11      
C                      MOVEA*ZEROS    AR6

请问这段代码大概是什么意思呢?

最佳答案

查看完整内容

E AR6 12 13 0 解释: 定义了一个一维数据。ITOTD11 DS 3 156 I 1 156 AR6 解释:上面的一维数据定义为可以循环用3次。相当于变成了一个二维数组。 1 2 。。。。。。 121 元素1 元素2 元素1223......C DO 3 II C II ...

论坛徽章:
0
2 [报告]
发表于 2008-12-22 10:12 |只看该作者
E                    AR6        12 13 0  
解释: 定义了一个一维数据。

ITOTD11      DS                          3 156     
I                                                1 156 AR6
解释:上面的一维数据定义为可以循环用3次。相当于变成了一个二维数组。

     1         2   。。。。。。  12
1    元素1    元素2                  元素12

2

3

......
C                      DO       3              II
C           II        OCUR   TOTD11      
C                      MOVEA*ZEROS    AR6

解释:  通过循环,对二维数组清空。

论坛徽章:
0
3 [报告]
发表于 2008-12-22 10:16 |只看该作者

论坛徽章:
0
4 [报告]
发表于 2008-12-22 10:19 |只看该作者
英文不过关,看不太懂!

论坛徽章:
0
5 [报告]
发表于 2008-12-22 10:19 |只看该作者
RPG/400 Help

OCUR (Set/Get Occurrence of a Data Structure)

*---------*---------------*-----------------*----------------*---------------*
|   CODE  |    FACTOR 1   |     FACTOR 2    |     RESULT     |  INDICATORS   |
|         |               |                 |      FIELD     |               |
*---------*---------------*-----------------*----------------*---------------*
| OCUR    | Occurrence    | Data structure  | Occurrence     |    _ ER _     |
|         | value         |                 | value          |               |
*---------*---------------*-----------------*----------------*---------------*

The OCUR operation code specifies the occurrence of the data structure that is to be used next within an RPG/400 program. If a data structure with multiple occurrences or a subfield of that data structure is specified in an operation, the first occurrence of the data structure is used until an OCUR operation is specified. After an OCUR operation is specified, the occurrence of the data structure that was established by the OCUR operation is used.

Factor 1 is optional; if specified, it can contain a numeric, zero decimal position literal, field name, named constant, or a data structure name. Factor 1 is used during the OCUR operation to set the occurrence of the data structure specified in factor 2. If factor 1 is blank, the value of the current occurrence of the data structure in factor 2 is placed in the result field during the OCUR operation.

If factor 1 is a data structure name, it must be a multiple occurrence data structure. The current occurrence of the data structure in factor 1 is used to set the occurrence of the data structure in factor 2.

Factor 2 is required and must be the name of a multiple occurrence data structure.

The result field is optional; if specified, it must be a numeric field name with no decimal positions. During the OCUR operation, the value of the current occurrence of the data structure specified in factor 2, after being set by any value or data structure that is optionally specified in factor 1, is placed in the result field.

You can specify a resulting indicator in positions 56 and 57 to be set on if the occurrence specified is outside the valid range set for the data structure. If the occurrence is outside the valid range, the occurrence of the data structure in factor 2 remains the same as before the OCUR operation was processed.

The OCUR operation establishes which occurrence of a multiple occurrence data structure is used next in a program. Only one occurrence can be used at a time.

Figure "Uses of the OCUR Operation" illustrates uses of the OCUR operation.

OCUR Examples

Figure 41. Uses of the OCUR Operation

                  *------*------*        50th        *------*------*
                  | FLDA | FLDB ||----Occurrence----*| FLDC | FLDD |
                  |      |      |                    |      |      |
                *------*------*-*      49th        *------*------*-*
                | FLDA | FLDB ||----Occurrence----*| FLDC | FLDD |
                |      |      |                    |      |      |
              *-------------*-*                  *-------------*-*
            *-------------*                    *-------------*
          *-------------*                    *-------------*
        *-------------*                    *-------------*
      *-------------*                    *-------------*
    *------*------*         3rd        *------*------*
    | FLDA | FLDB ||----Occurrence----*| FLDC | FLDD |
    |      |      |                    |      |      |
  *------*------*-*       2nd        *------*------*-*
  | FLDA | FLDB ||----Occurrence----*| FLDC | FLDD |
  |      |      |                    |      |      |
*------*------*-*       1st        *------*------*-*
| FLDA | FLDB ||----Occurrence----*| FLDC | FLDD |
|      |      |                    |      |      |
*------*------*                    *------*------*
      DS1                                DS2

*...1....+....2....+....3....+....4....+....5....+....6....+....7...
I....................................PFromTo++DField+L1M1FrPlMnZr...
I*
I*  DS1 and DS2 are multiple occurrence data structures.
I*  Each data structure has 50 occurrences.
IDS1         DS                         50
I                                        1   5 FLDA
I                                        6   80FLDB
I*
IDS2         DS                         50
I                                        1   6 FLDC
I                                        7  11 FLDD

*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*  DS1 is set to the third occurrence.  The subfields FLDA
C*  and FLDB of the third occurrence can now be used.  The MOVE
C*  and Z-ADD operations change the contents of FLDA and FLDB,
C*  respectively, in the third occurrence of DS1.
C           3         OCUR DS1
C                     MOVE 'ABCDE'   FLDA
C                     Z-ADD22        FLDB
C*
C*  DS1 is set to the fourth occurrence.  Using the values in
C*  FLDA and FLDB of the fourth occurrence of DS1, the MOVE
C*  operation places the contents of FLDA in the result field,
C*  FLDX, and the Z-ADD operation places the contents of FLDB
C*  in the result field, FLDY.
C           4         OCUR DS1
C                     MOVE FLDA      FLDX
C                     Z-ADDFLDB      FLDY
C*
C*  DS1 is set to the occurrence specified in field X.
C*  For example, if X = 10, DS1 is set to the tenth occurrence.
C           X         OCUR DS1
C*
C*  DS1 is set to the current occurrence of DS2.  For example, if
C*  the current occurrence of DS2 is the twelfth occurrence, DSI
C*  is set to the twelfth occurrence.
C           DS2       OCUR DS1
C*
C*  The value of the current occurrence of DS1 is placed in the
C*  result field, Z.  Field Z must be numeric with zero decimal
C*  positions.  For example, if the current occurrence of DS1
C*  is 15, field

论坛徽章:
0
6 [报告]
发表于 2008-12-22 10:25 |只看该作者

回复 #4 ziggler 的帖子

可不可以把DS1和DS2理解为两个数组,取哪个记录取决于OCUR前的变量?

[ 本帖最后由 阿爱死四百 于 2008-12-23 07:12 编辑 ]

论坛徽章:
0
7 [报告]
发表于 2008-12-22 10:45 |只看该作者
相当于数组的索引。
我的例子:
     D IISTRU        E DS                  EXTNAME(INP_INTF)
     D OISTRU        E DS                  EXTNAME(OUT_INTF)
     D DETAIL        E DS                  OCCURS(20) EXTNAME(OUT_DETL)
     C*
     C                   CLEAR                   OISTRU
     C                   Z-ADD     0             CNT               2 0
1{   C     CNT           DOWLT     20
     C                   ADD       1             CNT
     C     CNT           OCCUR     DETAIL
     C                   CLEAR                   DETAIL
1}   C                   ENDDO
清输出接口、输出明细接口

输出字符串结构:
|---OISTRU---|---DETAIL---|---DETAIL---|...|---DETAIL---|
| 输出接口(头) | 输出明细1    |   明细2    |...|   明细20   |

上面是RPGLE的写法,RPG的写法:
     IIISTRU    E DSINP_INTF
     IOISTRU    E DSOUT_INTF
     IDETAIL    E DSOUT_DETL                 20
     C                     CLEAROISTRU
     C                     Z-ADD0         CNT     20
     C           CNT       DOWLT20
     C                     ADD  1         CNT
     C           CNT       OCUR DETAIL
     C                     CLEARDETAIL
     C                     ENDDO

[ 本帖最后由 ux400 于 2008-12-22 11:00 编辑 ]

论坛徽章:
0
8 [报告]
发表于 2008-12-22 10:51 |只看该作者
你的例子是RPG4的,在RPG3里,这个用法有什么好处呢
为什么不在E行直接定义E                    AR6    3    12 13 0
这样直接定义2维数组了啊

[ 本帖最后由 阿爱死四百 于 2008-12-22 11:12 编辑 ]

论坛徽章:
0
9 [报告]
发表于 2008-12-23 08:26 |只看该作者
楼主的两个数组定义都是rpg iii的编程代码,rpg iv对数组,用dim定义。

就楼主的occur问题来说,如果只是用于对数组的清空,在rpg iv中可以直接

/free
    ......
   totd11 = 0;
    ......
/end-free

occur  n 的使用概念相当与dim(n)的使用概念,如
  occur    1  相当于dim(1)

论坛徽章:
0
10 [报告]
发表于 2008-12-23 09:57 |只看该作者
我们用的是RPG3
不过还是谢谢各位楼上的!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP