IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

conversion of varchar to numeric comp-3


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
soundari

New User


Joined: 23 Feb 2007
Posts: 7
Location: chennai

PostPosted: Thu Mar 29, 2007 12:11 pm
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Mar 29, 2007 1:35 pm
Reply with quote

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
View user's profile Send private message
soundari

New User


Joined: 23 Feb 2007
Posts: 7
Location: chennai

PostPosted: Thu Mar 29, 2007 2:30 pm
Reply with quote

i am extracting only 19 chars out of 254 and converting it as comp-3 variale.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Mar 29, 2007 2:33 pm
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Fri Mar 30, 2007 5:42 am
Reply with quote

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:
Code:
pic 9(013).9(6)

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
View user's profile Send private message
soundari

New User


Joined: 23 Feb 2007
Posts: 7
Location: chennai

PostPosted: Fri Mar 30, 2007 12:26 pm
Reply with quote

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
View user's profile Send private message
venosol
Warnings : 1

New User


Joined: 16 Nov 2006
Posts: 43
Location: Bangalore

PostPosted: Fri Mar 30, 2007 3:25 pm
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Mar 31, 2007 4:13 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts 10 byte RBA conversion DB2 2
No new posts 10 byte RBA conversion -non applicati... JCL & VSAM 1
No new posts file manager is doing string conversion IBM Tools 3
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Convert HEX to Numeric DB2 3
Search our Forums:

Back to Top