---
title: "How to Optimize COBOL-DB2 Program: 10 Killer Tips"
description: "The best explained tips to write awesome COBOL DB2 program. These tips you can apply now with little effort. Read more."
url: https://srinimf.com/2014/07/08/10-killer-tips-for-cobol-db2-developers/
date: 2014-07-08
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2014/07/pexels-photo-7647921.jpeg?fit=1880%2C1253&ssl=1
categories: ["COBOL", "DB2 V10"]
tags: ["COBOL Tips and Tricks", "DB2 Tips and Solutions"]
type: post
lang: en
---

# How to Optimize COBOL-DB2 Program: 10 Killer Tips

1. The SQLCODE must be checked after every SQL statement. [The SQL for beginners](http://bit.ly/2iCCHy8) is highly useful course, if you would like to know more.
2. Every program must include SQLCA(only once), and DCLGEN for each table
3. Every program must have abend routine. In this routine make sure to use,SQLCODE and SQLSTATE to display
4. Never code SELECT * in program. It takes unnecessary I/O, and in turn more CPU usage
5. Make sure all Nullable columns must use Indicator variable along with host variable
6. Better use scalar functions, when you expect nulls – as below example
7. For example:

   ```
   SELECT IFNULL(AVG(SALARY), 0)    
   FROM EMP    
   WHERE WORKDEPT = 'XYZ'
   ```

8. Minimize the no of times Opens or Close a cursor
9. During SELECT,INSERT and UPDATE always use counters in Program. When problem comes, we can easily trace back to root.
10. SQLERRD(3), it will be updated, when INSERT,UPDATE and DELETE takes place. **THIS IS NOT POPULATED WHEN MASS DELETES OCCURRED WITHOUT WHERE CLAUSE. **For example deletes due to DELETE CASCADE.

Related[Ensure These 4 Steps Before You Run DB2 Load](https://srinimf.com/2015/12/23/4-different-steps-that-you-need-to-do-before-load-process-in-db2/)

---

**More resources to read**

- [Decoding data mining and ETL with MS-Excel 2013](http://bit.ly/2hMkNoj)

Related[COBOL-DB2 Program: SQLCA is Not Mandatory Why](https://srinimf.com/2016/02/21/how-to-get-sqlcode-in-db2-cobol-program-without-sqlca/)

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2014%2F07%2F08%2F10-killer-tips-for-cobol-db2-developers%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2014%2F07%2Fpexels-photo-7647921.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=How%20to%20Optimize%20COBOL-DB2%20Program%3A%2010%20Killer%20Tips)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2014/07/08/10-killer-tips-for-cobol-db2-developers/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2014/07/08/10-killer-tips-for-cobol-db2-developers/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2014/07/08/10-killer-tips-for-cobol-db2-developers/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2014/07/08/10-killer-tips-for-cobol-db2-developers/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20How%20to%20Optimize%20COBOL-DB2%20Program%3A%2010%20Killer%20Tips&body=https%3A%2F%2Fsrinimf.com%2F2014%2F07%2F08%2F10-killer-tips-for-cobol-db2-developers%2F&share=email)
-

### Like this:

Like Loading…
