Wednesday, December 4, 2013

Day-13.

Data Area:

 Overview:
This module enables the student to understand the concept of Data Area.
 Outline:
Topics covered,
·         Create Data Area.
·         Change Data Area
·         Delete Data Area.
·         Retrieve Data Area
·         Data area opcodes.
Objective:
By the end of this module, the student should be able to:
  • Create a Data-Area
  • Change Data Area
  • Delete Data Area.
  • Retrieve Data Area
  • Understand the Data Area opcodes.
 Definition
Data Area is an object used for passing information between programs within a job and between jobs.

Two programs can not simultaneously use the same data area for update. If the program calls another program that uses the same data area with UNLCK opcode before the other program is called.

Steps to create data Area .
  1. Type CRTDTAARA on Command prompt.
  1. Press F4
  2. The screen shown below will get displayed.

                    Create Data Area (CRTDTAARA)       
                                                                                              
 Type choices, press Enter.                                                     
                                                                               
Data area  . . . . . . . . . . .   DTA1          Name                         
Library  . . . . . . . . . . .  PB01U01O  Name, *CURLIB                
Type . . . . . . . . . . . . . .*CHAR *DEC,*CHAR,*LGL, *DDM      
  Length: 
                                                                      
   Length . . . . . . . . . . . .   21            1-2000                        
   Decimal positions  . . . . . .                 0-9                          
 Initial value  . . . . . . . . .   'DUKESTAR TECHNOLOGIES'                    
 Text 'description' . . . . . . .   *BLANK                                      
                                                                                                                                                                               
                                                                         Bottom
 F3=Exit   F4=Prompt   F5=Refresh   F10=Additional parameters   F12=Cancel     
 F13=How to use this display        F24=More keys                              
                                                        
   
       4.  Press Enter & Data Area  will get created with initial value  
‘Dukestar Technologies’      

Change Data Area.
  1. Type CHGDTAARA on Command prompt. 
  1. Press F4
  1. The screen shown below will get displayed.

                      
          Change Data Area (CHGDTAARA)                                                                                                   
 Type choices, press Enter.                                                     
                                                                               
Data area specification:                                                      
Data area  . . . . . . . . . .DTA1  Name, *LDA, *GDA, *PDA       
Library  . . . . . . . . .   PBO1U01O    Name, *LIBL, *CURLIB         
Substring 
specifications:                                                   
   Substring starting position  .   1      1-2000, *ALL                 
   Substring length . . . . . . .   15     1-2000                       
 New value  . . . . . . . . . . .   'DATA AREA     '                           
                                                                                                                                                                          
                                                                                                           Bottom
 F3=Exit   F4=Prompt   F5=Refresh   F12=Cancel   F13=How to use this display   
 F24=More keys                                                                 
                                                                               
                                                                                                                  
        4. Press Enter & Data Area will get changed   

Delete Data Area.
  1. Type DLTDTAARA on Command prompt. 
  1. Press F4
  1. The screen shown below will get displayed.
                          Delete Data Area (DLTDTAARA)                         
                                                                               
 Type choices, press Enter.                                                     
                                                                               
 Data area  . . . . . . . . . . .   DTA1          Name, generic*               
   Library  . . . . . . . . . . .     PB01U01O    Name, *LIBL, *CURLIB...       
                                                                               
                                                                               
                                                                                                             
                                                                               
                                                                         Bottom
 F3=Exit   F4=Prompt   F5=Refresh   F12=Cancel   F13=How to use this display   
 F24=More keys                                                                 
        4. Press Enter to Delete the Data Area   

 Retrieve Data Area

To retrieve the value of data area we have to write a CL program 

  1. Create a CL program CL2
Columns . . . :    1  71            Edit                        PB01U01S/MYCLP
SEU==>                                                                     CL2
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 .
************* Beginning of data ********************
0001.00  PGM                                                                   
0002.00  DCL  VAR(&VAR1) TYPE(*CHAR) LEN(10)           
0003.00   RTVDTAARA  DTAARA(PB01U01O/ DTA1 (1 10))+  
              RTNVAR(&VAR1)          
