Optimization of codes on report

liizzliizz Member Posts: 125
Hi all,

I wish to reduce the codes as the only part which is changing in the SETRANGE is the Dimension Code part(highlighted in bold) and thus retrieving the corresponding Dimension Value Code from Posted Document Dimension table. This piece of code is being used on a report.

PostedDocDimension.SETRANGE("Table ID",110);
PostedDocDimension.SETRANGE("Document No.","Sales Shipment Header"."No.");
PostedDocDimension.SETRANGE("Dimension Code",'D');
IF PostedDocDimension.FINDFIRST THEN
GTxt[1]:=PostedDocDimension."Dimension Value Code";

PostedDocDimension.SETRANGE("Table ID",110);
PostedDocDimension.SETRANGE("Document No.","Sales Shipment Header"."No.");
PostedDocDimension.SETRANGE("Dimension Code",'L');
IF PostedDocDimension.FINDFIRST THEN
GTxt[2]:=PostedDocDimension."Dimension Value Code";

PostedDocDimension.SETRANGE("Table ID",110);
PostedDocDimension.SETRANGE("Document No.","Sales Shipment Header"."No.");
PostedDocDimension.SETRANGE("Dimension Code",'H');
IF PostedDocDimension.FINDFIRST THEN
GTxt[3]:=PostedDocDimension."Dimension Value Code";

Is there a possible way to optimize the codes as I am fetching from the same Table ID and Document No..

Please help me.

Thanks
Liizz

Comments

  • lvanvugtlvanvugt Member Posts: 774
    What about:
    PostedDocDimension.SETRANGE("Table ID",110);
    PostedDocDimension.SETRANGE("Document No.","Sales Shipment Header"."No.");
    
    PostedDocDimension.SETRANGE("Dimension Code",'D');
    IF PostedDocDimension.FINDFIRST THEN
      GTxt[1]:=PostedDocDimension."Dimension Value Code";
    
    PostedDocDimension.SETRANGE("Dimension Code",'L');
    IF PostedDocDimension.FINDFIRST THEN
      GTxt[2]:=PostedDocDimension."Dimension Value Code";
    
    PostedDocDimension.SETRANGE("Dimension Code",'H');
    IF PostedDocDimension.FINDFIRST THEN
      GTxt[3]:=PostedDocDimension."Dimension Value Code";
    
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • liizzliizz Member Posts: 125
    No, this is not working when I apply your codes.
  • dansdans Member Posts: 148
    Is there reason why you don't filter the Line No. ? Then you could use GET instead of filter.

    Below code will not work if you have multiple records per Dimension Code.
    PostedDocDimension.SETRANGE("Table ID",110);
    PostedDocDimension.SETRANGE("Document No.","Sales Shipment Header"."No.");
    PostedDocDimension.SETFILTER("Dimension Code",'%1|%2|%3','D','L','H');
    IF PostedDocDimension.FINDSET THEN
      REPEAT
         CASE PostedDocDimension."Dimension Code" OF
           'D' :
            GTxt[1]:=PostedDocDimension."Dimension Value Code";
           'L' :
            GTxt[2]:=PostedDocDimension."Dimension Value Code";
           'H' :
            GTxt[3]:=PostedDocDimension."Dimension Value Code";
         END;
      UNTIL PostedDocDimension.NEXT = 0;
    
    Microsoft Certified IT Professional for Microsoft Dynamics NAV

    Just a happy frood who knows where his towel is
Sign In or Register to comment.