You are on page 1of 37

Basic Concepts:

- RPG400 is a Position-Dependent language. (i.e. each entry start in a particular


position)
- HFELICO
- ‘Data Structure’ is an area in storage and considered to be a character field. (To
define DS first use IPD then IPJ specs.)

- ‘Program Status Data Structure’ is defined by putting a ‘S’ in column 18. It


contains predefined sub-fields that provide information about the exception/error
occurred in the program.

- ‘U’ in position 18 of data structure statement can define Data Area Data
Structures.

- INFDS: File Information data Structure.

- For NE condition always use AND & for EQ conditions use OR (multiple cases).

- To use DUMP in the program;


H FORMALIGN DATEDIT (*YMD) DEBUG (*YES)
Write the above line as the first line and put DUMP in the program where ever
you want to view the details.

RPG400 limitations:

- Arrays & Tables: Max of 200/pgm


- Compile Time Array: Max length of 80.
- Data Structure Length: Max 9999
- Data Structure Occurrence: Max 9999 occur/DS
- Elements in Array: 9999 elements/array
- Files: Max 50/pgm
- Overflow Indicators: only One unique Overflow/Printer file
- Passing Parameters: Max of 255
- Primary File: One/pgm
- Printer File: 80/pgm
- Program Status DS: 1/pgm
- Subroutines: 254/pgm

Free AS400 sites:

1. http://as400.holgerscherer.de/indexeng.html
2.

1
RPG400 Program Cycle

1. Heading and detail line is performed.


2. Next I/P record is read and record identifying & control level indicators
are SETON.
3. Total calculations are processed.
4. All total output lines are processed.
5. It is determined if the LR indicator is ON. ON means program ends.
6. Fields of selected i/p records are moved from the record to a processing
area.
7. All detail level calculation is performed.

1P /N1P (First Page Indicator)


a) When RPG400 pgm is executed, then logic cycle automatically turns ON the
1P indicator.
b) Any o/p records conditioned by 1P indicator will be executed.
c) After last o/p instruction is tested 1P is automatically turned OFF & first
record is read from PF.
d) The NOT condition (N1P) of the 1P indicator prevents any o/p for the first
cycle processing.

Different Date Formats:


- Separating a Date:
a) Total Date /10000 = Year
b) Reminder will give you month & date.
c) Now b/100 = Month
d) Final Reminder is Date.

Now DATE IFEQ Condn.


Z-ADD 1 DATE
ADD 1 MONTH.

- Date using Hyphen or Space:


Define a Data Structure S@DATE using IPD and define the fields as ;
Y1 1 4
SP1 5 5 INZ (‘-‘)
M1 6 7
SP2 8 8 INZ (‘-‘)
D1 9 10
- To Calculate date in the other way;
Y1*10000+ M1*100+D1

2
Procedure:
Is a set of self-contained HLL statements that performs a particular task?
Module:
It is a object that results from compiling a Source.
Service Program:
- It is the OS/400 object that combines one or more modules.
- It can’t be called directly.
Files:

PF:
- A PF can have only one Record Format. It describes the way actually data is
stored.
- A PF can’t share the format of a Logical File.

LF:
- A Logical file contains no data. Used to arrange data from one or more PF’s.
- For Every LF described you must have to specify a 1) Record Format Name & 2)
Either PFILE (for simple & multiple format LF’s) or JFILE keyword (for Join
LF’s).
- Using Join Logical File 32 PF’s can be joined. These files must be specified in
JFILE.
- Select & Omit specifications appear after key specification.
- Depending upon the keywords like VALUE, RANGE, and CMP either record are
selected or omitted.
o E.g. S ITEMNBR VALUES (1000 2000 3000 4000 +
5000 6000)
o E.g. S ITEMNBR RANGE (1000 5000)
o E.g. S ITEMNBR CMP (LE 5000 )

The principal requirements for join logical files are:

Each join logical file must have:


– Only one record format, with the JFILE keyword specified for it.
– At least two physical file names specified on the JFILE keyword. (The
Physical file names on the JFILE keyword do not have to be different files.)
– At least one join specification (J in position 17 with the JFLD keyword
specified).
– A maximum of 31 secondary files.
– At least one field name with field use other than N (neither) at the field
Level.
- If only two PF’s are specified for JFILE keyword, then JOIN keyword is not
required.
- Join LF’s are read only files.

3
SEQUENTIAL FILE:
- It is the file where the order of records in the file is based on the order of records
placed in the file.
- Can be processed randomly by RRN.

RECORD ADDRESS FILE:


- This can be used to process another file.
- ‘R’ in position 16 of File specification identifies it.
- It can contain
o Limits records that are used to process a file sequentially within limits.
o RRN to process a file by the same.
PRIMARY FILE:
- If a primary File is defined then system handles that.
- No need of defining SETON =LR.
- Only one (1) Primary File can be defined.

Difference between Database Files & Device Files:

- Database files are PF, LF, & files used as model files (in which no data exists).
- Device files are Diskette (DKTF), tape (TAPF) and printer (PRTF).

Display File:
- Display File is an Object in the system.
- It defines the format of the information to be presented on a display station.
- Can be created in 2 ways;
o Using SDA
o CRTDSPF in command line & writing the DDS.

Assume, Keep, CLRL in Display File:

- Assume means, when two record formats are used (say main screen & one window sub
file) then if you use in the window sub file, window will be displayed with previous screen.
- Keep is used, when say there 3or 4 record formats in a single display file and where ever
(in record format) you define keep, that will remain irrespective of what is there in
background.
- CLRL (clear line). It is having default as *YES.

Difference between CA & CF:

CF (Command Function): A record containing changed fields is returned to the program.

CA (Command Attention): Record is returned to the program but the record doesn’t
contain the data entered by user & no field validation is performed.

4
CPYF (Copy File) Concepts:
When you copy from one file to another, the target file may have a different
Record layout than the original file.

- When this happens their Formats are considered to be different.


- In order for CPYF to work properly, since this is a True database system, it
needs to know where to put the fields that have similar names.
- Normally CPYF does a space/byte copy and blasts the data from one file to
another very quickly.

FMTOPT (*MAP):
- Means copy the fields from file A to file B based on their names.
- This option is used by itself if all the fields in file A are also in file B,
but may or may not be in the same buffer position in the file.
- In addition, the attributes of the fields in file B can be different from file A and CPYF
will Map the data to the target format.
- Attribute in File B can have same attributes of File A or can have different lengths, but
according to name CPYF will MAP it.

Ex.
FileA FileB
R REC1 R REC2
NAME 10A CITY 3A/5A
CITY 3A NUM 2S 0/ 3S 0
NUM 2S 0 NAME 10A/ 8A
K NUM K NAME

FMTOPT (*DROP):
- Means that any fields in file A that are not also in file B should Simply not be copied--
they are dropped.

FMTOPT (*NOCHK):
- Means that CPYF should work the way it would normally work had the formats of the
two files been identical. Since they are not identical, CPYF will give you a formatting
error and fail. Adding *NOCHECK allows you to force CPYF to do a byte-copy anyway,
and ignore the format variance. You can end up with good data or bad data depending on
the target layout.

Difference between CQE & SQE:

- CQE stands for Classic Query Engine. But SQE stands for Sequel Query Engine.
- Examples of CQE is: OPNQRY
- Examples of SQE are: QM400, SQ400.
- SQE = 4 x Efficiency of CQE.

5
Difference between Packed (P) & Zoned (S):

- Packed is commonly used to reduce the amount of disk space used in a file.
- A packed field uses ½ byte per digit & a ½ byte sign (round up length).
- For e.g. if 15,5 P uses 7.5 (for digits) + 0.5 (sign) = 8bytes
- Where in for the above example Signed field will take complete 15 bytes.
- From a programming standpoint, anytime you do any arithmetic on a numeric
field if it is a not packed field, the compiler will generate code to Pack the data
before doing the math.
- If the data is already packed, the compiler will not generate that code & directly
jump right into math.
- Packed takes less space where in Zoned takes full length.
- Zoned more acts like Character.
- In CL *DEC always is PACKED. And in RPG if you don’t specify either zoned
or packed the default is packed.

Level Check Parameter (LVLCHK) :

Suppose your program is using a File, of which say the record Format Description
is changed but you are not aware of the same. So the program can’t process the file. The
system normally notifies your program of this condition. This condition is known as
Level check.

To see JOB LOG:

WRKSBSJOB QSYSWRK  QZRCSRVS (MSGW)  Option7 Study  Cancel


(C) Refresh

Locking Concepts:

File: File is locked only when “Renaming, Copying or any changes that are done in
attributes of the file. Otherwise they’re no locks.

Record: While writing/updating a particular record, only that record is locked. All other
records in the file are accessible for any other operation.

Difference between UDATE & *DATE:


The user date special words allow the programmer to supply a date for the program at
Runtime. The user date special words accept the JOBDATE from the job description.

- UDATE, when specified in output specifications, prints a 6-character numeric


date field. *DATE, when specified in the same way prints an 8-character numeric
date field.
- UDATE & *DATE can be edited when they are written if the ‘Y’ edit code is
specified

6
Difference between INFSR & *PSSR:
- INFSR: Controls File exceptions or errors.

- *PSSR: If there is an error in any of the MOVE statement, then program goes into
Abnormal End i.e. *PSSR routine. And in most of the cases it will display a return code
& error message.

Difference between SFLCLR & CLEAR:


- In SFLCLR data from Sub file Screen will be erased as well System
buffer/memory will also be cleared. But field level memory will contain the
values internally. You will get only the last record contents.
- Simple CLEAR op-code is used to initialize the field level values.

Difference between Bind by Reference & Dynamic Call:

- In Dynamic call, when the command is issued to the OS, the called program is found by
name & loaded into the memory. If another dynamic call is issued on the same program
then one more copy of the program is loaded in to the memory so on & so forth.

- But in Bind by reference the location of the program in memory is found & that
version is used. Copy of the program is needed in bind by reference no matter
how many times it is used.

Difference between CALLB & CALLP:

CALLB: Means calling a “Bound Procedure”.


Can be used only in Procedures.
Module should be bounded in your program.

CALLP: Calling a Prototyped Procedure.


Can be used anywhere where there is Prototype.
Can be used while calling External Programs.
Can be used while calling External functions like service programs, java classes

Advantages of Data Area Data Structure:

- When this is defined in factor2, RPG/400 program implicitly retrieves data from
the Data Area at program start & writes data to the data area when program ends.
- No Need of use IN & OUT to read & update data area.

How to Read a Record that is Locked by the Some Other Program:

INFDS will come into picture. It will give/contain the return/exception.

7
Explanation:

Var1 READE Filename 50(Equal)


50 MOVE ‘Y’ Var2
N50 MOVE ‘N’ Var2
Explanation of this code is If record is found then 50 is OFF, then control will go to N50
& flag value will be ‘N’.
If record is not found then 50 is ON, flag value will be ‘Y’. Control goes to 2nd line.

Difference between Z-ADD & Z-SUB:

Z-ADD will move zeros to Resulting field & then move value of Factor 2 to Resulting
Field.
Z-SUB will do the same way. Moving zeros to Resulting field & then subtracting the
value present in Factor2. (i.e. Result Field – Factor2 = -ve of Factor2).

Difference between CHAIN & SETLL:


The main two differences between these two keywords are;
1. Chain operation puts lock in the record when the file is either
open or in Update mode. Where as Setll doesn’t lock the
record.
2. Chain copies the record to the internal buffer, but setll
doesn’t.
How to Know what Primary & Secondary Languages Installed in R450 & R520:

- Type GO LICPGM in command line. (Work with Licensed Programs Screen)


- Take option ‘20’ (Display installed secondary languages).
- Check for Primary Language: It will give a 4-digit code.
- And Description: As English or English DBCS.
- In bottom it will give (No secondary Languages installed).
- For RR400 (Power Link) it’s giving 2984 & English DBCS.
- For PUNE Server its giving 2924 & English as the Primary Language.
- For Hong Kong, Primary Language: 2984 & Description is English DBCS,
Secondary Languages are also installed, i.e. 2924- English, 2987- Traditional
Chinese DBCS, 2989- Simplified Chinese DBCS (PRC).
- Refer Screen Shot:

8
-

Uploading Excel Sheet data to AS400 System & Vice Versa:


Steps:
- Programs  IBM iseries Access For Windows  Data transfer TO iseries/Data
transfer from iseries.
- Dialogue box will pop up where in you have to give your file path & in next row
you have to give Library/file name.
- Then click on Details button & Disable “Use PC file description”.
- Give File type BIFF8 (MS Excel 8).
- In iseries File option give “Yes Create File & member”.
- Give Record length (as 9999)
- Authority will be Read/Write. Then click OK.
- It will automatically create Flat file object in your AS400 system in the specified
Library.
- Then prepare a Query File.
- By using Copy file (CPYF) command copy the data to Input File.
Query File: WRKQRY Select O/P type  Option3

3) The other way of Uploading/Downloading the data is as follows;


