View previous topic :: View next topic
|
Author |
Message |
soundari
New User
Joined: 23 Feb 2007 Posts: 7 Location: chennai
|
|
|
|
could you please tell how to convert the var char variable to numeric comp-3 variable (x(254) into 9(12)v9(6)) to use the variable in calculations |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
The intrinsic function NUMVAL could do it but which 20 or so bytes of the 254 are you going to apply it to? |
|
Back to top |
|
|
soundari
New User
Joined: 23 Feb 2007 Posts: 7 Location: chennai
|
|
|
|
i am extracting only 19 chars out of 254 and converting it as comp-3 variale. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
soundari wrote: |
i am extracting only 19 chars out of 254 and converting it as comp-3 variale. |
Sounds like you have your answer then. Give it a try and let us know how it worked. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Assuming you selected ARITH(EXTEND) as a compiler option and var-data contains only external decimal data (trailing A/N data is OK), you can do this:
Your var field is defined as:
Code: |
01 var-char.
49 var-len pic s9(004) comp.
49 var-data pic x(254). |
And is a DB2 host variable.
Define an intermediate field as:
Code: |
01 hld-num pic 9(019). |
If var-data contains a decimal point define hld-num as:
Define your packed field as:
Code: |
01 pd-num pic 9(013)v9(6) comp-3. |
then:
Code: |
move var-data(1:var-len) to hld-num
move hld-num to pd-num |
[/code] |
|
Back to top |
|
|
soundari
New User
Joined: 23 Feb 2007 Posts: 7 Location: chennai
|
|
|
|
hi
your concept is working fine. now i just want to do the reverse process(converting x(254) to 9(15).9(3) comp-3)
will the following code work properly
01 COMP-VAR
05 COMP-LEN PIC S9(04) COMP
05 COMP-DATA PIC 9(15)V9(3).
01 HLD-CHAR PIC X(19).
01 FINAL-CHAR PIC X(254).
MOVE COMP-DATA TO HLD-CHAR
MOVE HLD-CHAR TO FINAL-CHAR |
|
Back to top |
|
|
venosol Warnings : 1 New User
Joined: 16 Nov 2006 Posts: 43 Location: Bangalore
|
|
|
|
soundari wrote: |
hi
your concept is working fine. now i just want to do the reverse process(converting x(254) to 9(15).9(3) comp-3)
will the following code work properly
01 COMP-VAR
05 COMP-LEN PIC S9(04) COMP
05 COMP-DATA PIC 9(15)V9(3).
01 HLD-CHAR PIC X(19).
01 FINAL-CHAR PIC X(254).
MOVE COMP-DATA TO HLD-CHAR
MOVE HLD-CHAR TO FINAL-CHAR |
Comp, Comp-1, comp-2, comp-3 . All are used for Numeric calculations.
To increase the performance of the compiler these Comp variables are used which will work dynamically. There won't be necessary for alpanumeric or alphabets manipulations. If at all you use means it will cause errors. Systems may hangup sometimes. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Please show us an example of the data contained in the packed field and the data string you expect to see in FINAL-DATA.
Include both pos/neg examples. |
|
Back to top |
|
|
|