Wednesday, August 9, 2017

Questoin bank 1


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 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            10A                                 
 D                               10A                                 
 PPROC1            B                   EXPORT                        
 DPROC1            PI            10A                                 
 DX                              10A                                  
 Dlower            S             26A   inz('abcdefghijklmnopqrstuvwxyz’)
 Dupper1           S             26A   inz('ABCDEFGHIJKLMNOPQRSTUVWXYZ’)
 C     lower:upper1  XLATE     X             X                       
 C                   RETURN    X                                     
 PPROC1            E    

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                                 
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
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           s             12p 2 inz(1234567890.12)               
dedit             c                   '$ ,   ,   ,   &dollars&and&  &cents’
damount           s             40a                                    
c                        eval      amount=%editw(salary:edit)               
c     amount        dsply                                              
c                       seton                                        lr    

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)  
                                                               
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)

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.
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                                             Empno      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       Empname                       Empsal
1                  shyam                                1000000
2                 sundar                                2000000

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                    JFILE(JP01 JP02)         
                 J                                  JOIN(1 2)                
                                                     JFLD(EMPNO EMPNO)        
                   EMPNO                    JREF(JP01)               
                   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.
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              5s 0 inz(10)                          
di                s              5s 0                    
 * for(i=0;i<n;i++)
c                   for       i=1 to n                                  
c     i             dsply                                              
c                   endfor                                             
 *  for(i=n;i<1;i--)                                                 
c                   for       i=n downto 1                             
c    i             dsply                                              
c                   endfor                                             
 *  for(i=5;i<40;i=i+10)                                              
c                   for       i=5 by n to 40                           
c     i             dsply                                              
c                   endfor                                             
c                                                                       
c                   for       i=5  to 40 by n                          
c     i             dsply                                              
c                   endfor                                         
c                                                                 
 *   for(i=5;i<40;i=i+10)                                             
c                   seton                                        lr

Question 21
What are the various stages for a job after it is submitted?
(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
Join Logical Files
We can able to insert or delete or update records using non join logical files.
Insertion, updating or deletion of records is not possible in join logical files
DFU  can be used to display Non join logical files
DFU is not available
1-32 record format can be specified
Only one record format can be specified
Commitment control is used
Commitment control is possible

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  Physical File
            EMPID   EMPNAME                          MGRID                                
000001 10,001   Sebi Joseph C.        50,001                                
000002 10,002   Purushottam             50,002                                 
000003 10,003   Sameer Dighe          50,003                                
000004 10,004   Sharada Menon                    50,004                                
000005 10,005   Saju Paul C.                          50,005                                
000006 50,001   Shivaram Pasuvan                90,001                                
000007 50,002   Praveen K. Gaurav                90,002                                
000008 50,003   Lionel King                          90,003                                
000009 50,004   Sam Mathew Varghese        90,004                                
000010 50,005   Anil Jandyam          90,005                                
****** ********  End of report  ********                                    


 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   ....+....1....+....2....+....3....+....4....+....5. 
              EMPID   EMPNAME               MANAGER              
000001 10,001   Sebi Joseph C.        Shivaram Pasuvan     
000002 10,002   Purushottam           Praveen K. Gaurav    
000003 10,003   Sameer Dighe          Lionel King          
000004 10,004   Sharada Menon         Sam Mathew Varghese  
000005 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)
opnqryf
sqlrpg
Opnqryf will come along with os/400 system and no need to have any additional package needed to execute it.
We need to have sqlrpg installed in as/400 system which involves additional cost to the programmers
Opnqryf is faster as compared to sqlrpg
It is slower
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
Open Program Model is the old RPG/400 system, which will not allow a program type to call another program type.
Extended program model will support PASCAL, FORTRAN and other programming concepts.
It supports mixed program support in which you can combine any program with another type of program

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
Here all the modules to be bounded are physically copied into the main program object.
In this case we are binding the programs by using service programs which contains a reference to the modules that has been called and the modules are not physically copied into the program objects
The program will be executed even when you delete all the modules that have been called.
The program will not executed when the bind modules are deleted.
Bind by value is faster than bind by reference
It is not as faster as bind by 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
 DA                S              2P 0 INZ(8)                                                         CALLB ‘PGM1’
 DB                S              2P 0 INZ(8)                                                          SETON         LR                        
 DC                S              2P 0                               
 C                   EVAL      C=A+B                                 
 C                   SETON                                        LR 

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.
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 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
      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 sequentially based on the position of the record.
It will sort the records based on the field values.
If any changes in the attribute size of a pf then we have to change the program specification also
If there is any change in the attribute size it will not affect the program specification also.
FMTDTA is bit faster in process than opnqryf.
OPNQRYF is slower as compare to 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                                            
C                      SETON                                        LR  

Program 2
ddd               s              2s 0 import                       
c                   eval      dd=6                                 
c                   seton                                        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')           
 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                   







No comments:

Post a Comment