Tuesday, 1 October 2013

Date field in RPG


Date Field

Date field is always a tricky data type for the programmers. Today I will try to explain the date field to make it easier for all of us. We define a variable in D specification with a data type d.

D  testdate                    s                        d                    // d is the data type

Default value of date variable is 0001-01-01 which also *LOVAL. 9999-12-31 is *HIVAL of a date variable.

There are different types of Date formats. For example

*ISO  :   YYYY-MM-DD    (Default date format)
*YMD:  YY/MM/DD
*USA:    MM/DD/YYYY
*DMY:   DD/MM/YY
*EUR:     DD/MM/YYYY  etc

How to initialize the value in any date field

For initializing the value in date field the value must be preceded by character d and date must be in the single quotes as mention in the below examples.
D  testdate1                    s                           d           INZ(d’2013-10-03’)  
D  testdate2                    s                           d           INZ(d’2013-12-31’)

Now let’s talk about any other date format for understanding more on this.
D testdate1                      s                          d           INZ(d’13/10/03’)

When we compile the above statement in RPG program it will throw a compile time error by saying that “the date literal is not valid” because as I mention in the above that default format of the date is *ISO however in the above example we are dealing with *YMD format. So for this kind of situation we need to mention the date which we want to see in the H specification.

H DATFMT(*YMD)

Now what if we want to subtract or add years/months/days in our date.

Please have a look in the following example for subtraction of one year from the system date.

Dloandate         S               D                                                 
Dduedate          S               D                                            
C                   eval      loandate = %date()                     //  loandate field has the system date   
C     loandate      adddur    1:*years      duedate            //   Adding one year to the system date              
C     duedate       dsply                                                 //   duedate has the one year more the system date
C                   seton                                          lr        

For example my system date is 2013-10-03 so after executing the above RPG Program duedate will be having value 2014-10-03. And observed one thing in the above example that I did not mention the date format so by default it will take the *ISO date format.
So in our case the output will be: 2014-10-03







Thursday, 8 August 2013

Open Query(OPNQRY) and Override with Database File(OVRDBF) concept

You can use the Override with Database file (OVRDBF) command to replace the database file named in a CL program or to change certain parameters of the existing database file.
It is not mandatory to use OVRDBF(*Yes) before OPNQRYF. You can still use OPNQRYF without OVRDBF.But here the pupose of the OPNQRYF won't be solved.
Opnqryf creates its own Open data path and to share the same data path in a program we use ovrdbf share(*yes), if we do not use ovrdbf, then program will have its own ODP, so it will read the file from beginning on which query has been run. So, OPNQRYF selected records will have no importance.
So, we need to use CPYFRMQRYF command and put the selected records in to runtime file and use that file to read in program.


Sunday, 14 July 2013

When program1 calls program2 for the first time program2 executes the *INZSR subroutine.Program2 uses the RETRN operation to return to program1.However when program1 call again program2 this time is the *INZSR subroutine executed?


If you specify RETRN in called program, the *INZSR will not execute again.
Reason: The INZSR is used to "initialise" the environment for the execution of your program by setting/resetting variables, etc, however many times it is called. If only return is used, all the values are held in memory anyway, so you don't have to initialize everything all over again. If LR is on at the end, INZSR will be executed again.

Some important Operation in RPGLE

READ  To read the records sequentially.
READE To read the equal key records
READP To read the previous records
READC To read the records from the workstation file (Subfile).
REDEP To read the equal key previous records.




Saturday, 22 June 2013

Difference between Array and Table in AS400

Array: Array is stored any where in the body of the input records.
Table: Table is stored at the beginning of the input records.
Array: We can access all the elements in array by specifying the array name.
Table:  Only one table element can be accessed at a time.
Array:  Array can be searched randomly.
Table:  Table can be searched consecutively. 




How to Convert Spool File into PDF or other Formats and send via Email.

Hi All,
          Here are the steps to convert the Spool file into PDF or any other format and Send Via Email.

1. Please add ESEND library into your library list.
2. Get the Spool File,Job Name,User,Number and Spool File Number for the spool file which you want to convert.(Give option 2 for the spool file you will get all the details).
3. Give command ESNDFILE in the command line and Press F4.
4. Give the email id in the Recipient List do a Page Down and give *File in the type.
5. Press Enter and Check your email....!

Saturday, 4 May 2013

How it works.

Step1: Please register with your update email id and other details in the below post link.

Step2: Get the username and password.

Step3: Download mocha 3270 or 5250.

Step4: Install into your laptop/desktop/iphone/ipad.

Step5: Here we go..it is ready to use.