You are on page 1of 21

Question bank by Shyam sundar

WRKOBJPDM If we want to list all the source physical file or files of a particular type the Wrkobjpdm with file type as pf-src for source physical file ior *file for listing all the files etc can be given

DSPOBJD If we know library name and object name and we want to know the source physical file where it is residing then dspobjd with option as services instead of basic will give the source physical file name WRKACTJOB To display the active jobs running in as/400 systems RTVMSG If you want to retrieve the text message from message files and move it to a temporary variable we can make use of this command PGM DCL VAR(&MSGVAL) TYPE(*CHAR) LEN(100) DCL VAR(&MSGFI) TYPE(*CHAR) LEN(10) VALUE(SHYAMFILE) DCL VAR(&MSGID) TYPE(*CHAR) LEN(7) VALUE(MSG0002) DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(3) CHGVAR VAR(&MSGDTA) VALUE(5) RTVMSG MSGID(&MSGID) MSGF(&MSGFI) MSGDTA(&MS MSG(&MSGVAL) SNDMSG MSG(&MSGVAL) TOUSR(SHYAMR) ENDPGM This will retrieve the message whose message id is msg0002 and message file is shyam file and msgdta is the value passed and here it is 5 CPYSRCF If we want to copy all the members in a source physical file to another source physical file we can use this command CPYTODKT If we want to copy from source physical file to a diskette file CPYTOTAP If we want to copy a source physical file to a tape then we can use this command STRDBG If we want to debug a ILE program then we can use this command. We have to create a ile program by compiling with 15 which is CRTRPGMOD command and give debugging values as *source .This will create a module. Then we have the create the program by giving program name and module name as the same and if we are calling any other modules also in that include that in the crtpgm command

Question bank by Shyam sundar EX: CRTPGM PGM(SHYAMRLIB/ZP1263) MODULE(SHYAMRLIB/ZP1263 SHYAMRLIB/ZR3002) Now the program as well as the module is created .Then we have to start the debug by using the command STRDBG PGM(SHYAMRLIB/ZP1263) UPDPROD(*YES) It will show the source code of the program and we have to press F10 key and call the program Call pgm(zp1263) And it will move to debug mode and we can watch the flow of the program. When we start the debug and when the source is not available then there is some problem in the creation of the program ENDDBG After the debugging is over we have to end it by using this command DSPDBR This is used to list all the files which are related to a physical file. It displays all the logical files that are referring the physical files and also list the child table if it is having a relation through ADDPFCST CopyBook in ile It will copy a subroutine or any group of codes physically into the program which is copying it.
C DSPLY A C EXSR ADD C SETON C/COPY TESTSHYAM,SUBRTN C C C C ADD A BEGSR ADD 3 DSPLY ENDSR 50 LR

A

In the above program we are copying a subroutine called SUBRTN residing in the source physical file TESTSHYAM.The subroutine SUBRTN called can be of any type even text and no need to compile this program. In the above example the object will be created with code present in both the programs. Normally a copy book will be presented after seton lr statement if you are using it as a subroutine but if you are just including a piece of code or initializing some statements then it can be used in between the programs either in d spec or c spec or even fspec depends on the application. In other words we can create 3 programs having F SPEC,D SPEC and C SPEC and just use 3 copy books like below F/COPY TESTSHYAM,FILEDEF D/COPY TESTSHYAM,DDEF C/COPY TESTSHYAM/CDEF TEST

Question bank by Shyam sundar Test is the most powerful opcode which will check a date is a valid or not. The low level indicator is set on if the date is not valid or set off if the date is a valid one. Test will be given with extended factor like test(d),test(t), Test(z) for date, time and time stamp and if test without extended factor defaults to date(z). Factor 1 will be date format or time format. If it is blank it will take the value from H-spec and no H-spec then default format is *iso . Factor 2 is blanks and result contains the data to be tested datfmt(*dmy) movel '13/03/1999' a 8 test(d) a 30 *in30 dsply seton lr In the above example the date format is *dmy and 30 will set to off (valid date) .If in the H-Spec if we give *mdy then it is an error. DUMP Dump is a opcode in RPG which is used to force to produce a dump if any error occurs. It is used in program status data structure or file information data structure and it is used for a user to see if any error occurs in the system. We have to specify debug(*yes) in h-spec to make a dump
HDEBUG(*YES) dpssr DSTATUS DROUTINE DPARMS dRES C C C C 'NOTCOM' C A C 'COMING' C C *PSSR C STATUS C ROUTINE C PARMS C C C sds *STATUS *ROUTINE *PARMS S Z-ADD Z-ADD EVAL DSPLY TAG DSPLY SETON BEGSR DSPLY DSPLY DSPLY DUMP GOTO ENDSR

2S 0 1 NUM1 0 NUM2 RES=NUM1/NUM2

2 0 2 0

LR

A

In the above example divide by zero exception is caused and the control will be transferred to *pssr routine where it is making the dump and move the control to tag a. This program also illustrate the usage of parms status, routine keywords in program status data structures Pre runtime array: In case of compile time array the elements of the array will be loaded before the execution of the programs. The value will be static in this case.

Question bank by Shyam sundar
In case of runtime array the value will be loaded during the runtime only and this is dynamic Pre runtime array is in between these 2 conditions where the values are static and the value will be retrieved from the disk and loaded into the array. As a result there is no need to retrieve the value every time from the disk and usage of pre runtime array makes it fast. Example of pre runtime array FPF02 IT F 80 DISK Here T will represents that this is a pre runtime array and F for representing it as a program described file and 80 is the size of the file. DARR1 S 15 0 DIM(100) Here the from file size is 80 and since perrcd from file will have elements like this element1element2element3element4+20 free space Like this there are 100 elements are stored in We can specify to file location if you want to from file and this is optional FPF02 IT Fwsdatapf o DARR1 d DI C 1 C ARR1(I) C C C F F S S DO DSPLY ADD ENDDO SETON 10 1 I LR 80 80 DISK DISK 15a FROMFILE(PF02) PERRCD(4) is 4 and length is 15 the the array. copy the content of the

DIM(100) FROMFILE(PF02) PERRCD(1) tofile(wsdatapf) 2S 0 INZ(1)

This will load first 100 records into the file and display only the first 10 records Build in functions in ILE %SUBST(String name:starting position:length) %abs(-32.32)= Absolute value by omitting the sign %editc(string:’X’) In a application if we want to concatenate a string with a numeric then we can use this editc da s 5a INZ('SHYAM') db s 5s 0 INZ(20) dc s 5a INZ('SUNDA') dd s 5s 0 INZ(12) de s 5a INZ('RAMBA') dout s 25a c eval out=a+ %editc(b:'X') +c+%editc(d:'X')+e c out dsply %REPLACE: %replace(replacing string,actual string,starting position,offset) Here we are replacing shyamsundar from position 1to 5 by sam. The output will be sam sundar. DC S 12A INZ('SHYAMSUNDAR') C EVAL C=%REPLACE('SAM ':C:1:5) If we are not giving starting position then the result will be samamsundar. If we are giving starting position as 3 then the output will be shsamsundar.

Question bank by Shyam sundar
If we are giving EVAL samhyamsundar. C=%REPLACE('SAM ':C:1:1) then result is

Keyword Overlay ddds1 ds ddate1 10a inz('2001-01-01') dyyyy 4s 0 overlay(date1:1) inz(1999) dmm 2s 0 overlay(date1:6) inz(12) ddd 2s 0 overlay(date1:9) inz(12) c date1 dsply c eval *inlr=*on Here the value of date1 is 1999-01-01 instead of 2001-01-01.Here the first four character are overlaid by the next statement Note1: We can create a module in CLP by making the type as CLLE

Question1: How can you copy only 100 records in a file which contains millions of records? (Ans) By using CPYF command we can give the record copying position starting and ending of the records. If we want to copy the records between 1000 and 1100 in the million records we can give 1000 in the start position and 1100 in the end position. In the another way by using CHGPF commands we can restrict the number of records to be there in a file by giving number of records as 100 and increments as 0. In this case we can copy only the first 100 records and not possible to copy from one position to another. Question2: How to convert a field from Uppercase to lowercase? (Ans) By using XLATE command we can convert a field from upper to loew case or vice versa. FDSPF001 CF E WORKSTN Dlower S 26A inz('abcdefghijklmnopqrstuvwxyz') Dupper1 S 26A inz('ABCDEFGHIJKLMNOPQRSTUVWXYZ') C *in03 doweq *off C exfmt casecon C 03 leave C if *in09=*on C upper1:lower XLATE lowcase upper C endif C enddo C seton lr Here lowcase and upper are the two fields in the screen and the user is entering characters in lowcase in upper case and convert that to upper case and move it to field upper when user press f9 key. Question 3: How to copy a file from as/400 system to a local pc. (Ans) Do the following to copy ftp as/400 machine ip address In wipro case ftp 10.200.9.80 It will ask for user name and password. Enter your as/400 user id and password. It will then say the user has logged in successfully. If you want to copy a rpgle program called load2 residing in shyamrlib library and source physical file name is shyamrile then we have to change the current library into shyamrlib .Just type cd shyamrlib and it

Question bank by Shyam sundar
will change the library. And then get shyamrile.load2 will copy the file into c:\ in local pc. If you want to copy from a PC to as/400 library then do the following To do: Copy from c:\shyam\load2 to shyamrile\load2 in shyamrlib Steps: cd shyamrlib put c:\shyam\load2 shyamrile.load2 will copy the file in shyam in c directory into shyamrile in shyamrlib. Question 4: How will your read a 100th record in a group of records in a file? (Ans) Declare the file without K in record address type in file definition. z-add the position you want to retrieve. Suppose you want to retrieve 125th records then z-add 125 to rrn Do chain based on rrn. fworkfile1 if e disk c z-add 2174 rrn1 4 0 c rrn1 chain workfile1 40 c seton lr Here we are reading the 2174th record. Question 5: Explain the usage of procedure in a life project (Ans) Here is a procedure which will accept the character in lower case and return the value in upper case. In java the user may enter either in lower or upper cases and we have to convert into uppercase else the chain will fail. So we create a procedure in our program which do this and call the procedure in our program. Ex: This is the program which is calling the procedure. DPROC1 PR DX 10A DA S 10A C EVAL A='shyamsunda' C CALLP PROC1( C A) c A dsply c seton lr The procedure HNOMAIN DPROC1 PR D PPROC1 B DPROC1 PI DX Dlower S Dupper1 S C lower:upper1 XLATE C RETURN PPROC1 E

10A 10A EXPORT 10A 10A 26A 26A X X inz('abcdefghijklmnopqrstuvwxyz’) inz('ABCDEFGHIJKLMNOPQRSTUVWXYZ’) X

Question 6: How to query a record for getting the rrn value? (Ans) Select rrn(zphamsp) from zphamsp where code=’AE’ Here zphamsp is the program name.

Question bank by Shyam sundar

Question 7: Is it possible to send arrays,data structures as a parameter to another program? (Ans) Yes it is possible and we have to call in the same way a parameter is passed in the program. Ex: darr1 s 2p 0 dim(10) darr2 s 2p 0 INZ(1) c callB 'ARR2PGM' C PARM ARR1 C 1 DO 10 C ARR1(ARR2) DSPLY C ADD 1 ARR2 C ENDDO c SETON LR called program DARR1 S 2P 0 DIM(10) DI S 2P 0 INZ(1) C *ENTRY PLIST C PARM ARR1 C 1 DO 10 C EVAL ARR1(I)=I C ADD 1 I C ENDDO C SETON LR Here the array is passed as a parameter and the values after callb is 1 to 10 Question 8: What is the difference in between CALL,CALLB,CALLP (Ans) Call is a dynamic call where the control will be transferred when the program Is executed where as Callb and Callp are static calls. A module is a non executable program and it contains one or more procedures. If you have modules without procedure then it means that it is having only one default procedure and in case we can use CALLB. But if a module is having more than one procedure then we can give explicitly the procedure name to be called in case of CALLP Out of these three Callp is the most efficient one. Question 9: What is the new name for as/400? (Ans) Iseries 400 is the new name given to as/400 by IBM now. Question 10: How to see the source of copy books included in a program while compiling or debugging? (Ans) While Compiling the program give *list instead of *source which will expand all the copy books. Question 11: How to retrieve the value from data area and how to change the value of a data area? (Ans) ds s 10a

Question bank by Shyam sundar
dg s 10a inz('i hate u') c *dtaara define data1 s c *lock in s c eval s=g c out s c s dsply c seton lr I created a data area by using the command crtdtaara and give the length as 10a and value as I love you Statement *dtaara define data1 s *lock in s will copy the content into a temporary variable s and now we are changing the value of s as I hate you and now by using out command the value of the data structure will be changed Question 12: How you will avoid multiple users updating the same record? (Ans) While displaying the records in the screen we will be getting the timestamp Along with the actual data. Store this in output data structure and while updating check weather the previous time stamp is the same timestamp before updating. If the record is updated by another user then the time stamp will be changed and if it does not matches then throw the error message ‘Record is already updated by another user’ else update the records with current time stamp Program1 Store the time stamp and this time stamp will come as a input to the second program Program 2 Here wstmst1 contains the input time stamp and check this matches with the database.If matches Update else send error message C K1CDFL CHAIN ZPCDFLR 80 C MOVEL WSTMST1 WSTMST C IF CDMOTS=WSTMST C TIME CDMOTS C UPDATE ZPCDFLR C ELSE C EVAL ERROR=1 c LEAVE C ENDIF C ENDDO Question 13: What will %size and %elem keywords will do? (Ans) %size will display the size of the variable where as %elem will display the array dimension. darr1 s 3s 0 dim(1000) c eval c=%size(arr1) c eval d=%elem(arr1) c c dsply c d dsply c seton lr In the above program c will be 3 and d will be 1000 Question 14: What will you format a number by using as/400? (Ans) By using Editw Keyword

Question bank by Shyam sundar
For example if you want to print 1234567890.12 as $1,234,567,890 dollars and 12 cents then the edit word must contains ‘$ , , , &dollars&and& &cents.’ Here & will be used to add a space and a blank space represents the variable. So for printing and 12 cents we will give as &and& 12&cents. Where & represents blanks space in edit word and actual blank space is the variable 12. dsalary dedit &cents’ damount c c amount c s c s eval dsply seton 12p 2 inz(1234567890.12) '$ , , , &dollars&and& 40a amount=%editw(salary:edit) lr
Deleted: 14:

Question 15 How you can schedule a job to run periodically? (Ans) We have to create a job scheduler for running a job periodically. Here we can make a job to run once or periodically at a given date and time. . We can create a job scheduler by using addjobscde command. We can list all the job scheduler running by using the command wrkjobscde and we can delete a job scheduler by using rmvjobscde or we can reschedule the job by using chgjobscde. Question 16: How you can bind a C module with a RPG Program? (Ans) Create a C module of type c void logit (char *t) { printf("'%s'\n",t); } And bind this program by calling it as a module in RPG program D txt S 40A INZ('Hello, world !') D logit PR EXTPROC('logit') dtxt * value OPTIONS(*STRING)

Deleted: 15

c CALLP logit(%TRIMR(txt)) c return Create program for this rpg by binding with the c module and call this program. Question 17 How to debug a batch job? (Ans) Hold the batch job to be debuged by using wrkactjob command and having option 3. Set the pointer in the batch program to be debuged by using strdbg and then call the strsrvjob command and start the service program which will enter into the debug mode. After entering into debug mode release the job that is hold before. Question 18 Explain briefly about Non join Logical File. (Ans)
Deleted: 16:

Deleted: 17:

Question bank by Shyam sundar
Logical files can be derived from 1 to 32 physical files and so a logical file can have a maximum of 32 Record formats. If a logical file is derived from single physical file without joining then it is single record format logical file. Single record format logical file: Refaccpth is applicable for Non join logical file only and meaning is refer the access path from the physical or the logical file in the file level entry. PFILE is applicable only for non join logical file in record level entry. R RECPF2 PFILE(PF02) K EMPNAME Here the employee files key will be changed from empno to empname. Output of this query is No NAME ADDRESS1 ADDRESS2 CITY STATE ZIPCODE 1 SHYAM 29,ARUNA NAGAR PUTHUR TRICHY TN 17 2 RAMBABU 29,ARUNA NAGAR PUTHUR TRICHY TN 17 3 SASI 53,KULALAR STREET CUMBUM TN 54 ******** End of report ******** Here runqry will select all the records in pf02. R RECPF2 PFILE(PF02) EMPNAME 15A CITY 10A K EMPNAME Here the attribute size of city is changed from 30 to 10 and also the key value is changed. The output of this query is EMPNAME CITY SHYAM TRICHY RAMBABU TRICHY SASI CUMBUM R RECPF2 PFILE(PF02) EMPNAME 15A CITY 10A EMPNO 5S 0 K EMPNAME O EMPNO CMP(GT 2) The output of this is EMPNAME CITY empno SHYAM TRICHY 1 RAMBABU TRICHY 2 Here the employee number 3 is omited since it is greater than 2. Multiple record non join logical file will select records from 2 or more physical files by referring to only one logical file 1) Each record format is always associated with one or more physical file. 2) The same PF can be used in more than one record format. Question 19: Explain Inner join or natural join and left outer join. (Ans) Natural join In case of natural join only the matching records in between the joining file will be selected.

