Some RDML commands require that associated parameters appear as "quoted strings" because LANSA uses the IBM i operating system command definition and prompting facilities.
Command parameter with imbedded blanks
For example, to increment field #COUNT by 1 the correct format is:
CHANGE FIELD(#COUNT) TO('#COUNT + 1')
or CHANGE #COUNT '#COUNT + 1'
or CHANGE #COUNT ('#COUNT + 1')
or CHANGE #COUNT '(#COUNT + 1)'
but NOT CHANGE #COUNT (#COUNT + 1)
This is because the IBM i command facilities demand that a command parameter be enclosed in quotes if it contains imbedded blanks. In this case the string "#COUNT + 1" definitely contains imbedded blanks and thus must be enclosed in quotes (ie: made into a "quoted" string).
Quotes within a quotes string
When LANSA processes the command only the part between the quotes (but not the quotes themselves) are passed to LANSA by the operating system.
The matter is complicated even further if you wish to use quotes within a "quoted" string. This situation usually arises when coding IF or CASE conditions.
The rule for using quotes inside a quoted string is: use 2 quotes instead of just one.
For instance, to check if #FIELD contains a lowercase "a" you would have to code:
IF '#FIELD = ''a'''
What is passed to LANSA by the IBM i command processor as the expression associated with the IF command is actually:
#FIELD = 'a'
because the operating system does not pass the outer quotes and replaces occurrences of 2 quotes within the string with just one quote.
Simple guidelines for quotes
However, the handling of quotes within LANSA can be made much easier by following 2 simple guidelines:
1. Only use quotes inside a quoted string when absolutely necessary.
2. Use the formatted prompting facilities to input complex quoted strings.
With regard to point 1, LANSA does not require that alphanumeric literals be quoted. Thus the following are identical conditions because alphanumeric literals that are not enclosed in quotes are converted to uppercase:
IF '#FIELD = A'
IF '#FIELD = a'
IF '#FIELD = ''A'''
Only use quotes around alphanumeric literals if the test involves lowercase characters. For instance to test for a lowercase "a" in #FIELD:
IF '#FIELD = ''a'''
With further regard to point 2, you will find that the formatted prompting facility will automatically insert the required outer quotes. For instance if you prompt an IF command and enter the condition as:
#FIELD = A
then the prompter will automatically re-format the condition so that it is a valid "quoted" string.
The final version of the command created by the prompter would look like this:
IF COND('#FIELD = A')
The same applies when it is necessary to use quotes within the expression. For instance if you specify to the prompter the following condition:
#FIELD = 'a'
then it will re-format the command automatically and insert the necessary inner and outer quote symbols. The command created by the prompter would look like this:
IF COND('#FIELD = ''a''')
Quoted strings as parameter values
On the RDML CALL command, care should be taken if using quoted strings as parameter values. A quoted string has to be enclosed in triple quotes. For example, to use 'ABC' as the parameter value, enter '''ABC'''.
When the function containing the CALL is compiled the RPG generator uses the length of the string, including the single quotes, to create the parameter fields. For example if program A has two alpha parameters both 5 characters long and a call is inserted in function B as:
CALL PGM(A) PARM('ABC' '''ABC''')
The generator will create a 3 character parameter (ABC) and a 5 character parameter ('ABC') for the call. When function B is executed program A may end in error because the 4th and 5th characters of the first parameter within program A will contain garbage.
Triple quotes with first character that looks like a number
For information, please refer to the Change command's Comments and Warnings.