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).

Thursday, June 26, 2008

FTP in AS400

File Transfer Protocol can be used to transfer files from server to your PC and vice versa. Steps are shown for easy and basic operations

1. Goto RUN in Windows Desktop.
2. Type Cmd and enter.
3. Then type
1. ftp ipaddress
2. user name
3. password


If you want to transfer the file from the server. Then

1. Goto proper location by (CD directoryname in server).
2. Type LCD(local directory) folder name.
3. Get filename (to copy one file from the remote machine to the local machine )

If you wannt to get multiple file's from server. Then
In step 3, there is a slight change.

3. mget * (copies all the files in the current remote directory to your current local directory, using the same filenames. Notice the use of the wild card character, *.)

(to copy multiple files from the remote machine to the local machine;
you are prompted for a y/n answer before transferring each file );

If you wannt to transfer file from your local PC to Server then

3.mput *( to copy multiple files from the local machine to the remote machine;
you are prompted for a y/n answer before transferring each file );

3.put (to copy one file from the local machine to the remote machine );

Some important commands in FTP are also as follows.

open to open a connection with another computer
put to copy one file from the local machine to the remote machine
pwd to find out the pathname of the current directory on remote machine
quit to exit the FTP environment (same as bye)
rmdir to remove (delete) a directory in the current remote directory
bye to exit the FTP environment (same as quit)
cd to change directory on the remote machine
close to terminate a connection with another computer
delete to delete (remove) a file in the current remote directory
? to request help or information about the FTP commands

Thursday, June 19, 2008

Subfiles

Subfiles
A subfile is a group of records that is read from or written to a display device file in one operation.
Created with two parts
i) Data part SFL
ii) Control part. SFLCTL

e.g.
In subfiles, there are three methods to load

It can be

i) Size > page (Load all)

ii) Size = Page (Load on demand)

iii) Size > Page (Expandable i.e. Size > Page (size only one greater than page))


i) Load all
ii) And iii) are Load on demand

Load All
In load all we can load up to 9,999 records. All records are loaded by clearing the subfile one time, and then loading all the records into subfile at a time. Each and every record gets written to the subfile by incrementing the RRN. Then we can EXFMT the screen for displaying the subfile.

First we have to set display layout for the subfile.
SFLSIZ, SFLPAG. We have to set indicators for the subfile control part for SFLCLR, SFLDSPCTL, and SFLDSP.

Demo program is shown below. For getting basic idea.



