Working with variable length fields in VISION:Results.

Document ID : KB000024222
Last Modified Date : 14/02/2018
Show Technical Document Details

When records are variable in length, the user can specify the LENGTH parameter on the FILE statement to determine the record length (see Chapter 6 in the Reference Guide). However, when fields within the record are not consistent in length, users are sometimes unsure of how to manipulate the data as desired.

VISION: Results does not have a variable length field type, but users frequently have a fixed length field where the content is of variable length and blanks fill the remainder. In these cases, positioning is easily handled using indexing.

Say there is a field with data which may be up to 40 characters long and you want to append a literal at the end of the data. Here is an example of how to do it:

OPTION STRUCTURED2 

* the 'structured' option is required for the DO loop below

 FILE SYSIN CARDS                                                             
     VNAME    40                                                              
 WORKAREA                                                                     
     LITERAL  15 VALUE ",VOL=SER=VOLUME"                                      
     DESIRED  65

* initialize the result field and index

MOVE ' ' TO DESIRED                                                          
   INW = 0               

* move entire input field to output field

 MOVE VNAME TO DESIRED  

* loop through input field until blank is encountered

 DOWHILE VNAME (INW) NE SPACE                                                 
   INW = INW + 1                                                             
 ENDDO       
 

* when the loop terminates, INW contains length of the data

 MOVE LITERAL TO DESIRED (INW)                                             
                                                                              
 LIST VNAME INW DESIRED                                                       
                                                                              
 FIN                                                                          
 FILE.NAME.ONE                                                                 
 FILE.NAME.THREE                                                               
/*   

This results in the following output:

VNAME               INW    DESIRED 
FILE.NAME.ONE       13     FILE.NAME.ONE,VOL=SER=VOLUME
FILE.NAME.THREE     15     FILE.NAME.THREE,VOL=SER=VOLUME

For more information, please refer to the Indexing section of Chapter 14 of the VISION:Results Reference Guide.