RPG III:如何将数组重新定义为单独的字段,就像在 COBOL 中一样

发布于 2024-12-13 17:28:49 字数 1230 浏览 0 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赤濁 2024-12-20 17:28:49

使用 数据结构 覆盖将各个字段合并到主字段中:

IMPDV        DS                                      
I                                        1 250 W01PDV
I                                      251 500 W02PDV
I                                      501 750 W03PDV
                      . . .
I                                     37514000 W16PDV

有关更多信息,我推荐以下资源:

IBM i 信息中心
ILE RPG 程序员指南
ILE RPG 语言参考

Safari 在线图书
现代 RPG IV 语言

Use a Data Structure to overlay the individual fields into the main field:

IMPDV        DS                                      
I                                        1 250 W01PDV
I                                      251 500 W02PDV
I                                      501 750 W03PDV
                      . . .
I                                     37514000 W16PDV

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

天荒地未老 2024-12-20 17:28:49

角色扮演游戏 III?使用 RPG IV 的效果要好得多。真的。

在RPG III中,数据结构方法是一个很好的方法。不过,有一种不同的方法来解决这个问题。更实际地定义文件。定义每个字段,而不是任意大小的数组“块”。例如,假设我们正在谈论每周的销售数据,并且我们希望保留许多周的价值。将每周的销售额定义为表中的单独列,而不是仅组成 250 字节字符字段,这些字段实际上并不反映存储在其中的数据。

在下面的示例中,我编程描述了该文件,但相同的技术也适用于外部定义的文件。我只做了 10 列,但你可以看到它是如何工作的。数据库文件实际上定义了真正的列。这意味着查询用户、SQL 用户(ODBC...Web 应用程序?)都可以访问实际数据,而无需求助于cast(substring()) 操作。

它的工作方式是将数据库表中的定义复制到数据结构中。在 RPG 中,数据结构共享存储,因此您在第 1 列到第 10 列中定义的任何内容都可以重新映射到第 1-10 列中定义的另一个字段。在这里,我们将整个销售数组映射到各个销售列的顶部。对 ARY,1 的任何更改都会自动更改 WEEK01,反之亦然,因为存储是共享的 - 它是完全相同的存储。

 E                    ARY        10 10 0              
 IDUMMY   AA  01                                      
 I                                        1  100WEEK01
 I                                       11  200WEEK02
 I                                       21  300WEEK03
 I                                       31  400WEEK04
 I                                       41  500WEEK05
 I                                       51  600WEEK06
 I                                       61  700WEEK07
 I                                       71  800WEEK08
 I                                       81  900WEEK09
 I                                       91 1000WEEK10
 I            DS                                      
 I                                        1  100WEEK01
 I                                       11  200WEEK02
 I                                       21  300WEEK03
 I                                       31  400WEEK04
 I                                       41  500WEEK05
 I                                       51  600WEEK06
 I                                       61  700WEEK07
 I                                       71  800WEEK08
 I                                       81  900WEEK09
 I                                       91 1000WEEK10
 I                                        1 100 ARY    

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.

 E                    ARY        10 10 0              
 IDUMMY   AA  01                                      
 I                                        1  100WEEK01
 I                                       11  200WEEK02
 I                                       21  300WEEK03
 I                                       31  400WEEK04
 I                                       41  500WEEK05
 I                                       51  600WEEK06
 I                                       61  700WEEK07
 I                                       71  800WEEK08
 I                                       81  900WEEK09
 I                                       91 1000WEEK10
 I            DS                                      
 I                                        1  100WEEK01
 I                                       11  200WEEK02
 I                                       21  300WEEK03
 I                                       31  400WEEK04
 I                                       41  500WEEK05
 I                                       51  600WEEK06
 I                                       61  700WEEK07
 I                                       71  800WEEK08
 I                                       81  900WEEK09
 I                                       91 1000WEEK10
 I                                        1 100 ARY    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文