Vous êtes sur la page 1sur 14

Q. How to update only a field of a PF in an RPG program.

I don't want to update the record, only one field.


A. If file FileA has fields field1, field2, field3, and we want to
write out field2 only ...
C...except. Change

OfileA...E...Change
O...............field2

For Free Format try out following...

Update Recformat %fields(field2);

Q. What would be the result on writing a data record to a PF


file using the "WRITE" opcode after the SETON *ON *INLR
statement?
A. All files used remain opened till it executes last 'C' spec
Statement.

Q. 1) How to define keyed file in CL pgm.


2) How can I read particular records in CL pgm from
database file.
A. 1. Using DCLF command
2. OVRDBF with Position parameter
DCLF FILE(&FILENAME)

OVRDBF FILE(&FILENAME) POSITION(*KEY 1 FMT2 X'123F')

The system searches for a record from the record format


FMT2.
A single key field is used in the search (even though the
key value may have more key fields).
The record contains the hexadecimal value 123F (the
hexadecimal equivalent of packed decimal value 123.0). You
get this record when it is found.

Q. 1) How to declare a file?


2) How to define a display file?
3) How to monitor error messages in RPG?
4) How to find the attributes for subfiles? and what is the
DDS for subfiles?

Answer to 3)
Method 1:

To monitor Error in RPG make use of


MONITIOR
.....
ON-ERROR <some error number>

ENDMON

u can place a subroutine , procedure etc under this to


handle the error for the following

Method 2:
Activate the Error Indicator, for the field you want to
place the error handling
if any error occurs for that field %error is SETON, and u
can use this indicator to take action accordingly

1Ans).DCL VAR(&A) TYPE(*DEC) VALUE(54)


2ans). DCLF FILE(LIBNAME/FILENAME) RCDFMT(SCREEN NAME)
3Ans.) In FREE FORMAT WE ARE USING MONITOR AND END-MON,THE
CODE LIKE MONITOR;
--------
ON-ERROR(FILE NAME/PGM NAME);
---------
END-MON;
AND ALSO IN RPG/400 WE ARE USING *PSSR Subroutine WE CAN TRAP
THE ERRORS
AND ALSO WE R USING FILE INFORMATION DATA STRUCTERS, PROGRAM
STATUS DATA STRUCTERS WE CAN TRAP THE ERRORS
4Ans)in subfile we can find out variables and variables
lengths in subfile record format key word.

Q. I have 1000 records in a file. I would like to generate 10


identical reports from this record with same format
(structure of records) how do I do this?
A. Override yr printer file with having copy(10)
it will generate 10 spool file.

Q. How do you code file / field renames in ILE RPG?


A. Define a Data Structure in ILE RPG.

D New_File E DS EXTNAME(Old_File)
D New_Field1 E EXTFLD(Old_Fld1)
D New_Field2 E EXTFLD(Old_Fld2)

You can use PREFIX keyword instead of EXTFLD on different


Way.

Q. steps for debugging two rpg programs????


A. If you question is related to debug 2 pgms
(PGMA>>>Calling>>PGMB)both are rpg pgms.

Compile PGMA with source type(*SRCDBG) and PGMB with


(*Source)

1)STRDBG PGMA
2)In debugging view press F14 and select option 1 ,specify
pgm name ,library.
3)Press enter ,select module source from list, add break
point in PGMB
4)Press F14, add brk point sin PGMA.
5)Call PGMA
It will start the debugging for 2 programs
Q. What is scan and check ? give me real time scenarios where
we used these keywords in your projects?
A. FACTOR 1 OPERATION FACTOR 2 RESULT
Comparator SCAN Base left most
String: Length String: length position
of string

The SCAN operation scans a character string (base string)


contained in factor 2 for a substring (compare string)
contained in factor 1. The scan begins at a specified
location contained in factor 2 and continues for the length
of the compare string which is specified in factor 1.
The result field contains the numeric value of the leftmost
position of the compare string in the base string.

