SENTENCE Function
Returns the command line used to execute the current program.
Syntax
SENTENCE({element})
Syntax Elements
element An integer that specifies a syntax element in the command. 0 specifies the command name.
If element is omitted, SENTENCE returns the complete command line (including options).
It is recommended that you always specify an element (see examples below).
Return Value
-
If an element is specified, single or double quotes enclosing the element are removed.
If there is no syntax element in the specified position, SENTENCE returns a null string.
-
If element is omitted, any parameters enclosed in single or double quotes are returned unchanged (quotes are not removed).
-
If you specify the options element, SENTENCE returns a null string. To obtain this information, use either SYSTEM(15) or SENTENCE without an element number.
Comments
You can run a DataBasic program in two ways: directly via a command definition item in the account's MD (created when you catalog the program), or indirectly using RUN or DEBUG. In the first case, the program name is element 0, whereas in the second, it is element 2. You can use SYSTEM(20) to find out which method is being used (see Example 4).
Example 1
Item TEST1 in file BP contains:
A = 40 B = 30 C = A+B PRINT "The result of ":SENTENCE():"is ":C PRINT "The command was ":SENTENCE(0) PRINT "The first parameter was ":SENTENCE(1) PRINT "The second parameter was ":SENTENCE(2) PRINT "The third parameter was ":SENTENCE(3)
When run as follows:
RUN BP TEST1
this program prints:
The result of RUN BP TEST1 is 70
The command was RUN
The first parameter was BP
The second parameter was TEST1
The third parameter was
Example 2
Item TEST2 in file BP contains:
PARAM = "" I = 0 LOOP PARAM = SENTENCE(I) UNTIL PARAM = "" DO PRINT "SENTENCE(":I:") = ":PARAM I += 1 REPEAT
Then entering:
RUN BP TEST2 "myparam"
displays:
SENTENCE(0) = RUN
SENTENCE(1) = BP
SENTENCE(2) = TEST2
SENTENCE(3) = myparam
Example 3
This example shows the differences between SENTENCE used with and without a parameter, SYSTEM(60) and User Exit U20E0 (now obsolescent).
Item SENTENCE in BP file contains:
PRINT "U20EO = ":ICONV('','U20E0') PRINT PRINT "SYSTEM(60) = ":SYSTEM(60) PRINT PRINT "SENTENCE = ":SENTENCE() PRINT PRINT "SENTENCE(0) = ":SENTENCE(0) PRINT "SENTENCE(1) = ":SENTENCE(1) PRINT "SENTENCE(2) = ":SENTENCE(2) PRINT "SENTENCE(3) = ":SENTENCE(3) PRINT "SENTENCE(4) = ":SENTENCE(4) PRINT
This program has been compiled and cataloged. Then, running:
SENTENCE PARAM1 'PARAM 2' "PARAM 3" (AB
results in the following:
U20EO = PARAM1^ SYSTEM(60) = PARAM1^PARAM 2^PARAM 3^ SENTENCE = SENTENCE PARAM1 'PARAM 2' "PARAM 3" (AB SENTENCE(0) = SENTENCE SENTENCE(1) = PARAM1 SENTENCE(2) = PARAM 2 SENTENCE(3) = PARAM 3 SENTENCE(4) =
Similarly, running:
SENTENCE 1 2 3 4 (CD
displays:
U20EO = 1^2^3^4 SYSTEM(60) = 1^2^3^4 SENTENCE = SENTENCE 1 2 3 4 (CD SENTENCE(0) = SENTENCE SENTENCE(1) = 1 SENTENCE(2) = 2 SENTENCE(3) = 3 SENTENCE(4) = 4
Example 4
Item TEST2 in file BP contains:
PARAM = "" IF SYSTEM(20) THEN I = 0 ELSE I = 2 LOOP PARAM = SENTENCE(I) UNTIL PARAM = "" DO PRINT "SENTENCE(":I:") = ":PARAM I += 1 REPEAT
This program has been compiled and cataloged. Then, running:
TEST2 "myparam"
displays:
SENTENCE(0) = TEST2
SENTENCE(1) = myparam
whereas running:
RUN BP TEST2 "myparam"
displays:
SENTENCE(2) = TEST2
SENTENCE(3) = myparam
See Also
SYSTEM(60). This returns a dynamic array containing the parameters supplied to the last TCL command.
SYSTEM(15). This returns the options specified as part of the last TCL statement.
SYSTEM(20). This returns whether the program was run using a command definition item created when it was cataloged, or with the RUN or DEBUG command.
TCLREAD statement (D3 compatibility mode).