Newsletters   Subscriptions  Forums  Store  Media Kit  About Us  Contact  Search   Home 
fhg
Volume 4, Number 3 -- February 4, 2004

How Many Records Did SQL Delete?


Hey, Ted:

I have an RPG IV program with an embedded SQL DELETE statement. Is it possible for my program to determine how many records are deleted when the statement executes?

--Tom


DB2/400 returns this information to you through a subfield of the SQL communications area (SQLCA), a data area that is automatically included in your RPG program when you compile. You can refer to this subfield by either of two names: SQLERRD(3) or SQLER3. When a DELETE, UPDATE, or INSERT operation completes normally, DB2 updates the subfield with the number of rows that qualified for the operation.

C/exec sql                              
C+             delete from somefile   
C+              where company = :company
C/end-exec                              
 /free                                  
            if SQLER3 > *zero;          

I understand that RPG is the only compiler that includes the SQLCA by default. According to the SQL Reference, the COBOL, C, PL/I, and FORTRAN programs must use the SQL INCLUDE command to reference the SQLDA. In the following short COBOL program, the SQLCA is included in the working-storage section.

Identification division.                   
Program-ID.    SQL005.                     
                                           
Environment division.                      
                                           
Data division.                             
Working-storage section.                   
01  Company     pic s999   packed-decimal. 
01  EmptySet    pic x.                     
                                           
    Exec SQL include SQLCA end-exec.       
                                           
Procedure division.                        
Main-logic.                                
    Exec SQL                               
         set option commit=*none           
    end-exec.                              
    Exec SQL                               
         delete from qtemp/cuxt
          where company = 99   
    end-exec.                  
    if SQLERRD(3) > zero       
       move "N" to EmptySet    
    else                       
       move "Y" to EmptySet    
    end-if.                    
    goback.                    

For more information about the SQLCA, consult the DB2 reference on IBM's Web site.

--Ted

Sponsored By
COMMON

COMMON Spring 2004 IT Education Conference & Expo
San Antonio, Texas
May 2-6, 2004

Conference activities will take place in the Marriott River Walk and the Henry B. Gonzalez Convention Center.

Click here for online registration and hotel reservations.

The conference includes a special focus on Linux Education.

Browse the Online Session Guide for the conference.

View an online video on COMMON conferences and other member benefits.

Download a PDF of the Conference Invitation and the Conference Preview brochure. (Right-click on these links and select "Save Target as" to download.)

First time attending a COMMON conference? You need the First-Timers' Kit --information that will "show you the ropes."

COMMON is the best value in IT education, so don't miss out!
Click and visit www.common.org for details!


Editors: Howard Arner, Joe Hertvik, Ted Holt,
Shannon O'Donnell, Kevin Vandever
Managing Editor: Shannon Pastore
Contributing Editors: Raymond Everhart, G. Wayne Hawks,
Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

THIS ISSUE
SPONSORED BY:

ASNA
COMMON
WorksRight Software
Client Server Development
Twin Data


BACK ISSUES

TABLE OF
CONTENTS
Setting up an OS/400 HTTP Firewall Using Reverse Proxy

How Many Records Did SQL Delete?

Recovering from WDSc Errors

Admin Alert: Alternate Ways to Ensure a Subsystem Ends

OS/400 Alert: alphaWorks and Homeland Security



Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, 50 Park Terrace East, Suite 8F, New York, NY 10034
Privacy Statement