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.