View previous topic :: View next topic |
Author |
Message |
harisubs Beginner
Joined: 03 Aug 2007 Posts: 8 Topics: 2
|
Posted: Thu Sep 13, 2007 7:14 am Post subject: convert Numeric edited field to numeric |
|
|
Hi
I have a numeric edited field in X(10) field.
(It is alphanumeric as it comes from an online screen.)
I need to de-edit the field into numeric field.
For example, consider the following data
01 WS-AMOUNT-EDITED PIC X(14)
01 WS-AMOUNT-NUM PIC 9(10)
If WS-AMOUNT-EDITED has the value 12,34,567.99 then I need to convert this into 0123456799 (that is the ',' or '.' have to be removed and missing digits should be replaced with 0).
For example, if
WS-AMOUNT-EDITED = 1,23,45,678.99 then
WS-AMOUNT-NUM = 1234567899
if WS-AMOUNT-EDITED = 1,234.99 then
WS-AMOUNT-NUM = 0000123499
Is this possible by defining variables of numeric or editedjust 'MOVE' statements with having to inspect each character of WS-AMOUNT-EDITED and moving it to a numeric variable?
I tried moving the X(14) to a Numeric-edited variable, but it gave a S0C7.
Moving X(14) to 9(10) variable directly also did not produce the desired result.
Thanks & Regards
harisubs |
|
Back to top |
|
 |
harisubs Beginner
Joined: 03 Aug 2007 Posts: 8 Topics: 2
|
Posted: Thu Sep 13, 2007 7:23 am Post subject: |
|
|
Hi
There is a typo in my post.
The first line "I have a numeric edited field in X(10) field. "
should be read as "I have a numeric edited field in X(14) field. "
Thanks
harisubs |
|
Back to top |
|
 |
CICS Guy Intermediate
Joined: 30 Apr 2007 Posts: 292 Topics: 3
|
Posted: Thu Sep 13, 2007 7:30 am Post subject: |
|
|
Have you tried NUMVAL?
Have you looked into a perform loop and single byte check and move (via FM) from the rear forward? |
|
Back to top |
|
 |
CICS Guy Intermediate
Joined: 30 Apr 2007 Posts: 292 Topics: 3
|
Posted: Thu Sep 13, 2007 7:43 am Post subject: |
|
|
E x(14) value '12,34,567.99'
N 9(10)
I comp
J comp
move length of E ro I
move length of N to J
perform varying I by -1 until I = zero
if E(I:1) numeric
move E(I:1) to N(J:1)
subtract 1 from J
end-if
end-perform
move zeros to N(1:J) |
|
Back to top |
|
 |
harisubs Beginner
Joined: 03 Aug 2007 Posts: 8 Topics: 2
|
Posted: Thu Sep 13, 2007 7:54 am Post subject: |
|
|
Hi CICS Guy,
Thank you for the quick response.
NUMVAL is not available in our shop.
I was looking if there is a way using the Move statements without having to inspect every character of the X(14) variable. The other option was to inspect each character a solution similar to the one which you have posted.
I had another typo in the intial post. Sorry for that
"'MOVE' statements with having to inspect each character " should have been
"'MOVE' statements with OUT having to inspect each character "
Thanks
Srihari |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Thu Sep 13, 2007 7:57 am Post subject: |
|
|
harisubs,
Try this untested code
Code: |
01 WS-AMOUNT-EDITED PIC X(14) VALUE '1,23,45,678.99'.
01 WS-AMOUNT-NUM PIC 9(10).
01 WS-TALLY PIC S9(04) COMP.
01 WS-ISUB PIC S9(04) COMP.
01 WS-OSUB PIC S9(04) COMP.
INSPECT WS-AMOUNT-EDITED TALLYING WS-TALLY
FOR ALL ',' '.' ' '
COMPUTE WS-OSUB = 10 - (14 - WS-TALLY) + 1
MOVE ZEROES TO WS-AMOUNT-NUM
PERFORM VARYING WS-ISUB FROM 1 BY 1
UNTIL WS-ISUB > 14
IF WS-AMOUNT-EDITED (WS-ISUB : 1) = ','
OR WS-AMOUNT-EDITED (WS-ISUB : 1) = '.'
OR WS-AMOUNT-EDITED (WS-ISUB : 1) = ' '
CONTINUE
ELSE
MOVE WS-AMOUNT-EDITED(WS-ISUB : 1) TO
WS-AMOUNT-NUM (WS-OSUB : 1)
ADD +1 TO WS-OSUB
END-IF
END-PERFORM
|
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
|
|