[Info-vax] How Do You Define Record (Data Structure) Dummy Arguments in Subroutine Definitions in HP Basic for OpenVMS?
Arne Vajhøj
arne at vajhoej.dk
Sat Dec 21 21:33:42 EST 2019
On 12/21/2019 12:55 PM, Neil Rieck wrote:
> I am assuming that "record size" in your question is referring to
> something written to disk. This depends upon the file type (in RMS,
> text files can be either "variable length" or "fixed"). Variable
> length records can be used in sequential files but not relative or
> indexed files. Click here to see three simple little hacks:
Index-sequential files can have variable length records.
Pascal:
type
datarec = record
id : [key(0)] integer;
data1 : integer;
data2 : varying [32] of char;
end;
var
isqf : file of datarec;
begin
open(isqf, 'p.isq', new, organization := indexed, access_method :=
keyed);
do result in:
$ dir/full p.isq
Directory DISK2:[ARNE]
P.ISQ;1 File ID: (4463,26,0)
Size: 16/16 Owner: [ARNE]
Created: 21-DEC-2019 22:14:49.49
Revised: 21-DEC-2019 22:14:49.50 (1)
...
File organization: Indexed, Prolog: 3, Using 1 key
...
File attributes: Allocation: 16, Extend: 0, Maximum bucket size: 2, ...
Record format: Fixed length 44 byte records
Record attributes: None
C:
struct datarec
{
int id;
int data1;
int data2len;
char data2[32];
};
static char *fnm = "c1.isq";
...
int main()
{
struct FAB fab;
struct RAB rab;
struct XABKEY xab;
...
long stat;
fab = cc$rms_fab;
fab.fab$l_fna = fnm;
fab.fab$b_fns = strlen(fnm);
fab.fab$b_org = FAB$C_IDX;
fab.fab$b_rfm = FAB$C_FIX;
fab.fab$b_rat = FAB$M_CR;
fab.fab$l_fop = FAB$M_CIF;
fab.fab$w_mrs = sizeof(struct datarec);
fab.fab$b_fac = FAB$M_PUT;
fab.fab$l_xab = (char *)&xab;
xab = cc$rms_xabkey;
xab.xab$b_dtp = XAB$C_STG;
xab.xab$w_pos0 = 0;
xab.xab$b_ref = 0;
xab.xab$b_siz0 =sizeof(int);
stat = sys$create(&fab,0,0);
fab.fab$l_xab = 0;
rab = cc$rms_rab;
rab.rab$l_fab = &fab;
rab.rab$b_rac = RAB$C_KEY;
stat = sys$connect(&rab,0,0);
also gives:
$ dir/full c1.isq
Directory DISK2:[ARNE]
C1.ISQ;1 File ID: (4465,27,0)
Size: 16/16 Owner: [ARNE]
Created: 21-DEC-2019 22:14:58.00
Revised: 21-DEC-2019 22:14:58.01 (1)
...
File organization: Indexed, Prolog: 3, Using 1 key
...
File attributes: Allocation: 16, Extend: 0, Maximum bucket size: 2, ...
Record format: Fixed length 44 byte records
Record attributes: Carriage return carriage control
but C:
struct datarec
{
int id;
int data1;
int data2len;
char data2[32];
};
static char *fnm = "c2.isq";
...
int main()
{
struct FAB fab;
struct RAB rab;
struct XABKEY xab;
...
long stat;
fab = cc$rms_fab;
fab.fab$l_fna = fnm;
fab.fab$b_fns = strlen(fnm);
fab.fab$b_org = FAB$C_IDX;
fab.fab$b_rfm = FAB$C_VAR;
fab.fab$b_rat = FAB$M_CR;
fab.fab$l_fop = FAB$M_CIF;
fab.fab$w_mrs = sizeof(struct datarec);
fab.fab$b_fac = FAB$M_PUT;
fab.fab$l_xab = (char *)&xab;
xab = cc$rms_xabkey;
xab.xab$b_dtp = XAB$C_STG;
xab.xab$w_pos0 = 0;
xab.xab$b_ref = 0;
xab.xab$b_siz0 =sizeof(int);
stat = sys$create(&fab,0,0);
fab.fab$l_xab = 0;
rab = cc$rms_rab;
rab.rab$l_fab = &fab;
rab.rab$b_rac = RAB$C_KEY;
stat = sys$connect(&rab,0,0);
gives:
$ dir/full c2.isq
Directory DISK2:[ARNE]
C2.ISQ;1 File ID: (4467,26,0)
Size: 16/16 Owner: [ARNE]
Created: 21-DEC-2019 22:15:06.43
Revised: 21-DEC-2019 22:15:06.44 (1)
...
File organization: Indexed, Prolog: 3, Using 1 key
...
File attributes: Allocation: 16, Extend: 0, Maximum bucket size: 2, ...
Record format: Variable length, maximum 44 bytes, longest 0 bytes
Record attributes: Carriage return carriage control
So Pascal and likely also Cobol, Fortran and Basic record structures
give you fixed length.
But direct RMS calls (necessary in C or Macro-32, possible but not
needed in above languages) you chose yourself between fixed and
variable.
Arne
More information about the Info-vax
mailing list