IBM Cognos and Motio Best Practices Blog

How to Identify Cognos Reports with Embedded SQL

Posted by Kevin Strong on Wed, Sep 07, 2016 @ 09:30 AM
Find me on:

A common question that keeps getting asked of the MotioPI Support Staff is how to identify IBM Cognos reports, queries, etc. that utilize in-line SQL in their specifications. While most reports leverage a package to access your data warehouse, it is possible for reports to run SQL statements directly against the database, bypassing your package. Let's talk about why it's important to know which reports have embedded SQL.


Why it's Important to Identify Cognos Reports with Embedded SQL

Due to the nature of hard-coded SQL statements, they require continual oversight and maintenance. In fact, if you make changes in your database it can be almost impossible to identify which reports have assumptions built in to their in-line SQL. Until they fail to run that is. Because of how difficult it is to maintain reports with embedded SQL, it is imperative to identify them so you can provide them the extra attention they require. This attention can take the form of removing the embedded SQL or updating the SQL to conform with changes to your data warehouse. Let's explore how to use MotioPI to identify these "special" reports.

How to Use MotioPI to Find Cognos Reports with Embedded SQL

The Search & Replace Panel in MotioPI is designed to search over the specifications of your report, identify reports that match criteria set by you, and even perform simple changes on a set of Cognos objects. Today we will utilize the search feature of Search & Replace to quickly identify all reports that use embedded SQL so you can validate their contents, convert them to use the model, or remove them from production altogether.

  1. Open the Search & Replace panel in MotioPI. If needed, narrow down your search to only cover sections of your content store, which can be particularly helpful if you are only concerned with a subsection of your content store or are concerned about the speed of your search in MotioPI. To Narrow, select the "Narrow" button. Narrow in Search and Replace
    Click to enlarge
  2. Select the files or folder that you want to conduct your search in and then select the ">>" button.
    Select Cognos Files to Search
    Click to enlarge
  3. In the search column, you will enter a search term that searches for SQL statements in your report specifications. Select the checkbox in the column button labeled [a-z]* to make the Search & Replace Panel perform a regular expression search. This enables you to perform more complex searches than a regular search would otherwise allow. **Note, Regular Expression search may appear a bit complicated. Scroll to the bottom of the blog for a full description or just continue to follow along. Enable Regex Search in Cognos
    Click to enlarge
  4. Enter in “(?sui)^select.*from” (without quotes) in the search field.
    Enter Regex Expression in Cognos
    Click to enlarge
  5. Press the "Search" button. 
    Submit Search
    Click to enlarge
  6. MotioPi will return all reports that contain embedded SQL from your search.
    View Results
    Click to enlarge
  7. Note that you can mouse over a snippet to see the full text of your SQL.
    View SQL text
    Click to enlarge
  8. Once you have located all of your reports with embedded SQL, you can document them using the export feature in MotioPI (File->Export output), move them to one location using MotioPI so that you can easily locate them in the future, or even perform simple transformations on the spec using the "Replace" feature of the Search & Replace Panel.


CONCLUSION:

That is how you can use the Search & Replace panel in MotioPI to identify all reports with embedded SQL. You may get a few false positives using this technique, but that is done so that MotioPI does not miss any reports with embedded SQL. You can also narrow your search terms so that you only search for the exact syntax of your SQL statements. If you have any questions about how to best use the Search & Replace Panel, just ask below in the comments, I’m always happy to share any Cognos knowledge I may have!

Get Your PI Pro Trial Here. Now. Free.

**Explanation of Regular Expression Search Term

A regular expression, or "regex search" is a type of search that enables wildcards, and/or matches, and other powerful text searching tools. MotioPI uses Java’s implementation of regular expression to empower you to accurately and quickly get detailed information about report specifications. The specific regex term ‘(?sui)’ used in the example above, modifies how Java performs it’s regex search while the * is a wildcard, meaning match a variable number of any characters. The "select" and "from" match the words, select and from, just as you would expect them to. You can see Oracle’s regex documentation here, and there are a host of other great tutorials online for the truly inquisitive!

Tags: Cognos management, Cognos admin tools, IBM Cognos, motiopi