This article explains if there is a way to raise a trappable error when length parameter causes substring extraction to exceed the size of the source field.
Problem:
Compile and run the following program with COBCONFIG environment variable set to a file containing set memory_strategy=0x80000001 should cause an RTS 252 error, but the error did not occur.
01 FIELD-1 PIC X(80) VALUE ALL "*".with
01 FIELD-2 PIC X(80) VALUE SPACE.
01 SUB-1 PIC S9(04) VALUE 10.
MOVE FIELD-1(75:SUB-1) TO FIELD-2.
Is there a way to raise a trappable error in Micro Focus COBOL when the length parameter would cause substring extraction to exceed the size of the source field?
The desire is to stop program execution if a parameter (SUB-1 in this example) would cause an invalid MOVE and hence possibly an invalid value in FIELD-2.
Resolution:
The memory_strategy config variable will only check overruns at the beginning or end of a memory block. It does not apply to this example for two reasons. Firstly, there is no guarantee the working-storage will be dynamically allocated. In object code working-storage is .bss (statically allocated by the OS). Secondly, memory_strategy cannot check overruns of sub-allocations internal to a memory block.



