PREFIX(prefix{:nbr_of_char_replaced})

The PREFIX keyword allows the specification of a character string or character literal which is to be prefixed to the subfield names of the externally described data structure being defined. In addition, you can optionally specify a numeric value to indicate the number of characters, if any, in the existing name to be replaced. If the parameter 'nbr_of_char_replaced' is not specified, then the string is attached to the beginning of the name. To remove characters from the beginning of every name, specify an empty string as the first parameter: PREFIX('':number_to_remove).

If the 'nbr_of_char_replaced' is specified, it must represent a numeric value between 0 and 9 with no decimal places. Specifying a value of zero is the same as not specifying 'nbr_of_char_replaced' at all. For example, the specification PREFIX(YE:3) would change the field name 'YTDTOTAL' to 'YETOTAL'.

The 'nbr_of_char_replaced' parameter can be a numeric literal, a built-in function that returns a numeric value, or a numeric constant. If it is a named constant, then the constant must be defined prior to the specification containing the PREFIX keyword. In addition, if it is a built-in function, all parameters to the built-in function must be defined prior to the specification containing the keyword PREFIX.

The following rules apply:

See the ALIAS keyword for information on how the PREFIX keyword interacts with the ALIAS keyword.

Figure 147. Using PREFIX to remove characters from the names

The following example uses PREFIX('':2) on the externally-described data structures DS1 and DS2. The fields of the file FILE1 all begin with the characters X4, and the fields of the file FILE2 all begin with the characters WR. If the two files have any fields whose names are the same aside from the initial two characters, then by specifying PREFIX('':2) for the externally-described data structures, the subfields will have identical names within the RPG program. This will enable the subfields to be assigned using the EVAL-CORR operation.

Ffile1     if   e             disk    
Ffile2     o    e             disk    
D ds1           e ds                  extname(file1) prefix('':2)
D                                     qualified
D ds2           e ds                  extname(file2) prefix('':2)
D                                     qualified
 /free
     read file1 ds1;      // Read into data structure

     eval-corr ds2 = ds1; // Assign fields with same name

     write file2 ds2;     // Write from data structure

 /end-free

For more examples, see PREFIX(prefix{:nbr_of_char_replaced}).



[ Top of Page | Previous Page | Next Page | Contents | Index ]