CHANGECOMPANY

Hi All, I’ve got a problem with Flowfields. Our Customer works with two companys. The table 18 is declared with DataPerCompany = No This table has a Flowfields which refers to Table 37. This table has the Property DataPerCompany = Yes The field is called “Auftragsbestand (MW)” (Sorry, i don’t know the english word). What i want is to calc the flowfield for both companies. I’ve tried it the following way: CALCFIELDS(“Auftragsbestand (MW)”); Sum := “Auftragsbestand (MW)”; .CHANGECOMPANY(’’); CALCFIELDS(“Auftragsbestand (MW)”); Sum := sum + “Auftragsbestand (MW)”; CLEAR(); But sum does mot contain the part of the second company. What is my mistake? Thanks in advance. Greetings, Frank p.s. What i really want is to change form 343 so that all the values are values of both companies. Perhaps there is a better way to do this?!?!

CHANGECOMPANY only changes comany for the variable that You staded CHANGECOMPANY. All tables that flowfields depend on and all tables that are called by triggers is still in the company that You are logged in. It would be a lot easier if there was a GLOBALCHANGECOMANY(NewComapnyName). Then You could even update tables in other companys and reuse the triggers //Lars Edited by - Lars Westman on 2001 Sep 13 17:59:12

I would advise to make sure you are pointing at the correct record in the second company. After switching company, re-apply the filters (and keys), do a FIND, then do calcfields. John

quote:


CALCFIELDS(“Auftragsbestand (MW)”); Sum := “Auftragsbestand (MW)”; .CHANGECOMPANY(’’); CALCFIELDS(“Auftragsbestand (MW)”);


The idea is not bad but (I know it sounds unlogical) you have to do a CHANGECOMPANY on Debitor and not on Verkaufszeile. The following should work: CALCFIELDS(“Auftragsbestand (MW)”); Sum := “Auftragsbestand (MW)”; Debitor.CHANGECOMPANY(’’); CALCFIELDS(“Auftragsbestand (MW)”); Sum += “Auftragsbestand (MW)”; I recommend to defines a Function which loops through the companies (Mandant) and use this function in Reports, Forms etc: –


Procedure fuAuftragsbestand ("DebitorNr." : Code20) "Total Auftragsbestand" : Decimal;
Var
  Mandant : Table2000000006;
  Debitor : Table18;
BEGIN
  Clear ("Total Auftragsbestand");
  Mandant.RESET;
  Mandant.FIND('-');
  REPEAT
    Debitor.RESET;
    Debitor.CHANGECOMPANY(Mandant.Name);
    Debitor.Get ("DebitorNr.");
    Debitor.CALCFIELDS("Auftragsbestand (MW)");
    "Total Auftragsbestand" += Debitor."Auftragsbestand (MW)";
  UNTIL Company.NEXT =0;
END;

------- With best regards from Switzerland Marcus Fabian

Thanks for your answers, Fabian, i’ve tried it, but it does not work. Yes it sounds unlogical. The property “DataPerCompany” of table 18 is set to NO. So all records of this table are available in both companies. The sourcerecord of form 343 is table 18. So, there must be another way?!?!?! Greetings, Frank

Hi All, I am not 100% sure, but i think the problem is the datapercompany = NO. When i make calkfields(…) on a table the data is cought new out of the database. Variables of the same table the flowfield refers to are ignored. So if i make changecompany of the main table the changecompany works fine (thats what you say, fabian :-)) But in my case the main table has DataPerCompany = No. So i cannot make a Changecompany to it and the data will be cought out of the actual company ervery time. So, one solution is to sum the values directy out of table 37 with setrange, etc. What do you think, am i right? Greetings, Frank

Yes. You have to do a changecompany on the source table and there setragne and calcsums. Changecomapany does not affect the tables that flowfields use. You will allways get the values fråm the company that you have logged into. //Lars

You would normally do the change company on table 18. You then do a CALCFIELDS and the flow fields should now refer to the company you want to use. But when the DataPerCompany = No then it does not work, your results are always in the company that you logged in with. The two alternatives are either to have copy of table 18 with data per company set to yes. (not very good??). The best way is to define a function that will calculate the value from the base table in a Company (recreate the flowfield using Changecompnay, Setrange, and looping through and totalling up the values). As this is for a form you should remove you references from the table off the form and replace them with variables (probably an array a dimension per company). On the OnAfterGetRecord trigger of the form call your function for each company. You can use table 2000000006 Company to loop through each company. I hope this helps Paul Baxter

Ok, ok… don’t panic… :wink: As i can see… there is a modification that has changed the customer’s table from data per company yes to no… no problemo. I’ve no idea of german, but after having a look to table 18, there is a flowfield called Shipped Not Invoiced ($) (field 114) that it’s aiming at the table 37 (Sales lines), so i’ll assume that’s that one… First question: Do you want to obtain the value per company or the total value? If the flowfield don’t likes giving you the right value… forget about the flowfield and imitate it : If you need just the value for the actual company, you can make the code for imitating the flowfield as follows (if you need to get the value for ALL the companies, you’ll need also using a loop through all the companies using the CHANGECOMPANY function on the rSalesLine variable and accumulating the values in the decimal variable). Var rSalesLine : record Table 37; Valueexpected: decimal; OnAfterGetRecord() ValueExpected := 0; CLEAR (rSalesLine); RSalesLine.RESET; RSalesLine.SETCURRENTKEY(“Document Type”,“Bill-to Customer No.”,“Department Code”,“Project Code”,“Currency Code”); RSalesLine.SETRANGE(“Document Type”,RSalesLine.“Document Type”::Order); RSalesLine.SETRANGE(“Bill-to Customer No.”,“No.”); RSalesLine.SETRANGE(“Department Code”,“Department Filter”); RSalesLine.SETRANGE(“Project Code”,“Project Filter”); RSalesLine.SETRANGE(“Currency Code”,“Currency Filter”); RSalesLine.CALCSUMS(“Shipped Not Invoiced ($)”); ValueExpected := RSalesLine.“Shipped Not Invoiced ($)”; – Alfonso Pertierra apertierra@teleline.es Spain Western Computer Los Angeles, California

CHANECOMPANY doesn’t take effect on flowfields :-((( Use only CALCSUMS :-((( Business Applications Programmer Sertified Navision Developer SIA “Sintegra” Latvia

CHANECOMPANY does take effect on flowfields you must remember to use CALCFIELDS first to update the values but it does work. But when the DataPerCompany = No then it does not work. Paul Baxter