Using a Data Structure to group fields in RPG AS400

Using a Data Structure to group fields in RPG AS400
Using a Data Structure to group fields in RPG AS400, data structure , data structure to group fields, introduction,as400
Using a Data Structure to group fields in RPG AS400

In this example, we will see how the data structure is used to group fields. All the subfields groupd to form single DS field DS1.

Coding RPG Data Structure to group fields in Fixed, Free and Fully Free format

RPG Code in Fixed format for Using a Data Structure to group the fields
     D DS1             DS                              
     D  subfld1                       2P 0             
     D  subfld2                       2A               
     D  subfld3                       3S 0             
     D  subfld4                       5A                                    
     C                   EVAL      subfld1 = 20                         
     C                   EVAL      subfld2 = 'AB'                           
     C                   EVAL      subfld3 = 200                         
     C                   EVAL      subfld4 = 'HELLO'                                                   
     C     subfld1       DSPLY                                               
     C     subfld2       DSPLY                                               
     C     subfld3       DSPLY                                               
     C     subfld4       DSPLY                                                                    
     C                   SETON                                        LR                                 
RPG Code in /Free format for Using a Data Structure to group the fields
     D DS1             DS                              
     D  subfld1                       2P 0             
     D  subfld2                       2A               
     D  subfld3                       3S 0             
     D  subfld4                       5A               
      /Free                                            
           subfld1  = 20 ;                             
           subfld2  = 'AB';                            
           subfld3  = 200;                             
           subfld4  = 'HELLO';                         
           DSPLY subfld1;                              
           DSPLY subfld2;                              
           DSPLY subfld3;                              
           DSPLY subfld4;                              
           *INLR  = *ON;                               
      /End-Free                                                                                                                                              
RPG Code in fully Free format for Using a Data Structure to group the fields
**FREE                         
 DCL-DS DS1;                   
   subfld1 packed(2:0);     
   subfld2 char(2);     
   subfld3 zoned(3:0);     
   subfld4 char(5);         
 END-DS;                       
           subfld1  = 20 ;                             
           subfld2  = 'AB';                            
           subfld3  = 200;                             
           subfld4  = 'HELLO';                         
           DSPLY subfld1;                              
           DSPLY subfld2;                              
           DSPLY subfld3;                              
           DSPLY subfld4;                              
           *INLR  = *ON;                                 

Output

DSPLY  20   
DSPLY  AB   
DSPLY  200  
DSPLY  HELLO

Related Post

Post a Comment

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