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
 

 

VSAM status code 46

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM
View previous topic :: :: View next topic  
Author Message
Sengar.80

New User


Joined: 08 Jul 2011
Posts: 10
Location: INDIA

PostPosted: Mon Aug 08, 2011 6:37 pm    Post subject: VSAM status code 46
Reply with quote

Hi,

I am facing VSAM status code 46 in one of my programs. In the spool its saying logical error occured.

Below is the code of my program :

PERFORM START-KEY-PARA THRU START-EXIT.
MOVE 0 TO TABLE-LEN.
PERFORM LOAD-TABLE VARYING INDEX FROM 1 BY 1
UNTIL TABLE-ID > 4386 OR
TABLE-LEN > 1000.

START-KEY-PARA.

MOVE '4386 #1' TO WS-VSAM-KEY.
MOVE WS-VSAM-KEY TO T-VSAM-KEY.
START VSAM-FILE KEY IS GREATER THAN T-VSAM-KEY.

IF FILE-STAT = '00' OR '04'
NEXT SENTENCE
ELSE
IF FILE-STAT = '10' OR '23'
DISPLAY 'ERROR'.

VSAM-READ.

READ VSAM-FILE NEXT.
MOVE SPACES TO WS-VSAM-KEY.
MOVE T-VSAM-KEY TO WS-VSAM-KEY.

IF FILE-STAT = '00' OR '04'
NEXT SENTENCE
ELSE
IF FILE-STAT = '10'
DISPLAY 'ERROR'.

START-EXIT. EXIT.

LOAD-TABL.

ADD +1 TO TABLE-LEN.
IF TABLE-LEN GREATER THAN 1000
DISPLAY 'VSAM TABLE 4386 OVERFLOW'
ELSE
MOVE WS-VSAM-KEY TO WS-TABLE(INDEX).
PERFORM VSAM-READ.
LOAD-EXIT. EXIT.

In the above code, I am starting the key from '4386' and then reading the records from there onwards and uploading them into an array. It reads and loads them into the table, but when it encountered more than 4386 say 5000 from the VSAM file, it throughs Status code 46.

Thanks.
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Mon Aug 08, 2011 6:54 pm    Post subject: Re: VSAM status code 46
Reply with quote

Can you please copy/paste your code, not re-write it. There are many typo's which we won't want to wade through.

Use the Code button to retain the formatting of anything that you want to retain formatting for. Use Preview to check that it looks how you want.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Mon Aug 08, 2011 6:59 pm    Post subject:
Reply with quote

File status 46 in the COBOL Language Reference manual is described as
Quote:
A sequential READ statement was attempted on a file open in the input or I-O mode and no valid next record had been established because: 1. The preceding READ statement was unsuccessful but did not cause an at end condition 2. The preceding READ statement caused an at end condition.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1219
Location: Israel

PostPosted: Mon Aug 08, 2011 7:56 pm    Post subject: Reply to: VSAM status code 46
Reply with quote

Sengar.80 wrote:
IF FILE-STAT = '00' OR '04'
NEXT SENTENCE
ELSE
IF FILE-STAT = '10'
DISPLAY 'ERROR'.
That's very nice!
You reach end of file, shout ERROR but keep reading ????
What do you expect should happen ?
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Tue Aug 09, 2011 5:09 am    Post subject: Re: VSAM status code 46
Reply with quote

Sengar.80 wrote:
[...]
Code:
PERFORM START-KEY-PARA THRU START-EXIT.
MOVE 0 TO TABLE-LEN.
PERFORM LOAD-TABLE VARYING INDEX FROM 1 BY 1
                                 UNTIL TABLE-ID > 4386 OR
                                 TABLE-LEN > 1000.

START-KEY-PARA.

MOVE '4386                        #1' TO WS-VSAM-KEY.
MOVE  WS-VSAM-KEY TO T-VSAM-KEY.
START VSAM-FILE KEY IS GREATER THAN T-VSAM-KEY.

IF FILE-STAT = '00' OR '04'
   NEXT SENTENCE
ELSE
  IF FILE-STAT = '10' OR '23' 
  DISPLAY 'ERROR'.

VSAM-READ.

READ VSAM-FILE NEXT.
MOVE SPACES TO WS-VSAM-KEY.
MOVE T-VSAM-KEY TO WS-VSAM-KEY.

IF FILE-STAT = '00' OR '04'
   NEXT SENTENCE
ELSE
  IF FILE-STAT = '10' 
  DISPLAY 'ERROR'.

START-EXIT. EXIT.

LOAD-TABL.

ADD +1 TO TABLE-LEN.
IF TABLE-LEN GREATER THAN 1000
    DISPLAY 'VSAM TABLE 4386 OVERFLOW'