a) Type CMD in RUN.
b) Type FTP
c) Then FTP> O (open) 192.168. 71.29
d) It will ask for User-Id. Give TRG3
e) Then it will ask for Password give TRG3
f) Now FTP> CD (change directory) CHITTY (library)
g) FTP> LCD (local directory) [set C or D drive where u want to dump
the data)
h) FTP> GET QRPGSRC.ASSSIN (to download)
PUT QRPGSRC.ASSSIN (to upload)

9
FTP Concepts:

To down load source directly from the CL program to local PC in text format.
Steps:
1. In your local PC, in any of the drive create a “.bat” file say ftptrail.bat which
contains the following code.
- cd \
- cd ftpfolder
- ftp -s:ftp.txt

2. Create another file with name say ftp.txt that contains the executable commands in
FTP prompt say;
open 192.168.71.29
user mumtrg mumtrg
cd laxmanlib
lcd c:\ftpfolder
get qrpgsrc.mank5
bye
3. Now write a CL program with the following structure;
PGM
MONMSG
STRPCO
STRPCCMD PCCMD (‘C:\FTPFOLDER\FTPTRAIL.BAT’)
ENDPGM

4. Compile that code & call it a FTP screen will be popped up, wait for a second to finish
the FTP commands, then it will ask you to ‘Press any key to Return”.

5.Note: All my .bat & text file resides in C:\ FTPFOLDER.

6. To get all the sources present in a Source PF under a library is use “mget” instead of
“get”.

Name some of the Subsystems:

QBATCH, QINTER, QSPL, QCMN, QCTL etc. are the basic subsystems.

How to Copy Text File from AS400 to flat file in My library:

- If the text is in the AS400 folder (QDLS) then, Do CPYFRMPCD (copy from PC
Document) + F4.
- If the text is in other area, then CPYFRMSTMF (copy from Stream file)+F4

10
How to find all the details of the PF’s in a given Source PF with attributes:
- There is a system API or you can say, it is a system PF, where in all the PF’s
created by user (all) are stored with attributes & all the other details.
- We can use it as a simple PF; the unique key is “LIBRARY NAME”.
- So once you know the PF & key, then you can play with that.
- The name is QSYS/QADBIFLD.

Tips on Printer File:


- In printer file if you want “Number of Copies” to be printed is more than one …
then you have to select at the time of compilation.
- 14+ F4+ F10 +PAGE DOWN (look for no. of copies).
- It can be max of 255.
- Default Page Size is 66/132.
- Default Lines per inch to be printed are  ‘6’.
- Default Characters per inch to be printed are  ‘10’.
- If you want to print on both sides, then make the corresponding parameter as
*YES & give *TUMBLE in duplex parameter.

If you Know Library Name to Find What Source Files are there :
- Say the library Name is ‘LaxmanLib’.
- Type DSPFD + F4
- Enter the details, give File Name as  *ALL & Library Name as  Laxmanlib
- Type of Information will be  *BASATR
- Refer Snap Shot

- Then type STRSQL on command line & type the query as


- “ SELECT * FROM LAXMANLIB/OPT WHERE ATDTAT = ‘S’.
- It will display only the Source PF’s on that Library.
Or

11
- Simply you can type WRKOBJPDM & give your library name. It will give all
the objects in your library. And make position to “Q”.

How to Send mail/sms to other system:

- First you have to create/add mail id in the system by the command


“WRKNAMSMTP” (Work with Names for SMTP)
- Using this command, you enter all the details like;
o User id (e.g. sangeet)
o Address (S658460B)
o SMTP User id (sangeetrao.kumar)
o SMTP domain (patni.com)
o SMTP Route
- Then type SNDDST (send distribution), & enter the details.
- But to execute all these commands you need to have authority.
-------------------------------------------------------------------------------------------------------
RUNSQLSTM:

- Main disadvantage is, you can’t use a “SELECT” statement in this command.

Why & When we get Session Device Error:


In Sub-File prospective, whenever we are trying display Sub file with RRN <0.

How internally System Stores Loadall selected Records:


In QTEMP Loadall will store our selected records in memory as a New File with key as
RRN.

How to Make Milli/Micro seconds delay in AS400:

In AS400, you have to use SLEEP API to have milliseconds delay. The prototype is
given below.

D Sleep PR 10I 0 ExtProc ('sleep')


D 10U 0 Value

If you want microseconds delay in AS400, then you have to use USLEEP API. The
prototype is given below.

D Sleep PR 10I 0 ExtProc ('usleep')


D 10U 0 Value
C CALLP usleep(10)

12
How to Use EXTPGM & EXTPROC in RPGLE with Examples:

- For EXTPGM, a return value is required; the program calling the 2nd program
should pass one extra variable to the calling program. Refer sample code;

Called Program (ADD):

Steps for EXTPROC:

- For EXTPROC, we have to use EXPORT & Procedure Interface in the calling
Proc.

13
- Compile both called program & calling procedure with option 15 i.e. makes it
Module. (*MOD).
- Then using command CRTPGM, create the called program. In this case it is
FREE2.
- Refer screen shots.

FREE2:

ADD1:

14
Creating Program & calling:

Then call the program FREE2, it will display, total 15.


************************************************************************

Sub File types:


LOAD ALL (Page UP, Page DOWN by System)
EXPANDED (Page UP System, Page DOWN by User)
SINGLE PAGE (Page UP, Page DOWN by User)

In LOAD ALL sub file


All records are READ and with each record written to SFL, RRN is incremented.
Both page up and page down are handled by system.
SLFPAG < SFLSIZ

In Expanded Sub file


We have to use two main keys RRN – Relative record number, SFLPAG whose
position is 378 to 379 of type binary.
In Expanded SRRN goes on increasing but only record equal to SFLPAG are read
and display. Here RRN is incremented and SFLPAGE is moved to page Variable.
Here we use indicator for ERASE (SFLCTL) on when no record in SFL and off when
RCD in SFL Page down logic is written by page and Page up is handled by system.

SINGLE PAGE:
Both SFLSIZE and SFLPAGE are equal. In Single Page SFL following keywords
cannot be used
a) SFLDROP b) SFLFOLD c) SFLROLVAL
SFLFOLD & SFLDROP is handled by the system just like Load all Sub-file but not
by the program.

15
SFLRCDNBR (Sub file record no.): It is used to display that sub file page in which
given relative record number is to be displayed /specified .If this keyword is not used
then the sub file would display the 1st page by default.

SFLCSRRRN (Sub file Cursor Relative Record No.): Generally after declaring the
SFLCSRRRN, where ever you place the cursor in the Sub file Record part & hit
enter, the RRN value of that particular record is retrieved into the defined variable.
- And after that open the DDS in Edit mode (option 2), declare the variable in
hidden state with attributes 5 S 0H(hidden).

Return Cursor Location: (RTNCSRLOC)

