The INSPECT Statement
Syntax
Format 1
INSPECT identifier-1 TALLYING identifier-2 FOR
{ CHARACTERS [{ BEFORE
AFTER } INITIAL { identifier-3
literal-1 }] ... } ...
{ ALL
LEADING }{{ identifier-4
literal-2 }[{ BEFORE
AFTER } INITIAL { identifier-5
literal-3 }] ... } ...
Format 2
INSPECT identifier-6 REPLACING
{ CHARACTERS BY { identifier-7
literal-4 }[{ BEFORE
AFTER } INITIAL { identifier-8
literal-5 }] ... } ...
{ ALL
LEADING
FIRST } { identifier-9
literal-6 } BY { identifier-10
literal-7 } [{ BEFORE
AFTER } INITIAL { identifier-11
literal-8 }] ... } ...
Format 3
INSPECT identifier-12 TALLYING identifier-13 FOR
{ CHARACTERS [{ BEFORE
AFTER } INITIAL { identifier-14
literal-9 }] ... } ... REPLACING
{ ALL
LEADING }{{ identifier-15
literal-10 }[{ BEFORE
AFTER } INITIAL { identifier-16
literal-11 }] ... } ...
{ CHARACTERS BY { identifier-17
literal-12 }[{ BEFORE
AFTER } INITIAL { identifier-18
literal-13 }] ... } ...
{ ALL
LEADING
FIRST } { identifier-19
literal-14 } BY { identifier-20
literal-15 } [{ BEFORE
AFTER } INITIAL { identifier-21
literal-16 }] ... } ...
Format 4
INSPECT identifier-22 CONVERTING
{ identifier-3
literal-1 } TO { identifier-23
literal-17 } [{ BEFORE
AFTER } INITIAL { identifier-24
literal-18 }] ...
Description
The INSPECT statement is used to perform various operations on string data. Each of the four formats works slightly differently and is described in the correspondingly numbered area.
1. The first format is used to count occurrences of characters or strings within another string.
The number of occurrences is stored in identifier-2.
The value in identifier-1 is unchanged.
2. The second format is used to replace occurrences of characters or strings within another string.
The replacement strings must be of the same length as the original string.
3. The third format is used to count while replacing occurrences of characters or strings within another string..
It is basically a combination of the first two formats.
4. The fourth format is used to replace occurrences of characters within another string using only one INSPECT.
Any occurrence on the first character of the CONVERTING in the inspected string will be replaced by the first character in the TO string, while occurrences of the second character in the CONVERTING string will be replaced by the second character in the TO string, and so on. The CONVERTING string must be of the same length as the to string.
Tips
1. Format 2 can be used to convert leading spaces to zeros, in a numeric item, e.g.
INSPECT LEADING-SPACE-ITEM REPLACING LEADING SPACES BY ZEROS.
2. Format 4 can be used to convert lowercase to uppercase, e.g.
INSPECT MIXED-CASE-ITEM CONVERTING "abcde..." TO "ABCDE...".
The MERGE Statement
Syntax
Format
MERGE file-name-1{ON { ASCENDING
DESCENDING } KEY {data-name-1}...}...
[COLLATING SEQUENCE IS alphabet-name-1] USING file-name-2 {file-name-3}...
{ [OUTPUT PROCEDURE IS procedure-name-1 [ { THROUGH
THRU } procedure-name-2] }
[GIVING {file-name-4} ...
Description
The MERGE statement is used to merge data files. The records must be in the files to be merged in the same order in which they are entered in the merged file, that is in sequential order specified in the ASCENDING/DESCENDING KEY clause. Two options are available for the output of the operation:
" If the GIVING phrase is specified, the records to be merged are copied in appropriate ASCENDING/DESCENDING KEY order into the GIVING file.
" If the OUTPUT PROCEDURE phrase is specified, the records to be merged are copied in the appropriate ASCENDING/DESCENDING KEY order into the merge file. Records can be obtained from the file using the RELEASE statement.
Tips
1. All of the files referenced must be closed when the MERGE statement is executed.
2. The key fields must all be defined in the record description(s) for the merge file.
3. The merge file cannot be opened or closed.
4. If the GIVING option is used, the GIVING file must have the same record layout as the merge file.
Syntax
Format 1
INSPECT identifier-1 TALLYING identifier-2 FOR
{ CHARACTERS [{ BEFORE
AFTER } INITIAL { identifier-3
literal-1 }] ... } ...
{ ALL
LEADING }{{ identifier-4
literal-2 }[{ BEFORE
AFTER } INITIAL { identifier-5
literal-3 }] ... } ...
Format 2
INSPECT identifier-6 REPLACING
{ CHARACTERS BY { identifier-7
literal-4 }[{ BEFORE
AFTER } INITIAL { identifier-8
literal-5 }] ... } ...
{ ALL
LEADING
FIRST } { identifier-9
literal-6 } BY { identifier-10
literal-7 } [{ BEFORE
AFTER } INITIAL { identifier-11
literal-8 }] ... } ...
Format 3
INSPECT identifier-12 TALLYING identifier-13 FOR
{ CHARACTERS [{ BEFORE
AFTER } INITIAL { identifier-14
literal-9 }] ... } ... REPLACING
{ ALL
LEADING }{{ identifier-15
literal-10 }[{ BEFORE
AFTER } INITIAL { identifier-16
literal-11 }] ... } ...
{ CHARACTERS BY { identifier-17
literal-12 }[{ BEFORE
AFTER } INITIAL { identifier-18
literal-13 }] ... } ...
{ ALL
LEADING
FIRST } { identifier-19
literal-14 } BY { identifier-20
literal-15 } [{ BEFORE
AFTER } INITIAL { identifier-21
literal-16 }] ... } ...
Format 4
INSPECT identifier-22 CONVERTING
{ identifier-3
literal-1 } TO { identifier-23
literal-17 } [{ BEFORE
AFTER } INITIAL { identifier-24
literal-18 }] ...
Description
The INSPECT statement is used to perform various operations on string data. Each of the four formats works slightly differently and is described in the correspondingly numbered area.
1. The first format is used to count occurrences of characters or strings within another string.
The number of occurrences is stored in identifier-2.
The value in identifier-1 is unchanged.
2. The second format is used to replace occurrences of characters or strings within another string.
The replacement strings must be of the same length as the original string.
3. The third format is used to count while replacing occurrences of characters or strings within another string..
It is basically a combination of the first two formats.
4. The fourth format is used to replace occurrences of characters within another string using only one INSPECT.
Any occurrence on the first character of the CONVERTING in the inspected string will be replaced by the first character in the TO string, while occurrences of the second character in the CONVERTING string will be replaced by the second character in the TO string, and so on. The CONVERTING string must be of the same length as the to string.
Tips
1. Format 2 can be used to convert leading spaces to zeros, in a numeric item, e.g.
INSPECT LEADING-SPACE-ITEM REPLACING LEADING SPACES BY ZEROS.
2. Format 4 can be used to convert lowercase to uppercase, e.g.
INSPECT MIXED-CASE-ITEM CONVERTING "abcde..." TO "ABCDE...".
The MERGE Statement
Syntax
Format
MERGE file-name-1{ON { ASCENDING
DESCENDING } KEY {data-name-1}...}...
[COLLATING SEQUENCE IS alphabet-name-1] USING file-name-2 {file-name-3}...
{ [OUTPUT PROCEDURE IS procedure-name-1 [ { THROUGH
THRU } procedure-name-2] }
[GIVING {file-name-4} ...
Description
The MERGE statement is used to merge data files. The records must be in the files to be merged in the same order in which they are entered in the merged file, that is in sequential order specified in the ASCENDING/DESCENDING KEY clause. Two options are available for the output of the operation:
" If the GIVING phrase is specified, the records to be merged are copied in appropriate ASCENDING/DESCENDING KEY order into the GIVING file.
" If the OUTPUT PROCEDURE phrase is specified, the records to be merged are copied in the appropriate ASCENDING/DESCENDING KEY order into the merge file. Records can be obtained from the file using the RELEASE statement.
Tips
1. All of the files referenced must be closed when the MERGE statement is executed.
2. The key fields must all be defined in the record description(s) for the merge file.
3. The merge file cannot be opened or closed.
4. If the GIVING option is used, the GIVING file must have the same record layout as the merge file.