[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Question Re WEBFORM_SetVar



Scott,

Thank you for the explanation and education.  I have changed the code to %ADDR(xmldata:*DATA) and I will never have to worry again about xmldata being a fixed length field vs varying field. :-)

Bruce


-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: Wednesday, February 11, 2015 11:56 AM
To: HTTPAPI and FTPAPI Projects
Subject: Re: Question Re WEBFORM_SetVar

Bruce,

The reason it works this way is that WEBFORM_setPtr() can accept input from different types of variables.  For a fixed-length RPG field, the data begins directly at the address of the field.  For a VARYING field, the first two (or 4 for larger fields) bytes are used by RPG internally to keep track of the length of the field, so you have to skip those bytes, and that's why you add 2.  You can also use setPtr() with other data types, such as data structures, Unicode fields, dynamically allocated memory, etc.  This approach also allows people that aren't yet up to V6R1 to still give very long fields (in excess of the 64k limit that RPG has in V5R4)  So it's very versatile, but requires a little bit of understanding about how RPG works under the covers.

But, you wouldn't add to the length... only the address.   And if you're 
on V6R1 or higher, it's better to use %ADDR(xmldata:*DATA) instead of %ADDR(xmldata)+2.  When you use *DATA it gives you the address of the data in the field rather than the length portion, so you don't have to add anything to the address -- and it's a bit more self-documenting that 
way.   Unfortunately, the *DATA option didn't exist until V6R1, and 
HTTPAPI supports older versions than that, so the example still have to use the older methods.

Hope that helps.
-SK



On 2/10/2015 5:41 PM, Anthony, Bruce wrote:
> Scott,
>
> I looked at my debug in the last message sent to you and see that I should have added 2 to the Address not to the length.
>
> When I add 2 to the address it removes the first two characters that should not have been sent:
>
> %01%A3
>
> Don't know what the above 2 characters are but I should not have sent it as part of xmldata.
>
>
> My code is as follows:
> c                   callp     WEBFORM_setPtr(Form: 'xmldata'
> c                                     : %Addr(xmldata) + 2
> c                                     : %len(%trimr(xmldata)))
>
> Bruce
>
>
>
> -----Original Message-----
> From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Scott 
> Klement
> Sent: Tuesday, February 10, 2015 8:33 AM
> To: HTTPAPI and FTPAPI Projects
> Subject: Re: Question Re WEBFORM_SetVar
>
> Why are you adding 2 to the length?
>
> On 2/10/2015 10:17 AM, Anthony, Bruce wrote:
>> Mike,
>>
>> Thank you.  I had to make a minor change as follows:
>>
>> c                   callp     WEBFORM_setPtr(Form: 'xmldata'
>> c                                     : %Addr(xmldata)
>> c                                     : %len(%trimr(xmldata)) + 2)
>>
>> The above works great and you made my day!
>>
>> Thank you,
>>
>> Bruce
>>
> ----------------------------------------------------------------------
> - This is the FTPAPI mailing list.  To unsubscribe, please go to:
> http://www.scottklement.com/mailman/listinfo/ftpapi
> ----------------------------------------------------------------------
> -
> ----------------------------------------------------------------------
> - This is the FTPAPI mailing list.  To unsubscribe, please go to:
> http://www.scottklement.com/mailman/listinfo/ftpapi
> ----------------------------------------------------------------------
> -
>

-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------