Field Loops

 

A field loop is a template file construct which allows you to iterate through the collection of fields that CodeGen has information about. These field definitions can come from one of two places:

If you are generating code based on information obtained form a repository structure, the field collection is based on the fields which are defined in that repository structure.

If you are generating code based on the definition of a UI Toolkit input window (defined in a window script file), the field collection is determined by the fields defined in that input window. Of course these fields may in turn refer to a repository structure.

If you are generating code based on information obtained from a Synergy Method Catalog, and you are currently processing a structure parameter, the field collection is based on the fields which are defined in the repository structure associated with the current parameter.

 

Field loops are delimited by a matching pair of <FIELD_LOOP> and </FIELD_LOOP> tags that surround the template code to be inserted for each field. The code between the opening and closing tags of a field loop is repeated for each field in the structure being processed.

Field Loop Expansion Tokens

Field Loop Expression Tokens

Field loops may be defined within structure loops and parameter loops, but may not be declared within any other loop construct.

CodeGen processes array fields as multiple individual fields. Normally CodeGen does not process overlay fields, or fields marked “Excluded by Language”.

There are two types of field loops, called multi-line field loops, and in-line field loops.

Multi-Line Field Loops

Multi-line field loops occur when the opening and closing field loop tags appear on separate lines in a template file, and delimit one or more entire lines of template code, like this:

[code]

<FIELD_LOOP>
code
</FIELD_LOOP>

[code]

Multi-line field loops generate one or more lines of output code for each field that is processed.

In-Line Field Loops

In-line field loops exist when the opening and closing field loop tags appear on the same line in a template file, and delimit part of a line of template code, like this:

[code] <FIELD_LOOP> code </FIELD_LOOP> [code]

In-line field loops generate code into the current output line.

Field Loop Example 1 (Multi-Line)

The following template file code:

sql = "CREATE TABLE <STRUCTURE_NAME> ("
<FIELD_LOOP>
& + "<FIELD_SQLNAME> <FIELD_SQLTYPE><IF REQUIRED> NOT NULL</IF><,>"
</FIELD_LOOP>
& + ")"

 

could produce output like this:

sql = "CREATE TABLE PROJECT ("
& + "SYNERGYGRFA VARCHAR(22),"
& + "PROJECT_ID DECIMAL(8) NOT NULL,"
& + "CUSTOMER_ID VARCHAR(10) NOT NULL,"
& + "CONTRACT_ID VARCHAR(10) NOT NULL,"
& + "CONTRACT_PROJECT_ID DECIMAL(3) NOT NULL,"
& + "DESCRIPTION VARCHAR(60) NOT NULL,"
& + "START_DATE DATETIME NOT NULL,"
& + "END_DATE DATETIME,"
& + "CURRENT_STATUS DECIMAL(2) NOT NULL,"
& + "STATUS_DATE DATETIME NOT NULL,"
& + "LEAD_CONSULTANT VARCHAR(15) NOT NULL,"
& + "COORDINATOR VARCHAR(15) NOT NULL,"
& + "APPROVED_BY_FIRST DECIMAL(3) NOT NULL,"
& + "APPROVED_BY_LAST DECIMAL(3) NOT NULL,"
& + "APPROVED_DATE DATETIME NOT NULL,"
& + "APPROVAL_LOCATION DECIMAL(2) NOT NULL,"
& + "WORK_LOCATION_ID DECIMAL(2),"
& + "CREATED_BY VARCHAR(15) NOT NULL,"
& + "CREATED_DATE DATETIME NOT NULL,"
& + "MODIFIED_BY VARCHAR(15),"
& + "MODIFIED_DATE DATETIME,"
& + "TEXT VARCHAR(700),"
& + "REPLICATION_KEY VARCHAR(20)"
& + ")"

 

Field Loop Example 2 (Multi-Line and In-Line)

The following template file code:

sql = "INSERT INTO <STRUCTURE_NAME> ("
<FIELD_LOOP>
& + "<FIELD_SQLNAME><,>"
</FIELD_LOOP>
& + ") VALUES(<FIELD_LOOP>:<FIELD#LOGICAL><,></FIELD_LOOP>)"
 

Could produce output like this:

sql = "INSERT INTO PROJECT ("
& + "SYNERGYGRFA,"
& + "PROJECT_ID,"
& + "CUSTOMER_ID,"
& + "CONTRACT_ID,"
& + "CONTRACT_PROJECT_ID,"
& + "DESCRIPTION,"
& + "START_DATE,"
& + "END_DATE,"
& + "CURRENT_STATUS,"
& + "STATUS_DATE,"
& + "LEAD_CONSULTANT,"
& + "COORDINATOR,"
& + "APPROVED_BY_FIRST,"
& + "APPROVED_BY_LAST,"
& + "APPROVED_DATE,"
& + "APPROVAL_LOCATION,"
& + "WORK_LOCATION_ID,"
& + "CREATED_BY,"
& + "CREATED_DATE,"
& + "MODIFIED_BY,"
& + "MODIFIED_DATE,"
& + "TEXT,"
& + "REPLICATION_KEY"
& + ") VALUES(:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,:14,:15,:16,:17,:18,:19,:20,:21,:22,:23)"

 

Field Loop Example 3

The following template code:

#region Private fields (storage for properties)

<FIELD_LOOP>
private <FIELD_CSTYPE> p_<Field_Sqlname>;
</FIELD_LOOP>

#endregion
 

Could produce code like this:

#region Private fields (storage for properties)

private string p_Synergygrfa;
private int p_Project_Id;
private string p_Customer_Id;
private string p_Contract_Id;
private int p_Contract_Project_Id;
private string p_Description;
private DateTime p_Start_Date;
private DateTime p_End_Date;
private int p_Current_Status;
private DateTime p_Status_Date;
private string p_Lead_Consultant;
private string p_Coordinator;
private int p_Approved_By_First;
private int p_Approved_By_Last;
private DateTime p_Approved_Date;
private int p_Approval_Location;
private int p_Work_Location_Id;
private string p_Created_By;
private DateTime p_Created_Date;
private string p_Modified_By;
private DateTime p_Modified_Date;
private string p_Text;
private string p_Replication_Key;

#endregion

 

Video

Here's the Introduction to Field Loops video. Make sure you select a high-definition version of the video, by default YouTube tends to play the lowest resolution which can look pretty awful!

 

 

 


Copyright © 2018  Synergex International, Inc.