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

COBOL: Reference Modification to handle decimal numbers


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Mar 23, 2010 5:42 pm
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
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: 1353
Location: Israel

PostPosted: Tue Mar 23, 2010 6:42 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top