Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Problem while Moving Values from 2D array to WS 1D array

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

New User


Joined: 25 Jun 2008
Posts: 24
Location: Pune

PostPosted: Sun Jun 26, 2011 2:52 pm    Post subject: Problem while Moving Values from 2D array to WS 1D array
Reply with quote

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
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Sun Jun 26, 2011 3:00 pm    Post subject: Re: Problem while Moving Values from 2D array to WS 1D array
Reply with quote

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
View user's profile Send private message
soumen2255

New User


Joined: 25 Jun 2008
Posts: 24
Location: Pune

PostPosted: Sun Jun 26, 2011 3:03 pm    Post subject: Re: Problem while Moving Values from 2D array to WS 1D array
Reply with quote

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
View user's profile Send private message
soumen2255

New User


Joined: 25 Jun 2008
Posts: 24
Location: Pune

PostPosted: Sun Jun 26, 2011 3:13 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Sun Jun 26, 2011 3:23 pm    Post subject: Reply to: Problem while Moving Values from 2D array to WS 1D
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sun Jun 26, 2011 3:36 pm    Post subject:
Reply with quote

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
View user's profile Send private message
soumen2255

New User


Joined: 25 Jun 2008
Posts: 24
Location: Pune

PostPosted: Sun Jun 26, 2011 3:56 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Sun Jun 26, 2011 3:59 pm    Post subject:
Reply with quote

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
View user's profile Send private message
seagull

New User


Joined: 28 May 2007
Posts: 24
Location: Dublin

PostPosted: Thu Aug 04, 2011 3:53 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Thu Aug 04, 2011 4:31 pm    Post subject:
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Aug 04, 2011 4:34 pm    Post subject:
Reply with quote

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
View user's profile Send private message
seagull

New User


Joined: 28 May 2007
Posts: 24
Location: Dublin

PostPosted: Thu Aug 04, 2011 4:36 pm    Post subject: Reply to: Problem while Moving Values from 2D array to WS 1D
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Aug 04, 2011 4:47 pm    Post subject:
Reply with quote

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
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Fri Aug 05, 2011 2:43 am    Post subject:
Reply with quote

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
View user's profile Send private message
seagull

New User


Joined: 28 May 2007
Posts: 24
Location: Dublin

PostPosted: Fri Aug 05, 2011 2:15 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Fri Aug 05, 2011 3:40 pm    Post subject: Reply to: Problem while Moving Values from 2D array to WS 1D
Reply with quote

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
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 Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm
No new posts Overlaying one set of charater values... Kevin Lindsley SYNCSORT 7 Sat Nov 05, 2016 3:21 am
No new posts Low values Results from VARCHAR FORMAT balaji81_k DB2 10 Thu Oct 20, 2016 1:18 am
No new posts Problem in Running Query via JCL vickey_dw DB2 3 Tue Oct 18, 2016 11:11 pm
No new posts Moving a PD to PD spoorni DFSORT/ICETOOL 8 Fri Oct 07, 2016 9:52 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us