Define an externally-described data structure using the LIKEREC keyword in RPG AS400

Define an externally-described data structure using the LIKEREC keyword in RPG AS400
Define an externally-described data structure using the LIKEREC keyword in RPG AS400, data struture, ds, externally described data structure, likerec keyword in rpgle, external ds using LIKEREC, Introduction, create, make, about
Define an externally-described data structure using the LIKEREC keyword in RPG AS400

Using the LIKEREC keyword to define the data structure

LIKEREC keyword is used to define data structure, its subfield, prototype parameter like a record, prototype return value.

LIKEREC has two paramters.

LIKEREC(RecordFormatName:extracttype)

The first parameter accepts the Record format name. The second parameter is optional and can have the following values.

  • *INPUT - All Input capable fields only
  • *OUTPUT - All Output capable fields only
  • *ALL - All fields in the external records
  • *KEY - The Key fields in the order they defined in K specs in the DDS
  • A data structure defined using the LIKEREC keyword is a QUALIFIED data structure. Subfields can also be declared using the LIKEREC keyword which in itself becomes data structure.

    Coding an externally-described data structure using the LIKEREC keyword

    RPG Code in Fixed format for Externally Described Data Structure using LIKEREC keyword.
                                
         FRPGLE14PF IF   E             DISK                                  
         D ds1             DS                  LIKEREC(Rcdfmt14:*ALL)        
         C                   EVAL      ds1.IDN = 2                           
         C     ds1.IDN       DSPLY                                           
         C                   EVAL      ds1.Name = 'DUMMY'                    
         C     ds1.Name      DSPLY                                           
         C                   EVAL      ds1.Addr1 = 'Address1'                
         C     ds1.Addr1     DSPLY                                           
         C                   EVAL      ds1.Addr2 = 'Address2'                
         C     ds1.Addr2     DSPLY                                           
         C                   SETON                                        LR 
         C                   RETURN                                                                   
    
    RPG Code in /Free format for Externally Described Data Structure using LIKEREC keyword.
         FRPGLE14PF IF   E             DISK                               
         D ds1             DS                  LIKEREC(Rcdfmt14:*ALL)     
          /Free                                                           
               ds1.IDN = 2;                                               
               dsply ds1.IDN;                                             
               ds1.Name = 'DUMMY';                                        
               dsply ds1.Name;                                            
               ds1.Addr1 = 'Address1';                                    
               dsply ds1.Addr1;                                           
               ds1.Addr2 = 'Address2';                                    
               dsply ds1.Addr2;                                           
               *inlr = *on;                                               
               return;                                                    
          /End-Free                                                                                                                                                                                                               
    
    RPG Code in fully Free format for Externally Described Data Structure using LIKEREC keyword.
    **FREE                                  
    dcl-f RPGLE14PF disk usage(*input);     
    DCL-DS ds1 LIKEREC(Rcdfmt14:*All);      
    ds1.IDN = 2;                            
    dsply ds1.IDN;                          
    ds1.Name = 'DUMMY';                     
    dsply ds1.Name;                         
    ds1.Addr1 = 'Address1';                 
    dsply ds1.Addr1;                        
    ds1.Addr2 = 'Address2';                 
    dsply ds1.Addr2;                        
    *inlr = *on;                            
    return;                                                                               
    
  • Using the LIKEREC keyword to define the data structure will require to define the file as well for the field definitions for the external ds.
  • Output

    DSPLY   2         
    DSPLY  DUMMY      
    DSPLY  Address1   
    DSPLY  Address2   

    Related Post

    Post a Comment

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