Version 6.3.8 for OpenVMS
 —  Statements  —

Examples of DEFINE DATA Statement Usage

The following topics are covered:


Example 1 - DEFINE DATA LOCAL (Direct Data Definition)

** Example 'DDAEX1': DEFINE DATA                                        
************************************************************************
DEFINE DATA LOCAL                                                       
1 #VAR1     (A15)                                                       
1 #VAR2                                                                 
  2 #VAR2A  (N4.1) INIT <1111>                                          
  2 #VAR2B  (N6.2) INIT <222222>                                        
1 REDEFINE #VAR2                                                        
  2 #VAR2C  (A2)                                                        
  2 #VAR2D  (A2)                                                        
  2 #VAR2E  (A6)                                                        
END-DEFINE
*                                                                       
WRITE NOTITLE '=' #VAR2A / '=' #VAR2B /                                 
              '=' #VAR2C / '=' #VAR2D / '=' #VAR2E                      
*                                                                       
END                                                                    

Output of Program DDAEX1:

#VAR2A:  1111.0   
#VAR2B:  222222.00
#VAR2C: 11        
#VAR2D: 11        
#VAR2E: 022222   

Top of page

Example 2 - DEFINE DATA LOCAL (Array Definition/Initialization)

** Example 'DDAEX2': DEFINE DATA (array definition/initialization)      
************************************************************************
DEFINE DATA LOCAL                                                       
1 #VAR1 (A1/1:2,1:2) INIT (1,V)   <'A','B'>                             
1 #VAR2 (N5/1:2,1:3) INIT (1,2)   <200>                                 
1 #VAR3 (A1/1:4,1:3) INIT (V,2:3) <'W','X','Y','Z'>                     
END-DEFINE
*                                                                       
WRITE NOTITLE '=' #VAR1 (1,1) '=' #VAR1 (1,2)                           
            / '=' #VAR1 (2,1) '=' #VAR1 (2,2)                           
*                                                                       
WRITE     /// '=' #VAR2 (1,1) '=' #VAR2 (1,2)                           
            / '=' #VAR2 (2,1) '=' #VAR2 (2,2)                           
*                                                                       
WRITE     /// '=' #VAR3 (1,1) '=' #VAR3 (1,2) '=' #VAR3 (1,3)           
WRITE       / '=' #VAR3 (2,1) '=' #VAR3 (2,2) '=' #VAR3 (2,3)           
WRITE       / '=' #VAR3 (3,1) '=' #VAR3 (3,2) '=' #VAR3 (3,3)           
WRITE       / '=' #VAR3 (4,1) '=' #VAR3 (4,2) '=' #VAR3 (4,3)           
*                                                                       
END

Output of Program DDAEX2:

#VAR1: A #VAR1: B          
#VAR1:   #VAR1:            


                                                                                 
#VAR2:      0 #VAR2:    200
#VAR2:      0 #VAR2:      0


                                                      
#VAR3:   #VAR3: W #VAR3: W                            

#VAR3:   #VAR3: X #VAR3: X                            

#VAR3:   #VAR3: Y #VAR3: Y                            

#VAR3:   #VAR3: Z #VAR3: Z

Top of page

Example 3 - DEFINE DATA (View Definition, Array Redefinition)

** Example 'DDAEX3': DEFINE DATA (view definition, array redefinition)  
************************************************************************
DEFINE DATA LOCAL                                                       
1 EMPLOY-VIEW VIEW OF EMPLOYEES                                         
  2 NAME                                                                
  2 ADDRESS-LINE (A20/2)                                                
  2 PHONE                                                               
*                                                                       
1 #ARRAY    (A75/1:4)                                                   
1 REDEFINE #ARRAY                                                       
  2 #ALINE  (A25/1:4,1:3)                                               
1 #X        (N2) INIT <1>                                               
1 #Y        (N2) INIT <1>                                               
END-DEFINE
*                                                                       
FORMAT PS=20                                                            
LIMIT 5                                                                 
FIND EMPLOY-VIEW WITH NAME = 'SMITH'                                    
  MOVE NAME            TO #ALINE (#X,#Y)                                
  MOVE ADDRESS-LINE(1) TO #ALINE (#X+1,#Y)
  MOVE ADDRESS-LINE(2) TO #ALINE (#X+2,#Y)
  MOVE PHONE           TO #ALINE (#X+3,#Y)
  IF  #Y = 3                              
    RESET INITIAL #Y                      
    PERFORM PRINT                         
  ELSE                                    
    ADD 1 TO #Y                           
  END-IF                                  
  AT END OF DATA                          
    PERFORM PRINT                         
  END-ENDDATA                             
END-FIND                                  
*                                         
DEFINE SUBROUTINE PRINT                   
  WRITE NOTITLE (AD=OI) #ARRAY(*)         
  RESET #ARRAY(*)                         
  SKIP 1                                  
END-SUBROUTINE
*  
END

Output of Program DDAEX3:

SMITH                    SMITH                    SMITH             
ENGLANDSVEJ 222          3152 SHETLAND ROAD       14100 ESWORTHY RD.
                         MILWAUKEE                MONTERREY         
554349                   877-4563                 994-2260          
                                                                    
SMITH                    SMITH                                      
5 HAWTHORN               13002 NEW ARDEN COUR                       
OAK BROOK                SILVER SPRING                              
150-9351                 639-8963                                  

Top of page

Example 4 - DEFINE DATA (Global, Parameter and Local Data Areas)

** Example 'DDAEX4': DEFINE DATA (global and local data area definition)
************************************************************************
DEFINE DATA                                                             
GLOBAL                                                                  
  USING DDAEX4G                                                         
LOCAL                                                                   
1 #FIELD1 (A10)                                                         
1 #FIELD2 (N5)                                                          
END-DEFINE
*                                                                       
MOVE 'HELLO' TO #FIELD1                                                 
MOVE 123     TO #FIELD2                                                 
*                                                                       
CALLNAT 'DDAEX4N' #FIELD1 #FIELD2                                       
*                                                                       
END

Global Data Area DDAEX4G Used by Program DDAEX4:

1 GLOBAL-FIELD                     A   10                  

Subprogram DDAEX4N Called by Program DDAEX4:

** Example 'DDAEX4N': DEFINE DATA PARAMETER (called by DDAEX4)          
************************************************************************
DEFINE DATA                                                             
PARAMETER                                                               
1 #FIELDA (A10)                                                         
1 #FIELDB (N5)                                                          
END-DEFINE
*                                                                       
WRITE '=' #FIELDA '=' #FIELDB                                           
END                                                                    

Output of Program DDAEX4:

Page      1                                                  05-01-12  08:55:53
                                                                               
#FIELDA: HELLO      #FIELDB:    123                                           

Top of page

Example 5 - DEFINE DATA (Initialization)

** Example 'DDAEX5': DEFINE DATA (initialization)                       
************************************************************************
DEFINE DATA LOCAL                                                       
1 #START-DATE (D)   INIT <*DATX>                                        
1 #UNDERLINE  (A50) INIT FULL LENGTH <'_'>                              
1 #SCALE      (A65) INIT LENGTH 65 <'....+..../'>                       
END-DEFINE
*                                                                       
WRITE NOTITLE #START-DATE (DF=L)                                        
            / #UNDERLINE                                                
            / #SCALE                                                    
END                                                                    

Output of Program DDAEX5:

2005-01-12                                                       
__________________________________________________               
....+..../....+..../....+..../....+..../....+..../....+..../....+

Top of page

Example 6 - DEFINE DATA (Variable Array)

** Example 'DDAEX6': DEFINE DATA (variable array with (1:V))            
************************************************************************
DEFINE DATA LOCAL                                                       
1 #ARRAY   (A1/1:10)                                                    
1 #MAX-ARR (P3)                                                         
END-DEFINE
*                                                                       
#ARRAY (1) := 'R'                                                       
#ARRAY (2) := 'E'                                                       
#ARRAY (3) := 'D'                                                       
#MAX-ARR   := 4                                                         
*                                                                       
WRITE #ARRAY(*)                                                         
*                                                                       
CALLNAT 'DDAEX6N' #ARRAY(1:4) #MAX-ARR                                  
*                                                                       
WRITE #ARRAY(*)                                                         
*                                                                       
*                                                                       
#MAX-ARR   := 5                       
*                                     
CALLNAT 'DDAEX6N' #ARRAY(1:5) #MAX-ARR
*                                     
WRITE #ARRAY(*)                       
*                                     
END                                  

Subprogram DDAEX6N Called by Program DDAEX6:

** Example 'DDAEX6N': DEFINE DATA (variable array with (1:V))           
************************************************************************
DEFINE DATA                                                             
PARAMETER                                                               
1 #STRING (A1/1:V)                                                      
1 #MAX    (P3)                                                          
END-DEFINE
*                                                                       
IF #MAX = 4                                                             
  MOVE 'B' TO #STRING (1)                                               
  MOVE 'L' TO #STRING (2)                                               
  MOVE 'U' TO #STRING (3)                                               
  MOVE 'E' TO #STRING (4)                                               
END-IF                                                                  
*                                                                       
IF #MAX = 5                                                             
  MOVE 'W' TO #STRING (1)                                               
  MOVE 'H' TO #STRING (2)                                               
  MOVE 'I' TO #STRING (3)                                               
  MOVE 'T' TO #STRING (4)
  MOVE 'E' TO #STRING (5)
END-IF                   
END                     

Output of Program DDAEX4:

Page      1                                                  05-01-12  09:06:43
                                                                               
R E D                                                                          
B L U E                                                                        
W H I T E                                                                     

Top of page