karthi
karthi

Reputation: 1109

How get one record in DB2 using cics and cobol program

I have a table called room_table

room_no room_status  room_type
-------|-----------|----------
1001   | A         |single
1002   | A         |single
1003   | B         |single

I am using following code in CICS COBOL program but I am getting SQL error code -811

    select room_no 
    from room_table 
    where room_status='A' 
      and room_type ='single'
    fetch first 1 row only

I have used cursor concept too but it returns error code -311

Any idea?

Upvotes: 0

Views: 1109

Answers (3)

mckenzm
mckenzm

Reputation: 1840

-311 is not -811 : Something is wrong with a host variable.

For -811 we would "fetch first row only".

Now,

prior to this feature being available, many coders ignored IBM's warnings and simply allowed -811 as OK, as a value was somehow always returned (albeit without guarantee). I would hope that any such code has long been touched up.

Upvotes: 0

MrSimpleMind
MrSimpleMind

Reputation: 8627

Did you try using DB2 Fetch-first-clause?

replace select first 1 row only with fetch first row only

Upvotes: 0

Bruce Martin
Bruce Martin

Reputation: 10553

This would of been answered before but:

  1. Use a cursor and only fetch the first record, see Cursor
  2. Use group by
       
     Select min(room_no) from  room_table 
      where room_status='A' and room_type ='single'
     group by room_status

Upvotes: 1

Related Questions