Everhart, Glenn From: Waybright, Don [WaybrightD@tyson.com] Sent: Monday, July 20, 1998 2:12 PM To: Info-VAX@Mvb.Saic.Com Subject: RE: EBCDIC to ASCII conversion OpenVMS] Example-MACRO Translating Files From ASCII To EBCDIC Last Technical Review: 25-APR-1991 Size: 281 lines Any party granted access to the following copyrighted information (protected under Federal Copyright Laws), pursuant to a duly executed Digital Service Agreement may, under the terms of such agreement copy all or selected portions of this information for internal use and distribution only. No other copying or distribution for any other purpose is authorized. Copyright (c) Digital Equipment Corporation 1989, 1991. All rights reserved OP/SYS: OpenVMS VAX, All Versions OpenVMS AXP, All Versions COMPONENT: MACRO SOURCE: Digital Equipment Corporation OVERVIEW: This MACRO program can be useful when transferring files between an IBM system which uses the EBCDIC character set and an OpenVMS system using the ASCII character set. The program is written in MACRO because all sites should have the MACRO compiler as part of OpenVMS. This article is 274 lines long. *** CAUTION *** This sample program has been tested using the Macro-32 compiler on VMS V6.1. However, we cannot guarantee its effectiveness because of the possibility of error 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 program prompts for an input disk filename, an output filename and whether the input file was originally ASCII or EBCDIC. Since most file transfers will be via magtape, the data must first be copied to disk. The output file is the default text file, sequential with variable length records and implied carriage control. NOTE: The program limits the maximum record size to 2048. This could be changed. SAMPLE PROGRAM: ; ; ASCII_EBCDIC ; ; This program reads an ASCII or EBCDIC file on disk and then uses ; the appropriate runtime library routine to translate the data to ; the opposing character set. ; ; ; CHECK_STATUS MACRO, path out of program as well ; .macro check_status code=r0,?go,?not_eof cmpl code,#rms$_eof bneq not_eof jmp hit_eof not_eof: blbs code, go pushl code calls #1, g^lib$stop go: .endm check_status .psect data,long,wrt,noexe prompt1: .ascid /Name of input file to translate: / prompt2: .ascid /Name of output file to create or append to: / prompt3: .ascid /Is the input file (1) ASCII or (2) EBCDIC: / out_desc: .ascid /Value is out of range, program exiting./ infile_name: .blkb 255 infile_desc: .long 255 .address infile_name outfile_name: .blkb 255 outfile_desc: .long 255 .address outfile_name trans_return: .blkb 16 trans_desc: .long 1 .address trans_return trans_value: .long 0 in_record: .blkb 2048 ;Record buffer ;** Change here size to increase max record size ** out_record: .blkb 2048 ;Record buffer ;** Change here size to increase max record size ** in_rec_desc: .long 0 .address in_record out_rec_desc: .long 0 .address out_record .align long infab: $fab fac=get inrab: $rab fab=infab,- ;associated fab usz=2048,- ubf=in_record ;input buffer address ;** Change here size to increase max record size ** .align long outfab: $fab fac=put- fop=cif,- ;create if file doesn't exist org=seq,- ;organization (SEQ is default) rfm=var,- ;record type (variable) rat=cr,- ;implied carriage control mrs=2048 ;maximum record size ;** Change here size to increase max record size ** outrab: $rab fab=outfab,- ;associated fab rop=eof,- ;set up for put rbf=out_record ;input buffer address ; ; .title ASCII_EBCDIC, translates between ASCII and EBCDIC ; ;code here ; .psect code,exe,nowrt .entry start,^m ; ; This statement needs to be changed for versions prior to ; OpenVMS VAX Version 6.1 to the following: ; ; start: .word ^m ; ; ; prompt for input file spec ; pushal infile_desc pushal prompt1 pushal infile_desc calls #3,g^lib$get_input movb infile_desc,infab+fab$b_fns moval infile_name,infab+fab$l_fna ; ; prompt for output file spec ; pushal outfile_desc pushal prompt2 pushal outfile_desc calls #3,g^lib$get_input movb outfile_desc,outfab+fab$b_fns moval outfile_name,outfab+fab$l_fna ; ; prompt for whether input file is ASCII or EBCDIC ; pushal trans_desc pushal prompt3 pushal trans_desc calls #3,g^lib$get_input ; ; convert from text to integer ; pushal trans_value pushal trans_desc calls #2,G^ots$cvt_ti_l check_status check: ; ; check to make sure response in range ; subl #1,trans_value beql top cmpb #1,trans_value beql top jmp out_range top: ; ; open input and output files and connect record stream ; $open fab=infab ;Open the input file check_status $connect rab=inrab ;Connect record stream check_status $create fab=outfab ;Create/open the output check_status $connect rab=outrab ;Connect record stream check_status cmpb #1,trans_value beql input_ebcdic input_ascii: ; ; do the convert here from ASCII to EBCDIC ; $get rab=inrab check_status movzwl inrab+rab$w_rsz,in_rec_desc movzwl inrab+rab$w_rsz,out_rec_desc pushal out_rec_desc pushal in_rec_desc calls #2,g^lib$tra_asc_ebc movzwl out_rec_desc,outrab+rab$w_rsz $put rab=outrab brb input_ascii input_ebcdic: ; ; do the convert here from EBCDIC to ASCII ; $get rab=inrab check_status movzwl inrab+rab$w_rsz,in_rec_desc movzwl inrab+rab$w_rsz,out_rec_desc pushal out_rec_desc pushal in_rec_desc calls #2,g^lib$tra_ebc_asc movzwl out_rec_desc,outrab+rab$w_rsz $put rab=outrab brb input_ebcdic out_range: ; ; If response is out of range, output error msg and exit ; without doing anything. ; pushal out_desc calls #1,g^lib$put_output jmp bye hit_eof: ; ; normal program exit when we hit EOF ; $disconnect rab=outrab $disconnect rab=inrab $close fab=outfab $close fab=infab bye: ret .end start > -----Original Message----- > From: Leah Berkowitz [SMTP:lberkow1@gmford.com] > Sent: Monday, July 20, 1998 10:59 AM > To: Info-VAX@Mvb.Saic.Com > Subject: EBCDIC to ASCII conversion > > Does anyone know of a file conversion utility that will run at the DCL > level, to convert a file received from an IBM system into a format > that > VMS can handle? > > I know the OpenVMS RTL has a subroutine LIB$TRA_EBC_ASC, but I'm > trying > to avoid having to write code when there is probably already a utility > available. > > We are receiving this file as an email attachment sent from an IBM > mainframe (Advantis) and need to be able to read it on our VAX. > -- > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Leah M. Berkowitz > lberkow1@ford.com > Ford Motor Company World Headquarters > to send email, eliminate the competition