× 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.



Hi Robert,

> This works:
>
> D* Get the *LDA
> D DALDA          UDS                  dtaara(*LDA)
> D  DAFld1                 1      4
> D  DAFld2                10     19
> D  DAFld5                20     30
> D  DAFld3               115    115
>
> C
> C* Get the Local Data Area
> C                   in        DALDA
> C
> C* Populate the workfields from the *LDA
> C                   eval      #fld1 = DAFld1
> C                   eval      #fld2 = DAFld2

Yeah, you're right that it works.  But do you realize that you're reading
the LDA twice?  There are two ways to read the LDA, and it appears that
you've decided to do both :)

When you code a data structure with a "U", the RPG program will
automatically read it as a character data area when the program starts,
and it will automatically update the data area when the program ends.  If
you leave the data area name blank, it will use the *LDA.

Here's an example:

     D                UDS
     D  DAFld1                 1      4
     D  DAFld2                10     19
     D  DAFld5                20     30
     D  DAFld3               115    115

     C                   eval      #fld1 = DAFld1
     C                   eval      #fld2 = DAFld2

As you can see, the IN and OUT op-codes are not needed.  Any changes that
you make to the LDA will be saved when the program ends.

If you want to give your data structure a different name, then you can use
the DTAARA keyword to make it refer to the LDA, as follows:

     D DALDA          UDS                  dtaara(*lda)
     D  DAFld1                 1      4
     D  DAFld2                10     19
     D  DAFld5                20     30
     D  DAFld3               115    115

But, agian, you do not need to use IN or OUT.  The "UDS" will
automatically read it when the program starts, and write it when the
program finishes.

This can cause problems, however.  If you call another program during your
program, it will not see any changes that you've made to the LDA. If it
makes any changes, your program won't see them.   That's because the LDA
is only read when the program starts, and written when it finishes.

The IN and OUT keywords are designed to give you more control over when
the data area is written or read.  They also give you the ability to
reference numeric data areas (though, that's not part of the question, so
I won't explain it here)

     D DALDA           DS                  dtaara(*lda)
     D  DAFld1                 1      4
     D  DAFld2                10     19
     D  DAFld5                20     30
     D  DAFld3               115    115

     c                   in        DALDA

     C                   eval      #fld1 = DAFld1
     C                   eval      #fld2 = DAFld2

Note that I do NOT have the "U" coded on the data structure.  It's not
needed - I don't want the system to read my data area automatically
because I'll read it manually with the IN op-code.

If I wanted to call a program, then receive it's changes to the LDA, I
could do so by doing the call, and THEN executing the IN op-code.
Likewise, if I wanted to make changes to the LDA before calling that
program, I could change the DAFld1, DAFld2, DAFld5, DAFld3 fields, then
use the OUT op-code to write them, then call the other program.  Since the
changes were written before that program was run, it'll be able to see
them.

IMHO, it doesn't make much sense to specify BOTH "UDS" and the IN/OUT
op-codes. It may be syntatically valid, but it's illogical, and I think it
confuses people into thinking that you need a "U" in order to read a data
area, or the LDA, both of which are completely false.


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.