Domanda

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.

È stato utile?

Soluzione

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

Altri suggerimenti

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    
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top