If a window has to be populated only at some positions in the simple display file
& Sub file then use this key word.

WRKOBJLCK: (Work with Object Locks):


- Suppose you are trying to do something with a file, but the same is say is either
opened or used by some other user/program. This issue can be viewed by using
this command.
- If you have authority, even you end/cancel.

1) MONMSG: If the RPG/400 compiler stops because of errors, the escape


message QRG9001 is issued. A CL program can monitor for this exception by
using the CL command MONMSG (monitor message).
- There are two types of MONMSG;
i. Program level MONMSG
ii. Command level MONMSG
- Different types messages that are monitored by MONMSG are;
i. *STATUS
ii. *NOTIFY
iii. *ESCAPE
iv. *INFO
v. *INQ
- First three are monitored by a MONMSG, but last two are not monitored.

2) ITER operation transfers control with in a Do group from a DO to the ENDDO.


LEAVE is same as ITER, but transfers control to the statement following the
ENDDO.

3) CHGPF:
- Open the PF in Edit Mode & insert the required field with attributes.
- Save but don’t compile.
- Write CHGPF in command line + F4, enter the details + enter.
- It will come to QDDSSRC screen. Then update with DFU.

16
4) EXFMT in RPG is same s WRITE & READ in COBOL/400.
- EXFMT is valid for only Workstation (WORKSTN) file defined as Full
procedural (F) or Externally Defined File (E).

5) TESTN (Test Numeric):


- Main condition is Result Field should be Character field.
- Condition checks for the presence of Zoned decimal digits & blanks in the
character result field.

6) A. CONTROL LEVEL INDICATOR:

- L1 thru L9 are the control level indicators.


- Generally used in Control Break Programs & Report programs.
- Control level indicators need not be written in any sequence.
- Control indicators can’t be used, when an ARRAY is specified in 53-58. But can
use with Array Element.
- If same indicator is used for different record types then control fields associated
with that Level indicator must have same length.
- For Control Level indicators following things are important;
o Control fields can be specified for Primary or Secondary files.
o Control fields can’t be specified for Full Procedural files.

B. MATCHING RECORD INDICTORS:


- M1 - M9 are the matching record indicators.
- Used for matching fields.
- There should be a primary file & at least a secondary file to use indictors from
m1-m9.

7) What are the 3 types of queue?


a) Message Queue:
b) Output Queue,
c) Job Queue
d) Data Queue
16) Three categories of software on AS400?

a) Application software
b) Operating system software
c) Licensed internal code (LIC)

17) What are the Parts of physical file?


a) Object header
b) Record format
c) Access path
d) Data member

17
18) What is the Maximum length of Record format? 32766 bytes

19) Physical file can have maximum of 120 key fields

20) Maximum number of members in a physical file is 32766


21) Maximum number of fields in a PF is 8000.

22) What is the way to Add members in a PF?


A) To add members to a physical file is CHGPF then ADDPFM.

23) DSPFD: Will display total number of key fields in a PF.

24) DSPFFD: Will give total number of fields in PF, Length of each field and Record
format Number etc.,
- If you specify either SETLL of SETGT with *LOVAL and then READ it will
read the 1st record.
- If you use either SETLL /SETGT with *HIVAL and then READP it will READ
the Last Record.

25) DSPPGMREF:
- It is a CL command, and when it is used in RPG, it will give the objects used by
the called program and the details of the objects. (i.e. no of record formats, in
which library it is used, etc.)
- It is also gives the details of the calling program in addition to files & data areas.
- It won’t give details of Data structures.

26) PROGRAM SIGNATURES:


- It is similar to Record Format in PF.
- It is used in Service Programs i.e. each service program uses a program signature.
And all the other programs that use the service program checks for the signature
when as the service program is activated.

27) Shortcuts with Scroll: (Depends on the Emulator)


For Power Link;
- Shift + Scroll 1 is toggle between two sessions.
- Shift + Scroll 2 is Ending/Killing a session.
- Shift + Scroll 3 is, it will take you to Display Job Screen.
- Shift + Scroll 4 is, it will take you the logs of the particular job. (KMUSER)
- Shift + Scroll 6 to check, if at all any exceptions are there. It will show which file
or program is failed. It shows directly messages in QSYSOPR.

18
28) STRPCCMD: (Start PC Command)
- Directly from AS400 server you can open notepad/calculator etc.
- But prior to that you have to run this command on the command line STRPCO
(Start PC Organizer).

29) Using COMMIT control in RPG program


Either start journal PF after PF is created with required parameter on command line OR
in a CLP program, write the following pgm.
CLP program
PGM
STRJRNPF File () JRN () IMAGES (*BOTH)
STRCMTCTL LCXLVL (*ALL) CMISCOPT (*JOB)
CALL PGM(RPG1) PARM(PARM1 PARM2)
ENDCMTCTL
ENDJRNPF FILE (*ALL)
ENDPGM

RPG program
F PF1 IF E K DISK A
F K COMMIT
F DSPF1 CF E WORKSTN
C READ
WRITE
05 COMIT
06 ROLBK

30) What do you mean by %ABS?


It accepts number value as parameter, if numeric value is positive then it returns value
unchanged. If negative it removes the negative value and return positive sign
Syntax (Example):
V2 = -1
V1 = %ABS (V2)  1

V2 = -123
V1 = %ABS (V2-321)  444

V3 = -1234.567
V1 = %ABS (V3)  1234.567

30) In OPNQRYF if you want that records retrieved from OPNQRYF should be
written back to file then following code has to be written. For this we have to use

CPYFRMQRYF

