As400 Faq
As400 Faq
PGM
MONMSG MSGID(SQL9010)
RUNSQL SQL(‘CREATE TABLE QTEM/TABLE AS(SELECT FLD1,FLD2,FLD3 FROM TESTPF) WITH DATA’)
COMMIT(*NONE) – THIS WILL CRAETE A NEW TABLE WITH FIELDS FLD1,FLD2,FLD3 FROM
TESTPF WITH THE RECORDS FROM TESTPF
There are two types of access path Arrival and keyed sequence access path
It depends upon the declaration of key fields in DDS and if there is a key field then it is keyed access path
or it is Arrival access path
File A has 1025 records and how to retrieve the no of records in CL? –
By using RTVMBRD we can retrieve the no of records for a file in CL (refer to Local server program -
retrieve)
1100 07/30/20
The RTNSUBR can be used like the LEAVESR in RPGLE, to exit the subroutine immediately. It
has an optional parameter, RTNVAL, that can be used to return a "return code". When I have
used this command it was to leave the subroutine, without a need for the RTNVAL. For
example:
How to handle error mesasage in CL and default monmsg types?
By using MONMSG command. There two types of MONMSG Generic level monmsg and Command level
Monmsg
Generic:
MONMSG MSGID (CPF0000)
Command level:
MONMSG MSGID(CPF0864)
List of messages:
Conditional operators and condition in CL and syntax for conditions in CL? having a variable A and it has
to execute when the number is leasser than 10?
We can also use the IF command and check whether the A =10 and if the condition is satisfied then put
GOTO statement and go to end.
If the condition passes it will execute the THEN part in CL and do is normal command used in Then part.
(Refer -IFTHEN)
We can call an RPG program by supplying RRN number and delete the record or we can use a SQL
statement DELETE to delete the Records from a file or we can also use CLRPFM command. (refer -
delete)
100 PGM 07/29/20
1100 ENDPGM
Use of Ovrdbf and scenarios when to use Ovrdbf - Refer to PDF study material
OVRDBF is a command to temporarily overrides the parameters of a Data base file. It is used in
association with OPNQRYF, to use different file with same record format in a program.
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.
By using OVRDBF we can share the access path to other programs. We can also set the pointer.
FNDSTRPDM or option 25
We can use OVRDBF to select which member needs to be used in the CLLE
MSGW in as400
WRKMSGQ(QSYSOPR)
WRKUSRJOB
By using DSPDBR
Batch debugging?
(6) AFTER RELAEASING THE SERVICE JOB WILL START AND WILL SHOW YOU THE SCREEN
AS BELOW:
(6) PRESS F10 AND ON THE COMMNAD LINE GIVE COMMAND 'DSPMODSRC'
(7) DSPMODSRC TO DISPLAY THE SOURCE AND TO PUT THE BREAK POINT
(8) F3 AND F12 TO GET THE SCREEN OF STEP(6), PRESS " ENTER TO CONTINUE"
(10)ENDDBG
(11)ENDSRVJOB
Static sql means, the sql statement remains the same value what we gave the program and dynamic sql
means the values will be changed inside the program based the on the parameters we receive inside the
program
parameters with a? mark in the sql statement where we can substitute the value to the sql statement.
(example - DYNAMICSQL)
1 Hoption(*nodebugio:*srcstmt:*nounref) 05/28/20
806 05/28/20
1 H OPTION(*NODEBUGIO:*SRCSTMT:*NOUNREF) 05/22/20
300 /END-FREE
Can we retrieve data in bulk using cursor without using loop and it should fetch 10 records at a single
shot
What are Sql set options - Sql set option establishes the processing options used in SQL statements, it
will not be executed and we can use only one SET option in SQL.
NAMING = *SQL,
CLOSQLCSR = *ENDMOD,
DATFMT = *USA,
TIMFMT = *USA ;
In rpg or rpgle i have a PF and its associated LF and pf doesnt have Keys and how to diff between that PF
and LF? how to differentiate the fileds of the PF and LF?it will read the values
From the file which has been read by the program even if they the same fields.
We should rename the LF record format name so the program will read the LF. Or it will throw error like
both files are having same record format name.
End-Ds;
I’m calling a program and its failing is there a possibility to get the line number?
By using code 0202 we can get the line number. (Refer - PSDS)
File information data structure and in which situations we will use it?
BY using fsds we can get the rrn number and we can the file name, rec name, and the record in the file
we can check the exsistence of records in a file by using FSDS without reading the file. Refer FILEDS
400 * 07/24/20
900 * 07/24/20
1000 * 07/24/20
1800 * 07/24/20
1900 * 07/24/20
2800 * 07/24/20
2900 * 07/24/20
3000 * 07/24/20
4400 C SETON LR
How differentiate between normal data structure and File information data structure –
The FSDS will be declared in the F spec with the file with key word INFDS and
Normal data structure will not be declared as INFDS with file, that way we can differentiate between
them.
Hoption(*Nodebugio:*Srcstmt)
F INFDS(FILEDS)
DFILEDS DS
DRECORD *RECORD
DDATA1 DS
DFLD1 10
DFILLER1 2 INZ('--')
DFLD2 10
DFILLER2 2 INZ('--')
DFLD3 4 0
how to use dtaaarea in program? by using dataarea data structure with keyword dtaara and by using in
to read date dorm Dataarea and out to write the records to Dataarea.
2 DFld1 1 10 01/10/21
400 C Seton LR
Compiler directives?
if A value is 2 and we are using Dou a=1 means it will go insisde the loop below the loop
we can put a if codition if a <> 1 means then leave the loop. Refer Dou
400 /end-free
For numeric field what i will use? diff between Zoned and integer and packed?
Packed will assign only one hexadecimal value at the end F but zoned will add F for all the numbers.
Refer Num_field.
NAME ATTRIBUTES VALUE
I- This is signed integer field. We can have negative and positive values in signed
integer field.
N- This is an indicator field and can be used with indicator data structure.
P- This packed field. The data in the packed field will be as ‘00000F’X. For example, if
there are two numbers 123 and -123 with length of 6. Then the packed field will be
‘000123F’X and ‘000123D’X, where F is for positive field and D is for negative field.
S- This is Zoned field. The data in the packed field will be as’F0F0F0F0F0F’X. For
example, if there are two numbers 123 and -123 with length of 6. Then the packed field
will be ‘F0F0F0F1F2F3’X and ‘F0F0F0F1F2D3’X, where F is for positive field and D is for
negative field.
U- This is unsigned integer field. We can only positive values in unsigned integer field
starting from range 0.
* = This is an pointer.
How to check the existence of record in a file before writing the record to file?
We can used FSDS to check the existence of a record in file before writing to it.
- in Cl we can use rtvmbrd file(mylibrary/myfile) nbrcurrcd(&records)
- We can FSDS to check the existence of record or we can use Setll and %equal to find if the record is
there in the file (Refer Equal) or we can do chain and %found to find
400 /end-free
Suppose I have two records and how to read the records?How to read the first record and what if I have
two ID as 1 same value and what to do in that situation?
Activation group
Activation group is releated to a job, when job ends activaton group [Link] giving the DFtact grp as
*N0 and giving the name to the activation group, it will reduce time for program execution and the
activation group created will not be killed until the user sign off the [Link] will be in No status and we
can use wrkjob and opt 18 to see the activation group when running a job or program. If it is a ILE
program then we need to give H Dftactgrp (*No) for subprocedurs when its is not compiled as a Module.
Move opcode and Can we move the character value to a numeric field using move opcode? or how to
covert the character value to numeric and move them in RPG fixed format?
We can use Move opcode to move character values to numeric fields and numeric values to charater
field. It will move the values from right to left and will not check for the
200 dA s 5P 0 08/11/20
300 db s 5A 08/11/20
500 c seton lr
How to find that how many duplicates are there for each ID in a file using sql?
By using Group by we can get the original values and by using Having along with count we can
When passing 4 parameters from program A where program B has only 3 parameters? what will
happen? –
The receiving pgm will have the first three values from the called program A.
That means the first values will be passed to B program without any error.
When using subfile when we enter option 4 in wrkmbrpdm one of the prompt appears and when
coming to the same screen that option remains same? why is it happening? -Refere AS400 study
material.
How to read a record with field name starting with A alone in Rpg using chain?
C/Exec SQL
C/End-Exec
select emp_sql.EMPNAME,EMP_SQL.EMPSALARY,EMP_SQL.EMPDEPT,
ON EMP_SQL.EMPID=[Link]
select emp_sql.EMPNAME,EMP_SQL.EMPSALARY,EMP_SQL.EMPDEPT,
ON EMP_SQL.EMPID=[Link]
select emp_sql.EMPNAME,EMP_SQL.EMPSALARY,EMP_SQL.EMPDEPT,
ON EMP_SQL.EMPID=[Link]
SELECT statement run complete.
select emp_sql.EMPNAME,EMP_SQL.EMPSALARY,EMP_SQL.EMPDEPT,
ON EMP_SQL.EMPID=[Link]
(refer W3schools)
Supoose if I pass 1 parametr to a program having 2 param how to over come that error?
There will be an error pointer not set for location referenced and we need pas the correct parameter to
overcome that error or we can check the joblog. Error name - Pointer or parameter error - (Pointer or
parameter error) (Refer - PARAMETERS)
We can use RTNCSRLOC to get the field name and SFLCSRRN to get the RRN number. By putting a
condition like if the field is ID then we can display the prompt screen. But we can’t use RTNCSRLOC in
subfile it can used in display file only.
[Link]
We need to check the condition if RRN =0 then turn off the SFLDSP indicator (refer - Loadall)
if rrn = 0;
*in46=*off;
endif;
/////////////////////
clrsfl in subfile - we should turn SFLCLR indicator then write to sflctl and turn off the SFLCLR indicatior
(refer - Loadall)
EX - endsr;
/////////Clear SFL////////////
begsr clr;
*in45=*on;
write CTL;
*in45=*off;
endsr;
///////////////////////////
When we try to move ABC to numeric field, it will move its number to numeric field for
Hoption(*Nodebugio:*srcstmt)
dA s 5P 0
db s 5A
c Move 'xyze' A
c Move 123 B
c a dsply
c b dsply
c seton lr
Group by is used to give the values in file without duplicates or we can also use DISTINCT to get the
records without duplicates
POSBDF or OVRDBF
By using MONMSG and refer MONMSG in this same document which is already explained
BY using ROW_NUMBER() keyword in SQL or we can also try with TOP keyword
mbalamuru/flatfile
[Link]
server-table/#:~:text=So%20to%20delete%20the%20duplicate,and%20after%20the%20delete
%20occurs.
It is used refer the attributes from the other file. We need to use the keyword REF(<<Filename>>)
before the record format name. In field, we need to use the keyword REFFLD(<<FIELDNAME>>)
Field level keywords?
When the file is compiled with LVLCHK parameter as *YES, then we need to complie the programs
dependent on this file or LVLCHK error will occur. If its value is *NO, then the record format level
identifier is not checked, hence no error.
Program status data structure is used to get the program information like status code, crt date, crt time,
user name, program name. BY using this we can get the error line number.
*PSSR
It is an error status subroutine, which will be executed if the program gets into error.
Check
For example, if I am searching M in Mohanraj, then it will return the position 2, because at staring
position M is present.
Scan
For example, if I am searching M in Mohanraj, then it will return the position 1, because at staring
position M is present.
SFLRCDNBR
In subfile, if we press enter it will come back to first page. To avoid this we are using this keyword to
keep track of records.
sflrcdnbr = recno
except
This keyword is used to write the output to printer files or Output files
%error
Eval will check for data type, if we are moving numeric values to charater field it will be error, eval will
be moved from left to right.
Then it will start moving from M. If we need to move from right to left we can use EvalR
Move opcode will not check data type and move the values from right to left.
Then it will start moving from N. If we need to move from left to right we can use MoveL
to find value in a array?
arr(1) = 'Cornwall';
arr(2) = 'Kingston';
arr(3) = 'London';
arr(4) = 'Paris';
arr(5) = 'Scarborough';
arr(6) = 'York';
If the element is found then the indicator 81 will be *on or it will be *off.
No, when passing parameters we need to give PGM and ENDPGM. But it is good to use these keywords
always in the program.
IF setonlr and return is not declared and what error will occur when didnt mention it
When passing characters fields to numeric in parameters this error will occur
To avoid these errors, we can pass it as hexadecimal value. For example if field B is 10 length
Referenced to parameters is not passed or Pointer not set for location referenced.
If we are having program with duplicates in file how to write original values alone
READ: RCVF,
Read records
Goto READ.
count of file
test opcode
Is used to check whether any character is used in Character field.( Refer - Testn)
sorta and put a condition wheter array(1) =*blanks and if it is blanks then it is an empty array.
D Number S 1 0 DIM(10)
C SORTA Alpha
C IF Alpha(1) = *BLANKS
* Empty
C ELSE
* Not empty
C ENDIF
C IF %XFOOT(Number) = *ZEROS
* Empty
C ELSE
* Not empty
C ENDIF
C RETURN
totDigits = %XFoot(%len(qty))
how to acess file from one server to another without using ftp? - ddm
RMTLOCNAME(KC105)
MBROPT(*ADD)
Refer - [Link]
how to create multi member PF and add records in multi member PF?
Then use command ADDPFM and create the Mbr - MBR2 and MBR3
Use UPDDTA command to add date by mention the member name with it.
Refer - Multi
Refer - Multimbrcl
Refer - Multimbrpg
If there is thre departments it,hr,as400 for a field department and how to read all the three in a single
shot? - read setgt dow not eof(file)
We can use settl *loval and dow not %eof and read all the records.
Flat file? how to read the seprate fields in flat file? - Flatfile is a PF type file and it will not have any
source. The field will be same as the file name and we can inert the
records in that file as whole single one. We can use flat file to move data to alcl variable like notes data.
By using DSPFD we can see the file descrption and using sql we can find
H spec dump - H Debug(*no) means no dump will be performed and H Debug(*Yes) means dump
operation will be performed.
H spec Nodebugio - If it is not used seperate break points will be set for the fields in a file. If used it will
set a single break point.
Suppose Im having two files with same field name how to distinguish between them? - By using Prefix
(Refer - Dynamic sql)
Subprocedures and modules - Refer - Subprocedures and module document. Pgm - Getday - 2 and
Getdayname - 1.
EMPID EMPSALARY
101 - 2000
101 - 3000
102 - 5000
102 - 3000
105 - 5000
how to get the total sum of all IDS like 101 = 5000, 102 = 8000, 105 = 5000?
BY Empid
How to find whther there any character in a Mobile phone no? - Testn
When the Indicator associated with Testn is on thn there is only numerics in the field or it is an error
field.
RTVJOBA
In kfld what if I didnt pass the value for 3rd field - It will execute without picking the 3rd field value
maybe the 3rd field value will be 0. (Refer - Kfld)
*arrays in synon? If I create array in pgm a and after closing the pgm a, what if i tried to open it in pgm
c? will it open?
What if there is job running so much of time? Reading each record in a file one by one? what can we do
in that time?
12/01:
How to handle errors in Cl? Monmsg, Progam level and cmd level messsage and refer google
Can we read a PF file in CL? We can read a PF file with DCLF command and we can read only one file and
we need to use OpenId concept to read till 5files
how to find how many records are present in a PF through CL? RTVMBRD (refer - Reterive)
Have u used RTVJOBA? Which user is using the job? Rtvjoba command is used to give job name,no,user
name, currentuser of the job, Sbmuser,outq,jobq,Jobtype,Sbmjobnbr,jobsts.
Suppose I need to get the data from datarea from Cl? RTVDTAARA
What cmd to is used in CL to convert the date format? CVTDAT command is used to convert date. (Refer
- CVTDATE)
How to copy the data from CSV file to PF file and vice versa? CPYTOIMPF and CPYFRMIMPF
What is %Scan and %Check in rpgle? %scan - to find occurence of charater and %check to find non
occurence of character (Refer - CHECK_SCAN)
%Diff in rpgle? How it will calculate the differnce between the dates? %diff is used to return differnce
bettween two dates or two times (Refer - As400sce4)
Have u used Monitor block? Monitor block is used for error handling method along with On error
opcode.
For example if trying to convert the Blanks to zero's with %Dec it will throw an error so there we can
code the logic in on-error block according to the situation.
Have u used Chain(n)? To read the record without applying the lock
I have a PF? I want to read all the records in RPG? There is no key field in the file? How to read all the
records? If there is no key field then we can use *start
Setll *Start PF
Read pf
field operations
Read PF
enddo
Diff between Setll *start and *loval? When there is a key field we can use *loval and when there is no
key field we can use *start.
How to do them in Sqlrpgle? Declare Cursor, Open cursor, Fetch from C1 into file name or datastructure
name,Fech next from C1(Refer - Cursor)
How to read from last record in sqlrpgle? Fetch Last from C1 ,Dow sqlcod = 0, Fetch Prior from C1.
What will happen if I didnt spcify Fetch Next from instead of that if i give fetch from? No differnce
between them.
Result
**
***
****
String 3 = %xlate(locase:Upcase:String1)
Pos = %scan('a':String)
Dow Pos<>0
Num = Num +1
Pos = ('a':string1:Pos+1)
Endddo;
Num dsply
PF - 1
Mohan It 80
Shomi ECE 70
Ram It 50
Vicky ECE 90
how to get the count of for each dept with total student no?
Transaction file:
102 01/01/2021
Pendig file
Cust id
Need to write rpgle program to find the customers who has done the transaction 6 months before from
todays date and we need to write that cust no to pending file? (Refer - AS400SCE4)
[Link] would you achieve this requirement with out using RPG/RPGLE pgm,but by using only CL?Read a
database file and display file contents on the screen when enter key pressed the next record should be
displayed on [Link] the last record is reached or when F3 key is pressed the program should exit
if the file is empty,a message should be displayed indicate that there are no records to display. Database
file Name=EMPDBF Fields in EMPDBF to be displayed on screen Employee Number- EMPNUM(5,0)
Employee Name- EMPNAM(30,A) Employee Address-EMP ADDR(50) ?
We need to use two display file one to get the data and one to display them.
where will control be passed after the execution of the *pssr subroutine if the factor2 of the endsr?
Control will return to the next sequential instruction
what is message subfile?..Message subfile is special file contains multiple messages taken from program
message queue and placed in message sub file for display on the screen.(need to check)
if &var='good++++' &var2='day' &var *cat &var2 &var1 *tcat &var2 what is output
Answer:
first variable)
first field).
can we create a member in a logical file? You can add members to a LF. All the members in a PF must be
added to its logicals using ADDLFM
i want to display the 10000 record in a subfile by using loadall , can we do it? No we cant because the
buffer size is 9999.
of the data area like 91-92,93-94 at a time up till 100? To read the specified length of a data raea in cl
there we can specify the substring length in RTVDTAARA command.
PGM
0004.04 ENDDO
0007.00 ENDDO
0008.00 END:
0009.00 ENDPGM
write the SQL statement to retrieve the 2nd Highest salary ammount(File Name="EMPLOY",Fi..
14/01:
How to design a program like if i give a file name it should disply all the library names where it is stored?
Which subroutine is initialed called when runing rpgle? what will happen when *inzsr it is not used?
from where the program will start?
*inzsr will be called defaultely and when it is not used it will start from beginning of the program.
Joint logical files? whther it can be used in sql? Yes we can run Joint logical files in sql. Example -
FINDPRO file in XGSI.
What are the indicators used in Read operation ? HI LO EQ and their line no? Hi - 74 lo - 76 Eq - 78.
What is subsystem? What is the parent subsytem of i-series? if i submit a job which subsytem will be
taken directly?
Subsytem is a specialized environment used for the execution for the jobs. Qbatch is the default sbs.
when we found job in MSGW using WRKSBMJOB,simply we can enter into job log using 5 option.
the error occurred line,here we can change any values directly using EVAL then after press F3,it will sho
wjob log screen,then again press f3 to come to MSGW [Link] press 7(display message screen) to
continue the execution of batch job we press G(continue).then it will execute remaing steps without
abnormal ending the job.
Level check error? how to resolve it without using Chgpf? In Cl we can use OVRDBF with LVLCHK as *NO
and in RPG there is no other way.
Scan and check opcodes? to check occurrence and non occurence of character.
C Sorta Arrayname,
Look for any data in array? If I didnt get any record in array what value will i get in that array? If we use
an indicatior with Lookup it will turn it off when the record is not there
when the record is present the indicator will be on. EQ - In (Refer - Array1)
If we give *hival setgt with read it will not read any reord and if we use readp it will read the reords.
(Refer - Equal1)
Covert float value 99.9999 and covert to decimal? Num = %Dec(99.9999:5:4) (NEED TO CHECK)
Diff between dspf and subfile? main compomemts for subfile and diff bettween sflrcd and sftctl?Sflpag
and sflsiz? Refer google.
Can we display 110000 records in a subfile? No it wont be allowed because of buffer size.
%Xlate? Used to convert from Lower case to upper case (Refer - AS400SCE1)
How to call the programs in free format and how can we pass the parameters?
**free
02 ctl-opt option(*nodebugio:*srcstmt) ;
04 Parm1 char(5) ;
05 Parm2 packed(3) ;
06 Parm3 char(1) ;
07 end-pr ;
11 Var1 = 'Hello' ;
12 Var2 = 1 ;
13 Var3 = '' ;
14 OtherPgm1(Var1:Var2:Var3) ;
15 if (Var3 = 'Y') ;
other than chgdtara and out there is any command to update dataarea?
How to pass parameters in cl if we are not specifying pgm and end pgm commands? To pass parameters
PARM is a neccessary keyword and we need to specify the parameter name in PGM keyword. In Param
we should specify that variable name to passed and we need to declare those variables in a cl) or we can
concat those variable into a single variable and use
it in PGM.
External ds and normal ds? In E DS we can use ecternal files and fileds and DS is a normal DS.
Move flat string value to ds? Yes we can move a Flat string to a DS.
After reorganizing, the records in ACCOUNT get arranged as per the key value of ACCOUNT.
Clrpfm will compress the deleted record space and Delete sql wil not compress the space.
Delte will not clear the space and clrpfm will clear the space
Journals?
PGM
STRCMTCTL LCKLVL(*CHG)
CALL PGM(*LIBL/CCTEST2)
COMMIT
CALL PGM(*LIBL/CCTEST2)
ROLLBACK
ENDCMTCTL
RETURN
ENDPGM
DCOUNTER S 5I 0
C DO 7 COUNTER
C WRITE FCCTESTPF
C ENDDO
C RETURN
What is the purpose of PR and PI in calling program and called program? in Called program PR is comp..
In Prototype we define the variables as parameters for calling. In Procedure interface, we define both
the variables and the calculation or function of the procedure. Prototype is mandatory in both calling
and called programs because we have to pass parameters and receive some parameters while calling
Whereas the data area can have the data stored in it until
the user opts to clear it. In DataQ one had variable for
We can use DDM concept for this. So we can access the file in prod from Dev.