Default Value in RECORD
Hi,
Is it possible to provide a Default Value for a given field in a RECORD statement? I need to add a new field in some layouts, which are already being used and I don't wanna to change old code, that already use this layout. So, my idea would be add a new field to this layout and set a default value for it and change it only when I use it in my new code.
I tried this, but didn't worked:
But every time try this, I see an error telling that I should provide a value to newValue1.
Thanks,
Att.
Artur Baruchi
Is it possible to provide a Default Value for a given field in a RECORD statement? I need to add a new field in some layouts, which are already being used and I don't wanna to change old code, that already use this layout. So, my idea would be add a new field to this layout and set a default value for it and change it only when I use it in my new code.
I tried this, but didn't worked:
- Code: Select all
EXPORT myLayout := RECORD
STRING oldvalue1;
STRING oldvalue2;
....
STRING newValue1 = '';
END;
But every time try this, I see an error telling that I should provide a value to newValue1.
Thanks,
Att.
Artur Baruchi
- abaruchi
- Posts: 19
- Joined: Thu Apr 18, 2019 4:50 pm
Artur,
The default value for a field in a RECORD structure requires use of the definition operator (:=) so your code example should be:
HTH,
Richard
The default value for a field in a RECORD structure requires use of the definition operator (:=) so your code example should be:
- Code: Select all
EXPORT myLayout := RECORD
STRING oldvalue1;
STRING oldvalue2;
....
STRING newValue1 := '';
END
- Code: Select all
EXPORT myLayout := RECORD
STRING oldvalue1;
STRING oldvalue2;
....
STRING newValue1{DEFAULT('')};
END
HTH,
Richard
- rtaylor
- Community Advisory Board Member
- Posts: 1619
- Joined: Wed Oct 26, 2011 7:40 pm
Hi Richard, thanks for your reply.
When I run this code, I got an error saying that I didn't provide values to MyError2.message2 and MyError2.code2. As far as I understand, since I defined MyError2 in lMyFinalLayout as an empty row, t01 transform shouldn't care about it.
Thanks,
Att.
Artur Baruchi
- Code: Select all
// Deprecated Layout
EXPORT lMyLayout01 := RECORD
STRING message {XPATH('messagge')};
UNSIGNED code {XPATH('code')};
END;
// New Record Layout
EXPORT lMyLayout02 := RECORD
STRING message2 {XPATH('Message')};
UNSIGNED code2 {XPATH('Code')};
END;
// Main record structure that uses both layouts.
EXPORT lMyFinalLayout := RECORD
lMyLayout01 MyError;
lMyLayout02 MyError2 := [];
END;
r01 := ROW({'abc', 123}, lMyLayout01);
t01 := ROW(TRANSFORM(lMyFinalLayout,
SELF.MyError := r01;));
When I run this code, I got an error saying that I didn't provide values to MyError2.message2 and MyError2.code2. As far as I understand, since I defined MyError2 in lMyFinalLayout as an empty row, t01 transform shouldn't care about it.
Thanks,
Att.
Artur Baruchi
- abaruchi
- Posts: 19
- Joined: Thu Apr 18, 2019 4:50 pm
Artur,
The TRANSFORM must supply a value for every field in the result RECORD structure. That's why you get the error. The DEFAULT field modifier works like this:
HTH,
Richard
The TRANSFORM must supply a value for every field in the result RECORD structure. That's why you get the error. The DEFAULT field modifier works like this:
- Code: Select all
// Deprecated Layout
EXPORT lMyLayout01 := RECORD
STRING message {XPATH('messagge')};
UNSIGNED code {XPATH('code')};
END;
// New Record Layout
EXPORT lMyLayout02 := RECORD
STRING message2 {XPATH('Message'),DEFAULT('default')};
UNSIGNED code2 {XPATH('Code'),DEFAULT(42)};
END;
// Main record structure that uses both layouts.
EXPORT lMyFinalLayout := RECORD
lMyLayout01 MyError;
lMyLayout02 MyError2;
END;
r01 := ROW({'abc', 123}, lMyLayout01);
t01 := ROW(TRANSFORM(lMyFinalLayout,
SELF.MyError := r01;
SELF := []));
r01;
t01;
HTH,
Richard
- rtaylor
- Community Advisory Board Member
- Posts: 1619
- Joined: Wed Oct 26, 2011 7:40 pm
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest