XMXLIST ;ISC-SF/GMB-List message: multiple conditions ;03/01/2001  09:40
 ;;8.0;MailMan;;Jun 28, 2002
LISTMSGS(XMDUZ,XMK,XMFLDS,XMFLAGS,XMAMT,XMSTART,XMF,XMTROOT) ;
 ; XMDUZ is the user doing the search
 ; XMK is the place to look
 ;              =number - Look in this basket of the mailbox of XMDUZ
 ;              =*      - Look in all baskets of the mailbox of XMDUZ
 ;              =!      - Look in the MESSAGE file for all messages
 ;                        that XMDUZ sent or received.  If XMFLAGS["U"
 ;                        and the user (DUZ) holds the XM SUPER SEARCH
 ;                        key, ALL messages are examined,
 ;                        regardless of ownership.
 ; XMFLDS is a list, separated by ';', of fields to retrieve.
 ; e.g. XMFLDS="SUBJ;DATE" means retrieve subject and date.
 ;       "BSKT" = basket (default: <basket ien>^<basket name>)
 ;                optionally followed by ":" and
 ;                "I" for basket IEN only (no 2nd piece)
 ;                "X" adds basket name xref
 ;                (If XMK="!", and msg is not in user's mailbox, will be:
 ;                 "0^* N/A *")
 ;       "DATE" = date sent (default: <internal date>^<dd mmm yy hh:mm>)
 ;                optionally followed by ":" and
 ;                "I" for internal date only (no 2nd piece)
 ;                "F" for FileMan date as the 2nd piece
 ;                "X" adds FileMan date xref
 ;       "FROM" = message from (default: <internal from>^<external from>)
 ;                optionally followed by ":" and
 ;                "I" for internal from only (no 2nd piece)
 ;                "X" adds external from xref
 ;       "LINE" = number of lines in the message
 ;       "NEW"  = is the msg new? (0=no; 1=yes; 2=yes, and priority, too)
 ;       "PRI"  = is the message priority? (0=no; 1=yes)
 ;       "READ" = how much of the message has the user read?
 ;                null   = has not read the message at all
 ;                0      = has read the message, but no responses
 ;                number = has read through this response
 ;       "RESP" = how many responses does the message have?
 ;                0      = none
 ;                number = this many
 ;       "SEQN" = sequence number in basket (If XMK="!", and msg is not
 ;                in user's mailbox, will not be returned at all.)
 ;       "SUBJ" = message subject (always external)
 ;                optionally followed by ":" and
 ;                "X" adds subject xref
 ; XMFLAGS are used to control processing
 ;              =B Backwards order (Default is traverse forward)
 ;              =U Ignore the file screen on file 3.9 so that all
 ;                 messages can be examined.  (valid only if user holds
 ;                 XM SUPER SEARCH key and XMK="!")
 ;              If XMK="!", the following flags are ignored:
 ;              =C Use basket C-xref (Default is message IEN)
 ;              =N New messages only (C flag ignored)
 ;              =P New Priority messages only (C, N flags ignored)
 ; XMAMT        How many?
 ;              =number - Get this many
 ;              =*      - Get all (default)
 ; XMSTART is used to start the lister going.  The lister will keep it
 ; updated from call to call.  (If XMK="!", FileMan handles XMSTART,
 ; and you should look at FM documentation for an explanation.)
 ; XMSTART("XMK")  Start with this basket IEN (valid only if XMK="*")
 ;                 Continues from there, with each successive call,
 ;                 to the end.
 ;                 (Default is to start with basket .5, the WASTE basket)
 ; XMSTART("XMZ")  Start AFTER this message IEN (valid only if no C flag)
 ;                 Continues from there, with each successive call,
 ;                 to the end.
 ;                 (Default is to start at the beginning (or end) of the
 ;                 basket)
 ; XMSTART("XMKZ") Start AFTER this message C-xref (valid only if C flag)
 ;                 Continues from there, with each successive call,
 ;                 to the end.
 ;                 (Default is to start at the beginning (or end) of the
 ;                 basket)
 ; XMF contains conditions which are 'and'ed together to select only
 ; those messages which meet the conditions.
 ; XMF("FROM")  Message is from this person
 ; XMF("FDATE") Message was sent on or after this date
 ;              (If XMK="!", make sure this doesn't conflict w/XMF("PD"))
 ; XMF("FLINE") Message has this many or more lines
 ; XMF("PD")    Message was sent in this period (FM equiv. of yyy/yyymm)
 ;              (default is current month) (valid only if XMK="!")
 ; XMF("RFROM") Message has a response from this person
 ; XMF("SUBJ")  Subject contains this string
 ; XMF("SUBJ","C") =0 - Search is not case-sensitive (default)
 ;                 =1 - Search is case-sensitive
 ; XMF("TDATE") Message was sent on or before this date
 ;              (If XMK="!", make sure this doesn't conflict w/XMF("PD"))
 ; XMF("TEXT")  Message contains this string
 ; XMF("TEXT","L") =1 - Look in message only (default)
 ;                 =2 - Look in both message and responses
 ;                 =3 - Look in responses only
 ; XMF("TEXT","C") =0 - Search is not case-sensitive (default)
 ;                 =1 - Search is case-sensitive
 ; XMF("TLINE") Message has this many or fewer lines
 ; XMF("TO")    Message is to this person
 ; XMTROOT is the target root to receive the message list.
 ;              (default is ^TMP("XMLIST",$J))
 ;
 ; Variables set and used by the routine:
 ; XMF("SUBJ","S") Look for this string in the subject
 ; XMF("TEXT","S") Look for this string in the message
 ; XMF("PD","S")   Look for messages created during this period
 N XMORDER
 I XMDUZ'=DUZ,'$$RPRIV^XMXSEC Q
 D INIT(.XMFLDS,.XMFLAGS,.XMAMT,.XMORDER,.XMF,.XMTROOT)
 I XMK="!" D ALLMSGS(XMDUZ,$G(XMFLAGS),XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT) Q
 I XMK="*" D  Q
 . I XMFLAGS["P" D NEWA^XMXLIST1(XMDUZ,"N",XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT) Q
 . I XMFLAGS["N" D NEWA^XMXLIST1(XMDUZ,"N0",XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT) Q
 . I XMFLAGS["C" D REGAC^XMXLIST1(XMDUZ,XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT) Q
 . D REGAZ^XMXLIST1(XMDUZ,XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT)
 N XMKN
 S XMKN=$P(^XMB(3.7,XMDUZ,2,XMK,0),U,1)
 I XMFLAGS["P" D NEW1^XMXLIST2(XMDUZ,XMK,XMKN,"N",XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT) Q
 I XMFLAGS["N" D NEW1^XMXLIST2(XMDUZ,XMK,XMKN,"N0",XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT) Q
 I XMFLAGS["C" D REG1C^XMXLIST2(XMDUZ,XMK,XMKN,XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT) Q
 D REG1Z^XMXLIST2(XMDUZ,XMK,XMKN,XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT)
 Q
INIT(XMFLDS,XMFLAGS,XMAMT,XMORDER,XMF,XMTROOT) ;
 I $D(XMFLDS),XMFLDS="" K XMFLDS
 I $D(XMTROOT),XMTROOT'="" D
 . K @$$CREF^DILF(XMTROOT)
 . S XMTROOT=$$OREF^DILF(XMTROOT)_"""XMLIST"","
 E  D
 . K ^TMP("XMLIST",$J)
 . S XMTROOT="^TMP(""XMLIST"",$J,"
 I $D(XMF) D
 . I $D(XMF)'>9 K XMF Q
 . S:$D(XMF("SUBJ")) XMF("SUBJ","S")=$S('$G(XMF("SUBJ","C")):$$UP^XLFSTR(XMF("SUBJ")),1:XMF("SUBJ"))
 . I $D(XMF("TEXT")) D
 . . S XMF("TEXT","S")=$S('$G(XMF("TEXT","C")):$$UP^XLFSTR(XMF("TEXT")),1:XMF("TEXT"))
 . . I '$D(XMF("TEXT","L")) S XMF("TEXT","L")=1
 . I $D(XMF("PD")) S XMF("PD","S")=$S($E(XMF("PD"),4,5)="00":$E(XMF("PD"),1,3),1:$E(XMF("PD"),1,5))
 . I $D(XMF("FROM")) S XMF("FROM")=$$UP^XLFSTR(XMF("FROM"))
 . I $D(XMF("RFROM")) S XMF("RFROM")=$$UP^XLFSTR(XMF("RFROM"))
 . I $D(XMF("TO")),XMF("TO")["@" S XMF("TO")=$$UP^XLFSTR(XMF("TO"))
 S XMFLAGS=$G(XMFLAGS)
 S XMORDER=$S(XMFLAGS["B":-1,1:1)
 I $G(XMAMT)="" S XMAMT="*"
 Q
ALLMSGS(XMDUZ,XMFLAGS,XMORDER,XMFLDS,XMAMT,XMSTART,XMF,XMTROOT) ; Look in the entire MESSAGE file.
 N XMSCREEN,XMK,XMKN,XMZ,I,XMNA,XMCNT
 I XMFLAGS["U",'$$SSPRIV^XMXSEC1 Q
 S XMFLAGS=$TR(XMFLAGS,"CNP")
 I XMFLAGS["U" D AUDIT^XMJMFC(.XMF) Q:$D(XMERR)
 S XMSCREEN=$$SCREEN^XMJMFC(XMDUZ)
 ; File screen ^DD(3.9,0,"SCR") insists that user be author or recipient.
 ; If FLAGS["U", then file screen is ignored.
 D LIST^DIC(3.9,"","@",XMFLAGS,XMAMT,.XMSTART,$G(XMF("PD","S"),$E(DT,1,5)),"C",XMSCREEN)
 S I="",XMCNT=0,XMNA=$$EZBLD^DIALOG(34014) ; * N/A *
 F  S I=$O(^TMP("DILIST",$J,2,I),XMORDER) Q:I'>0  D
 . S XMZ=^TMP("DILIST",$J,2,I)
 . S XMCNT=XMCNT+1
 . S @(XMTROOT_XMCNT_")")=XMZ
 . Q:'$D(XMFLDS)
 . I $S(XMFLDS["BSKT":1,XMFLDS["NEW":1,XMFLDS["SEQN":1,1:0) D
 . . S XMK=+$O(^XMB(3.7,"M",XMZ,XMDUZ,0))
 . . S XMKN=$S(XMK:$P(^XMB(3.7,XMDUZ,2,XMK,0),U),1:XMNA)
 . . Q:'XMK
 . . I '$D(^XMB(3.7,XMDUZ,2,XMK,1,XMZ,0)) D ADDITM^XMUT4A(XMDUZ,XMK,XMZ)
 . . I XMFLDS["SEQN" D KSEQN^XMXLIST1(XMDUZ,XMK,XMZ,.XMFLDS,XMTROOT,XMCNT)
 . D FIELDS^XMXLIST1(XMDUZ,.XMK,.XMKN,XMZ,.XMFLDS,XMTROOT,XMCNT)
 S @(XMTROOT_"0)")=$G(^TMP("DILIST",$J,0)) ; # found^# requested^more?
 K ^TMP("DILIST",$J)
 Q
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HXMXLIST   8905     printed  Sep 23, 2025@19:50:12                                                                                                                                                                                                     Page 2
XMXLIST   ;ISC-SF/GMB-List message: multiple conditions ;03/01/2001  09:40
 +1       ;;8.0;MailMan;;Jun 28, 2002
LISTMSGS(XMDUZ,XMK,XMFLDS,XMFLAGS,XMAMT,XMSTART,XMF,XMTROOT) ;
 +1       ; XMDUZ is the user doing the search
 +2       ; XMK is the place to look
 +3       ;              =number - Look in this basket of the mailbox of XMDUZ
 +4       ;              =*      - Look in all baskets of the mailbox of XMDUZ
 +5       ;              =!      - Look in the MESSAGE file for all messages
 +6       ;                        that XMDUZ sent or received.  If XMFLAGS["U"
 +7       ;                        and the user (DUZ) holds the XM SUPER SEARCH
 +8       ;                        key, ALL messages are examined,
 +9       ;                        regardless of ownership.
 +10      ; XMFLDS is a list, separated by ';', of fields to retrieve.
 +11      ; e.g. XMFLDS="SUBJ;DATE" means retrieve subject and date.
 +12      ;       "BSKT" = basket (default: <basket ien>^<basket name>)
 +13      ;                optionally followed by ":" and
 +14      ;                "I" for basket IEN only (no 2nd piece)
 +15      ;                "X" adds basket name xref
 +16      ;                (If XMK="!", and msg is not in user's mailbox, will be:
 +17      ;                 "0^* N/A *")
 +18      ;       "DATE" = date sent (default: <internal date>^<dd mmm yy hh:mm>)
 +19      ;                optionally followed by ":" and
 +20      ;                "I" for internal date only (no 2nd piece)
 +21      ;                "F" for FileMan date as the 2nd piece
 +22      ;                "X" adds FileMan date xref
 +23      ;       "FROM" = message from (default: <internal from>^<external from>)
 +24      ;                optionally followed by ":" and
 +25      ;                "I" for internal from only (no 2nd piece)
 +26      ;                "X" adds external from xref
 +27      ;       "LINE" = number of lines in the message
 +28      ;       "NEW"  = is the msg new? (0=no; 1=yes; 2=yes, and priority, too)
 +29      ;       "PRI"  = is the message priority? (0=no; 1=yes)
 +30      ;       "READ" = how much of the message has the user read?
 +31      ;                null   = has not read the message at all
 +32      ;                0      = has read the message, but no responses
 +33      ;                number = has read through this response
 +34      ;       "RESP" = how many responses does the message have?
 +35      ;                0      = none
 +36      ;                number = this many
 +37      ;       "SEQN" = sequence number in basket (If XMK="!", and msg is not
 +38      ;                in user's mailbox, will not be returned at all.)
 +39      ;       "SUBJ" = message subject (always external)
 +40      ;                optionally followed by ":" and
 +41      ;                "X" adds subject xref
 +42      ; XMFLAGS are used to control processing
 +43      ;              =B Backwards order (Default is traverse forward)
 +44      ;              =U Ignore the file screen on file 3.9 so that all
 +45      ;                 messages can be examined.  (valid only if user holds
 +46      ;                 XM SUPER SEARCH key and XMK="!")
 +47      ;              If XMK="!", the following flags are ignored:
 +48      ;              =C Use basket C-xref (Default is message IEN)
 +49      ;              =N New messages only (C flag ignored)
 +50      ;              =P New Priority messages only (C, N flags ignored)
 +51      ; XMAMT        How many?
 +52      ;              =number - Get this many
 +53      ;              =*      - Get all (default)
 +54      ; XMSTART is used to start the lister going.  The lister will keep it
 +55      ; updated from call to call.  (If XMK="!", FileMan handles XMSTART,
 +56      ; and you should look at FM documentation for an explanation.)
 +57      ; XMSTART("XMK")  Start with this basket IEN (valid only if XMK="*")
 +58      ;                 Continues from there, with each successive call,
 +59      ;                 to the end.
 +60      ;                 (Default is to start with basket .5, the WASTE basket)
 +61      ; XMSTART("XMZ")  Start AFTER this message IEN (valid only if no C flag)
 +62      ;                 Continues from there, with each successive call,
 +63      ;                 to the end.
 +64      ;                 (Default is to start at the beginning (or end) of the
 +65      ;                 basket)
 +66      ; XMSTART("XMKZ") Start AFTER this message C-xref (valid only if C flag)
 +67      ;                 Continues from there, with each successive call,
 +68      ;                 to the end.
 +69      ;                 (Default is to start at the beginning (or end) of the
 +70      ;                 basket)
 +71      ; XMF contains conditions which are 'and'ed together to select only
 +72      ; those messages which meet the conditions.
 +73      ; XMF("FROM")  Message is from this person
 +74      ; XMF("FDATE") Message was sent on or after this date
 +75      ;              (If XMK="!", make sure this doesn't conflict w/XMF("PD"))
 +76      ; XMF("FLINE") Message has this many or more lines
 +77      ; XMF("PD")    Message was sent in this period (FM equiv. of yyy/yyymm)
 +78      ;              (default is current month) (valid only if XMK="!")
 +79      ; XMF("RFROM") Message has a response from this person
 +80      ; XMF("SUBJ")  Subject contains this string
 +81      ; XMF("SUBJ","C") =0 - Search is not case-sensitive (default)
 +82      ;                 =1 - Search is case-sensitive
 +83      ; XMF("TDATE") Message was sent on or before this date
 +84      ;              (If XMK="!", make sure this doesn't conflict w/XMF("PD"))
 +85      ; XMF("TEXT")  Message contains this string
 +86      ; XMF("TEXT","L") =1 - Look in message only (default)
 +87      ;                 =2 - Look in both message and responses
 +88      ;                 =3 - Look in responses only
 +89      ; XMF("TEXT","C") =0 - Search is not case-sensitive (default)
 +90      ;                 =1 - Search is case-sensitive
 +91      ; XMF("TLINE") Message has this many or fewer lines
 +92      ; XMF("TO")    Message is to this person
 +93      ; XMTROOT is the target root to receive the message list.
 +94      ;              (default is ^TMP("XMLIST",$J))
 +95      ;
 +96      ; Variables set and used by the routine:
 +97      ; XMF("SUBJ","S") Look for this string in the subject
 +98      ; XMF("TEXT","S") Look for this string in the message
 +99      ; XMF("PD","S")   Look for messages created during this period
 +100      NEW XMORDER
 +101      IF XMDUZ'=DUZ
               IF '$$RPRIV^XMXSEC
                   QUIT 
 +102      DO INIT(.XMFLDS,.XMFLAGS,.XMAMT,.XMORDER,.XMF,.XMTROOT)
 +103      IF XMK="!"
               DO ALLMSGS(XMDUZ,$GET(XMFLAGS),XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT)
               QUIT 
 +104      IF XMK="*"
               Begin DoDot:1
 +105              IF XMFLAGS["P"
                       DO NEWA^XMXLIST1(XMDUZ,"N",XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT)
                       QUIT 
 +106              IF XMFLAGS["N"
                       DO NEWA^XMXLIST1(XMDUZ,"N0",XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT)
                       QUIT 
 +107              IF XMFLAGS["C"
                       DO REGAC^XMXLIST1(XMDUZ,XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT)
                       QUIT 
 +108              DO REGAZ^XMXLIST1(XMDUZ,XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT)
               End DoDot:1
               QUIT 
 +109      NEW XMKN
 +110      SET XMKN=$PIECE(^XMB(3.7,XMDUZ,2,XMK,0),U,1)
 +111      IF XMFLAGS["P"
               DO NEW1^XMXLIST2(XMDUZ,XMK,XMKN,"N",XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT)
               QUIT 
 +112      IF XMFLAGS["N"
               DO NEW1^XMXLIST2(XMDUZ,XMK,XMKN,"N0",XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT)
               QUIT 
 +113      IF XMFLAGS["C"
               DO REG1C^XMXLIST2(XMDUZ,XMK,XMKN,XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT)
               QUIT 
 +114      DO REG1Z^XMXLIST2(XMDUZ,XMK,XMKN,XMORDER,.XMFLDS,XMAMT,.XMSTART,.XMF,XMTROOT)
 +115      QUIT 
INIT(XMFLDS,XMFLAGS,XMAMT,XMORDER,XMF,XMTROOT) ;
 +1        IF $DATA(XMFLDS)
               IF XMFLDS=""
                   KILL XMFLDS
 +2        IF $DATA(XMTROOT)
               IF XMTROOT'=""
                   Begin DoDot:1
 +3                    KILL @$$CREF^DILF(XMTROOT)
 +4                    SET XMTROOT=$$OREF^DILF(XMTROOT)_"""XMLIST"","
                   End DoDot:1
 +5       IF '$TEST
               Begin DoDot:1
 +6                KILL ^TMP("XMLIST",$JOB)
 +7                SET XMTROOT="^TMP(""XMLIST"",$J,"
               End DoDot:1
 +8        IF $DATA(XMF)
               Begin DoDot:1
 +9                IF $DATA(XMF)'>9
                       KILL XMF
                       QUIT 
 +10               if $DATA(XMF("SUBJ"))
                       SET XMF("SUBJ","S")=$SELECT('$GET(XMF("SUBJ","C")):$$UP^XLFSTR(XMF("SUBJ")),1:XMF("SUBJ"))
 +11               IF $DATA(XMF("TEXT"))
                       Begin DoDot:2
 +12                       SET XMF("TEXT","S")=$SELECT('$GET(XMF("TEXT","C")):$$UP^XLFSTR(XMF("TEXT")),1:XMF("TEXT"))
 +13                       IF '$DATA(XMF("TEXT","L"))
                               SET XMF("TEXT","L")=1
                       End DoDot:2
 +14               IF $DATA(XMF("PD"))
                       SET XMF("PD","S")=$SELECT($EXTRACT(XMF("PD"),4,5)="00":$EXTRACT(XMF("PD"),1,3),1:$EXTRACT(XMF("PD"),1,5))
 +15               IF $DATA(XMF("FROM"))
                       SET XMF("FROM")=$$UP^XLFSTR(XMF("FROM"))
 +16               IF $DATA(XMF("RFROM"))
                       SET XMF("RFROM")=$$UP^XLFSTR(XMF("RFROM"))
 +17               IF $DATA(XMF("TO"))
                       IF XMF("TO")["@"
                           SET XMF("TO")=$$UP^XLFSTR(XMF("TO"))
               End DoDot:1
 +18       SET XMFLAGS=$GET(XMFLAGS)
 +19       SET XMORDER=$SELECT(XMFLAGS["B":-1,1:1)
 +20       IF $GET(XMAMT)=""
               SET XMAMT="*"
 +21       QUIT 
ALLMSGS(XMDUZ,XMFLAGS,XMORDER,XMFLDS,XMAMT,XMSTART,XMF,XMTROOT) ; Look in the entire MESSAGE file.
 +1        NEW XMSCREEN,XMK,XMKN,XMZ,I,XMNA,XMCNT
 +2        IF XMFLAGS["U"
               IF '$$SSPRIV^XMXSEC1
                   QUIT 
 +3        SET XMFLAGS=$TRANSLATE(XMFLAGS,"CNP")
 +4        IF XMFLAGS["U"
               DO AUDIT^XMJMFC(.XMF)
               if $DATA(XMERR)
                   QUIT 
 +5        SET XMSCREEN=$$SCREEN^XMJMFC(XMDUZ)
 +6       ; File screen ^DD(3.9,0,"SCR") insists that user be author or recipient.
 +7       ; If FLAGS["U", then file screen is ignored.
 +8        DO LIST^DIC(3.9,"","@",XMFLAGS,XMAMT,.XMSTART,$GET(XMF("PD","S"),$EXTRACT(DT,1,5)),"C",XMSCREEN)
 +9       ; * N/A *
           SET I=""
           SET XMCNT=0
           SET XMNA=$$EZBLD^DIALOG(34014)
 +10       FOR 
               SET I=$ORDER(^TMP("DILIST",$JOB,2,I),XMORDER)
               if I'>0
                   QUIT 
               Begin DoDot:1
 +11               SET XMZ=^TMP("DILIST",$JOB,2,I)
 +12               SET XMCNT=XMCNT+1
 +13               SET @(XMTROOT_XMCNT_")")=XMZ
 +14               if '$DATA(XMFLDS)
                       QUIT 
 +15               IF $SELECT(XMFLDS["BSKT":1,XMFLDS["NEW":1,XMFLDS["SEQN":1,1:0)
                       Begin DoDot:2
 +16                       SET XMK=+$ORDER(^XMB(3.7,"M",XMZ,XMDUZ,0))
 +17                       SET XMKN=$SELECT(XMK:$PIECE(^XMB(3.7,XMDUZ,2,XMK,0),U),1:XMNA)
 +18                       if 'XMK
                               QUIT 
 +19                       IF '$DATA(^XMB(3.7,XMDUZ,2,XMK,1,XMZ,0))
                               DO ADDITM^XMUT4A(XMDUZ,XMK,XMZ)
 +20                       IF XMFLDS["SEQN"
                               DO KSEQN^XMXLIST1(XMDUZ,XMK,XMZ,.XMFLDS,XMTROOT,XMCNT)
                       End DoDot:2
 +21               DO FIELDS^XMXLIST1(XMDUZ,.XMK,.XMKN,XMZ,.XMFLDS,XMTROOT,XMCNT)
               End DoDot:1
 +22      ; # found^# requested^more?
           SET @(XMTROOT_"0)")=$GET(^TMP("DILIST",$JOB,0))
 +23       KILL ^TMP("DILIST",$JOB)
 +24       QUIT