IBM i message

RNQ0100: String position or length out of range

RNQ0100 means an ILE RPG program ran a string operation, most often %SUBST, with a start position or length that falls outside the string. It matches RPG program status code 00100, and the job is waiting for a reply.

Other names for this code

Also written as RNX0100, status 00100, RPG status 100, %STATUS 100, RNQ0100 %SUBST, RPG string out of range.

What it means

RNQ0100 comes from the ILE RPG runtime. The number after the prefix is the RPG program status code, so RNQ0100 is status 00100. IBM's ILE RPG Reference describes that status as a value out of range for a string operation. In practice the program asked for a piece of a string that isn't there. A start position of zero or less, a negative length, or a start plus length that runs past the end of the field all do it.

The usual source is %SUBST or the older SUBST operation. %SCAN and other built-ins that take a start position raise the same status when the start is beyond the string. For a variable-length (VARYING) field the check is made against the current length, not the declared size, so a field that is shorter today than it was in testing can trip it.

The Q in RNQ means inquiry. The RPG default handler sends it when nothing in the program dealt with the error, and the job stops until someone answers. An interactive user sees it on screen. In a batch job it usually goes to the QSYSOPR message queue. RNX0100 is the escape form of the same message, with the same number and meaning. An escape message doesn't wait for anyone. It is logged and can be caught by a MONITOR group or passed to a caller.

Common causes

  • A length worked out from %SCAN when the search string wasn't found. %SCAN returns 0, so an expression like %SCAN(',' : name) - 1 gives a length of -1.
  • Input data shorter than the program assumed, for example a code that is normally 10 characters arriving as 6.
  • A VARYING field whose current length is shorter than the start position the program uses.
  • A loop that steps one position past the end of the field.
  • A start position read from a file or a parameter that holds 0 or a value larger than the field.

How to find the problem

  1. Put the cursor on the message and press F1. The help text names the RPG procedure, the program and the statement number. In batch, look in QSYSOPR with DSPMSG QSYSOPR, or in the job log with DSPJOBLOG.
  2. Match the statement number to the compile listing. With OPTION(*SRCSTMT) it is the source sequence number. With *NOSRCSTMT it is the listing's own statement number.
  3. If you reply D, the runtime writes a formatted dump of the program's variables to a spooled file before it ends the program. Look there for the values of the start and length expressions.
  4. To reproduce it, run the program under STRDBG with a breakpoint on that statement and display the string, its %LEN and the start and length values.

How to fix it

  • Check the values before you use them. Make sure the start is at least 1 and that start plus length minus 1 is no more than %LEN of the field.
  • When %SCAN feeds a position, test its result for 0 before you build a substring from it.
  • Wrap the statement in a MONITOR group with ON-ERROR 00100 if the program should carry on with a default value. EVAL has no (E) extender, so MONITOR is the way to catch this in an expression.
  • Reply C to end the program cleanly, then fix the data or the code and rerun. Use D if the developers want a dump.

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.

Report a correction to WND Software.

Questions

What is the difference between RNQ0100 and RNX0100?

They report the same condition, status 00100. RNQ0100 is an inquiry that waits for a reply because nothing handled the error. RNX0100 is the escape form, which is logged and can be caught by MONITOR or a caller.

Which reply should I give to an RNQ message?

C (cancel) is the safe answer when you don't know the program. D and F also cancel, but first write a dump the developers can use. G skips the rest of the current RPG cycle and resumes at its input step (*GETIN). That is a call for the program's owner to make.

Can %STATUS tell me this happened?

Yes. After the error, %STATUS returns 100. You can test it in an ON-ERROR group or in the *PSSR subroutine.