<!--
* 
*
*  ProLinga-Doc
*
*  Copyright (C) 2002-2008 Xobas Software.
*  All rights reserved.
*  
*  This file is part of ProLinga-Doc.
*
*  ProLinga-Doc is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  ProLinga-Doc is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with ProLinga-Doc.  If not, see <http://www.gnu.org/licenses/>.
*
*  More information is available at the following addresses:
*
*  Website     : http://www.prolinga.org
*
*  Email       : prolinga-list@prolinga.org
*
*
-->
<refentry id="cmd_foreach">
  <refmeta>
    <refentrytitle>FOREACH Command</refentrytitle>
    <manvolnum>1</manvolnum>
  </refmeta>

  <refnamediv>
    <refname>FOREACH</refname>
    <refpurpose>Return data rows of a returned datamodel.</refpurpose>
  </refnamediv>

  <refsynopsisdiv>
    <cmdsynopsis>
      <command>FOREACH</command>
      <arg choice='plain'><replaceable>data_model_name</replaceable></arg>
    </cmdsynopsis>
  </refsynopsisdiv>

  <refsect1 id="cmd_foreach_introduction">
    <title>Introduction</title>
    <para>
      The <link linkend="cmd_foreach">FOREACH</link> command returns all rows 
      from a data model. Entries in the data model can be referenced as:
      <orderedlist>
        <listitem>
          <para>
            M-<replaceable>_col_no.datamodel_name</replaceable>
          </para>
        </listitem>
        <listitem>
          <para>
            M-<replaceable>external_field_name.datamodel_name</replaceable>
          </para>
        </listitem>
        <listitem>
          <para>
            M-<replaceable>alias.datamodel_name</replaceable>
          </para>
        </listitem>
      </orderedlist>

      Columns which have no obvious name (result of calculation for instance), 
      can only be referenced by the column number. Alternatively, the complete 
      data model can be copied to a Record or VariableGroup in a single 
      assignment statement.
    </para>
  </refsect1>
  <refsect1 id="cmd_foreach_arguments">
    <title>Arguments</title>
    <variablelist>
      <varlistentry>
	<term><replaceable>data_model_name</replaceable></term>
	<listitem>
	  <simpara>
            Valid and existing data model object.
	  </simpara>
	</listitem>
      </varlistentry>
    </variablelist>

  </refsect1>

  <refsect1 id="cmd_foreach_example">
    <title>Example</title>
<programlisting>
. . .
. . .
CLEAR DATAMODEL dm_customer
SQL QUERY Order COMMAND "select * from " T-Cust DATAMODEL dm_customer
FOREACH dm_customer
    CALL PrintLabel M-_col_1.dm_customer M-cust_name.dm_customer
ENDFOR
. . .
. . .
CLEAR DATAMODEL dm_customer
DATAMODEL SELECT dm_customer TABLE Cust
FOREACH dm_customer
    LET R-Customer = O-dm_customer
    CALL PrintLabel F-Cust_Id.Customer F-Name.Customer
ENDFOR
. . .
. . .
</programlisting>
  </refsect1>

  <refsect1 id="cmd_foreach_related">
    <title>Related Commands</title>
    <para>
      <link linkend="cmd_break">BREAK</link>
      <link linkend="cmd_continue">CONTINUE</link>
      <link linkend="cmd_datamodel">DATAMODEL</link>
      <link linkend="cmd_endfor">ENDFOR</link>
      <link linkend="cmd_sql">SQL</link>
    </para>
  </refsect1>

</refentry>