Question bank by Shyam sundar
If the pf of 2 files is like this PF01 PF02 R JP1REC R JP2REC EMPNO 5S 0 EMPNO 5S 0 EMPNAME 20A EMPSAL 15P 0 K EMPNO K EMPNO The records in the 2 files are as follows Empno Empname Empsal 1 shyam 1 1000000 2 sundar 2 2000000 3 rambabu 4 1000000 Then in case of natural or inner join the records selected are Empno 1 2 Empname shyam sundar Empsal 1000000 2000000

Empno

where as in Left outer join all the records from primary file and the matching records from the secondary file will be selected. The output is Empno Empname Empsal 1 shyam 1000000 2 sundar 2000000 3 rambabu 0 Note that the salary will be defaulted to default values and the employee number 4 is not selected since this is the secondary file. R JL1REC J JFILE(JP01 JP02) JOIN(1 2) JFLD(EMPNO EMPNO) JREF(JP01)

EMPNO EMPNAME EMPSAL K EMPNO Where as in inner join we have to specify jdftval in file level entry JDFTVAL R JL2REC JFILE(JP02 JP01) J JOIN(1 2) JFLD(EMPNO EMPNO) EMPNO JREF(JP02) EMPNAME EMPSAL K EMPNO JFILE: It is similar to indicate that this is a Join logical file and it must have more than 2 physical files Join : It indicates what are the files to be joined in this case. We can represent the position of the files. There must be one primary file and can have more than 1 secondary files. JFLD which fields we are going to join JREF represent the primary file reference field.

