HP OpenVMS Systems

ask the wizard
Content starts here

Converting File Record Length?

» close window

The Question is:

 
How can I convert a 512-byte fixed-length file to 227-byte fixed-length.
 


The Answer is :

 
    You would have to define exactly how the mapping is supposed to happen.
    You will also want to consider the sequence of events leading up to
    this mismatch, particularly if network file transfers are occuring.
 
    For example, if only the first 227 bytes of each input record are
    needed, then a simple convert with truncate will do:
 
    	$CONVER/FDL=SYS$INPUT/TRUNCATE/STAT input.tmp output.tmp
    	record; fomat fixed; size 227
    	$
 
    If the 512-byte record file is really a 'byte stream' and needs to be
    chopped up in a 227 byte morsels, then you'll have to make a program
    in the langue of your preference to read the input, and reorganize the
    data into the desired output format.  A DCL sample is attached.
 
    For EVEN byte counts, one can merely change the file attributes to
    indicate the new record length:
 
    		$SET FILE/ATTRI=(MRS=256,LRL=256)
 
    However, for historical performance reasons, RMS starts records in
    a fixed and vairable length record files at 'word' boundaries: even.
    It will expexct/insert a FILL byte for odd record lengths.
 
    Sometimes the EXCHANGE/NET [/transfer=record]  tool can be used to
    alter files to become acceptable for the receiving end, but not in
    this case.
 
    Sometimes, you can simply declare the file as a byte stream
 
      SET FILE/ATT=RFM=UDF
 
    but comparitively few applications will honor this.
 
    Depending on what you are up to, a ZIP or a BACKUP saveset or similar
    omnibus file can be of use, particularly if you use a tool that will
    preserve OpenVMS file attributes.  (This assumes that the fixed-length
    512-byte transfer is occuring as a result of a network file transfer or
    other potential source of a record attributes corruption.)
 
    Alternatively, modifications to the application(s) -- to increase the
    tolerance of differing record formats -- could be required here.
 
 
$set noon
$open/read input input.tmp
$create/fdl=sys$input output.tmp
record; format fixed; size 227
$open/append output output.tmp
$data = ""
$n = 0
$loop:
$  l = f$len(data)
$  if l.ge.227
$   then
$    write output f$extr(0,227,data)
$    data = f$extr(227,999,data)
$    n = n + 1
$   else
$    read/end=done input record
$    data = data + record
$  endif
$  goto loop
$done:
$write sys$output "Created ''n' 227 byte records"
$if l.ne.0
$ then
$  f = 227 - 'l
$  write output data + f$fao("!''f'* ")
$  write sys$output "Added ''l' byte space padded record"
$endif
$close input
$close output
$exit
 
 
 

answer written or last revised on ( 8-JAN-2001 )

» close window