arg_val()

Returns a command line argument by position.

Syntax

arg_val(
   position INTEGER )
  RETURNING result STRING
  1. position is an integer defining the argument position.
  2. result is a string containing the program argument.

Usage

This function provides a mechanism for passing values to the program through the command line that invokes the program. You can design a program to expect or allow arguments after the name of the program in the command line.

The position parameter defines the argument to be returned. 0 returns the name of the program, 1 returns the first argument.

Like all built-in functions, arg_val() can be invoked from any program block. You can use it to pass values to MAIN, which cannot have formal arguments, but you are not restricted to calling arg_val() from the MAIN statement.

Use the arg_val() function to retrieve individual arguments during program execution. Use the num_args() function to determine how many arguments follow the program name on the command line.

If position is greater than 0, arg_val(position) returns the command-line argument used at a given position. The value of position must be between 0 and the value returned by num_args(), the number of command-line arguments. The expression arg_val(0) returns the name of the application program.

If the argument position is negative or greater than num_args(), the method returns NULL.