View previous topic :: View next topic |
Author |
Message |
radkrish Beginner

Joined: 12 Aug 2005 Posts: 102 Topics: 19
|
Posted: Mon Feb 26, 2007 7:40 pm Post subject: move alphanumeric to numeric |
|
|
Hi,
I need to move alphanumeric to numeric.I saw some of the post which explains the same thing.But it deals with 9(02).
My variable has to move from X(7) to 9(7) comp.
can anyone please tell me how to acheive this...
regds,
krish |
|
Back to top |
|
 |
radkrish Beginner

Joined: 12 Aug 2005 Posts: 102 Topics: 19
|
Posted: Mon Feb 26, 2007 7:41 pm Post subject: |
|
|
For your information,my compiler doesn't support intrinsic function NUMVAL.
regds,
krish |
|
Back to top |
|
 |
programmer1 Beginner
Joined: 18 Feb 2004 Posts: 138 Topics: 14
|
Posted: Mon Feb 26, 2007 10:36 pm Post subject: |
|
|
If your alphanumeric variable doesn't contain any spaces you can simply move the X(7) into 9(7) and then 9(7) into 9(7) comp.
If the variable contains spaces and you cannot use NUMVAL, simply use Inspect to remove the leading or trailing spaces. _________________ Regards,
Programmer |
|
Back to top |
|
 |
radkrish Beginner

