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

Fixed, /Free and Fully Free RPG


Using a Data Structure to subdivide the field in RPG AS400

Using a Data Structure to subdivide the field in RPG AS400
Using a Data Structure to subdivide the field in RPG AS400,brea fields using data structure, data structure, ds,as400,introduction
Using a Data Structure to subdivide the field in RPG AS400

In this example, Data structure is being used to break fields into several subfields as below. Field SUBFLD1 break into subfields SUBFLD2, SUBFLD3 and SUBFLD4.

Coding RPG Data Structure to subdivide the field in Fixed, Free, and Fully Free format

RPG Code in Fixed format for Using a Data Structure to subdivide the field
     D DS1             DS                                                    
     D  subfld1                1      5                                      
     D  subfld2                1      2                                      
     D  subfld3                3      4                                      
     D  subfld4                5      5                                      
     D  subfld5                6      8                                      
     C                   EVAL      subfld1 = 'ABCDE'                         
     C                   EVAL      subfld5 = 'FGH'                           
     C     subfld1       DSPLY                                               
     C     subfld2       DSPLY                                               
     C     subfld3       DSPLY                                               
     C     subfld4       DSPLY                                               
     C     subfld5       DSPLY                                               
     C                   SETON                                        LR                                 
RPG Code in /Free format for Using a Data Structure to subdivide the field
     D DS1             DS                              
     D  subfld1                1      5                
     D  subfld2                1      2                
     D  subfld3                3      4                
     D  subfld4                5      5                
     D  subfld5                6      8                
      /Free                                            
           subfld1  = 'ABCDE';                         
           subfld5  = 'FGH';                           
           DSPLY subfld1;                              
           DSPLY subfld2;                              
           DSPLY subfld3;                              
           DSPLY subfld4;                              
           DSPLY subfld5;                              
           *INLR  = *ON;                               
      /End-Free                                                                                                         
RPG Code in fully Free format for Using a Data Structure to subdivide the field
**FREE                         
 DCL-DS DS1;                   
   subfld1 char(5) pos(1);     
   subfld2 char(2) pos(1);     
   subfld3 char(2) pos(3);     
   subfld4 char(1) pos(5);     
   subfld5 char(3) pos(6);     
 END-DS;                       
           subfld1  = 'ABCDE'; 
           subfld5  = 'FGH';   
           DSPLY subfld1;      
           DSPLY subfld2;      
           DSPLY subfld3;      
           DSPLY subfld4;      
           DSPLY subfld5;      
           *INLR  = *ON;                              

Output

DSPLY  ABCDE
DSPLY  AB   
DSPLY  CD   
DSPLY  E    
DSPLY  FGH  

Related Post

Post a Comment

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