Use built-In ABL functions
- Last Updated: January 16, 2024
- 4 minute read
- OpenEdge
- Version 12.8
- Documentation
To complete this latest change to the procedure, you need to define the
statement that checks whether the ShipDate is Unknown, and then picks out the
month from the date, using the cMonthList variable you defined just above,
and converts it to one of the three-letter abbreviations in the list. Here is the whole
statement:
|
Now take a closer look at the elements in the DISPLAY statement.
First there is a new keyword, ENTRY. This is the
name of a built-in function in ABL. There are many such functions
to do useful jobs for you, to save you the work of writing the code
to do it yourself. The ENTRY function takes two
arguments, and as you can see, those arguments are enclosed in parentheses.
The first is an INTEGER value, which identifies
an entry in a comma-separated list of character values. In this
case it represents the month of the year, from 1 to 12. The second
argument is the list that contains the entry the function is retrieving.
In this case it is the variable you just defined.
Looking closer, you can see that the first of the two arguments to the
function, MONTH(ShipDate), is itself another function. This
function takes an ABL DATE value as an argument, extracts the
month number of the date, and returns it. The returned value is an INTEGER from 1 to 12 that the ENTRY function then
uses to pick out the right entry from the list of months in cMonthList. So if
the month is May, the MONTH function returns 5 and the
ENTRY function picks out the fifth entry from the list of
months and returns it to the DISPLAY statement.
Here are some general observations about built-in functions:
- A function takes a variable number of arguments, depending on what the
function requires. Some functions take no arguments at all (for example, the
TODAYfunction, which returns today's date). Some functions have a variable number of arguments, so that one or more arguments at the end of the argument list are optional. For example, theENTRYfunction can have an optional third argument, which is a character string representing a delimiter to use between the values in the list, if you don't want it to use a comma (,). Because the comma is the default delimiter, it is optional. You cannot leave out arguments from the middle of the list, or specify them in a different order. Each of the arguments must be of the proper data type, depending on what the function expects. - The arguments to a function can be constant values, variable names, database field names, or any expression involving these which evaluates to a value of the proper data type.
- Each function returns a value of a specific data type.
- You can nest functions to any depth in your code. The result of any function is returned up to the next level in the code.
- You can place functions anywhere within a statement where a value can
appear. Because a function returns a value, it can appear only on the
right-side of an assignment statement. You cannot use the
MONTHfunction to assign the month value to a date variable, for example, or theENTRYfunction to assign the value of an entry in a list. There are ABL statement keywords in some cases to do those kinds of assignments. - If you are displaying the result of a function or an expression involving
a function, you can specify a
LABELorFORMATfor it, just as you can for a variable. The defaultLABELfor an expression is a text string representing the expression itself. The default format is the default for the function's data type. In this example you should add the labelMonthto the expression.
To display the month along with each Order:
- Add the new statement with the function references into your procedure,
inside the block of code that loops through the
Orders:DEFINE VARIABLE cMonthList AS CHARACTER NO-UNDO INITIAL "JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC". FOR EACH Customer NO-LOCK WHERE Customer.State = "NH" BY Customer.City: DISPLAY Customer.CustNum Customer.Name Customer.City. FOR EACH Order OF Customer NO-LOCK: DISPLAY Order.OrderNum LABEL "Order" Order.OrderDate Order.ShipDate FORMAT "99/99/99" WITH CENTERED. IF Order.ShipDate NE ? THEN DISPLAY ENTRY(MONTH(Order.ShipDate), cMonthList) LABEL "Month". END. END. - To see the effect of the new code, rerun the procedure:
Note: Several separate ABLDISPLAYstatements contribute to the display of fields in a single line for eachOrder. This is one of the powerful and flexible characteristics of ABL. ABL can gather together a number of different statements in a procedure, some of which might be executed conditionally, and combine them together into a single operation such as this. This feature is generally not possible with other programming languages. - To save your procedure, press F6.