buffer-field:position wrong

Posted by James Palmer on 13-Feb-2017 06:01

OE 10.2B08. 

Has anyone come across a scenario where the position attribute of a buffer field is wrong? 

do i = 1 to bh:num-fields:
message  i bh:buffer-field(i):position - 1
    view-as alert-box info buttons yes-no update ok as log.
if not ok  then
    return.

end.

In the above code i and the position match until a certain point, until a position is suddenly missed. Would this maybe be because of a deleted field? Is there any way to fix this? Is there a better attribute to use? We use the position later to refer to the field's value. 

Posted by Fernando Souza on 13-Feb-2017 10:47

Yes, most likely a field got deleted. The value is calculated when new fields are added and in incremental order, but it is a logical position of the field, and you can change it if you want but that will force you to recompile any r-code that references that table. The value is dumped as POSITION in the .df file.

All Replies

Posted by Frank Meulblok on 13-Feb-2017 06:13

"Would this maybe be because of a deleted field?"

Probably. Position attribute does reflect the r-code position of the field, so it's tied to physical record layout.

"Is there a better attribute to use? We use the position later to refer to the field's value."

Why not use the ordinal number (the "i" in your example) of the buffer-field within the the buffer object instead ?

Posted by James Palmer on 13-Feb-2017 06:18

The code above is to illustrate the point, rather than a direct rip of the code from the product. We don't iterate through the fields rather refer to them by name. It's a very complicated piece of code that drops hugely dynamic data from a browse to excel. There's probably better ways of doing it, but I don't have the time to rework it in detail at the moment.

I can probably rework to use the above code to find the value, but doing that for 500+ columns of data would certainly slow down the extract.

Posted by Fernando Souza on 13-Feb-2017 10:47

Yes, most likely a field got deleted. The value is calculated when new fields are added and in incremental order, but it is a logical position of the field, and you can change it if you want but that will force you to recompile any r-code that references that table. The value is dumped as POSITION in the .df file.

Posted by Patrick Tingen on 14-Feb-2017 02:12

Not sure how you are using it exactly, but you might get away by simply adding NO-ERROR at the end.

Posted by James Palmer on 14-Feb-2017 05:40

Thanks all for the input. I now calculate the actual position of the field in the table.

I do think there's an area for enhancement though, so will put in an idea. The product lets you refer to a buffer-field by name and by position. If you refer by position you can use the NAME attribute to refer to it by name in future if you wish, but you can't use the POSITION attribute to refer to it by position later. Maybe we need another attribute that specifies the position so you can use that later.

Posted by gus bjorklund on 14-Feb-2017 07:04

> On Feb 14, 2017, at 6:42 AM, James Palmer wrote:

>

> Maybe we need another attribute that specifies the position so you can use that later.

note that the position can change when schema changes are made and also when tables are dumped and loaded.

Posted by James Palmer on 14-Feb-2017 07:51

Indeed - a valid point Gus. We're not storing the position in the database anywhere, just as part of the session. I'm not sure why we don't do it all by name, but it's easier to make it work by position than by name if that's what we already do through the system.

This thread is closed