TechTip: Are You Using Table Files?

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times
What is old is new again. The concept of table files pre-dates the AS/400. It even pre-dates the S/3x systems. To successfully trace the origins of table files, you would have to go back to the days when Roger Maris was the king of home runs, and the IBM 360 was the king of computers. These were the days when most data was stored on tapes, card input was common, and disk access was relatively rare.

Most programs were written to process everything sequentially, from beginning to end. The process of creating a disk file that could use the Indexed Sequential Access Method (ISAM) involved a great deal of preparation by assembly language system programmers, and in many cases, it was not worth the effort.

To allow easy random access of any file--be it on card, tape, or disk--IBM created the concept of the table file for RPG. (Did you know you can still access data from your tape drives directly from RPG IV without uploading the data first? But that's a topic for another day.) Essentially, the table file places the entire file into memory and treats it as any other table or array. Today, in RPG IV, all table and array functions are valid with table files.

There are two principle drawbacks to using table files: 1) You must describe the data within the program using I-specs, and 2) You must know how many records are in your file. This alone is enough to turn most programmers away from using table files. On the other hand, this technique does have advantages. Loading data into main storage creates lightning fast retrievals. This can be most useful for small tables that are used repetitively against larger files. You also have a great deal of flexibility in defining the fields that will be used for lookups. You can define alternate array entries that contain subfields. You can even define multiple elements per record!

The RPG IV manual for V5R2 refers to this method of array processing as "Prerun-Time Arrays." Additional information may be found by referring to that heading.

To code a table file, begin with the F-spec:

FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords+
FMyArray   it   f   80        disk  

Notice that the file must be program described with a record length specified. It is not necessary to use any keywords with a table file. This is new with RPG IV. It is advisable not to specify a key, even if the database is indexed. Doing so just adds unnecessary overhead to the program.

D-specs are necessary to define arrays:

DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++++++++
DLookHere         s              8a   dim(100) fromfile(MyArray) 
DGetThis          s             72a   dim(100) alt(LookHere)

This indicates that there are 100 records in the array and, therefore, 100 records in the file. The mandatory FROMFILE keyword tells the compiler to load data from the table file. To the best of my knowledge, the array will not automatically expand if there are more records in the file, but there will be blank array entries if there are less than 100 records in the file.

The final step in the process is the I-specs:

IFilename++SqNORiPos1+NCCPos2+NCCPos3+NCC.
IMyArray   ns  02                         

I........................Fmt+SPFrom+To+++DcField+++++++++L1
I                                  1    8  LookHere        
I                                  9   80  GetThis        
I                                  9   25  SubField1       
I                             p   26   30 2SubField2       
I                                 31   40 0SubField3         
I                                 41   80  Etcetera           

Any array function may now be performed in the calculations section. When the field GETTHIS is retrieved, all of the defined subfields are available for use.

Table files are best used if performance is an issue or if you are reading directly from tape. There is little call for this type of processing under other circumstances. On the other hand, the knowledge of table file processing is a valuable tool to place in your RPG tool belt.

David Abramowitz is an independent consultant who is never late to the table. He may be reached at This email address is being protected from spambots. You need JavaScript enabled to view it..

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: