Here you add another procedure call that illustrates some of the block types you studied in this section and some of the list handling functions summarized in Introduction to ABL. The procedure looks at the Warehouse and Bin tables to see which Warehouses can and cannot supply the Items for a given Order.

To modify the h-OrderCalcs.p procedure, add the new statements in bold type:
DEFINE INPUT PARAMETER piOrderNum AS INTEGER NO-UNDO.
DEFINE OUTPUT PARAMETER pdOrderPrice AS DECIMAL NO-UNDO.
DEFINE OUTPUT PARAMETER pdOrderTotal AS DECIMAL NO-UNDO.
DEFINE OUTPUT PARAMETER pcWarehouseList AS CHARACTER NO-UNDO.

DEFINE OUTPUT PARAMETER pcBestWarehouse AS CHARACTER NO-UNDO.


DEFINE VARIABLE cItemList AS CHARACTER NO-UNDO.


FIND order WHERE Order.orderNum = piOrderNum NO-ERROR.

FOR EACH OrderLine OF Order:
  ASSIGN pdOrderTotal = pdOrderTotal + OrderLine.ExtendedPrice
    pdOrderPrice = pdOrderPrice + OrderLine.Price * OrderLine.Qty
    cItemList = cItemList +
      (IF cItemList = "" THEN "" ELSE ",") + STRING(ItemNum).

END.

RUN h-BinCheck.p (INPUT cItemList, OUTPUT pcWarehouseList, OUTPUT
pcBestWarehouse).

The additional code defines two new OUTPUT parameters and a new variable.

Then, as part of the ASSIGN statement, it constructs a list of Item numbers for the OrderLines of the Order. To make a list, it uses a CHARACTER variable cItemList. The assignment statement effectively means:

  1. Take the current value of the cItemList variable (which is initially blank).
  2. If it is blank, then append a blank value to it (this is just a no-op condition for the IF-THEN-ELSE statement, which requires both a THEN phrase and an ELSE phrase). Otherwise, if there is already something in the list, append a comma to it to separate the Items.
  3. Use the STRING built-in function to convert the integer ItemNum to a CHARACTER value and append it to the variable. (There are other built-in functions like this one named DECIMAL, INTEGER, DATE, and LOGICAL to convert character strings to those other data types as well.)

At the end of the FOR EACH block, cItemNum holds a comma-separated list of all the Items for the current Order.

Finally, the procedure runs another procedure, h-BinCheck.p, which you write next.

To write the h-BinCheck.p procedure:

  1. Save this modified version of h-OrderCalcs.p.
  2. Open a New Procedure Window and start to write h-BinCheck.p with the following code. Add each new group of statements to the procedure as they are discussed:
    /* h-BinCheck.p */
    
    DEFINE INPUT PARAMETER pcItemList AS CHARACTER NO-UNDO.
    DEFINE OUTPUT PARAMETER pcWarehouseList AS CHARACTER NO-UNDO.
    DEFINE OUTPUT PARAMETER pcBestWarehouse AS CHARACTER NO-UNDO.
    
    DEFINE VARIABLE iEntry AS INTEGER NO-UNDO.
    DEFINE VARIABLE iItemNum AS INTEGER NO-UNDO.
    DEFINE VARIABLE iWHQty AS INTEGER NO-UNDO.
    DEFINE VARIABLE iWHNum AS INTEGER NO-UNDO.
    DEFINE VARIABLE iBestWH AS INTEGER NO-UNDO.
    DEFINE VARIABLE cBestList AS CHARACTER NO-UNDO.

This procedure takes the list of item numbers as an INPUT parameter and returns two CHARACTER parameters. The various variables are used throughout the procedure.