04
Mon, Nov
5 New Articles

Going Native: Local Data Area and Switches

General
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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') 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: