I took the freedom to enhance the code a bit.

I did regret that there was no way to for example perform a hex sort.  So,
my enhancement allows the user to pass either simple arguments for the SORT
stage, or to pass a few stages, which would normally include a SORT.  I also
changed the parse of the input parameters.
I didn't like that such a SORT would not be seen as a change (the code
restored the alteration count).  So, I bump the alteration counts by 1.
And, there was no need to turn AUTOSAVE OFF while the macro runs.  XEDIT
performs an autosave only after that a macro ends.
Here's the result:
/* This XEDIT macro makes it possible to use PIPEs to sort in XEDIT
    +-----------------------------------------------------------+
    | format:  | PSORT sort_args                                |
    +-----------------------------------------------------------+
 "sort_args" can have two formats
 - arguments recognized by PIPE's SORT stage
   Example: PSORT W3.2
 - When "sort args" starts with a | character, then you can add some
   extra PIPE stages (you must explicitly insert the SORT stage too)
   Example: to sort minidisk addresses in Hex:
         PSORT |XLATE W4 A-F FA-FF |SORT W3.2|XLATE W4 FA-FF A-F
    or   PSORT |xlate W4 E2A |sort W3.2|xlate w4 A2E
   There is no check that a SORT stage is present.  As end-user you
   should assure there is at least one stage that buffers the records,
   otherwise XEDIT records get lost.

Created by:
 Mike Walter, Aon Corporation
 with the help of Rob van der Heij, Velocity
Some improvements by myself.
Written by: Kris Buelens IBM Belgium;  BUELENSC at BRUVMBRS 23 Dec 2010*/
/* PIPXESRT XEDIT - CMS Pipelines sort in XEDIT w/o disk I/O        */
/*                  No Pipelines Runtime Library (RTL) reliance     */
  parse source xos xct xfn xft xfm xcmd xenvir .

  parse arg operands
  if left(strip(operands,'L'),1)='|' then sortit=operands
  else sortit='|SORT' operands

 'COMMAND EXTRACT /MSGMODE/ALT/'       /* Current settings  */
 'COMMAND SET MSGMODE OFF'             /* Many line deletes */
 'COMMAND TOP'
  address command,
    'PIPE (END ?)' ,
       '| XEDIT',           /* Read recs from XEDIT ring file      */
       sortit,              /* Sort and pass XEDIT input recs      */
       '| o: FANOUT' ,      /* Copy sorted recs to XEDIT ring file */
       '| TAKE FIRST 1' ,   /* Do not buffer full file             */
       '| SPECS /:0 DELETE */' ,
       '| SUBCOM XEDIT' ,   /* Execute ":0 DELETE *" command       */
       '? o:' ,           /* Accept sorted records from FANOUT   */
         '| XEDIT'         /* Write sorted recs to XEDIT ring file*/
  src=rc
 'COMMAND SET ALT' alt.1+1 alt.2+1       /* Prevent AUTOSAVE & QUIT*/
 'COMMAND TOP'                             /* Back to first line */
 'COMMAND SET MSGMODE' msgmode.1           /* Restore setting    */
Exit src


2010/12/15 Mike Walter <mike.wal...@hewitt.com>

