use report to write into a table

LazlowLazlow Member Posts: 9
Hi Masters,

I'm sorry for this beginner question but how can I use a report to write into a table field?
I've aleady made a report with a temp (Temporary property is No) global record variable based on the target table.

I put this short code to the report OnPreDataItem trigger:
IF temp.FIND('-') THEN
 REPEAT
  temp."field1 value" := temp."field2 value";
  //just for test:
  MESSAGE(FORMAT(temp."field1 value"));
 UNTIL temp.NEXT = 0;

The report runs without any errors, but the table is not updated.

Can someone help me?

Br,

Comments

  • MBergerMBerger Member Posts: 413
    you forgot the Modify !
  • LazlowLazlow Member Posts: 9
    Ahhh! ](*,)
    Big mistake!

    I'm a lamer.

    Thank you!
  • krikikriki Member, Moderator Posts: 9,110
    BTW: it is best you don't use the same variable to change your table as the one you use to loop.
    In your case, I would do this:
    IF temp.FINDSET(TRUE,TRUE) THEN // or use LOCKTABLE+ FIND('-') in case you don't have at least 4.0SP1
      REPEAT
        temp2 := temp;
        temp2."field1 value" := temp2."field2 value";
        temp2.MODIFY;
      UNTIL temp.NEXT = 0;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • MBergerMBerger Member Posts: 413
    kriki wrote:
    BTW: it is best you don't use the same variable to change your table as the one you use to loop.
    In your case, I would do this:
    IF temp.FINDSET(TRUE,TRUE) THEN // or use LOCKTABLE+ FIND('-') in case you don't have at least 4.0SP1
      REPEAT
        temp2 := temp;
        temp2."field1 value" := temp2."field2 value";
        temp2.MODIFY;
      UNTIL temp.NEXT = 0;
    
    Agreed.....but this is only really necessary if you change the value you are also sorting or filtering on in the dataitem.
  • krikikriki Member, Moderator Posts: 9,110
    MBerger wrote:
    kriki wrote:
    BTW: it is best you don't use the same variable to change your table as the one you use to loop.
    In your case, I would do this:
    IF temp.FINDSET(TRUE,TRUE) THEN // or use LOCKTABLE+ FIND('-') in case you don't have at least 4.0SP1
      REPEAT
        temp2 := temp;
        temp2."field1 value" := temp2."field2 value";
        temp2.MODIFY;
      UNTIL temp.NEXT = 0;
    
    Agreed.....but this is only really necessary if you change the value you are also sorting or filtering on in the dataitem.
    Also true, BUT think about this:
    You create a loop with no second variable because it isn't needed.
    Next month, some filter (or field to be modified) has to be added that makes it necessary to use a second variable. Because it is a small change (just 1 filter to be added!), a junior programmer does this. The junior programmer doesn't know this problem because no one told him yet or someone told him but he doesn' remember (he has been bombarded with info lately) and does the change and does some small test in which there is only 1 record to change (and juniors do test with 1 record and not more!).
    No one else tests it (it is a small change after all!)..
    It gets into production.
    After some time (generally after a week or so), to customer calls that the program doesn't work anymore.

    So you have to search where the bug is AND fix the wrong data.
    Time needed to do all that : 1 hour to several days!

    Time needed to use a second buffer from the beginning : < 1 minute!
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • DenSterDenSter Member Posts: 8,305
    Lazlow wrote:
    I'm a lamer.
    You mean a learner :mrgreen:
Sign In or Register to comment.