Example 5 Accessing an Internally Described File

LANSA for i

Example 5: Accessing an Internally Described File

A transaction file called S3TRANS has no external description.

The file record is one 14 character field called DATA, but it is actually made up of 3 fields PRODNO (product number - alpha 7), WHOUSE (warehouse - alpha 2) and QUANTY (quantity - packed 9,0).

Define these 3 fields as virtual fields to allow read and write access to the file as if it were an externally described file.

Step 1 - Define the Virtual Fields

 

 

     Seq    Name_________ Description______________________

      10    PRODNO        Product number

      20    WHOUSE        Warehouse identifier

      30    QUANTY        Quantity supplied

 

 

Step 2 - Input RPG Section "Data Structure Specifications"

IEXTDTA      DS

I                                        1   7 EXT001

I                                        8   9 EXT002

I                                    P  10  14 EXT003

Step 3 - Input RPG Section "Calculations After Input from File"

C*

C* VC_USING FIELDS(DATA PRODNO WHOUSE QUANTY)

C*

C                     MOVELDATA      EXTDTA

C                     MOVELEXT001    PRODNO

C                     MOVELEXT002    WHOUSE

C                     Z-ADDEXT003    QUANTY

Step 4 - Input RPG Section "Calculations Before Output to File"

C*

C* VC_USING FIELDS(DATA PRODNO WHOUSE QUANTY)

C*

C                     MOVELPRODNO    EXT001

C                     MOVELWHOUSE    EXT002

C                     Z-ADDQUANTY    EXT003

C                     MOVELEXTDTA    DATA

Note the "double shuffle" of all fields via data structure EXTDTA is required because LANSA declares all real and virtual file fields in a data structure. Thus it is not possible to directly declare the fields in another data structure or the I/O module will fail to compile.