Now, Get RPG Codes in all three formats only on this website on every RPGLE related programming article.

Fixed, /Free and Fully Free RPG


Externally Described Data Structure in RPG AS400

Externally Described Data Structure in RPG AS400
Externally Described Data Structure in RPG AS400, data structure, EXTNAME, EXTFLD, introduction, create, make, about, what,as400
Externally Described Data Structure in RPG AS400

Introduction to Externally Described Data Structure

An Externally Described Data Structure is identified by the EXT or EXTNAME keyword for a fully free definition or by an E in position 22 of a fixed format definition.

You can also define the Externally described data structure using the LIKEREC keyword.

Create an Externally described physical file

Let's first create a physical file(PF) named RPGLE14PF whose DDS structure is as follows.

     A          R RCDFMT14              
     A            IDN            2P 0   
     A            NAME          20A     
     A            ADDR1         50A     
     A            ADDR2         50A     

Create the Physical file object using the command CRTPF command or option 14 on the RPGLE14PF source member of type PF.

Coding Externally Described Data Structure in RPG Fixed, Free and Fully Free format

Example1: Using EXTNAME to code Externally Described DS in RPG

In this example, the Externally described data structure DS1 is defined on a file named RPGLE14PF using EXTNAME keyword. After this, All the fields from file RPGLE14PF can be referred to in the data structure DS1.

RPG Code in Fixed format for Externally Described Data Structure
                            
     D ds1           E DS                  EXTNAME(rpgle14pf:Rcdfmt14)                         
     C                   EVAL      IDN = 2                               
     C                   EVAL      Name = 'DUMMY'                        
     C                   EVAL      Addr1 = 'Address1'                    
     C                   EVAL      Addr2 = 'Address2'                                                              
     C                   SETON                                        LR   
     C                   RETURN                                                                           
RPG Code in /Free format for Externally Described Data Structure
                    
    D ds1           E DS                  EXTNAME(rpgle14pf:Rcdfmt14)             
     /Free                                                           
          IDN = 2;                                                 
          Name = 'DUMMY';                                          
          Addr1 = 'Address1';                                      
          Addr2 = 'Address2';                                      
          *inlr = *on;                                               
          return;                                                    
     /End-Free                                                                                                                                                             
RPG Code in fully Free format for Externally Described Data Structure
**FREE                                 
 DCL-DS DS1 EXTNAME('RPGLE14PF') ;     
 END-DS;                               
           IDN = 2;                    
           Name = 'DUMMY';             
           Addr1 = 'Address1';         
           Addr2 = 'Address2';         
           *inlr = *on;                
           return;                                               

Program Output

 > EVAL DS1                                                            
   IDN OF DS1 = 02.                                                    
   NAME OF DS1 = 'DUMMY               '                                
   ADDR1 OF DS1 = 'Address1                                          ' 
   ADDR2 OF DS1 = 'Address2                                          ' 

Example2: Using EXTFLD to code Externally Described DS in RPG

In this example, the Externally described data structure DS1 is defined on a file named RPGLE14PF using the EXTNAME keyword, and individual file fields are renamed using the EXTFLD keyword.

Using EXTFLD to code Externally Described DS in RPG

Related Post

Post a Comment

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