This article explains a simplified test case resulting in the 154 PERFORM nested too deeply error message.
Problem:
We received the following error when the program was compiled to .gnt or .so or .exe (not .int), and then only when the PROFILE compiler directive was used.
Execution error : file 'b'
error code: 154, pc=0, call=1, seg=0
154 PERFORM nested too deeply
Following is a simplified test case:
000001 WORKING-STORAGE SECTION.
000002 01 WS98-COUNT PIC S9(4) COMP VALUE 0 SYNC.
000003
000004 PROCEDURE DIVISION.
000005 A-MAIN SECTION.
000006 A-00.
000007 PERFORM B-HANDLE-INSERT-MODE.
000008 PERFORM Z-FINISH.
000009
000010 B-HANDLE-INSERT-MODE SECTION.
000011 PERFORM 500 TIMES
000012 PERFORM F-GET-NEXT-ACCOUNT
000013 END-PERFORM.
000014 DISPLAY "F-EXIT 1 -- " WS98-COUNT.
000015 display " End 1st Loop ".
000016 PERFORM 500 TIMES
000017 PERFORM F-GET-NEXT-ACCOUNT
000018 END-PERFORM.
000019 DISPLAY "F-EXIT 1 -- " WS98-COUNT.
000020 display " End 2nd Loop ".
000021 B-EXIT.
000022 EXIT.
000023
000024 F-GET-NEXT-ACCOUNT SECTION.
000025 F-00.
000026 ADD 1 TO WS98-COUNT.
000027 F-EXIT.
000028 EXIT.
000029
000030 Z-FINISH SECTION.
000031 Z-00.
000032 STOP RUN.
000033 Z-EXIT.
000034 EXIT.
The program actually PERFORMS a section which includes a STOP RUN, which doesn't make much sense because PERFORM implies a return of control, but the STOP RUN would never return.
Resolution:
If the PROFILE directive is not used during compile time, then the problem will not occur at runtime. This error was experienced on Server Express version 4.0 ServicePack2. The problem is already fixed in Server Express version 5.0 and subsequent versions, so that even if PROFILE is specified, the error will not occur.
The PROFILE directive causes a file with extension .ipf to be produced each time the program is run. Later a person can use the cobprof command to interpret this .ipf file and generate a performance statistics report. For more information, refer to the Server Express documentation and look up "Profiler" in the index.
The PROFILE directive is useful when debugging or when exploring performance issues. It is not recommended when compiling for production because (like many debugging tools) it involves some overhead, so it is reasonable to remove it when compiling for production.