as400 interview questions and answers-Part 30


1. Explain MOVE opcode with example.

 

Ans:

 

MOVE (Move)

·         The MOVE operation transfers characters from factor 2 to the result field.

·         Moving starts with the rightmost character of factor 2.

·         When moving Date, Time or Timestamp data, factor 1 must be blank unless either the source or the target is a character or numeric field.

·         If factor 2 is longer than the result field, the excess leftmost characters or digits of factor 2 are not moved.

·         If the result field is longer than factor 2, the excess leftmost characters or digits in the result field are unchanged, unless padding is specified.

·         If factor 2 is shorter than the length of the result field, a P specified in the operation extender position causes the result field to be padded on the left after the move occurs.

·         A MOVE operation does not change the length of a variable-length result field.

·         If the source or target is a character field, you may optionally indicate the separator following the format in factor 1. Only separators that are valid for that format are allowed.

 

Factor 1

Op-code

Factor 2

Result Field

Resulting Indicators

       HI                            LO                      EQ

Data attribute

MOVE

Source field 

Target field

 

 

 

 

 

Example

    I.        MOVE Operation with Date/Time

 


Columns . . . :    6  80               Browse                                AMINEM/QRPGLESRC
SEU==>                                                                                OP_MOVE
FMT D  DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++
*************** Beginning of data ****************************************************
0001.00 DDATE0            S               D                                             130124
0002.00 DDATE1            S               D                                             130129
0003.00 DDATE2            S               D   DATFMT(*JIS)                              130129
0004.00 DDATE3            S               D   INZ(D'2001-01-12')                        130129
0005.00 DDATE3_CHAR       S             10                                              130129
0006.00 DTIME0            S               T   INZ(T'10.12.15')                          130129
0007.00 DTIME0_CHAR       S              8                                              130129
0008.00 C                   MOVE      *DATE         DATE0                               130129
0009.00 C     *MDY          MOVE      010112        DATE1                               130129
0010.00 C     *MDY/         MOVE      '01/01/12'    DATE2                               130129
0011.00 C                   MOVE      DATE3         DATE3_CHAR                          130129
0012.00 C                   MOVE      TIME0         TIME0_CHAR                          130129
0013.00 C     DATE0         DSPLY                                                       130124
0014.00 C     DATE1         DSPLY                                                       130124
0015.00 C     DATE2         DSPLY                                                       130129
0016.00 C     DATE3_CHAR    DSPLY                                                       130129
0017.00 C     TIME0_CHAR    DSPLY                                                       130129
0018.00 C                   SETON                                            LR         130124
****************** End of data *******************************************************

 

OUTPUT

DSPLY  2013-01-29

DSPLY  2012-01-01

DSPLY  2012-01-01

DSPLY  2001-01-12

DSPLY  10.12.15 

 

 

 

 

 

 

II.     MOVE Operation with Date/Time

 

 


Columns . . . :    6  80                        Browse                        AMINEM/QRPGLESRC
SEU==>                                                                                OP_MOVE1
FMT D  DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++
*************** Beginning of data ****************************************************
0001.00 D A1              S              5A   INZ('AAAA') VARYING                       130129
0002.00 D A2              S             10A   INZ('AAAAAAAA') VARYING                   130129
0003.00 D A3              S             20A   INZ('AAAAAAAAAAAA') VARYING               130129
0004.00 D B1              S              5A   INZ('BBBBB')                              130129
0005.00 D B2              S             10A   INZ('BBBBBBBBBB')                         130129
0006.00 D B3              S             20A   INZ('BBBBBBBBBBBBBBBBBBBB')               130129
0007.00 D C1              S              5A   INZ('CCC') VARYING                        130129
0008.00 D C2              S             10A   INZ('CCCCCCC') VARYING                    130129
0009.00 D C3              S             20A   INZ('CCCCCCCCCCCCCCCCC') VARYING          130129
0010.00 C     A1            DSPLY                                                       130129
0011.00 C     A2            DSPLY                                                       130129
0012.00 C     A3            DSPLY                                                       130129
0013.00 C     B1            DSPLY                                                       130129
0014.00 C     B2            DSPLY                                                       130129
0015.00 C     B3            DSPLY                                                       130129
0016.00 C     C1            DSPLY                                                       130129
0017.00 C     C2            DSPLY                                                       130129
0018.00 C     C3            DSPLY                                                       130129
0019.00 C                   MOVE      A1            B2                                  130129
0020.00 C                   MOVE      A2            B3                                  130129
0021.00 C                   MOVE      A3            B1                                  130129
0022.00 C                   MOVE      B1            C3                                  130129
0023.00 C                   MOVE      B2            C1                                  130129
0024.00 C                   MOVE      B3            C2                                  130129
0025.00 C                   MOVE      C1            A3                                  130129
0026.00 C                   MOVE      C2            A1                                  130129
0027.00 C                   MOVE      C3            A2                                  130129
0028.00 C     A1            DSPLY                                                       130129
0029.00 C     A2            DSPLY                                                       130129
0030.00 C     A3            DSPLY                                                       130129
0031.00 C     B1            DSPLY                                                       130129
0032.00 C     B2            DSPLY                                                       130129
0033.00 C     B3            DSPLY                                                       130129
0034.00 C     C1            DSPLY                                                       130129
0035.00 C     C2            DSPLY                                                       130129
0036.00 C     C3            DSPLY                                                       130129
0037.00 C                   SETON                                            LR         130129
****************** End of data *******************************************************     

