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
 

 

When i read array i get only the last stored value as right

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

New User


Joined: 16 Apr 2005
Posts: 33

PostPosted: Tue Nov 08, 2011 2:51 pm    Post subject: When i read array i get only the last stored value as right
Reply with quote

Hi,
I'm reading a file and storing the data in to array. when i tied to read the array if i had stored 10 occurences first 9 will be junk data and 10th will be proper one. Any idea.what mistake i must be doing here?

Array declaration is as below.
Code:
77  CHASSI-CNT                  PIC S9(8) COMP VALUE ZERO.
                                                           
01  PRECH-WSRECORD.                                       
    03 PRECH-ARRAY OCCURS      100000 TIMES               
                   DEPENDING ON CHASSI-CNT                 
                   ASCENDING KEY PCHWS-IDCHASNR           
                   INDEXED BY CHASS-INDX.                 
       05 PCHWS-IDCHNRS         PIC X(05).                 
       05 PCHWS-IDCHASNR        PIC S9(6) COMP-3.         

in Procedure division
SET  CHASS-INDX       to  1
SET  CHASS-INDX       down  BY  1

PERFORM S02-READ-R1711J2
PERFORM UNTIL END-OF-R1711J2
SET  CHASS-INDX       UP  BY  1
MOVE PCHFS-IDCHNRS    TO  PCHWS-IDCHNRS(CHASS-INDX )
MOVE PCHFS-IDCHASNR   TO  PCHWS-IDCHASNR(CHASS-INDX )
PERFORM S02-READ-R1711J2



Thanks & regards,
Bhavya
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7904
Location: Bellevue, IA

PostPosted: Tue Nov 08, 2011 3:00 pm    Post subject:
Reply with quote

Is this table in WORKING-STORAGE? If so, why are you using OCCURS DEPENDING ON since the maximum number of elements will define the amount of storage used? Where do you increment CHASSI-CNT before you attempt to use that table element -- this problem could explain your results?
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Tue Nov 08, 2011 3:06 pm    Post subject: Reply to: When i read array i get only the last stored value
Reply with quote

Ditch the Occurs Depending On. Won't affect your problem, but since you are not utilising its properties, there is no point in having it in your program.

What do you mean by "junk"?


Have you searched the Cobol forum for the "Junk Buster"? :-)
Back to top
View user's profile Send private message
bhavya_sha

New User


Joined: 16 Apr 2005
Posts: 33

PostPosted: Tue Nov 08, 2011 3:07 pm    Post subject: When i read array i get only the last stored value as right
Reply with quote

I'm so sorry that i had put wrong code. You are right Array is in working-storage section & i had removed tht depending on clause.

Code:
01  PRECH-WSRECORD.                                       
    03 PRECH-ARRAY OCCURS      1000 TIMES                               
                   ASCENDING KEY PCHWS-IDCHASNR           
                   INDEXED BY CHASS-INDX.                 
       05 PCHWS-IDCHNRS         PIC X(05).                 
       05 PCHWS-IDCHASNR        PIC S9(6) COMP-3.         

in Procedure division
SET  CHASS-INDX       to  1
SET  CHASS-INDX       down  BY  1

PERFORM S02-READ-R1711J2
PERFORM UNTIL END-OF-R1711J2
SET  CHASS-INDX       UP  BY  1
MOVE PCHFS-IDCHNRS    TO  PCHWS-IDCHNRS(CHASS-INDX )
MOVE PCHFS-IDCHASNR   TO  PCHWS-IDCHASNR(CHASS-INDX )
PERFORM S02-READ-R1711J2

when i try to display after this i get last value right n-1 values as junk data.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Tue Nov 08, 2011 3:12 pm    Post subject: Reply to: When i read array i get only the last stored value
Reply with quote

To put it another way, what do you mean by "right"?

