How to use RBASIC SELECT into cursor ? (AREV Specific)
At 13 OCT 2000 04:47:35PM Larry Sweet wrote:
I am trying to do something very simple but AREV is not my primary language, so please bear with me. I want to select a list of records, then loop through the list and print a MERGE form to a file for each one. I need to loop through the list so I can name each file with the key from each record. Problem is when I execute the MERGE statement, the SAVELIST is lost. If I do another GETLIST, I am back at the 1st record. I am using the TCL SELECT and
SAVELIST/GETLIST to make the list. I have tried but not had any luck with the RBASIC "SELECT BY sortfield SETTING cursor" examples as shown in the RBASIC manual. The code snippets in the manual do not work for me. I am using AREV 3.1. Could somebody be so kind as to send me a code snippet that would accomplish the following:
SELECT table WITH select_criteria
LOOP through the records
READ @ID each recordrecordkey=@IDPDISK recordkey.txtMERGE mergeform recordkeyPDISK PRNREPEAT
END THE LOOP
Thanks in advance
At 14 OCT 2000 12:39AM Curt Putnam wrote:
One way to do it is to do a SAVELIST after the select - and then read the list records yourself. Just remember the little funny about List record IDs.
Record 1 is: LISTNAME
Record 2 is: LISTNAME*2
Record 3 is: LISTNAME*3
Your loop ends when you fail to read a LISTNAME*n
At 14 OCT 2000 04:09AM Cameron Christie wrote:
Curt's suggestion is probably the most efficient, but the loop control logic can get a little ugly. You might try using a couple of system subroutines to store the list as you go through your existing loop, minimising the programming effort!
Perform "SELECT rows" (Or GETLIST name…)
Done=False$
Loop Until Done
Readnext Id Else Done=True$Until Done
Call Push.Select(A,B,C,D)Execute 'MERGE MergeName Id' (or whatever...)Call Pop.Select(A,B,C,D)Repeat
At 14 OCT 2000 07:01AM Bill Titus wrote:
Replace every instance of PERFORM (which passes your list of active keys along to the called subroutine or process) with EXECUTE (which does not) and your code should run fine.
At 16 OCT 2000 11:09AM Don Miller - C3 Inc. wrote:
The reason that your program is failing is that when you do subsequent performs after the first, the select list is exhausted. So:
PERFORM "SELECT YOURFILE WITH WHATEVER CRITERIA YOU NEED"
IF @RECCOUNT < 1 then .. error in select .. no records vound
* you can do a SAVELIST, but it's not really necessary unless you
* need to reprocess, but we'll do it for drill
PERFORM "SAVLIST MYLIST" ;* this saves it for later
PERFORM "GETLIST MYLIST" ;* and this gets it back
* OPEN YOUR DATA FILES HERE …
* wamt to use OPEN DICT.YOURFILE TO @DICT for dictionary calls
OPEN "YOURFILE" TO FILE_IN ELSE …
OPEN "DICT.YOURFILE" TO @DICT ELSE …
L0:
READNEXT @ID THEN
READ @RECORD FROM FILE_IN,@ID THENEXECUTE "PDISK <YOURKEY" PRN (S) ;* DON'T USE A PERFORM
DO YOUR PRINT THINGIE …EXECUTE "PDISK PRN (S)" ;* DON'T USE A PERFORM
NOW, DON'T EAT THE SELECT LISTEXECUTE "MERGE STUFF" ;* DON'T USE A PERFORM
GO TO THE TOP OF THE LOOOP HERE IF YOU WANT TO ABORT ON READSGOTO L0END ELSE
ERROR PROCESSING AND ABORT RUN ON I/O ERRORSTOPEND
OPTIONALLY YOU CAN PUT YOUR GOTO HERE TO CONTINUE
DON'T PUT THE STOP ABOVEGOTO L0:END ELSE
END OF JOB LOGICSTOPEND
That's about it. Remember that a PERFORM statement will pass the current select list to the next process with the current key popped off. If the next process can do a READNEXT it will continue and exhaust the list - MERGE will do this. If it can't then the select list will just be exhausted. Therefor PDISK will clear the current select list.
Don Miller
C3 Inc.
At 16 OCT 2000 11:56AM Michael Slack wrote:
As alluded to in other responses you can do one of two things. First and probably the easiest is to store your keys from the Select statement into a dynamic array by using a small LOOP/REPEAT statement. Second would be to use the PUSH and POP statements to store your active select list while you do another Perform statment, once you are done with that Perform statmen you can bring your acitve select list back.
I hope this helps.
Michael Slack
At 16 OCT 2000 03:39PM Larry Sweet wrote:
Thanks guys. I ended up replacing the PERFORM with EXECUTE and got it to work, as the simplest thing to do.