Deal of the Day

Friday, 8 July 2011

SQL where Clause (Row Value Expressions)


Hi Guys,


Again thanks to Issak (my linkedin Friend) who made me re-call the new feature which was introduce in V5R4 for SQL Where clause
Quoting his words.
SQL WHERE clause usually checks if a condition is true, false or unknown. In the past, each condition was evaluated for a single value. Starting with V5R4 groups or "rows" of values can be evaluated at once. These groups of values are called "row value expressions." 


Below is a simple example with constants: 

SELECT * FROM DEPTBL WHERE (DEPT, BRANCH)=('Shipping', '0012M')

The number of columns must be equal and of compatible data types. 

Statement provides the same result as 

SELECT * FROM DEPTBL WHERE DEPT='Shipping' AND BRANCH='0012M' 


Please note the parentheses usage in first example. 

The same technique applies to IN (SELECT…) predicate. However a constant list is not allowed when using a row value expression in this case. 

This saves some coding, but could look confusing in the beginning. It is just the matter of preferences.



Do write me @ iSeriesblogs@gmail.com for any query or you can simply post comments below.

Happy Learning


Tuesday, 5 July 2011

OLAP Functions in i-Series


 Hi Guys, 
One of my Linkedin friend asked me about OLAP Functions in i-Series, So just thought of writing a brief on OLAP.

OLAP functions in i-Series

 IBM gave developers an impressive set of Online Analytical Processing (OLAP) tools to aid with common ranking and numbering issues. The significance of these OLAP tools lies in the amount of work they do and the time it will save database programmers.

ROW_NUMBER
To start, the ROW_NUMBER is a huge blessing as it finally furnishes SQL with a built-in counter function. Here's a trivial example that adds a row number column to a result set:
Insert Into OrderItm
Select OrderNo,
       Row_Number() Over (Partition By OrderNo
                          Order By OrderNo,ItemNo),
       ItemNo,
       QtyOrdered,
       SalePrice


In this scenario, ROW_NUMBER will continually increment the ItemSeq field over all orders that are being imported and counter would get reset for every change in order number.

SQL Stored Procedures


Hi Guys,

Today I am writing about Stored Procedures. What are stored Procedures, How to write them, How to compile and how to call them?

Stored Procedures

Stored procedures are programs that are called from SQL. These programs can be written using the SQL procedure language, but they may also be written using RPG.

So how do you write SQL Procedure? It is simple. You just need to write SQLRPGLE with “CREATE PROCEDURE” SQL Statement

Example 1.

C/Exec SQL
C+CREATE PROCEDURE GetName 

C+ (IN ProgLang CHARACTER(10), 

C+IN Comp CHARACTER(20), 

C+INOUT FOUND INTEGER(4)) 

C+LANGUAGE SQL 

C+SELECT COUNT(*) INTO FOUND FROM TestLib/NameData 

C+WHERE TechLang = ProgLang AND Employeer = Comp
C/End-Exec

How to compile the Procedure?
You can compile the above code like any other SQLRPGLE code

How to call above procedure?
Create another RPGLE code as below
D GetName        PI
     D  ProgLang                     10A
     D  COMP                         20A
     D  Found                         4 
.
.
.
.
    Call GetName( :EMPID, :Comp, :Found);

Example 2.

c/EXEC SQL                                                
c+ Create procedure OrderSumm(                            
c+   in    partnerID            NUMERIC(5,0),             
c+   in    storeNumber          NUMERIC(7,0) )            
C+ LANGUAGE RPGLE NOT DETERMINISTIC                       
c+ READS SQL DATA                                         
c+ EXTERNAL NAME EXTPGM01                                 
c+ PARAMETER STYLE GENERAL                                
c/END-EXEC                      

Above code will be called as below

Create another RPGLE code as below
D OrderSumm        PI
     D  PartnerID                     5
     D  StoreNumber                   7
.
.
.
.
    Call OrderSumm( :PartnerId, :StoreNumber);

In example 2 when OrderSumm is called, it in returns call further a new program “EXTPGM01”

Do write me @ iSeriesblogs@gmail.com for any query or you can simply post comments below.

Happy Learning

Monday, 4 July 2011

XML Parsing using XML-INTO