Seriously, copy and past the Junk Buster. Compile it. Call it from your program with the table and the length of the occurs (9 from memory, but you can check, I'm not even going to scroll down to see). Then paste the output.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7904
Location: Bellevue, IA

PostPosted: Tue Nov 08, 2011 3:14 pm    Post subject:
Reply with quote

Quote:
when i try to display after this i get last value right n-1 values as junk data.
There is no such thing as "junk data". EBCDIC is only defined as having 256 characters in the collating sequence, and every last one of them is known -- not "junk". YOU may not understand the data, but it can be understood. If you want help, you're going to need to post some of this "junk data" using the Code button to preserve spacing. Use a hexadecimal display so we can see the full hex value for each byte, too.
Back to top
View user's profile Send private message
bhavya_sha

New User


Joined: 16 Apr 2005
Posts: 33

PostPosted: Tue Nov 08, 2011 3:19 pm    Post subject:
Reply with quote

Right in the sense the value stored in array icon_smile.gif.

I read 2 records from file as below

A 722197
B 722198
c 722199

WHEN I DISPLAY i always get output as below i mean junk is 040404 and first field as space.

040404
040404
A 722198

Thanks & Regards,
Bhavya
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Tue Nov 08, 2011 3:22 pm    Post subject: Reply to: When i read array i get only the last stored value
Reply with quote

did You notice that Your posts were edited to add the code tags ?

practice a bit so that people helping You will view things in a more readable format !
Back to top
View user's profile Send private message
bhavya_sha

New User


Joined: 16 Apr 2005
Posts: 33

PostPosted: Tue Nov 08, 2011 3:27 pm    Post subject:
Reply with quote

Sure..but i had followed the indentation before pasting it's gone.
anyways from now on will be carefull with tht
thanks icon_smile.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7904
Location: Bellevue, IA

PostPosted: Tue Nov 08, 2011 3:31 pm    Post subject:
Reply with quote

Quote:
I read 2 records from file as below

A 722197
B 722198
c 722199
What on earth are you talking about? If you are reading TWO records, why do you have THREE values displayed?

Further, as I said, your values are not "junk". A space is X'40'. If this is converted to packed decimal (COMP-3), the value would be X'040404C4' for signed and X'040404F4' for unsigned -- PIC S9(06) becomes a 4-byte packed decimal value and the following D or 4 is part of the value, not distinct. Perhaps you should start by figuring out why your so-called numeric values have spaces in them?
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Tue Nov 08, 2011 3:31 pm    Post subject:
Reply with quote

bhavya_sha wrote:
[...]

Code:
         040404     
         040404
A       722198

[,,,]


Look at the power of the Code button! Robert and enrico have both pointed this out, so use it in future please.

Robert also requested you show us the data in hexadecimal. I suggested the same, although through a different route.

If you look in hexedecimal you will see

4040404040 (that is your five bytes of space) and 4040404F, which is your number. Can't be sure about the F there, but if you used the Junk Buster you'd see for sure, and it is then a further clue to whatever it is you have done.

Now, you would have noticed a similarity between the two fields, wouldn't you?

Basically, you have blatted all but the last occurence of your data with space, somehow.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Tue Nov 08, 2011 3:45 pm    Post subject:
Reply with quote

bhavya_sha wrote:
[...]

I read 2 records from file as below

Code:
A       722197
B       722198
c       722199

WHEN I DISPLAY i always get output as below i mean junk is 040404 and first field as space.

Code:
         040404     
         040404
A       722198


[...]


From your example I notice you have a mixture of records one and two in your third array entry? Typo, or Junk?

Looking again at your definitions, it seems that you are preparing for a SEARCH ALL? Don't ditch the Occurs Depending On, but ensure that the value is correct before you do the SEARCH ALL.

The value that is in your COMP-3 in the table is important as a clue because it can tell you how the spaces got into the table.

If no sign is present, then space was moved to a group item, or you have NUMPROC(PFD) compiler option and the source field contains space.

If sign is present as a C, then it was an individual move and you have NUMPROC(NOPFD) or the source field already contained that value.

If sign is present as an F, then it was an individual move and you have NUMPROC(NOPFD).

An "individual move" in this case is intended to include the MOVE of another table with same lengths that has directly, or indirectly, been populated with an individual move to the items.

EDIT: With the ODO I'd be highly suspicious that there is a MOVE SPACE TO table-name, with the ODO being one out of step and the MOVE being done at an incorrect point (or your code being at an incorrect point).
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Tue Nov 08, 2011 4:08 pm    Post subject: Reply to: When i read array i get only the last stored value
Reply with quote

Further, how do you know those spaces are the values in your table? Are you serially displaying them, or is this the result of a SEARCH ALL that you have not used correctly?

At some point I'm going to moan about the meaningless of your datanames.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1218
Location: Israel

PostPosted: Tue Nov 08, 2011 8:48 pm    Post subject: Reply to: When i read array i get only the last stored value
Reply with quote

Can we see how PCHFS-IDCHNRS and PCHFS-IDCHASNR are defined ?
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 743
Location: Germany

PostPosted: Wed Nov 09, 2011 4:25 pm    Post subject:
Reply with quote

@ bhavya_sha

Morning Sir !

Just something, i'm always wondering about, seeing that modus operandi.

You use two "SET INDX" and two "READ INPUT".
Absolutely redundant.

SET INDX TO 1

PERFORM UNTILL END-OF-FILE OR ERROR-HAPPENED
...READ INPUT
...EVALUATE TRUE
......WHEN EVERYTING-OK......MOVE TO FIELD(INDX)
............................................SET INDX UP BY 1
......WHEN OTHER...
...END-EVALUATE
END-PERFORM
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Wed Nov 09, 2011 5:05 pm    Post subject: Reply to: When i read array i get only the last stored value
Reply with quote

Morning Umey!

I like:

Code:
read-the-file-header - contains read
check-the-file-header - abend if not header, or header data not good
priming-read - contains read
check-data-or-trailer - abend if not data or trailer
first-record-setup - save anything needed from record for comparison processing

if not file-is-good-but-empty
    process-file-until-trailer-or-eof - abend if file is not in logical sequence

if eof
    file-is-stuffed - abend

process-trailer - abend if trailer not good
closing-read - contains read
check-for-eof - abend if not eof


Keeps (nearly) all the "housekeeping" away from the business logic.

Of course, there may be a dumb error-prone system without headers and trailers on the files, so after a battle to get them on, some of the "normal" stuff comes out :-)