0004.00  SNDPGMMSG  MSG(&VAR1)                               
0005.00  ENDPGM                                                                
********** End of data ************************
                                                                               
                                                    
                                                                               
 F3=Exit   F4=Prompt   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle       
 F16=Repeat find       F17=Repeat change          F24=More keys                
                                         (C) COPYRIGHT IBM CORP. 1981, 2002.   

  1. Retrieve Data Area (RTVDTAARA) is used to retrieve values from a data area                      

                         Retrieve Data Area (RTVDTAARA)                        
                                                                               
 Type choices, press Enter.                                                     
                                                                               
 Label  . . . . . . . . . . . . .                                              
 Data area specification:                                                      
   Data area  . . . . . . . . . . > DTA1          Name, *LDA, *GDA, *PDA       
     Library  . . . . . . . . . . >   PB01U01O    Name, *LIBL, *CURLIB         
   Substring specifications:                                                   
   Substring starting position  . > 1             1-2000, *ALL                 
   Substring length . . . . . . . > 10            1-2000                       
 CL variable for returned value   > &VAR1         Character value              
 Comment  . . . . . . . . . . . .                                              
                                                                               
                                                                               
                                                                                
                                                                                                                                                 
                                                                         Bottom
 F3=Exit   F4=Prompt   F5=Refresh   F12=Cancel   F13=How to use this display   
 F24=More keys                                                                 
                                                                               


In this CL program value from Data Area is Retrieve and store the value in variable var1. and then this value is passed to the program message queue.


Data area Opcodes
Following are the data area opcodes.

IN, OUT and UNLCK. We will see all opcodes one by one.

IN (Retrieve Data area)
IN opcodes retrieves a data area specified in factor 2 of calculation specification. This allows you to control the locking or unlocking of a data area.

Note: If you want to use data area opcodes IN, OUT or ULCK then you must define this data area with DEFN opcode using *NAMVAR in factor 1 and name of data area in result field.

Following is the specification format for the IN opcode.

Factor1
OPERATION
FACTOR 2
RESULT
HI LO   EQ
*LOCK
IN
Data area name or *NAMVAR
b
b   ER   b

Factor1 entry is optional. It can be blank or contain the reserve word *LOCK. Factor1 must be blank if factor 2 is name of local data area (*LDA) or program initialization parameters (PIP) data area. *LOCK in factor 1 indicates that the data area cannot be updated or locked by another program until (i) an UNLCK operation is processed, (ii) an OUT operation with no factor1 entry is processed or (iii) the RPG/400 program implicitly unlocks the data area when the program ends.

Factor 2 entry contains the name of data area or the reserve word *NAMVAR. Opcode IN with *NAMVAR retrieves all the data area defined in the program (See program PGMDTA3)

You can specify resulting indicator in positions 56 and 57 (LO entry). This indicator will set on if an error has occurred during the operation.


OUT (Update Data area)
The out opcode update the data area specified in factor2.

Factor1
OPERATION
FACTOR 2
RESULT
HI LO   EQ
*LOCK
OUT
Data area name or *NAMVAR
b
b   ER   b


Factor 1 entry is optional. It can be blank or contain the reserve word *LOCK. Factor 1 must be blank if factor 2 is name of local data area (*LDA) or program initialization parameters (PIP) data area. *LOCK in factor 1 indicates that data area remains locked after it is updated. When factor1 is blank, the data area is unlocked after it is updated.
Factor 2 entry contains the name of data area to be updated or the reserve word *NAMVAR. Opcode OUT with *NAMVAR updates all the data area defined in the program. You can specify resulting indicator in positions 56 and 57 (LO entry). This indicator will set on if an error has occurred during the operation.


UNLCK (Unlock a Data Area or Release a Record)
The UNLCK operation is used for 2 purpose.

The UNLCK operation unlocks data areas and allows the most recently locked record to be unlocked for an update disk file.

The following is the specification format for the IN opcode.
Factor1
OPERATION
FACTOR 2
RESULT
HI LO   EQ
b
UNLCK
Data area name or File Name
b
b   ER   b

Factor2 must contain the name of the data area to be unlocked, the name of an update disk file, or the reserve word *NAMVAR. When *NAMVAR is specified in factor2 all data areas in the program which are locked, will be unlocked.
Factor 2 must not refer to the local data area of the program initialization parameter (PIP) data area. If factor 2 contains file name then that file must be defined as an update disk file.

You can specify resulting indicator in positions 56 and 57 (LO entry). This indicator will set on if an error has occurred during the operation.
                                                                        
RPG Program for IN opcode

Columns . . . :    1  71            Edit                        PB01U01S/MYRPG
 SEU==>                                                                 DTARPG1
 FMT *  ..... *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
************* Beginning of data ***********************
0000.01 C*Define Data Area with *NAMVAR                        
0001.00 C   *NAMVAR   DEFN           DTA1   21                  
0001.02 C*Retrieve Data Area with IN                     
0002.00 C  *LOCK     IN   DTA1                                 
0003.00 C            MOVE 'Pune'    FLD1   10                   
0004.00 C            MOVE *BLANKS   FLD2   50                   
0004.02 C*Concatenate DTA1 value with FLD1 value and store it in         C* FLD2    

