Skip to main content

Posts

Showing posts from September, 2020

READ vs SQL SELECT, A Quick Performance Test - Part 2

We have seen the comparison between READ and SQL SELECT (with CURSOR & Fetch one record at a time) and SQL SELECT has run about 30% less time than READ (70% of READ). Click Here to see more details on this. However, Fetching more number of Records into a Multi Occurrence Data Structure and looping the data through DS should run even faster. We would be using same Table created in Part - 1, Please see Part - 1 using the above link for these details. We will see a sample program with FETCH multiple rows into DS and compare the results.  Program with SELECT (PPSQL1): Now, This program took just 2 seconds to read one million records, which is much faster than using READ (> 70% Faster) and SELECT with single record for every FETCH (> 60% Faster). Please note that,  File Size and Data are same as used in the Part - 1.  

READ vs SQL SELECT, A Quick Performance Test

READ vs SQL SELECT With no doubt, SQL is the advanced and efficient way for operations (Read, Write, Update or Delete) on Tables (or Files) on IBM i.  With the use of Embedded SQL programming (SQLRPGLE), it is efficient to use SELECT to read the data from a table compared to using READ.  Here is the result from a quick performance test between READ and SELECT to read One million records from a table. Below are few points to consider about the test before we see the results.  Created Physical File (using DDS) for the use in RPGLE with READ Operation.  Created Table from SQL Session for the use in SQLRPGLE with SQL SELECT Operation. Both the files has same number of fields, length and same number of records. Both Programs are called from a new Interactive Session immediately after login. Let's see the code used to create File/Table and Program.  Physical File (PPTESTFILE): Table (PTESTTABL): Inserted one million records (same data) to both the files. And, Table is...

CHAIN vs SETLL/READE, What to use & When?

CHAIN vs SETLL/READE CHAIN & READE, These are the two Operations that are used to read the data from a database file using a specified Key data.  SETLL Operation is used to point to the record provided in the Key data.  How do we use?  CHAIN CHAIN (Search Arguments/Key Fields) FILENAME ; IF %FOUND(FILENAME) ;  // Required Program Logic ENDIF ; Click Here to find more details about CHAIN. SETLL/READE SETLL (Search Arguments/Key Fields) FILENAME ;  READE (Search Arguments/Key Fields) FILENAME ; DOW NOT %EOF(FILENAME) ; // Required Program Logic READE (Search Arguments/Key Fields) FILENAME ; ENDDO ; SETLL SETLL (Search Arguments/Key Fields) FILENAME ;  IF %FOUND(FILENAME) ; // Required Program Logic ENDIF ;  Click Here to find more details about SETLL/RPGLE. Now, What to use When?  If the Data base file used has Unique key constraint and/or if only one/first matching record is required by the Program, CHAIN would be the best choice.  If th...

All about READ in RPGLE & Why we use it with SETLL/SETGT?

READ READ is one of the most used Opcodes in RPGLE. As the name suggests main purpose of this Opcode is to read a record from Database file. What are the different READ Opcodes? To list, Below are the five Opcodes.  READ - Read a Record READC - Read Next Changed Record READE - Read Equal Key Record READP - Read Prior Record READPE - Read Prior Equal Record We will see more about each of these later in this article. Before that, We will see a bit about SETLL/SETGT .  SETLL (Set Lower Limit) SETLL accepts Key Fields or Relative Record Number (RRN) as Search Arguments and positions the file at the Corresponding Record (or Next Record if exact match isn't found).  SETGT (Set Greater Than) SETGT accepts Key Fields or Relative Record Number (RRN) as Search Arguments and positions the file at the Next Record (Greater Than the Key value). Syntax: SETLL SEARCH-ARGUMENTS/KEYFIELDS FILENAME SETGT  SEARCH-ARGUMENTS/KEYFIELDS FILENAME One of the below can be passed as Search...

What we need to know about CHAIN (RPGLE) & How is it different from READ?

CHAIN READ & CHAIN, These are one of the most used (& useful) Opcodes by any RPG developer. These Opcodes are used to read a record from file. So, What's the difference between CHAIN & READ?   CHAIN operation retrieves a record based on the Key specified. It's more like Retrieving Random record from a Database file based on the Key fields.  READ operation reads the record currently pointed to from a Database file. There are multiple Opcodes that start with READ and all are used to read a record but with slight difference. We will see more about different Opcodes and How they are different from each other (and CHAIN) in another article. Few differences to note.  CHAIN requires Key fields to read a record where as READ would read the record currently pointed to (SETLL or SETGT are used to point a Record).  If there are multiple records with the same Key data, CHAIN would return the same record every time. READE can be used to read all the records with the s...