Tuesday, July 8, 2008

Date Operation

Date and Time Operation in RPGLE:
*ISO format is the default format, for all Date, Time and Timestamp.
There are various formats available for Date and Time. There are as follows.

Length ->8
*MDY mm/dd/yy
*DMY dd/mm/yy
*YMD yy/mm/dd
*JUL yy/days

*LOVAL=1940
*HIVAL=2039

Length ->10
*EUR dd.mm.yyyy
*USA mm/dd/yyyy
*ISO yyyy-mm-dd
*JIS yyyy-mm-dd


*LOVAL=0001
*HIVAL=9999

*CMDY cmm/dd/yy
*CDMY cdd/mm/yy
*CYMD cyy/mm/dd
*LONGJUL

C=0 1900-1999
C=1 2000-2099
C=2 2100-2199

TIME

*HMS hh:mm:ss

*ISO hh.mm.ss

*USA hh:mm(AM/PM)

*JIS hh:mm:ss

*EUR hh.mm.ss


Timestamp:
*ISO-> yyyy-mm-dd-hh.mm.ss.mmmmmm =>length is 26.

H-Spec Declaration:

If we specify DATFMT in H-spec with particular format, then whole project would follow in the same format, as mentioned above.

e.g. For declaring date field inside the RPGLE program.

D Datefield S D INZ(D’21 07 99’)

If it is Date then it should have ‘D’ infront. If it is Time then we should have ‘T’ infront. If it is Timestamp then we can have ‘Z’.

In Free Format:

%date(expression{:Date-format})

While declaring Date,Time and Timestamp inside the program in the D-specification, Dataformats can be ‘D’,’T’,’Z’ respectively.

e.g.

D loandate S D
D Curtime S T
D Timest S Z

e.g. For Built in Functions is

D str S 8A Inz(‘20080630’)
D date1 S D
/free
date1=%date(str:*ISO0)
/end-free


*ISO0
0-> No separator or else we have to specify which parameter we have to use in the program.

Built-in Functions DurationCodes

%years *Years or *Y
%months *Months or *M
%days *Days or *D
%hours *Hours or *H
%Minutes *Mintues or *MN
%Seconds *Seconds or *S
%Mseconds *Mseconds or *MS


Operation with Date:

Subset of a Date:

SUBST

Built in Functions : %Subst(value:*durationcodes)


EXTRCT:
e.g. and Usage exactly

C EXTRCT Date1:*D Days

Date1: 2006-08-24
Days: 24

DIFF


Built in functions:

Var=%Diff(op1:op2:*m)

Op1=2008-07-30
Op2=2008-05-23

Var=2

MOVE
We can move the string to Date/Time/Timestamp or from Date/Time/Timestamp to String also.

e.g.

C MOVE Date1 nudate2
C *MDY0 MOVE Date1 stdate2

ADDDUR:
It is used to Add duration of period or time or timestamp. It usage is as follows.

C Loandate ADDDUR 18:*Years Loandate1

Loandate = 2008-06-10
Loandate1= 2026-06-10

SUBDUR
It is used to subtract the period or Time or timestamp.

C Date/time SUBDUR Date/time var1:*m

TEST:
Test opcodes are used to check whether the given factor1 is exactly equal to factor2. If not LOW level indicator will be on.

TEST(D)
TEST(T)
TEST(Z)


e.g.

C Datfmt TEST(D) char/num ER
C Timfmt TEST(D) char/num ER
C Timstmp TEST(D) char/num ER


CONVERSION OF DATE IN CLP PROGRAM :

CVTDAT DATE(&OLDDATE) TOVAR(&NEWDATE)
FROMFMT(*DMY) TOFMT(o*USA) TOSEP(/)

Monday, July 7, 2008

Members in As 400

Members:
Different sets of data’s in the same format of Records are called Members.

Saved Keyed PF allows creating Maximum of 3,999 members.
Saved Non-Keyed PF allows creating Maximum of 7,999 members.

Operations with Members are as follows.

CRTPF
CRTLF
ADDPFM
ADDLFM
CHGPF
CHGLF
CHGPFM
CHGLFM


PF- Members Operation:-

*INZPFM -> Initialize Physical Members

When you create the PF we can give DFT(value), for default values in function keywords. So when you initialize the physical file then fields, will get default value we have already declared. It can restrict others from writing the new records. So we can update the values of those already created by fetching the RRN value of them.

*CLRPFM ->Clear Physical Members
It can clear the values of the members such that it would empty the PF. And it also can re-organize the sequence number created by file operation (WRITING AND DELETING).

*DSPPFM -> Display Physical Members

*CHGPFM ->Change Physical Members

*RNMM ->Rename Physical Members

*RMVM ->Remove Members

*RGZPFM ->Re-Organize Physical Members
RGZPFM is used to organize the PF such that its sequence number will continue properly even though records have been deleted through program. After doing RGZPFM then Sequence would continue normally.

