MEMVAR DEFINE()
From Recital Documentation Wiki
Revision as of 15:04, 27 March 2009 by Yvonnemilne (Talk | contribs)
PURPOSE
Define a Recital memory variable
SYNONYM
api_memvar_define()
SYNOPSIS
#include "dbapi.h" struct API_MEMVAR MEMVAR_DEFINE(name, level) <input parameters> char *name; /* Address of a buffer containing the name of memory variable */ int level; /* Private or public declaration */ <output parameters> none
DESCRIPTION
The MEMVAR_DEFINE() function will define a Recital memory as .F..
The level of declaration must be specified from one of the following.
VALUE | DESCRIPTION |
---|---|
API_PRIVATE | Private to the Recital calling procedure |
API_PUBLIC | Public to all Recital higher level procedures |
The following API_MEMVAR structure is used to store the results.
union API_UNION { char *info_character, /* Char memory variable */ char info_logical; /* Logical memory variable */ double info_number; /* Numeric memory variable */ unsigned long info_date; /* Date memory variable */ DATETIME info_datetime; /* Datetime memory variable */ CURRENCY info_currency; /* Currency memory variable */ }; struct API_MEMVAR { char type; /* Data type of memory variable */ union API_UNION value; /* Value of the memory variable */ int width; /* Display width */ int decimal; /* Display # of decimal places */ };
The API_MEMVAR type specifies both the data type and which API_UNION value will be used to return the value of the memory variable.
The API_MEMVAR width returns the length of the memory variable. A decimal place may be returned for a number, but will be 0 for other data types.
A memory variable can be defined as any one of the following.
TYPE | OUTPUT | WIDTH | DESCRIPTION |
---|---|---|---|
C | *info_character | 1-8192 | Address of a buffer containing a character string |
D | info_date | 8 | Unsigned long representing a recital date |
L | info_logical | 1 | Character of either 'T' for true or 'F' for false |
N | info_number | 1-16 | A value stored in a double |
T | info_datetime | sizeof(DATETIME) | RCT_DATETIME_DEF structure |
Y | info_currency | sizeof(CURRENCY) | RCT_CURRENCY_DEF structure |
EXAMPLE
The following example defines the six memory variables and then stores the specified values to them.
#include "dbapi.h" dbapi_memvar_define() { int rc; double numeric; char string[8]; char logical; unsigned long date; DATETIME datetime; CURRENCY currency; strcpy(string,"Recital"); date = DATE_CTOD(DATE_DATE()); logical = 'T'; numeric = 23.5; datetime = DATE_STOT(DATE_DATETIME()); currency = CURR_STOY("6363.939"); COMMAND("release all"); MEMVAR_DEFINE("character", API_PUBLIC); MEMVAR_DEFINE("number", API_PUBLIC); MEMVAR_DEFINE("logical", API_PUBLIC); MEMVAR_DEFINE("date", API_PUBLIC); MEMVAR_DEFINE("datetime", API_PUBLIC); MEMVAR_DEFINE("currency", API_PUBLIC); rc = MEMVAR_UPDATE( "character", 'C', 7, 0, string, &numeric, logical, date, datetime, currency); rc = MEMVAR_UPDATE( "number", 'N', 10, 2, string, &numeric, logical, date, datetime, currency); rc = MEMVAR_UPDATE( "logical", 'L', 1, 0, string, &numeric, logical, date, datetime, currency); rc = MEMVAR_UPDATE( "date", 'D', 8, 0, string, &numeric, logical, date, datetime, currency); rc = MEMVAR_UPDATE( "datetime", 'T', sizeof(DATETIME), 0, string, &numeric, logical, date, datetime, currency); rc = MEMVAR_UPDATE( "currency", 'Y', sizeof(CURRENCY), 0, string, &numeric, logical, date, datetime, currency); _retni(rc >= 0) ? 1 : 0); }