Dataset hasChanges()

Posted by burnmw on 06-Sep-2011 08:31

Hopefully this is something very simple that I'm missing here!

Essentially I want to check whether my dataset has had any changes, which I thought I shpuld be able to do in the following manner:

DEFINE DATASET dsDataset FOR ttData.

MESSAGE dsDataset:hasChanges().

However when I try this I simply get "Unknown attribute hasChanges used in widget:attribute phrase".

Can anybody explain why I'm getting this?

Thanks in adavance.

All Replies

Posted by Admin on 06-Sep-2011 08:40

Can anybody explain why I'm getting this?

 

To my knowledge there is no such method in the ABL.

You may get confused because of this:

http://msdn.microsoft.com/en-us/library/system.data.dataset.haschanges.aspx

ADO.NET Dataset and the ProDataset have a lot in common - but not everything

Posted by burnmw on 06-Sep-2011 09:05

Yes Mike, that's exactly what I'd been looking at. And I was worried that you were going to say that it didn't exist.

Thanks anyway!

Martin

Advanced Computer Software Ltd.

Posted by Admin on 06-Sep-2011 09:15

Yes Mike, that's exactly what I'd been looking at. And I was worried that you were going to say that it didn't exist.

 

It's not difficult to cook your own. You'll just have to (dynamically) search for a record in each before-table. We use code like this here to do so:

DO i = 1 TO hDataset:NUM-BUFFERS:

ASSIGN hBuffer = hDataset:GET-BUFFER-HANDLE .

IF VALID-HANDLE(hBuffer:BEFORE-BUFFER) THEN DO:

lFind = hBuffer:BEFORE-BUFFER:FIND-FIRST () NO-ERROR .

IF lFind = TRUE THEN RETURN TRUE .

END.

END.

RETURN FALSE .

Now, the race is open for a better solution, Peter?

Posted by Peter Judge on 06-Sep-2011 09:35

How about ...


def temp-table ttOne no-undo before-table btOne
field f1 as char.

def dataset dsOne for ttOne.

temp-table ttOne:tracking-changes= true.
DO transaction:
create ttOne.
ttOne.f1 = 'a'.
END.

def var i as int.
DO i = 1 TO dataset dsOne:NUM-BUFFERS:
if dataset dsOne:GET-BUFFER-HANDLE(i):table-handle:BEFORE-TABLE:HAS-RECORDS then
message dataset dsOne:GET-BUFFER-HANDLE(i):name 'has at least one change'
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.

-- peter

Posted by Admin on 06-Sep-2011 13:25

How about ...

Neat. Almost...

Make the check

IF VALID-HANDLE (dataset dsOne:GET-BUFFER-HANDLE(i):table-handle:BEFORE-TABLE) AND dataset dsOne:GET-BUFFER-HANDLE(i):TABLE-HANDLE:BEFORE-TABLE:HAS-RECORDS THEN ...

You should not assume that every ProDataset member table has a before-table. There are good reasons not to have a before-table on some tables.

Posted by burnmw on 07-Sep-2011 08:44

Thanks to both of you for your answers. I have used Mikes (mainly because it was there sooner), however it still hasn't solved the problem I had originally (and had hoped this solution would solve).

Essentially I was using bindingSource:RowModified to see if any changes had occured, but for some reason RowModified reports changes even when none have been made/I have SAVE-ROW-CHANGES/REJECT-ROW-CHANGES.

Posted by Tim Kuehn on 07-Sep-2011 17:31

mikefe wrote:

You should not assume that every ProDataset member table has a before-table. There are good reasons not to have a before-table on some tables.

On a related note, isn't it possible for a TT to get a BT even if it wasn't declared as such?

Posted by Admin on 07-Sep-2011 17:46

On a related note, isn't it possible for a TT to get a BT even if it wasn't declared as such?

I doubt that.

Posted by Peter Judge on 08-Sep-2011 08:06

On a related note, isn't it possible for a TT to get a BT even if

it wasn't declared as such?

I doubt that.

You can turn on TRACKING-CHANGES for temp-tables that don't have BEFORE-TABLE in the DEFINE TEMP-TABLE statement.

-- peter

Posted by Admin on 08-Sep-2011 09:11

You can turn on TRACKING-CHANGES for temp-tables that don't have BEFORE-TABLE in the DEFINE TEMP-TABLE statement.

 

Are you serious? What is message # 12344 all about then?

Cannot turn on TRACKING-CHANGES for a static temp-table unless DEFINED with a BEFORE-TABLE phrase. (12344)

Sample code:

DEFINE TEMP-TABLE ttTest NO-UNDO

FIELD cTest AS CHARACTER .

DEFINE DATASET dsTest FOR ttTest .

TEMP-TABLE ttTest:TRACKING-CHANGES = TRUE .

Knowing that you usually work on future releases of OE, will that change in any future release?

Posted by Peter Judge on 08-Sep-2011 09:56

Cannot turn on TRACKING-CHANGES for a static temp-table unless

DEFINED with a BEFORE-TABLE phrase. (12344)

I've done it on a dynamic reference to a static temp-table. dsOrder in this case is a static PDS with static TT's with no before-tables.

    method override protected handle CopyStaticDataset (output dataset-handle phDataset):

        phDataset = dataset dsOrder:handle.

    end method.

Tested recently with OrderEntity in AutoEdge|TheFactory. service_captureorder.p has a EnableDatasetForUpdate function which dynamically loops through the PDS's buffers/tables.

This is in 10.2B04.

-- peter

Message was edited by: Peter Judge. Added OE version info.

Posted by Admin on 08-Sep-2011 10:06

I've done it on a dynamic reference to a static temp-table. dsOrder in this case is a static PDS with static TT's with no before-tables.

 

And what is that error message all about, that claerly says, that you cannot turn on TRACKING-CHANGES without be BEFORE-TABLE???

Posted by Peter Judge on 08-Sep-2011 10:23

mikefe wrote:

I've done it on a dynamic reference to a static temp-table. dsOrder in this case is a static PDS with static TT's with no before-tables.

And what is that error message all about, that claerly says, that you cannot turn on TRACKING-CHANGES without be BEFORE-TABLE???

So it looks like the  DYNAMIC bit gets flipped, and so the check's not done: the returned dataset is now dynamic and so you can set TRACKING-CHANGES.

class testDS:

    def temp-table eOrder no-undo

            field ordernum as int.

    def temp-table EORDERLINE no-undo

        field ordernum as int

        field linenum as int.

    def dataset dsOrder for eorder, eorderline.

    constructor public testDS():

        def var hPDS as handle.

        CopyStaticDataset(output dataset-handle hPDS).

        MESSAGE

            dataset dsOrder:dynamic skip

            hPDS:dynamic

        VIEW-AS ALERT-BOX INFO BUTTONS OK.

    END constructor.

    method protected handle CopyStaticDataset (output dataset-handle phDataset):

        phDataset = dataset dsOrder:handle.

    end method.

END class.

/*

---------------------------

Information

---------------------------

no

yes

---------------------------

OK  

---------------------------

*/

-- peter

Posted by Admin on 08-Sep-2011 10:26

Ok - but that's a dynamic deep copy (of a static temp-table). I wouldn't call that a static temp-table anymore.

This thread is closed