does anyone know wether it's possible to define and program user defined function as introduced with ANSI 2002 to Cobol?
I've used PL/I as programmng language and think it the more comfortable way ´compared to using subprogramms.
Thanks for your help, Bridgy
This topic has been locked.
5 replies Latest Post - 2012-01-24T19:37:45Z by brataj
Pinned topic Use User defined function with IBM Cobol Compiler 3.4.1
Answered question This question has been answered.
Unanswered question This question has not been answered yet.
Updated on 2012-01-24T19:37:45Z at 2012-01-24T19:37:45Z by brataj
wmklein 200000329M79 PostsACCEPTED ANSWER
Re: Use User defined function with IBM Cobol Compiler 3.4.12011-03-05T03:09:37Z in response to SystemAdminEven with the latest version of Enterprise COBOL (V4R2), IBM does NOT provide support for "user defined functions" as specified in the 2002 ISO Standard (and in the current revision work that iBM participagtes in).
There are a number of features from teh ISO 2002 Standard that SHARE has requested IBM to implment. This is not one of them.
If you shop belongs to SHARE, then I would suggest that you submit a requirement in the LANG project for this facility (if you think it is important to your business).
I should add, however, that with the ability to have RETURNING phrases (on the procedure division header), that I am not quite certain why you think that coding a user-defined funciton is "easier" (or "better") than just using a COBOL subprogram. If you can (better) describe what you want to DO we may be able to help you do it in Enterprise COBOL "native" syntax.
TimVanderWall 270005161K1 PostACCEPTED ANSWER
Re: Use User defined function with IBM Cobol Compiler 3.4.12012-01-23T20:57:50Z in response to wmkleinYou asked why one would want a user-defined function, as opposed to using CALL with RETURNING. I am working on an older very large (mostly) COBOL system that has to handle dates in several different formats. We currently have nearly 50 different routines to convert, manipulate, and compare various format dates. The COBOL code is not very readable when one has to use these routines (for example) to compare two dates. I proposed simplifying the code using a function to convert dates into a standard format (e.g., ccyymmdd) for comparison. Then the programmer could a statement like the following and not worry about what's behind it.
IF XXDATE(START-DATE, 'C6') > XXDATE(EFFECTIVE-DATE, 'J5')
Function XXDATE would convert the date provided to the standard compare format (in this case ccyymmdd) based upon the specification in the second operand. In my example 'C6' specifies a 6-digit calendar date (yymmdd) and 'J5' specifies a 5-digit Julian date. A valid comparison can then be done. A function like that would make the program easier to read/maintain and save the programmer time in coding.
Unfortunately, my proposal cannot be implemented with current IBM Enterprise COBOL.
brataj 100000816340 PostsACCEPTED ANSWER
Re: Use User defined function with IBM Cobol Compiler 3.4.12012-01-24T19:37:45Z in response to SystemAdminThe LE date functions have the same problem as subprograms defined with RETURNING: you have to call the functions/subprograms first, explicitly defining "temporary" fields to hold the returned values. Only then can you write the IF statement, testing on the temporary fields.
That's what user defined functions buy you--the compiler handles the temporaries in the background and you can unclutter your program.