Skip to content

TypeCobolFunctionNutshell

Olivier Smedile edited this page Dec 5, 2016 · 6 revisions
identification division.
program-id. MyProgram.
data division.
working-storage section.
01  myDate1 TYPE Date.
01  myDate2 TYPE Date.
01  numberOfDays pic 9(05) comp-5.

procedure division.

*Procedure to calculate the number of days between 2 dates
declare procedure daysBetween private
                                  input   date1 type Date
                                          date2 type Date
                                  output  nbOfDays pic 9(05) comp-5.
procedure division.
*     The details of the calcul is not detailled here...
      move result to nbOfDays
 .
end-declare.

 
*Appel à ma procédure déclarée ci-dessus
     call daysBetween input  myDate1
                             myDate2
                      output numberOfDays

     goback
     .
 end program MyProgram. 

Advantages of function/procedure:

  • ✓ Syntax shorter than a nested program or a program

  • ✓ Name your function with more than 8 caracters

  • ✓ Specify your input/output parameters

  • ✓ Control your arguments (input/output) at compilation time

    • ✓ control the number of arguments and their types

    • control the size of paramers

  • Have the return code as an implicit parameter (2017)

  • Check if caller test the return code (2017)

  • Propose visibily mechanism (2017)

  • Function chaining (2017/2018)

Clone this wiki locally