NET/MASTER Network Control Language (NCL) Programmer's Guide

Getting Started With Functions
An NCL Tutorial
3–24 106160 Tandem Computers Incorporated
The C2X Built-in Function
The C2X built-in function converts any string to its hexadecimal equivalent. In
BUILTIN2, the string “hello, world” is converted to its hexadecimal equivalent.
The CENTER Built-in Function
The CENTER built-in function centers a string of characters inside another string of
characters. In BUILTIN2, the string of characters to center is “hello, world.” The next
parameter specifies the length of the final string in which “hello, world” is centered.
The final parameter in this example specifies a pad character; this character pads the
left side and the right side of “hello, world” with asterisks (*).
The LENGTH Built-in Function
The LENGTH built-in function returns the length of a specified string of characters. In
BUILTIN2, the length of the string “hello, world” is 12. The built-in function does not
include the opening and closing quotes as part of the string.
The UPPER Built-in Function
The UPPER built-in function converts lowercase letters to uppercase letters. In
BUILTIN2, the result of the task is “HELLO, WORLD.”
The USERW1 NCL
Procedure
The appearance and structure of a user-written function is much the same as an NCL
procedure: the method of declaration is very similar and it is called in much the same
way. The following listing shows a user-written function called CUBE; it is part of an
NCL procedure called USERW1:
userw1: PROCEDURE
WRITE DATA="Cube of 2 is: "CUBE()
cube: FUNCTION
RETURN(2**3)
END cube
END userw1
Follow the steps described earlier in this section to create, test compile, correct, and
execute USERW1. When executed, this NCL procedure displays the following
message in the OCS message display area:
Cube of 2 is: 8
Features of USERW1 Here are some of the features of the USERW1 NCL procedure.
The Function Call—CUBE()
CUBE() calls the user-written function CUBE. It does not pass any parameters to
CUBE because the parameter list is empty. Even though the parameter list is empty,
you must follow the name of the function by parentheses (( )).