| Front Page | News Headlines | Technical Headlines | Planning Features | Advanced Search |
Robelle Sponsor Message

February 2003

Get the most out of your Robelle Tools

Latest Tips for Qedit and Suprtool

How to Change Trailing Spaces to Leading Zeroes

If you have an ASCII fixed-column flat file that contains a column with left-justified numerics and you wish to change those numerics to be right-justified with leading zeros, there are two ways to do it. One uses Qedit and the other uses MPE commands.

For example, if you have a file that contains the following records:

other data
more stuff
last record

and you want it to look like:

xxxxxx00001234other data
yyyyyy00000066more stuff
zzzzzz00098765last record

you can use one of the following two methods

Method 1: Using Qedit:

/Text datafile
/Set left 7     { first digit }
/Set right 14   { last digit }
/Justify right  @
/C " "0" @
/Set left       { reset to first column }
/Set right      { reset to last column }

Method 2: Using an MPE command file:

parm infile="~", entry="Main", eofparm=0

if "!entry" = "Main"
   setvar start_pos 7
   setvar field_len 8
   # build a temporary, "randomly"-named
   # holding file for the updated data
   setvar tmp_outfile "T" + rht("0000000" + "!HPCPUMSECS",7)
   setvar in_eof finfo('!infile','eof')
   setvar in_recsize finfo('!infile','byterecsize')
   build !tmp_outfile;rec=-!in_recsize,,f,ascii; disc=!in_eof
   file outfile=!tmp_outfile,old
   # run command again with alternate entry point
    xeq !hpfile dummy, Replace, !in_eof < !infile
   purge !infile
   rename !tmp_outfile, !infile
   reset outfile
   deletevar tmp_outfile, in_eof, in_recsize, i, &
       file_rec, start_pos, field_len,   &
       first_part, new_field, last_part

if "!entry" = "Replace"
   setvar i 0
   while setvar (i, i+1) <= !eofparm
      input file_rec
      setvar first_part str(file_rec, 1, start_pos-1)
      setvar new_field rht( rpt("0",field_len) + &
         rtrim(str(file_rec,start_pos,field_len)), &
              field_len )
      setvar last_part str(file_rec, &
            start_pos + field_len,        &
            in_recsize - start_pos - field_len )
      echo !first_part!new_field!last_part>>*outfile

The syntax for using the command file (assuming the command file is named “zerofill” and the data file is named “mydata”) would be :ZEROFILL MYDATA


Both methods require that the user change the starting position and the length or ending position to fit their needs. Further, the command file method requires that the input record size must be less than or equal to the lesser of

a) the maximum length of a CI string variable, or

b) the maximum length of a CI command string minus the lengths of the strings “echo” and “>>*outfile”

Credits: The MPE command file solution is from Barry Lake at Allegro, and the Qedit solution is from François Desrochers of Robelle.

How To Combine Three Fields Into One Field?

Tech support question of the week:

I want to concatenate three fields to one field, enthr,“:”,entmin. How do I make the three fields into one, with no separators, if I output as a comma delimited field?

Answer: You can concatenate three fields in Suprtool by doing the following:

DEFINE myfield,1,30,byte

EXTRACT myfield = $trim(enthr) + “:” + $trim(entmin)

The resulting field will have the contents of the three fields with both leading and trailing spaces trimmed. For more details and examples on string functions, please see the following page on our Web site: www.robelle.com/tips/st-strings.html

Hint: If your fields are of type Z (zoned numeric display), you need to use Define to redeclare them as type Byte before you can use string functions on them in Suprtool.

Qedit/UX “Length” Option

Host-based Qedit for HP-UX pre-release 5.3.13 is ready for download by users interested in testing the new improved ability to edit data files.

The version’s Text command has a new option called Length.

When specified, Qedit folds lines at the specified number of characters. This option makes it easier to handle all types of files whether they contain Newline delimiters or not.

The List command has a new $length option to perform a similar operation while listing a file. Set Keep LF ON requests that the file be kept with Newline delimiters after each line. Set Keep LF OFF requests that the file be kept without Newline delimiters. Similar file formats are obtained using the LF and NOLF options of the Keep command.

Any Qedit/UX user who would like to test this new feature should send e-mail to francois@robelle.com


Copyright The 3000 NewsWire. All rights reserved.