Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 15 : INTRINSIC functions


Intrinsic functions

  • Intrinsic functions are built-in functions provided by COBOL.
  • Intrinsic functions return values on passing arguments to them. COBOL Intrinsic functions are made up of a specific algorithm which works on arguments passed to it and returns the calculated/modified value
  • For example, we have five variables containing some value and we want to identify the maximum value, in such case, instead of writing algorithm in our program, we can directly use intrinsic function “MAX”
    Example:-

    MOVE FUNCTION MAX (10, 20, 30, 40, 50) TO MAX-NUM.

    Above statement will move value 50 to MAX-NUM, as it is maximum value
  • Using of intrinsic function in nested manner is allowed i.e. you can use a function such that it can have an argument as other function that has another set of arguments.
  • General format of intrinsic function is :-

    FUNCTION function-name [({argument}… )]  [reference-modifier]

  • Where,
    • function-name is name of intrinsic function (example :- MAX, LENGTH etc..)
    • argument is an identifier, a literal or an arithmetic expression. Multiple arguments can be passed by separating it with comma. Argument’s data type and class must comply with legal constraints of the function.
    • reference-modifier can be specified only for alphanumeric functions
  • Below are list of all function by its category:-
  • CATEGORY FUNCTION
    String Manipulation LOWER-CASE,  UPPER-CASE,  REVERSE,  NUMVAL, NUMVAL-C
    Relational MAX,   MIN,   ORD-MAX,   ORD-MIN
    Date and Time CURRENT-DATE,  DATE-OF-INTEGER,  DATE-TO-YYYYMMDD DAY-TO-YYYYDDD,  DAY-OF-INTEGER,  INTEGER-OF-DATE, INTEGER-OF-DAY,   TEST-DATE-YYYYMMDD,  TEST-DAY-YYYYDDD   WHEN-COMPILED,  YEAR-TO-YYYY
    Statistics ANNUITY, MEAN,  MEDIAN,  MIDRANGE,  PRESENT-VALUE,  RANGE,   STANDARD-DEVIATION,  VARIANCE
    Scientific/Mathematics ACOS, ASIN, ATAN, COS, FACTORIAL, LOG, LOG10, MOD, REM, SIN, SQRT, SUM, TAN
    Other ARGCOUNT (OpenVMS), CHAR, INTEGER, INTEGER-PART, LENGTH, ORD, RANDOM
  • Based on type of value function returns, there are three types of functions:-
    • Alphanumeric :- Function which returns string value containing one or more character
    • Numeric :- Function which returns numeric value which may have non-zero digit to the right of decimal point
    • Integer function:- Function which returns numeric value which cannot have any non-zero digit to the right of decimal point

Important INTRINSIC functions explanation:-

Function Explanation
LOWER-CASE Purpose:- Returns string value converted to lowercase

Number and Type of arguments passed: 1 alphabetic or 1 alphanumeric

Returned value type: Alphanumeric

Example :-

MOVE FUNCTION LOWER-CASE (SOURCE-STR) TO DEST-STR.

If SOURCE-STR contains ‘MAIFRAME’, then ‘mainframe’ will be returned by function and hence that value will be moved to DEST-STR
UPPER-CASE Purpose:- Returns string value converted to uppercase

Number and Type of arguments passed: 1 alphabetic or 1 alphanumeric

Returned value type: Alphanumeric

Example :-

MOVE FUNCTION UPPER-CASE (SOURCE-STR) TO DEST-STR.

If SOURCE-STR contains ‘mainframe’, then ‘MAINFRAME’ will be returned by function and hence that value will be moved to DEST-STR
REVERSE Purpose:- Returns string value in reverse order

Number and Type of arguments passed: 1 alphabetic or 1 alphanumeric

Returned value type: Alphanumeric

Example :-

MOVE FUNCTION REVERSE (SOURCE-STR) TO DEST-STR.

If SOURCE-STR contains ‘ABCD’, then ‘DCBA’ will be returned by function and hence that value will be moved to DEST-STR
NUMVAL Purpose:-  Returns the numeric value represented by the string specified by the argument. Leading and trailing spaces are not considered. This function is used to convert an alphanumeric field to numeric.

Number and Type of arguments passed: 1 alphanumeric

Returned value type: Numeric

Example :-

COMPUTE DEST-TOT = FUNCTION NUMVAL ("4123").

The value returned and stored in DEST-TOT (a numeric data item) is 4123.
NUMVAL-C Purpose:-  Returns the numeric value represented by the string specified by the first argument. Any currency sign found in the string and any commas preceding the decimal point are not considered in determining the result.

Number and Type of arguments passed: 1 or 2 alphanumeric

Returned value type: Numeric

Example :- COMPUTE DEST-TOT = FUNCTION NUMVAL-C ("$4,500.00", "$").
The value returned and stored in DEST-TOT (a numeric data item) is 4500.

MAX

Purpose:- Returns the content of argument that contains maximum value

Number and Type of arguments passed: 1 or more alphabetic and/or alphanumeric, or 1 or more integer and/or numeric

Returned value type: Depends on arguments

