Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

COBOL User-defined function

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Vishwamurthy

New User


Joined: 11 Mar 2008
Posts: 57
Location: India

PostPosted: Mon Nov 17, 2008 7:38 pm    Post subject: COBOL User-defined function
Reply with quote

Hi,
I would like to know the syntax for writing a COBOL User-defined function.
The function when called, should return something which I should be able to store into a WORKING-STORAGE variable.

I have searched, opened and found nothing in 158 of the 802 matching topics.

Do reply.

Thank you.
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7904
Location: Bellevue, IA

PostPosted: Mon Nov 17, 2008 7:42 pm    Post subject:
Reply with quote

Have you tried searching the COBOL manuals for user-defined function? What results did you get?
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Nov 17, 2008 10:06 pm    Post subject:
Reply with quote

Hello and welcome to the forum,

What functionality do you want to provide?
Back to top
View user's profile Send private message
Vishwamurthy

New User


Joined: 11 Mar 2008
Posts: 57
Location: India

PostPosted: Tue Nov 18, 2008 9:32 am    Post subject:
Reply with quote

Hi,
on the internet, I got to know that there's a Paragraph 'FUNCTION-ID'. I've seen something like 'ROUTINE-ID' for an option in a multiple choice question in a COBOL Quiz (option may be wrong too). But neither of them is a COBOL Keyword. I've searched a few COBOL books to find description only about intrinsic functions.
No COBOL manual speaks about User-defined functions, surprisingly.

Any functionality..
lets say, if I call that User-defined function like
C = FUNCTION ADD1 (A, B), it should throw no errors and C should have some value. If A and B are both numeric, C should be equal to A + B after the statement is run.

Any help in this regard is appreciable.

Thank you.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Nov 18, 2008 10:12 am    Post subject:
Reply with quote

Hello,

To do what you want, i'd suggest you create a common subroutine (funcadd) that is called dynamically (rather than statically).

The CALL would name 2 input fields, 1 output field, and 1 return-status. When invoked, the code would validate the 2 input numbers and if numeric, add them placing the total in the "output" field. Any problems would be noted in the return-status.
Back to top
View user's profile Send private message
Vishwamurthy

New User


Joined: 11 Mar 2008
Posts: 57
Location: India

PostPosted: Tue Nov 18, 2008 10:18 am    Post subject:
Reply with quote

Thanks for the quick reply. Can you show me an example showing how we'll make use of the return-status, which I've never used before. How does the output variable come back to the main routine? is it a part of the argument list being called BY REFERENCE?

Thank you.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Nov 18, 2008 10:38 am    Post subject:
Reply with quote

Hello,

Quote:
Can you show me an example showing how we'll make use of the return-status,
For example, a return-status of zero could mean the function completed successfully, a 1 could mean the first value was not numeric, a 2 if the second value was not numeric and so on for whatever situations need a return-status.

In the called code, there would be a LINKAGE SECTION that describes the 4 fields. In the calling code, 4 similar fields would be defined and used in the CALL:
Code:
   CALL THE-FUNCTION USING FLD1, FLD2, THE-RESULT, RETURN-STATUS.

THE-FUNCTION is a working-storage field that contains the name of the called module.
Back to top
View user's profile Send private message
Vishwamurthy

New User


Joined: 11 Mar 2008
Posts: 57
Location: India

PostPosted: Tue Nov 18, 2008 11:11 am    Post subject:
Reply with quote

Thanks Scherrer.
That was really informative.
How do I implement a function like this: C = FUNCTION MAX1 (A, B) for getting the maximum of A and B, instead of going for a default function, this way: C = FUNCTION MAX (A, B). 'MAX1 (Arg. list)' would be a function defined by me.

Thank you.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Nov 18, 2008 11:18 am    Post subject:
Reply with quote

Hello,

By adding more code to the called function, you could incorporate whatever options/functionality you wanted. If the code was to be made more general porpose, the called code would need to be provided with which operation to perform as part of the calling parameters (add, max, etc).
Back to top
View user's profile Send private message
Vishwamurthy

New User


Joined: 11 Mar 2008
Posts: 57
Location: India

PostPosted: Tue Nov 18, 2008 11:24 am    Post subject:
Reply with quote

Thats true indeed, about CALLing a SUBROUTINE, but USER-DEFINED FUNCTIONS will never be CALLed using the CALL verb. In COBOL, can we create USER-DEFINED FUNCTIONS? to call them using the keyword FUNCTION..

Thank you icon_cool.gif
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 685
Location: Earth

PostPosted: Tue Nov 18, 2008 12:10 pm    Post subject:
Reply with quote

Answer is NO.
Back to top
View user's profile Send private message
Vishwamurthy

New User


Joined: 11 Mar 2008
Posts: 57
Location: India

PostPosted: Tue Nov 18, 2008 1:32 pm    Post subject:
Reply with quote

Thank you. Scherrer for being very active, and AGKSHIRSAGAR for the reply.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Nov 18, 2008 10:50 pm    Post subject:
Reply with quote

Hello,

You're welcome icon_smile.gif

Quote:
can we create USER-DEFINED FUNCTIONS? to call them using the keyword FUNCTION
As was posted - no, but that does not prevent the need from being filled by invoking a subroutine rather than a "function".

The mechanism ("call" versus "function") is not nearly as important as delivering solutions that always work, are easily maintainable, and do not require unreasonable amounts of system resources.
Back to top
View user's profile Send private message
sfazel

New User


Joined: 16 Jan 2014
Posts: 1
Location: us

PostPosted: Thu Aug 07, 2014 11:59 pm    Post subject: Reply to: COBOL User-defined function
Reply with quote

A function by definition is a region residant object at execution time. A sub-program is a library call therefore it is loaded. Older COBOL used one giant load library to bring everything in.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Fri Aug 08, 2014 12:49 am    Post subject: Reply to: COBOL User-defined function
Reply with quote

You got references for any of that?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am
No new posts Cobol list of programs being called biswajit.dattagupta COBOL Programming 5 Tue Nov 01, 2016 2:10 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us