19
PGM
DCLF FILE (PATNI2/CP534LF)
MONMSG MSGID (CPF0000) EXEC (GOTO CMDLBL (ERR1))
OPNQRYF FILE (PATNI1/CP534LF) FORMAT (PATNI2/CP534LF CP534R)
QRYSLT (‘INSMR=”S”) OPNID (QRY1)
OVRDBF FILE (CP534LF) TOFILE (PATNI2/CP534LF)
CPYFRMQRYF FROMOPNID (QRY1) TOFILE (PATNI2/OPPA + MBROPT
(*REPLACE) CRTFILE (*NO)
CLOF OPNID (QRY1)
GOTO END1
ERR: SNDPGMMSG MSG (‘Error’)
END: SNDPGMMSG MSG (‘Added’)
ENDPGM
- If PF to which you are writing this is not there then specify CRTFILE (*YES). \
- If you want to append existing rows, specify ADD in MBROPT (*ADD)
----------------------------------------------------------------------------------------------------

In a CLP program a user created CMD written in CL can accept less then given,
expect parameter only if it is No Mandatory PARM. This has been done in Taiwan
source.
-----------------------------------------------------------------------------------------------------
*CPF2103  Library already exist in Library list
CLP CPF9801  Object existence check, used with CHKOBJ command
-----------------------------------------------------------------------------------------------------

 In ILE RPG  Declaration type -> PR defines a prototype for a call and PI
defines a procedure interface.
C  defines constant
DS  defines Data Structure
S  Standard loan field, Array, Table
-----------------------------------------------------------------------------------------------------

 In RETRN opcode
If RETURN is executed the following things occur
- If Halt Indicator is ON then it would abnormally end program and return to caller
- If Half Indicator is ON, If LR on the Program ends normally, Closes all files
locked DS, Array, T is written and an external indicator is SETON.
- If Halt is ON and LR OFF then procedure return to calling routine. Data is
preserved for next time it is run. Files DS are not written out.
*PARM opcode is/should always be followed by PLIST, CALL, CALLB
255 parameters  CALL
399 parameters  CALLB/PLIST

 For checking number of parameters passed prototype & Procedure interface


definition for the call interface, rather than using PLIST and PARM

20
 An externally described file in position 22/flat file can be read if specified as
program described file in F. If DS is specified in Result, Data is directly moved to
DS.
F FLAT1 I F F DISK
I DS1 DS
C READ FLAT1 DS1

Built In Functions in ILE RPG


% ABS % ADDR
%ALLOC %BITAND
%BITNOT %BITOR
%BITXOR %CHAR
%CHECK %CHECKR
%DATE %DAYS
%DEC %DECH
%DECPOS %DIFF
%DIV %EDITC
%EDITFLT %EDITW
%ELEM %EOF
%EQUAL %ERROR
%FIELDS %FLOAT
%FOUND %GRAPH
%HOURS %CNT
%CNTH %KDS
%LEN %LOOKUPxx
%MINUTES %MONTHS
%MSECONDS %NULLIND
%OCCUR %OPEN
%PADDR %PARMA
%REALLOC %REM
%REPLACE %SCAN
%SECONDS %SHIDN
%SIZE %SQRT
%STATW %STR
%SUBDT %SUBST
%THIS %TIME
%TIMESTAMP %TLOOKUPxx
%TRIM %TRIML
%TRIMR %UCSZ
%UNS %XFOOT
%XLATE %YEARS

21
IBM Supplied libraries
QSYS: System libraries are maintained
QHLPSYS: Online doc. for some system
QTEMP: User temp lib
QSPL: Spooling lib

Library list command


1) CHGLIBL LIB () CURLIB ()
2) EDTLIBL
3) ADDLIBL
4) RMVLIBL
5) CHGCURLIB
6) DSPLIBL

Message Handling
SNDMSG
SNDBRKMSG
DSPMSG
MSGF

Device File
*PRTF
*DSPF
*TAPF
*DKTF

Data Type
P  PACKED
S  ZONED
A  CHARACTER
F  FLOATING
B  BINARY
H  HEXADECIMAL
L  DATE
T TIME
Z  TIMESTAMP

Entry of DATA in PHYSICAL FILE can be done in following ways


1) DFU
2) INTERACTIVE PROGRAM
3) BATCH PROGRAM
4) CPYF
5) STRSQL
6) CLIENT ACCESS UPLOAD
7) CPYSPLF
8) WRKQRY

22
View data in PF
1) STRSQL
2) STRQRY
3) RUNQRY
4) DSPPFM
5) STRDFU

JFILE, JOIN, JFLD, JREF


DSPFFD, DSPPGMREF, DSPDBR, FNDSTRPDM

To provide a LOOKUP on a particular field in display file .you have to follow the
following steps
1) Declare two hidden fields of length 10 one for record level field and 2nd for field
level field. These 2 fields have to be declared for each record separately.
To use the fields declared in RPG/RPGLE
Check for field level should be equal to field name on which you have to show
lookup window

EG: $RCDNM $FLDNM

$FLDNM IFEQ ‘AUDB1’


EXSR @INIT
EXSR @LOAD
EXSR @SHOW

How to restore user name in CLP program so that name can be used in pgm

RTVJOBA USER (&NM)  It is used to retrieve job attribute such as JOBNM,


USRNM, JOBNBR, RTNCDE
For retrieving USRNM use
RTVJOBA USER (&NM1)  NM1 Length 10 character
For retrieving return opcode used (Status when)
RTVJOBA RTNCDE (*RTNCD)  Length 5,0

- For Reading records from a file without locking then what you have to use
Specify N in H/N/P position at C-Spec so that records can be read without locking.

To open the file OPEN opcode, so that user can handle open/close event of file you
have to specify UC in file condition.

- Value of *LOVAL  -9999 (LEAST VALUE) for 4,0 length


- Value of *HIVAL  9999 (HIGHEST VALUE) for 4,0 length

- %EOF = ’0’ Record is found but not EOF


-------------------------------------------------------------------------------------------------------

23
- Difference Between IF and SELEC

Select eliminates the need for nested IF/ELSE group, which confused when 3 OR 4
level used

Multiple ENDIF operation is not required with select group. Only one ENDSL (or
END) operation ends the group
-------------------------------------------------------------------------------------------------------

- “%EQUAL” when used with SETLL/SETGT if value equal to value in KFLD is


found in PF, on which you are setting LL/GT. %EQUAL will be set to ‘1’ if no equal
value is found then it will return ‘0’

- %EQUAL is used with SETLL & LOOKUP opcode


- %FOUND  If it finds given search string /field then %FOUND is set to ‘1’ if not
found it returns

- ‘O’ this will be used with following opcodes


CHAIN, DELETE, SETGT, SETLL, CHECK, CHECKR, SCAN, LOKUP

Important Points:
- In Free format, we can’t use CALL statement. For that case we have to use
EXTPGM keyword.

Creating Commands:

- Write a CL program where in you put the command that you want to create the
shortcut.
- Structure of the CL is;
PGM
WRKQRY
ENDPGM
- Suppose if you want the short cut of the WRKQRY is say “WQ”.
- Create one more program with type CMD in the name of WQ (program name).
And write a statement as CMD in the program.
- Compile both the programs in QGPL, and call the first one i.e CL program.
- After you can always use that Short command as WQ for WRKQRY.

24
Debugging Issues

1) For debugging ILE PGM just use put *source  Debugging views option and
using STRDBG you can debug the program.
For debugging the inner call PGM use shift+F2  and by using option 1 add the
call program to list…After PGM is loaded to list use option 5 to display source
and set the break point

 In case of debugging ILE program through OPM Program i.e., ILE program