OUTPUT

DSPLY  AAAA               
DSPLY  AAAAAAAA          
DSPLY  AAAAAAAAAAAA        
DSPLY  BBBBB                          
DSPLY  BBBBBBBBBB                     
DSPLY  BBBBBBBBBBBBBBBBBBBB           
DSPLY  CCC                            
DSPLY  CCCCCCC                        
DSPLY  CCCCCCCCCCCCCCCCC              
DSPLY  AAAA                        
DSPLY  CCCAAAAA                    
DSPLY  AAAAAAAAAAAA                 
DSPLY  AAAAA                       
DSPLY  BBBBBBAAAA                  
DSPLY  BBBBBBBBBBBBAAAAAAAA        
DSPLY  AAA                         
DSPLY  AAAAAAA                     
DSPLY  CCCCCCCCCCCCAAAAA           

 

 

 

 

*** As we know that Moving starts with the rightmost character of factor 2. So, we derive the result here on the basis of this fact, as shown below.

 

1.  MOVE      A1            B2  

MOVE pic1

          Result:  B2= BBBBBBAAAA

 

2.  MOVE      A3            B1  

MOVE pic2

 

          Result:  B1= AAAAA

 

 

3.  MOVE      B3            C2  

 

MOVE pic3

           Result:  C2= AAAAAAA

 

4.  MOVE      C3            A2  

 

MOVE pic4

           Result:  A2= CCCAAAAA

 

 

 

2. Explain MOVEL(P) with example.

 

Ans:

 

MOVEL (P)

 

 

Example

 


Columns . . . :    6  80                     Edit                            AMINEM/QRPGLESRC
SEU==>                                                                               OP_MOVE1
FMT D  DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++
*************** Beginning of data ****************************************************
0001.00 D A1              S              5A   INZ('AAAA') VARYING                       130129
0002.00 D A2              S             10A   INZ('AAAAAAAA') VARYING                   130129
0003.00 D A3              S             20A   INZ('AAAAAAAAAAAA') VARYING               130129
0004.00 D B1              S              5A   INZ('BBBBB')                              130129
0005.00 D B2              S             10A   INZ('BBBBBBBBBB')                         130129
0006.00 D B3              S             20A   INZ('BBBBBBBBBBBBBBBBBBBB')               130129
0007.00 D C1              S              5A   INZ('CCC') VARYING                        130129
0008.00 D C2              S             10A   INZ('CCCCCCC') VARYING                    130129
0009.00 D C3              S             20A   INZ('CCCCCCCCCCCCCCCCC') VARYING          130129
0010.00 C     A1            DSPLY                                                       130129
0011.00 C     A2            DSPLY                                                       130129
0012.00 C     A3            DSPLY                                                       130129
0013.00 C     B1            DSPLY                                                       130129
0014.00 C     B2            DSPLY                                                       130129
0015.00 C     B3            DSPLY                                                       130129
0016.00 C     C1            DSPLY                                                       130129
0017.00 C     C2            DSPLY                                                       130129
0018.00 C     C3            DSPLY                                                       130129
0019.00 C                   MOVEL(P)  A1            B2                                  130129
0020.00 C                   MOVEL(P)  A2            B3                                  130129
0021.00 C                   MOVEL(P)  A3            B1                                  130129
0022.00 C                   MOVEL(P)  B1            C3                                  130129
0023.00 C                   MOVEL(P)  B2            C1                                  130129
0024.00 C                   MOVEL(P)  B3            C2                                  130129
0025.00 C                   MOVEL(P)  C1            A3                                  130129
0026.00 C                   MOVEL(P)  C2            A1                                  130129
0027.00 C                   MOVEL(P)  C3            A2                                  130129
0028.00 C     A1            DSPLY                                                       130129
0029.00 C     A2            DSPLY                                                       130129
0030.00 C     A3            DSPLY                                                       130129
0031.00 C     B1            DSPLY                                                       130129
0032.00 C     B2            DSPLY                                                       130129
0033.00 C     B3            DSPLY                                                       130129
0034.00 C     C1            DSPLY                                                       130129
0035.00 C     C2            DSPLY                                                       130129
0036.00 C     C3            DSPLY                                                       130129
0037.00 C                   SETON                                            LR         130129
****************** End of data *******************************************************

 

 

 

