MCH0603: Range of subscript value or character string error
MCH0603 (Range of subscript value or character string error) means a program on IBM i used a subscript outside an array's bounds, or a substring that falls outside the string it is taken from.
Other names for this code
Also written as MCH0603 error, MCH0603 range of subscript value, range of subscript value or character string error, MCH0603 COBOL, MSGID MCH0603.
What it means
Arrays and strings have a fixed size. The machine checks references that use a subscript or a start position and length. When the subscript is below 1 or above the number of elements, or the substring would start or end outside the string, it raises MCH0603 and the instruction stops.
IBM's ILE COBOL guide lists MCH0603 as one of the common exceptions. It covers two cases. One is a subscript outside the bounds of a table. The other is an operand that defines a character string reaching outside the string it is based on, which in COBOL is reference modification and in other languages is a substring.
The message is an escape message sent to the program that ran the instruction. If the program doesn't handle it, the job ends with a function check or an inquiry message. RPG reports its own status codes for the same kinds of mistakes, 00121 for an array index that isn't valid and 00100 for a value out of range in a string operation.
Common causes
- A loop ran one step too far, for example a counter that goes to the table size plus one, or a loop that starts at 0.
- A count from the data is larger than the table. A record says it has 60 detail lines and the table in the program holds 50.
- A substring start position or length was calculated from data, such as the result of a search that returned 0 when nothing was found, and then used as a position.
- A string is shorter than the program assumed, for example a variable-length field whose current length is less than the position used.
How to find the problem
- Run
DSPJOBLOG, put the cursor on MCH0603 and press F1, then F9. The message details name the program, module, procedure and statement. - Look at the subscripts and substring positions in that statement, and at the size of each table and string they refer to.
- Debug with
STRDBGand stop on the statement. Display the subscript or the start and length values and compare them with the declared sizes. - Find the record or input being processed. If the failure happens on one record only, its data (a count, a length, a missing value) is usually what pushed the subscript out of range.
How to fix it
- Check every subscript that comes from data or a loop against the table size before using it.
- Make the table big enough for the real data, or stop filling it at the limit and report the overflow.
- Check search results before using them as positions. A result of 0 means not found and isn't a valid start position.
- Use the current length of variable-length strings, not their declared length, when you calculate a substring.
IBM documentation
IBM Display Message Descriptions (DSPMSGD). Use the documentation for your installed release.
This link opens the relevant IBM reference library or lookup instructions. Match the complete code and your installed product release; it is not a code-specific review.
Read the installed message description:
DSPMSGD MSGID(MCH0603) MSGF(QSYS/QCPFMSG)
Also inspect the full job log and second-level message text, including substitution values.
Related codes
Questions
Is MCH0603 the same as RNQ0121?
They report the same kind of mistake. MCH0603 is the machine's message. RNQ0121 is ILE RPG's inquiry for status 00121, an array index that isn't valid.
Why does the error happen only on some records?
The subscript or position usually comes from the data. Only records with a large count, a short value or a missing search result push it out of range.