Access a File with Variable Length Field

LANSA

Access a File with Variable Length Field
Example 220 - Rating: specific
The Things that Make Up this ExampleTo Execute this Example

This example demonstrates how LANSA programs can access data in files with variable length fields.



OS/400 variable length fields are fields that occupy less disk space when their non-blank length is shorter. They are defined as a having a maximum possible length. They can be used in files where for most records the field is blank but for some records it contains a long value, and the programmer does not want to waste disk space. (An alternative solution would be to put the long field in its own file).

Notes and Suggestions

It is not possible to define variable length fields when creating a file using LANSA. But if such a file exists already, it is possible to define it to LANSA as an “OTHER” file. In this example the file S220PFL was created using DDS and the CRTPF command. (See S220PFL DDS and CRTPF).

The first step was to edit system data area DC@OSVEROP and add to it the option *OTHER_VARCHAR. The file S220PFL was then defined to LANSA as an OTHER file:



And the LANSA definition of the file was loaded from the OS/400 file object:



Field S_220TXV was defined using LANSA and added to the file as a virtual field. Then the virtual field derivation code was edited:



The following specifications were edited (see S220PFL Virtual Field Logic for the source code):
  • Data structure specifications
  • Calculations after input from file
  • Calculations before output to file
The file was then compiled using LANSA.

This Example Also Demonstrates:
  • Examples of virtual field logic (I specs C specs )
  • OTHER files
Keywords
Example 220VARLEN
*VARCHARVariable length fields
Virtual field logicOTHER files