Skip to the content.

Function LEFT

TABLE OF CONTENTS

  1. How do I use LEFT?
  2. Syntax
  3. Rules for the syntax
  4. Examples: LEFT function in ERF
  5. Examples: LEFT function in ECL

How do I use LEFT?

The function LEFT is used to specify the left most bytes of a string. It can be applied to alphanumeric source file fields, column references to alphanumeric columns, alphanumeric lookup fields, and alphanumeric constants. You specify the field name, column reference, or constant, and the desired length.
It can be used in assignments, and in comparisons with the string comparison operators.

(Syntax Legend)

Syntax


    ►►──LEFT(─┬─<Field Reference>───┬─,─<Length>─)───────────►◄
              ├─<COL.nnn Reference>─┤
              └─<String>────────────┘    

Function LEFT Field Ref

Function LEFT Lookup

Function LEFT COL

Function LEFT String

Rules for the syntax

The length is a positive integer and must be equal or less than the field, column or string length.

LEFT can only be used in Extract Record Filter (ERF) and Extract Column Logic (ECL) text.
If used in an Extract Record Filter (ERF), the Column references COL.nnn can not be used.

LEFT can be used in a comparison but only using the string comparison operators BEGINS_WITH, CONTAINS and ENDS_WITH.

See also topic: Rules for all Logic Text

Examples: LEFT function in ERF

Example logic text Meaning
IF (LEFT({field2},5) CONTAINS “AA”) THEN
    SELECT
ENDIF
Select only records where field2 has the
characters “AA” somewhere in the first five bytes.
This example can also be written:
  SELECTIF(LEFT({field2},5) contains “AA”)

Examples: LEFT function in ECL

Example logic text Meaning
COLUMN = LEFT({Cust_Code},4) Set the current column to the first four bytes of field Cust_Code.
COLUMN = LEFT(COL.3,8) Set the current column to the first eight bytes column 3. This column must be after column 3.
IF (LEFT({Cust_Code},8) CONTAINS “AA”) THEN
    WRITE(SOURCE=VIEW,DEST=EXT=03)
ENDIF
Write to extract 3 those records where
the Cust_code contains “AA” anywhere in the first eight characters.