>
> Finally closing the loop with this thread:
> With offline help from Rob, the following are two slightly different means
> to accomplish the same thing - answering my original question about how to
> sort a file within XEDIT without performing disk I/O, and without needlessly
> buffering the whole file twice in XEDIT, and not even mentioning avoidance
> of the XEDIT command "INSERT" (which truncates very long records based on
> the maximum command line input).
>
> Mike Walter
> Aon Corporation
> The opinions expressed herein are mine alone, not my employer's.
>
> /* PIPXESRT XEDIT - CMS Pipelines sort in XEDIT w/o disk I/O        */
> /*                  No Pipelines Runtime Library (RTL) reliance     */
>   parse source xos xct xfn xft xfm xcmd xenvir .
>   parse upper arg parms 1 operands '(' options ')' parmrest
>
>   parse var operands sortargs
>
>  'COMMAND EXTRACT /MSGMODE/AUTOSAVE/ALT/'     /* Current settings  */
>   $alt.1=alt.1
>   $alt.2=alt.2
>
>  'COMMAND SET MSGMODE OFF'                    /* Many line deletes */
>  'COMMAND SET AUTOSAVE OFF'                   /* Many line deletes */
>  'COMMAND TOP'
>   address command,
>     'PIPE (END ?)' ,
>        '| XEDIT',           /* Read recs from XEDIT ring file      */
>        '| SORT' sortargs ,  /* Sort and pass XEDIT input recs      */
>        '| o: FANOUT' ,      /* Copy sorted recs to XEDIT ring file */
>        '| TAKE FIRST 1' ,   /* Do not buffer full file             */
>        '| SPECS /:0 DELETE */' ,
>        '| SUBCOM XEDIT' ,   /* Execute ":0 DELETE *" command       */
>        '? o:' ,             /* Accept sorted records from FANOUT   */
>          '| XEDIT'          /* Write sorted recs to XEDIT ring file*/
>   src=rc
>
>  'COMMAND SET ALT' $alt.1 $alt.2             /* Prevent AUTOSAVE   */
>  'COMMAND SET AUTOSAVE' autosave.1           /* Restore setting    */
>  'COMMAND TOP'                               /* Back to first line */
>  'COMMAND SET MSGMODE' msgmode.1             /* Restore setting    */
> Exit src
>
>
> The following is a nearly-identical version, but which requires the
> Pipelines RunTime Library "CONDITIONAL" keyword on the STRLITERAL stage
> (see: PIPELINE NEWS1111), and also provides an example of the "IF" stage.
>  The "IF" stage _is_ present in the distributed CMS Pipelines, just not
> documented there - perhaps because it was never fully tested?
>
>
> /* RTLXESRT XEDIT - CMS Pipelines sort in XEDIT w/o disk I/O        */
> /*                  Prereq: Pipelines Runtime Library (RTL) "COND"  */
>   parse source xos xct xfn xft xfm xcmd xenvir .
>   parse upper arg parms 1 operands '(' options ')' parmrest
>
>   parse var operands sortargs
>
>  'COMMAND EXTRACT /MSGMODE/AUTOSAVE/ALT/LRECL/'  /* Curr settings  */
>   $alt.1=alt.1
>   $alt.2=alt.2
>
>  'COMMAND SET MSGMODE OFF'                    /* Many line deletes */
>  'COMMAND SET AUTOSAVE OFF'                   /* Many line deletes */
>  'COMMAND TOP'
>   address command,
>     'PIPE (END ?)' ,
>        '| XEDIT',           /* Read recs from XEDIT ring file      */
>        '| SORT' sortargs ,  /* Sort and pass XEDIT input recs      */
>        '| STRLITERAL PREFACE CONDITIONAL /:0 DELETE */' , /*Preface*/
>        '| PAD' lrecl.1 ,    /* Force cmd to match file lrecl       */
>        '| x: IF TAKE' ,     /* "IF" recs (yes: ":0 DELETE *" + recs*/
>        '| SUBCOM XEDIT' ,   /* "THEN" execute ":0 DELETE *" cmd    */
>        '| x:' ,             /* "ELSE"                              */
>        '| XEDIT' ,          /* Write sorted recs to XEDIT ring file*/
>        '| x:'               /* "ENDIF"                             */
>   src=rc
>
>  'COMMAND SET ALT' $alt.1 $alt.2             /* Prevent AUTOSAVE   */
>  'COMMAND SET AUTOSAVE' autosave.1           /* Restore setting    */
>  'COMMAND TOP'                               /* Back to first line */
>  'COMMAND SET MSGMODE' msgmode.1             /* Restore setting    */
> Exit src
>
> ------------------------------
>
> The information contained in this e-mail and any accompanying documents may
> contain information that is confidential or otherwise protected from
> disclosure. If you are not the intended recipient of this message, or if
> this message has been addressed to you in error, please immediately alert
> the sender by reply e-mail and then delete this message, including any
> attachments. Any dissemination, distribution or other use of the contents of
> this message by anyone other than the intended recipient is strictly
> prohibited. All messages sent to and from this e-mail address may be
> monitored as permitted by applicable law and regulations to ensure
> compliance with our internal policies and to protect our business. E-mails
> are not secure and cannot be guaranteed to be error free as they can be
> intercepted, amended, lost or destroyed, or contain viruses. You are deemed
> to have accepted these risks if you communicate with us by e-mail.




-- 
Kris Buelens,
IBM Belgium, VM customer support

Reply via email to