The "cute" SET to 1, SET down by one is to "avoid" leaving the index "one too high" when the table is stored. Yuk :-) Just add to a count of entries (starting from zero) every time you add an entry to the table. Otherwise, if you store nothing in the table, the index is "shot".
Back to top
View user's profile Send private message
CaptBill

New User


Joined: 28 May 2009
Posts: 15
Location: Oklahoma City, OK USA

PostPosted: Fri Nov 11, 2011 7:48 am    Post subject:
Reply with quote

It has been a very long time since I wrote any COBOL code. I have one question: Where do you set the initial value of the index? I don't see it set anywhere other than up by 1.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 743
Location: Germany

PostPosted: Tue Nov 15, 2011 4:13 pm    Post subject:
Reply with quote

@ Bill

Morning Sir, also nice way.

@ CaptBill

>> It has been a very long time since I wrote any COBOL code.

Same for me. From summer last year till now i'm only using the one and only high level programming language named Assembler.

Where are you looking for that index. My post or the post from Bill.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Tue Nov 15, 2011 5:11 pm    Post subject: Re: When i read array i get only the last stored value as ri
Reply with quote

bhavya_sha wrote:

Code:
SET  CHASS-INDX       to  1
SET  CHASS-INDX       down  BY  1

PERFORM S02-READ-R1711J2
PERFORM UNTIL END-OF-R1711J2
SET  CHASS-INDX       UP  BY  1
MOVE PCHFS-IDCHNRS    TO  PCHWS-IDCHNRS(CHASS-INDX )
MOVE PCHFS-IDCHASNR   TO  PCHWS-IDCHASNR(CHASS-INDX )
PERFORM S02-READ-R1711J2


I think the question was about this code. The initialisation is to set the index to one (because you can't set it to zero) and then to set it down by one and hope to remember never to use it with that value. Then no thinking needed about where to set the index UP for storing data for each record.

Well, thinking was needed as if there is no data on the file, the index will be "zero" so pointing outside the table at the storage before it.
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 Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts Access SQLCA fields inside a stored p... gangapd DB2 4 Thu Oct 27, 2016 10:20 am
No new posts CICS VSAM RLS READ akodakka CICS 3 Tue Oct 04, 2016 3:09 pm
No new posts Multi row fetch - "for read only... Nileshkul DB2 3 Sun Aug 14, 2016 12:52 am
No new posts Is possible to call subprogram from c... cmsmoon COBOL Programming 3 Fri Aug 05, 2016 6:46 pm


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