Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pointers to pull multiple fields into one.

Status
Not open for further replies.

Fooch

Programmer
Dec 19, 2005
63
0
0
US
Is there an easy way to do this, I have an SQL table set up like the folowing:

Create Table TRM003R (

"File Name" for Column "FILE" CHAR(10) Not NULL,
"File Library" for Column LIBRARY CHAR(10) Not NULL,
"Machine 1" for Column MACHINE1 CHAR(8) Not NULL,
"Machine 2" for Column MACHINE2 CHAR(8) Not NULL,
"Machine 3" for Column MACHINE3 CHAR(8) Not NULL,
"Machine 4" for Column MACHINE4 CHAR(8) Not NULL,
"Machine 5" for Column MACHINE5 CHAR(8) Not NULL,
"Machine 6" for Column MACHINE6 CHAR(8) Not NULL,
"Machine 7" for Column MACHINE7 CHAR(8) Not NULL,
"Machine 8" for Column MACHINE8 CHAR(8) Not NULL,
"Machine 9" for Column MACHINE9 CHAR(8) Not NULL,
... etc.

Up to 20 Machines(AS/400s). This is a list of machines that I need to connect to to update a file.

Now what I want to do is pull all 20 of those fields into one field in the RPG. I want to pull it straight into an array so that I can loop through the machines and connect to them. I tried a pointer:

D MachinesPtr S *
*
D Machines S 160 BASED(MachinesPtr)
*
/Free


MachinesPtr = %ADDR(Machine1);

Read TRM003F;

*InLR = *On;
Return;

/End-Free

but all I pull is the first field. Is there anyway to pull this into a single field/array without having to do:

array(1) = machine1;
array(2) = machien2;
array(3) = machine3;
etc.?

I keep thinking there is some easy way to do this but for some reason I am drawing a blank. If I can't do it I am going to make a 160 char field in the file and just count out spaces when populating that field...but that would be a pain for other users in future maintenance.
 
Do so

Code:
D dsTRM003R       DS                  likerec([i]FormatName[/i])  
D MyRcd           DS                                
D  fld1                         10a                 
D  fld2                         10a               
D  Machine_Ary                   8a 0 dim(20)       
                                                    
 /free                                              
    Read Format dsTRM003R; // read into  dsTRM003R                            
    MyRcd = dsTRM003R;

After execution of this last stm, the 20 machines are in the Machine_Ary field
 
That is a lot of lines of code. 2 DS lines, 21 linse under the second DS, and then the move into the DS. I was looking for something more like MoveA Field(based on a Pointer) to Machine_ary kind of thing in free. 1 or 2 lines. can you think of anything smiilar?
 
A lot of lines of code ??? Where are the 21 lines you're talking about ?
Why would you want to use a pointer at any price ?
Here's the previous somewhat made simpler.
Code:
D dsTRM003R       DS                  likerec(FormatNm)  
D MyRcd           DS                                
D                               20a                 
D  Machine_Ary                   8a 0 dim(20)       
                                                    
 /free                                              
    Read FormatNm dsTRM003R; // read into dsTRM003R                            
    MyRcd = dsTRM003R;
Machine_Ary(1) holds the MACHINE1 field
Machine_Ary(2) holds the MACHINE2 field
etc.

Now you can loop through the Machine_Ary array and connect to the machines.
 
You could alternatively use a pointer as below and get just 2 lines of code. However I don't think that it is feasible with only one data storage.

Code:
D MachinesPtr     s               *
D dsTRM003R       DS                  likerec(FormatNm)  
D MyRcd           DS                  based(MachinesPtr)              
D                               20a                 
D  Machine_Ary                   8a 0 dim(20)       
                                                    
 /free                                              
    Read FormatNm dsTRM003R; // read into dsTRM003R 
    MachinesPtr = %addr(dsTRM003R);
Machine_Ary(1) holds the MACHINE1 field, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top