EDIT (E)
The EDIT parameter replaces character, packed, or hexadecimal data in a record with character, packed, or hexadecimal data of a different length. When EDIT is executed, File-AID shifts the remaining data to adjust for the change. The EDIT parameter only changes the first occurrence of matched compare-data in a record. To change more than one occurrence of compare-data, use multiple EDIT parameters. To change all occurrences, use the EDITALL parameter.
The syntax of the EDIT parameter is:
{operator}
location
Location where the search for the data begins. Any valid actual or relative location can be used.
length
Length of the search field. The value must be at least one byte longer than the compare-data length. Any valid number can be entered as long as it does not exceed the record length. Use 0 to search the area between the current actual or relative location and the end of the record.
operator
Any valid operator element listed in Operator Element is allowed.
dupl
Optional duplication factor that defines the number of times File-AID looks for the compare-data to be contiguously repeated, starting at the specified location. A dupl element is valid only when an operator element other than NE is specified. The dupl value is ignored when a length is specified.
compare-data
Data to search for in the specified location. Most valid data types described in Data Element are allowed, except that data types I and ILn are not accepted in EDIT. Multiple compare-data values, separated by commas, are allowed.
new-data
Data that replaces the compare-data when a match is found. If the new-data length is larger than the compare-data length, the remaining contiguous data is shifted to the right. If the new-data is shorter, the contiguous data to the right is shifted left and kept contiguous to the new-data.
When a packed data element is used as new-data, the number of decimal digits (including leading zeros), entered in the control card, determines the length of the new packed field (see Example 5:).
When EDIT inserts data by replacing a field with another of greater length, File-AID shifts the data to the right to make room (see Example 1:). This shift is done field by field. Fields that are separated by more than one blank may be compressed to a single space to make room for inserted fields (see Example 2:).
When EDIT replaces a data field with new-data of shorter length, File-AID shifts contiguous data to the left until a blank is found (see Example 3:). File-AID inserts blanks to compensate for the eliminated data. If no blanks are found, blanks are inserted at the end of the record (see Example 4:).
When the EDIT parameter is used with the COPY function to process variable-length files, File-AID lengthens or shortens the output record when necessary.
In an UPDATE function, record lengths must stay the same. When EDIT is used with the UPDATE function, lengthened records are truncated as discussed in Example 1:. Records from which data is eliminated during an UPDATE function remain the same length because File-AID adds trailing blanks to fill any remaining space in the record (see Example 3:).
Example 1:
Example 1 uses the UPDATE function and replaces the compare-data string 1234 in a field with the longer new-data string ABCDE. When this statement is executed, the results on two records are:
Before:
1234 ABCD9999999999999STUVWXYZ
12346ABCD9999999999999STUVWXYZ
After:
ABCDE ABCD9999999999999STUVWXY
ABCDE6ABCD9999999999999STUVWXY
The last character of each record is truncated because the length of both records is 30 bytes and the UPDATE function was used.
Example 2:
Example 2 replaces string AAAA with string BBBBBBBB. When the longer new-data string is inserted, the fields are shifted, and when required, compressed. When this statement is executed, the results on two records are:
Before:
AAAAA 12 34 56 789000
AAAAA 123 456 78 900000
After:
BBBBBBBBA 12 34 56 789000
BBBBBBBBA 123 456 78 900000
Example 3:
Example 3 replaces the string 1234 with the shorter string1. When this statement is executed, the results on two records are:
Before:
1234 ABCD9999999999999ZZZZ
12346ABCD9999999999999ZZZZ
After:
1 ABCD9999999999999ZZZZ
16ABCD9999999999999ZZZZ
Note that because Record 1 contained a blank after the compare-data string 1234, File-AID inserts blanks immediately after the new-data string 1. However, Record 2 contained no embedded blanks, so the remaining data is shifted to the left.
Example 4:
Example 4 totally eliminates data by coding a null entry to replace the string AAAA. When this statement is executed, the results on two records are:
Before:
AAAAA 12 34 56 789000
AAAAAAAA123 456 78 900000
After:
A 12 34 56 789000
AAAA123 456 78 900000
Example 5:
Example 5 converts a zoned numeric value of 123 to a 3-byte packed value of +123 (X’00123C’). Leading zeros in the packed new-data value are used to calculate the new-data length. The plus sign (+) in the new-data value forces a C sign (positive) for the new packed field. A minus sign (-), if specified, forces a D sign (negative) for the new packed field. If no sign is specified, an F sign is placed in the new packed field. In this example, data does not shift because the compare-data and the new-data are the same length (three bytes). When the statement shown in example 5 is executed, the results on two records are:
Before:
ZONE FFFCCC4FFF
NUMR 1231230123
1...5...10
CHAR AB123C 123
ZONE CCFFFC4FFF
NUMR 1212330123
1...5...10
After:
ZONE 013CCC4FFF
NUMR 02C1230123
1...5...10
CHAR AB C 123
ZONE CC013C4FFF
NUMR 1202C30123
1...5...10