|
||||
|
|
||||
|
MODIFY: Old Dog, New Trick
Don’t you just wish you could use some of the features from a new release in your current release? Well, we have just the thing for you the MODIFY SPA procedure. Many times we need to gather and store information in separate areas based on different selection criteria. The process of storing this information was thought to be impossible in MODIFY since it does not support stacks. Or does it? We have developed a way of doing just that by using MODIFY SPA to simulate MAINTAIN stacks. Look at Figure 1 for the complete code for the MODIFY. First, let’s discuss the definitions of MAINTAIN and MODIFY: MAINTAIN provides the power of set-based processing, enabling you to read, manipulate, and write groups of records at a time. You manipulate these sets of data using a data structure called a database stack, which is a simple temporary table. Columns in a database stack generally correspond to data source fields, and rows correspond to records, or path instances, in that data source. The database stack itself represents a data source path. MAINTAIN allows users to set up and identify multiple stacks. MODIFY SPA allows for multiple-record processing, which enables you to process multiple segment instances at one time. Each time the request retrieves an instance, it stores the instance values in a work area in memory called the Scratch Pad Area (SPA). The request continues to retrieve instances until it reaches a specified number. After the request has retrieved and stored the instances, the user can read the instance values from the SPA and process them. This is commonly accomplished by using FIDEL to display them all on one screen. The user can update these values and transmit the updated values back to the data source or SPA. Basically the difference between MODIFY and MAINTAIN is that in MODIFY only one stack is available. How can we make the best use of it? Let's look at the sample MODIFY in Figure 1 using a version of the CAR file. (Notice that only two keys are generated.) This stores all the cars for a country in the SPA. If you put your cursor on a particular BODYTYPE and press PF5, it looks up all cars of the same BODYTYPE and stores them after the last HELD CAR later in the SPA. Pressing PF5 again takes you back to the original screen.
Figure 1: MODIFY SPA FOCEXEC for simulating MAINTAIN stacks
In CASE GETINITIAL, we establish the size of the SPA by doing a REPEAT 100. This reserves enough space for 100 entries. After selecting England as the country, we perform a NEXT through the CAR segment and HOLD COUNTRY and the entire CAR segment, the contents of the SPA then appear as shown in Figure 2 below.
Figure 2: All records with BODYTYPE=SEDAN collected
The value of HOLDCOUNT is 4 and HOLDINDEX is 5. We save the value of HOLDCOUNT as MAX_HELD (4) so that we can determine where we want to place more data later in the code.
When we select SEDAN from the second screen, we need to ensure the correct position in the SPA. We accomplish this by changing the value of HOLDINDEX to the next available line in the SPA. This is necessary because the default value of HOLDINDEX is 1 and will overwrite the previously stored values.
Since HOLDCOUNT was 4 and MAX_HELD is 4, we can set HOLDINDEX to MAX_HELD +1 (5) and position HOLDINDEX to the next available SPA line. The selection of all records having a BODYTYPE of SEDAN is collected and placed in the SPA beginning at the OLDINDEX of 5 as shown in Figure 3.
Figure 3: BODYTYPE=SEDAN records inserted in SPA at OLDINDEX 5
As you can see, storing the value of the next available line in the SPA and then setting HOLDINDEX to that value effectively allows you to manage the SPA space. In effect we created two "STACKS" in this case. Looks like this old dog really can learn new tricks. For more on this, visit http://techsupport.ibi.com/app/css_web_tool/default.htm.
|