Function definition: Difference between revisions

→‎{{header|COBOL}}: I don't actually have access to IBM Enterprise COBOL for z/OS version 6.4 so I'm just going off the docs
imported>Acediast
(→‎{{header|COBOL}}: I don't actually have access to IBM Enterprise COBOL for z/OS version 6.4 so I'm just going off the docs)
Line 1,142:
=={{header|COBOL}}==
In COBOL, ''multiply'' is a reserved word, so the requirements must be relaxed to allow a different function name. The following uses a program:
{{works with|OpenCOBOLGnuCOBOL}}
{{works with|IBM Enterprise COBOL for z/OS}}
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. myTest.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 x PICPICTURE IS 9(3) VALUE IS 3.
01 y PICPICTURE IS 9(3) VALUE IS 2.
01 z PICPICTURE IS 9(9).
PROCEDURE DIVISION.
CALL "myMultiply" USING
Line 1,162 ⟶ 1,163:
DATA DIVISION.
LINKAGE SECTION.
01 x PICPICTURE IS 9(3).
01 y PICPICTURE IS 9(3).
01 z PICPICTURE IS 9(9).
PROCEDURE DIVISION USING BY REFERENCE x, y, z.
MULTIPLY x BY y GIVING z.
EXIT PROGRAM.
Line 1,171 ⟶ 1,172:
 
This example uses user-defined functions, which were added in COBOL 2002.
{{works with|GNU CobolGnuCOBOL|2.0}}
{{works with|IBM Enterprise COBOL for z/OS|6.4}}
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. myTest.
Line 1,180 ⟶ 1,182:
DATA DIVISION.
WORKING-STORAGE SECTION.
01 x PICPICTURE IS 9(3) VALUE IS 3.
01 y PICPICTURE IS 9(3) VALUE IS 2.
PROCEDURE DIVISION.
DISPLAY myMultiply(x, y).
Line 1,191 ⟶ 1,193:
DATA DIVISION.
LINKAGE SECTION.
01 x PICPICTURE IS 9(3).
01 y PICPICTURE IS 9(3).
01 z picPICTURE IS 9(9).
PROCEDURE DIVISION USING x, y RETURNING z.
MULTIPLY x BY y GIVING z.
EXIT FUNCTIONGOBACK.
END FUNCTION myMultiply.</syntaxhighlight>
 
Anonymous user