Progress
Language Reference


SUBSTRING Function

Interfaces
OS
SpeedScript
All
All
Yes

Extracts a portion of a character string from a field or variable.

SYNTAX

SUBSTRING (source , position [ , length [ , type ] ] ) 

source

A character expression from where you want to extract characters or bytes.

position

An integer expression that indicates the position of the first character you want to extract from source.

length

An integer expression that indicates the number of characters you want to extract from source. If you do not use the length argument or specify -1 as the length, SUBSTRING uses the remainder of the string from the specified position.

type

A character expression that directs Progress to interpret the specified position and length values as character units, bytes, or columns. A double-byte character registers as one character unit. By default, Progress interprets the specified position and length values as character units.

There are FOUR valid types: "CHARACTER," "FIXED," "COLUMN," and "RAW." The expression "CHARACTER" specifies character units. The expression "FIXED" specifies that position is in character units and the length is in bytes, but directs SUBSTRING to yield only whole characters. That is, if the last byte or bytes represent part of, but not all of, a multi-byte character, these bytes are excluded. The expression "COLUMN" specifies display or print character-columns. The expression "RAW" specifies bytes. If you specify the type as a constant expression, Progress validates the type specification at compile time. If you specify the type as a non-constant expression, Progress validates the type specification at run time.

EXAMPLE

The r-substr.p procedure uses the SUBSTRING function to create invoice numbers. You supply a starting invoice number. The first SUBSTRING function produces the first two characters of today’s date; the second SUBSTRING function produces the last two characters of today’s date. The procedure concatenates these four characters to a hyphen and the number you entered to produce an invoice number.

r-substr.p
DEFINE VARIABLE inv-num AS CHARACTER FORMAT "x(11)"
  LABEL "Invoice Number".
DEFINE VARIABLE snum AS INTEGER FORMAT "9999"
  LABEL "  Starting Order Number".
DEFINE VARIABLE enum LIKE snum LABEL "    Ending Order Number".
DEFINE VARIABLE num LIKE snum LABEL "Starting Invoice Number".

UPDATE "      Creating Invoices" 
  SKIP(2) snum SKIP(1) enum SKIP(2) num SKIP(2)
  WITH SIDE-LABELS CENTERED NO-BOX.

FOR EACH order WHERE order.order-num >= snum 
  AND order.order-num <= enum:
  inv-num =  SUBSTRING(STRING(TODAY),1,2,"CHARACTER") + 
            SUBSTRING(STRING(TODAY),7,2,"CHARACTER") + " - " + 
             STRING(num,"9999").
  DISPLAY order-num inv-num WITH CENTERED.    
  /* Do creation and printing of invoice here */    

  num = num + 1.
END. 

SEE ALSO

OVERLAY Statement, SUBSTRING Statement


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095