× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.





My experience with data areas is to define a UDS ex. for a 10 alpha data
area:

    D DMARTXDATE     UDS                  DTAARA
    D  ODREVDT                      10A

You're mixing two different techniques! There are two completely separate ways to read a data area in RPG, and although it's possible to combine them, it's not necessary to.

Here are the two ways:

a) Using the old style "UDS" data area.  When you put a U in front of the
letters "DS", the data area will automatically be read & locked when your program starts, and written back to disk/unlocked when the program ends.

It's not necessary to use the DTAARA keyword with a UDS data area.

UDS data areas must be created as TYPE(*CHAR)

b) a DTAARA (or *DTAARA DEFINE) data area. This is just a variable -- any variable -- defined with the DTAARA keyword. You can then read this data area with the IN and OUT op-codes. You control when the data area is read and/or written using these op-codes.

In this case, you can put the DTAARA keyword in a data structure if you want many subfields in the data area (in which case, it again has to be TYPE(*CHAR)) or you can put it on a standalone field def in a D-spec, in which case it can be numeric as well.

In any case DTAARA keyword can be given a data area name as a parameter so the data area name does not have to match the variable name.

If the DTAARA keyword is given a parameter that starts with *VAR, then the name can be a variable (which is what you want) and it can be calculated anytime before the data area is read.

--

In your example, you've used UDS and DTAARA on the same definition, so it'll be automatically read when your program starts, but you can still use IN and OUT with it... I guess you could call that the "best of both worlds" but frankly, it seems to confuse more people than anything else.

The problem with the new program is that the data area won't be in the
library list at runtime.  I need to resolve the library name at runtime,
then retrieve the contents of the data area, and proceed based on these
contents.

The problem with using UDS in your current scenario is that you don't WANT the data area to be read as the program starts, because you want to be able to calculate the filename first. No big problem... just don't use UDS. Use DTAARA with *VAR, and calculate the name prior to using the IN op-code.

I don't want to make a CL/RPG pair.  I looked at the QWCRDTAA
API, but I wonder if this is really necessary for this task.  Can I
accomplish the task without using this API?

Rest assured that this can be done very easily in RPG, and without resorting to an additional CL program or a nasty API.

     D CoolName        s             21A
     D ODREVDT         s             10A   dtaara(*Var:CoolName)

      /free

          CoolName = 'TONYLIB/DMARTXDATE';
          IN *LOCK ODREVDT;
          ODREVDT = '12/13/2014';
          OUT ODREVDT;

          *inlr = *on;
      /end-free

In the above example, the data area's name is stored in the CoolName variable. You can use whatever calculations are necessary to populate that variable prior to calling the IN op-code.

In the above example, I demonstrate not only reading the data area, but also updating it. If you don't need to change the contents of the data area, you can omit the "*LOCK" on the IN op-code, and you can omit the OUT op-code completely. (Unlike UDS, the IN op-code won't lock the data area unless you specify *LOCK)


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.