New User-Defined Functions in Elliott DDF

New User-Defined Functions in Elliott DDF

Release Date: 12/6/17
Modified Date: 07/08/2024
Version: 8.5 & up

In the future DDF (target to be released with Elliott 8.5,), we will add the following four user-defined functions:
  • ELIDATE2SQL
  • SQLDATE2ELI
  • ELITIME2SQL
  • SQLTIME2ELI
For example, you can use the following SELECT statement:
                select order_no, ELIDATE2SQL(order_date) from cpordhdr;
The date return in the above sample statement will be in the native SQL date format, instead of the Elliott 8-digit date.

The following is the detail of the script that we use to create these four user-defined functions:

CREATE FUNCTION ELIDATE2SQL(:ELIDATE NUMERIC(8,0))
RETURNS DATE
AS 
BEGIN
DECLARE :C CHAR(8);
DECLARE :D DATE;
IF (:ELIDATE = 0) THEN
  SET :D=NULL;
ELSE
  SET :C=CONVERT(:ELIDATE,SQL_CHAR);
  SET :D=CONVERT(concat(concat(concat(concat(left(:C,4),'-'),substring(:C,5,2)),'-'),right(:C,2)),SQL_DATE);
END IF;
RETURN :D;
END;
 
CREATE FUNCTION SQLDATE2ELI(:SQLDATE DATE)
RETURNS NUMERIC(8,0)
AS 
BEGIN
DECLARE :C CHAR(10);
DECLARE :Y NUMERIC(4,0);
DECLARE :M NUMERIC(2,0);
DECLARE :D NUMERIC(2,0);
DECLARE :N NUMERIC(8,0);
IF (:SQLDATE = NULL) THEN
  SET :N=0
ELSE
  SET :C=CONVERT(:SQLDATE,SQL_CHAR);
  SET :Y=CONVERT(LEFT(:C,4),SQL_NUMERIC);
  SET :M=CONVERT(SUBSTRING(:C,6,2),SQL_NUMERIC);
  SET :D=CONVERT(RIGHT(:C,2),SQL_NUMERIC);
  SET :N=:Y * 10000 + :M * 100 + :D;
END IF;
RETURN :N;
END;
 
CREATE FUNCTION ELITIME2SQL(:ELITIME NUMERIC(6,0))
RETURNS TIME
AS 
BEGIN
DECLARE :C VARCHAR(12);
DECLARE :T TIME;
SET :C=CONVERT(:ELITIME,SQL_CHAR);
-- PAD ZEROES ON THE LEFT
SET :C=RIGHT(CONCAT('000000',:C),6);
SET :T=CONVERT(concat(concat(concat(concat(left(:C,2),':'),substring(:C,3,2)),':'),right(:C,2)),SQL_TIME);
RETURN :T;
END;
 
CREATE FUNCTION SQLTIME2ELI(:SQLTIME TIME)
RETURNS NUMERIC(6,0)
AS
BEGIN
DECLARE :C CHAR(8);
DECLARE :H NUMERIC(2,0);
DECLARE :M NUMERIC(2,0);
DECLARE :S NUMERIC(2,0);
DECLARE :N NUMERIC(6,0);
IF (:SQLTIME=NULL) THEN
  SET :N=0;
ELSE
  SET :C=CONVERT(:SQLTIME,SQL_CHAR);
  SET :H=CONVERT(LEFT(:C,2),SQL_NUMERIC);
  SET :M=CONVERT(SUBSTRING(:C,4,2),SQL_NUMERIC);
  SET :S=CONVERT(RIGHT(:C,2),SQL_NUMERIC);
  SET :N=:H * 10000 + :M * 100 + :S;
END IF;
RETURN :N;
END; 

Please also reference the following related KB article:

EMK


    • Related Articles

    • Developing a New Elliott V8.6 Report Desk User Defined Report (UDR)

      'Release Date: 6/20/2018 Version: 8.6 & Up This document is written for licensed Elliott Software developers. It is not relevant for regular Elliott users. Overview With proper licensing, Elliott developers can follow these three steps to create a ...
    • Login SUPERVISOR to Update DDF Files After Elliott 8.6 Installation

      Release Date: 8/17/2022 Version: Elliott V8.6 and Higher Background Most of Elliott Business Software uses the PSQL transactional database engine (Btrieve) to perform its work. However, some new features of Elliott V8.6 use the PSQL relational ...
    • Feature - User Defined CSV Export Item Batch Support

      Release Date - 2/5/18 This feature gives the user the ability to define a batch that can be used when running the User Defined CSV Export. The batch can be defined from I/M-> Reports-> User Defined CSV Report-> Maintenance-> User Defined CSV Batch. ...
    • A Comparison of Elliott 7.5, 8.2, 8.5, 8.6 and 8.6 V2 DDF Files

      Release Date: 11/15/2022 Last Updated: 06/25/2024 Version: 7.5 & Up DDF Files are used to define the PSQL database schema. Generally speaking, we distribute five different types of DDF files for different versions of Elliott releases: 7.5 DDF: These ...
    • Feature - Reorder Advice/User Defined CSV Export Introduction

      Release Date: 08/07/2020 Version: 8.0 & Up Introduction The User-Defined CSV Export is a specialized report writing tool and CSV creator for inventory information to allow you to analyze an Excel spreadsheet. This program allows access to ...