You are viewing this site as a guest. You can still ask questions and help others! Join our Dev2Dev IT Community to receive your own blog, share your knowledge, and much more.

Problem while calulating aggregate using relative display fields

12 replies [Last post]
ashok_star2004's picture
User offline. Last seen 1 year 20 weeks ago. Offline
Joined: 02/13/2009
Posts: 45

im having 4 fields in a grid.one is display control,one is relative control,one is derived record field,another is level1 record field.
when im trying to calculate aggregate sum,while inserting it is giving correct sum.but while deleting it is giving the sum without reducing previous deleted row value.Moreover when we edit a field which looks its value from another table,there is no effect in the sum.

My task is to calculate aggregate sum in a grid.
The field are
ERPA_AK_ITEM--it looks the item names from another table.it is display control field.
ERPA_AK_COST--it is relative display field of the item.
ERPA_AK_NUMITEMS--we give values at runtime.
ERPA_AK_ORDER4-it is a derived record field which gives the individual item cost by writing a code in field change of ERPA_AK_NUMITEMS.

my code as follows.i kept the code in field change of field ERPA_AK_NUMITEMS

Local Rowset &Level0_Rs, &Level1_Rs;
Local Row &Level0_Row, &Level1_Row;
Local Record &Level0_Rec, &Level1_Rec;
Local Field &Level1_Fld1, &Level1_Fld2;
Local number &Level1_Fld3, &aggr;

&aggr = 0;
&Level0_Rs = GetLevel0();
&Level0_Row = &Level0_Rs.GetRow(1);
&Level1_Rs = &Level0_Row.GetRowset(Scroll.ERPA_AK_CUS31);
For &I = 1 To &Level1_Rs.ActiveRowCount
&Level1_Fld1 = &Level1_Rs(&I).GetRecord(Record.ERPA_AK_ITEMS).GetField(Field.ERPA_AK_COST);
&Level1_Fld2 = &Level1_Rs(&I).GetRecord(Record.ERPA_AK_CUS31).GetField(Field.ERPA_AK_NUMITEMS);
&Level1_Fld3 = &Level1_Fld1.Value * &Level1_Fld2.Value;
&aggr = &aggr + &Level1_Fld3;
End-For;
ERPA_AK_DRORDER.ERPA_AK_ORDER4 = &Level1_Fld3;
ERPA_AK_DDL1.ERPA_AK_DDL2 = &aggr;
MessageBox(0, "Hi", 30000, 2, "The Total Cost is " | &aggr);

abhi10aug's picture
User offline. Last seen 4 years 26 weeks ago. Offline
Joined: 06/11/2008
Posts: 10
Re: Problem while calulating aggregate using relative ...

Hi Ashok
The code looks fine. I guess when u delete the rows the component buffer is not getting refreshed. Try to print the number of rows (value of &I) after you delete the row.

Ashar's picture
User offline. Last seen 3 years 38 weeks ago. Offline
Joined: 03/26/2008
Posts: 227
Re: Problem while calulating aggregate using relative ...

The problem is that the FieldChange event doesnt get triggered when you delete an item, try the same logic in RowDelete event of the record.

ashok_star2004's picture
User offline. Last seen 1 year 20 weeks ago. Offline
Joined: 02/13/2009
Posts: 45
Re: Problem while calulating aggregate using relative ...

Hi Ashar,

I tried the same logic in RowDelete Event.But it remained unchanged

Ashar's picture
User offline. Last seen 3 years 38 weeks ago. Offline
Joined: 03/26/2008
Posts: 227
Re: Problem while calulating aggregate using relative ...

did u check if the code is triggered at all by using some winmessage?

ashok_star2004's picture
User offline. Last seen 1 year 20 weeks ago. Offline
Joined: 02/13/2009
Posts: 45
Re: Problem while calulating aggregate using relative ...

hi Ashar!!

i tested it with winmesg.but its not solved.pls do help me.the code is correct.its only problem to complete the task.can you tell an example for deleting a row in grid.and tell me the events also with the people code..

Thanks,
Ashok

Ashar's picture
User offline. Last seen 3 years 38 weeks ago. Offline
Joined: 03/26/2008
Posts: 227
Re: Problem while calulating aggregate using relative ...

Not sure why it is not working!
Did you place the code in the rowdelete of the grid's primary record?

ashok_star2004's picture
User offline. Last seen 1 year 20 weeks ago. Offline
Joined: 02/13/2009
Posts: 45
Re: Problem while calulating aggregate using relative ...

Hi Ashar,
I placed the same code in Grid's primary record's field row delete event.
But the result is same.Give me a simple example for deletion in a grid with people code.Im thankful to u for your response to my query..

Thanks,
Ashok

Ashar's picture
User offline. Last seen 3 years 38 weeks ago. Offline
Joined: 03/26/2008
Posts: 227
Re: Problem while calulating aggregate using relative ...

I have done so many validation in RowDelete and it worked fine for me.. not sure why the winmessage itself is not triggered for you. did u have any conditions before calling winmessage? or did u write it as the first statement in the event?

ashok_star2004's picture
User offline. Last seen 1 year 20 weeks ago. Offline
Joined: 02/13/2009
Posts: 45
Re: Problem while calulating aggregate using relative ...

Hi Ashar!!

I have no conditions before calling message.The deletion is successful after saving and refreshing the component.Can u send me that RowDelete Code.

ashok_star2004's picture
User offline. Last seen 1 year 20 weeks ago. Offline
Joined: 02/13/2009
Posts: 45
Re: Problem while calulating aggregate using relative ...

Hi Ashar!!
Now if i delete a row,the correct sum is not displayed.But when i add a row then it is displaying the correct sum.

Ashar's picture
User offline. Last seen 3 years 38 weeks ago. Offline
Joined: 03/26/2008
Posts: 227
Re: Problem while calulating aggregate using relative ...

Hi Ashok,
Sorry i was not able to post reply as i'm busy with my work. I really do not have a clue on whats wrong in your scenario. May be you need to have some senior developers analyze your code/event you are using.

/Ashar

iammanku's picture
User offline. Last seen 10 years 27 weeks ago. Offline
Joined: 03/24/2009
Posts: 10
Re: Problem while calulating aggregate using relative ...

Hi,

When you delete the row, it will not be directly deleted from the backend. This is done completely only on save. May be because of some cashe issues, oyu are facing this issue.

So you change your RowDelete code to SUBTRACT the val of sum of the row being deleted from the Aggr value.

&Level1_Fld3 = &Level1_Fld1.Value * &Level1_Fld2.Value;
&aggr = &aggr - &Level1_Fld3;

Where &Level1_Fld3 is from the row being deleted.