intersystems-cachemumps

Validation Pattern MUMPS


I am working to create a program in M that reads an input of names in a certain format. Once the user places a null value it prints out all of the values. Where I am getting stuck is reading into a global variable. I look forward to any input I can receive.

          n prompt,val,done
          s prompt="Enter a name (LAST,FIRST MI): "
          s val="" f in=1:1 s val=$O(^ZNAME(val)) q:val=""
          f  w !,prompt r val q:val=""  d   q:done 
          . i val'?1.A1",".1" "1.A.1(1" "1A) w !,"Invalid name" q
          . s val=$GET(^ZNAME)
          . s done=1
          i val="" q  
          w !,"You entered: ",val
         . s done=1
         q

Solution

  • I don't completely understand what you want to do but this is what I built:

    Here you go:

    readlist
        N prompt,val
        S prompt="Enter a name (LAST,FIRST MI): "
        F  W !,prompt R val Q:val=""  D
        .   I val'?1.A1",".1" "1.A.1(1" "1A) W !,"Invalid name"
        .   E  S ^ZNAME(val)=""
        F  S val=$O(^ZNAME(val)) Q:val=""  D
        .   W !,"You entered: ",val
        Q
    

    Example (using GTM):

    GTM>D readlist^ZZTEST
    
    Enter a name (LAST,FIRST MI): first,last
    Enter a name (LAST,FIRST MI): name,surname
    Enter a name (LAST,FIRST MI):
    You entered: first,last
    You entered: name,surname
    GTM>zwr ^ZNAME
    ^ZNAME("first,last")=""
    ^ZNAME("name,surname")=""