View previous topic :: View next topic
|
Author |
Message |
devidas-patil
New User
Joined: 08 Jan 2007 Posts: 54 Location: pune
|
|
|
|
Hi all friend,
i want to know why we cant use array variable as varible in operation like +, _ etc |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Why do you say we can't? Can you give an example? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Array variables are often used in comnputations. Make sure that you have properly defined them.
If you post your code and your error message (if you got one), we will be able to help. If youi got undesired results, please post that also. |
|
Back to top |
|
|
devidas-patil
New User
Joined: 08 Jan 2007 Posts: 54 Location: pune
|
|
|
|
William Thompson wrote: |
Why do you say we can't? Can you give an example? |
'
declare array_A(10) float binary;
declare array_B(10)fixed binary static
initial (0,l,2,3,4,5,6,7,8,9);
declare i fixed binary;
do i = 1 to 10;
array_A(i) = sqrt(array_B(i));
end;
variables cannot be operands for arithmetic operators such as
+ and ? . For example, any statement of the form:
C= A + B;
is invalid if A, B, and C are array variables. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
PL/I? I don't know. Assembler and COBOL I do. There they can without restriction. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Please post the actual error message. |
|
Back to top |
|
|
devidas-patil
New User
Joined: 08 Jan 2007 Posts: 54 Location: pune
|
|
|
|
Hi all,
i not tried it practically but while reading the book i got..
i know we can use array variable in calculation using subscipt or index e why not without index or subscipt....... |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
devidas-patil wrote: |
i not tried it practically but while reading the book i got.. |
Can you quote the part of the book that gives you this idea?
Quote: |
i know we can use array variable in calculation using subscipt or index e why not without index or subscipt....... |
Without the subscript or index, which member of the array would be used? |
|
Back to top |
|
|
devidas-patil
New User
Joined: 08 Jan 2007 Posts: 54 Location: pune
|
|
|
|
i know without subscript we cant but i want to know that only why...thats was my basic question? |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Why? Because "without the subscript or index, which member of the array would be used?" |
|
Back to top |
|
|
Bitneuker
CICS Moderator
Joined: 07 Nov 2005 Posts: 1104 Location: The Netherlands at Hole 19
|
|
|
|
In addition to Bill:
So it's just about subscripting Suppose you're in a street with 10 sidestreets. You want to reach some address and ask me the way. What would it bring you if I told you to go strait ahead and then turn left? You'd ask me which sidestreet to turn into; well that's exactly what the computer would need to know. |
|
Back to top |
|
|
devidas-patil
New User
Joined: 08 Jan 2007 Posts: 54 Location: pune
|
|
|
|
Thnaks
i was on leave so not replied..
hanks for your co-operation.. |
|
Back to top |
|
|
cheryala
New User
Joined: 20 Mar 2006 Posts: 46
|
|
|
|
HI,
It is possible to use array name as variable in expressions like
i) C = A + B ;
ii)C = A * 5 ;
iii) C = A * B (i ) ;
Where A,B and C are arrays..
But there are some restrictions..for example in i) statement
A,B and C should be declared with the same bounds and substript ranges..
Regards,
Raj |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Would you give an example of how you would define A, B and C as arrays? |
|
Back to top |
|
|
cheryala
New User
Joined: 20 Mar 2006 Posts: 46
|
|
|
|
Hello Thompson,
You can declare the array variables as follows...
DCL (A(5),B(5),C(5)) FIXED BIN(31,0);
here all array sizes are equal and default bounds are considered from 1 to 5.
If you want to specify your own bounds then bounds of all arrays should match...
eg:
DCL (A(3:7),B(3:7),C(3:7)) FIXED BIN (31,0);
Regards,
Raj |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Oh dear, that weird language......But you have answered as I expected you would....
You want the compiler to be smart enough to do something like a "corresponding" function - C = A B would go as C(n) = A(n) B(n) where n = 1 through the max size of the array, right?
I don't think that is allowed but it would be very easy to write a small generalized routine to do it. |
|
Back to top |
|
|
cheryala
New User
Joined: 20 Mar 2006 Posts: 46
|
|
|
|
Yes thomson, What you said is correct. It performs exactly what you said.
Regards,
Raj |
|
Back to top |
|
|
|