How To Use Indexing Rules (Example 2)

The following document explains how complex indexing works in map editor

The input file is an XML IDoc file and we want to group all LOT_NUMBER fields together along with the quantity accumulated per Lot Number.  The only way to do this is using indexing within the Extended Rules as shown below.

INPUT IDoc XML File

<ZEXPINV04>
      <IDOC>
            <E1EDP01>           Line item 10
                  <MENGE>
                  <MATNR>
                  <ZE1PALLET>
                  |     <MATNR>
                  |     <LOT_NUMBER>    Lot number 1000
                  |_<LOT_QTY>       Quantity 25
                  <ZE1PALLET>
                  |     <MATNR>
                  |     <LOT_NUMBER>    Lot number 1000
                  |_<LOT_QTY>       Quantity 25
            <E1EDP01>           Line item 20
                  <MENGE>
                  <MATNR>
                  <ZE1PALLET>
                  |     <MATNR>
                  |     <LOT_NUMBER>    Lot number 1001
                  |_<LOT_QTY>       Quantity 10
                  <ZE1PALLET>
                  |     <MATNR>
                  |     <LOT_NUMBER>    Lot number 1002
                  |_<LOT_QTY>       Quantity 30

OUTPUT XML File Expectation

<CreateShipment>
      <DataArea>
            <Shipment>
                  <Items>
                        <Item>
                              <Product>
                                    <ProductCode>
                                    <Qty>
                                    <LotAllocation>
                                    |     <LotAllocations>
                                    |           <LotLineNumber>
                                    |           <BatchNumber>    Lot number 1000
                                    |___<LotQuantity>    Lot quantity 50
                              <Product>
                                    <ProductCode>
                                    <Qty>
                                    <LotAllocation>
                                    |     <LotAllocations>
                                    |           <LotLineNumber>
                                    |           <BatchNumber>    Lot number 1001
                                    |___<LotQuantity>    Lot quantity 10
                                    <LotAllocation>
                                    |     <LotAllocations>
                                    |           <LotLineNumber>
                                    |           <BatchNumber>    Lot number 1002
                                    |___<LotQuantity>    Lot quantity 30

Extended Rules

Pre-Session
integer i;
integer j;

i = 1;
j = 1;

ZEXPINV04
On Begin
string[14] a_s_matnr[9999];
integer intL2;

a_s_matnr[1] = "";
intL2 = 1;

E1EDP01
On Begin
// SF 2016/03/04
// Set variables for lot allocation and an string array to store the current lot allocation
string[10] cur_lot_number;
string[10] prev_lot_number;
string[10] a_s_lot[9999];

integer p01_count;
integer v_i_lot_count;
integer a_i_lot_qty[9999];
integer v_i_last_pos;
integer v_tmp_qty;

cur_lot_number = "";
prev_lot_number = "";
a_s_lot[1] = "";

intL2 = 1;
p01_count = 1;
v_i_lot_count = 0;
a_i_lot_qty[1] = 0;
v_i_last_pos = 0;
v_tmp_qty = 0;

On End
IF #MATNR != "" THEN
  BEGIN
    $temp_item[i][j].#TEMP_MATNR = trimleft(#MATNR,"0");
    $temp_item[i][j].#TEMP_MENGE = #MENGE;
    j = j + 1;
  END

ZE1PALLET
On Begin
// SF 2016/03/04
// Set the variables for the quantity count and the last lot allocation to write out
integer count_qty;
integer v_i_last_pall_tot;

count_qty = 0;
v_i_last_pall_tot = 0;
v_i_last_pos = 0;

On End
// Set variables for the lotline number increment
real v_r_p01_count;
v_r_p01_count = 0;

if cur_lot_number != prev_lot_number then
  begin
    $temp_lotallocations[i][j][p01_count].#TEMP_BATCH = a_s_lot[v_i_lot_count];
    v_r_p01_count = (p01_count * 10);
    ntoa(v_r_p01_count,$temp_lotallocations[i][j][p01_count].#TEMP_LOTLINE);
    p01_count = p01_count + 1;
  end

//*** Output the Lot Allocation Quantities ***/
intL2 = v_i_last_pos;

while intL2 <= v_i_lot_count do
  begin
    v_i_last_pall_tot = v_i_last_pall_tot + a_i_lot_qty[intL2];

   if cur_lot_number = prev_lot_number then
     begin
       $temp_lotallocations[i][j][p01_count-1].#TEMP_QTY = v_i_last_pall_tot;
     end
   else
     begin
       $temp_lotallocations[i][j][p01_count-1].#TEMP_QTY = v_i_last_pall_tot;
     end

   //******* Do Not Delete *******
          intL2 = intL2 + 1;
          if intL2 = 100 then break;
   //*****************************
  end

MATNR:3.MATNR:3
v_i_lot_count = v_i_lot_count + 1;
count_qty = count_qty + 1;

a_s_matnr[v_i_lot_count] = trimleft(#MATNR:3,"0");

LOT_NUMBER.LOT_NUMBER
a_s_lot[v_i_lot_count] = #LOT_NUMBER;

cur_lot_number = a_s_lot[v_i_lot_count];
prev_lot_number = a_s_lot[v_i_lot_count-1];

QTY.QTY
// SF 2016/03/04
// Accumulate lot allocation quantities if the lot numbers are the same
if cur_lot_number = prev_lot_number then
  begin
    a_i_lot_qty[count_qty] = a_i_lot_qty[count_qty] + #QTY;
    v_i_last_pos = count_qty;  // store the current count of lot allocation loop
  end

// Accumulate lot allocation quantities if the lot numbers are NOT the same
if cur_lot_number != prev_lot_number then
  begin
    a_i_lot_qty[count_qty] = #QTY;
    v_i_last_pos = count_qty;  // store the current count of lot allocation loop
  end

// Writes out the correct accumulative qty into the variable for use on end of ze1pallet
v_tmp_qty = a_i_lot_qty[count_qty];

Click below to find out more what Appleyard’s EDI Services can do for you

Leave a Reply

Your email address will not be published. Required fields are marked *

*