View previous topic :: View next topic
|
Author |
Message |
soumen2255
New User
Joined: 25 Jun 2008 Posts: 24 Location: Pune
|
|
|
|
Hi,
I am facing Problem while Moving Values from Copybook 2D array to WS 1D .
My copybook layout is -
Code: |
01 xxx-table
05 yyy-value occurs 50 times indexed by s1
15 yyy-product-id PIC 9(06)
15 yyy-product-num REDEFINES yyy-product-id.
20 yyy-product-code Pic 9(04).
20 yyy-text-code pic 9(02).
15 xxx-table-entry occurs 100 times.
20 xxx-table-code pic 9(02).
20 xxx-table-num pic 9(04)
My WS layout -
01 ws-xxx-table
05 ws-yyy-value occurs 50 times indexed by z1
10 ws-yyy-product-code pic 9(04).
10 ws-xxx-table-num pic 9(04).
Procedure Div -
Perform varying - Initialised
Perform varying s1 from 1 by 1 until s1 > 50
move yyy-product-code (s1) to ws-yyy-product-code(s1)
move xxx-table-num(s1 1) to ws-xxx-table-num(s1) |
Note - I need the first occurnce of xxx-table-num only.
Problem -
After the first value is moved correctly , rest of the values are not moved for ws-xxx-table-num(s1), though it shows that the movement is happening correctly |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
soumen2255 wrote: |
Hi,
I am facing Problem while Moving Values from Copybook 2D array to WS 1D .
My copybook layout is -
Code: |
01 xxx-table
05 yyy-value occurs 50 times indexed by s1
15 yyy-product-id PIC 9(06)
15 yyy-product-num REDEFINES yyy-product-id.
20 yyy-product-code Pic 9(04).
20 yyy-text-code pic 9(02).
15 xxx-table-entry occurs 100 times.
20 xxx-table-code pic 9(02).
20 xxx-table-num pic 9(04) |
My WS layout -
Code: |
01 ws-xxx-table
05 ws-yyy-value occurs 50 times indexed by z1
10 ws-yyy-product-code pic 9(04).
10 ws-xxx-table-num pic 9(04). |
Procedure Div -
Code: |
Perform varying - Initialised
Perform varying s1 from 1 by 1 until s1 > 50
move yyy-product-code (s1) to ws-yyy-product-code(s1)
move xxx-table-num(s1 1) to ws-xxx-table-num(s1)
Note - I need the first occurnce of xxx-table-num only. |
Problem -
After the first value is moved correctly , rest of the values are not moved for ws-xxx-table-num(s1), though it shows that the movement is happening correctly |
Please learn how to use the code tags.
Please copy/paste your actual code.
In the above perform your ws-yyy... says it is using s1 as an index. Ain't gonna work.
If these are your real data-names, perhaps you deserve to be in a constant mess. Try making names meaningful, self-descriptive, and it will cut down enormously on totally dumb errors.
And what
Quote: |
shows that the movement is happening correctly |
? |
|
Back to top |
|
|
soumen2255
New User
Joined: 25 Jun 2008 Posts: 24 Location: Pune
|
|
|
|
Bill Woodger wrote: |
soumen2255 wrote: |
Hi,
I am facing Problem while Moving Values from Copybook 2D array to WS 1D .
My copybook layout is -
Code: |
01 xxx-table
05 yyy-value occurs 50 times indexed by s1
15 yyy-product-id PIC 9(06)
15 yyy-product-num REDEFINES yyy-product-id.
20 yyy-product-code Pic 9(04).
20 yyy-text-code pic 9(02).
15 xxx-table-entry occurs 100 times.
20 xxx-table-code pic 9(02).
20 xxx-table-num pic 9(04) |
My WS layout -
Code: |
01 ws-xxx-table
05 ws-yyy-value occurs 50 times indexed by z1
10 ws-yyy-product-code pic 9(04).
10 ws-xxx-table-num pic 9(04). |
Procedure Div -
Code: |
Perform varying - Initialised
Perform varying s1 from 1 by 1 until s1 > 50
move yyy-product-code (s1) to ws-yyy-product-code(s1)
move xxx-table-num(s1 1) to ws-xxx-table-num(s1)
Note - I need the first occurnce of xxx-table-num only. |
Problem -
After the first value is moved correctly , rest of the values are not moved for ws-xxx-table-num(s1), though it shows that the movement is happening correctly |
Please learn how to use the code tags.
Please copy/paste your actual code.
In the above perform your ws-yyy... says it is using s1 as an index. Ain't gonna work.
If these are your real data-names, perhaps you deserve to be in a constant mess. Try making names meaningful, self-descriptive, and it will cut down enormously on totally dumb errors.
And what
Quote: |
shows that the movement is happening correctly |
? |
Thanks for the Reply.. Sorry for for not putting tags.. Do I need to Put in the Index defined in WS ? Please help |
|
Back to top |
|
|
soumen2255
New User
Joined: 25 Jun 2008 Posts: 24 Location: Pune
|
|
|
|
Hi,
I tried This
Code: |
Perform varying z1 from 1 by 1 until z1 > 50
move yyy-product-code (z1) to ws-yyy-product-code(z1)
move xxx-table-num(z1 1) to ws-xxx-table-num(z1)
|
But Now I can see the values getting populated for ws-xxx-table-num(z1) but apart from the first one rest of them are junk.PLease help |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Your profile says "Cobol", it is three years and one day since you registered.
Are you unfamiliar with indexes?
Look at your definitions. One table defines one index, the idiotic and meaningless s1, and the other table (perforce) defines another, equally idiotic name, z1. When referencing data indexed by s1, you have to use s1. When referencing data indexed by z1, you have to use z1. In the same statement, you need to use both indexes, on the appropriate fields.
You do not define the indexes seperately yourself. The compiler defines the storage for the index because you say "INDEXED BY".
If you are new to indexes, check out the manuals really thoroughly. Do some practice usage. Read the manuals again. More practice. Then, when you understand what is wrong with what you have done and said, get back to this program. If we just give you the answers, you are going to make countless other errors through lack of knowledge. Put in the understanding first, then you'll know how to do the code.
And use meaningful data-names! Including indexes!
Let us know how you get on. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
i added/changed a little of your code. try this:
Code: |
Perform varying z1 from 1 by 1 until z1 > 50
SET S1 TO Z1
move yyy-product-code (S1) to ws-yyy-product-code(z1)
move xxx-table-num (S1, 1) to ws-xxx-table-num (z1)
|
|
|
Back to top |
|
|
soumen2255
New User
Joined: 25 Jun 2008 Posts: 24 Location: Pune
|
|
|
|
dbzTHEdinosauer wrote: |
i added/changed a little of your code. try this:
Code: |
Perform varying z1 from 1 by 1 until z1 > 50
SET S1 TO Z1
move yyy-product-code (S1) to ws-yyy-product-code(z1)
move xxx-table-num (S1, 1) to ws-xxx-table-num (z1)
|
|
tHANKS A lot!!.
This seems to be working... !!
Thanks everyone for their help.. I will go through Index manuals for more details and more learning on this as suggested.. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Mmmm.... or just wait long enough and the working code pops up. :-)
Now dbz has done that for you, a couple of other things.
You have "> 50". What does the 50 mean? Size of your table. If you reference in more than one place in your program (often the case) you have 50 scattered through your procedure division. Then you want to change the size of your table (or, more importantly, someone else does as you have moved on to new "development only" projects) and you've made the maintenance more difficult. Plus, someone has to look at all the 50's in the program, to see if they refer to your tables or to something else, and make sure they only change the 50's referring to your table.
Same with the "1" as your 2nd-level index. In business terms, what does the first row mean? If nothing particular, at least come up with a name that indicates it is the first row. |
|
Back to top |
|
|
seagull
New User
Joined: 28 May 2007 Posts: 24 Location: Dublin
|
|
|
|
When you want to use the same instance for both tables, try using a subscript instead of using the indexes. It makes coding easier. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Are you saying "easier" to mix subscripts and indexes in the same program? Or to abandon indexes altogether? Or just in selected programs so you have a mix in your system?
That all makes it "easier" for whom? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
seagull wrote: |
When you want to use the same instance for both tables, try using a subscript instead of using the indexes. It makes coding easier. |
but the performance sucks.
granted you need to have millions of iterations to realize the savings in your program,
but even at a few iterations, it means less cpu used by you and more for others. |
|
Back to top |
|
|
seagull
New User
Joined: 28 May 2007 Posts: 24 Location: Dublin
|
|
|
|
I was meaning use subscripts in an example like this, where you want to use the same occurrence in more than one table. That way, you only have to worry about one variable to get to the correct instance of both tables.
Use indexes as appropriate, and subscripts where appropriate. Subscripts are probably easier to understand for programmers starting out. The issue is that a lot of people are never taught how indexes actually work, and just assume they work in the same way as subscripts. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
show me an appropriate use of a sub-script.....
literal subscripts (which generate the address at compile time) are the most efficient.
then indexes
then subscripts.
if you are going to use subscripts make sure that they are comp (binary).
people use subscripts because they are second rate coders.
They do not know how to properly use perform varying with multiple until phrases. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
people use subscripts because they are second rate coders. |
Or because the organization long ago determined they would not use indexes. Same with the internal sort and many other features that the "management" at that time did not understand. . . |
|
Back to top |
|
|
seagull
New User
Joined: 28 May 2007 Posts: 24 Location: Dublin
|
|
|
|
dbzTHEdinosauer wrote: |
people use subscripts because they are second rate coders. |
Or because the bright spark who wrote the program initially didn't bother to add indexes to their tables.
Or because we assume that the number of programmers who actually understand indexes seems to be dropping, and the minor cost in performance in many instances is outweighed by the development costs in having to explain them numerous times, and the debugging hassles. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
We are meandering off-topic a little.
I don't mind subscripts, in the obvious situation pointed out earlier by Dick.
I do mind mixing subscripts and indexes in the same program or the same system. Fortunately this would be rare, as the "subscript-only" sites won't allow indexes and the "index" sites would'nt want to use subscripts, particularly with the risk of causing confusion. One or the other per system, and I keep quiet. |
|
Back to top |
|
|
|