|
User spaces are extremely high speed data objects. The data in them is just data. Unlike a data base file, it has no format, just data in the format you wrote it out in. Before RPG IV, user spaces were used for really used for only one thing by RPG programmers. If you use the system API's, the AS/400 writes the output to a user space. You then had to call special API's to retrieve the data and it was a pain. If you were working with system API's, you no choose but other than that, people didn't use them for much. With RPG IV, everything has changed. You just define a data structure based on a pointer and then call a system API to get a pointer to the user space. Instantly, your local storage becomes the same as the disk storage because of the AS/400 virtual memory manager. You can then just walk through the user space using an occurs statement or by doing pointer arithmetic. I am using them all over the place where I need temporary storage or even for permanent storage in one application. They can be used anyplace and can even be searched using the 'bsearch' (binary search) api and all at blistering speed. Here is an example: d ptrPackStruc s like(stdptr) d dsPackStruc ds occurs(150) d based(ptrPackStruc) d sfQuantity 9 3 d sfUnit 5a d sfWeight 11 5 This just declares a data structure and says that it can have up to 32767 entries. Important thing to realize here is that no storage is actually allocated. This is just a template. The code below just shows how the program maps the user space to the data structure. Please note that I am using functions in a service program to encapsulate the user space functions. That way, any complexity is hidden and the programmer does need to know how the functions work. * set pointer to userspace... c if ptrPackStruc = *null c eval ehResult = GetPtrToUsrSpc( c 'PFACOMSPC':'QTEMP':ptrPackStruc) c endif Next you just want to use the user space. * If no errors, do the following updates: c if wfError = No * Increment number of records... c eval OutNoRecs = OutNoRecs + 1 * Sum quantities... c if B_UNIT <> 'EA' c eval ehResult = GetEachQty(O_Product : c B_UNIT : c B_QUANTITY: c wfQuantity) c else c eval wfQuantity = B_QUANTITY c endif c eval SumEaQty = SumEaQty + wfQuantity * Update user space... c OutNoRecs occur dsPackStruc c eval sfQuantity = B_QUANTITY c eval sfWeight = B_WEIGHT * Otherwise, there was an error and we need to re-display... c else c leave c endif c endif c readc RD01_01S c enddo This technique can be used for anytime you need a fast temporary storage. I just love RPG ILE! There are a bunch of other ways to map the user spaces but to much to talk about here. Hope this makes some sense. -----Original Message----- From: Silvio.Santos@brainag.com [mailto:Silvio.Santos@brainag.com] Sent: Friday, October 01, 1999 1:23 PM To: RPG400-L@midrange.com Subject: What is a user space ? What is a user space and when it is used ? TIA, Silvio. +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +--- +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.