Unstring query



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Unstring query

Postby Ewizard » Mon Jun 30, 2014 7:24 pm

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).
Ewizard
 
Posts: 10
Joined: Fri Jan 29, 2010 9:41 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Unstring query

Postby Robert Sample » Mon Jun 30, 2014 8:10 pm

In order to unstring the second field into the variable, where is the second decimal point you needed to delimit that second field?
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Unstring query

Postby Ewizard » Mon Jun 30, 2014 8:17 pm

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?
Ewizard
 
Posts: 10
Joined: Fri Jan 29, 2010 9:41 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Unstring query

Postby BillyBoyo » Mon Jun 30, 2014 8:17 pm

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.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Unstring query

Postby Ewizard » Mon Jun 30, 2014 8:23 pm

Of course. Oh I am an idiot!

Thanks!
Ewizard
 
Posts: 10
Joined: Fri Jan 29, 2010 9:41 pm
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post