Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
conversion of varchar to numeric comp-3

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: conversion of varchar to numeric comp-3
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: 3158
Location: Tucson AZ

PostPosted: Thu Mar 29, 2007 1:35 pm    Post subject:
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    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Thu Mar 29, 2007 2:33 pm    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts File Aid tool to compare numeric data balaji81_k Compuware & Other Tools 2 Tue Sep 26, 2017 3:35 am
No new posts Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am
No new posts Return a Non Numeric value from REXX Learncoholic CLIST & REXX 3 Fri Sep 01, 2017 8:33 pm
No new posts Select numeric portion from CHAR data... balaji81_k DB2 6 Sat Aug 19, 2017 1:51 am
No new posts Validate if a Value from the file is ... balacsv2 COBOL Programming 8 Mon Jun 19, 2017 11:52 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us