Line 1: Code will be fully free.
Line 2: To be able to use /charcount compile directive it is mandatory to type charcounttypes control specification to specify the types of data that are processed by characters rather than by bytes or double bytes when CHARCOUNT NATURAL.
Line 4: Variable to store a string value.
Line 5: Variable to store the position of the character searched with %scan.
Line 6: Variable to store the first name of var1.
Line 7: Variable to store the middle name of var1.
Line 9: var1 contains a string with some double byte characters. In this case the Spanish name José Luís.
Line 11: Using the compiler directive /charcount natural we are specifying that the count of the characters must be done for natural characters.
Line 12: Sends a message to the job log and to the last line of the screen showing that the charcount is NATURAL.
Line 13: Obtain the position of the blank character to be used in the %subst built-in function. As ccsid of var 1 is utf8 %ucs2 built-in function is used.
Line 14: Sends a message to the job log and to the last line of the screen with a message showing the value of the pos variable.
Line 15: Sends a message to the job log and to the last line of the screen with a message showing the value of the length in bytes of var1.
Line 16: Obtains the first name using the position of the blank character.
Line 17: Sends a message to the job log and to the last line of the screen with a message showing the value of firstName variable.
Line 18: Obtains the middle name using the position of the blank character.
Line 19: Sends a message to the job log and to the last line of the screen with a message showing the value of middleName variable.
Line 21: Using the compiler directive /charcount stdcharsize we are specifying that the count of the characters must be done for its length in bytes.
Line 22: Sends a message to the job log and to the last line of the screen showing that the charcount is STDCHARSIZE.
Lines 23-29: It is exactly the same code as above but for CHARCOUNT(*STDCHARSIZE)