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.