MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

checking for a value in table.

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
ranga_subham
Intermediate


Joined: 31 Jan 2006
Posts: 255
Topics: 72

PostPosted: Wed Jan 13, 2010 6:38 am    Post subject: checking for a value in table. Reply with quote

Hi,

I have a field in a table in our DB2 database against which I need to check whether date field is having value or not. And, depending on successful return code want to process some other para. I have written the code like below:

Code:

EXEC SQL                                               
    SELECT MATCH_DT                               
      INTO :W-MATCH-DT                       
      FROM DB1.MATCH_TABLE                                 
     WHERE MATCH_ONE = 'ABC123'
       AND MATCH_TWO = 'OLD'     
       AND MATCH_CD = '1000'     
END-EXEC                             

EVALUATE SQLCODE   
    WHEN W-SQL-RC-00
         PERFORM 1000-MOVE-PARA
    WHEN W-SQL-RC-100                   
         PERFORM 2000-ABEND
END-EVALUATE.


How else we can modify the SELECT to not put the values into the host-variable ":W-MATCH-DT"?

Thanks.
_________________
Ranga
*****
None of us is as smart as all of us - Ken Blanchard
Back to top
View user's profile Send private message
papadi
Supermod


Joined: 20 Oct 2009
Posts: 594
Topics: 1

PostPosted: Wed Jan 13, 2010 5:11 pm    Post subject: Reply with quote

Quote:
How else we can modify the SELECT to not put the values into the host-variable ":W-MATCH-DT"?
What are you asking?

Showing some kind of example may help clarify.

Explaining what you want to happen would be more informative than posting what you don't waht. . .
_________________
All the best,

di
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Thu Jan 14, 2010 1:50 am    Post subject: Reply with quote

I am going out on a limb here.

If the date COLUMN is nullable:
if
Code:

WHERE MATCH_ONE = 'ABC123'
  AND MATCH_TWO = 'OLD'     
  AND MATCH_CD  = '1000' 

are not the primary (unique) keys for the table
you run the risk of a -811 (look it up if you don't know) using a singleton select..
you should use a cursor.

and select the primary keys
using a WHERE clause composed of
Code:

WHERE MATCH_ONE = 'ABC123'
  AND MATCH_TWO = 'OLD'     
  AND MATCH_CD  = '1000'   
  AND MATCH_DT IS NULL

other wise if MATCH_ONE, MATCH_TWO and MATCH_CD constitute a unique key, use a singleton select as follows:
Code:

SELECT 1
  INTO :numeric-host-variable
FROM DB1.MATCH_TABLE
WHERE MATCH_ONE = 'ABC123'
  AND MATCH_TWO = 'OLD'     
  AND MATCH_CD  = '1000'   
  AND MATCH_DT IS NULL



If the MATCH_DT column is not nullable, what do you mean by
Quote:
whether date field is having value or not.

_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Thu Jan 14, 2010 7:17 pm    Post subject: Reply with quote

Please post in the appropriate forum (Database) next time.
_________________
....Terry
Back to top
View user's profile Send private message Send e-mail
ranga_subham
Intermediate


Joined: 31 Jan 2006
Posts: 255
Topics: 72

PostPosted: Mon Jan 18, 2010 7:37 am    Post subject: thx Reply with quote

Hi,

Thanks. I wrote a program to check if a SELECT works without a host-variable. It failed during compilation itself.
_________________
Ranga
*****
None of us is as smart as all of us - Ken Blanchard
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group