Version 4.2.6
 —  Statements  —

Beispiele für die Benutzung des DEFINE DATA-Statements

Die folgenden Themen werden behandelt:


Beispiel 1 — DEFINE DATA LOCAL (Direkte Daten-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                                                                    

Ausgabe des Programms DDAEX1:

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

Seitenanfang

Beispiel 2 — DEFINE DATA LOCAL (Array-Definition/Initialisierung)

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

Ausgabe des Programms 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

Seitenanfang

Beispiel 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

Ausgabe des Programms 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                                  

Seitenanfang

Beispiel 4 — DEFINE DATA (Global, Parameter und 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

Vom Programm DDAEX4 benutzte Global Data Area DDAEX4G:

1 GLOBAL-FIELD                     A   10                            

Vom Programm DDAEX4 aufgerufenes Subprogramm DDAEX4N:

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

Ausgabe des Programms DDAEX4:

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

Seitenanfang

Beispiel 5 — DEFINE DATA (Initialisierung)

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

Ausgabe des Programms DDAEX5:

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

Seitenanfang

Beispiel 6 — DEFINE DATA (Variables Array mit (1:V))

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

Vom Programm DDAEX6 aufgerufenes Subprogramm DDAEX6N:

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

Ausgabe des Programms DDAEX4:

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

Seitenanfang