From: cheryl@redriverad-emh1.army.mil (Cheryl Gross)
Newsgroups: comp.databases.informix
Subject: ACE functions
Date: 29 Sep 92 23:03:07 GMT
Reply-To: cheryl@redriverad-emh1.army.mil
X-Informix-List-ID: <list.1492>

I am responding to Stuart's message about .ace functions.  I don't have
time to do a lot of editing, and pretty-ing up.  And I'm afraid that 
I'm exposing, in my haste, myself to the folks that really know what 
they are doing in esql/c.

Most of what we do here we have to teach oursselves and the attached portions
of an .ace and the function.ec program, hopefully will help someone else if
Stuart already has his answers.  The Read the manual stuff isn't always 
an easy task.

Sometimes, you read but do not understand the missing holes that you should
already know.  It took us a while to get and .ace perform as a function and
we were proud that it worked.  But I realize it is not perfect.  We just got
it to work, if not the best or most efficient way, or even the right way,
it just works.  I apologize to all those that cringe at our clumbsiness.

From a previous message posted to the net earlier this year...
Yes, our ESQL/C reference book Chapter 6 "C Functions in ACE and PERFORM".
We are running 2.10.03 and have done functions in ace reports, to update
the database after a report is complete.
See page 6-15 of the ESQL/C for a sample function program.
Ace functions work a lot like the perform functions.  
Compile the functions with cace instead of cperf.

cace programname.ec -o programname

Compile the .ace report as usual.

saceprep acereport.ace

then run:

programname acereport

This is placed at the top of the ace report in the define area:

define
function writercn            {  noting the function name    }
param[1] rcn_entry char(7)   {  noting a parameter passed this ace report    }
end

on last row
call writercn(rcn_nbr,qdr_issued[1])   { doing the function calling    }
end


Now here is the the sacefunc.ec program.  Again I apologize for any redundant
or extra steps, amatuerish style, or unnecessary include files.

#include <stdio.h>
#include <time.h>
#include "ctools.h"
#include "decimal.h"
#include "include/stoi.h"
$include sqlca;

extern valueptr writercn();

struct ufunc userfuncs[] =
	{
	"writercn", writercn,
	0,0
	};
valueptr writercn(rcn,status)
valueptr rcn;
valueptr status;
{
$ char vrcn_nbr[8];
$ char vqdr_issued[2];
$ long *vqdr_iss_dt;
char *fmtstring[9];
char qdr_iss[2];
int vqdr_cnt;
dec_t *cnt_dect;
char last[3];
long seconds, time();
char *usertime[9], *getlogin();
struct tm *timerec, *localtime();
seconds = time((long *) 0);
timerec = localtime(&seconds);
timerec->tm_mon = timerec->tm_mon + 1;
bycopy(rcn->v_charp,vrcn_nbr,rcn->v_len);
bycopy(status->v_charp,qdr_iss,status->v_len);
qdr_iss[status->v_len]=0;
vrcn_nbr[rcn->v_len]=0;
strcpy(fmtstring,"mm/dd/yy");
rstoi(qdr_iss,&vqdr_cnt);
vqdr_cnt = vqdr_cnt + 1;
deccvint(vqdr_cnt,&cnt_dect);
dectoasc(&cnt_dect,qdr_iss,1,0);
strcpy(vqdr_issued,qdr_iss);
sprintf(usertime, "%02d/%02d/%02d", timerec->tm_mon,timerec->tm_mday,timerec->tm_year);
rdefmtdate(&vqdr_iss_dt,fmtstring,usertime);
$ update nrcn 
 set (qdr_issued) = ($vqdr_issued)
 where rcn_nbr = $vrcn_nbr;
if (sqlca.sqlcode == 0)
{
char errstr[80];
sprintf(errstr, "Complete %d processed - passed %s", sqlca.sqlcode,vrcn_nbr);
intreturn(1);
}
else
{
char errstr[80];
sprintf(errstr, "error %d in select - passed %s", sqlca.sqlcode,vrcn_nbr);
intreturn(0);
}
}


Cheryl Gross

Newsgroups: comp.databases.informix