Did you have to strategically replace J primitives
with inconspicuous monikers? It looks like a narration,
and presumably gives an idea whats going on to an
outsider. But for someone who knows J, it is like
trying to decipher cockney rhyming :) . It is an
interesting approach anyways.
----- Original Message ----
> From: Alex Rufon <[EMAIL PROTECTED]>
>
> Ok. I am being burdened by my ignorance that its creating more questions
> than I can handle. What I mean is that I now have a feeling that I am
> solving the problem the wrong way. I am going to explain the problem as
> a whole so that I can get an idea on how advanced J programmers would
> solve it. You can also see from my explanations below how I use J to
> solve problems too. Any advice/criticism are welcome and appreciated.
>
> What I am doing right now is reviewing my existing codes and trying to
> optimize them by removing the for loops. This came about when I had a
> complaint from some of my users that some operations were taking around
> 30 minutes to complete. The code below is running fine but I'm using it
> as an example because this type of loop is prevalent in my projects:
> NB. ======== START OF CODE ========
> NB. STEP 1d: Make copies of DUV by the number of destination declared
> sids=. searchLOOKUP 'DUV'
> masks=. (BOM_USAGE_CLASS colsfrom bomv) member sids
> if. sum across masks do.
> NB. STEP 1b1: Work only with rows that matches
> wrkbom=. masks copy bomv
> wrkvbom=. (0,behead shape wrkbom) shape 0
> for_data. wrkbom do.
> NB. Check if we have a UV Summary defined for current GMC
> msk=. (atomize BOM_GEN_MAT_ID colsfrom data) = DUV_GEN_MAT_ID
> colsfrom DUVV
> if. tally where msk do.
> NB. Copy the current bom to the number of defined destination
> temp=. (tally where msk) copy tomatrix data
> NB. Update the destination code to the ship to customer code
> wired=. DUV_CUSTOMER_CODE colsfrom DUVV selectrows where msk
> if. 1 = shape wired do.
> wired=. atomize wired
> end.
> temp=. temp replacecols BOM_DESTN_CODE;wired
> NB. Now save the current bom
> wrkvbom=. wrkvbom atop temp
> end.
> end.
> NB. Now remove the processed bom's then add the new BOM's
> bomv=. bomv selectrows where not masks
> bomv=. bomv atop wrkvbom
> end.
> NB. ======== END OF CODE ========
>
> First off, I know that you'll be horrified because it doesn't look like
> any J script that you know. :P Hehehehehehe.
>
> In summary, what this code does is expands a list of materials to the
> number of destination. To illustrate, take the following data:
> NB. List of Destination by Generic Material ID:
> DUV_FIELDNAMES,DUVD
> +--------------+-------------+-----------------+
> |DUV_GEN_MAT_ID|DUV_CITY_CODE|DUV_CUSTOMER_CODE|
> +--------------+-------------+-----------------+
> |1002091 |OSAKA |0000020071 |
> +--------------+-------------+-----------------+
> |1002091 |NODA - SHI |0000020073 |
> +--------------+-------------+-----------------+
> NB. The numeric equivalent of the data above is:
> DUVV
> 1002091 195 156
> 1002091 196 157
>
> NB. List of Materials
> (<:BOM_USAGE_CLASS,BOM_GEN_MAT_ID,BOM_DESTN_CODE) { "1
> BOM_FIELDNAMES,ADBOMDTLD
> +---------------+--------------+--------------+
> |BOM_USAGE_CLASS|BOM_GEN_MAT_ID|BOM_DESTN_CODE|
> +---------------+--------------+--------------+
> |DUV |1002091 | |
> +---------------+--------------+--------------+
> (<:BOM_USAGE_CLASS,BOM_GEN_MAT_ID,BOM_DESTN_CODE) { "1 ADBOMDTLV
> 139 1002091 0
>
> NB. Result of operation
> (<:BOM_USAGE_CLASS,BOM_GEN_MAT_ID,BOM_DESTN_CODE) { "1
> BOM_FIELDNAMES,BCONSUMPD
> +---------------+--------------+--------------+
> |BOM_USAGE_CLASS|BOM_GEN_MAT_ID|BOM_DESTN_CODE|
> +---------------+--------------+--------------+
> |DUV |1002091 |0000020071 |
> +---------------+--------------+--------------+
> |DUV |1002091 |0000020073 |
> +---------------+--------------+--------------+
> (<:BOM_USAGE_CLASS,BOM_GEN_MAT_ID,BOM_DESTN_CODE) { "1 BCONSUMPV
> 139 1002091 156
> 139 1002091 157
>
> So basically, the code above takes the list of materials and the number
> of matching destination and combine them. So in this case, we only get
> two resulting records because we only have 1 material and 2 destination.
> There will be cases where the list of materials will have repeating
> BOM_GEN_MAT_ID or a material that does not match any entry in the
> destination.
>
> As you can see, my approach is using traditional programming technique
> where I would loop through the list of materials and check if there is a
> matching material in the destination. If there are, I would then
> replicate the material to the number of matching destination and copy
> the DUV_CUSTOMER_CODE to the BOM_DESTN_CODE as is, otherwise I'll just
> continue to the next material in the list.
>
> Unfortunately, this is only for BOM_USAGE_CLASS of DUV or by
> Destination. I also have permutations of this like:
> 1. SUV - by size
> 2. SDUV - by size and destination
> 3. AUV - by article
> 4. ASDUV - by article, size and destination
> 5. ASSTPOUV - by article, size, sub-style, and purchase order
> 6. etc.
>
> The combination of Usage Class is mind boggling and the merchandisers
> are coming up with new ways to make my life difficult. So here is the
> problem, I think I am using J to solve the problem the wrong way. For
> example, for ASDUV, I would loop by:
> NB. Pseudo code
> for_article. articles do.
> NB. Do something for articles
> for_size. sizes do.
> NB. Do something for sizes
> for_destination. destinations do.
> NB. Do something for destination and save it
> end.
> NB. Save changes for size and destination
> end.
> NB. Save changes for colorway, size and destination
> end.
>
> So as you can see, I'll be looping 3 levels deep and one local variable
> for each level and updates to the parent variable until the whole
> operation is complete.
>
> As I said, any suggestion, insights and/or criticism are appreciated.
> Thanks.
>
> r/Alex
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm