Thanks Kurt, actually your first reply gave me the answer I was looking
for. The exact scenario was that a procedure was being called/passed with
10 parameters. The first two were the keys to a file and never changed
(hense the const keyword). The other 8 parameters were to be populated.
I just thought the code would look cleaner passing a datastructure rather
than 10 parameters.
After your first reply I changed it to pass three parameters. Two const
parameters and a datastructure of the remaining 8 changeable fields.
This would make sense would it not?
On 2012-06-15 4:56 PM, Anderson, Kurt wrote:
Hi Robert, I just had an idea. If you truly don't want getDaysOfWeek touching subfield1. However I will say that I don't really see any harm in subfield1 being set by that procedure. In fact, I would suggest, as in my last email, sending the starting day as a separate parm, then the procedure loads it into the DS along with all of the other subfields it's loading.
But, here's an idea on getting getDaysOfWeek to not touch subfield1 at all.
d testpgm7 pr
d t_DayDs ds template
d subfield1 10a varying
d subfield2 like(subfield1)
d subfield3 like(subfield1)
d subfield4 like(subfield1)
d subfield5 like(subfield1)
d subfield6 like(subfield1)
d subfield7 like(subfield1)
// define this within the service program's copybook
d t_NewDayDs ds template
d subfield2 10a varying
d subfield3 like(subfield2)
d subfield4 like(subfield2)
d subfield5 like(subfield2)
d subfield6 like(subfield2)
d subfield7 like(subfield2)
d testpgm7 pi
d DayDs ds likeds(t_DayDs)
d newDayDs ds likeds(t_newDayDs)
/free
*inlr = *on ;
DayDs.subfield1 = 'Sunday';
GetDaysOfWeek(Days.subfield1: newDayDs);
// I think eval-corr is available at v6.1. will load all the subfields except subfield1.
eval-corr DayDs = newDayDS;
Return;
/end-free
-----Original Message-----
From: [1]rpg400-l-bounces@xxxxxxxxxxxx [[2]mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Robert Rogerson
Sent: Friday, June 15, 2012 2:31 PM
To: RPG programming on the IBM i / System i
Subject: Explanation of a datastructure as a parameter...
Hi All,
I'm just hoping that someone can spare a moment and help me understand
this better.
I'm unclear how or if I can stipulate a parameter as const when passing a
datastructure defined like a template. For example, see the following
code.
h option(*nodebugio:*srcstmt)
d testpgm7 pr
d t_DayDs ds template
d subfield1 10a varying
d Overlay(t_DayDs)
d subfield2 like(subfield1)
d Overlay(t_DayDs: *next)
d subfield3 like(subfield1)
d Overlay(t_DayDs: *next)
d subfield4 like(subfield1)
d Overlay(t_DayDs: *next)
d subfield5 like(subfield1)
d Overlay(t_DayDs: *next)
d subfield6 like(subfield1)
d Overlay(t_DayDs: *next)
d subfield7 like(subfield1)
d Overlay(t_DayDs: *next)
d testpgm7 pi
d DayDs ds likeds(t_DayDs)
/free
*inlr = *on ;
DayDs.subfield1 = 'Sunday';
GetDaysOfWeek(DayDs);
Return;
/end-free
p GetDaysOfWeek b
d GetDaysOfWeek pi
d i_DayDs likeds(t_DayDs)
/free
*inlr = *on ;
If i_DayDs.subfield1 = 'Sunday';
i_DayDs.subfield2 = 'Monday';
Endif;
Return;
/end-free
p GetDaysOfWeek e
The datastructure DayDs is defined like the template t_DayDs. I don't
want the procedure GetDaysOfWeek to be able to change subfield1. If I had
passed all 7 parameters I would have specified the keyword const for the
first parameter.
How or can I do with a keyword when I pass a datastructure.
Thanks to all in advance.
Robert Rogerson
--
This is the RPG programming on the IBM i / System i (RPG400-L) mailing list To post a message email: [3]RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: [4]
http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: [5]RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at [6]
http://archive.midrange.com/rpg400-l.
References
Visible links
1. mailto:rpg400-l-bounces@xxxxxxxxxxxx
2. mailto:rpg400-l-bounces@xxxxxxxxxxxx
3. mailto:RPG400-L@xxxxxxxxxxxx
4.
http://lists.midrange.com/mailman/listinfo/rpg400-l
5. mailto:RPG400-L-request@xxxxxxxxxxxx
6.
http://archive.midrange.com/rpg400-l
As an Amazon Associate we earn from qualifying purchases.