SetAt() command not working for insert into 2nd value mark position when value is null

6 views
Skip to first unread message

Rich Brim

unread,
May 16, 2012, 6:49:59 PM5/16/12
to InterSystems: MV Community
I am having some problems with the following code. I am trying to
insert some data and some data is getting lost. Is there any way to
solve this?

CRT 'ENTER CIT':
INPUT ID
pSource = "MVFILE.CITATION"->%OpenId(ID)

POS=pSource->PAYMENTAMT->Count() + 1
pSource->PAYMENTBYUSER->SetAt(@AUTHORIZATION,POS)
pSource->PAYMENTBATCH->SetAt('BATCH',POS)
pSource->PAYMENTTYPE->SetAt('',POS)
pSource->PAYMENTSOURCE->SetAt('SOURCE',POS)
pSource->PAYMENTAMT->SetAt(POS,POS)

before
--------------------------------
LCONV
LCONV


0

---------------------------
after
---------------------------
LCONV<vm> rbrim
LCONV<vm> BATCH


0 <vm>200

---------------------------
should be
---------------------------
LCONV<vm> rbrim
LCONV<vm> BATCH
<vm>
<vm> SOURCE
0 <vm>200

---------------------------

thanks,
Rich

Ed Clark

unread,
May 18, 2012, 4:22:56 PM5/18/12
to intersy...@googlegroups.com
The documentation for %Collection.MV.ListOfDT SetAt() doesn't mention it though the doc for InsertAt() does: the value for POS needs to be between 1 and count()+1. You can't set an element that's more than 1 greater than count(). I think that's part of the fundamental definition of a "list" vs an "array"--you can only add at the end of a list, not past it. If you change the code to:
ST=pSource->PAYMENTSOURCE->SetAt('SOURCE',POS)
crt $SYSTEM.Status->GetErrorText(ST)
you should see:
ERROR #5820: Collection key '2' is invalid Because there isn't already an element 1.

I think the workaround would be to check the Count() on every property, and Insert() empty elements until they are all the same length as the key property PAYMENTAMT. (or write a method SetAtPad() which would do it)
> --
> You received this message because you are subscribed to the Google Groups "InterSystems: MV Community" group.
> To post to this group, send email to Cac...@googlegroups.com
> To unsubscribe from this group, send email to CacheMV-u...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/CacheMV?hl=en

Peter Lynch

unread,
May 19, 2012, 2:25:08 AM5/19/12
to intersy...@googlegroups.com
Why the restriction of SetAt? If the programmer wants to set pos 2, and no pos 1 exists, so what? Why not just set it?

Reply all
Reply to author
Forward
0 new messages