Coder Challenge - Tricky Item creation

SteveSteve Member Posts: 81
Hello All,

I have a client that requires us to create thousands of item numbers based on a intelligent number scope. I need a way to create all the combinations of item numbers based on these options.

Item Number = Type + Style + Color + Option

Type
1
2
3

Style
A01 -
A02
A03
A04

Color
L01
L02
T01
T02
V01

Option
S
F
0

** There are many more options per category, but I minimized this for the example.

So I would need write code to read each of these and combine them into new item numbers.

i.e.

1A01L01S
1A01L01F
1A01L010
1A01L02S
1A01L02F
1A01L020


And so on.


Any ideas?
Steve

Comments

  • PloegPloeg Member Posts: 70
    Hi Steve,

    You could use the code below. All you need to do is create a table for each component of the item number (type, style, color, option) and fill these tables with all the available elements (for example in the Style_Table: A01, A02, ..).

    After that you create a CodeUnit or Report in which you put the code and run it. Ofcourse you might have to adjust the code depending on the types of fields you put in the new tables.
    //GeneratedItem [code (array) variable]
    IF Type_Table.FINDSET THEN
    REPEAT
      GeneratedItem[1] := Type_Table.Type;
      IF Style_Table.FINDSET THEN
      REPEAT
        GeneratedItem[2] := FORMAT(Style_Table.Style);
        IF Color_Table.FINDSET THEN
        REPEAT
          GeneratedItem[3] := FORMAT(Color_Table.Color);
          IF Option_Table.FINDSET THEN
          REPEAT
            GeneratedItem[4] := FORMAT(Option_Table.Option);
            // Insert new item
            NewItem.INIT; // NewItem [record variable of subtype Item]
            NewItem.NewItemNo := GeneratedItem[1]+GeneratedItem[2]+GeneratedItem[3]+GeneratedItem[4];
            NewItem.INSERT(TRUE);
          UNTIL Option_Table.NEXT = 0;
        UNTIL Color_Table.NEXT = 0
      UNTIL Style_Table.NEXT = 0;
    UNTIL Type_Table.NEXT = 0;
    

    Hope this helps!
  • aseigleaseigle Member Posts: 207
    While this doesn't answer your question exactly, have you considered using Non-stock items instead. If you create 10's of thousands of records for things that MIGHT be sold or purchased, then anything that uses the Item table will take longer. Instead, create them as non-stocks, and when necessary, convert to Item. You might have to do something with the Item Nos. to meet your requirement, but surely is a better approach.
  • SteveSteve Member Posts: 81
    I believe i have resolved this. I will post the code once tested and signed off.
    Steve
  • apertierraapertierra Member Posts: 61
    What's the difficulty on this: it's just repeats inside repeats to obtain the 180 different items from it.
    var vtype : code[10]  dimension [3];
         vstyle: code[10] dimension[5];
         vcolor: code[10] dimension[5];
         voption: code[10] dimension[3];
         Auxcounters integer dimension 4;
         vPartNo: code[20];
    BEGIN
      CLEAR (AuxCounters);
      CLEAR (Vtype);
      vType[1] := '1';
      vType[2] := '2';
      vType[3] := '3';
      VStyle[1] := 'A01';
       // ..... ETC... initialize all the values on the arrays for the info you need to use for the part no. for each of the variables, vcolor, voption..
    
      Auxcounters[1] := 1;
      REPEAT 
        Auxcounters[2] := 1;
         REPEAT
    
        Auxcounters[3] := 1;
         REPEAT
    
          Auxcounters[4] := 1;
          REPEAT
    
              vPartNo := COPYSTR(VType[Auxcounters[1]] + vStyle[Auxcounters[2]] + vColor[Auxcounters[3] + vOption[AuxCounters[4]],1,MAXSTRLEN(VPartNo));
              clear (vItem);
              vItem.INIT;
              VItem.TRANSFERFIELDS(Reference_Item_variable_to_copy_default_values_from);
              vItem."No." := vPartNo;
              vItem.INSERT(TRUE);
           Auxcounters[4] += 1;
          UNTIL (Auxcounters[4] > 5);
    
           Auxcounters[3] += 1;
         UNTIL (Auxcounters[3] > 5);
      
           Auxcounters[2] += 1;
         UNTIL (Auxcounters[1] > 5);
    
        Auxcounters[1] += 1;
    
      UNTIL (AuxCounters[1] > 3); 
      
    END;
    
Sign In or Register to comment.