Decision Optimization

 View Only
Expand all | Collapse all

Extracting the product of 2 numbers using IBM WTX (and summing them)

  • 1.  Extracting the product of 2 numbers using IBM WTX (and summing them)

    Posted Thu June 04, 2020 11:58 AM
    Hello, this is my first time posting to these forums, and I'm not sure if this is the best location for this sort of question.
    I'm using IBM WTX to map an XML input file to X12.
    My XML input card has a structure like this.

    <Order>
    	<Line lineNumber="1">
    		<Quantity>10</Quantity>
    		<packageQty packageNumber="P1">6</packageQty>
    		<packageQty packageNumber="P2">4</packageQty>
    		<packagingCost>2.50</packagingCost>
    	</Line>
    	<Line lineNumber="2">
    		<Quantity>10</Quantity>
    		<packageQty packageNumber="P1">10</packageQty>
    		<packagingCost>2.75</packagingCost>
    	</Line>
    	<Line lineNumber="3">
    		<Quantity>10</Quantity>
    		<packageQty packageNumber="P1">8</packageQty>
    		<packageQty packageNumber="P1">2</packageQty>
    		<packagingCost>2.65</packagingCost>
    	</Line>
    	<Line lineNumber="4">
    		<Quantity>10</Quantity>
    		<packageQty packageNumber="P1">2</packageQty>
    		<packageQty packageNumber="P1">8</packageQty>
    		<packagingCost>3.50</packagingCost>
    	</Line>
    	<Package packageNumber="P1">
    		...information about this package
    	</Package>
    	<Package packageNumber="P2">
    		...information about this package
    	</Package>
    </Order>

    For a given packageNumber, I want to sum up the product of <packageQty> * <packagingCost> for all Lines that link to this packageNumber.

    So, if I were to run this code for "P1"
    I would want (6 * 2.50) + (10 * 2.75) + (2 * 3.50)

    My first attempt at this went like this

    SUM(
    	TEXTTONUMBER(
    		EXTRACT(value:packageQty:Line:Order, 
    			package_id:packageQty:Line:Order = "P1"
    		)
    	) 
    	* 
    	TEXTTONUMBER(
    		value:packagingCost:Line:Order
    	)
    )
    

    but it returns inconsistent results.  Sometimes it only extracts 1 or 2 of the lines that link to given packageNumber.  The math always seems to come out right for whatever is being extracted, but when I run the map repeatedly against a static input file, the value of this SUM keeps changing (sometimes giving me (6 * 2.50), sometimes giving me (6 * 2.50) + (10 * 2.75) and sometimes giving me what I actually want, (6 * 2.50) + (10 * 2.75) + (2 * 3.50)

    Does anyone have any advice?



    ------------------------------
    Brian
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Extracting the product of 2 numbers using IBM WTX (and summing them)

    Posted Thu June 04, 2020 12:44 PM
    Hi,

    this is not the right forum

    Here we deal with decision optimization (CPLEX)

    regards

    ------------------------------
    ALEX FLEISCHER
    ------------------------------