SQL IF EXISTS in RPGIV

[Pages:10]SQL IF EXISTS in RPG IV

SQL iQuery Scripting

with

Bob Cozzi

bob@ Twitter: @bobcozzi

? 2017 Cozzi Productions, Inc.

iQ



Transforming Db2 into Excel, JSON & more with SQL

Your Data

Programming with SQL iQuery

Modern SQL Scripting

Your Data with SQL iQuery

TXT

CSV

{JSON}

,

*Write One and Done!

? 2016 Cozzi Productions, Inc.

Results are blah

iQ



* Write one SQL statement, output to any supported format.

Download this Presentation

What is SQL "IF EXISTS"

? Tests if the subselect produces any rows ? If rows are returned, the IF test is true ? If no rows are returned, the IF test is false ? SQL UDFs and "stored" Procedures support IF Exists tests ? SQL iQuery Supports IF Exists tests ? What about RPG?

SQL iQuery Script

If a record exists that matches the WHERE clause, then DO.

RPG IV IF Exists

5770ST1 V7R3M0 160422 4

Create SQL ILE RPG Object

IFEXISTS

DIAGNOSTIC MESSAGES

EXEC SQL IF EXISTS (SELECT * FROM DATALIB.ORDHIST

5770ST1 V7R3M0 160422

Create SQL ILE RPG Object

IFEXISTS

DIAGNOSTIC MESSAGES

MSG ID SEV RECORD TEXT

SQL0199 30

4 Position 22 Keyword IF not expected. Valid tokens: ( CL

END GET SET CALL DROP FREE HOLD LOCK OPEN WITH ALTER BEGIN.

What Can We Do in RPG?

? RPG IV does not support IF EXISTS ? Using RPG and SQL we can work around this limitation

How to Code "IF EXISTS" in RPG IV with SQL

? IF EXISTS does not exist in RPG

? However RPG does have IF statement itself

? RPG supports the SQL WHERE EXISTS clause ? We can combined RPG with SQL to simulate the "IF EXISTS" condition

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download