%TRIM

Return the length of a variable without trailing blanks

WSupported on Windows
USupported on Unix
VSupported on OpenVMS
NSupported in Synergy .NET
length = %TRIM(variable)

or

xcall TRIM(variable, length)

Return value

length

The length of variable minus the number of trailing blanks. If the variable is blank, %TRIM returns a value of one. If the variable is null, %TRIM returns a value of zero. In other words, the statement

%trim(" ")

returns a value of one, while the statement

%trim("")

returns a value of zero. (i)

Arguments

variable

A variable whose length will be returned. (a)

Discussion

%TRIM returns the length of a variable minus the number of trailing blanks.

The difference between %TRIM and %TRIMZ is that with blank strings, %TRIM returns a value of one, and %TRIMZ returns a value of zero.

Examples

The following subroutine displays a prompt, gets the input, and returns the length of the actual data that was input. If no data is input, the return length is one.

subroutine input 
    a_data      ,a 
    a_prompt    ,a 
    a_len       ,d 

proc 
    display(TTCHN, a_prompt, ": ") 
    reads(TTCHN, a_data, done) 
    a_len = %trim(a_data)
done,
    xreturn 
endsubroutine

The example below checks for valid input.

subroutine chk_inp
    a_valid             ,a
    a_status            ,d
.define TTCHN           ,1 
record
    input               ,a60
    len                 ,d2
proc
    reads(TTCHN, input)
    xcall trim(input, len)
    reads(TTCHN, input)
    xcall trim(input, len)
    if ((len.eq.1) .and. (input.ne.' ') .and. 
  &     (input(1:len) .eq. a_valid)) then
      a_status = %true
    else
      a_status = %false
    xreturn
endsubroutine