0005.00 C  DTA1      CAT  FLD1      FLD2                       
0006.00 C  FLD2      DSPLY                                     
0006.02 C*Unlock Data Area                                      
0007.00 C            UNLCKDTA1                                  
0008.00 C            SETON                     LR               
*************** End of data *******************************
                                                                               
                                                                                                                                          
 F3=Exit   F4=Prompt   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle      
 F16=Repeat find       F17=Repeat change          F24=More keys                
                                                                                



RPG Program for OUT Opcode


Columns . . . :    1  71            Edit                        PB01U01S/MYRPG
 SEU==>                                                                DTARPG2
 FMT *  ..... *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data *************************************
0001.00      C*Define Data Area with *NAMVAR                                   
0002.00      C           *NAMVAR   DEFN           DTA1   21                    
0003.00      C*Retrieve Data Area with IN                                        
0004.00      C            *LOCK         IN   DTA1                                   
0005.00      C                                  MOVE 'PUNE'    FLD1   10                    
0006.00      C                                  MOVE *BLANKS   FLD2   50                     
0007.00      C*Concatenate DTA1 value with FLD1 value and store it in FLD2     
0008.00      C            DTA1            CAT  FLD1      FLD2                         
0009.00      C            FLD2             DSPLY                                       
0009.01       *MOVEING ‘HELLO’ TO THE DATA AREA                                 
0009.03      C                                   MOVEL'HELLO'   DTA1                         
0009.04       *UPDATING DATA AREA                                              
0009.05      C                     OUT      DTA1                                   
0009.06       *DISPLAYING DATA AREA                                            
0009.07      C                   DTA1      DSPLY                                       
0010.00      C*Unlock Data AREA                                                 
0011.00      C                                  UNLCKDTA1                                   
0012.00      C                                  SETON                     LR                
        ****************** End of data ****************************************

                                                                               
                                                                               
 F3=Exit   F4=Prompt   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle      
 F16=Repeat find       F17=Repeat change          F24=More keys                
                                                                               



Example of Use of Data Area :
In this example we store the name of the school in the data area. we retrieve the name of school from the data area through a cl program (CL3) .
In following example, we display the details of the students. the name of school on display screen comes from the data area.     

First we will create a Data Area SCHOOL and store the name of the school in that.

DDS for the Physical file (STUD):

Columns . . . :    1  71           Browse                       PB01U01D/MYDDS
 SEU==>                                                                    STUD
 FMT A* .....A*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data ***************
0001.00       *****************************************************************
0002.00       *                                                                
0003.00       *                STUDENT MASTER                                  
0004.00       *****************************************************************
0005.00                 R STUDR                                                
0006.00                     ROLL            3  0       COLHDG('ROLL NUMBER')      
0007.00                     NAME         10           COLHDG('NAME OF STUDENT')  
0008.00                     CLASS          2  0        COLHDG('STUDENT CLASS')    
0009.00                     SEC                1           COLHDG('CLASS SECTION')    
0010.00                 K ROLL                                                 
        ****************** End of data ****************************************
                                                                               
                                                                                                                                                          
 F3=Exit   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle   F12=Cancel     
 F16=Repeat find        F24=More keys                                          
                                         (C) COPYRIGHT IBM CORP. 1981, 2002.   



Display File Record (S1):
UUUUUUUUUU                       OOOOOOOOOO                                           TT:TT:TT
                                                                                                                          DD/DD/DD
 ------------------------------------------------------------------------------
                                                                               
                                                                               
                                                                               
    NAME..................:               OOOOOOOOOO                                    
                                                                               
    ROLL NUMBER...........:      999-                                          
                                                                                
    CLASS.................:                99-                                           
                                                                               
    SECTION...............:              O                                             
                                                                               
                                                                                                                                               
                                                                               
 ------------------------------------------------------------------------------
   F3=EXIT                                                                     
 Work screen for record S1: Press Help for function keys.                      

DDS for the Display file (STUD):
Columns . . . :    1  71            Edit                        PB01U01D/MYSCR
 SEU==>                                                                  STUDIN
 FMT A* .....A*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data *************************************
