GetResultSets unexpected result sets

SOLVED

I have 2 sets of GetResultSets that produce different results.  Could some please explain to me why these 2 examples of GetResultSet methods return different result sets? I've read some examples, including Advanced GetResultSets() by a Sage developoer Bret Richion, dlech's example here, and SY_SERVICE section of object references but i'm stuck in understanding it.

Below are 2 versions of the same codes, one mimics Bret and others mimic dlech.  The script tries to get a list of SalesOrderNo for CustomerNo TEMP from SO_SalesOrder, just as the aforementioned 2 guys showed in their examples.   Basically, I'm confused because Bret clarifies in his post that that's how it should be done to get a list of sales order numbers for a particular CustomerNo but his way produces an incorrect result set, while dlech's way correctly produces an expected result set.  

Could someone please help me understand the differences?  Thank you!


Parameter setting based on Bret's example: 

Set oBoObj =  oBoObj =oSession.AsObject(oSession.GetObject("SO_SalesOrder_bus"))

strCustomerNo = "TEMP"

orderFilter = "OrderType$ = """ & "whatever it is" & """"

intColLenCustomerNo = oFileObj.GetColumnLength("AR_Customer", "CustomerNo$")

Pad = String (intColLenCustomerNo - Len(strCustomerNo), NUL) ' NUL = Chr(0) = NULL
CustNoPadded = strCustomerNo & Pad

retVal = oBoObj.GetResultSets("SalesOrderNo$", "Nothing$", retOrderList, retJUNK, orderFilter, "00" + strCustomerNo, CustNoPadded + HexFE, "kCUSTOMER")

  • Source key =  "nothing$"
  • Begin$ = "00TEMP"
  • End$  = "TEMP" + 16 CHR(0) + Chr(254)
  • Alt Index "KCUSTOMER" (Div+CustNo+SoNo)
  • Filter = Non-key columns   
  • With this method, the it returns a list of SalesOrderNo that have CustomerNo equal to or larger than the value "TEMP" (e.g. TEMQ, TFMP, and all CustomerNo starting with U, V,W, X, Y, and Z ).  


Parameter setting based on dlech's example: 

orderFilter = "CustomerNo$ = """ & "TEPM" & """ AND OrderType$ = """ & "whatever it is" & """""

retVal = oBoObj.GetResultSets("SalesOrderNo$", "Nothing$", retOrderList, retJUNK, orderFilter, "", "", "")

  • Source key = "SalesOrderNo$"
  • Begin$ = ""
  • End$ = ""
  • Alt Index = ""
  • Filter = CustomerNo$ (surrounded by double quotes) 
  • With this method, it returns only the SalesOrderNos for TEMP, nobody else.  

EDIT-5/6/2019----------- I found out that the oddities also was caused by how CustomerNo was retrieved from the record.  I noticed that I had GetValue"s" instead of GetValue, thereby padding CustomerNo with Chr(138).  Don't be like me and check the methods, variable name/type agreement, and any other typos everyone!


  • +1
    verified answer

    You need to prefix the END$ (argument 7) with the ARDivisionNo which is "00" for you. Otherwise you're telling it to Begin selecting where Div = 00 and Cust No = TEMP but to End where Div = TE and the Cust No = MP. Therefore you get everything from 00-TEMP to TE-MP. That's why all these customer numbers > TEMP were evaluated. Putting it together:

    r=oBoObj.GetResultSets("SalesOrderNo$", "Nothing$", retOrderList, retJUNK, orderFilter, "00" + strCustomerNo, "00" + CustNoPadded + HexFE, "kCUSTOMER")

    DLech's code includes the Customer No in the filter instead of specifying the BEGINning Div + Cust No (Arg 6) and ENDing Div + Cust No (Arg 7). Also by not specifying an Alt Index, he implicitly uses the default KPrimary index. His code is just fine. But if you have thousands or more records to evaluate you'll see the performance difference of using Bret's way which takes advantage of the kCUSTOMER index. Also if your requirements need you to evaluate a range of customers instead of a single customer then you should use the BEGIN and END . 

    Hope that helps.

  • 0 in reply to Alnoor

    Thanks Alnoor!  I understand now and able to get the records i need.