Assignments involving C NUL-terminated strings
A C NUL-terminated string variable that is referenced in a CONNECT statement does not need to contain a NUL. Otherwise, DB2® enforces the convention that the value of a NUL-terminated string variable, either character or graphic, is NUL-terminated.
An input variable that does not contain a NUL will cause an error. A value that is assigned to an output variable will always be NUL-terminated even if a character must be truncated to make room for the NUL.
When a string of length n is assigned to a C NUL-terminated string variable with a length greater than n+1, the rules depend on whether the source string is a value of a fixed-length string or a varying-length string:
- If the source is a fixed-length string and the value of field PAD NUL-TERMINATED on installation panel DSNTIP4 is YES, the string is padded on the right with x-n-1 blanks, where x is the length of the variable. The padded string is then assigned to the variable and a NUL is appended at the end of the variable. If the value of field PAD NUL-TERMINATED is NO, the string is assigned to the first n bytes of the variable and a NUL is appended at the end of the variable.
- If the source is a varying-length string, the string is assigned to the first n bytes of the variable and a NUL is appended at the end of the variable.