cucucucu
9th June 2005, 12:15
Hi all,
I have a problem. I insert some records in a session(form type is 3) but not saved, how can I get some value of previous records?
For example, I insert 4 SO detail lines in maintain Sales Order, but not saved. I want to compare the field item with the second line and the 4th line. How to do that?

Best Regards,
Cu

Evert-Jan Bosch
9th June 2005, 12:49
You can use do.occ.without.update(occurrence.number, functionname)

For example.
|* global declaration
domain tcitem store.item

function compare.items()
{
domain tcitem item1
domain tcitem item2

do.occ.without.update(2, get.item)
item1 = store.item
do.occ.without.update(4, get.item)
item2 = store.item
if item1 = item 2 then
...
endif
}
function get.item()
{
store.item = tdsls041.item
}

By the way: this will only work for multi occ edit sessions.

cucucucu
10th June 2005, 04:28
Thank you, it is very helpful. I have another question, how can I get the number of records in a multi occ edit session before saved?

Evert-Jan Bosch
10th June 2005, 08:22
tools variable filled.occ contains the number of filled occurrences on the screen.

cucucucu
10th June 2005, 09:33
filled.occ only contains the number of filled occurrences on the current screen, but cannot contains all records in this session. For example, one sales order have 100 lines, but the current screen display 5 lines, filled.occ = 5 not 100.

Evert-Jan Bosch
10th June 2005, 09:43
That's true.

To be complete I programmed it in the past in following way.
1. Check all records on the screen (via filled.occ and do.occ.without.update)
2. Store the already checked records in an array.
3. Select all records from the database (via sql). Skip those that are present in the array and check the values.
4. Clear the array.

beginer
10th June 2005, 09:48
Hi,

I suppose cu.. u wanted to know the count of unsaved records.

If the no. of records while inserting neways increase the current occ. then the save command is executed while starting with the fresh set of occurances in a multiocc.
So filled.occ would be the right no. of unsaved records at a given point of time.

cucucucu
10th June 2005, 10:10
Actually, I want to know all records including saved and unsaved. :P

v_chandra
10th June 2005, 10:59
Hi Cu

I think you can use predefined variable fattr.occurnr this will give you total number of occurence on form (irrespective of whether filled or not) may be this will help you achieve what you want to do.

Regards
Vinod

cucucucu
13th June 2005, 04:11
Hi Vinod,
I tested that fattr.occurnr is same as filled.occ. :(

v_chandra
13th June 2005, 08:38
Hi Cu

I have check it in the BAAN Tools Help (predefined variables) and this are the description to these standard variables.

fattr.occurnr - Number of occurences on current Form
filled.occ - Number of filled occurence

Both can only be used in 4GL program and are Read only Variables.

Regards
Vinod

baanprog
13th June 2005, 10:12
Hi,

I think you want to manipulate a multi occ session, it has lot of limitations.
If you can keep the filled.occ to 10 you can play a little, otherwise you have to go for 3GL programming.

Regards

cucucucu
13th June 2005, 12:37
Hi all,
The problem has been solved. Thanks a lot!!!!
We found when switched screen, these records of previous screen has been saved automaticly.
Best Regards,
Cu

Evert-Jan Bosch
13th June 2005, 12:41
Hi all,
The problem has been solved. Thanks a lot!!!!
We found when switched screen, these records of previous screen has been saved automaticly.
Congratulations!
It's a surprising end of this topic ;)

beginer
13th June 2005, 12:55
Hay cu ,

That is what i had already mentioned :-

If the no. of records while inserting neways increase the current occ. then the save command is executed while starting with the fresh set of occurances in a multiocc.


neways, congrats...the problem is solved.

ralf@lub
13th June 2005, 14:55
Hi all,

I have a similar problem. I created four tables. First two tables contain the actual values. The others are for archiving.

In the maintain session ( multi occurence, inner join of the two tables) I want to archive the old values / all changes. I use after.rewrite of main.table.io. Of course the new value is stored to the archive but actually I would like to store the old values...

Do you have any suggestions how to store the old values and take care of all session behaviour (update by button, automatic update by scolling, abort session etc.)

I thought about the use of some arrays with the occurence number as index. But what about scrolling and automatic save then ??

Thanks for any help :-)

Ralf

Evert-Jan Bosch
13th June 2005, 15:17
Each record that is written to the database passes the before.write and after.write sections. Function on.old.occ can be used in before.write section. With that mechanism you can store the old values to the archive tables.

Arrays with occurrence number are definitely not needed!

main.table.io:
before.write:
on.old.occ(add.to.archive)

functions:
function add.to.archive()
{
db.set.to.default(t....)
|* set.table.values
db.insert.(t....)
}
PS 1. Within function add.to.archive the old values are current.

ralf@lub
13th June 2005, 15:53
Beautiful! :-) Thank you.

I just tried the first version you posted and wondered about the result. But with "on.old.occ" it works. Is there a special reason why you use before.rewrite (write) instead of after.rewrite ? Isn't there a rest risk of archiving old value but not saving new one to db ? Hmm. Probably transactions will handle this anway.

Ralf

Evert-Jan Bosch
13th June 2005, 15:57
On.old.occ retrieves the old values from the database.
In after.(re)write the new values are already written to the database. So, in after.(re)write on.old.occ does not work.
Before and after (re) write are all in the same transaction. The 4GL engine will take care of the transaction handling. So, there is no risk. Instead: it is the safest way to use those sections!