AMODE switching

When you have an application that has COBOL subprograms, some of the COBOL subprograms can be AMODE 31 and some can be AMODE 24. To have this mixed AMODE support, the calls must be dynamic and the Language Environment® runtime options ALL31(OFF) and STACK(,,BELOW) must be in effect.

If your application consists of only COBOL programs, and you are using dynamic calls, each COBOL subprogram will always be entered in the proper AMODE. For example, if you are using a dynamic call from an AMODE 31 COBOL program to an AMODE 24 COBOL program, the AMODE is automatically switched.

However, if you are using procedure pointers, function pointers, or other languages that call COBOL subprograms, you must ensure that when a COBOL program is called more than once in an enclave, it is entered in the same AMODE each time that it is called. The AMODE is not automatically switched in this case.

The following scenario shows that AMODE problems can arise when procedure pointers are used to call COBOL subprograms. This scenario is not supported because the COBOL program COBOLY is not entered in the same AMODE each time that it is called.

This figure illustrates the following steps.

  1. COBOLX is AMODE 31. It uses the SET statement to set a procedure pointer to COBOLZ. COBOLZ is a reentrant program object and is AMODE 31 and RMODE 24. COBOLX calls COBOLZ using the procedure pointer. COBOLZ is entered in AMODE 31.
  2. COBOLZ returns to COBOLX.
  3. COBOLX dynamically calls COBOLY, passing the procedure pointer for COBOLZ. COBOLY is a reentrant program object, and is AMODE 24 and RMODE 24. COBOLY is entered in AMODE 24.
  4. COBOLY calls COBOLZ using the procedure pointer. This call causes COBOLZ to be entered in AMODE 24, which is not the same AMODE in which COBOLZ was entered when it was called the first time.

The following scenario uses a mix of COBOL and assembler language. This scenario is not supported because the COBOL program COBOLB is not entered in the same AMODE each time that it is called.

This figure illustrates the following steps.

  1. COBOLA is AMODE 31. COBOLA dynamically calls COBOLB. COBOLB is a reentrant program object and is AMODE 31 and RMODE 24. COBOLB is entered in AMODE 31.
  2. COBOLB returns to COBOLA.
  3. COBOLA dynamically calls ASSEM10, which is in assembler language. ASSEM10 is a reentrant program object, and is AMODE 24 and RMODE 24. ASSEM10 is entered in AMODE 24.
  4. ASSEM10 loads COBOLB. ASSEM10 does a BALR instruction to COBOLB. COBOLB is entered in AMODE 24, which is not the same AMODE in which COBOLB was entered when it was called the first time.

related tasks  
Making dynamic calls

related references  
Language Environment Programming Reference (ALL31)