called in OPM program
- Compile the program with Debugging view = *SCRDBG
- STRDBG to debug OPM object then use Shift+F2 to add module in list and by
using option 5 set breakpoint in ILE PGM

2) For Debugging COBOL-ILE programs we shall use STRDBG. But while compile
you should take care of the following parameters. ;
a. Compile the code with Compiler Option as *SOURCE.
b. Press Page Down & enter the Debug View as *LIST.
c. Once the code is compiled, then continue with STRDBG.

3) While Compiling JAVA-COBOL, use the following command as the first line of
Cobol Program;
“PROCESS MAP NOMONOPRC NOSTDTRUNC OPTIONS THREAD
(SERIALIZE) “, before the IDENTIFICATIONDIVISION. And the code should
end with GOBACK rather than STOPRUN.

4) Debugging a Batch Job:


Steps:
- SBMJOB + F4
- CALL the “Program Name” + F4
- Press F10 for Additional Parameters.
- Look for “Hold on Job Queue” & make it *YES, press ENTER.
- Note down the Job number/user.
- Type WRKUSRJOB to monitor the job.(it will be in held state).
- In command Line type STRSRVJOB & enter the details. (Name, User, Job No.)
- STRDBG + F4
- Enter details for debugging.
- In command line type WRKUSRJOB, go to your job & “release it by option6”.
- It will give you a message to continue by pressing either F10 or Enter. (just like
step in debug).
- Once you finish debug, ENDDBG.
- ENDSRVJOB.

25
CPYTOIMPF:

It copies an externally described file to an Import File.


Import File: Means file created for a purpose of copying data between heterogeneous
databases.

RCVMSG & RTVMSG:

- RCVMSG is used to retrieve messages from a “Message Queue”.


- RTVMSG is used to retrieve messages from a “Message File”.

COMP:

-This operation compares factro1 & factor2.


- Must Specify the HI, LO, EQ indicators.
- If F1>F2 : HI sets ON.
- If F1= F2: EQ sets ON.
- If F1 < F2: LO sets ON.

Arrays:

Array is a systematic arrangement of data fields.

- Runtime
- Compile Time
- Pre Run Time
1. Run time Array is loaded while your program is running.
2. Compile Time is when your program is Created. And is a
permanent part of your program.
3. Pre run Time is loaded from an Array File.

Defining Arrays:
- Array name + comma (,)+ Index
- Array name with comma & index can be max up to 6 characters.
- Index is a Numeric field with Zero Decimal positions or Numeric constant.

26
Use of H-Spec Keyword (H OPTION(*SRCSTMT)):

- *SRCSTMT allows you to assign statement numbers for debugging from;


The source ID’s & SEU sequence numbers in the compiler listing. The statement
number is used to identify errors in the compiler listing by the Debugger & to identify
the statement where a run time error occurs.
- *NOSRCSTMT specifies that statement numbers are associated with the “Line
Numbers of the listing & the numbers are assigned sequentially.

Open Query File (OPNQRYF):


- It’s a CL command that allows you to perform many data processing functions on
database files (PF or LF).
- OPNQRYF command acts as a Filter between the Processing program &
Database Records.
- OPNQRYF creates a Temporary File for processing the data. It doesn’t create a
permanent file.
- CPYFRMQRYF is very much required to copy records from OPNQRYF.
-
RUNQRY example the following are PGM used 1st
PF – PRM1  Contains following fields
BSTY, PRLN, AGE, SEX, ID, DFLG, TDR, RT1, RT2, RT3, MSG1, MSG2, COD

Main Aim: To update all the records such that sum of (RT1.RT2, RT3) should be
added to TDR when SEX=M
These are 2 pgm  CLLE pgm  OPNQRYCLE and OPQRYPGM

OPNQRY CLE

PGM
DCL &SX *CHAR LEN (1)
DCLF FILE (TWANLIB/PRM1)
MONMSG MSGID (CPF0000) EXEC (GOTO CMDLBL (ERR1))
CHGVAR VAR (&SX) VALUE (‘M’)
OPNQRYF FILE (TWANLIB/PRM1) FORMAT (TWANLIB/PRM1/PARM1R)
QRYSLT (‘SEX = ‘M’)
OVRDBF FILE (PRM1) TOFILE (TWANLIB/PRM1)
MONMSG MSGID (CPF4174) EXEC (GOTO CMDLBL (CLOSE1))
CALL PGM (TWANLIB/OPNQRYF PGM)
CLOSE:
CLOF OPNID (PRM1)
SNDPGMMSG MSG (‘DONE’)
GOTO END1
ERR1: SNDPGMMSG MSG (‘ERROR’)

27
END1:
ENDPGM

OPNQRYPGM  update records in PRM1 on selected records from i.e., SEX=M


-------------------------------------------------------------------------------------------------

Very Important Message ID

CPF 2103  LIBRARY already exist in LIST


CPF 9801
CPF 9810  Check for object existence
CPF1023  Data Area cannot be created
CPF4131  Level Check/Open file is tried to OPEN
--------------------------------------------------------------------------------------------------
Use of *SHARE
When a file is opened in a CL PROGRAM it remain open and open data path (ODP)
returns to called program /EOF of file reached /another OVRDBF is used. When a
file PF is used in a current executing program its ODP cannot be shared other
program/procedures .So far sharing ODP between two programs you specify. SHARE
(*YES) in OVRDBF.

 In RCLRSC do not specify LVL (*CALLER) in CL procedure/program using


files. Since LVL (*CALLER) will close the files opened by procedure/program
and access to the files would end abnormally
 *DCLF cannot be used to declare files like TAPE, DISKETTE, PRINTER,
MIXED type files

SNDRCVF (Record format NM)


Advance commands
1) QCAPCMD  Checks for syntax of CMD string prior to running it
2) Prompt the CMD and receive the changed CMD string

QCMDEXE  To execute CL command in HLL program / CL.


CALL PGM (QCMDEXC) PARM (CMD CMDLEN)
CMDLEN  Should have default length 15,5

QCMDCHK  Performs syntax checking for single command and optionally prompt
for the command

CALL PGM (QCMDCHK) PARM (CMD CMDLEN)


CMDLEN -- 15,5 *DEC