0000.10      A*%%TS  SD  20050317  135046  PB01U01     REL-V5R2M0  5722-WDS    
0000.20      A*%%EC                                                            
0000.30      A                                      DSPSIZ(24 80 *DS3)          
0000.40      A          R S1                                                   
0000.50      A*%%TS  SD  20050317  135046  PB01U01     REL-V5R2M0  5722-WDS    
0000.60      A                                      CF03(03)                   
0000.70      A                                  1 72TIME                       
0000.80      A                                  2 72DATE                       
0000.90      A                                      EDTCDE(Y)                  
0001.00      A                                  1  2USER                       
0001.10      A                                  3  2'--------------------------
0001.20      A                                      ---------------------------
0001.30      A                                      ---------'                 
0001.40      A                                      COLOR(BLU)                 
0001.50      A                                 22  2'--------------------------
0001.60      A                                      ---------------------------
0001.70      A                                      ---------'                 
0001.80      A                                      COLOR(BLU)                 
0001.90      A            SCNAME        10A  O  1 35DSPATR(HI)                 
0002.00      A                                 23  4'F3=EXIT'                  
0002.10      A                                      COLOR(BLU)                 
0002.20      A                                  7  5'NAME..................:'  
0002.30      A                                  9  5'ROLL NUMBER...........:'  
0002.40      A                                 11  5'CLASS.................:'  
0002.50      A                                 13  5'SECTION...............:'  
0002.60      A            SNAME         10A  O  7 34                           
0002.70      A            SROLL          3S 0B  9 34                           
0002.80      A            SCLASS         2S 0B 11 34                           
0002.90      A            SSEC           1A  O 13 34                           
        ****************** End of data ****************************************
                                                                               
F3=Exit   F4=Prompt   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle      
 F16=Repeat find       F17=Repeat change          F24=More keys                
                                                                               



CL Program CL2:


Columns . . . :    1  71            Edit                        PB01U01S/MYCLP
 SEU==> C                                                                   CL3
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data *************************************
0001.00              PGM        PARM(&VAR1)                                    
0002.00              DCL        VAR(&VAR1) TYPE(*CHAR) LEN(10)                 
0002.01              DCL        VAR(&VAR2) TYPE(*CHAR) LEN(10)                 
0003.00              RTVDTAARA  DTAARA(SCHOOL (1 10)) RTNVAR(&VAR2)            
0004.00              CHGVAR     VAR(&VAR1) VALUE(&VAR2)                        
0005.00              ENDPGM                                                     
        ****************** End of data ****************************************
                                                                               
                                                                                
                                                                                                                                                          
                                                                               
 F3=Exit   F4=Prompt   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle      
 F16=Repeat find       F17=Repeat change          F24=More keys                
                                         (C) COPYRIGHT IBM CORP. 1981, 2002.   




RPG Program Description:

Columns . . . :    1  71            Edit                        PB01U01S/MYRPG
 SEU==>                                                                  SCHOO1
 FMT FX .....FFilenameIPEAF........L..I........Device+......KExit++Entry+A....U
        *************** Beginning of data *************************************
0001.00      FSTUD    IF  E           K        DISK                            
0002.00      FSTUDIN  CF  E                    WORKSTN                         
0003.00       *                                                                
0004.00      C           *IN03     DOWEQ*OFF                                    
0005.00      C   03                   LEAVE                                       
0005.01       *CALLING THE CL PROGRAM TO FEATCH SCHOOL NAME FROM DATA AREA     
0005.02       *SCHOOL                                                           
0006.00      C                         CALL 'CL2'                                  
0007.00      C                         PARM           SSNAME 10                    
0008.00      C                         MOVELSSNAME    SCNAME                        
0009.00      C        *LOVAL  SETLLSTUDR                                  
0010.00      C        *IN90       DOWEQ*OFF                                   
0012.00      C                         READ STUD                     90            
0013.00      C                         EXSR P2S                                    
0014.00      C                         EXFMTS1                                     
0014.01      C   03                   LEAVE                                       
0015.00      C                          ENDDO                                       
0016.00      C                          ENDDO                                       
0017.00      C                          SETON                     LR                
0018.00       *                                                                 
0019.00       **************************************************************   
0020.00      C           P2S        BEGSR                                       
0021.00      C                          MOVELNAME      SNAME                        
0021.01      C                          Z-ADDROLL      SROLL                        
0021.02      C                          Z-ADDCLASS     SCLASS                       
0022.00      C                          MOVELSEC       SSEC                          
0023.00      C                          ENDSR                                       
        ****************** End of data ****************************************

                                                                                
 F3=Exit   F4=Prompt   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle      
 F16=Repeat find       F17=Repeat change          F24=More keys                
                                                                               


No comments:

Post a Comment