Question bank by Shyam sundar
JDFTVAL represents that it as a left outer join. If we are joining more than one Physical files then we can represent it as follows. If the first two files are the same JP01 and JP02 and the third file to be joined is JP05 Which is having these fields R JP1REC Empno address Empno 5s 0 1 Trichy Address 20a 2 Cumbum K empno Then the result is 1 shyam 1000000 trichy 2 sundar 2000000 cumbum which fetches the matching record in all the three files. JDFTVAL R JL5REC JFILE(JP01 JP02 JP05) J JOIN(JP01 JP02) JFLD(EMPNO EMPNO) J JOIN(JP02 JP05) JFLD(EMPNO EMPNO) EMPNO JREF(JP01) EMPNAME 20A EMPSAL 15P 0 ADDRESS K EMPNO Question 20 What will FOR opcode will do? (Ans) dn s di s * for(i=0;i<n;i++) c for c i dsply c endfor * for(i=n;i<1;i--) c for c i dsply c endfor * for(i=5;i<40;i=i+10) c for c i dsply c endfor c c for c i dsply c endfor c * for(i=5;i<40;i=i+10) c seton

5s 0 inz(10) 5s 0 i=1 to n

i=n downto 1

i=5 by n to 40

i=5

to 40 by n

lr

Question 21 What are the various stages for a job after it is submitted?