A SFLSIZ(0007
A SFLPAG(0006)
A OVERLAY
A 12 SFLDSP
A 13 SFLDSPCTL
A 14 SFLCLR


RPG program is as below.

FPFNAME UF E K DISK A
FDSPFILE CF E WORKSTN
F RRN KSFILE DATA
C *IN03 DOWEQ*OFF
C EXSR CLR
C EXSR LOAD
C EXSR DSP
C ENDIF
C ENDDO
C SETON LR
C***----CLEAR SUBPROGAM
C CLR BEGSR
C SETON 40
C WRITECONTROL part name
C SETOF 40
C Z-ADD0 RRN 40
C ENDSR
C***----LOADING SUBPRORAM
C LOAD BEGSR
C *LOVAL SETLL pf rec format
C READ pf rec format 50
C *IN50 DOWEQ*OFF
C ADD 1 RRN
C WRITEDATA
C READ pf rec format 50
C ENDDO
C ENDSR
C***----- DISPLAYING SUBPROGRAM
C DSP BEGSR
C SETON 2030
C EXFMTCONTROL part name
C SETOF 2030
C ENDSR



SIZE = PAGE (LOAD ON-DEMAND)
In load on-demand we can load more than 9,999 records to the subfile. In this subfile we have to load the records only at the demand. (I.e. When ever page down is pressed we have to take control of the subfile and for page up also).

When we declare the display layouts for the subfile SFLSIZ and SFLPAG, take care of both to be equal. And for PAGEUP and PAGEDWN we have to set indicator for them and we should handle them in the program.

We have to care of the page down and page up by noticing the first and last position of the subfile records displayed at that page. If you read the code you can understand it easily.

HOPTION (*NODEBUGIO)
FSINGLEPF IF E K Disk
FSINGLEDSPFCF E Workstn Sfile (SNGSFL: Rrn1)
C ExSR #CLEARSNG
C ExSR #LOADSNG
C DoW Not *In03
C ExSR #VIEWSNG
C 03 Leave
C If *In15 = *On
C N71 ExSR #CLEARSNG
C ExSR #PGDOWN
C EndIf
C If *In16 = *On
C* N72 ExSR #CLEARSNG
C ExSR #PGUP
C EndIf
C EndDO
C SetON LR
********************
C #CLEARSNG BegSR
C 15 z-add 0 RRn1 4 0
C 16 z-add 6 RRn1
C Eval *In21 = *Off
C Eval *in22 = *Off
C Eval *In34 = *Off
C Eval *In71 = *Off
C Eval *In72 = *Off
C Eval *In33 = *On
C Write SNGSFLCTL
C Eval *In33 = *Off
C EndSR
********************
C #LOADSNG BegSR
C *Loval SetLL SNGREC
C Do 5
C Read SNGREC 71
C Eval Rrn1 = Rrn1 + 1
C N71 Write SNGSFL
C If Rrn1 = 1
C Move PNO first 2 0
C Else
C Move PNO last 2 0
C EndIf
C EndDo
C* Read SNGREC 71
C EndSR
*********************
C #VIEWSNG BegSR
C If Rrn1 <> 0
C Eval *In31 = *On
C EndIf
C Eval *In32 = *On
C Write SNGFTR
C Exfmt SNGSFLCTL
C EndSR
***********************
C #PGDOWN BegSR
C Last SetGT SNGREC
C* Z-Add 0 Rrn1 4 0
C Read SNGREC 71
C 71 Eval *In34 = *On
C 71 Eval *In22 = *On
C 71 LeaveSR
C Do 5
C
C N71 Eval Rrn1 = Rrn1 + 1
C N71 Write SNGSFL
C If Rrn1 = 1
C Move PNO first
C Else
C Move PNO last
C EndIf
C
C Read SNGREC 71
C EndDo
C EndSR
****************************
C #PGUP BegSR
C First SetLL SNGREC 54
C* z-add 6 Rrn1
C ReadP SNGREC 72
C 72 Eval *In21 = *On
C 72 LeaveSR
C ExSR #CLEARSNG
C Do 5
C N72 Eval Rrn1 = Rrn1 - 1
C N72 Write SNGSFL
C If Rrn1 = 5
C Move PNO last
C Else
C Move PNO first
C EndIf
C
C ReadP SNGREC 72
C EndDo
C EndSR

EXPANDABLE SUBFILE
In expanding subfile we have to declare the size just greater than one from page.
Such that we have to make SFLRCDNBR to be declared in the subfile.

Steps:
Make a output variable in control part of the subfile with the size equal to the RRN.
Make it non-display and then set ‘Y’ for SFLRCDNBR.(In display attributes of that output field).
Rename the same output field.

We have to take care of the PAGEDOWN only, as we have given size greater than the page by one. System may take care of the PAGEUP.
Initially we have to make SFLRCDNBR field to 1, while load begins. Then in loading
Part we have to make RRN field equal to the SFLRCDNBR. Such that for next page up system can load the records for the previous page. You can understand better as you see the sample program code.

Disadvantage:
Same as load-all we can load only up to 9,999 records to the subfile.

HOPTION(*NODEBUGIO)
FPFname UF A E K DISK
FDspfilnam CF E WORKSTN SFILE(SDPT:RRN)
C EXSR CLR
C EXSR LOAD
C *IN03 DOWEQ *OFF
C EXSR DSP
C *IN15 IFEQ *ON
C *IN38 IFEQ *OFF
C EXSR PGDWN
C ENDIF
C ENDIF
C ENDDO
C SETON LR
*****************
C CLR BEGSR
C SETON 14
C WRITE SCPT
C SETOFF 14
C Z-ADD 0 RRN 3 0
C ENDSR
************
C DSP BEGSR
C IF RRN=0
C EVAL *IN12=*OFF
C ELSE
C SETON 1213
C ENDIF
C EVAL *IN13=*ON
C EXFMT SCPT
C SETOFF 1213
C ENDSR
****************
C LOAD BEGSR
C *LOVAL SETLL STUDENT
C DO 6
C READ STUDENT 38
C 38 LEAVE
C ADD 1 RRN
C EXSR REP_A
C WRITE SDPT
C ENDDO
C EVAL RN=RRN
C ENDSR
*****************
C PGDWN BEGSR
C DO 6
C EXSR CLEARING
C READ STUDENT 38
C 38 LEAVE
C ADD 1 RRN
C EXSR REP_A
C WRITE SDPT
C ENDDO
C EVAL RN=RRN
C ENDSR
C REPL BEGSR
C MOVE SNO_S SNO
C MOVE NAME_S NAME
C MOVE M1_S M1
C MOVE M2_S M2
C MOVE M3_S M3
C MOVE TOT_S TOT
C MOVE AVG_S AVG
C MOVE GRADE_S GRADE
C ENDSR
C REP_A BEGSR
C MOVE SNO SNO_S
C MOVE NAME NAME_S
C MOVE M1 M1_S
C MOVE M2 M2_S
C MOVE M3 M3_S
C MOVE TOT TOT_S
C MOVE AVG AVG_S
C MOVE GRADE GRADE_S
C ENDSR
C CLEARING BEGSR
C EVAL SNO_S=*ZEROS
C EVAL NAME_S=*BLANKS
C EVAL M1_S=*ZEROS
C EVAL M2_S=*ZEROS
C EVAL M3_S=*ZEROS
C EVAL TOT_S=*ZEROS
C EVAL AVG_S=*ZEROS
C EVAL GRADE_S=*BLANKS
C ENDSR

Wednesday, June 18, 2008

Control Language Programming

1.OVER RIDING DBF

CHGPF -> Change the maximum member.
ADDPFM- > Add the new member name.
Create override CLP program.

Program:

RUNQRY *N (lib/filename)
OVRDBF FILE (filename) TOFILE (lib/filename) MBR (newMembername)
CALL PGM (rpgpgmname)
DLTOVR FILE (filename)

In over riding DBF, We can add records to the Member which ever created newly.


2.OPNQRYF

OPNQRYF FILE (LIB/FILENAME) QRYSLT (CNDN)

After creating query we can have it in a separate file

CPYFRMQRYF FROMFILE (fileA) TOFILE (fileB) CRTPF (*YES)

Then we have to close the Opened PF.

CLOF OPNID (fileA)

3.CL PROGRAM FOR PF

PGM
DCLF FILE (LIBNAME/FILENAME) RCDFMT (RECORDFORMAT)
LABEL1: RCVF RCDFMT (RECORDFORMAT)
MONMSG MSGID (CPF0864) EXEC (GOTO CMDLBL (EXIT))
SNDUSRMSG MSG (&NAME)
GOTO CMDLBL (LABEL1)
EXIT: CLOF OPNID (FILENAME)
ENDPGM

RCVF is used to receive the information Message from Physical file.


4.CL PROGRAM FOR DISPLAY FILE

Here I have used a display file to show the week days.

And I also used a data area, declared with size 21. And data area is named as ‘WEEK’

It has following information.

Value
Offset *...+....1....+....2....+....3....+....4....+....5
0 'MONTUEWEDTHUFRISATSUN'

And my display file contains two fields, One input (INP) and one output (OUP).

Program for CL is given below,

PGM
DCLF FILE (LIBNAME/filename) RCDFMT (dsprecformat)
DCL VAR (&VAR1) TYPE (*DEC) LEN (2 0)
L1: SNDRCVF RCDFMT (dsprecformat)
IF COND (&IN03 *EQ '0') THEN (DO)
IF COND (&INP *NE 0) THEN (DO)
CHGVAR VAR (&VAR1) VALUE (&INP * 3 - 2)
RTVDTAARA DTAARA (LIBNAME/WEEK (&VAR1 3)) RTNVAR (&OUP)
ENDDO
GOTO CMDLBL (L1)
ENDDO
ENDPGM


Another program for demonstration of Display files with CLP.

PGM
DCLF FILE (PALANI/CLPDSP2)
L1: SNDRCVF
IF COND (&IN03 *EQ '1') THEN (GOTO CMDLBL (RE))
CHGVAR VAR (&C) VALUE (&A + &B)
GOTO L1
RE: RETURN
ENDPGM

Display file has three fields (A, B, C)


5.Passing parameters between two CL programs

Consider the situation, program is written for that.

PGM
DCLF FILE (lib/ PF filename) RCDFMT ( rec format PF)
DCL &IN03 *LGL
FIRST: RCVF RCDFMT (rec format PF)
MONMSG MSGID (CPF0864) EXEC (GOTO CMDLBL(END))
CALL PGM (lib/ CL2 filename) PARM (&EID &PWD &IN03)
IF (&IN03 = '1') THEN (GOTO END)
GOTO CMDLBL (FIRST)
END: ENDPGM

I am going to pass the variable like EID, PWD, IN03 to another program, which is right below

PGM PARM(&EID &PWD &IN03)
DCLF FILE(lib/ display filename) RCDFMT(display recformat)
DCL VAR(&EID) TYPE(*CHAR) LEN(10)
DCL VAR(&PWD) TYPE(*CHAR) LEN(10)
SNDRCVF RCDFMT (display rec format)
ENDPGM


Successfully parameter has been passed. And received in another program.