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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SETLL AND READE

Status
Not open for further replies.

rstitzel

MIS
Apr 24, 2002
286
US
I have a order detail file that i'm retrieving records from. I have a klist named speckey and it's made up of three fields Customer Number, Block Number and Order Number. The file itself has four key fields Customer Number, Block Number, Order Number and Product Number.

I use the following code to position the file:
c speckey setll specd

I then use this code to read the records
c speckey reade specd

I loop through the file and retrieve the matched records and write it to a display file. And it works. The only problem I have is that the records come back sorted in ascending key order. I don't want any sorting. I just want it to read the records as they are found in the file.

Does anyone know how to accomplish this?

Thanks in advance for any and all help.
 
I would assume you are reading the PF, and what happens is as you do a setll, and reade,, the machine actually reads the index file, ie. doing it much faster,,, and besides that is the way it will be able to access the information. So when you get an record from the index,, the machine then goes and get the actual data from the file. There 2 separate things that go on, when you retrieve records this way. In other words,,, the data is kept in a file, and then the machine buils an index to the information, ie being able to do a direct retrieval via the record number of the index. An simple illustration would be as follows,,,, key index of 00010, would equal physical record 22 of the file. I hope I have confused everyone very much... hee hee hee hee
 
There might be a way. Your keys for the file, did you define them in a separate logical file, or did you define the PF with key fields?

RedMage1967
IBM Certifed - RPG IV Progammer
 
RedMadge

The keys are defined in the physical file. They are customer number, block number, order number AND product number.

My KLIST (SPECKEY) that I used to READE the file has Customer Number, Block Number and Order Number.

I'm trying to retrieve all the records for a particular order number but I don't want them sorted.

Please advise.

Thanks
 
This would only work if the pf was defined with no keys, and a separate lf defined the key fields.

RedMage1967
IBM Certifed - RPG IV Progammer
 
rstitzel

When you wrote the data to the file, did you write it using the keys?

RedMage1967
IBM Certifed - RPG IV Progammer
 
Define a logical file with the same keys as the physical, but without the Product Number. Use just Customer Number, Block Number, and Order Number in your key list, and change the file to the logical. It should display in the order that the products were entered.


"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
REDMADGE:

I see. No I just added the records without using the keys. I think I'll redefine the file (since I'm still in a test environment) WITHOUT keys and create a logical file with the keys as you described.

Thanks for all your help.



 
rstitzel

try this. Don't change the PF. Create a new LF, using the same keys. But, give it a different record name than that of the PF. Give me some time to write something up and post it here. Got an idead of how to do this.

RedMage1967
IBM Certifed - RPG IV Progammer
 
OK. I'm using the Relative Record Number from the File Information Data Structure to help me out here. This only works if you logical file has a different record name than the physical file.

Code:
FLogical   IF   E           K Disk    InFds(Lf1)
FPhysical  IF   E             Disk
FDisply    CF   E             WorkStn
 //--------------------------------------------------------
D Lf1             Ds
D  RrnLf1               397    400B 0
D                    
D Work            Ds
D  DataRrn                            Inz(*Zeros)   
D                                     Like(RrnLf1) Dim(100)
D  A                             3S 0 Inz(0)
 //--------------------------------------------------------
 /Free               
                          
 // first, get the key information from the screen
                          
                            
 SetLl Keys LogicalR;
 If %Equal(Logical);
   ReadE Keys LogicalR;
   DoW NOt %EoF(Logical);
     A = A + 1; 
     DataRrn(A) = RrnLf1;
   EndDo;         
 EndIf;           
                          
// once you have all the data selected, sort the array
                          
 SortA DataRrn;
 A = 1;             
 DoW DataRrn(A) = 0; // skip all of the cells with nothing in them
   A = A + 1;       
 EndDo;           
 DoW A <= %Elem(DataRrn);
   SetLl DataRrn(A) PhysicalR;
   Read PhysicalR;  
 //  load your output fields here
   A = A + 1;  
 EndDo;

See if that makes sense to you.

RedMage1967
IBM Certifed - RPG IV Progammer
 
RedMage:

It's still going to display the records in that keyed order, regardless of whether you have the product number in the KLIST.

However, if you create a logical without the fourth key, that fourth field should be in RRN order, therefore, it will be displayed in the order it was entered (assuming nobody has done a RGZPFM on the physical).


&quot;When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return.&quot;

--Leonardo da Vinci

 
If you write the the PF without using the keys, it's stored in the pf in RRN order (FIFO). The above code allows you to resort the data back into that order.

RedMage1967
IBM Certifed - RPG IV Progammer
 
RedMage:

Your example will probably work, I was writing my response at the same time you were writing yours, apparently.


&quot;When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return.&quot;

--Leonardo da Vinci

 
flapeyre, no disrespect intended.

my example does work, use it a lot here at work.

:)

RedMage1967
IBM Certifed - RPG IV Progammer
 
RedMadge:

Yes that makes sense. Capture the relative record number in an array and then sort the array. Smart! I hadn't changed my pf yet so I'll create the logical and give your example a whirl. Thank you!!

Robert
 
Like I said, just make sure the logical has a different record name than the physical, otherwise, my trick won't work.

RedMage1967
IBM Certifed - RPG IV Progammer
 
RedMadge:

One question on the sort array piece.

You have the code SORTA DATARRN but then you have a dow that looks like all it does is increment the A variable. Doesn't the SORTA DATARRN do all the sorting of the relative record numbers?

Here's your code from above:
a = 1;
DoW Datarrn(a) = 0;
a = a+1
enddo;

Can you explain what the program is doing here? Or is supposed to be doing here ;-) Thank you.
 
rstitzel

Here's the problem, when you sort the array, it will sort 0 to 9. Since I initialize the array to zeros, any cell that wasn't used, will have a zero in it. The loop moves the index past all of the zeros, so that when you come out of the loop, you're at a valid RRN.

RedMage1967
IBM Certifed - RPG IV Progammer
 
I see. Thank you so much for the explanation. I'm still working on getting this set up so I can test it later.

Thanks again.
 
RedMage1967:

Sorry I was misspelling your &quot;handle&quot;.

I finished setting up the logical file as you instructed and have finished modifying the program with the code you provided. The program compiles but when I run the program I get an &quot;AN ARRAY INDEX IS OUT OF RANGE&quot;. This happens at the point where the new code would be running.

Since you mentioned that you use this &quot;technique&quot; a lot at work I was wondering if you had come across this error before and know what the cause is and of course how to fix it :)

I just wanted to mention that I'm still learning and I REALLY APPRECIATE YOUR ASSISTANCE AND TIPS.

Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top