IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

VSAM status code 46


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
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
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Aug 08, 2011 6:54 pm
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Mon Aug 08, 2011 6:59 pm
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: 1353
Location: Israel

PostPosted: Mon Aug 08, 2011 7:56 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 09, 2011 5:09 am
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
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 09, 2011 6:09 pm
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
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 09, 2011 7:29 pm
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
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Aug 10, 2011 4:17 am
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

Senior Member


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

PostPosted: Wed Aug 10, 2011 6:44 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts run rexx code with jcl CLIST & REXX 15
No new posts Compile rexx code with jcl CLIST & REXX 6
No new posts Access to non cataloged VSAM file JCL & VSAM 18
No new posts Job completes in JES, but the status ... IBM Tools 1
No new posts Merge two VSAM KSDS files into third ... JCL & VSAM 6
Search our Forums:

Back to Top