HP OpenVMS Systems

ask the wizard
Content starts here

Use SORT to select records, or a program?

» close window

The Question is:

 
I'm having a problem with the SORT/SPEC command. I need to remove unwanted
 records (based on a date/time field) from a file but all input records are
 propagating to the output file. I could have a DCL procedure read the file,
 but I figured SORT would be f
aster. I use the command;
$sort/spec=specfile infile outfile
 
The input file contains:
7 district names loaded.
123456789-123456789-123456789- this line is to count columns
MIM00326004061102003030319551
MIM00326005002702003030119551
MIM00326005002702003030319551
NSI12016003001012003030320154
NSI12016009601022003030320154
SOM11323001806062003030320401
SOM11323010806072003030322444
SLM00228714001562003030320074
SLM00216006603062003030319301
NRM01224005107202003030401184
NRM01224011909132003030323564
SJC11505860405872003030316331
SJC11505862806712003030316131
 
The specification file contains:
/pad=%x20
/field=(name=district,position:1,size:6,character)
/field=(name=unitid,position:7,size:10,character)
/field=(name=datetime,position:17,size:12,CHARACTER)
/field=(name=unitype,position:29,size:1,character)
/field=(name=today,value:"200303051200",size:12,character)
/ field=(name=tomorrow,value:"200303061200",size:12,character)
/condition=(name=istoday,test=(datetime ge today))
/condition=(name=istomorrow,test=(datetime le tomorrow))
/condition=(name=nottoday,test=(datetime lt today))
/condition=(name=nottomorrow,test=(datetime gt tomorrow))
/include=(condition=istoday)
/include=(condition=istomorrow)
/omit=(condition=nottoday)
/omit=(condition=nottomorrow)
 
I've tried the spec file with all upper case, switched "=" for ":" and no
 change; all input data goes to the output file. I am not using high
 performance sort, either. Any ideas? Thanks!
 
Dave
 


The Answer is :

 
  Your SORT command already looks rather complex, and the OpenVMS
  Wizard is not entirely certain which records you seek to select.
 
  The OpenVMS Wizard would use DCL, or would write a simple program
  in C or Perl or such.
 
  One possible problem with your example is that the values for both
  today and tomorrow are larger than all data values in your input
  file, for the datetime field.
 
  That said, if you are trying to select records whose datetime field
  falls between two values, here is one way to do that.
 
$ create s217.in
MIM00326004061102003030319551
MIM00326005002702003030119551
MIM00326005002702003030319551
NSI12016003001012003030320154
NSI12016009601022003030320154
SOM11323001806062003030320401
SOM11323010806072003030322444
SLM00228714001562003030320074
SLM00216006603062003030319301
NRM01224005107202003030401184
NRM01224011909132003030323564
SJC11505860405872003030316331
SJC11505862806712003030316131
$ create s217.spc
/pad=%x20
/field=(name=district,position:1,size:6,character)
/field=(name=unitid,position:7,size:10,character)
/field=(name=datetime,position:17,size:12,CHARACTER)
/field=(name=unitype,position:29,size:1,character)
/field=(name=today,   value:"200303031200",size:12,character)
/field=(name=tomorrow,value:"200303041200",size:12,character)
/condition=(name=between,test=((datetime ge today)
                           and (datetime le tomorrow)))
/include=(condition=between)
$ sort/spec=s217.spc s217.in s217.out
$ exit
 
  When using /condition with a compound condition, please make certain
  to specify the test with an outer enclosing set of parentheses
 
      test=((datetime ge today) and (datetime le tomorrow))
 
  instead of as follows
 
      test= (datetime ge today) and (datetime le tomorrow)
 
  SORT32 currently does not give a diagnostic in the 2nd
  case to warn that 'and (datetime le tomorrow)' is ignored
 
      http://h71000.www7.hp.com/doc/731FINAL/6652/6652pro_010.html#sort
 
  And as stated, selection with DCL might well be easier to maintain.
 

answer written or last revised on ( 2-APR-2003 )

» close window