The CHECK operation verifies that each character in the


base string (factor 2) is among the characters indicated in
the comparator string (factor 1). Verifying begins at the
leftmost character of factor 2 and continues character by
character, from left to right. Each character of the base
string is compared with the characters of factor 1. If a
match for a character in factor 2 exists in factor 1, the
next base string character is verified. If a match is not
found, an integer value is placed in the result field to
indicate the position of the incorrect character.

Q. what is the difference between array and multiple occurence


data structure?
A. Multi occurance Data structure can hold different types of
data per record where Array can have only one data type.

we can read multi occurance DS using OCCUR and for arrays


we have to read based on index

As you know all Multiple occurrence DS is a data


Structure, Means Collections of dissimilar data, It treat as an
Multi-dimension Array.

We read array By their Index positions, But Mul-Occr DS we


first set the positions by OCCUR Opcode and positions on
Factor1,Then only we can read Mul-Occur DS.

Q. I have two sessions S1 & S2 under this 3 jobs(say j1,j2,j3


under session S1) And 2 jobs(Say j4, j5 Under session S2)is
running. How many QTEMP & how many LDA will create for the
same.
A. For two sessions 2 LDA and 2 QTEMP will be created. Wihtin
the first session, 3 jobs are submitted so that these 3
jobs will have their own QTEMP (3 QTEMP) and LDA (3 LDA).
Second session submitted 2 jobs so that this will have its
own QTEMP (2 QTEMP) and LDA (2 LDA).
Total numbers of LDA and QTEMP will be 7 and 7 respectively.

Q. What is the purpose of Panel Groups?


A. Panel Groups is an Object on AS/400 (*PNLGRP)
CRTPNLGRP = to create a panel group program
For Help screen using Panel Group
On AS/400 all help screens used Panel Group objects.

Q. How can we read a particular record from the database file which is
not having DDS (Flat File). For example, there are 100 records in the
flat file. How can we retrieve 15th record in RPG/400 program (Without
using CL.
A. We need to use the following.

Factor 1 = 15
Opcode = CHAIN
Factor 2 = File Name

Yes ,Using RRN of the file we can retrieve.


Chain the file with RRN or Query the file with RRN
select * from temp33 where RRN(temp33) = 15

Q. How can we find out whether the job is interactive or Batch


through RPG program?
2) How can we find out through CL program?
A. using RTVJOBA command...
if the TYPE option gives value "1" then it is interactive job.
if the value is "0" it is batch job.

QUSRJOBI API can be used to find out whether the job is


interactive or batch from RPG program.

Q. what is the difference between the cpyf command crtdupobj


command?
A. CPYF command are used to copy the all data from one data
base file to another or copy the required data from one
file to another files.

when we copy the data from one file to another file that
time if user want to create new file then create new file
object by using CPYF command. We can add/replace the add by CPYF
command while by CRTDUPOBJ command can’t.
We can copy specific records with the help of CPYF command but we can’t
do with CRTDUPOBJ.

CRTDUPOBJ - this command used to create duplicate object with data or


without data from any existing object your AS400 system.
Q. what is meant by hidden field , why it is used?
A. In Hidden field user cant be modified. The difference
between hidden field and non display field is that in non
display user can do modification and cursor will point to
that field. in hidden field cursor will not point. Hidden
field declared type as H.Normally hidden filed is used to
return the value of RTNCSRLOC(Return cursor Location),CSRLOC
(Cursor Location)function.

Q. What is journalling and commitment control?


A. Journaling is a function which records the changes in a
file in a journal.
Commitment control is a function that allows you to define
and process a number of changes to database files
as a single unit (transaction.
Q. 1.CA(command Attention key)& CF(command Function key)
difference with example? Please can any body tell me in real
time exp?
2.Can any body tell me some mandatory function keys using
while creating any screen with use of SDA-FUNCTION
keys?
A. The CF and CA keywords are used in display files to enable
function keys. CF01 and CA01 both enable the F1 key on your
keyboard. The difference is that a CF (command function) key
updates the fields in your program, while a CA (command
attention) key does not.

A CA key also bypasses any field editing. For example, if


you enter a bad value into a field that has the VALUES
keyword specified in the DDS and then press a CF key, you
will get an error, and the screen will not be returned to
the program because the field doesn't pass validation. If,
on the other hand, you hit a CA key, the editing is
bypassed, and the CA key is returned to the program
(although the fields are not). The best use for CA keys is
keys that exit a screen without updating data--typically,
CA03 or CA12 in iSeries applications.

Q. 1..Write an sql query to find the employee name who is


having 2 phone number?
2.Write an sql query to the second highest salary of
the employee?
A1. select Emp_name from Table-Name group by Emp_name having
count(Phone_number)=2
A2: select max(SAL) from EMP_TAB where SAL < (select max
(SAL) from EMP_TAB

Q. I would like to know under what circumstance the object


will get locked on AS400.
A. In most of the cases files(*file) will be locked.
Reason: If any program is using that particular file.

Q. How do you know if a record exists without doing a READ and


CHAIN?
A. setll KeyA FileA;
if %equal( FileA );
...
endif;

By using file information data structure we can find the


number of records in a file.

Q. How to retrieve particular field records from a physical


file, say I have a physical file called 'employee' in it i
have to retrieve the records of a field 'admin' present in
pf 'employee' using rpg,but I should not use logical file
or openquery file.
A. We can use embedded SQL in RPG to retrieve records. It works
faster as compared to other methods.

TESTN:- this opcode test whether the variable placed at


result field is numeric and return the high(HI) indicator
value as '1'. Rest LO and EQ will remain off.

Eval:- This opcode is applicable for only same type of


character. Eg:- if you want to move a character value to
numeric value then IT WILL THROUGH COMPILATION ERROR.
By default, eval opcode will move from left. For eg:- let
abc=' ' then
eval abc='AAA' abc will be 'AAA '

EVALR:- same as previous difference is right adjust.

TIME:- This opcode will return the system time of day.

MONITOR:- this opcode is used to monitor the error in rpgle


program.

ENDMON:- This opcode is used in conjunction with MONITOR


opcode.

ON-ERROR:- This is used again wilt monitor and endmon opcode


MONITOR
ON-ERROR
ENDMON

COMMIT:- This opcode is used to commit the changes in the


file.
COMMMIT keyword is used in F-specs like
Fabc UA F DISK COMMIT(*IN03)
:
:
C If *in03='1'
C COMMIT
C ELSE
C ROLLACK
C ENDIF

If Indicator 03 is '1' then commit all the changes done in


the database file. Else rollback is done onto that database
file.

Q. I have a PF(ABC)with no key fields.


PF(ABC)have 2 fields (cusno and cusname).
Please let me know how can I read the cusno = 1150 directly
from PF in CL and RPG program(Without creating the LF and
without reading the complete file and then compare 1150)
A. In CL PGM
Do CPYF from file ABC to ABC qtemp with the selection
field (CUSTNO) = 1150 (value) so ABC in qtemp have only one
record with that cust no. then read this file in CL program.
In RPGLE...
you can used SQLRPGLE program and write a SQL select
statement on the on file ABC.

Q. what is mean by *MAP and *DROP? what commands use these two
keywords? why are they used?
A. Why *MAP and * DROP?
When we copy data from FILE A to FILE B and if FILE A has
20 fields and FILE B has 30 fields (say there are 10 fields
which is not common among both the files). Using *MAP and
*DROP option we can copy the data from FILE A to FILE B.
All the fields would be mapped between both the files and
the unmatched fields would be dropped.
Which command uses *MAP & *DROP - CPYF command (Copy file).
Q. how to display all the members records in a physical file
without using ovrdbf?
A. The question mean to display the records in particular
members of Physical file ...this can be achieved by
EXTMBR(member name) along with the file in f specs

as it is clearly mentioned that OVrdbf is not allowed ...


use EXTMBR('*ALL') in file specification.

Q. How do you code file / field renames in ILE RPG?


A. Define a Data Structure in ILE RPG.

D New_File E DS EXTNAME(Old_File)
D New_Field1 E EXTFLD(Old_Fld1)
D New_Field2 E EXTFLD(Old_Fld2)

You can use PREFIX keyword instead of EXTFLD on different


way

Q. How can I keyed a flat file in RPGLE


A. FMASTER IF F 96 96 DISK A
F KRECNO RRN

Q. How can you detect and handle a record lock situation?


A. If you try to read the locked record, we can get system defined
message i.e. , the program will ended abnormally. With the help of File
Information Data Structure we can handle record lock situation.
Generally it will happen, when the same file of type " U" used in
different programs.

Q. what is the procedure of debugging the service program?


A. I hope u know, service program will always be binded and it
can't be called directly.
Now, to create a wrapper:
create one RPG Program in which service program is binded
as follows:
wrapper(test program) will have:
Define all the required fields in parameter list.
CALLB 'ABC' Parameter list;
and then create a module of it.
then create *PGM object of the same wrapper by using CRTPGM
+F4 and bind the service program 'ABC' with the module.
Now, to debug,

Strdbg SRVPGM(ABC)
add brak point
now call the Wrapper program.
------or -----------------------
Strdbg Wrapper program name
than F14 to work with module list
and add your service program(*SRVPGM) and add the break.
Call wrapper.

Q. In Program B there is a SBMJOB, which is a call to program C


.There is also a CALL to program D from B. How would you
check the program C has been executed in D?
A.
Q. Job is in MSGW while reading the input file and writing a
new record / updating a record due to Duplicate data error.
What action would you take ( C D I R )...?
A. Take the dump option(D) and delete the duplicate record and
retry the job.

Q. Please anyone explain about compile time array,pre run time


array run time array?
A. Compile time array is the array which is declared with all
the actual values in the program. using CTDATA

Pre run time array: It is loaded from a column of physical


file

Run time array: values are loaded in the array during


execution time.

1) pgm1 calls pgm2 , pgm2 calls pgm3, pgm3 calls pgm4, pgm5 calls
pgm6 . you are in pgm6. How you will find main progam ???
A. Use LDA to store main program name
2) some source is deleted. Object is there ? how you will retrieve the
source ?
A. object should be present in the spool file and we can copy restore
source from spool file.
3) without doing SETLL, read , chain how you can find that there are
records in file?
A.Use OVRDBF command with QCMDEXC and return the number of records in
the file.
4) there is one file PF in lib1, same PF file in lib2 , you have to
access those same files lying in different libraries in RPG pgm . How
you will do that ?

