monica1
15th July 2011, 15:11
I have a new multi ocurrence screen. This screen has a table fields and a new program variable.
I want that this new program variable changes a new table related with the main table will be changed.
The problem is when there is more than one record changed in all the records appears the same valor of the program variable.

How can I do that?


|****************************** DECLARATION SECTION ***************************
declaration:
table ttcmcs031 | Sectores
table tcasap124 | Sector - Actividad cliente - Actividad obra
table tcasap104 | Actividad cliente
table tcasap114 | Actividad obra

extern domain tcmcs.str2 actc fixed
extern domain tcmcs.str2 acto fixed

domain tcmcs.long i


main.table.io:
before.write:
for i = 1 to filled.occ
do.occ(i, modificar)
endfor

before.rewrite:
for i = 1 to filled.occ
do.occ(i, modificar)
endfor

before.delete:
for i = 1 to filled.occ
if mark.table(i) then
do.occ(i, borrar)
endif
endfor

|****************************** FUNCTION SECTION ***************************
functions:
function borrar()
{
select casap124.*
from casap124 for update
where casap124._index1 = {:tcmcs031.cbrn}
selectdo
db.delete(tcasap124, db.retry)
endselect
}
function modificar()
{
select casap124.*
from casap124 for update
where casap124._index1 = {:tcmcs031.cbrn}
selectdo
casap124.actc = actc
casap124.acto = acto
db.update(tcasap124, db.retry)
selectempty
casap124.cbrn = tcmcs031.cbrn
casap124.actc = actc
casap124.acto = acto
db.insert(tcasap124, db.retry)
endselect
}

mark_h
15th July 2011, 15:22
Not sure I get what you are asking. Are acto and actc form fields or what? If they are form fields then you need to make them arrays. That way each multioccurence record on the form can have different data. Then when you do your for statements you can access acto(i) and actc(i).

monica1
18th July 2011, 10:31
Yes, the fields are form fields.

There isn't any way that arrays to solve the problem. I don't know how may records the user can add in the form.

Thank you in advance,

mark_h
18th July 2011, 15:38
Well you only need the number of fields that can be on the screen at one time. You can either force a save or an update after so many records. You can put the session in debug mode and see what happens after screen full of records. Just a thought.

monica1
19th July 2011, 10:19
Thank you very much.
It's a good idea.
I try to put the form field in array but, how can I put the variable in the screen? ( I attach the screen)



Thank you in advance,

mark_h
19th July 2011, 15:10
Good point. Let me look around to see if I have done this. I think so, but can't be sure.

Esther
19th July 2011, 15:36
Why don't you create a new field on the table?

mark_h
19th July 2011, 15:44
Esther recommendation is the easiest way to solve the problem. What I did find was that you need to turn off multioccurence field. Then add a field for each element of the array down the form. The problem with this is that as you scroll thru the records you have to make sure each element is set correctly. I can see where coding would be needed to handle the events - like first, last, etc.

I have not been able to find where I have done something exactly like you are doing.

Hitesh Shah
20th July 2011, 17:27
main table io sections work for each occurrence individually . So iterating all occurrence in main table io section (using i =1 to filled.occ) is not necessary .
Instead u may use pre-defined variable actual.occ to check the occurence being interacted with data base .

Also u may use on.old.occ section to check/ see / verify the old values of fields which have been changed.