Announcement

Collapse
No announcement yet.

Miva_struct_members() Issue Highly confused

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Miva_struct_members() Issue Highly confused

    Can someone please explain why i am getting this out put from this code. I use structured arrays a lot, and have never seen this.
    CODE:
    <MvOPENVIEW NAME = "trans_data" VIEW = "chk" QUERY = "{ 'select namount,cckno,cnmptcode from m6pttrnc where dactive = ' $ l.strat_date $ ' and cdesc = \'Credit Card Payment\'' }">
    <MvWHILE EXPR = "{ NOT chk.d.eof }">
    <MvIF EXPR = "{ chk.d.namount EQ 0 }">
    <MvSKIP NAME = "trans_data" VIEW = "chk" ROWS = "1">
    <MvWHILECONTINUE>
    </MvIF>
    <MvASSIGN NAME = "account_num" VALUE = "{ trim(glosub(chk.d.cnmptcode,'M','')) }">
    <MvASSIGN NAME = "old_amount" VALUE = "{ payments_arr[account_num]:amount }">
    <MvASSIGN NAME = "payments_arr" INDEX = "{ account_num }" MEMBER = "amount" VALUE = "{ old_amount + chk.d.namount }">
    <MvASSIGN NAME = "payments_arr" INDEX = "{ account_num }" MEMBER = "acct" VALUE = "{ chk.d.cnmptcode }">
    <MvASSIGN NAME = "payments_arr" INDEX = "{ account_num }" MEMBER = "auth" VALUE = "{ chk.d.cckno }">
    <MvASSIGN NAME = "payments_arr" INDEX = "{ account_num }" MEMBER = "sub_acct" VALUE = "{ account_num }">
    <MvSKIP NAME = "trans_data" VIEW = "chk" ROWS = "1">
    </MvWHILE>
    <MvCLOSEVIEW NAME = "trans_data" VIEW = "chk">



    <MvASSIGN NAME = "l.arraystuff" VALUE = "{ miva_struct_members(payments_arr,l.arrayinfo) }"><BR><BR>

    <br><MvEVAL EXPR = "{ 'miva_array_max: ' $ miva_array_max(payments_arr) }">
    <br><MvEVAL EXPR = "{ 'miva_member_exists amount: ' $ miva_member_exists(payments_arr,'amount') }">
    <br><MvEVAL EXPR = "{ 'miva_member_exists acct: ' $ miva_member_exists(payments_arr,'acct') }">
    <br><MvEVAL EXPR = "{ 'miva_member_exists auth: ' $ miva_member_exists(payments_arr,'auth') }">
    <br><MvEVAL EXPR = "{ 'miva_member_exists sub_acct: ' $ miva_member_exists(payments_arr,'sub_acct') }">
    <BR>Miva_struct_members amount:<MvEVAL EXPR = "{ l.arraystuff }">
    <BR>Miva_struct_members:<MvEVAL EXPR = "{ l.arrayinfo }">
    <BR>
    <br>
    <MvCLOSE NAME = "trans_data">

    My output from this code is as follows:
    miva_array_max: 200407759
    miva_member_exists amount: 0
    miva_member_exists acct: 0
    miva_member_exists auth: 0
    miva_member_exists sub_acct: 0
    Miva_struct_members amount:0
    Miva_struct_members:

    I am very confused. Hope i am doing something stupid and its easy. The array_max is correct, I am using account numbers as the index.
    This output shows it is not a structured array, but it runs through a foreach loop and i access these type's of arrays all day long as a structure.

    This started because my boss was trying to populate an array with:

    <MvASSIGN NAME = "referring:code" INDEX = "{ l.refcnt }" VALUE = "{ trim(referring.d.ccode) }">
    <MvASSIGN NAME = "referring:fname" INDEX = "{ l.refcnt }" VALUE = "{ trim(referring.d.cfname) }">
    <MvASSIGN NAME = "referring:lname" INDEX = "{ l.refcnt }" VALUE = "{ trim(referring.d.clname) }">
    <MvASSIGN NAME = "referring:npi" INDEX = "{ l.refcnt }" VALUE = "{ trim(referring.d.cnpi) }">

    I have never seen it done this way which brought up another interesting issue. With miva_struct_members() his code outputs the correct member
    structure, although miva_array_max() shows a -1. Also this would not run through a foreach loop.

    Maybe you guys could shed some light on this ?

  • I am also having an issue here. I do not understand it. It would be great if this could be explained.

    Comment


    • One issue could be you aren't scoping all your variables.

      Such as payments_arr -

      <MvASSIGN NAME = "l.arraystuff" VALUE = "{ miva_struct_members(payments_arr,l.arrayinfo) }">

      is not the same as

      <MvASSIGN NAME = "l.arraystuff" VALUE = "{ miva_struct_members(l.payments_arr,l.arrayinfo) }">

      Also, it's easier and cleaner to populate an array of structure members with miva_array_insert(....) instead of the reference stuff you are trying to do. See this article for details:

      https://www.scotsscripts.com/blog/mi...of-arrays.html
      Last edited by Scot - ScotsScripts.com; 06-23-20, 04:06 PM.
      M.A.D.* since 1997

      http://www.scotsscripts.com

      *miva application developers

      Comment


      • Squanchy26 your issue is 'payments_arr' is an array of structures, not a structure itself. You would need to do something like
        Code:
        <br><MvEVAL EXPR = "{ 'miva_member_exists amount: ' $ miva_member_exists(payments_arr[ARRAY_INDEX_HERE],'amount') }">
        David Carver
        Miva, Inc. | Software Developer

        Comment

        Working...
        X

        This website uses cookies to identify visitors, track visitors to our website, store login session information and to remember your user preferences. By continuing to use this site you agree to our use of cookies. Learn More.

        This website uses cookies. By continuing to use this site you agree to our use of cookies. Learn More.

        Accept