Thursday, September 6, 2012
Subsystem Details:
Saturday, August 13, 2011
AS400 SQL STORED PROCEDURES AND EXTERNAL STORED PROCEDURES EXAMPLES
AS400 the stored procedures cane called from SQLRPGLE program or from STRSQL utility screen. Stored procedures may return result sets i.e. the results of a SELECT statement,or it can retun the paramters declared as OUT. Result sets can be processed using cursors, by other stored procedures, by associating a result set locator, or by applications. Stored procedures may also contain declared variables for processing data and cursors that allow it to loop through multiple rows in a table. Stored procedure languages typically include IF, WHILE, LOOP, REPEAT, and CASE statements, and more. Stored procedures can receive variables, return results or modify variables and return them, depending on how and where the variable is declared
There are two type of stored procedures in AS400 - External stored procedures and SQL stored procedures. While creating the external Procedures an external program( CL,RPGLE,COBOL,C etc) will linked to procedure. But in SQL stored procedures all the statements will be SQL statements. The AS400 stored procedures can also be called from .NET,JAVA,VB etc other front end applications.
External Stored Procedure
In the below example an external procedure is created with CREATE PROCEDURE statement in the STRSQL utility. The program CHECKCUST( RPGLE - for checking the customer is present or not ) is linked to the procedure so that when a call comes to the procedure, indirectly procedure invokes the program with passed parameters. Below program (CHECKCUST) returns a flag(RECFND) which procedure passes to the calling program PROTESTPGM (SQLRPGLE).
SOURCE : Procedure calling program (PROTESTPGM)
-----------------------------------------------
The real cases the procedures are called from the front-end applications. But we can also call the procedures from SQLRPGLE in AS400 itself.
SOURCE: CHECKCUST ( RPGLE Program attached to Procedure)
-------------------------------------------------------
CREATE PROCEDURE :
The below SQL statment includes the language of the external program,External program Name/Library. For more Stored Procedures
CREATE PROCEDURE DAVNAV1/PROCCHECKCUST(IN CUSTNUM DECIMAL (5,0), OUT
RECFOUND CHAR (1 )) LANGUAGE RPGLE DETERMINISTIC NO SQL EXTERNAL
NAME DAVNAV1/CHECKCUST PARAMETER STYLE GENERAL
Procedure PROCCHECKCUST was created in DAVNAV1.
For verifing:
SELECT * FROM SYSROUTINES or SELECT * FROM SYSPARAMS , execute the SQL and see the SCHEMA entry in the tables.
SQL Stored Procedures
SQL stored procedures are written in SQL language and this can be compiled or created using CREATE PROCEDURE or RUNSQLSTM command or iSeries Navigator
SQL SOURCE(DELETCUST):
Below example SQL source is for creating a procedure to delete the specific Customer Record.
http://publib.boulder.ibm.com/html/as400/v4r5/ic2931/info/db2/rbafymst151.htm#HDRSQLPROC
Compilation: The sql source can be compiled using the Command RUNSQLSTM
RUNSQLSTM SRCFILE(DAVNAV1/QSQLSRC) SRCMBR(DELETCUST) COMMIT(*NC) DBGVIEW(*SOURCE)
COMMIT(*NC) --> Specifies that commitment control is not used. Uncommitted changes in other jobs can be seen. If the SQL DROP SCHEMA
statement is included in the program, *NONE or *NC must be used.
DBGVIEW(*SOURCE) --> debugging with source.
CALLING SQLRPGLE PROGRAM:
--------------------------------------
Wednesday, December 1, 2010
Wednesday, November 24, 2010
Subfile programs and Docs
subfile doc basics and simple programs
2. Subfile Keywords:
Subfile Keywords
3. Subfile Programs
Subfile Programs
4. subfiles detailed document
subfile
Saturday, May 8, 2010
searching for as400 scope
http://as400blog.blogspot.com/search/label/history
Wednesday, March 3, 2010
Procedures within an ILE RPG program
Something more am trying to know about procedure,subprocedure,service program. While googling sample programs and I created one procedure in program. Iam not sure about the the other concepts now. Let me hack it later.
these procedures can be used like built-in functions:-)
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/books/c092508410.htm
steps for creation:
(1)
A Prototype which specifies the name, return value if any, and parameters if any.
(2)
A Begin-Procedure specification (B in position 24 of a procedure specification)
(3)
A Procedure-Interface definition, which specifies the return value and parameters, if any. The procedure interface must match the corresponding prototype. The procedure-interface definition is optional if the subprocedure does not return a value and does not have any parameters that are passed to it.
(4)
Other definition specifications of variables, constants and prototypes needed by the subprocedure. These definitions are local definitions.
(5)
Any calculation specifications, standard or free-form, needed to perform the task of the procedure. The calculations may refer to both local and global definitions. Any subroutines included within the subprocedure are local. They cannot be used outside of the subprocedure. If the subprocedure returns a value, then the subprocedure must contain a RETURN operation.
(6)
An End-Procedure specification (E in position 24 of a procedure specification)
See sample program:
Rest of the code highlighted:
But default activation group(DFTACTGRP) as 'YES' throwing error while compiling, this can solveed giving as option 'NO'
not sure the reason for this ( need to investigate)
Activation group . . . . . . . . ACTGRP QILE
OUTPUT
See little about free format.... we can write direct statements separated by semicolon in between /free ...and /end-free
Please refer :
Code400.com
Friday, February 26, 2010
RPG flaw in addition
Monday, February 22, 2010
SETLL
http://publib.boulder.ibm.com/iseries/v5r1/ic2924/books/c0925083713.htm
CHGPF http://search400.techtarget.com/tips/index/0,289482,sid3_tax2f9,00.html
When the structure of a physical file changes, most AS/400 programmers take the following steps to incorporate the change:
a. Change the DDS to reflect the new structure.
b. Make a copy of the data from the old structure file.
c. Delete any logical files based on the physical file.
d. Recompile the source and rebuild any logical files.
e. Copy the old data back to the new structure, specifying options *DROP and *MAP.
You can use the CHGPF command to achieve the same goal with less effort. When you need to recompile because of a change in file structure, follow these steps:
a. Make the necessary changes to the DDS source.
b. Type CHGPF and press F4 to display the screen below:
�������������������� Change Physical File (CHGPF)
� Type choices, press Enter.
� Physical file� . . . . . .��� ARETURNS�� Name
��� Library� . . . . . . . .����� INVLIB�� Name, *LIBL, *CURLIB
� System . . . . . . . . . .��� *LCL������ *LCL, *RMT, *FILETYPE
� Source file� . . . . . . .��� QDDSSRC��� Name, *NONE
��� Library� . . . . . . . .����� SRCLIB�� Name, *LIBL, *CURLIB
Enter the name of the physical file and the name of the library in which the file resides. Also type the source physical file name and the name of the library in which the source file resides.
c. Press Enter to display the screen below:
�������������������� Change Physical File (CHGPF)
� Type choices, press Enter.
� Physical file� . . . . . . .� ARETURNS�� Name
��� Library� . . . . . . . . .��� INVLIB�� Name, *LIBL, *CURLIB
� System . . . . . . . . . . .� *LCL������ *LCL, *RMT, *FILETYPE
� Source file� . . . . . . . .� QDDSSRC��� Name, *NONE
��� Library� . . . . . . . . .��� SRCLIB�� Name, *LIBL, *CURLIB
� Source member� . . . . . . .� *FILE����� Name, *FILE
� Source listing options . . .������������ *SRC, *NOSRC,*SOURCE...
���������������� + for more values
� Generation severity level� .� 20�������� 0-30
� Flagging severity level� . .� 0��������� 0-30
� Delete dependent logical file *NO������� *NO, *YES
� Remove constraint� . . . . .� *RESTRICT� *RESTRICT, *REMOVE
� Expiration date for member .� *NONE����� Date, *SAME, *NONE
Enter the source member name, and press Enter. This step recompiles the physical and logical files and copies data back. In fact, it does all the steps you've been doing manually.
Note that when you change the DDS to reduce a field's size or drop a field, you may receive a message warning that you may lose your data. You can ignore the message by responding to it with I(gnore).
You can use a similar technique to delete all the logical files based on a physical file. Rather than using the DSPDBR command to find all dependent logicals and then deleting them one by one, simply use the CHGPF command as described above and specify *YES for "Delete dependent logical file" on the second screen to delete all dependent files.
Saturday, February 20, 2010
CHAIN AND SETLL -- RPGLE
If the programmer is using SETLL and READE to get a single record you could change the program to CHAIN and get quicker results. The SETLL and READE is good only for situations where you need to read a group of records with the same propertie
The below program is for fetching Employee Name and Employee Salary based on the Employee Number Entered through the screen.
Based on the input ( Employee Nmber - EMPIDS ) the CHAIN opcode will directly point to the record . READE will read that records and passing the values to Screen variables ... quite easy and simple.
I will publish the SETLL program in the next------------------------------
Saturday, February 13, 2010
RPGLE - Compile Time Array
Compile time array get populated at the time compilation of the code.Mostly these type of array use for error message display.
** and then data in successive lines at the bottom of the source.Below example we have defined an COMARR compile time array using CTDATA
OUTPUT:
======
The COMARR compile time array data we can hard code as row wise. But while declaring we have to specify how many values entering per row . Below example entering 5 records ( all the array values) per row. Keyword PERRCD(5)
OUTPUT:
=====
Thursday, February 11, 2010
RPGLE - Runtime Array
Wednesday, February 10, 2010
Convert date format RPGLE
C ....*USA....... MOVE.......Datetemp.....Dat
C .... Dat ...... DSPLY....
Dat declared as 8 D ( date data type with 8 length ) to compact with *USA format
OUTPUT:
======
Character (A)
Graphic (G)
Numeric - Integer format (I)
Numeric – Packed decimal format (P)
Numeric - Zoned format (S)
Numeric - Unsigned format (U)
Float (F)
Date (D)
Time (T)
Timestamp (Z)
Shifting to tn5250
This has given by the http://www.rzkh.de/ as400 service administrators
See wiki.
http://en.wikipedia.org/wiki/IBM_5250
Tuesday, February 9, 2010
RPGLE - Concatenate two strings,addition
Simple programs are always helpful to get good step to learn a new language. See below how easy this is to write RPGLE ( am learning from basic ) rather than jumping to big things
INZ keyword is used to initialize the 'surname' and 'forename'. But before concatenating the variables using 'CAT' the valued changed using EVAL opcode.
Addition can be done using 'ADD'.
Arithmetic operations:
http://publib.boulder.ibm.com/infocenter/iadthelp/v7r0/index.jsp?topic=/com.ibm.etools.iseries.langref.doc/evferlsh354.htm
Wednesday, February 3, 2010
RPG opcode screen
ACQ -- Acquire device
BEGSR -- Begin Subroutine
CALLP -- Call Prototyped Procedure or Program
CHAIN -- Retrieve Record by key
CLEAR -- Clear
CLOSE -- Close File
COMMIT -- Commit Database changes
DEALLOC -- Release Dynamically Allocated Storage
DELETE -- Delete Record
DOU -- Do Until
DOW -- Do While
DSPLY -- Display message
DUMP -- Dump Program
ELSE -- Else
ELSEIF -- Else If
ENDyy -- End a Structured Group (where yy = DO, FOR, IF, MON, SL, or SR)
EVAL -- Evaluate expression
EVALR -- Evaluate expression and right adjust result
EXCEPT -- Perform Exception Output
EXFMT -- Write/Then Read Format from display
EXSR -- Execute Subroutine
FEOD -- Force End of Data
FOR -- For
FORCE -- Force specified file to be read on next Cycle
IF -- If
IN -- Retrieve a Data Area
ITER -- Iterate
LEAVE -- Leave a Do/For Group
LEAVESR -- Leave a Subroutine
MONITOR -- Begin a Monitor Group
NEXT -- Next
ON-ERROR -- Specify errors to handle within MONITOR group
OPEN -- Open File for Processing
OTHER -- Start of default processing for SELECT group
OUT -- Write Data Area
POST -- Post
READ -- Read a record
READC -- Read next changed record
READE -- Read next record with equal Key
READP -- Read prior record
READPE -- Read prior record with equal Key
REL -- Release
RESET -- Reset
RETURN -- Return to Caller
ROLBK -- Roll Back uncommitted database changes
SELECT -- Begin a Select Group
SETGT -- Position database to record with key greater than specified key
SETLL -- Position database to record with key not greater than specified key
SORTA -- Sort an Array
TEST -- Test Date/Time/Timestamp
UNLOCK -- Unlock a Data Area or Release a Record
UPDATE -- Modify Existing Record
WHEN -- Condition test within SELECT group
WRITE -- Write New Record
RPGLE Built in function reference
===================================
%ABS - Absolute Value of Expression
%ADDR - Get Address of Variable
%ALLOC - Allocate Storage
%CHAR - Convert to Character Data
%CHECK - Check Characters
%CHECKR - Check Reverse
%DATE - Convert to Date
%DAYS - Number of Days
%DEC - Convert to Packed Decimal Format
%DECH - Convert to Packed Decimal Format with Half Adjust
%DECPOS - Get Number of Decimal Positions
%DIFF - Difference Between Two Date, Time, or Timestamp Values
%DIV - Return Integer Portion of Quotient
%EDITC - Edit Value Using an Editcode
%EDITFLT - Convert to Float External Representation
%EDITW - Edit Value Using an Editword
%ELEM - Get Number of Elements
%EOF - Return End or Beginning of File Condition
%EQUAL - Return Exact Match Condition
%ERROR - Return Error Condition
%FLOAT - Convert to Floating Format
%FOUND - Return Found Condition
%GRAPH - Convert to Graphic Value
%HOURS - Number of Hours
%INT - Convert to Integer Format
%INTH - Convert to Integer Format with Half Adjust
%LEN - Get or Set Length
%LOOKUPxx - Look Up an Array Element
%MINUTES - Number of Minutes
%MONTHS - Number of Months
%MSECONDS - Number of Microseconds
%NULLIND - Query or Set Null Indicator
%OCCUR - Set/Get Occurrence of a Data Structure
%OPEN - Return File Open Condition
%PADDR - Get Procedure Address
%PARMS - Return Number of Parameters
%REALLOC - Reallocate Storage
%REM - Return Integer Remainder
%REPLACE - Replace Character String
%SCAN - Scan for Characters
%SECONDS - Number of Seconds
%SHTDN - Shut Down
%SIZE - Get Size in Bytes
%SQRT - Square Root of Expression
%STATUS - Return File or Program Status
%STR - Get or Store Null-Terminated String
%SUBDT - Extract a Portion of a Date, Time, or Timestamp
%SUBST - Get Substring
%THIS - Return Class Instance for Native Method
%TIME - Convert to Time
%TIMESTAMP - Convert to Timestamp
%TLOOKUPxx - Look Up a Table Element
%TRIM - Trim Blanks at Edges
%TRIML - Trim Leading Blanks
%TRIMR - Trim Trailing Blanks
%UCS2 - Convert to UCS-2 Value
%UNS - Convert to Unsigned Format
%UNSH - Convert to Unsigned Format with Half Adjust
%XFOOT - Sum Array Expression Elements
%XLATE - Translate
%YEARS - Number of Years
Tuesday, February 2, 2010
Creating DDS for Physical File (PF)
Physical file is like a Table in the oracle database . Using select statments and RUNQRY its possible to access the table
step1: wrkmbrpdm ( in command line )
F6 option is for creating new DDS,RPG,CL etc
The source file for DDS is QDDSSRC and library for me it is DAVNAV1
Source member is the name of the Physical file and source type is PF( Physical file )
Now we are entering into the DDS creation. We have to follow below sequence
1. File level entries
2. record level entries
3. Field level entries
4. Key field lvel entries
step1:
The Functions(F4 - Prompt )- UNIQUE have used for keyword is used to indicate that the value of the key field in each record in the file must be unique ( duplicate records are not allowed )
step2:
In record row give the Name type - R and also the corresponding optional text also can be mention in the function field
step3:
The fields (analogy columns) can be mentioned in next line
step4:
Key field level entries is the last preceeding with 'K'
The DDS can be saved by typing 'FILE' in the top and enter
Compiling the DDS is easy using the option 14-Compile and errors can viewed through the spool files using 'SA' corresponding to the PF in screen
Entry
Meaning
A
Character
P
Packed decimal
S
Zoned decimal
B
Binary
F
Floating point
H
Hexadecimal
L
Date
T
Time
Z
Timestamp
Notes:
strsql from command
insert into student values ('Naveen',1000,50) 1 rows inserted in STUDENT in DAVNAV1.
AS400 machine learning
Its very difficult for me to study these IBM (iSeries)machines
http://en.wikipedia.org/wiki/IBM_System_i, but slowly am getting some basic findings .
Two weeks back I got access to one online AS400 machine through internet . So learning RPGLE ,CL and basic commands we can practice in my UBUNTU.
just telnet pub1.rzkh.de