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
 
COBOL: Reference Modification to handle decimal numbers

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
gsmohanty

New User


Joined: 23 Mar 2010
Posts: 1
Location: Bangalore

PostPosted: Tue Mar 23, 2010 5:23 pm    Post subject: COBOL: Reference Modification to handle decimal numbers
Reply with quote

Hi All,

I am writing a program where I am picking out data from a String. The String contains the data in various formats like numeric, packed decimal, alphanumeric, all present together. I am using REFERENCE MODIFICATION while pulling out the data by mentioning the starting position of the data in the string and length occupied by the data. For alphanumeric data and non decimal numeric data it is working fine. Now the situation I am facing is while handling numeric data which are supposed to be decimal. We use copybook to build the string but when my program is reading the string it doesn't have access to the copybook, so my program doesnot know if data is decimal or numeric. The decimal data which I am reading I am moving it to a Variable S9(11)V9(4).
For Example:

01 WS-TEST-VARIABLE.
05 WS-NAME PIC X(5) VALUE 'NAME '.
05 WS-TEST-TET1 PIC S9(3)V9(2) VALUE ZEROS.
01 WS-TTTTT PIC S9(11)V9(2) VALUE ZEROS.
01 WS-T PIC S9(11)V9(2) VALUE ZEROS.
.
.
.
.
MOVE 5.6 TO WS-TEST-TET1
MOVE WS-TEST-VARIABLE(6:5) TO WS-TTTTT
COMPUTE WS-T = WS-TTTTT + 5
DISPLAY WS-TEST-TET1
DISPLAY WS-TTTTT
DISPLAY WS-T
.
.
.

OUTPUT

0056{
000000005600{
5650{

It is treating the value in WS-TTTTT as 560 instead of 5.6
As the expected value of WS-T should be 1060{ instead of
5650{

Please suggest how can I handle this scenario, also please suggest if via Reference Modification in COBOL if we can handle decimal numbers.

Thanks in Advance,[/b]
Back to top
View user's profile Send private message

cvishu

Active User


Joined: 31 Jul 2007
Posts: 136
Location: india

PostPosted: Tue Mar 23, 2010 5:35 pm    Post subject:
Reply with quote

am not sure if it will work but try to Redifne WS-TEST-TET1 as a edited picture clause PIC S9(3).9(2) and the move the edited picture caluse to
WS-TTTTT .

Also am not sure y u want to specificy the positions, when u know ur input is going to be numeric , u can just dirctly move WS-TEST-TET1 .

The gropu variable will alweaya be treated as a character if i am not wrong.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8152
Location: East Dubuque, Illinois, USA

PostPosted: Tue Mar 23, 2010 5:42 pm    Post subject:
Reply with quote

The V in a PICTURE clause is an implied decimal point. You need to either use FUNCTION NUMVAL (which I have not verified to work for what you are attempting), or handle the digits before and after the decimal point separately.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Tue Mar 23, 2010 6:24 pm    Post subject:
Reply with quote

This :
MOVE WS-TEST-VARIABLE(6:5) TO WS-TTTTT
will try to convert the content to numeric before moving to ws-tttt, because ws-tttt is numeric

this:
MOVE WS-TEST-VARIABLE(6:5) TO WS-TTTTT (1:)
will move the content as alphanumeric, because ws-ttttt(1:) is alphanumeric. (length must be the same)

Redefining ws-ttttt as ws-tttttX pic X(5) , and moving to ws-ttttX will also work.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1243
Location: Israel

PostPosted: Tue Mar 23, 2010 6:42 pm    Post subject: Reply to: COBOL: Reference Modification to handle decimal nu
Reply with quote

The problem lays in this move:
Quote:
MOVE WS-TEST-VARIABLE(6:5) TO WS-TTTTT

The group field WS-TEST contains "NAME 00560". As Robert says, the decimal point is implied.
When you look at it this way, then WS-TEST-VARIABLE(6:5) contains 00560, not 005.60
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed Mar 24, 2010 4:53 am    Post subject:
Reply with quote

You might try this to get the alignment you need:

MOVE WS-TEST-VARIABLE(6:5) TO WS-TTTTT(9:5)
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
This topic is locked: you cannot edit posts or make replies. Extract all "IF" Statements... Adarsh Damodaran CLIST & REXX 1 Wed Sep 06, 2017 9:28 am
No new posts ALPHABETIC check in COBOL vidyaa COBOL Programming 8 Thu Aug 17, 2017 7:13 pm
No new posts XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm
No new posts StreamWeaver language reference chetanambi Compuware & Other Tools 1 Wed Jul 05, 2017 12:50 pm
No new posts How to generate a new unique Input fi... for1ranjith CLIST & REXX 11 Sat Jul 01, 2017 12:09 pm

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