Method Implementation
...which creates a new LogicalToDisplay method in the Studio Editor.
ClassMethod LogicalToDisplay(%val As %Integer) As %String
[ CodeMode = generator, ServerOnly = 0 ]
{
}
We can now use the Studio editor to enter the code for our method.
Here's the code we use to convert our duration to a display format:
Quit (%val \ 60) _ "h" _ (%val # 60) _ "m"
The backslash ( \ ) operator performs integer division, giving us the number of hours. The hash ( # ) operator calculates a modulo or remainder, in this case the number of minutes in the "fractional" hour. The underscore ( _ ) operator concatenates (joins) two values. And, finally, the Quit command exits the method, returning the generated string to whoever called it. Note that you must place some whitespace before the Quit command or Caché will interpret it as a label instead of a command. If you do make a syntax error, the Studio editor will highlight the incorrect syntax with a wavy red underscore.
There is no need to explicitly convert numbers (e.g., %val \ 60) to strings before concatenation. Caché does this automatically. (In object terms, the language is polymorphic.)
We've just done our first programming using the ObjectScript language. If you are unfamiliar with ObjectScript, we have included a quick introduction.