You can give 2 different names to the different Physical


Files like the following code and then use the
keyword "EXTFILE" to give a fully qualified PF -
Fname1 if f 10 disk extfile(LIBRARY1/filename)
Fname2 if f 10 disk extfile(LIBRARY2/filename)
RENAME(rcdname1:rcdname2)

Then, use DOW, Read and write.


5) suppose some job is running for long time .Generally this job runs
for long time .i have to reduce the time how you will do?
That depends upon the job and no of records processing in the file.
If the program uses SQL cursor then try to remove and write simple RPG
program.

Q. Activation group in ILE.


A. Activation group is the environment where the ILE jobs are
executed. You can specify the activation group in CRTPGM or
CRTSRVPGM command.
There are three possible values for Activation Group
parameter. 1. Name 2. New 3. Caller.
You can not create the activation group by command
CRTACTGRP.
Its a kind of environment which provide all the necessary
resources required for the sucessfull execution of program.
Activation group is very similar to Subsystem. It allocates
the necessary resources for the ILE job to executes.

This can be 4 types of

*ENTMOD : The program entry procedure module (ENTMOD


parameter) is ckecked.If the module attribute is RPGLE,
CBLLE, or CLLE, then ACTGRP is QILE or QILETS.QILE is used
when STGMDL(*SNGLVL) is specified, and QILETS is used when
STGMDL(*TERASPACE) is specified.

*NEW :When the program gets called, a new activation


group is created.

*CALLER :When the program gets called, the program is


activated into the caller's activation group.

Name :Specify the name of the activation group to be


used when this program is called.

Hi,

I faced in most interviews below questions

Without doing I/O operations how you will find the number of records in RPG
program( Cl command should not be used)

today I got answer by doing hands on RPGLE practice program.

In INFDS , There is subfield starting from 156 to 159 thru which you can get count of
records in file against which INFDS is specified.

But another trick is also that you have to populate this subfield thru POST opcode
otherwise you can’t get it. Below are codes that I used for finding the answer.

FJLRPFT O E disk RECNO(DBRRN1)

F INFDS(NUMRCDS)

DNUMRCDS ds

DNUM_RCDS 156 159i 0


POST JLRPFT NUMRCDS(In C specs ).

Q. How can i check the object existance in RPG program without


using QCMDEXC command.
A. Without using QCMDEXC.
RPG Free format

/Free
MONITOR;
Open emp1;
ON-ERROR 1217;
Dsply ' File not found'
return;
ENDMON;
/END-FREE

Q. Q1.How we can copy the data of file one session to another


session?
Q2.how we can execute a loop infinitely in AS/400 coding?
Q3.In ALDON tool, multitask is possible on a particular
object by the user?
A2. Loop with a condition which is always true.

DOW '1'
//whatever
ENDDO

Q. Difference between program and service programs?

A. service program differs from a program in two ways:

• A service program is bound to existing programs or other service programs. It


cannot run independently.
• A service program does not contain a program entry procedure. Therefore, you
cannot call a service program using an OS linkage specification. However, you can
call a service program with a c linkage specification, because it contains at least
one user entry procedure. A service program may have data exports rather than a
user entry procedure.
• Service programs are bound by reference. This means that the content of the
service program is not copied into the program to which it is bound. Instead,
linkage information about the service program is bound into the program.

This process is different from the static binding process used to bind modules into
programs. However, you can still call the service program's exported procedures
as if they were statically bound. The initial activation is longer, but subsequent
calls to any of the service program's exported procedures are faster than program
calls.

Q. difference Program Entry procedure and User Entry Procedure?


A. UEP is "USER ENTRY PROCEDURE". That is starting point of a program.
For example
*INZSR or *Entry PList or even first executable statement in the
program. UEP
is always programmer written code.

PEP is "PROGRAM ENTRY PROCEDURE". It is a compiler generated code and


it always
resides in program object (that is obvious). PEP always points to UEP.
That is
while executing the program, PEP directs the system from which
statement it
should execute this program (that is the first executable programmer
written
code staement).

That is, to execute any program from command line or call it from
another
program, your program should have PEP.

Suppose you have a program containing "only" subprocedure/s or a


service
program. You can call these subprocedures, independently, from your
main
program. That means, in this case, you are not calling the program
containing
subprocedures directly with "Call" statement. That is the programs
containing "only" subprocedures do not require PEP (as they do not
contain
UEP). You can avoid PEP in your program by specifying "NOMAIN" in
Header
specification of your RPG Code. (Ashu is wrong here: If NOMAIN is there
in the Header specification, compiler never generates PEP).

Q. what is signature. if u change only one line then signature will


change or not ?
A. The symbols identified between a STRPGMEXP PGMLVL(*CURRENT) and
ENDPGMEXP pair define the public interface to a service program. That
public interface is represented by a signature. A signature is a value
that identifies the interface supported by a service program.

Q: What is a signature?

A: A signature is a value that provides a similar check for service programs that a level check
does for files. It helps ensure that changes made to the service program are done in such a way
that the programs using them can still function properly. The signature is typically generated by
the system when you issue a Create Service Program (CRTSRVPGM) command specifying
Export(*ALL). The signature value is generated by an algorithm that uses as input the names of
all of the service programs "exports" and their sequence. "Exports" are the names of callable
procedures and any exported data items. When you create a program that references that service
program, its current signature value is copied into your program. If the export list were to be
changed without the programs detection, the program could potentially call the wrong procedure.