Example :-

MOVE FUNCTION MAX ("X", "Z", "Y") TO MAX-VALUE-CHAR.

Above statement will move ”Z” to MAX-VALUE-CHAR

MOVE FUNCTION MAX (10, 30, 20) TO MAX-VALUE-NUM.

Above statement will move 30 to MAX-VALUE-NUM

MIN

Purpose:- Returns the content of argument that contains minimum value

Number and Type of arguments passed: 1 or more alphabetic and/or alphanumeric, or 1 or more integer and/or numeric

Returned value type: Alphanumeric

Example :-

MOVE FUNCTION MIN ("X", "Y", "Z") TO MIN-VALUE-CHAR.

Above statement will move ”X” to MIN-VALUE-CHAR

MOVE FUNCTION MIN (10, 30, 20) TO MIN-VALUE-NUM.

Above statement will move 10 to MIN-VALUE-NUM

ORD-MAX

Purpose:- Returns position(ordinal number) of argument that contains maximum value

Number and Type of arguments passed: 1 or more alphabetic, or 1 or more numeric, or 1 or more alphanumeric

Returned value type: Integer

Example :-

MOVE FUNCTION ORD-MAX (10, 30, 20) TO MAX-VALUE-POSITION.

Above statement will move ‘2’ to MAX-VALUE-POSITION as 2nd argument holds the maximum value among three arguments

ORD-MIN

Purpose:-  Returns position(ordinal number) of argument that contains minimum value

Number and Type of arguments passed: 1 or more alphabetic, or 1 or more numeric, or 1 or more alphanumeric

Returned value type: Integer

Example :-

MOVE FUNCTION ORD-MIN (10, 30, 20) TO MIN-VALUE-POSITION.

Above statement will move ‘1’ to MIN-VALUE-POSITION as 1st argument holds the minimum value among three arguments

CURRENT-DATE

Purpose:- Returns current date in form of 21 chars alphanumeric value (YYYYMMDDHHMMSSnnnnnn)

Number and Type of arguments passed: None

Returned value type: Alphanumeric

Example :-

MOVE FUNCTION CURRENT-DATE TO WS-TODAY-DATE.

Above statement will move ”201806120330314500000” to WS-TODAY-DATE if job is run on Date ‘2018-June-12’ @ time ’03:30:31’.

‘45’ indicates, the hundredths of seconds, 45 after 03:30. Last 6 digits always have value zero it is reserved for future use.

DATE-OF-INTEGER

Purpose:- Returns date in format ‘YYYYMMDD’ on passing argument in form of a positive integer which represents a number of days succeeding 31-Dec-1600. Valid range of integer 1 to 3,067,671, which corresponds to dates ranging from January 1, 1601 through December 31, 9999.

Number and Type of arguments passed: 1 integer

Returned value type: Integer

Example :-

COMPUTE FINAL-DT = FUNCTION DATE-OF-INTEGER (11).

Above statement will move ‘16010111’ to FINAL-DT which represents 11-Jan-1601

MEAN

Purpose:- Returns arithmetic mean(average) of arguments

Number and Type of arguments passed: 1 or more numeric

Returned value type: Numeric

Example :-

COMPUTE AVERAGE-VALUE = FUNCTION MEAN (5, 10, 15).

Above statement will move ‘10’ to AVERAGE-VALUE which was calculated by MEAN function as ((5+10+15)/3 =10)

FACTORIAL

Purpose:- Returns an integer that is the factorial of the argument specified

Number and Type of arguments passed: 1 integer, int

Returned value type: Integer

Example :-

COMPUTE FACTORIAL-VALUE = FUNCTION FACTORIAL (5).

Above statement will move ‘120’ to FACTORIAL-VALUE which was calculated by FACTORIAL function as (5! = 5 * 4 * 3 * 2 * 1 = 120)

SUM

Purpose:- returns a value that is the sum of the arguments.

Number and Type of arguments passed: 1 or more integer or 1 or more numeric

Returned value type: Integer or numeric depending on arguments

Example :-

COMPUTE TOTAL-VALUE = FUNCTION SUM (5,15,10).

Above statement will move ‘30’ to TOTAL-VALUE which was calculated by SUM function as (5+15+10 =30)

LENGTH

Purpose:- Returns an integer equal to the length of the argument in bytes.

Number and Type of arguments passed: 1 alphabetic or numeric or alphanumeric data item, or 1 nonnumeric literal

Returned value type: Integer

Example :-

COMPUTE LENGTH-VALUE = FUNCTION LENGTH ("S. V. PATEL").

Above statement will move ‘11’ to LENGTH-VALUE which was calculated by LENGTH function as number of character in string “S. V. PATEL” is 11.

RANDOM

Purpose:- Returns a numeric value that is a pseudo-random number.

Number and Type of arguments passed: 1 integer or none

Returned value type: Numeric

Example :-

COMPUTE RAN-VALUE = FUNCTION RANDOM.

After execution above statement, RAN-VALUE will have some random number generated by function RANDOM



Advertisements






© copyright mainframebug.com
Privacy Policy