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
 
Move an alphanumeric 8 bytes to a numeric with 7 bytes

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

New User


Joined: 29 Nov 2003
Posts: 5
Location: chennai

PostPosted: Fri Jan 09, 2004 5:06 pm    Post subject: Move an alphanumeric 8 bytes to a numeric with 7 bytes
Reply with quote

icon_arrow.gif i have the following query before u all...

i have two variables, an alphanumeric with length 8 bytes and a numeric variable with 7 bytes.

ans1 - 8 bytes (alpha numeric variable with spaces)

num1 - 7 bytes (numeric variable)

I have the following scenario

1. When i move data from 'num1' variable to 'ans1' variable , how the data will be stored. (whether it will be left justified or right justified)

for eg- when num1 = 0001500 , what will be the value in 'ans1' ??

2. when i move the same data back from the 'ans1' variable to 'num1'
i am losing a byte in the left.

the value in the variable num1 = 001500, how do i lose that leftmost byte (i.e the value '0') after moving the data from 'ans1' to 'num1'.

Please someone clarify my doubts

thnx
[/b]
Back to top
View user's profile Send private message

anuradha

Active User


Joined: 06 Jan 2004
Posts: 247
Location: Hyderabad

PostPosted: Fri Jan 09, 2004 6:53 pm    Post subject: data types
Reply with quote

hi karthikshan,

ALPHANUMERIC ITEMS ARE LEFT JUSTIFIED.For example: the word SAR in a 5 character alphanumeric field would be stored as "SAR ". The number 1201 in a 7 character alphanumeric field would be stored as "1201 ". the contents are left justified with trailing spaces.


NUMERIC DATA TYPES(9) ARE RIGHT JUSTIFIED.The entire field contains zeros if unused (blanks are not allowed). If larger than 1 digit, the contents are right justified with leading zeroes. For example: the number 1201 in a 7 character numeric field would be stored as 0001201


SO WHEN num1 = 0001500 ,WHICH IS DECLARED AS 9(7) IS MOVED TO ans1 which is x(8),
icon_arrow.gif it will be stored as "0001500 ".

hence when u moved it back to num1 it will consider last 7 values including space "0001500 ".hence u r getting num1 as 001500.

if iam wrong someone correct me.

THANKS AND REGARDS
ANURADHA
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Jan 10, 2004 5:18 am    Post subject:
Reply with quote

Hi karth,

Your real problem is that you chose to mix AN/numeric formats in the move. This can cause problems, well... like the one you outlined here. icon_smile.gif

You can avoid the problems by either redefining the A/N field to numeric and MOVE numeric to numeric, e.g.:
Code:

01 fld1-num    pic 9(007).
01 fld2-an     pic x(008).
01 fld2-num    redefines     
    fld2-an    pic 9(008).

move fld1-num  to fld2-num
move fld2-num  to fld1-num

Displaying after the moves will show:

fld1 = 0001500
fld2 = 00001500


or

Use a re/fmod move after initing the A/N field to zeros.
Code:

01 fld1-num       pic 9(007).
01 fld2-an        pic x(008).
 
move zeros        to fld-2-an
move fld1-num(1:) to fld2-an (2:)
move fld2-an (2:) to fld1-num(1:)

Fields will display as above.

BTW, it's not a good idea to move a long field to a short field. Truncation may bite you.

Regards, Jack.
Back to top
View user's profile Send private message
karthikshan

New User


Joined: 29 Nov 2003
Posts: 5
Location: chennai

PostPosted: Tue Jan 13, 2004 7:52 pm    Post subject: Thanx a lot
Reply with quote

i am grateful for the early reply from u guys..


thanx a lot

karthik shan
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 Moving a COMP-3 Variable to a Numeric... ajayachander COBOL Programming 2 Thu Dec 14, 2017 5:46 pm
No new posts how can i move s9(9) to s9(9) usage comp HARENDRA CHOUDHARY COBOL Programming 3 Mon Nov 06, 2017 12:10 am
No new posts Move from Comp3 variable to Edited Va... Revathy.nair0485 COBOL Programming 7 Fri Nov 03, 2017 3:30 pm
This topic is locked: you cannot edit posts or make replies. Can a alphanumeric data be moved to a... nico_neoz COBOL Programming 10 Mon Oct 30, 2017 8:28 am
No new posts File Aid tool to compare numeric data balaji81_k Compuware & Other Tools 2 Tue Sep 26, 2017 3:35 am

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