• Subject: Re: AS/400 C and record I/O
  • From: Buck Calabro/commsoft<mcalabro@xxxxxxxxxxxx>
  • Date: Wed, 10 Mar 1999 11:21:37 -0500

On 03/09/99 11:18:51 PM Phil Hall  wrote:

>> get the file to open and actually print the buffer (fp->in-buf).  Is 
there
>> an easy way to map this buffer to the externally described field specs, 
or
>> do we have to manually describe the structure?  The C manual is less 
than
>> illuminating...
>
>Take a look at the '#pragma mapinc' section of the ILE/C reference
>manual. Also in the ILE/C Programmers Guide manual there is a whole
>chapter on accessing data files from within ilE/C
 
It was the details of the #pragma mapinc that were eluding us.  The 
examples don't show an application manipulating decimal fields read from a 
database file.  One thing that helped us in this "exploration" mode is to 
compile the program with these options: OUTPUT(*PRINT) OPTION(*SHOWINC 
*XREF) DBGVIEW(*LIST)  This way, we can see all the structures (even the 
system-supplied ones) and work out the details.

The only hangup appears to be that if we use packed decimals, we'll have to 
explicitly declare their size on printf's, etc.  Converting them to float 
does wierd rounding to the values unless you use the "p" option on the 
#pragma mapinc and then use QXXPTOD to convert them.

For the lurkers, here are the lines that make it work:

#include <stdio.h> 
#include <stdlib.h>
#include <recio.h>      /* provides record I/O support */
#include <decimal.h>      /* provides decimal number support */

/* Map file MASTER in library BUCK, record format RMASTER to an */
/* internal name called "master"  Also, apply options to the declaration */
/* options are include input fields, generate "packed" structure (do NOT 
align */
/* along 4 byte boundaries) and generate packed decimal fields */
#pragma mapinc("master","BUCK/MASTER(RMASTER)","input","_P d") 
#include "master" 

int main(void) 
{ 
    _RFILE      *fp; 
    BUCK_MASTER_RMASTER_i_t ddsbuf; 
 
    fp = _Ropen ( "BUCK/MASTER", "rr, arrseq=Y" )

   /* Get the first record and map to the record structure */
   _Rreadf ( fp, &ddsbuf, sizeof(ddsbuf), __DFT );

   /* Print the interesting fields */
   printf ( "Name= %s\n", ddsbuf.NAME );        /* char[30] */
   printf ( "Total= %D(9,2)\n", ddsbuf.TOTAL);   /* decimal(9,2) */

   _Rclose ( fp ); 
} 

Buck Calabro
Billing Concepts Inc (formerly CommSoft), Albany, NY
mailto:mcalabro@commsoft.net
+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---


This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].