Last active
December 20, 2019 22:36
-
-
Save jbratu/714c1ff26900354962c350d5e441b3a6 to your computer and use it in GitHub Desktop.
Simple subroutine to select a table, read each record, and write it back. It contains a Gosub branch where you can put code to modify the record before it is written back to the database.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Subroutine CS_SNIP_ReadNext_ReadWrite(TABLE_NAME, SAVED_LIST_NAME) | |
| declare function Set_FSError | |
| Declare Subroutine Set_Status, Rlist | |
| err = '' | |
| $Insert Logical | |
| open TABLE_NAME To TABLE else | |
| status = Set_FSError() | |
| return | |
| end | |
| If Unassigned(SAVED_LIST_NAME) Then | |
| SAVED_LIST_NAME = '' | |
| End | |
| If SAVED_LIST_NAME EQ '' Then | |
| *Use an active select instead of a latent select when the table is likely to be | |
| *in use by other users or possible changing. | |
| Set_Status(0) | |
| Rlist("SELECT " : TABLE_NAME : " WITH @ID NE ''",5,"","","") | |
| If Get_Status(err) Then Debug | |
| End Else | |
| Call Activate_Save_Select(SAVED_LIST_NAME) | |
| If Get_Status(err) Then | |
| Debug | |
| End | |
| End | |
| debug | |
| Done = False$ | |
| Loop | |
| ReadNext @ID else Done = True$ | |
| Until Done Do | |
| read @RECORD From TABLE, @ID Then | |
| Gosub processRecord | |
| Write @RECORD To TABLE, @ID Else | |
| status = Set_FSError() | |
| return | |
| End | |
| End Else | |
| status = Set_FSError() | |
| return | |
| End | |
| Repeat | |
| return | |
| * | |
| * End Main | |
| * | |
| processRecord: | |
| //Add your processing to @RECORD here | |
| return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment