Single Sourcing and Dual FCD Support in Native COBOL Programs

Restriction: The following information applies to native COBOL only.

All system components supplied with the 32-bit development system support the File Control Description formats FCD2 and FCD3. System components supplied with the 64-bit development system only support FCD3; they do not support FCD2 due to the incompatibilities in pointer size.

The system components that are supplied with your development system are single sourced, which means that they are compatible with FCD3 on 64-bit systems when compiling for 64-bit, or work with both FCD2 and FCD3 on 32-bit systems when compiling for 32-bit.

If your applications cannot solely use either FCD3 or FCD2, then we recommend that you take this single-sourcing approach in your applications. If you can only use one FCD format, you need make no further provisions to handle the extended FCD structure.

However, some programs in your application might provide interfaces to other components in your application, which might include FCD structures. In these cases, you might need to provide gradual transition to full FCD3 support; at run time, therefore, your program will need to accept both FCD2 and FCD3 formats, and to distinguish them as necessary.

For example, if there are few references to FCD fields within your code, the following source code model might be suitable:

       linkage section.
       01  fcd-user  pic x.
       01  fcd2.
           copy "xfhfcd2".
       01  fcd3.
           copy "xfhfcd3".
       procedure division using fcd-user.
       set address of fcd3  to address of fcd-user
       if  fcd-version of fcd3 = 0
         *> Code to deal with FCD2...
      $if P64 set
       display "Error: cannot accept FCD2 on 64 bit platform"
       goback
      $end
         set address of fcd2  to address of fcd-user
       end-if

Every time a field of the FCD is referenced you must add code that does something like the following:

       if  ( fcd-version of fcd3 not = 0 
          and fcd--line-sequential of fcd3)
       or  ( not fcd-version of fcd3 = 0
       and fcd--line-sequential of fcd2 )
        *> Do line sequential manipulation
       end-if

If, however, the bulk of the code in your component directly references the FCD structure, you could internally use only the FCD3 structure and, if necessary, establish mappings, to and from FCD2 at entry and exit gateways to the component. For example:

       working-storage section.
       78  78-fcd3-map-to-fcd3         value 0.
       78  78-fcd3-map-from-fcd3       value 1.
       78  78-fcd3-map-error-none      value 0.
       78  78-fcd3-map-error-64bit     value -1.
       78  78-fcd3-map-error-func      value -2.
       78  78-fcd3-map-error-reladdr   value -3.
       01  fcd3-work.
       copy "xfhfcd3".
       linkage section.
       01  fcd-user            pic x.
       procedure division using fcd-user.
      *> Entry Gate map FCD2 (if necessary) to FCD3
       call 'fcd3map' using fcd-user fcd3-work
                      by value 78-fcd3-map-to-fcd3 size 1
       if  return-code not = 0 
        display "Error: cannot convert FCD formats"
        goback
       end-if

      *> Operate on the FCD as FCD3 only
      *> ....
      *> Exit Gate map FCD3 (if necessary) to FCD2
       call 'fcd3map' using fcd-user fcd3-work
                      by value 78-fcd3-map-from-fcd3 size 1
     goback.