|
On Feb 22, 2024, at 4:31 AM, Patrik Schindler <poc@xxxxxxxxxx> wrote:
Hello,
I'm contemplating about optimizing code for a calendar display showing a whole year.
Each month is a row of a subfile, and one subfile line has fields named DF_DAY01 to DF_DAY31, type char with two positions. This saves indicators for various highlighting purposes (only 31 needed instead of 365).
At the moment, I'm using a "day" loop, counting from 1 to 31, CHAIN to the according value in a PF and copy the result into the respective DSPF fields, if there is a result at all.
C COMPKEY CHAIN BUCHUNGEN 73
B3 C *IN73 IFEQ *OFF
B4 C SELECT
C C_DAY WHENEQ '01'
C MOVE TYPKURZ DF_DAY01
C C_DAY WHENEQ '02'
C MOVE TYPKURZ DF_DAY02
C C_DAY WHENEQ '03'
C MOVE TYPKURZ DF_DAY03
…
This leads to an awful lot of conditionals and text. In C I would have used what is called "variable variables", but as far as I've understood this isn't a thing with (old) RPG.
Now I'm wondering if I could code an array with 31 elements of char with two positions each. Instead of allocating storage, the elements should eventually point to the memory locations of the respective display file fields (DF_DAY01, etc).
I want to assign the addresses of the DSPF fields to the defined individual array elements just once at program startup and later use array modifications such as counter variables to significantly lessen the code actually dealing with the DSPF fields (filling and clearing data within).
But… I still struggle to get the grip on pointers and base pointers in RPG. Examples in the net are scarce for old positional code. I found an example in positional code from Scott Klement (https://www.scottklement.com/rpg/pointers.html) but I fail to map this to my actual use case.
And I don't know if this could work with subfiles, where each line stores distinct values and as such has distinct memory locations. Maybe this is hidden from the programmer by lower layers?
I'd appreciate some comments or even example code.
Thank you!
:wq! PoC
--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.
As an Amazon Associate we earn from qualifying purchases.
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.