• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • How Many Records Did SQL Delete?

    February 4, 2004 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

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    ARCAD Software

    New Podcast Dedicated To IBM i DevOps!

    The topic of this IBM i DevOps TechTalk is “Moving to Git.” It features Jeff Tickner, Ray Bernardi, and Alan Ashley as they discuss what is Git and how to best use Git with the IBM i. Listen in for tips on:

    • Key Git Advantages
    • Git Considerations for a successful implementation
    • Working with branches and automated merges
    • Getting started and ARCAD’s Centralized approach

    Listen NOW

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Quadrant Updates Fax Server for OS/400, Other Platforms OS/400: There Are Always Possibilities

    Leave a Reply Cancel reply

Volume 4, Number 3 -- February 4, 2004
THIS ISSUE
SPONSORED BY:

ASNA
COMMON
WorksRight Software
Client Server Development
Twin Data

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

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Unattended IBM i Operations Continue Upward Climb
  • VS Code Is The Full Stack IDE For IBM i
  • Domino Runs on IBM i 7.5, But HCL Still Working on Power10
  • Four Hundred Monitor, March 6
  • IBM i PTF Guide, Volume 25, Number 11
  • You Ought To Be Committed
  • Thoroughly Modern: What You Need to Know About IBM i Security
  • Spring Brings Events To IBM i Community, And More
  • As I See It: AI-AI-O
  • IBM i PTF Guide, Volume 25, Number 10

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2023 IT Jungle