Previous Topic: &SELSTR

Next Topic: &STR


&SETLENG

The &SETLENG built-in function is used to assign data of a specific length to a target variable. If the original data is longer than the specified length, it is truncated. If the original data is shorter than the specified length, the data is padded with blanks before assignment takes place. If &SETLENG truncates DBCS data, the shift in character could be removed, causing an incomplete DBCS string to be produced. This could lead to syntax errors in later processing or undisplayable data being presented on the screen. With an &CONTROL DBCS, DBCSN, or DBCSP option in effect, a shift in is added to the end of the data if required.

When shift characters do not occupy a screen position, formatting tabular displays, such as selection lists, becomes difficult. This is because the columns of data are misaligned, due to the difference in the displayable length of the data and the length of the data contained in an NCL variable. With &CONTROL DBCSN or DBCSP in effect, &SETLENG overcomes this problem. It adjusts the length of data assigned to the target variable to ensure that if the shift characters are present and they do not occupy a position on the screen. The displayable length of the data will always be exactly the same as the length specified on the &SETLENG statement.

Examples: &SETLENG

&CONTROL NODBCS 
&A = &STR <.A.B.C.D> 
&A = &SETLENG 6

results in

&A = <.A.B.

No special consideration is given to the DBCS string.

&A = &STR  <.A.B.C.D>
&CONTROL DBCS
&A = &SETLENG 6

results in

&A = <.A.B>

Note: A shift in has been added to the end of the data. The length of the resultant data is 6.

&A = &STR <.A.B.C.D>
&CONTROL DBCSN
&A = &SETLENG 6

results in

&A = <.A.B.C>

Note: A shift in has been added to the end of the data. The length of the resultant data is 6. The shift characters are not counted in the final data length.

&A = &STR <.A.B> 
&CONTROL DBCS 
&A = &SETLENG 8

results in

&A = <.A.B>__

The length of the resultant data is 8. Two blanks have been added to the end of the data to ensure the resultant length is correct.

&A = &STR <.A.B.C.D> 
&CONTROL DBCSN 
&A = &SETLENG 8

results in

&A = <.A.B>____

The length of the resultant data is 8. The shift characters are not counted in the final data length. Four blanks have been added to the end of the resultant data to ensure that the resultant length is correct.

&A = &STR <.A.B> 
&CONTROL DBCSP 
&A = &SETLENG 8

results in

&A = <.A.B>__

if the terminal is an IBM DBCS terminal, or results in

&A = <.A.B>_____

if the terminal is a Fujitsu or Hitachi DBCS terminal.

The displayable length of the resultant data is 8 in both cases. Blanks have been added to the end of the resultant data in both cases to ensure that the resultant length is correct.

&COL1 = &STR data .... 
&COL2 = &STR data .... 
&COL3 = &STR data .... 
&CONTROL DBCSP 
&COL1 = &SETLENG 20 
&COL2 = &SETLENG 40 
&COL3 = &SETLENG 10 
&CONTROL NODBCS 
&LINE1 = &CONCAT  &COL1 &COL2 &COL3

This example is creating a variable called &LINE1, which is part of a tabular display in which the first column starts at column 1, the second starts at column 21, and the third starts at column 61. Regardless of the contents of the data, and regardless of the terminal on which the data will be displayed, the columns will always be at the correct offset. This is because &SETLENG always ensures that the displayable length of the data is exactly as requested.