Q: What causes a signature to change?


A: A signature changes when the list of exports for the service program changes. The most
common cause of a signature change is adding a new procedure to the service program. Despite
popular "wisdom" to the contrary, a change in a procedures parameters doesn't change the
service program's signature.

Q: What happens when the signature changes?

A: When a program is called, it immediately checks the signature value of any service programs
that it uses and produces a signature violation message if the signatures don't match. This
happens at program start up not when you actually call a service program procedure.

4) In binding directory u can add any source member that has no object?
A binding directory contains the names of modules and service programs
that you may need when creating an ILE program or service program.
Modules or service programs listed in a binding directory are used only
if they provide an export that can satisfy any currently unresolved
import requests. A binding directory is a system object that is
identified to the system by the symbol *BNDDIR.

Binding directories are optional. The reasons for using binding


directories are convenience and program size.

• They offer a convenient method of packaging the modules or


service programs that you may need when creating your own ILE
program or service program. For example, one binding directory
may contain all the modules and service programs that provide
math functions. If you want to use some of those functions, you
specify only the one binding directory, not each module or
service program you use.

Note:
The more modules or service programs a binding directory
contains, the longer it may take to bind the programs. Therefore,
you should include only the necessary modules or service programs
in your binding directory.

• Binding directories can reduce program size because you do not


specify modules or service programs that do not get used.

Very few restrictions are placed on the entries in a binding directory.

The name of a module or service program can be added to a binding


directory even if that object does not yet exist.

 Convenient method of grouping the names of service programs and


modules that may be needed to create an ILE program or service program.

 Because binding directory entries are just names, the objects listed
do not have to exist yet on the system.

Q. how you will read members of physical file?


A. FQPRCSRC uf e Disk Extfile(FileName) ExtMbr(MemberName)
F usropn rename(QPRCSRC:NewFormat)

FMYFILE IF A E DISK USROPN extmbr(mbrname)


mbrname='MYMEMBER';
open myfile;
blah blah blah;
close myfile;

2)In ALDON CMS how u check out(option?) and what options are for
finding dependable objects?
41 option is to search the pr
3)there is one physical file containing huge data in production. how u
will add one field in that file?
First change the Fields thru the DDS of the file
CHGPF FILE(yourlib/yourfile) SRCFILE(yoursrclib/yoursrcfile)
SRCMBR(*FILE)

4) what is activation group and their types?


5) OVRDBF SECURE(*YES). what is the use of secure?
A. This file is protected from the effects of any file override
commands that were previously called.

Q.How do I re-bind the programs that reference the service program?

A: Use the Update Program (UPDPGM) command. Because you aren't replacing any modules,
specify Module(*None). You don't need to specify the service program because the UPDPGM
command automatically re-checks the signatures of any bound service programs. If any
signatures have changed, it also updates the programs signature values.

Q: How do I know which programs need to be updated?

A: That can be difficult. If you have a cross-reference tool that understands service programs, it
should provide the information you need. Otherwise, you can display each program using the
Display Program (DSPPGM) command and see (on the fourth display screen) the list of service
programs it uses and what signature value it's looking for. Of course, if you know the signature
has changed, the fact that the program references the service program tells you it must be
updated. This method is tedious to do manually. You could also write a program to automatically
perform the updates for you using the appropriate APIs (DSPPGM has no outfile support). This is
beyond the scope of this article but we may cover it in the future.

Q. Do you have any idea about Argument fetch error? when it happens?
A.

Q.How to delete duplicate records from file through SQL?


A. delete from file1 f1 where RRN(f1) > (select MIN(RRN(F2)) from file1 f2 where F2.
key1 = F1.key1

its joining same file

Vous aimerez peut-être aussi