View previous topic :: View next topic |
Author |
Message |
hisabarinath Beginner
Joined: 25 Apr 2008 Posts: 36 Topics: 8 Location: Baltimore, USA
|
Posted: Wed Mar 25, 2009 9:53 am Post subject: Replace spaces instead of zeros thru COBOL Program |
|
|
I have searched but couldnt find the earlier post.
Thru COBOL Program, i want to replace prefix with zeros instead of spaces. My requirement is i have a price field of X(6).X(5) - this field should convert to 9(11)V9(5).
for eg-
Code: | ----+----1----+----2----+----3----+----4----+--
PRICE FIELD - CONVERT THE PRICE FIELD TO
123456.12345 - 00000123456.12345
45.88888 - 00000000045.88888
999.00000 - 00000000999.00000
.88000 - 00000000000.88000
5.00001 - 00000000005.00001 |
More information-
The decimal part X(5) always be fixed and there is NO space allowed, and the period also fixed in the 7th postion of the given price field. I have tried thru redefines and all string handling but unable to get the desired result.
It seems simple, but unable to handle, if some one have posted earlier, please share me the link. Thanks for your help. |
|
Back to top |
|
|
hisabarinath Beginner
Joined: 25 Apr 2008 Posts: 36 Topics: 8 Location: Baltimore, USA
|
Posted: Wed Mar 25, 2009 9:56 am Post subject: |
|
|
Sorry the convert field should be Assumed decimal NOT fixed decimal.
The updated eg -
Code: | ----+----1----+----2----+----3----+----4----+----5----+----6-
PRICE FIELD - CONVERT THE PRICE FIELD TO
123456.12345 - 0000012345612345
45.88888 - 0000000004588888
999.00000 - 0000000099900000
.88000 - 0000000000088000
5.00001 - 0000000000500001 | [/code] |
|
Back to top |
|
|
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Wed Mar 25, 2009 10:37 am Post subject: |
|
|
what have you tried so far? provide us a sample of this code and then we can help. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Wed Mar 25, 2009 11:10 am Post subject: |
|
|
hisabarinath,
Is this a trick question? I did not test but a simple numval would give you the desired results?
Code: |
01 WS-PRICE PIC X(12).
01 WS-NUM PIC 9(11)V9(5).
COMPUTE WS-NUM = FUNCTION NUMVAL(WS-PRICE)
|
|
|
Back to top |
|
|
hisabarinath Beginner
Joined: 25 Apr 2008 Posts: 36 Topics: 8 Location: Baltimore, USA
|
Posted: Wed Mar 25, 2009 11:24 am Post subject: |
|
|
dbzTHEdinosauer,
I have tried to find howmany spaces prefix with the Integer part of the X(6) then replace those spaces with 0 by moving 0 to the integer part thru reference modification.
Code: | PERFORM VARYING WH-INT-I FROM 1 BY 1
UNTIL WH-INT-I > LENGTH OF WH-PRC-UNLD-INT-9
IF (WH-PRC-UNLD-INT-9 (1:WH-INT-I) = SPACES)
MOVE 0 TO WA-PRC-UNLD-INT (1:WH-INT-I)
ELSE
MOVE WH-PRC-UNLD-INT-9 (1:WH-INT-I)
TO WA-PRC-UNLD-INT (1:WH-INT-I)
END-IF
END-PERFORM |
Here the field declarations are
Code: | 10 WH-PRC-UNLD-INT-9 PIC 9(06).
05 WA-PRC-UNLD-INT PIC 9(6). |
After getting X(6) to 9(6) with zeros then i will do a string concatenation of
Code: | STRING '000000'
WA-PRC-UNLD-INT
WH-PRC-UNLD-DEC-9 DELIMITED BY SIZE
INTO <Target 9(11)V9(5) Field> |
|
|
Back to top |
|
|
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Wed Mar 25, 2009 11:48 am Post subject: |
|
|
I appreciate you posting your code, but you should see kolusu's answer - which is a solution........ _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
|
hisabarinath Beginner
Joined: 25 Apr 2008 Posts: 36 Topics: 8 Location: Baltimore, USA
|
Posted: Wed Mar 25, 2009 12:03 pm Post subject: |
|
|
Thanks Kolus,
I'm testing your suggestion but getting ABEND. Since, i have declared the field to
Code: | 10 WH-PRC-UNLD-INT-9 PIC X(06) |
I have found the below error message information
IGZ0097S Argument-1 for function NUMVAL in program PDMR6523 at displacement X'1044' contained no digits.
Since, my Input fileds are
Code: | .00000
.00000
56.00000
1234.00000
.00000
.00000
556.67000 |
|
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Wed Mar 25, 2009 12:14 pm Post subject: |
|
|
hisabarinath,
*Sigh* In your first post you said it is PIC X(6).X(5) and now why are using only 6 bytes? . Also NUM val assumes that you have atleast 1 number in the input.
if you have all spaces then check for it and issue . Define the whole field as 12 bytes and just use that field in numval
Code: |
IF WH-PRC-UNLD-INT-9 > ' '
COMPUTE WS-NUM = FUNCTION NUMVAL(WH-PRC-UNLD-INT-9)
ELSE
MOVE ZERO TO WS-NUM
END-IF
|
|
|
Back to top |
|
|
hisabarinath Beginner
Joined: 25 Apr 2008 Posts: 36 Topics: 8 Location: Baltimore, USA
|
Posted: Wed Mar 25, 2009 1:28 pm Post subject: |
|
|
Pefect kolusu.. You are the real Hero in the FORUMs |
|
Back to top |
|
|
Dibakar Advanced
Joined: 02 Dec 2002 Posts: 700 Topics: 63 Location: USA
|
Posted: Fri Mar 27, 2009 5:49 pm Post subject: |
|
|
Quote: | Code: | PERFORM VARYING WH-INT-I FROM 1 BY 1
UNTIL WH-INT-I > LENGTH OF WH-PRC-UNLD-INT-9
IF (WH-PRC-UNLD-INT-9 (1:WH-INT-I) = SPACES)
MOVE 0 TO WA-PRC-UNLD-INT (1:WH-INT-I)
ELSE
MOVE WH-PRC-UNLD-INT-9 (1:WH-INT-I)
TO WA-PRC-UNLD-INT (1:WH-INT-I)
END-IF
END-PERFORM | |
you had wrong arguments for substring, should have been 'WH-INT-I:1' instead of '1:WH-INT-I'.
Diba. |
|
Back to top |
|
|
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Mon Apr 06, 2009 8:12 pm Post subject: |
|
|
A little late, but here goes:
Define your I/P field as Z(?).9(?) you pick your own ?s
Define your O/P field as 9(?)V9(?). Use the same ?s as above.
In the IF stmt use: MOVE I/P TO O/P ELSE etc.
If you can't change the I/P PIC, define an intermediate work fld as PIC Xs then redefine it as Z(?).9(?). Use 2 MOVEs - I/P to WRK (PIC X), WRK(PIC Z) to O/P.
Even w/the 2 moves you'll get better efficiency. _________________ Regards, Jack.
"A problem well stated is a problem half solved" -- Charles F. Kettering |
|
Back to top |
|
|
|
|