Going Native
by Ernie Malaga
The Local Data Area
System/36 programmers simply love the Local Data Area (LDA). After all, there is no better way to pass information between a procedure and a program, or between two different programs. The Read-Under-Format (RUF) technique can also be used, but it only works for interactive programs and is somewhat more complicated.
The latest news is good news - the LDA is still available in the native environment, so you can keep right on using it as you have been. I find it particularly interesting that the LDA is twice as long in the AS/400 as it was in the S/36: it has 1,024 bytes instead of 512.
Because the LDA is supported, all of those programs you have written (or migrated from the S/36) in the S/36E can be converted to native with ease. Keep in mind that the native environment supports a better way to pass information back and forth: parameters. Parameters are far more flexible and will make your programs run faster, since they are resident in memory, while each LDA operation requires a disk access. For the time being, until you have some time to spare to get acquainted with the new concept, you may prefer to stick with LDA and put the idea of passing parameters on the back burner.
The LDA is a bit more complicated to code in native, but the concepts are the same. In this article we will see how the LDA can be used in CL and RPG/400 programs.
If you are already familiar with the concept of data areas, you may skip this paragraph. In order to understand how the AS/400 supports the LDA, you should know that there is a data area object (*DTAARA) in the AS/400. Basically speaking, a data area is simply an area on disk with an assigned name, where you can store information. You can think of a data area as a file that has one record only.
The native environment treats the LDA the same as any other data area. The LDA data area is named *LDA (a special value, so it has one of those asterisks with which OS/400 seems to be so much in love). 1 illustrates the LDA operations with an example in OCL and its CL equivalent.
The native environment treats the LDA the same as any other data area. The LDA data area is named *LDA (a special value, so it has one of those asterisks with which OS/400 seems to be so much in love). Figure 1 illustrates the LDA operations with an example in OCL and its CL equivalent.
Basically, all LDA operations can be performed with only two commands: Change Data Area (CHGDTAARA) and Retrieve Data Area (RTVDTAARA). The first four examples show how to use CHGDTAARA whenever you need to modify the LDA.
The first example tells you how to clear the entire LDA; the second example shows how to clear it from a given beginning point all the way to the end. It is important for you to notice that the CHGDTAARA command always requires the beginning point and the length, unless *ALL is specified (as in the first example). So the second example instructs the system to change the data area beginning at position 15, for 1010 bytes.
The third example shows how to place literal data into the LDA. Again, we tell the system where to begin (101), how long the string is (five characters), and what value to use ('12345').
The fourth example shows how to place data contained in a variable into the LDA. Because OCL does not support variables, we use positional parameters (?1?). In CL, all parameters have variable names which must begin with an ampersand (&). In this case we are assuming that variable &PARM01 has been declared at the beginning of the CL program as having TYPE(*CHAR) LEN(8); that is, it is a character string eight bytes long. That is the reason why we indicate a length of eight in the CHGDTAARA command.
Next comes an example to show you how to use the information contained in the LDA. We need to run a program which has its name in positions 21 through 26 of the LDA. First, we must run the RTVDTAARA command to retrieve the LDA into variable &PGMNAM ("program name") which must have been declared beforehand as TYPE(*CHAR) LEN(6). When the RTVDTAARA command is executed, it will return the LDA contents into variable &PGMNAM. Following suit, we use the CALL command to execute the program. Notice that here again we reference the &PGMNAM variable.
Our sixth example is a variation of the previous one; the difference is that now the beginning position and the length of the LDA are variables instead of numeric literals. The concepts, however, are the same. First we use the RTVDTAARA command to retrieve the LDA contents into a variable (&FILENAME); then we use this value in the DLTF command.
The last example is pretty contrived. We are copying one portion of the LDA into another, using variables throughout. Once again, we use the RTVDTAARA command to retrieve the contents of the LDA, using variable beginning location and length; then we use the CHGDTAARA command to change the target portion of the LDA. Notice that variable &PARM03 (the length) is used twice, first in RTVDTAARA, then in CHGDTAARA.
In RPG/400, the LDA can be used in two different ways. The first way is to pretend you are still programming in RPG II, which should be good news to you. You simply code "U" in column 18 of the I-specs, and "DS" in columns 19 and 20 of the same I-spec, then list the subfields in continuation I-specs. Sounds familiar, right? Declared this way, the LDA is implicitly read when the program begins and written when the program ends.
The second way is to explicitly declare the LDA as any other data area. This involves the coding shown in 2. To be sure, this method is more involved, but it gives the programmer the flexibility to read and write the LDA at will, as many times as needed during the execution of the program. As a S/36 programmer, you will probably recall using the EXIT SUBR21 operation to read or write the LDA from MRT programs. It required four RLABL operations and it was every bit as complicated as the RPG/400 approach, if not even more so.
The second way is to explicitly declare the LDA as any other data area. This involves the coding shown in Figure 2. To be sure, this method is more involved, but it gives the programmer the flexibility to read and write the LDA at will, as many times as needed during the execution of the program. As a S/36 programmer, you will probably recall using the EXIT SUBR21 operation to read or write the LDA from MRT programs. It required four RLABL operations and it was every bit as complicated as the RPG/400 approach, if not even more so.
User Switches
The local data area and the user switches go hand-in-hand in the mind of most S/36 programmers - that is the reason why we are discussing them together. Again, the good news is that the user switches are still available in the native environment. This time, however, there is no bad news.
Let's begin by stating that RPG/400 treats the user switches exactly like RPG II: they become indicators U1 through U8. The added bonus is that you can also treat them as variables using the *IN notation, such as *INU4, which can have values '0' (off) or '1' (on). That taken care of, we can proceed to study the manipulation of user switches in CL.
There are only two operations you can perform on user switches: set them and test them. In 3 we compare OCL with CL using a side-by-side approach again.
There are only two operations you can perform on user switches: set them and test them. In Figure 3 we compare OCL with CL using a side-by-side approach again.
Our first example shows how to set switches to a given pattern. As you can see, the command you use is Change Job (CHGJOB), parameter SWS (switch settings). The 0's, 1's, and X's are used the same way.
The second example shows how to test a given switch pattern. First we use the Retrieve Job Attributes (RTVJOBA) command to retrieve the switch pattern to a variable (&SWITCHES) which must have been declared as TYPE(*CHAR) LEN(8) at the beginning of the CL program. Then we use the IF command to determine if &SWITCHES equals '11000111'.
Next there is an example to show how to test a single switch, instead of all of them at once. As in the previous example, first we run RTVJOBA. Since &SWITCHES is a character string, we can use the %SST (substring) function to extract any portion of it. We take advantage of this to extract the fourth byte with %SST(&SWITCHES 4 1), which is compared to '1'.
The last example shows how to test only two switches, disregarding the other six. We proceed as in the previous example; the difference is that this time the IF condition is more complicated, as we need to compare two individual switches and combine the results with an *AND operation.
What's Ahead
With that much established about local data area and user switches, you can look forward to next month's "Going Native," in which I will discuss how S/36E messages can be translated to AS/400 native.
Going Native: Local Data Area and Switches
Figure 1 CL equivalents of LDA operations
Figure 1: CL Equivalents of LDA Operations OCL Code CL Equivalent ---------------------------------------------------------------------- // LOCAL BLANK-*ALL CHGDTAARA DTAARA(*LDA *ALL) + VALUE(' ') // LOCAL OFFSET-15,+ CHGDTAARA DTAARA(*LDA (15 1010)) + BLANK-*ALL VALUE(' ') // LOCAL OFFSET-101,+ CHGDTAARA DTAARA(*LDA (101 5)) + DATA-'12345' VALUE('12345') // LOCAL OFFSET-101,+ CHGDTAARA DTAARA(*LDA (101 8)) + DATA-'?1?' VALUE(&PARM01) // LOAD ?L'21,6'? RTVDTAARA DTAARA(*LDA (21 6)) + // FILE NAME-... RTNVAR(&PGMNAM) // RUN CALL PGM(&PGMNAM) // DELETE ?L'?1?,?2?'?,F1 RTVDTAARA DTAARA(*LDA + (&PARM01 &PARM02)) + RTNVAR(&FILENAME) DLTF FILE(&FILENAME) // LOCAL OFFSET-?1?,+ RTVDTAARA DTAARA(*LDA + DATA-'?L'?2?,?3?'?' (&PARM02 &PARM03)) + RTNVAR(&DATA) CHGDTAARA DTAARA(*LDA + (&PARM01 &PARM03)) + VALUE(&DATA)
Going Native: Local Data Area and Switches
Figure 2 Using the LDA in RPG/400
Figure 2: Using the LDA in RPG/400 ....1.... ....2.... ....3.... ....4.... ....5.... ....6.... ....7.... ILDA DS I 1 4 FIELD1 I 5 8 FIELD2 I (etc.) * * Assigns name "LDA" to the local data area C *NAMVAR DEFN *LDA LDA * * Reads the local data area C *LOCK IN LDA * * Writes the local data area C OUT LDA ....1.... ....2.... ....3.... ....4.... ....5.... ....6.... ....7....
Going Native: Local Data Area and Switches
Figure 3 CL equivalents of SWITCH operations
Figure 3: CL Equivalents of SWITCH Operations OCL CL ---------------------------------------------------------------------- // SWITCH 00X11101 CHGJOB SWS(00X11101) // IF SWITCH-11000111 RTVJOBA SWS(&SWITCHES) IF COND(&SWITCHES *EQ '11000111') // IF SWITCH4-1 RTVJOBA SWS(&SWITCHES) IF COND(%SST(&SWITCHES 4 1) *EQ '1') // IF SWITCH-XXX11XXX RTVJOBA SWS(&SWITCHES) IF COND(%SST(&SWITCHES 4 1) *EQ '1' + *AND %SST(&SWITCHES 5 1) *EQ '1')
LATEST COMMENTS
MC Press Online