Changing report output params in RDS (code enclosed) 
Author Message
 Changing report output params in RDS (code enclosed)

A few days ago, Jonathan Leffler posted some code for I4GL that would
change report output parameters on the fly.  The code he posted works
only for the C compiler version, and I only have the RDS version of
Informix.  Since an Informix employee said he was unable to figure out
a RDS version, I took that as a challenge.

Below is a modified version of his report.c that works when linked into
a customized runner.  I leave the details to building the runner as an
exercise for the reader.

I used Jonathan's code as a hint on how reports work in Informix.  I
found the equivalent report pointer, and inferred the report structure
that the interpreter uses.  Since this code diddles with internal
interpreter variables, use this code at your own risk.  I use it now to
reset the page length when output is going to the screen, and it
*appears* to work correctly.  Your mileage may vary.

BTW, I am using Informix 4.00 on SCO Xenix.  I haven't tested this
anywhere else.  Of course, the size of the junk variable in the repdesc
structure may change on other machine architectures.  You could write
another C function that gets called in the ON EVERY ROW section, and
have it print out the values in the repdesc structure.  You can then
verify that the structure definition is correct on your machine.

I've wanted to do this, but after I had previously poked around in the
interpreter for awhile, I had also given up.  Thanks for the hints, Jonathan.

 -----------------------------------------------------------------------------
| Marlin Prowell               | There is a very thin line between ignorance  |
| (206) 676-1554               | and arrogance and I have totally obliterated |

---- cut here ----
/*
 *      Set report output parameters for Informix RDS
 *
 *      Adapted from report.c written for I4GL by J Leffler
 *      See documentation for original report.c for details
 */

#include <stdio.h>

/* Structure inferred from RDS */
typedef struct repdesc
{
        short junk[42];     /* unknown       */
        short ln;           /* Line number?  */
        short pagenumber;   /* Pge number    */
        short plength;      /* Page length */
        short tmargin;      /* Top margin    */
        short bmargin;      /* Bottom margin */
        short lmargin;      /* Left margin   */
        short rmargin;      /* Right margin  */
        short fphlines;     /* Lines in first page header */
        short phlines;      /* Lines in page header */
        short ptlines;      /* Lines in page trailer */
        short junktoo;      /* unknown       */
        short tot;

Quote:
}  Report;

extern  Report *currep;   /* Parameters of current report */

static  Report set;     /* Newly set report parameters  */
static  int newset = 0; /* Mask of newly set parameters */

#define TMARGIN 0x01
#define BMARGIN 0x02
#define LMARGIN 0x04
#define PLENGTH 0x08
#define RMARGIN 0x10

#define DEF_TMARGIN   3
#define DEF_BMARGIN   3
#define DEF_LMARGIN   5
#define DEF_PLENGTH  66
#define DEF_RMARGIN 132

/* Redefine page length */
int set_plength(i)
int i;
{
        if (i == 1)
        {
                popint(&i);
                if (i > 0)
                {
                        set.plength = i;
                        newset |= PLENGTH;
                }
        }
        return(0);

Quote:
}

/* Reset top margin */
/* This will not reset the top margin on the first page */
int set_tmargin(i)
int i;
{
        if (i == 1)
        {
                popint(&i);
                if (i >= 0)
                {
                        set.tmargin = i;
                        newset |= TMARGIN;
                }
        }
        return(0);

Quote:
}

/* Reset bottom margin */
int set_bmargin(i)
int i;
{
        if (i == 1)
        {
                popint(&i);
                if (i >= 0)
                {
                        set.bmargin = i;
                        newset |= BMARGIN;
                }
        }
        return(0);

Quote:
}

/* Reset left margin */
int set_lmargin(i)
int i;
{
        if (i == 1)
        {
                popint(&i);
                if (i >= 0)
                {
                        set.lmargin = i;
                        newset |= LMARGIN;
                }
        }
        return(0);

Quote:
}

/* Reset right margin */
int set_rmargin(i)
int i;
{
        if (i == 1)
        {
                popint(&i);
                if (i >= 0)
                {
                        set.rmargin = i;
                        newset |= RMARGIN;
                }
        }
        return(0);

Quote:
}

/* Copy reset output list into report configuration */
/* Call in first page header block */
int set_output(i)
int i;
{
        int newlen;

        if (i == 0 && newset && currep != (Report *)0)
        {
                if (newset & PLENGTH)
                {
                        currep->plength = set.plength;
                }
                if (newset & TMARGIN)
                {
                        newlen  = currep->plength
                                        - currep->ptlines
                                        - currep->phlines
                                        - currep->bmargin
                                        - currep->tmargin
                                        - 1;
                        if (set.tmargin < newlen)
                        {
                                currep->tmargin = set.tmargin;
                        }
                }
                if (newset & LMARGIN)
                {
                        currep->lmargin = set.lmargin;
                }
                if (newset & BMARGIN)
                {
                        newlen  = currep->plength
                                        - currep->ptlines
                                        - currep->phlines
                                        - currep->tmargin
                                        - currep->bmargin
                                        - 1;
                        if (set.bmargin < newlen)
                        {
                                currep->bmargin = set.bmargin;
                        }
                }
                currep->tot = currep->plength - (currep->bmargin + currep->ptlines
                        /*
                         * adding this last variable leaves the report
                         * title at the top of the terminal screen
                         */
                        + currep->phlines);
                newset = 0;
        }
        return(0);

Quote:
}

/* Return page length */
int get_plength(i)
int i;
{
        if (newset & PLENGTH)
                i = set.plength;
        else
                i = DEF_PLENGTH;
        retint(i);
        return(1);

Quote:
}

/* Return top margin */
int get_tmargin(i)
int i;
{
        if (newset & TMARGIN)
                i = set.tmargin;
        else
                i = DEF_TMARGIN;
        retint(i);
        return(1);

Quote:
}

/* Return bottom margin */
int get_bmargin(i)
int i;
{
        if (newset & BMARGIN)
                i = set.bmargin;
        else
                i = DEF_BMARGIN;
        retint(i);
        return(1);

Quote:
}

/* Return left margin */
int get_lmargin(i)
int i;
{
        if (newset & LMARGIN)
                i = set.lmargin;
        else
                i = DEF_LMARGIN;
        retint(i);
        return(1);

Quote:
}

/* Return right margin */
int get_rmargin(i)
int i;
{
        if (newset & RMARGIN)
                i = set.rmargin;
        else
                i = DEF_RMARGIN;
        retint(i);
        return(1);
Quote:
}

--
 -----------------------------------------------------------------------------
| Marlin Prowell               | There is a very thin line between ignorance  |
| (206) 676-1554               | and arrogance and I have totally obliterated |



Sun, 16 Oct 1994 12:30:46 GMT
 
 [ 1 post ] 

 Relevant Pages 

1. Compiling 4GL code in RDS 6.00 is not like RDS 4.00

2. FPW 2.6 Reports: changing printer output bin

3. GRAPHS -- as report output that dynamically change??

4. Stored Proc Return values / Output Params w ADO and SQL Server 7

5. Stored Proc Return values / Output Params w ADO and SQL Server 7

6. Stored Proc Return values / Output Params w ADO and SQL Server 7

7. Data-at-Execution and output params

8. Output Params in ODBC

9. output params

10. execute sp in vb6 with recordset and output params

11. Output params in Sprocs question

12. sp_executesql > 4000 characters, with output params


 
Powered by phpBB® Forum Software