Friday, July 4, 2008

Flat File

Flat File:
Flat files are physical files that have no field definitions and no indexes built off of them. Flat files, Record format and Field are all same. They all have a same name.
We can write, read, update, delete the Flat file.

Reading and Deleting can be done normally where as update and writing requires the use of Data Structures. Let me discuss one by one.

Creating a Flat File:

Creating a flat file is same as creating Physical File. It is very easy to declare either in command line or even in DDS in STRSEU editor.

CRTPF(Flatfilename) RCDLEN(length)

Consider an example:

CRTPF(Flatfilename) RCDLEN(length)


Writing a Flat File:
Writing can be done either in RPG-400 or In RPG ILE also.


F flatfile O F 150 DISK

1. In F spec File is declared, with Output mode [ O ] and File is described as Program described File [ F ]. And record length is also [ 150 ]declared.
2. We are selecting IPDS prompt to enter the Data Structure with the size of the flat file.( Actually 52 is the maximum length to display data structure in RPG-400).

IDS01 DS 150

3. Then we have to select IPJ prompt and specify the length of the subfields and name them.
We can either make use of them as Packed Decimals, Character and zoned decimals.
I P 1 50CUNO
I 6 24 CUNA
I 25 25 AMOL
I 26 350BALA
I 36 36 DEPL
I 37 470DEPO
I 48 48 WITL
I 49 590WITH

4. After giving the value then assign to them according to the Character and numerical (data type).

C Z-ADD10003 CUNO
C MOVEL'BEMA' CUNA
C MOVE 'A' AMOL
C MOVE 'D' DEPL
C MOVE 'W' WITL
C Z-ADD660 DEPO
C Z-ADD200 WITH
C DEPO SUB WITH BALA
C Z-ADDBALA BALA
C WRITE flatfile DS01

5. While you are writing the flat file you have to specify even the Data structure name in Result field.
C SETON LR

CHAIN in Flat File:

Flat file can be chained by using RRN value (Relative Record Number). According to that we can CHAIN particular record where we have to make changes. Or Delete particular Record.


Updating a Flat File:
It is also same as the WRITE operation. After specifying particular changes just use UPDATE FLATFILE with DATASTRUCTURE.


Deleting a Flat File:
It also same as UPDATE. After getting the RRN of record by CHAIN Operation, then we can DELETE using Delete operation.

C DELETE flat file name


Reading a Flat File:

Reading a Flat file is slightly different. Here we can use IPI prompt. Let me explain one by one.


FGFLAT IF F 150 DISK

After F-(file declaration) We can Take IPI prompt then we may get prompt like below picture.


A).We have to declare the file name. In Sequence we can give any two alphabets, (if specified then it will be in special sequenced mode), else if we specify any two numbers then it will be in non-sequenced mode). (While retrieving the data’s from the flat file).
B). If we specify the RECORD ID then will taken as indicator.(01 in e.g)
C) In Record Identification Codes we can specify the position , whether the searched one should have particular character at (this position) . I can be a character or zoned number or a digit. If so What character in character space.

2. After giving the values it will be as below line.

IGFLAT AA 01 6 CC

3. Then we have to take IPJ prompt to enter the details of position , fields , packed filed, character, zoned one. In RPGLE we can also have date fields, time fields (that too including the particular which format we need)

I P 1 50CUNO
I 6 24 CUNA
I 25 25 AMOL
I 26 350AMOU
I AA 02 6 CH
I 6 24 HUNA
I 36 36 DEPL
I 37 470DEPO
I 48 48 WITL
I 49 590WITH
I AA 03
I P 1 50MENO
I 6 24 MENA
I 25 25 MEOL
I 26 350MEOU


4. When a read operation is encountered, then control will get transferred to I spec. According to the condition particular indicator will get switched on. It will take particular records. Using that control will get transferred below the READ statement.

C READ GFLAT 25
C *IN25 DOWEQ*OFF
C *IN01 IFEQ *ON
C CUNO DSPLY
C CUNA DSPLY
C AMOL DSPLY
C AMOU DSPLY
C SETOF 01
C ENDIF
C *IN02 IFEQ *ON
C HUNA DSPLY
C DEPO DSPLY
C WITH DSPLY
C SETOF 02
C ENDIF
C *IN03 IFEQ *ON
C MENO DSPLY
C MENA DSPLY
C MEOL DSPLY
C MEOU DSPLY
C SETOF 03
C ENDIF
C READ GFLAT 25
C ENDDO
C SETON LR


ADVANTAGE OF THIS KIND OF READ :

When I use I SPEC with INDICATORS, then program can make use of any group of fields according to the INDICATOR selection.
So in a single file we can access RECORDS in what ever condition we specified.

OVERIDING :

Overriding a flat file is also possible. We can generate multiple members. Rule for members are also same as the flat file. (Same name for members and fields and record formats).