Could you post the error message you a getting from the precompiler? I’ve tried it out today (but my environment was zOS) and it works fine.
My variables were defined as
05 WS-BEGIN PIC S9(9) COMP.
05 WS-END PIC S9(9) COMP.
05 WS-TEXT PIC X(50).
If your precompiler doesn’t allow it (I’m not fit in DB2 for AS/400) you could define a UDF that gets the three parms (text, begin, end) and sends the substring back.
The declarations could be exactly that way in i5/OS COBOL. But without seeing the code that causes trouble, there is no way to know what is wrong. It could be the variables themselves or it could be an improper program structure for V5R2 (which was getting old at the time of the question.)