PreviousNextIndex

SUBSTRING function

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

Syntax

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

source
position
length
type
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 NO-UNDO FORMAT "x(11)" 
  LABEL "Invoice Number". 
DEFINE VARIABLE snum    AS INTEGER   NO-UNDO FORMAT "9999" 
  LABEL "  Starting Order Number". 
DEFINE VARIABLE enum    LIKE snum    NO-UNDO 
  LABEL "    Ending Order Number". 
DEFINE VARIABLE num     LIKE snum    NO-UNDO 
  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.OrderNum >= snum AND Order.OrderNum <= enum: 
  inv-num = SUBSTRING(STRING(TODAY),1,2,"CHARACTER") +  
            SUBSTRING(STRING(TODAY),7,2,"CHARACTER") + " - " +  
             STRING(num,"9999"). 
  DISPLAY Order.OrderNum inv-num WITH CENTERED. 
  /* Do creation and printing of invoice here */ 
  num = num + 1. 
END. 

See also

OVERLAY statement, SUBSTRING statement


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex