RPG III:如何将数组重新定义为单独的字段,就像在 COBOL 中一样
在 RPG III 中,我需要在文件中存储一个巨大的数组。最大字段长度为 256,因此我定义了包含 16 个字段的文件,每个字段长度为 250 个字符。有没有办法将数组的1000个值不移动的情况下放入16个字段中?就像COBOL中的REDEFINES一样?
程序中的数组:
E MPDV 1000 4
文件的规范:
D000001 1 4 WRPMOD
D000002 5 254 W01PDV
... etc. until
D000017 37554004 W16PDV
在 Cobol 中,我会写:
01 MPDV-TOP.
03 MPDV-ARR OCCURS 1000.
05 MPDV PIC X(4).
01 WRPREC REDEFINES MPDV-TOP.
03 W01PDV PIC X(250).
.... ETC. UNTIL
03 W16PDV PIC X(250).
读取文件,我得到数组 MPDV 及其值,并且使用 MPDV 中的值我可以写入文件。
我的解决方案如下所示: 额外的数组
E MPX 16250 MPDV REDEF
和大量的移动:
C MOVELMMEMOD WRPMOD
C MOVEAMPDV MPX
C MOVELMPX,1 W01PDV
C MOVELMPX,2 W02PDV
.... etc until
C MOVELMPX,16 W16PDV
C WRITEWRPASM
以及反向阅读。
in RPG III I need to store an huge array in a file. The maximum fieldlength is 256, thus I defined the file with 16 fields of 250 chars long each. Is there a way to put the 1000 values of the array into the 16 fields without moving? Just like the REDEFINES in COBOL?
array in the program:
E MPDV 1000 4
Specicifation of the file:
D000001 1 4 WRPMOD
D000002 5 254 W01PDV
... etc. until
D000017 37554004 W16PDV
In Cobol I would write:
01 MPDV-TOP.
03 MPDV-ARR OCCURS 1000.
05 MPDV PIC X(4).
01 WRPREC REDEFINES MPDV-TOP.
03 W01PDV PIC X(250).
.... ETC. UNTIL
03 W16PDV PIC X(250).
Reading the file I get the array MPDV with it's values and with values in MPDV I can write the file.
my solution looks like this:
an extra array
E MPX 16250 MPDV REDEF
and lots of moves:
C MOVELMMEMOD WRPMOD
C MOVEAMPDV MPX
C MOVELMPX,1 W01PDV
C MOVELMPX,2 W02PDV
.... etc until
C MOVELMPX,16 W16PDV
C WRITEWRPASM
and reverse for reading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 数据结构 覆盖将各个字段合并到主字段中:
有关更多信息,我推荐以下资源:
IBM i 信息中心
ILE RPG 程序员指南
ILE RPG 语言参考
Safari 在线图书
现代 RPG IV 语言
Use a Data Structure to overlay the individual fields into the main field:
For more information I recommend the following resources:
IBM i information center
ILE RPG Programmers Guide
ILE RPG Language Reference
Safari Books Online
The Modern RPG IV Language
角色扮演游戏 III?使用 RPG IV 的效果要好得多。真的。
在RPG III中,数据结构方法是一个很好的方法。不过,有一种不同的方法来解决这个问题。更实际地定义文件。定义每个字段,而不是任意大小的数组“块”。例如,假设我们正在谈论每周的销售数据,并且我们希望保留许多周的价值。将每周的销售额定义为表中的单独列,而不是仅组成 250 字节字符字段,这些字段实际上并不反映存储在其中的数据。
在下面的示例中,我编程描述了该文件,但相同的技术也适用于外部定义的文件。我只做了 10 列,但你可以看到它是如何工作的。数据库文件实际上定义了真正的列。这意味着查询用户、SQL 用户(ODBC...Web 应用程序?)都可以访问实际数据,而无需求助于cast(substring()) 操作。
它的工作方式是将数据库表中的定义复制到数据结构中。在 RPG 中,数据结构共享存储,因此您在第 1 列到第 10 列中定义的任何内容都可以重新映射到第 1-10 列中定义的另一个字段。在这里,我们将整个销售数组映射到各个销售列的顶部。对 ARY,1 的任何更改都会自动更改 WEEK01,反之亦然,因为存储是共享的 - 它是完全相同的存储。
RPG III? Far, far, far better to use RPG IV. Really.
In RPG III, the data structure method is a good one. There is a different way to approach the problem though. Define the file more realistically. Rather than arbitrarily sized 'chunks' of the array, define each field. For instance, let's say we're talking about weekly sales figures and we want to keep many weeks worth. Define each week's sales as a separate column in the table instead of just making up 250 byte character fields that don't actually reflect the data being stored in them.
In the example below, I program described the file but the same technique works for externally defined files as well. I only did 10 columns but you can see how it works. The database file actually has genuine columns defined. That means that query users, SQL users (ODBC... web applications?) can all access the actual data without having to resort to cast(substring()) gymnastics.
The way it works is that the definitions in the database table are copied into a data structure. In RPG, data structures share storage, so whatever you define in columns 1 through 10 can be re-mapped into another field defined in columns 1-10. Here, we map the entire sales array over the top of the individual sales columns. Any change to ARY,1 will automatically change WEEK01 and vice versa, because the storage is shared - it's the exact same storage.