 |
» |
|
 |
|
 |

Copyright (c) Digital Equipment Corporation 1988, 1991. All rights reserved
LAYERED PRODUCT: VAX PLI V3.4 OP/SYS: VMS V5.4-2
SOURCE: Digital Customer Support Center
OVERVIEW:
These programs demonstrate how to convert an ASCII file to EBCDIC
format and and EBCDIC file to ASCII format. They do this by calling the
Run Time Library routines LIB$TRA_EBC_ASC and LIB$TRA_ASC_EBC.
CAUTION: This sample program has been tested using VAX PLI V3.4 on
VMS V5.4-2. However, we cannot guarantee its effectiveness because of the
possibility of errors in transmitting or implementing it. It is meant
to be used as a template for writing your own program, and it may
require modification for use on your system.
PROGRAM NOTES:
The command file below has three steps:
1) create an ascii text file
2) create, compile, link and run a PL/I program to
convert the file to EBCDIC
3) create, compile, link and run a PL/I program to
convert the file back to ASCII.
A record dump is provided for each file. If the input/output file to
be read/written from/to is a tape it should be mounted as follows:
$MOUNT/FOREIGN/RECORD=record_size/BLOCK=multiple_of_record_size_in_bytes
PROGRAM SAMPLE:
$!begin EXTRACT
$!the following program creates a text ascii file
$create ascii.pli
creasc: proc options(main);
dcl outfile file output record env(block_size(80));
dcl 1 topoutrec union,
2 outrec char(80),
2 part2,
3 outname char(30),
3 outdate char(6),
3 outnum fixed bin(31),
3 filler char(40);
open file(outfile) title('ASCII.DAT');
outname = 'ASCII record ex 1';
outdate = '880901';
outnum = 1;
filler = ' ';
write file(outfile) from(topoutrec);
outname = 'ASCII record ex 2';
outdate = '881001';
outnum = 2;
filler = ' ';
write file(outfile) from(topoutrec);
outname = 'ASCII record ex 3';
outdate = '8801101';
outnum = 3;
filler = ' ';
write file(outfile) from(topoutrec);
close file(outfile);
end creasc;
$pli ascii.pli
$link ascii.obj
$run ascii.exe
$write sys$output "Created an ASCII file"
$!The following program converts an ASCII file to EBCDIC by calling
$!LIB$TRA_ASC_EBC.
$create ascebc.pli
vaxtoebc: proc options(main);
%include $iodef;
%include lib$TRA_ASC_EBC;
%include $STSDEF;
%include $ssdef;
dcl infile file input record env(block_size(80));
dcl outfile file output record env(block_size(80));
dcl 1 topoutrec union,
2 outrec char(80),
2 part2,
3 outname char(30),
3 outdate char(6),
3 outnum fixed bin(31),
3 filler char(40);
dcl eof bit(1) init('0'b);
dcl transoutrec char(80);
open file(infile) title('ASCII.DAT');
open file(outfile) title('EBCDIC.DAT');
on endfile(infile) EOF = '1'b;
read file(infile) into(topoutrec);
do while(^EOF);
sts$value = lib$tra_asc_ebc(outrec,transoutrec);
IF ^sts$success
then do;
put skip list('Problems with conversion');
signal vaxcondition(sts$value);
end;
write file(outfile) from(transoutrec);
read file(infile) into(topoutrec);
end;
close file(infile);
close file(outfile);
end vaxtoebc;
$pli ascebc.pli
$link ascebc.obj
$run ascebc.exe
$write sys$output "Created EBCDIC file from ASCII file"
$dump/record EBCDIC.DAT
$!The following program converts and EBCDIC file to ASCII by calling the
$!RTL routine LIB$TRA_EBC_ASC.
$create ebcasc.pli
ebctovax: proc options(main);
%include $iodef;
%include lib$TRA_EBC_ASC;
%include $STSDEF;
%include $ssdef;
dcl infile file input record env(block_size(80));
dcl outfile file output record env(block_size(80));
dcl eof bit(1) init('0'b);
on endfile(infile)
eof = '1'b;
dcl 1 topoutrec union,
2 outrec char(80),
2 part2,
3 outname char(30),
3 outdate char(6),
3 outnum fixed bin(31),
3 filler char(40);
dcl transoutrec char(80);
open file(outfile) title('ASCII.DAT');
open file(infile) title('EBCDIC.DAT');
read file(infile) into(transoutrec);
do while(^eof);
sts$value = lib$tra_ebc_asc(transoutrec,outrec);
IF ^sts$success
then do;
put skip list('Problems with conversion');
signal vaxcondition(sts$value);
end;
write file(outfile) from(topoutrec);
read file(infile) into(transoutrec);
end;
close file(infile);
close file(outfile);
end ebctovax;
$pli ebcasc.pli
$link ebcasc.obj
$run ebcasc.exe
$write sys$output "Created ASCII file from EBCDIC"
$dump/record ascii.dat
$del ascii.pli;,ascii.obj;,ascii.exe;
$del ebcasc.pli;,ebcasc.obj;,ebcasc.exe;
$del ascebc.pli;,ascebc.obj;,ascebc.exe;
$del ebcdic.dat;,ascii.dat;
$del ascii.dat;
$!end EXTRACT
|
buy online or call 1.800.AT.COMPAQ
|
|