MainframeSupports
tip week 51/2009:

Many times I have given COBOL credit for being able to do more than most PL/I programmers think COBOL can. Until now I did not find any replacement in COBOL for the functionality provided by TITLE in PL/I. I even teased one of my colleagues, Per Jørgensen, about the impossible task of doing the same thing in COBOL. But Per is a stubborn man so he found a tip on the internet which I hereby give to you in my words.

The functionality of the following program is to read a file in FB format with LRECL=80. The DD name of the file is specified in PARM= on the EXEC card in JCL. You may execute the program by using a //MYDDNAME EXEC PGM=MYDDNAME,PARM='DDNAME01' which will output the complete contents of the dataset allocated to DDNAME01 on SYSOUT, provided you have allocated something to DD name DDNAME01 with the specified DCB information:

identification division.
program-id. myDDname.
environment division.
input-output section.
file-control.
    select ddName assign to ddName
    file status is ddNameStatus.
data division.
file section.
fd  ddName
    recording mode is f.
01  ddNameRec pic x(80).
working-storage section.
01  ddNameLen pic 9(4) binary.
01  ddNameStatus pic 9(2).
01  actualDDname pic x(8).
linkage section.
01  parm.
  02  parmL pic 9(4) binary.
  02  parmD pic x(100).
procedure division using parm.
    if parml > 0
      move parmD(1:parmL) to actualDDname
      call 'newDDname' using actualDDname ddName
    end-if
    open input ddName
    read ddName
    perform until not ddNameStatus = 0
      display ddNameRec
      read ddName
    end-perform
    close ddName
    goback.
identification division.
program-id. newDDname.
data division.
linkage Section.
01  ddName pic x(8).
01  fdArea pic x(48).
procedure division using ddName fdArea.
    move ddName to fdArea(41:8)
    goback.
end program newDDname.
end program myDDname.

The idea is to manipulate the data found on the address where the FD variable ddName is located. This result is acheived in the specified way. Please be aware that the tip might not work at your installation if you are using another version of the COBOL compiler than the one used for this tip. If the tip does not work, the DD name is located at another offset in the FD variable. All you need is to determine this offset and use that instead.

Of course it is not very user friendly that COBOL does not have a function similar to TITLE in PL/I and have to use methods like the above which might be compiler version dependent. You must carefully consider your needs before you use this tip.

Did you notice the use of an internal program in COBOL? It is remarkable how few statements you need to define in order to make it work.

Previous tip in english        Sidste danske tip        Tip list