28
Eg:
CALL QCMDCHK (‘CRTCLPGM PGM (OGPL/(23)’ 22)
MONMSG MSGID (CPF00006) EXEC (GOTO ERROR)
CPF0006 Syntax Error

 Selective prompting

To use PGMQ in Error Handling using SFLPGMQ create 2 CLP programs

RMVCLP  Removing MSG from MSGQ


SNDCLP  Send MSG to SNDPGMMSG

 In DSP file
Specify SFLPGMQ (10)  PGMQ
SFLMSGID
SFLMSGKEY
In Sub file control i.e. message sub file control

In RPG 
Specify *PSSR i.e., program status data structure and specify VARNM for program
to stored
Move PGM NM to PGMQ var and call SNDMSGCLP program the message, which
you want to show

*IP you want to display more than 1 message in PGMQ change Message location
from 24 to 23/22…
---------------------------------------------------------------------------------------------------
Cobol Programs
0001.00 *------------------------*
0002.00 IDENTIFICATION DIVISION.
0003.00 *------------------------*
0004.00 PROGRAM-ID. PTEST1.
0005.00 *---------------------*
0006.00 ENVIRONMENT DIVISION.
0007.00 *---------------------*
0008.00 CONFIGURATION SECTION.
0009.00 SOURCE-COMPUTER. IBM-AS400.
0010.00 OBJECT-COMPUTER. IBM-AS400.
0011.00 INPUT-OUTPUT SECTION.
0012.00 FILE-CONTROL.
0013.00 SELECT IN-F ASSIGN TO DATABASE-ZAA03P
0014.00 ORGANIZATION IS INDEXED
0015.00 ACCESS MODE IS SEQUENTIAL
0016.00 RECORD KEY IS EXTERNALLY-DESCRIBED-KEY.
0017.00
0018.00 SELECT OUT-F ASSIGN TO DATABASE-TAA99P

29
0019.00 ORGANIZATION IS INDEXED
0020.00 ACCESS MODE IS SEQUENTIAL
0021.00 RECORD KEY IS EXTERNALLY-DESCRIBED-KEY.
0022.00 **************************************
0023.00 DATA DIVISION.
0024.00 *--------------*
0025.00 FILE SECTION.
0026.00 *--------------*
0027.00 FD IN-F LABEL RECORD IS STANDARD.
0028.00 01 RRVFCT-R.
0029.00 COPY DDS-ALL-FORMATS OF ZAA03P.
0030.00 FD OUT-F LABEL RECORD IS STANDARD.
0031.00 01 OUT-R.
0032.00 COPY DDS-ALL-FORMATS OF TAA99P.
0033.00 *---------------------------------*
0034.00 WORKING-STORAGE SECTION.
0035.00 *---------------------------------*
0036.00 77 SW PIC 9(1) VALUE ZEROS.
0037.00 77 CNT PIC 9(5) VALUE ZEROS.
0038.00 *01 C-DATE PIC 9(8) VALUE 19000000.
0039.00 K2000 01 C-DATE PIC 9(8).
0040.00 01 FILLER REDEFINES C-DATE.
0041.00 03 C-FILLER PIC X(2).
0042.00 03 C-YMD PIC 9(6).
0043.00 01 END-DATA PIC X(3) VALUE "NO ".
0044.00 88 END-OF-DATA VALUE "YES".
0045.00 *-----------------------------*
0046.00 PROCEDURE DIVISION.
0047.00 *-----------------------------*
0048.00 SIJAK.
0049.00 OPEN INPUT IN-F
0050.00 OUTPUT OUT-F.
0051.00 K2000 CALL "ZZCURDAY" USING C-DATE.
0052.00 * ACCEPT C-YMD FROM DATE.
0053.00 PERFORM IN-READ THRU IN-EXIT.
0054.00 MOVE A3PLAN TO TAPLAN.
0055.00 PERFORM MAIN-RTN THRU MAIN-EXIT UNTIL END-
OF-DATA.
0056.00 PERFORM WRIT-RTN THRU WRIT-EXIT.
0057.00 END-RTN.
0058.00 CLOSE IN-F OUT-F.
0059.00 STOP RUN.
0060.00 *=====================*
0061.00 IN-READ.
0062.00 READ IN-F AT END MOVE "YES" TO END-DATA
0063.00 GO TO IN-EXIT.

30
0064.00 IN-EXIT. EXIT.
0065.00
0066.00
0067.00 MAIN-RTN.
0068.00 IF (TAPLAN NOT = A3PLAN)
0069.00 PERFORM WRIT-RTN THRU WRIT-EXIT.
0070.00 ADD 1 TO CNT.
0071.00
0072.00 PERFORM IN-READ THRU IN-EXIT.
0073.00 MAIN-EXIT. EXIT.
0074.00
0075.00 WRIT-RTN.
0076.00 MOVE ZEROS TO TACNT1 TACNT2 TACNT3
TACNT5.
0077.00 MOVE CNT TO TACNT4.
0078.00 MOVE C-DATE TO TADATE.
0079.00 WRITE OUT-R.
0080.00 MOVE ZEROS TO SW CNT.
0081.00 MOVE A3PLAN TO TAPLAN.
0082.00 WRIT-EXIT. EXIT.
0083.00 *=======================*
---------------------------------------------------------------------------------------------------
0055.00 IN-READ.
0056.00 READ IN-F AT END MOVE "YES" TO END-DATA
0057.00 GO TO IN-EXIT.
0058.00 IN-EXIT. EXIT.
0059.00
0060.00
0061.00 MAIN-RTN.
0062.00 IF (A4PLAN NOT = TAPLAN)
0063.00 PERFORM WRIT-RTN THRU WRIT-EXIT.
0064.00 ADD 1 TO CNT.
0065.00
0066.00 PERFORM IN-READ THRU IN-EXIT.
0067.00 MAIN-EXIT. EXIT.
0068.00
0069.00 WRIT-RTN.
0070.00 MOVE TAPLAN TO SAPLAN.
0071.00 READ OUT-F INVALID MOVE 1 TO SW.
0072.00
0073.00 MOVE CNT TO TACNT3.
0074.00 IF SW = 0
0075.00 REWRITE OUT-R INVALID DISPLAY ' ERROR='
TAPLAN
0076.00 ELSE MOVE ZEROS TO TACNT5 TACNT1 TACNT2
TACNT4

31
0077.00 MOVE SAPLAN TO TAPLAN
0078.00 WRITE OUT-R INVALID MOVE 1 TO SW.
0079.00 MOVE ZEROS TO SW CNT.
0080.00 MOVE A4PLAN TO TAPLAN.
0081.00 WRIT-EXIT. EXIT.
0082.00 *=======================*
--------------------------------------------------------------------------------------------------
0008.00 CONFIGURATION SECTION.
0009.00 SOURCE-COMPUTER. IBM-AS400.
0010.00 OBJECT-COMPUTER. IBM-AS400.
0011.00 INPUT-OUTPUT SECTION.
0012.00 FILE-CONTROL.
0013.00 SELECT IN-F ASSIGN TO DATABASE-ZAA02P
0014.00 ORGANIZATION IS INDEXED
0015.00 ACCESS MODE IS SEQUENTIAL
0016.00 RECORD KEY IS EXTERNALLY-DESCRIBED-KEY.

32
FAQ’s:
1) Types of DS
2) Types of DATAAREA
3) Explain RPG LOGIC CYCLE
4) Explain something on indicators
5) Chain and SETLL
6) DELETE LF member command.
7) SFLINZ and SFLRNA
8) EXCPT and UPDAT