Question bank by Shyam sundar
(Ans) Jobqueue, Active job and OUTQ are the three stages after the job has been submitted. Question 22 What are the difference between non join logical files and join logical files (Ans) Non Join Logical Files We can able to insert or delete or update records using non join logical files. DFU can be used to display Non join logical files 1-32 record format can be specified Commitment control is used Question 23 Explain Self join in detail (Ans) In a employee physical file there are 3 fields named empno,empname and mgrid. Manager is also an employee and he has an employee id in the same table with some other as manager. We want to query the records with the fields empno,empname and manager name. So based on the manager id we have to select the corresponding employee id and select the employee name and move that as the manager name. DDS of Physical File SEU==> PFTEST FMT PF .....A..........T.Name++++++RLen++TDpB......Functions++++++++++++++++++ *************** Beginning of data ************************************* 0001.00 A R EMP 0002.00 A EMPID 5 0 0003.00 A EMPNAME 20 0004.00 A MGRID 5 0 ****************** End of data **************************************** Data in 000001 000002 000003 000004 000005 000006 000007 000008 000009 000010 ****** Physical File EMPID EMPNAME 10,001 Sebi Joseph C. 10,002 Purushottam 10,003 Sameer Dighe 10,004 Sharada Menon 10,005 Saju Paul C. 50,001 Shivaram Pasuvan 50,002 Praveen K. Gaurav 50,003 Lionel King 50,004 Sam Mathew Varghese 50,005 Anil Jandyam ******** End of report ******** MGRID 50,001 50,002 50,003 50,004 50,005 90,001 90,002 90,003 90,004 90,005 Join Logical Files Insertion, updating or deletion of records is not possible in join logical files DFU is not available Only one record format can be specified Commitment control is possible

Question bank by Shyam sundar
FMT LF .....A..........T.Name++++++.Len++TDpB......Functions++++++++++++++++++ *************** Beginning of data ************************************* 0001.00 A R EMP JFILE(PFTEST PFTEST) 0002.00 A J JOIN(1 2) 0003.00 A JFLD(MGRID EMPID) 0004.00 A EMPID JREF(1) 0005.00 A EMPNAME JREF(1) 0006.00 A MANAGER RENAME(EMPNAME) JREF(2) 0007.00 COLHDG('MANAGER') ****************** End of data **************************************** Output of Join Logical File Line 000001 000002 000003 000004 000005 ****** ....+....1....+....2....+....3....+....4....+....5. EMPID EMPNAME MANAGER 10,001 Sebi Joseph C. Shivaram Pasuvan 10,002 Purushottam Praveen K. Gaurav 10,003 Sameer Dighe Lionel King 10,004 Sharada Menon Sam Mathew Varghese 10,005 Saju Paul C. Anil Jandyam ******** End of report ********

Question 24: What is a field reference file? (Ans) This is a physical file which does not have any data and contains only the field descriptions and these fields are referred in other pf by using ref and reffld. This is the third type of file along with PF and LF. Question 25 What will runsqlstm will do? (Ans) If we want to execute set of sql statements (only insert, update and delete and no select is allowed) then we can write all the sql statement to be included with the source type as sql. Then use strsqlstm to execute the program RUNSQLSTM SRCFILE(SHYAMRLIB/TESTSHYAM) SRCMBR(SQL1) COMMIT(*NONE) Question 26 What is the advantage of Opnqryf over SQLRPG? (Ans) sqlrpg opnqryf Opnqryf will come along with os/400 We need to have sqlrpg installed in system and no need to have any as/400 system which involves additional package needed to additional cost to the programmers execute it. Opnqryf is faster as compared to It is slower sqlrpg

