Defining Repeatable Elements in XML Filter

If an XML element occurs in XML data for multiple times, it is a repeatable element. Usually, a repeatable element contains data for a single label. To indicate that you want to use data from all repeatable elements, and not just from the first one, define the element as a Data block and enable the Repeatable element option. If the filter contains definition of elements defined as data block / repeatable element, the Use Data Filter action displays repeatable elements with nested placeholders. All actions nested below such a placeholder execute only for data blocks at this level.

Example

The <item> element is defined as Data block and Repeatable element. This instructs the filter to extract all occurrences of the <item> element, not just the first one. In this case, the <item> should be defined as the sub-level in Use Data Filter action. You must nest the actions Open Label and Print Label under this sub-level placeholder, so they are going to be looped for as many times as there are occurrences of the <item> element. As shown in the example below, for three times.

<?xml ver sion="1.0" encoding="utf-8"?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" ver sion="1.0">
 <asx:values>
  <NICELABEL_JOB>
   <T IMEST AMP>20130221100527.788134</T IMEST AMP>
   <USER>PGRI</USER>
   <IT _LABEL_DAT A>
   <item>
      <LBL_NAME>goods_r eceipt.nlbl</LBL_NAME>
      <LBL_PRINT ER>Pr oduction01</LBL_PRINT ER>
      <LBL_QUANT IT Y>1</LBL_QUANT IT Y>
      <MAKT X>MASS ONE</MAKT X>
      <MAT NR>28345</MAT NR>
      <MEINS>KG</MEINS>
      <WDAT U>19.01.2012</WDAT U>
      <QUANT IT Y>1</QUANT IT Y>
      <EXIDV>012345678901234560</EXIDV>
   </item>

   <item>
      <LBL_NAME>goods_r eceipt.nlbl</LBL_NAME>
      <LBL_PRINT ER>Pr oduction01</LBL_PRINT ER>
      <LBL_QUANT IT Y>1</LBL_QUANT IT Y>
      <MAKT X>MASS T WO</MAKT X>
      <MAT NR>28346</MAT NR>
      <MEINS>KG</MEINS>
      <WDAT U>11.01.2011</WDAT U>
      <QUANT IT Y>1</QUANT IT Y>
      <EXIDV>012345678901234577</EXIDV>
   </item>

   <item>
      <LBL_NAME>goods_r eceipt.nlbl</LBL_NAME>
      <LBL_PRINT ER>Pr oduction01</LBL_PRINT ER>
      <LBL_QUANT IT Y>1</LBL_QUANT IT Y>
      <MAKT X>MASS T HREE</MAKT X>
      <MAT NR>27844</MAT NR>
      <MEINS>KG</MEINS>
      <WDAT U>07.03.2009</WDAT U>
      <QUANT IT Y>1</QUANT IT Y>
      <EXIDV>012345678901234584</EXIDV>
   </item>

  </IT _LABEL_DAT A>
 </NICELABEL_JOB>
 </asx:values>
</asx:abap>

Warning

XML data filter with nested data block duplicates values from previous assignment area if a variable is defined in the first block but not in the second. For example, you print two labels. In the first assignment area, you defined a variable <manufacturer_serial>. In the second assignment area, this variable is not present.

<?xml ver sion="1.0" encoding="utf-8"?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" ver sion="1.0">
    <jobs>
      <element>
         <data>
            <item>
               <manufacturer_serial>706583012001</manufacturer_serial>
               <package_code>AA792CY</package_code>
            </item>
         </data>
         <label_filename>serial_number_label.nlbl</label_filename>
         <print_quantity>1</print_quantity>
         <printer_name>Warehouse_printer_09</printer_name>
      </element>
      <element>
         <data>
            <item>
               <package_code>BE273XS</package_code>
            </item>
         </data>
         <label_filename>serial_number_label.nlbl</label_filename>
         <print_quantity>1</print_quantity>
         <printer_name>Warehouse_09</printer_name>
      </element>
   </jobs>
</asx:abap>

The expected result would be the second label without <manufacturer_serial> data. But in the actual print, the second label would contain <manufacturer_serial> value from the first label, which is 706583012001.

There are four possible solutions:

  • Avoid nested data blocks.

  • Define variable values as empty values if variables are not used in nested data blocks.

                <item>
                   <manufacturer_serial></manufacturer_serial>
                   <package_code>AA792CY</package_code>
                </item>
  • Use conditions on actions to set variables.

  • Use string manipulations when detected missing variables.