OUTPUT

 

DSPLY  AAAA                
DSPLY  AAAAAAAA          
DSPLY  AAAAAAAAAAAA        
DSPLY  BBBBB                          
DSPLY  BBBBBBBBBB                     
DSPLY  BBBBBBBBBBBBBBBBBBBB           
DSPLY  CCC                            
DSPLY  CCCCCCC                         
DSPLY  CCCCCCCCCCCCCCCCC              
DSPLY  AAAA                      
DSPLY  AAAAA                     
DSPLY  AAA                       
DSPLY  AAAAA                     
DSPLY  AAAA                      
DSPLY  AAAAAAAA                   
DSPLY  AAA                       
DSPLY  AAAAAAA                   
DSPLY  AAAAA     

 

 

*** Here the data will be moved to the left and rest of the right part will be padded with blank.

 

 

1.  MOVE(P)   A1            B2

MOVEL(P) pic1

 

          Result:  B2=AAAA

 

      All the above B in red will be removed while padding.

 

 

 

3. Explain MOVEL opcode in rpgle with example.

 

Ans:

MOVEL (Move Left)

·         The MOVEL operation moves characters from factor 2 to the result field and it does that by moving the leftmost character first.

 

 

Example

 


Columns . . . :    6  80                     Edit                             AMINEM/QRPGLESRC
SEU==>                                                                                OP_MOVE1
FMT D  DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++
*************** Beginning of data ************************************************************
0001.00 D A1              S              5A   INZ('AAAA') VARYING                       130129
0002.00 D A2              S             10A   INZ('AAAAAAAA') VARYING                   130129
0003.00 D A3              S             20A   INZ('AAAAAAAAAAAA') VARYING               130129
0004.00 D B1              S              5A   INZ('BBBBB')                              130129
0005.00 D B2              S             10A   INZ('BBBBBBBBBB')                         130129
0006.00 D B3              S             20A   INZ('BBBBBBBBBBBBBBBBBBBB')               130129
0007.00 D C1              S              5A   INZ('CCC') VARYING                        130129
0008.00 D C2              S             10A   INZ('CCCCCCC') VARYING                    130129
0009.00 D C3              S             20A   INZ('CCCCCCCCCCCCCCCCC') VARYING          130129
0010.00 C     A1            DSPLY                                                       130129
0011.00 C     A2            DSPLY                                                       130129
0012.00 C     A3            DSPLY                                                       130129
0013.00 C     B1            DSPLY                                                       130129
0014.00 C     B2            DSPLY                                                       130129
0015.00 C     B3            DSPLY                                                       130129
0016.00 C     C1            DSPLY                                                       130129
0017.00 C     C2            DSPLY                                                       130129
0018.00 C     C3            DSPLY                                                       130129
0019.00 C                   MOVEL     A1            B2                                  130129
0019.00 C                   MOVEL     A1            B2                                  130129
0020.00 C                   MOVEL     A2            B3                                  130129
0021.00 C                   MOVEL     A3            B1                                  130129
0022.00 C                   MOVEL     B1            C3                                  130129
0023.00 C                   MOVEL     B2            C1                                  130129
0024.00 C                   MOVEL     B3            C2                                  130129
0025.00 C                   MOVEL     C1            A3                                  130129
0026.00 C                   MOVEL     C2            A1                                  130129
0027.00 C                   MOVEL     C3            A2                                  130129
0028.00 C     A1            DSPLY                                                       130129
0029.00 C     A2            DSPLY                                                       130129
0030.00 C     A3            DSPLY                                                       130129
0031.00 C     B1            DSPLY                                                       130129
0032.00 C     B2            DSPLY                                                       130129
0033.00 C     B3            DSPLY                                                       130129
0034.00 C     C1            DSPLY                                                       130129
0035.00 C     C2            DSPLY                                                       130129
0036.00 C     C3            DSPLY                                                       130129
0037.00 C                   SETON                                            LR         130129
****************** End of data ***************************************************************

 

 