Question bank by Shyam sundar
Opnqryf Is nothing but a dynamic logical files which will be created and the records are queried and finally the logical files are deleted and OPNQRYF provides that facility SQLRPG is imbedding sql statements directly within SQL Statement

Question 27 What is the equivalent command to setll *loval in CL (Ans) POSDBF with file position as *start will set the file to the beginning or using ovrdbf and specify the keyfield value by rrn value or by giving *start. Question 28 What is the difference between OPM, EPM and RPGILE? (Ans) OPM EPM RPGLE It supports mixed Extended program model Open Program Model is program support in will support PASCAL, the old RPG/400 which you can combine FORTRAN and other system, which will not any program with programming concepts. allow a program type another type of to call another program program type. Version is V1R2 Version is V2R3 Question 29 What is the difference between Bind by value and Bind by reference? (Ans) Bind by value Bind by Reference In this case we are binding the Here all the modules to be bounded are physically copied into the main programs by using service programs which contains a reference to the program object. modules that has been called and the modules are not physically copied into the program objects The program will be executed even The program will not executed when when you delete all the modules the bind modules are deleted. that have been called. Bind by value is faster than bind It is not as faster as bind by by reference value Question 30 How to create a service program and what are the steps involved in this? (Ans) While creating service program we can create a binder program where we can refer the modules or procedures or even data types to be used by the program, which is using service program. If we are having 100 procedures in a module and if you want to specify only some procedures to be bind in the service program we can create the binder program. STRPGMEXP SIGNATURE('BND') EXPORT SYMBOL('PGM1') ENDPGMEXP Here there are 2 programs PGM1 and pgm PGM1 PGM

Question bank by Shyam sundar
DA CALLB ‘PGM1’ DB SETON DC C C S S LR S EVAL SETON 2P 0 C=A+B LR 2P 0 INZ(8) 2P 0 INZ(8)

