Multi field Item filter for dataport - ?best way?

jbrajbra Member Posts: 32
Using a dataport, I am trying to export only items that are members of a specific Item Categories, Product Groups or Product Lines. Each of these are a separate field in our Item table.

To exclude those that I do not want I have written the following.
Item - OnBeforeExportRecord()
IF NOT 
(
 ("Item Category Code"='1730')  OR
 ("Item Category Code"='2110')  OR

 ("Product Group Code"='241210') OR
 ("Product Group Code"='241212') OR

 ("Product Line Code"='28163201') OR
 ("Product Line Code"='28221002') OR
 ("Product Line Code"='28225002')
 )
 THEN CurrDataport.SKIP;

This works, but it's very slow. My actual list of categories and groups is much longer.
Do you have suggestions on a better way to get this done?
Thanks!

Comments

  • MBergerMBerger Member Posts: 413
    I would have added a boolean field to the Item categories, Product codes etc. to mark them for export ( or not ), then check them on the fly in your dataport
    if not ItemCategory.get("Item category code") then 
      ItemCategory.Init ;
    
    if not Productcode.get("Product Group Code") then
      ProductCode.Init ;
    
    If not ProductLine.get("Product Line Code") then
      ProductLine.Init ;
    
    if not ( Itemcategory.export OR Productcode.export OR productline.export) then
      currdataport.skip ;
    
  • mdPartnerNLmdPartnerNL Member Posts: 802
    I would presume the speed would be the same. :) Those records need to be evaluated with a filter or by your code..
  • MBergerMBerger Member Posts: 413
    I would presume the speed would be the same. :) Those records need to be evaluated with a filter or by your code..
    It might not be much of a speed boost, but the code is MUCH better maintainable, because you can now add items to include/exclude without having to change any code.
  • ReinhardReinhard Member Posts: 249
    Using a dataport, I am trying to export only items that are members of a specific Item Categories, Product Groups or Product Lines. Each of these are a separate field in our Item table.

    If you're only exporting a minority of the total records, you can avoid having to scan through the whole table by looking through each segment individually and combining them into a temp table:
    Item.MARKEDONLY(FALSE);
    Item.SETCURRENTKEY("Item Category Code");  //if available
    Item.SETFILTER("Item Category Code",'1730|2110');
    IF Item.FINDSET THEN
    REPEAT
      Item.MARK(TRUE);
    UNTIL Item.NEXT = 0;
    Item.SETRANGE("Item Category Code");
    
    Item.SETCURRENTKEY(""Product Group Code");  //if available
    Item.SETFILTER("Product Group Code",'241210|241212');
    IF Item.FINDSET THEN
    REPEAT
      Item.MARK(TRUE);
    UNTIL Item.NEXT = 0;
    Item.SETRANGE("Product Group Code");
    
    Item.SETCURRENTKEY("Product Line Code");  //if available
    Item.SETFILTER("Product Line Code",'28163201|28221002|28225002');
    IF Item.FINDSET THEN
    REPEAT
      Item.MARK(TRUE);
    UNTIL Item.NEXT = 0;
    Item.SETRANGE("Product Line Code");
    Item.SETCURRENTKEY("No.");
    
    Item.MARKEDONLY(TRUE);
    
    REPORT.RUN(123456,TRUE,TRUE,Item);
    

    Depending on the number of items and groups, and categories, this could be a lot faster.

    - Reinhard
Sign In or Register to comment.