DO loop through field names ending in a numeric

CompTech810 used Ask the Experts™
Hello Experts,

I have a RPGLE question concerning looping though field names instead of having multiple routines with each field name.

Exp.   I have field names FIELD1, FIELD2, FIELD3, etc.   I know in the past(I've been away from AS/400 for years) I would use a DOU loop something like this.

DOU I = 10
FIELD,I      CHAIN    FILE       99

How do I do that in RPGLE?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Phillip KnoxSenior Systems Analyst

In free form or RPGIV?
Phillip KnoxSenior Systems Analyst

In your example, it looks like you're chaining with an array element?
Theo KouwenhovenApplication Consultant

Define the field1, field2, field3 etc in a Datastructure and do an overlay with an array
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.


RPGLE.   In the example it should, from what I remember, it places the number at the end of FIELD, so if it is in it's first loop the field name would be FIELD1, then next loop FIELD2, etc.   I wish I had that old code I did.   I'm thinking Murphey is close to what I did, this was in RPGIV a long time ago.
Application Consultant
Oke CompTech810

Here is some code in good old RPG :-)
D FieldsDs        Ds                                       
D Field01                       10A                        
D Field02                             Like(Field01)        
D Field03                             Like(Field01)        
D Field04                             Like(Field01)        
D Field05                             Like(Field01)        
D Field06                             Like(Field01)        
D Field07                             Like(Field01)        
D Field08                             Like(Field01)        
D Field09                             Like(Field01)        
D Field10                             Like(Field01)        
D Field                               Like(Field01) Dim(10)
D                                     Overlay(FieldDs)

Open in new window

Or if you like in fullfree, it must be look like this:
Dcl-Ds FieldDs;                                    
     Field01 Char(10);                               
     Field02 Like(Field01);                          
     Field03 Like(Field01);                          
     Field04 Like(Field01);                          
     Field05 Like(Field01);                          
     Field06 Like(Field01);                          
     Field07 Like(Field01);                          
     Field08 Like(Field01);                          
     Field09 Like(Field01);                          
     Field10 Like(Field01);                          
     Field   Like(Field01)    

Open in new window


Thanks!  I really thought there was an easier solution that I did in the past.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial