Example: orders.4gl (Function order_move)

This function moves in the ordnums array to browse the list of orders fetched by the last query.

Function order_move (orders.4gl):
  1 PRIVATE FUNCTION order_move(dir SMALLINT) RETURNS ()
  2   MESSAGE ""
  3   IF NOT order_fetch(dir) THEN
  4      IF dir == move_next THEN MESSAGE msg05 END IF
  5      IF dir == move_prev THEN MESSAGE msg06 END IF
  6   ELSE
  7      MESSAGE SFMT(msg21,orders_index,ordnums.getLength())
  8   END IF
  9 END FUNCTION
Note:
  • Line 1 defines the function with the direction as parameter. The function returns no value.
  • Line 3 calls the order_fetch function, which is doing the real move in the order list and fetches data from the database. The result value of the function is tested with an IF statement.
  • Lines 4 and 5 are executed when the order_fetch function returns FALSE, indicating that we could not move in the requested direction. According to the direction, we display the appropriate message to the user.
  • Line 7: If the order position could be moved, we display a message to the user indicating the current position in the list of orders.