Something on XML-INTO

IBM has introduce a new OP-Code XML-INTO, which has make XML parsing as smooth as butter..:)
Steps to use XML-INTO
1.        Define a Data structure or array of data structures that matches the layout of XML document.
2.        Run XML-INTO (This loads the values from XML to Data Structure

Below sample code will help you write simple XML Parsing code.


D qualName        DS                   QUALIFIED
D   FrstName                    10A
D   LastName                    10A

D EmpInfo        DS                   QUALIFIED
D* Employee Name
D   EMPNme                             LIKEDS(qualName)
D* Manager Name
D   MName                              LIKEDS(qualName)

D* Manager Last Name
D MLName          S             10A    VARYING

 //  Assume file Emplpoyee.xml contains the following lines:
 //<empinfo>
 // <EMPNAME><Frstname>Scott</Frstname><LastName>Sherbert</LastName></EMPNAME>
 // <MNANE Frstname="Ken" LastName="Mahajan"></MNAME>
 //</empinfo>

 /free
    xml-into empInfo %XML('Employee.xml' : 'doc=file');
 // EMPInfo.EMPNme.Frstname='Scott' EMPInfo.EMPNme.Lastname = 'Sherbert'
 // EMPInfo.MName.Frstname='Ken' EMPInfo.MName.Lastname = 'Mahajan'

 // Parse the "empinfo/Mname/Lastname" information into variable
 // "MLName".  Use the "path" option to specify the location
 // of this information in the XML document.
  xml-into MLName %XML('Employee.xml'
                   : 'doc=file path=empinfo/MName/lastname';
 // MLName = 'Mahajan'



Do write me @ iSeriesblogs@gmail.com for any query or you can simply post comments below.

Happy Learning

Sunday, 3 July 2011

Advantages and Disadvantages of AS400


Hi Guys, 

One of my friend over Linkedin want to know the advantages and disadvantages of AS400. So thought of sharing the same.
Advantage of AS400
The main advantages of AS400 over other are
 1. Stability
You would have sometime re-booted your desktop twice or thrice a day. But can you afford to do the same with your Servers. I know few organizations where IT admin are not aware of AS/400 Machine reboot date
2.        Integration
Using AS400 you need not worry about integration of database, Programing languages to use
Will the security system work with the database and will the database work with the operating system, etc are questions that do not apply to AS/400. It is amazing how much time can be invested in making these things work together, but on iSeries (as with AS/400 and S/38), the question is simply irrelevant.
3.        Security
OS/400 is an object orientated operating system it is virtually immune to viruses.

Disadvantage of AS400
To count disadvantages of AS400, there would be less. Still to count, below are the few disadvantages of AS400
1.       Cost - 
          The hardware costs for NEW machines are significantly higher than other platforms.
2.       Developer Resource – 
        Nowadays RPG Developer are a rare breed of developers which comes with high Dollar value as compare to other development languages like JAVA
3.       Mindset - 
        The biggest problem is mindset of people. An AS400 is seen as a clumsy box capable of only green screen applications and suitable only for large businesses having large cash transactions. This is simply untrue. The box needs almost no supervision. All you ever have to do once it's loaded up is change the backup tapes. BUT, it is perceived as old technology when in fact it is probably more robust and cutting edge than most of it's competitors.


Do write me @ iSeriesblogs@gmail.com for any query or you can simply post comments below.

Happy Learning

Few SQL Questions


Hi Guy, 
This time I am back with Few SQL Questions....

What will runsqlstm will do?
If we want to execute set of SQL statement then we can write all the SQL statement to be including with the source.
Type as SQL
Only insert, update and delete and no select is allowed.
Then use STRSQLSTM to execute the program
RUNSQLSTM   SRCFILE (LIB/TEST) SRCMBR (SQL01) COMMIT (*NONE)

Saturday, 2 July 2011

Embedded SQL in RPGLE (SQLRPGLE)


Hi Guys,
Today I am here with Embedded SQL Program.

How to write embedded SQL Program.

SQLRPGLE is very simple if we can understand the flow of program. SQLRPGLE basically consist of below keyword

1.        Declare Cursor
2.        Open Cursor
3.        Fetch Cursor
4.        Close Cursor