If your configuration uses a DBCS code page, you can use the DSUBSTR function to extract a substring based on its length and position in the source string.
DSUBSTR(inlength, source_string, start, end, sublength, output)
Is the length of the source string in bytes, or a field that contains the length. The string can have a mixture of DBCS and SBCS characters. Therefore, the number of bytes represents the maximum number of characters possible in the source string.
Is the string from which the substring will be extracted enclosed in single quotation marks ('), or the field containing the parent string.
Is the starting position (in number of characters) of the substring in the source string. If this argument is less than one or greater than end, the function returns spaces.
Is the ending position (in number of characters) of the substring. If this argument is less than start or greater than inlength, the function returns spaces.
Is the length of the substring, in characters (normally end - start + 1). If sublength is longer than end - start +1, the substring is padded with trailing spaces. If it is shorter, the substring is truncated. This value should be the declared length of output. Only sublength characters will be processed.
Is the field to which the result is returned, or the format of the output value enclosed in single quotation marks (').
The following example extracts the 3-character substring in positions 4 through 6 from a 15-byte string of characters: