View previous topic :: View next topic
|
Author |
Message |
karthikshan
New User
Joined: 29 Nov 2003 Posts: 5 Location: chennai
|
|
|
|
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 |
|
|
anuradha
Active User
Joined: 06 Jan 2004 Posts: 247 Location: Hyderabad
|
|
|
|
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),
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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
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.
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 |
|
|
karthikshan
New User
Joined: 29 Nov 2003 Posts: 5 Location: chennai
|
|
|
|
i am grateful for the early reply from u guys..
thanx a lot
karthik shan |
|
Back to top |
|
|
|