PDA

View Full Version : Anyone care to look at why this no longer works?



chuckatkinson
5-May-2014, 02:06 PM
Had some old code that moved (rippled) some fields in a table down using the field number. Pretty simple, but no longer works. This is in a DD.



Procedure MoveDates
Integer iField
Date dDate
Boolean bErr
Move 20 to iField
Repeat
Get_Field_Value MAINTAIN.File_Number (iField-1) to dDate
Set_Field_Value Maintain.File_Number iField to dDate
Decrement iField
Until iField eq 9


Get Request_Validate to bErr
If (not(bErr)) Begin
Send Request_Save
End


End_Procedure




I can see the table is active and changed, but it doesn't save. I tried changing it to Field_Current_Value and Field_Changed_Value, but that didn't work either. This is moving to a DD in a cWebview.

FrankValcarcel
5-May-2014, 02:10 PM
First thing that comes to mind is since it is inside a DD you can't depend on the physical buffer having what you expect in it unless you are in a procedure that guarantees that. In a DD I'd use the Field_Current_value code depending on location.

Dennis Piccioni
5-May-2014, 02:31 PM
I don't see how this would ever have worked. You never move the data from the global record buffer to the DDO buffer. I think you're probably missing a step that the old code performed wherever you got it from.

FrankValcarcel
5-May-2014, 02:36 PM
If he executed the code at just the right spot it would work, ie. in SaveMainFile

Dennis Piccioni
5-May-2014, 02:39 PM
Perhaps, but we're just guessing now.

chuckatkinson
5-May-2014, 02:55 PM
I think this was in another part of the DD - like creating. Thanks you are right. I was trying to refactor the old code without changing too much. So it's my mistake. But what would be the recommended way to use essentially a field index to do this function using Set Field_Changed_Value? AFAIK - you have to use a field name in there?

Mike Cooper
5-May-2014, 03:15 PM
AFAIK - you have to use a field name in there?

Well (as you know) I am not an authority on DD, but I think you can use the field number in place of the name

M

matthewd
5-May-2014, 04:13 PM
Chuck,

No, you don't necessarily have to use the field name. The DDO field messages where you use the "field tablename.fieldname" syntax are just looking for a plain old integer parameter. The compiler sees the "field" keyword and looks up the field number for the "tablename.fieldname" and that is what is actually passed to the DDO message.

You don't have to use the "field" keyword, just pass an integer. This should work:


repeat
get field_current_value (iField-1) to dDate
set field_changed_value iField to dDate
decrement iField
until (iField=9)

Evertjan Dondergoor
5-May-2014, 06:10 PM
I'd still prefer to write it out, its just 11 lines or so. Just write the line once, copy it 10 times and block-copy the field names. Not a big task and more readable than a loop.

chuckatkinson
6-May-2014, 08:11 AM
Matt's solution works. What was throwing me off is the changes are not shown in the debugger viewing the table values. But they are saved in the database and the changes are shown on the screen. Thanks Matt.