Académique Documents
Professionnel Documents
Culture Documents
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
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
2 0 2 0
LR
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.
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.
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 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 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 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:
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.
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 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 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
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 dont 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.
dob
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')