Report Matrix Problem

bangswitbangswit Member Posts: 265
hai there
i want to create report like this

this is from table 39
if my code like this
i:=1;
SPH.FIND('-');
REPEAT
// SETRANGE("Shortcut Dimension 1 Code",SPH.Code);
// IF FIND('-') THEN
AmountLoc:=Quantity;
LocName := SPH.Code;
i:= i + 1;
UNTIL (SPH.NEXT = 0) OR (i > SPH.COUNT);

it gonna be
Category A Category B
Item A 15 20
Item B 15 20
Item C 15 20
Item D 15 20
Item E 15 20
Item F 15 20
--> All Lines in Purchase Lines will be showed

but if i Add the setrange
i:=1;
SPH.FIND('-');
REPEAT
SETRANGE("Shortcut Dimension 1 Code",SPH.Code);
IF FIND('-') THEN
AmountLoc:=Quantity;
LocName := SPH.Code;
i:= i + 1;
UNTIL (SPH.NEXT = 0) OR (i > SPH.COUNT);


the result is like this
Category A Category B
Item A 15 20

all I want is like this
Category A Category B
Item A 15 0
Item B 0 20

What mistaken I have made?
please help

Comments

  • ufukufuk Member Posts: 514
    It is difficult to read your code, write it in Code tag for better readability.

    You have to insert a repeat.. until loop after getting the first record. Otherwise you are only on the first record. Also you have to use THEN BEGIN..END; if your statements is more than one line. Otherwise code is executed starting from the second line below the if..then block.
    Ufuk Asci
    Pargesoft
  • bangswitbangswit Member Posts: 265
    i:=1;
    SPH.FIND('-');
    REPEAT
    // SETRANGE("Shortcut Dimension 1 Code",SPH.Code);
    // IF FIND('-') THEN
    AmountLoc:=Quantity;
    LocName := SPH.Code;
    i:= i + 1;
    UNTIL (SPH.NEXT = 0) OR (i > SPH.COUNT);
    --> this code display all records in Purchase line
    i:=1;
    SPH.FIND('-');
    REPEAT
    SETRANGE("Shortcut Dimension 1 Code",SPH.Code);
    IF FIND('-') THEN
    AmountLoc:=Quantity;
    LocName := SPH.Code;
    i:= i + 1;
    UNTIL (SPH.NEXT = 0) OR (i > SPH.COUNT);
    --> this gonna be like this
    No Category A Category B
    Item A 15 20

    what i want is like this
    No Category A Category B
    Item A 15 0
    Item B 0 20
  • ufukufuk Member Posts: 514
    It is difficult to understand the problem from the code part you sent but it seems like the problem is with the FIND part. This could cause getting out of dataset or returning back to the first one. Use a record variable instead of dataitem itself like.

    varItem.GET("No.");
    varItem.SETRANGE(...);
    IF varItem.FIND('-')
    ...
    Ufuk Asci
    Pargesoft
  • bangswitbangswit Member Posts: 265
    so you mean, the code should be like this ?
    FYI, SPH --> table dimension value
    before this code, exactly in on pre dataitem , I already filter it
    SPH.SETRANGE("Global Dimension Code",1);
    i:=1;
    SPH.GET("Dimension Code",Code);
    SPH.FIND('-');
    REPEAT
    SETRANGE("Shortcut Dimension 1 Code",SPH.Code);
    IF FIND('-') THEN
    AmountLoc:=Quantity;
    LocName := SPH.Code;
    i:= i + 1;
    UNTIL (SPH.NEXT = 0) OR (i > SPH.COUNT);
  • ufukufuk Member Posts: 514
    Bangwit, it seems there are many problems regarding your loop, array variable usage and value assignments. I recommend you work on development manuals. They could help you more than what I write here. It is important to understand what you are doing.
    bangswit wrote:
    i:=1;
    SPH.GET("Dimension Code",Code);
    SPH.FIND('-'); // not necessary to loop, because you used GET word above and it means you have only one record in your dataset.
    REPEAT
    SETRANGE("Shortcut Dimension 1 Code",SPH.Code); // which record you are filtering here?
    IF FIND('-') THEN // which record do you want to loop through? if you have more than one record found, what will you do?
    AmountLoc:=Quantity; // why do you use array here? you want to get only first value or sum all?
    LocName := SPH.Code;
    i:= i + 1;
    UNTIL (SPH.NEXT = 0) OR (i > SPH.COUNT); // isn't next statement enough?

    Maybe you can write something like:
    SPH.GET("Dimension Code",Code);
    varRecord.SETRANGE("Shortcut Dimension 1 Code",SPH.Code); 
    IF varRecord.FIND('-') THEN BEGIN
      i:= i + 1; //assuming you increment i per SPH
      LocName[i] := SPH.Code;
      REPEAT
         AmountLoc[i]+=varRecord.Quantity;    
      UNTIL varRecord.NEXT = 0; 
    END;
    
    Ufuk Asci
    Pargesoft
  • bangswitbangswit Member Posts: 265
    actually, this is my code
    Purchase Line - OnPreDataItem()
    SPH.SETRANGE(SPH."Global Dimension No.",1);
    SPH.FIND('-');

    Cylinder.SETRANGE(Cylinder."Global Dimension No.",2);
    Cylinder.FIND('-');

    i:= 1;
    REPEAT
    LocName := SPH.Code;
    i:= i +1;
    UNTIL
    (SPH.NEXT = 0) OR (i > SPH.COUNT);

    Purchase Line - OnAfterGetRecord()
    {
    i:=1;
    SPH.FIND('-');
    REPEAT
    SETRANGE("Shortcut Dimension 1 Code",SPH.Code);
    IF FIND('-') THEN
    AmountLoc:=Quantity;
    LocName := SPH.Code;
    i:= i + 1;
    SETRANGE("Shortcut Dimension 1 Code");
    UNTIL (SPH.NEXT = 0) OR (i > SPH.COUNT);
    }

  • bangswitbangswit Member Posts: 265
    i:=1;
    SPH.GET("Dimension Code",Code);
    SPH.FIND('-'); // not necessary to loop, because you used GET word above and it means you have only one record in your dataset.
    REPEAT
    SETRANGE("Shortcut Dimension 1 Code",SPH.Code); // which record you are filtering here? --> Purchase Line records
    IF FIND('-') THEN // which record do you want to loop through? if you have more than one record found, what will you do?
    AmountLoc:=Quantity; // why do you use array here? you want to get only first value or sum all? --> this this the cross from matrix so, i use array
    LocName := SPH.Code;
    i:= i + 1;
    UNTIL (SPH.NEXT = 0) OR (i > SPH.COUNT); // isn't next statement enough? --> yes
  • ufukufuk Member Posts: 514
    Bangwit, you should read my posts above :D

    There are many problems in that code and first of all you should study training manuals as I said before. We can correct your code here but it'll not be a permanent solution. You should better understand faults in code yourself and correct them by understanding what you are really doing.
    Ufuk Asci
    Pargesoft
  • bangswitbangswit Member Posts: 265
    I'm using 2 array
    filtering array 1
    SPH.SETRANGE(SPH."Global Dimension No.",1);
    SPH.FIND('-');

    filtering array 2
    Cylinder.SETRANGE(Cylinder."Global Dimension No.",2);
    Cylinder.FIND('-');

    i:= 1;
    REPEAT
    LocName := SPH.Code;
    i:= i +1;
    UNTIL
    (SPH.NEXT = 0) OR (i > SPH.COUNT);

    my problem is... how to use those 2 arrays in execution

    i:=1;
    j:=1;
    SPH.FIND('-');
    Cylinder.FIND('-');
    REPEAT
    RL.SETRANGE(RL."Shortcut Dimension 1 Code",SPH.Code);
    RL.SETRANGE(RL."Shortcut Dimension 2 Code",Cylinder.Code);
    IF RL.FIND('-') THEN
    AmountLoc:=RL.Quantity;
    i:= i + 1;
    RL.NEXT;
    UNTIL (SPH.NEXT = 0);
Sign In or Register to comment.