Then we create the binder program, which will give authority to only one module named PGM1 Then create the service program with binding program incorporated. If no binder program is incorporated then all the modules will be taken as default CRTSRVPGM SRVPGM(QTEMP/SRVPGM) MODULE(QTEMP/XXXX) SRCFILE(IDCPGRRSP/SHYAMR ILE) SRCMBR(BND) DSPSRVPGM Will helps us to display the details about the service program that has been created. We can also create a bind directory for a service program where we can bind all the modules together and if we do like this then there is no need to bind all the programs and we can compile the program straightly by using crtbndrpg even it has more than 1 module. CRTBNDDIR BNDDIR(QTEMP/BNDDIR) 2) ADDBNDDIRE BNDDIR(QTEMP/BNDDIR) OBJ((*LIBL/SRVPGM *SRVPGM)) The type of service program that is created is *srvpgm. Question 31 What is an activation group? (Ans) Activation group is the boundary set for similar programs. Activation group is also a storage space in memory. Consider for example the following scenario 2) CLP has a ovrdbf command and calls a rpg program 3) RPG program performs a read operation and the pointer is now in the second program and now call the program 3 4) RPG program that also do a read operation which will read the second record since the pointer is in the second position and then return to 2nd program In the above situation when the control transfers from 3rd program to the 2nd program then it will read the 3rd record since the 2nd record is already read in program 3. But we need to read the 2nd record according to the logic but this is not possible in any OPM programs. But in ILE there is a solution for this problem by giving a common activation group for 1st and 2nd program and have a separate activation group for the 3rd program while creating the program itself and this will avoid all the problem we faced before. In some situation we want to share between 2 programs then we can give the activation group in *job level in which the changes in one program will be affected in another program. Types of activation group levels: *new : In this case every time you call the program an new activation group will be created which this case will not be used mostly. *caller: If we don’t know the type of the program that is calling then we can specify *caller where the activation group will be the same of the program that is calling.

Question bank by Shyam sundar
Named activation group: We can give our own named for different activation group Question 32 What are the statements that are affected by activation group? (Ans) 1) OVRDBF 2) OPNQRYF 3) STRCMTCTL 4) DLTOVR 5) OPNDBF Question 33 What are the statements, which is not used in CLLE that is used in CLP? (Ans) 2) RCLRSC which is replaced by RCLACTGRP 3) TFRCTL Question 34 Write a brief note on procedures used in RPGLE (Ans) 1) Defining the Prototype: Prototype will specify the following things 2) Parameter type 3) Sequence of the parameter 4) Return variable and its type 5) It tells the name of the procedure and also the type of the call. It will avoid all the run time problems like parameter mismatch by specifying the prototype like this 2) Prototype interface: It is like the *entry parameter where we will specify the parameters that are received in this program. 3) IMPORT and EXPORT If you want to specify the procedures to be used by the external programs then we can specify EXPORT in your procedure. If you don’t want then leave it blank. It is similar like giving private or public in JAVA. 4) Global and local variables If you declare a variable in main procedure then it will be accessible in all its sub procedure and this is global declaration and if you specify the declaration in the sub procedures then it will not be accessed in other procedures or in the main procedure. 5) RETURN If we specify return in the sub procedure then it means that we are returning something to the calling program. We can return a maximum of only one variable to the calling program. 6) Recursion A procedure calling to it self is known as recursion 7) Pass by value/Pass by reference In case of pass by reference we are passing the address of the parameters and not the actual value and so the changes in the called procedure will affect the value in the calling programs. In OPM programs

Question bank by Shyam sundar
we are using only call by reference and in RPGLE we have the option to pass the parameter by value by giving the keyword VALUE 8) CALLP/Expression We can call the procedure by using CALLP command if it is not having any return type and by an expression if it returns any value Example EVAL C=PROC1(A:B) Example program doing recursion using procedure. Called procedure: H NOMAIN DRECUR PR 3S 0 DA 2S 0 * DB S 3S 0 INZ(1) PRECUR B EXPORT D RECUR PI 3S 0 D A 2S 0 C IF A<>1 C EVAL B = B*A C EVAL A = A-1 C CALLP RECUR(A) C ENDIF C RETURN B PRECUR E * Calling program DVAL S 2S 0 INZ(5) DFACT S 3S 0 INZ(1) DRECUR PR 3S 0 DA 2S 0 C C EVAL FACT = RECUR(VAL) C FACT DSPLY C SETON LR Question 35 What is program entry procedure (PEP) and User entry procedure (UEP) (Ans) If we are binding many modules together to form a program then we have to specify which module has to take control first when it has been called and that module is called as PEP for that program. User entry procedure is the first statement that takes the control when a program has been called. For example in C programs main( ) will be executed first when it has been called and like wise in RPG the statement coded in C spec will take the control first. Question 36 Explain about FMTDTA in detail. (Ans) Here there is a pf of the following attributes R REC1 EMPNO 5S 0 EMPNAME 20A ADDRESS 25A DOB 8S 0 And this physical file is having the following records Empno name address

dob

Question bank by Shyam sundar
1 shyam trichy 11,021,999 2 tom pune 11,122,002 3 ccc jjhhj 11,021,999 We want to sort the file based on address in ascending order then we have to code the format data in the following way. IPRH and IPRF are used to add the attributes of format data. HFILE 025A X pf02 FNC00260050 address FDC00010058 Here we want to sort the physical file based on the address and the length of the field to be sorted is 25. If we want to sort based on more than 1 field (address,dob) then give the length as 33(25+8) HFILE 025A X pf02 The address position starts from 26th position to 50 and we have more fields declare all the fields by taking IPRF Spec FNC00260050 address After coding all the fields to be sorted give the total length of all the fields in the file. Here the file pf02 has a length of 58 and we declare it as follows FDC00010058 The type of this program is anything even a text file. After coding the sorting manner we have to make use of format data command to create a file that contains the sorted record. FMTDTA INFILE((IDCPGRRSP/PF02)) OUTFILE(QTEMP/PF02) SRCFILE(IDCPGRRSP/SHYA MRILE) SRCMBR(FMT) This will copy the records into PF02/qtemp and the records will be sorted on address. Output after sorting: EMPNO EMPNAME ADDRESS DOB 3 ccc jjhhj 11,021,999 2 tom pune 11,122,002 1 shyam trichy 11,021,999 Question 37 What is the difference between FMTDTA and OPNQRYF (Ans) FMTDTA OPNQRYF It will sort the records based on It will sort the records the field values. sequentially based on the position of the record. If any changes in the attribute If there is any change in the size of a pf then we have to change attribute size it will not affect the program specification also the program specification also. FMTDTA is bit faster in process OPNQRYF is slower as compare to than opnqryf. FMTDTA if we are processing millions of records. Question 38 How you can import and export a data type between 2 programs (Ans) If you are using an export statement when declaring a variable then the data type can be imported in any modules that is bind either by value or by reference. So in this case we can pass values in between modules instead of using plist and *entry. Program 1 DDD S 2S 0 EXPORT INZ(1) C CALLB 'EXP01' C DD DSPLY

Question bank by Shyam sundar
C Program 2 ddd c c s eval seton SETON 2s 0 import dd=6 lr LR

In the above example the value of the variable DD will be passed to the next program and it value is changed in the second program without using *entry and plist Question 39 How you can use pointers in RPGLE (Ans) Pointer is concept of referring the variable in the basis of address. We can make many variables or data structures that refer the same address space by using this pointer. dbase_address s * ddsname1 ds based(base_address) dfirname 10a dlasname 10a ddsname2 ds 30 c eval base_address=%addr(dsname2) c eval dsname2='shyam sundar' c firname dsply c lasname dsply c seton lr Here in the above example we declare the pointer base_address and we make the datastructure dsname1 assigning to that pointer. We declare another data structure and till now the memory is not allocated to the pointer. Then by using the command c eval base_address=%addr(dsname2) we are allocating the address space to the pointer and since the data structure dsname1 is also referring this any change to dsname2 will affect dsname1. So assign some values to dsname2 and we can see the values in dsname1 also. Here the firname and lasname will print as shyam and sundar respectively. Question 40 Discuss about option keyword in detail (Ans) options(*varsize) : It is similar to declaring the variable as varchar instead of char. So if we declare a variable with size 100 and if you initialize with shyam then it will allocate only 5 spaces. Options(*nopass): This means that this parameter can be passed or even omitted Options(*omit): We can give both *nopass and *omit for a single variable. Options(*string): If we are passing string to the called program and if it is expecting the pointer then in such case we can give this option. Please refer the question 16 for further clarification Question 41 Explain EXTPGM in detail (Ans) If we want to call a procedure dynamically then we can make use of this command d prot1 pr extpgm('qcmdexc')

Question bank by Shyam sundar
d cmdstr 1000 options(*varsize) D CONST d cmdlen 15s 5 D CONST d const1 3 options(*nopass) D CONST D Cmds C 'DSPWSUSR' c callp prot1(cmds:%len(cmds)) c seton lr In the above program example we are passing 3 variables to qcmdexc command for listing cl command. Question 42 Explain O Spec and use of EXCEPT Opcode in detail (Ans) O-Spec is used for printing records and except opcode is equal to writing the record format name in case of RLU. We are printing all the records in the physical file pf02 whose has empno,name and address as the fields by using O-spec and except opcode. fpf02 if e disk fqsysprt o f 132 printer dss s 20a inz('--------------------') c* *loval setll rec1 c read rec1 80 c except header c *in80 doweq *off c except detail C read rec1 80 c enddo c seton lr * oqsysprt e header o ss 20 o ss 40 oqsysprt e detail o empno 5 o empname 25 o address 45 ****************** End of data ************************* The output of the spooled file is ---------------------------------------00001shyam trichy 00002tom pune 00003ccc jjhhj Question 43 Describe the architecture of MQ Series. (Ans)