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

Move an alphanumeric 8 bytes to a numeric with 7 bytes


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts How to move values from single dimens... COBOL Programming 1
No new posts total number of bytes PL/I & Assembler 10
No new posts Numeric check on packed signed and un... COBOL Programming 4
No new posts Packed decimal to Alphanumeric COBOL Programming 2
No new posts Numeric check w/SyncSort. SYNCSORT 1
Search our Forums:

Back to Top