Using keywords QUALIFIED, LIKEDS, and DIM with data structures

Using keywords QUALIFIED, LIKEDS, and DIM with data structures
Using keywords QUALIFIED, LIKEDS, and DIM with data structures, DIM keyword in rpg, data structure, ds, rpg data structure, qulaified, qualified data structure, likeds, rpg keyword, opcodes
Using keywords QUALIFIED, LIKEDS, and DIM with data structures

Qualified Keyword

The keyword QUALIFIED tells that data structure subfields are referenced using qualified notation. We can access a data structure subfield as a Data structure name followed by a period and the subfield name i.e. DS1.subfield1 if the QUALIFIED keyword is specified for data structure DS1 having subfield subfield1.

  • Definition in Fixed format RPG
  •      D DS1             DS                  QUALIFIED
         D subfld1                        1A
         D subfld2                        1A
    
  • Definition in Fully Free-format RPG
  • **FREE
    dcl-ds ds1 QUALIFIED;
     subfld1 char(1);
     subfld2 char(1);
    end-ds ds1;
    

    The QUALIFIED keyword can be used with subfields too.

    LIKEDS keyword

    The LIKEDS keyword is used to define a data structure, its subfield, prototype return value, and prototyped parameter like another data structure.

  • Definition in Fixed format RPG
  •      D DS1             DS                  QUALIFIED
         D subfld1                        1A
         D subfld2                        1A
          *
         D DS2             DS                  LIKEDS(DS1)
    
  • Definition in Fully Free-format RPG
  • **FREE
    dcl-ds ds1 QUALIFIED;
     subfld1 char(1);
     subfld2 char(1);
    end-ds ds1;
    
    dcl-ds ds2 likeds(ds1);
    

    DIM keyword

    The DIM keyword defines the number of elements in an array, table, prototype parameter, array data structure, prototype return value.

    DIM(numeric)

    The numeric should have zero decimal positions. It can be a literal, named constant, or bif.

    Coding Data structure using keywords QUALIFIED, LIKEDS, and DIM.

    RPG Code in Fixed format for Using keywords QUALIFIED, LIKEDS, and DIM with data structures in RPG AS400
         D DS1             DS                  QUALIFIED                 
         D subfld1                       10                              
         D subfld2                        5                              
         D subfld3                        5                              
                                                                         
         D DS2             DS                  LIKEDS(DS1)               
                                                                         
         D DS3             DS                  QUALIFIED                 
         D subfld1                        5                              
         D subfld2                             LIKEDS(DS2)               
         D                                     DIM(2)                    
                                                                         
         C                   EVAL      DS1.subfld1 = 'DS1_1'             
         C                   EVAL      DS1.subfld2 = 'DS1_2'             
         C                   EVAL      DS1.subfld3 = 'DS1_3'             
         C     DS1           DSPLY                                       
         C                   EVAL      DS2.subfld1 = 'DS2_1'             
         C                   EVAL      DS2.subfld2 = 'DS2_2'             
         C                   EVAL      DS2.subfld3 = 'DS2_3'             
         C     DS2           DSPLY                                            
         C                   EVAL      DS3.subfld1 = 'DS3_1'                  
         C                   EVAL      DS3.subfld2(1) = 'DS3_2'               
         C                   EVAL      DS3.subfld2(2) = 'DS3_3'               
         C     DS3           DSPLY                                            
         C                   SETON                                        LR         
    
    RPG Code in /Free format for Using keywords QUALIFIED, LIKEDS, and DIM with data structures in RPG AS400
         D DS1             DS                  QUALIFIED      
         D subfld1                       10                   
         D subfld2                        5                   
         D subfld3                        5                   
                                                              
         D DS2             DS                  LIKEDS(DS1)    
                                                              
         D DS3             DS                  QUALIFIED      
         D subfld1                        5                   
         D subfld2                             LIKEDS(DS2)    
         D                                     DIM(2)         
          /Free                                               
           DS1.subfld1 = 'DS1_1';                             
           DS1.subfld2 = 'DS1_2';                             
           DS1.subfld3 = 'DS1_3';                             
           DSPLY DS1;                                         
                                                              
           DS2.subfld1 = 'DS2_1';                             
           DS2.subfld2 = 'DS2_2';                             
           DS2.subfld3 = 'DS2_3';      
           DSPLY DS2;                  
                                       
           DS3.subfld1 = 'DS3_1';      
           DS3.subfld2(1) = 'DS3_2';   
           DS3.subfld2(2) = 'DS3_3';   
           DSPLY DS3;                  
                                       
           *INLR = *ON;                
          /End-Free                                                                              
    
    RPG Code in fully Free format for Using keywords QUALIFIED, LIKEDS, and DIM with data structures in RPG AS400
    **FREE                       
    dcl-ds ds1 qualified;        
     subfld1 char(10);           
     subfld2 char(5);            
     subfld3 char(5);            
    end-ds;                      
    dcl-ds ds2 likeds(ds1);      
    dcl-ds ds3 qualified;        
     subfld1 char(5);            
     subfld2 likeds(ds2) DIM(2); 
    end-ds;                      
                                 
    DS1.subfld1 = 'DS1_1';       
    DS1.subfld2 = 'DS1_2';       
    DS1.subfld3 = 'DS1_3';       
    DSPLY DS1;                   
                                 
    DS2.subfld1 = 'DS2_1';       
    DS2.subfld2 = 'DS2_2';       
    DS2.subfld3 = 'DS2_3';        
    DSPLY DS2;                    
                                  
    DS3.subfld1 = 'DS3_1';        
    DS3.subfld2(1) = 'DS3_2';     
    DS3.subfld2(2) = 'DS3_3';     
    DSPLY DS3;                    
                                  
    *INLR = *ON;                                
    
  • Here, In the above code example, DS1 is a Qualified data structure having 3 subfields.
  • DS2 is defined upon DS1 using LIKEDS keyword. Since DS1 is Qualified therefore DS2 would also ve qualified ds.
  • DS3 is a qualified data structure having 2 subfields namely subfld1 and subfld2. Further subfield subfld2 is based upon data structure DS2 and has two number of elements as DIM(2) is used with the DS subfield.
  • Output

    DSPLY  DS1_1     DS1_2DS1_3           
    DSPLY  DS2_1     DS2_2DS2_3           
    DSPLY  DS3_1DS3_2               DS3_3 
    

    Related Post

    Post a Comment

    © AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain