Operating System - OpenVMS
1753784 Members
6779 Online
108799 Solutions
New Discussion юеВ

Re: Indexed files and c++

 
SOLVED
Go to solution
Jason_429
Occasional Advisor

Indexed files and c++

Is there a way to open an indexed file in c++ similar to using HPbasic.

For example say we have a simple ddl defined in DDL:MAST.INC
----------------------------------------------
DDL:MAST.INC
----------------------------------------------
RECORD MAST_REC
VARIANT
CASE
STRING WHOLE=20
CASE
STRING KEY 0=4
CASE
STRING ACCT=4
STRING NA.ME=16
END VARIANT
END RECORD

After converting the data file with an fdl it would be opened in basic like this.

DECLARE LONG CONSTANT MAST.CHAN =22%

INCLUDE "DDL:MAST.INC"
MAP (MAST_MAP) MAST_REC MAST
OPEN MAST$DAT FOR INPUT AS FILE #MAST.CHAN, &
INDEXED, &
ACCESS READ, ALLOW MODIFY, &
MAP MAST_MAP, BUFFER 4%, &
PRIMARY MAST::KEY0

INPUT "Enter acct ";acct$
GET #MAST.CHAN, KEY #MAST::KEY0 EQ ACCT$
IF E%
THEN PRINT ERT$(E%)
EXIT PROGRAM
END IF
PRINT "ACCT= ";MAST::ACCT
PRINT "NAME= ";MAST::NA.ME
END PROGRAM

I have searched the web, but have not been able to find much on this. Any help would be much appreciated.
3 REPLIES 3
Jason_429
Occasional Advisor

Re: Indexed files and c++

Sorry about the formatting, is there a [code] [/code] tag i should be using on this forum ?

Hein van den Heuvel
Honored Contributor
Solution

Re: Indexed files and c++

>> formating

There is a check-box "Retain format(spacing)."

>> Is there a way to open an indexed file in c++ similar to using HPbasic

Typically you would set up a FAB and RAB
and call RMS directly: SYS$OPEN, SYS$CONNECT, SYS$GET.

Chapter 2 in the C Userguide explains all about the details:
http://h71000.www7.hp.com/commercial/c/docs/5492profile_009.html#index_sec

You would have to create a C - layout for the record. Chapter 5 has a section on CDD and CDDL usage.

But it could be directly re-mapped as:

struct mast_rec {
union {
char whole[20];
char key[4];
struct {
char act[4];
char name[16];
} parts;
} parts_union;
} mast_rec;

Typically you would not need the union as much in C as in Basic.
C is perfectly happy with

your_rab.rab$l_kbf = mast_rec.acct;
your_rab.rab$b_ksz = sizeof ( mast_rec.acct );

No need to call it both 'key' and 'acct'
And this 'whole' just becomes
address: &mast_rec, with size = sizeof (struct mast_rec);


Enjoy!
Hein.

Hoff
Honored Contributor

Re: Indexed files and c++

It appears you are seeking to port or to interoperate with BASIC code and related files from within a (new or updated) C/C++ application. Okfine.

You'll probably become familiar with DUMP (or with local code to perform a dump) here, to see exactly what is written into various records, and you'll also get familiar with the padding within records within a C structure. (See the #pragma member_alignment, for instance.)

As for code, there's a full source example
http://64.223.189.234/labsnotes/newuser102.zip which has a callable library of RMS operations in C, and record-level operations specifically with indexed files, and declarations and maintenance of record definitions using SDL (if that's of interest), which in aggregate should get you going.

Stephen Hoffman
HoffmanLabs LLC