Grouping by Line no.

Get our Free Newletter

Don't you have the time to be online here at DUG every day? So how do you follow what is going on in the Dynamics industry and community?
If you subscribe to the DUG Newsletter then you can relax! We will make sure that you don't miss the big news!

Check out our
Newsletter Subscription Center
page a complete list of our different newsletters.

Solution (Verified) This post has 1 verified solution | 4 Replies | 2 Followers

Male
94 Posts
1,050 Points
Joined: 2011-1-24
Last Online:
2013-2-21 11:18
Location: HYDERABAD,INDIA
RS posted on 2012-10-4 18:50

Hi

In coding i have used a temporary record variable with the Purchase line and I'm transferring the records from purchase line to the temporary Purch table(specific records).now the temp Purch line contains the records like below example

 

Doc No.  Line no. Qty

Doc 1      10000     10

Doc1       20000      12

Doc1       30000      15

Doc2       10000     5

Doc3       20000      10

now i want to sum the qty by line no. i.e 10000 15 ,20000  22, 30000 15 ,if the line no. is same i have to sum the qty irrespective of doc no.s .

 

 

Solution (Verified) Verified Solution

27 Posts
340 Points
Joined: 2011-8-12
Last Online:
2013-6-10 22:41
Location: ...
Solution (Verified) rriinnoo replied on 2012-10-5 20:31
Verified by RS

Hello,

 

i think you have at least 4 options order by elegance and style ascending:

1. google "Navision group by" there are tons of threads

2. if you have a table with the right key, use CALCSUM as Amol suggest

3. Create a SQL view that do the group by and then use NAV to show the output

4. use a nested loop to create another tempTable with the result of the group by (this is a dirty solution )

Something like that:

WITH yourTempTable

  DO BEGIN

    REPEAT

      yourTempTable.FINDSET();

      yourTempTable.SETRANGE(line,line) ;

      IF yourTempTable.FINDSET() THEN BEGIN

          yourTempTabletmp.INIT();

        REPEAT

         yourTempTabletmp.line := yourTempTable.line;

          yourTempTabletmp.doc := yourTempTable.doc;

          // sum qty

          yourTempTabletmp.qty := yourTempTabletmp.qty + yourTempTable.qty;

        UNTIL (yourTempTable.NEXT = 0);

        // fill another table after each iteration

        yourTempTabletmp.INSERT();

        //delete processed lineNo and go next

        yourTempTable.DELETEALL();

        RESET();

        yourTempTable.NEXT();

      END;

    UNTIL (  yourTempTable.ISEMPTY() )

  END;

 

yourTempTabletmp.FINDSET();

REPEAT

  MESSAGE('%1 %2 %3',yourTempTabletmp.doc,yourTempTabletmp.line,yourTempTabletmp.qty);

UNTIL (yourTempTabletmp.NEXT = 0 );

 

 

Hope this can give you some ideas how to move forward ...

All Replies

Male
2,350 Posts
34,180 Points
Joined: 2006-4-10
Last Online:
2013-6-19 14:43
Location: Pune India
Moderator
Amol replied on 2012-10-5 3:57

Hi,

What problem you are facing now ??

-Amol

http://dynamicsuser.net/blogs/amol

Don't forget to  the post(s) that solved your problem

Male
94 Posts
1,050 Points
Joined: 2011-1-24
Last Online:
2013-2-21 11:18
Location: HYDERABAD,INDIA
RS replied on 2012-10-5 13:50

How to sum the qty if the line nos are same and doc nos are different.

Male
2,350 Posts
34,180 Points
Joined: 2006-4-10
Last Online:
2013-6-19 14:43
Location: Pune India
Moderator
Amol replied on 2012-10-5 14:22

SET Key on the required fields and do the grouping....

-Amol

http://dynamicsuser.net/blogs/amol

Don't forget to  the post(s) that solved your problem

27 Posts
340 Points
Joined: 2011-8-12
Last Online:
2013-6-10 22:41
Location: ...
Solution (Verified) rriinnoo replied on 2012-10-5 20:31
Verified by RS

Hello,

 

i think you have at least 4 options order by elegance and style ascending:

1. google "Navision group by" there are tons of threads

2. if you have a table with the right key, use CALCSUM as Amol suggest

3. Create a SQL view that do the group by and then use NAV to show the output

4. use a nested loop to create another tempTable with the result of the group by (this is a dirty solution )

Something like that:

WITH yourTempTable

  DO BEGIN

    REPEAT

      yourTempTable.FINDSET();

      yourTempTable.SETRANGE(line,line) ;

      IF yourTempTable.FINDSET() THEN BEGIN

          yourTempTabletmp.INIT();

        REPEAT

         yourTempTabletmp.line := yourTempTable.line;

          yourTempTabletmp.doc := yourTempTable.doc;

          // sum qty

          yourTempTabletmp.qty := yourTempTabletmp.qty + yourTempTable.qty;

        UNTIL (yourTempTable.NEXT = 0);

        // fill another table after each iteration

        yourTempTabletmp.INSERT();

        //delete processed lineNo and go next

        yourTempTable.DELETEALL();

        RESET();

        yourTempTable.NEXT();

      END;

    UNTIL (  yourTempTable.ISEMPTY() )

  END;

 

yourTempTabletmp.FINDSET();

REPEAT

  MESSAGE('%1 %2 %3',yourTempTabletmp.doc,yourTempTabletmp.line,yourTempTabletmp.qty);

UNTIL (yourTempTabletmp.NEXT = 0 );

 

 

Hope this can give you some ideas how to move forward ...

Page 1 of 1 (5 items) | Get this RSS feed | Bookmark and Share