ELSE
    MOVE WS-VSAM-KEY TO WS-TABLE(INDEX).
PERFORM VSAM-READ.
LOAD-EXIT. EXIT.
[...]



Hi Sengar.80,

There is a great deal wrong with the code you have posted.

In no particular order: INDEX is a Cobol reserved word, at least in Enterprise Cobol. If you are using a different compiler, maybe it is not reserved (I haven't checked), but if you move to Enterprise Cobol, your program will not compile.

You identify error situations and gaily continue. As Marso has pointed out, this is the reason for your 46.

You are testing twice for > 1000 in your table - there should be no need for twice.

You are displaying error messages, but two of them are the same, with nothing to indicate in the Display which is which.

You include VSAM-READ in your perform thru of START-KEY-PARA thur START-EXIT. You then seperately perform VSAM-READ. This is not good practice, as it is prone to errors when anyone picks up the program again.

You initialise WS-VSAM-KEY before immediately moving something to it. This is pointless, and confusing - someone looking at the code will wonder what is missing in between.

You test your file status against literals. Much better to put 88's on your file status with meaningful names and use those.

The paragraph LOAD-TABL is not spelled the same as the perform, LOAD-TABLE.

You have LOAD-EXIT, but this is not part of a perform thru, not good practice.

You reference T-VSAM-KEY before you know that it is valid to do so.

You don't cater well for the file status codes, or display the values received for problem determination.

You data names and procedure names could be, and should be, much more meaningful.

There is more, but I think you need to do some fixing-up first.

I have spent a few minutes, with Wordpad, re-arranging and touching up your code a little. It is nowhere near complete, but then it's not my job.

Code:
    PERFORM START-KEY-PARA
    PERFORM PRIMING-READ-OF-VSAM-FILE
    MOVE 0 TO TABLE-LEN
    PERFORM LOAD-TABLE VARYING INDEX FROM 1 BY 1
                                     UNTIL ( TABLE-ID > 4386 )
                                       OR  ( TABLE-LEN > 1000 )

    do some other stuff and eventually get to a STOP RUN/GOBACK before dropping into the performed paragraphs


START-KEY-PARA.

    MOVE '4386                        #1' TO WS-VSAM-KEY
    MOVE  WS-VSAM-KEY TO T-VSAM-KEY

    START VSAM-FILE KEY IS GREATER THAN T-VSAM-KEY

    IF NOT VSAM-FILE-STATUS-OK-ON-START
        DISPLAY 'START ERROR ON VSAM-FILE, STATUS IS>" FILE-STAT "<"
        DISPLAY 'START KEY WAS>" T-VSAM-KEY "<"
        abend
    END-IF
    .

PRIMING-READ-OF-VSAM-FILE.

    PERFORM VSAM-READ
    .

VSAM-READ.

    READ VSAM-FILE NEXT

    IF NOT VSAM-FILE-STATUS-OK-ON-READ
        DISPLAY 'READ ERROR ON VSAM-FILE, STATUS IS>" FILE-STAT "<"
        DISPLAY 'LAST VALID RECORD WAS>" WS-VSAM-KEY "<"
        abend
    END-IF

    MOVE T-VSAM-KEY TO WS-VSAM-KEY
    .

LOAD-TABL.

    ADD +1 TO TABLE-LEN

    IF TABLE-LEN GREATER THAN 1000
        DISPLAY 'VSAM TABLE 4386 OVERFLOW'
        DISPLAY 'CURRENT VSAM-FILE KEY IS>" T-VSAM-KEY "<"
        abend
    ELSE
        MOVE WS-VSAM-KEY TO WS-TABLE(INDEX)
    END-IF

    PERFORM VSAM-READ
    .


Note, I will have introduced "errors" and "shortcomings" in doing this. I've taken off all your end-of-sentences, but not done all the end- constructs. The test on the perform for > 1000 is no longer needed, as in the other place where it is tested there is now a "codeless" abend. I am inconsistent with the use of the vsam key (ws vs T), but since I can't see the definitions, I can't guess.

With no exit paras and no perform thrus, this might not meet with your site standards, but neither did the original.
Back to top
View user's profile Send private message
Sengar.80

New User


Joined: 08 Jul 2011
Posts: 10
Location: INDIA

PostPosted: Tue Aug 09, 2011 6:02 pm    Post subject:
Reply with quote

Hi,

Sorry to all of you, I got the status code 46 not for the VSAM file, it was for a sequential file used in the same program.

I got confused after seeing status code 46, I thought its only for VSAM file and was concentrating on the START Key code in the program. Actually I forgot to code GO TO statement to terminate the para at the end of the file after READ statement for a sequential file, hence after the AT END reached it was again trying to read the record.

I resolved the issue, sorry once again.

Thanks.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Tue Aug 09, 2011 6:09 pm    Post subject: Reply to: VSAM status code 46
Reply with quote

Well, you will get a 46 for your VSAM.

I'm sure there is a good chance any sequential file processing has the same sort of faults.

Are you not concerned if you say 46 is VSAM only and you fixed a different file...?
Back to top
View user's profile Send private message
Sengar.80

New User


Joined: 08 Jul 2011
Posts: 10
Location: INDIA

PostPosted: Tue Aug 09, 2011 7:09 pm    Post subject:
Reply with quote

Hi,

Yes I got 46 for sequential file not for VSAM. The code I coded for reading the VSAM and uploading into table was correct but when it came to read a sequential file down the line in the same program, I did not handle the at end properly for sequential file.

I misunderstood that we get 46 only for VSAM, thats why only checking the VSAM code in the program neglecting the other read like sequential file.

Thanks.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Tue Aug 09, 2011 7:29 pm    Post subject:
Reply with quote

Well, well. If your code is "correct" then everything is OK.

Do you want to look through what I have posted earlier?

Sengar, we explained things about your PARM question, remember? If you are still open-minded, look at your code, then tell me it is OK.

If you still think everything is fine with your code, then I wish your organisation well with your future. They might get lucky.
Back to top
View user's profile Send private message
Sengar.80

New User


Joined: 08 Jul 2011
Posts: 10
Location: INDIA

PostPosted: Tue Aug 09, 2011 10:30 pm    Post subject:
Reply with quote

Hi Bill,

Yes my code is correct. Only thing I did not post the actual fields naming convention on this forum as it is a company code. Example you said you can not define INDEX as index in COBOL. Thats true, I defined with some other variable but surely not INDEX. I put the code here to just tell you what I have coded.

Thanks for remebering me on the PARM stuff.

I took your code which you have pasted above for reading the VSAM file. I did a check but I could not find any fault on what you coded and mine. Both gave the same result as status code 46. You define start-key-para and then priming-read-of-vsam, then vsam-read, then load-table para. Even if you do not define priming-read-of-vsam, that also solve the same purpose. And one more thing, we can put vsam-read para inside the start-key-para and terminate with exit. And we can give start-key-para thru statements or without thru also.

The problem was not on reading and loading the data from VSAM file. The problem was with the sequential file.

Thanks.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Wed Aug 10, 2011 4:17 am    Post subject:
Reply with quote

Hi Sengar80,

You have a problem you will need to overcome to post code in these forums. Unless we see the original code, what you show to us is useless. We are not (although I did) going to go chasing code full of typos.

There is a recent long discussion in the Cobol forum about "best practice". I suggest you read through all of it.

You can stick your read in the middle of a PERFORM THRU, and you can seperately PERFORM that individual paragraph. You can have an exit paragraph which is not part of a PERFORM THRU, etc. If you do this, you have a bad program, which is difficult to understand and to maintain.

For example, someone thinks the vsam read paragraph has got put there by accident (you have no other clues in the code that it should be there, like some sort of convention for ordering the paragraphs) and moves it. Now you have a subtle problem, in that the code still "works", but only mostly.

What is someone sticks a GO TO in your vsam read paragraph? It will "work" when part of the perform through, and not work when performed on its own.

What if someone codes a GO TO for the exit that is not included in a perform thru?

It is up to you. Your code in this example is not good. If you think it is, then it will be difficult for your to learn about good code, and you will continue to write bad code for much longer than is necessary.
Back to top
View user's profile Send private message
Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 961
Location: Richmond, Virginia

PostPosted: Wed Aug 10, 2011 6:44 am    Post subject:
Reply with quote

Quote:
IF FILE-STAT = '00' OR '04'
NEXT SENTENCE
ELSE
IF FILE-STAT = '10'
DISPLAY 'ERROR'.


Why not just say

Code:

IF FILE-STAT = '10'
DISPLAY 'ERROR'.
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 -> JCL & VSAM All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts PL/I code tuning/Performance improvement Virendra Shambharkar PL/I & Assembler 4 Mon Dec 05, 2016 11:57 am
No new posts What is the code in CLIST to enable t... jackzhang75 CLIST & REXX 1 Fri Dec 02, 2016 3:02 am
No new posts IDEAL - Code Retrieval yugendran CA Products 0 Fri Nov 25, 2016 3:27 pm
No new posts BWO option in VSAM blayek CICS 3 Sat Nov 05, 2016 10:47 am
This topic is locked: you cannot edit posts or make replies. Need to code a Rexx PGM sundaram.naveen CLIST & REXX 18 Thu Oct 06, 2016 6:45 pm


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