Page 1 of 1

Unstring query

PostPosted: Mon Jun 30, 2014 7:24 pm
by Ewizard
Variables are:
05 C-DECIMAL-POINT PIC X(01) VALUE ".".
10 WS-SCHD-PREM-AMT-CHAR PIC X(13).
10 WS-SCHD-INT PIC 9(10).
10 WS-SCHD-DEC PIC 9(2).

At execution:
WS-SCHD-PREM-AMT-CHAR = '247212.12'

UNSTRING WS-SCHD-PREM-AMT-CHAR(A-PROCESS-SCHD-CNT)
DELIMITED BY C-DECIMAL-POINT
INTO WS-SCHD-INT,
WS-SCHD-DEC
END-UNSTRING

Result:
WS-SCHD-INT = 0000247212
WS-SCHD-DEC = ???

Why does the UNSTRING statement not give a result for WS-SCHD-DEC = 12?
Where WS-SCHD-PREM-AMT-CHAR(A-PROCESS-SCHD-CNT) = '247212.12', C-DECIMAL-POINT = "." WS-SCHD-INT PIC 9(10).

Re: Unstring query

PostPosted: Mon Jun 30, 2014 8:10 pm
by Robert Sample
In order to unstring the second field into the variable, where is the second decimal point you needed to delimit that second field?

Re: Unstring query

PostPosted: Mon Jun 30, 2014 8:17 pm
by Ewizard
Are you suggesting that my input value needs to be ''247212.12.', i.e. a second decimal point is required at the end of the string?

Re: Unstring query

PostPosted: Mon Jun 30, 2014 8:17 pm
by BillyBoyo
Because 12 is followed by three blanks (or three other values that you are not interested in), numeric fields are right-aligned, so you get the final two blanks (or other values) in your WS-SCHED-DEC.

If you always have two decimal places, the easiest thing to do is to change it to PIC XX, which will left-align. If you can have one, or zero, decimal places occupied, so will need to set the PIC XX field to space before the UNSTRING (consult the manual for why) and then change the one or two blanks to zero by your site's preferred method.

If you delimit also by space, you will have a hard time with it. If you always have two decimal places and you know the value which delimits the decimal places (space?) then you'd be OK with specifying two delimiters.

Re: Unstring query

PostPosted: Mon Jun 30, 2014 8:23 pm
by Ewizard
Of course. Oh I am an idiot!

Thanks!