Joined: 12 Aug 2005 Posts: 102 Topics: 19
|
Posted: Mon Feb 26, 2007 10:47 pm Post subject: |
|
|
When we move x(7) to 9(7) it gives '0' as the last numeric value.
VAR1 PIC X(7)
VAR2 PIC 9(7)
VAR3 PIC 9(7) comp
MOVE VAR1 TO VAR2
MOVE VAR2 TO VAR3
result :
VAR1 is 989 then VAR2 = 989 0,VAR3 = 989 {
VAR2 is 189 then VAR2 = 189 0,VAR3 = 189 {
can any one give me sample code to resolve this.Iam using VAR3 as my host variable in db2.
regds,
krish |
|
Back to top |
|
 |
cobcurious Beginner

Joined: 04 Oct 2003 Posts: 68 Topics: 25
|
Posted: Mon Feb 26, 2007 11:21 pm Post subject: |
|
|
Hi,
You are getting "0" at the end because in VAR1, there are trailing spaces.I assume that you are expecting only numeric values in the VAR1.
You can try the following :
01 VAR1 PIC X(7) JUST. (It will move the value as $$$$989, where $ is a space)
01 VAR3 PIC 9(7) COMP.
INSPECT VAR1
CONVERTING ALL ' ' to '0'. (this will convert all spaces to zeros)
MOVE VAR1 TO VAR3.
Note : If VAR1 is not numeric, the aobe move statement may give S0C7 error.
Let me know if it works
Thanks
Tushar |
|
Back to top |
|
 |
radkrish Beginner

Joined: 12 Aug 2005 Posts: 102 Topics: 19
|
Posted: Wed Feb 28, 2007 6:18 pm Post subject: |
|
|
Thanks.It suited well.
While using UNSTRING,iam getting junk in place of SPACE.
UNSTRING SAJ24-V DELIMITED BY '|'
INTO SJ24-MTH
, SJ24-WK
. . . .
.. . . .
, SJ24-A-NUM
,SJ24-B-NUM
Throwing junk in the last 2fields A-NUM and B-NUM.
Code: | |90U57227|2161|||A|2006|||||||-5.0000|-129385.000|-5.0000|052501PD00CMS|052502PD
|90W05033|2161|||A|2003|||||||-94.0000|-4615.800|-94.0000|052501PD00CMS|052502PD
|90W05033|2161|||A|2003|||||||-164.0000|-8039.430|-164.0000|052501PD00CMS|052502
|||2300M82P01AH|0.0000|-2480.000|-2.0000||
0|-46200.000|-46200.0000||
0|-90.000|-90.0000||
000|-1440.000|-1440.0000||
000|-24000.000|-24000.0000||
006||||||LA-CU LOUVER BA|0.0000|-1953.600|-110.0000||
006||||||14001192-102|0.0000|-2148.300|-110.0000|| |
This is just one part ..for your reference.
---------------------------------------------------------------------
OUTPUT
[code:1:f15d5aa36d]-5.0000, -129385.000 -5.0000 052501PD00CMS 052502PD00900
-94.0000 -4615.800 -94.0000 052501PD00CMS 052502PD00900
-164.0000 -8039.430 -164.0000 052501PD00CMS 052502PD00900
0.0000 -2480.000 -2.0000 .M..200612
0.0000 -46200.000 -46200.0000 . |
|
Back to top |
|
 |
KIMOSABEE Beginner

Joined: 03 Apr 2006 Posts: 2 Topics: 0 Location: Alamo, TX
|
Posted: Wed Feb 28, 2007 7:50 pm Post subject: |
|
|
krish,
I recieve a file every year from a reputable vendor with the same problem. Here is how I solved the problem. You can examine each field for alphabetic or numeric data. Hope it helps.
10 VP-RVUNIT PIC X(007).
10 VP-RVUNITX1 REDEFINES VP-RVUNIT.
15 VP-RVUNITX PIC 9(006)V9.
10 VP-RVUNITX2 REDEFINES VP-RVUNITX1.
15 VP-RVUNIT1 PIC X(001).
15 VP-RVUNIT2 PIC X(001).
15 VP-RVUNIT3 PIC X(001).
15 VP-RVUNIT4 PIC X(001).
15 VP-RVUNIT5 PIC X(001).
15 VP-RVUNIT6 PIC X(001).
15 VP-RVUNIT7 PIC X(001). _________________ Elvis is not coming. Confucious. |
|
Back to top |
|
 |
radkrish Beginner

Joined: 12 Aug 2005 Posts: 102 Topics: 19
|
Posted: Thu Mar 01, 2007 8:28 pm Post subject: |
|
|
Thanks.
Is that solve my junk value problem? |
|
Back to top |
|
 |
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Thu Mar 01, 2007 9:55 pm Post subject: |
|
|
radkrish,
are SJ24-A-NUM and SJ24-B-NUM defined as numeric? If so, I would suggest changing the type of any receiving fields defined as numeric to alpha. An UNSTRING to numeric fields is unpredictable if there are any non-numerics within the string being unstrung.
I would redefine SJ24-A-NUM and SJ24-B-NUM, each with by alpha field to be used in the UNSTRING statement. Then, REPLACE leading spaces with zeros. Then issue an IF SJ24-A-NUM NUMERIC then move, if not don't. (same for SJ24-B-NUM)
Since your compiler does not support NUMVAL, i would not count on it to support a sophisticated UNSTRING. Keep It Simple, UNSTRING to x-types, using the numeric redefines for validation and MOVE's to your comp fields. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
 |
radkrish Beginner

Joined: 12 Aug 2005 Posts: 102 Topics: 19
|
Posted: Thu Mar 01, 2007 10:38 pm Post subject: |
|
|
Thanks for your reply,Dick.
SJ24-A-NUM and SJ24-B-NUM is defined as alphanumeric.But not sure why do i get junk values in that place.
regds,
krish |
|
Back to top |
|
 |
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Fri Mar 02, 2007 5:34 am Post subject: |
|
|
krish,
in your post of Thu Mar 01, 2007 1:18 am, you have 3 code windows. the first window is your input? Is that one record? or is each line a record? _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
 |
radkrish Beginner

Joined: 12 Aug 2005 Posts: 102 Topics: 19
|
Posted: Mon Mar 05, 2007 8:09 am Post subject: |
|
|
Thanks for the reply.
My window shows different timings on this post.Assuming that you are talking about this code window.
Code: | |90U57227|2161|||A|2006|||||||-5.0000|-129385.000|-5.0000|052501PD00CMS|052502PD
|90W05033|2161|||A|2003|||||||-94.0000|-4615.800|-94.0000|052501PD00CMS|052502PD
|90W05033|2161|||A|2003|||||||-164.0000|-8039.430|-164.0000|052501PD00CMS|052502
|||2300M82P01AH|0.0000|-2480.000|-2.0000||
0|-46200.000|-46200.0000||
0|-90.000|-90.0000||
000|-1440.000|-1440.0000||
000|-24000.000|-24000.0000||
006||||||LA-CU LOUVER BA|0.0000|-1953.600|-110.0000||
006||||||14001192-102|0.0000|-2148.300|-110.0000|| |
Every line shows one record.
Length is 486.But it shows the last 100 char.1o records are shown above.
regds,
krish |
|
Back to top |
|
 |
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Mon Mar 05, 2007 11:20 am Post subject: |
|
|
your problem is that there is garbage in whatever workarea you are using as the source object of the UNSTRING.
I suggest that records 4 thru whatever are different lengths, layouts, whatever that the first 3.
Quote: |
|90U57227|2161|||A|2006|||||||-5.0000|-129385.000|-5.0000|052501PD00CMS|052502PD
|90W05033|2161|||A|2003|||||||-94.0000|-4615.800|-94.0000|052501PD00CMS|052502PD
|90W05033|2161|||A|2003|||||||-164.0000|-8039.430|-164.0000|052501PD00CMS|052502
|||2300M82P01AH|0.0000|-2480.000|-2.0000|| |
Since you did not copy/paste properly, I can not replicate your data. i.e. you display the last field in record 1 as : 052502PD00900, but all we can see is 052502PD
you say that these are fixed length records. They have to be variable. Though you file designation may be fixed, it is obvious that the records are not the same length.
your read mechanism should have somekind of length.
i don't know what the source of your input records is, nor do I know how you are inputing them. tell us that and we maybe able to provide a solution. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Mon Mar 05, 2007 1:14 pm Post subject: |
|
|
It is a simple 101 programming exercise. check this
Code: |
WORKING-STORAGE SECTION.
01 WS-CHAR PIC X(07).
01 WS-NUM PIC 9(07).
01 WS-COMP PIC S9(07) COMP.
01 WS-SUB PIC S9(04) COMP VALUE 0.
01 S-ALPHABET-FOUND PIC X(01) VALUE 'N'.
PROCEDURE DIVISION.
MOVE '1 ' TO WS-CHAR
PERFORM 1000-FIND-SPACE-AND-MOVE
GOBACK
.
1000-FIND-SPACE-AND-MOVE.
MOVE 'N' TO S-ALPHABET-FOUND
MOVE '0000000' TO WS-NUM
PERFORM VARYING WS-SUB FROM 7 BY -1 UNTIL WS-SUB < 1
OR S-ALPHABET-FOUND = 'Y'
IF WS-CHAR(WS-SUB : 1) NOT = SPACE
MOVE 'Y' TO S-ALPHABET-FOUND
MOVE WS-CHAR(1 : WS-SUB) TO
WS-NUM( 7 - WS-SUB + 1 : WS-SUB)
END-IF
END-PERFORM
MOVE WS-NUM TO WS-COMP
DISPLAY 'THE COMP NUM IS : ' WS-COMP
.
|
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
radkrish Beginner

Joined: 12 Aug 2005 Posts: 102 Topics: 19
|
Posted: Mon Mar 05, 2007 6:30 pm Post subject: |
|
|
Thanks for the reply,dbzTHEdinosauer.I mentioned 486 which is the maximum record length of the VB file. |
|
Back to top |
|
 |
|
|