9) SETLL, SETGT, CHAIN


10) DOW (Indicator is checked with OFF) and DOU (Indicator is checked with ON
condition).
11) SETON LR. What does it do?
12) What are the ways a program ends?
13) OVRDBF, OPNQRYF along with parameters
14) PRINTER FILE
15) DATAQUE, DATAAREA, MESSAGE QUE

16) SUBFILE TYPES: a) Load All


b) Expandable
c) Single Page
17) Diff between TABLE and ARRAY
18) Explain OVRDBF, FLATFILE, SNDRCVF
19) Advantages of Data Area Data Structures.
20) Difference between SKIP & SPACE.
21) Conceptually OPNQRYF.
22) Logical Files full concepts.
23) How to Read Subfile from CL.
24) How internally system handles PGUP/PGDN in Single Page Subfile.
25) SFLNXTCHG keyword.
26) Difference between SFLCLR & CLEAR.
27) Why/When we will get Session or Device Error.

Queries:

2. What is the CCSID for Arabic? Will it contain Shift In-Shift Out characters?

- CCSID is 420.
- Arabic is a single-byte CCSID without shift-in/shift-out.
- When you create DSPF in 5250, fields should be defined as “right-to-left” in
input.
- In BCDIC Arabic characters will take 1 byte.
- In UTF-8, it is 2bytes.

33
3. Is EXTFILE & EXTMBR works same as OVRDBF?
- EXTFILE and EXTMBR do NOT work like OVRDBF.
- These two OPEN the file directly without applying an Override. This improves
open performances, as the system doesn’t have to go and check for override.
- If override is applied, it must be applied to the file named on the EXTFILE
keyword as the file in position 7 of the F-spec ignores overrides when EXTFILE
and EXTMBR is used.

4. What is QRPLOBJ?
- System takes the backup of the programs in this.
- Any program can be compiled while running. When the compilation is successful,
the existing object is renamed to “Q…” & moved to QRPLOBJ.
- The active job still uses the older version & the renamed or new one will be in
QRPLOBJ until SIGNOFF/ RCLRSC command is issued.
- QRPLOBJ is cleared by IPL.

5. XML in AS400 i.e. RPGIV:


There are two types of techniques used while using XML in RpgIV.
- DOM (Document Object Model)
- SAX parser.
DOM creates a “Map” of the document for use by “Xpath”. Where in SAX is ‘Event
driven’.
In RpgIV the syntax is: %xml(xml-file/variable:’options’)

Local Data Area:

The LDA is just a space object created when the job is initiated.
When a space is created using the CRTS MI instruction, you can specify that the new
space does not have a
"context". A "context" is a library.

The Work Control Block (WCB) has a pointer to the *LDA so the access is pretty
direct/quick--even faster
than data areas.

How to convert Seconds to Date & Time:

Please find the peace of code to convert the same.

34
ASP (Auxiliary Storage Pool):

An ASP is basically a partitioned area of disk. ASP’s allow you to isolate


Disk activity to particular locations. If 1 ASP is damaged, it does not
Impact the data in other ASP's. For this reason journals can be sent to one
ASP while the data can be stored in another ASP. If you loose either ASP you
Can still recover your data from the other ASP. You can also use ASP's to
separate high activity data from low activity data thus impacting performance.

Another use of ASP's is the isolation of system activity to 1 asp and


Applications to other ASP's

Prior to the introduction of raid this was the only tool we had to provide
some sort of online recovery of data.

From a subsystem standpoint we are more interested in memory pools then ASP's

35
SQL RPGLE: (How to Use Cursor):

Following are the steps used to code/use Cursor in AS400 programs.

- Declare cursor
- Open Cursor
- Fetch the record
- Close Cursor
Find attached the sample code that tells the use of Cursor to fetch & process the record.

FCntpf if e k disk
D*
DSCMPNY S 15
DSSAL S 5 0
D*
C/ EXEC SQL
C+ Declare cntcur cursor
C+ for select CMPNY, SAL from LAXMANLIB/CNTPF
C+ where name = 'SANGEET'
C/End-Exec
C*
C/EXEC SQL
C+ OPEN CNTCUR
C/End-Exec
C*
C/EXEC SQL
C+ FETCH CNTCUR INTO: SCMPNY,:SSAL
C/End-Exec
C*
C/EXEC SQL
C+ CLOSE CNTCUR
C/End-Exec
C*
C SCMPNY DSPLY
C SSAL DSPLY
C EVAL *INLR='1'

36
How To Copy From One AS400 Box to Other Box:

1. CRTDDMF then CPYF to the DDM file.


2. FTP
3. SAVOBJ, SNDNETF, RCVNETF, RSTOBJ
4. SQL- CONNECT to remote, INSERT into remote file using SELECT.
5. SAVF file Concept can also be used. (Save your file in SAVF, transfer the SAVF
into your PC, and then upload the SAVF in the second AS400 box.)

Error Handling while FTP:

FTP return codes are 3 digits followed by a space/blank and then an error message.

The first digit tells you whether the response is good, bad, or incomplete.
There are 5 possible values for the first digit:
"1" = Positive preliminary – request initiated and another reply should follow.
"2" = Positive completion – request was successfully completed.
"3" = Positive intermediate – subcommand accepted, but the requested action is being held
pending receipt of further information.
"4" = Transient negative completion – subcommand not accepted, but the error condition is
temporary and the action may be requested again.
"5" = Permanent negative completion – subcommand not accepted, and the request did not take
place.

The second digit is the function grouping:


"0" = Syntax – syntax errors
"1" = Information – replies to request for information (i.e. help)
"2" = Connections – replies referring to the control and data connections
"3" = Authentication and accounting – replies for the login process
"4" = Unspecified – not currently used
"5" = File system – indicates the status of the server file system

The third digit provides a more specific meaning and ranges from 0 to 9.

The actual message text can vary for different server systems and companies. Some companies
create their own messages using exit programs to control client actions.

Open Data Path (ODP):

- An open data path is the path through which all input and output operations for a file are
performed.
- Usually a separate open data path is defined each time a file is opened.
- If you specify SHARE(*YES) for the file creation or on an override, the first program's open
data path for the file is shared by subsequent programs that open the file concurrently.
- Sharing an open data path improves performance because the OS/400 system does not have
to create a new open data path.

37

You might also like