Trailing space/s entered are not recognized in the EXAMINE statement

I am having problem in getting the actual length size including the trailing space/s entered.
example: '-

Already considered using EXAMINE/GIVING statement and with the above example the result is 2.

  1. EXAMINE #SEARCH-VAL for ‘ ‘ GIVING LENGTH #LENGTH

  2. I also considered the hexadecimal value of space, same result
    EXAMINE #SEARCH-VAL FOR H’40’ REPLACE ‘*’ GIVING LENGTH #LENGTH

I need the actual lenght size entered by the user including trailing space/s to have a reference/ starting point on the next step to pad all trailing spaces (not entered by the user) with ‘%’ for the SQL statement.

Please advise. Thanks.

I don’t see how you can tell the difference between the default space value for the field and what’s been entered. You could try initialising the whole input field to H’6D’ then examine field for the first occurrence of this value after the user has entered their search value.

Here is the code:

DEFINE DATA LOCAL
1 #STRING (A30)
1 #POS (N2)
END-DEFINE
*
MOVE ALL H’6D’ TO #STRING
INPUT ‘ENTER #STRING HERE==>’ #STRING (AD=M)
EXAMINE FULL #STRING FOR H’6D’ GIVING POSITION #POS
WRITE ‘=’ #POS
END

You want position, not length which would be 30 for my code above.

NOTE: this will not work on PC Natural, which nulls out an AD=M field when anything is entered in the field