Topic
  • No replies
SystemAdmin
SystemAdmin
403 Posts

Pinned topic Use User defined function with IBM Cobol Compiler 3.4.1

‏2011-02-24T19:46:05Z |
Hello,

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
Updated on 2012-01-24T19:37:45Z at 2012-01-24T19:37:45Z by brataj
  • wmklein
    wmklein
    79 Posts

    Re: Use User defined function with IBM Cobol Compiler 3.4.1

    ‏2011-03-05T03:09:37Z  
    Even 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
    TimVanderWall
    1 Post

    Re: Use User defined function with IBM Cobol Compiler 3.4.1

    ‏2012-01-23T20:57:50Z  
    • wmklein
    • ‏2011-03-05T03:09:37Z
    Even 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.
    You 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.
  • SystemAdmin
    SystemAdmin
    403 Posts

    Re: Use User defined function with IBM Cobol Compiler 3.4.1

    ‏2012-01-24T02:17:13Z  
    You 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.
    Tim,
    Have you considered the LE provided DATE Callable Services? They are already there, and have been fully functional since the Y2K days.
  • SystemAdmin
    SystemAdmin
    403 Posts

    Re: Use User defined function with IBM Cobol Compiler 3.4.1

    ‏2012-01-24T02:17:41Z  
    You 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.
    Tim,
    Have you considered the LE provided DATE Callable Services? They are already there, and have been fully functional since the Y2K days.
  • brataj
    brataj
    40 Posts

    Re: Use User defined function with IBM Cobol Compiler 3.4.1

    ‏2012-01-24T19:37:45Z  
    Tim,
    Have you considered the LE provided DATE Callable Services? They are already there, and have been fully functional since the Y2K days.
    The 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.