Loek,
I think you're asking why %subst(XCVAR1:1:5) = 'false'; doesn't simply adjust the size of XCVAR1? My guess is that the program is evaluating the left-side of the equation first. So if XCVAR1 has a length of 0, and you try to substring the 1st 5 positions, you will get an error for exceeding the field's size. The right-hand side is not yet taken into consideration.
If it's important to retain existing data within XCVAR1 (that is past the 1st 5 digits), then why not:
If %len( XCVAR1 ) <= 5;
XCVAR1 = 'false';
Else;
%subst( XCVAR1: 1: 5 ) = 'false';
EndIf;
-Kurt
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Loek Maartens
Sent: Monday, February 27, 2012 1:47 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: Assigning a value to a DDS varlen defined field
Hello group,
I have a field named XCVAR1 in a database file with a size of 150 bytes defined with the DDS keyword VARLEN (no size specified).
I understand that this field initially has a length of zero.
Just setting the field XCVAR1 works;
XCVAR1 = 'false' ;
but there might be other values in this VARLEN defined field that I should leave intact (and at the same offset) when they were set by other programs.
When trying to set the field to a value like:
%subst(XCVAR1:1:5) = 'false';
the programs throws an error complaining about invalid field size.
If I first set the XCVAR1 field size like;
if %len(XCVAR1) < 5;
%len(XCVAR1) = 5;
endif;
all is well.
Should the compiler not just set the length of XCVAR1 to 5 when I assign the value 'false' if the XCVAR1 length is less then the value I want to set using the %subst function or can someone explain why not?
Kind regards,
Loek Maartens.
--
This is the RPG programming on the IBM i / System i (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.