OUTPUT

 

DSPLY  AAAA               
DSPLY  AAAAAAAA          
DSPLY  AAAAAAAAAAAA        
DSPLY  BBBBB                          
DSPLY  BBBBBBBBBB                     
DSPLY  BBBBBBBBBBBBBBBBBBBB           
DSPLY  CCC                            
DSPLY  CCCCCCC                        
DSPLY  CCCCCCCCCCCCCCCCC               
DSPLY  AAAA                                
DSPLY  AAAAACCC                            
DSPLY  AAAAAAAAAAAA                        
DSPLY  AAAAA                               
DSPLY  AAAABBBBBB                          
DSPLY  AAAAAAAABBBBBBBBBBBB                
DSPLY  AAA                                 
DSPLY  AAAAAAA                             
DSPLY  AAAAACCCCCCCCCCCC 

 

                 

 

 

·        Output Explanation

 

***Here due to MOVEL operation the data will start filling from the left.

 

 

1.  MOVEL      A1            B2  

MOVEL pic1

          Result:  B2= AAAABBBBBB

 

 

2.  MOVEL      A3            B1 

MOVEL pic 2

          Result:  B1= AAAAA

 

 

 

3.  MOVEL      B3            C2  

MOVEL pic 3

           Result:  C2=AAAAAAA

 

4.  MOVEL      C3            A2  

MOVEL pic4

           Result:  A2= AAAAACCCC

 

 

                                   

4. Explain XFOOT, SORTA, LOOKUP opcode in rpgle.

Ans:

XFOOT (sum-up the array element)

·         Lookup: It is used to look for an element in the array.

·         Sorta: It is used to sort the array element

·         Xfoot: It is used to sum-up the array element.

 

Example


Columns . . . :    1 100                                      Browse
SEU==>
FMT D  .....DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++++++++++++++++++++
*************** Beginning of data *******************************************
0001.00      darr2             s              3P 0 dim(5) ctdata perrcd(1)
0002.00      dn                s              2p 0 inz(1)
0003.00      C     n             do        5
0004.00      C     arr2(n)       dsply
0005.00      C                   eval      n=n+1
0006.00      C                   enddo
0007.00      C                   sorta     arr2
0008.00      C                   eval      n=1
0009.00      C     n             do        5
0010.00      C     arr2(n)       dsply
0011.00      C                   eval      n=n+1
0012.00      C                   enddo
0013.00      C     204           lookup    arr2                                   81
0014.00      C                   if        *in81=*on
0015.00      C     'found'       dsply
0016.00      C                   endif
0017.00      C                   xfoot     arr2          sum               4 0
0018.00      C     sum           dsply
0019.00      c                   seton                                        lr
0020.00 ** CTDATA arr2
0021.00 201
0022.00 205
0023.00 203
0024.00 202
0025.00 204
****************** End of data ************************************************

 

 

OUTPUT

 

DSPLY  201   
DSPLY  205   
DSPLY  203   
DSPLY  202   
DSPLY  204   
DSPLY  201   
DSPLY  202   
DSPLY  203   
DSPLY  204   
DSPLY  205   
DSPLY  found 
DSPLY  1015  

 

 




 

 







User Comments:



Subscribe

.  


Copyright © www.go4as400.com, 2013-2023. Copyright notice   Terms of services   Privacy policy