Help creating subroutine

43 views
Skip to first unread message

josephv...@gmail.com

unread,
Apr 7, 2022, 9:07:18 AM4/7/22
to OpenQM
Hello,

I have been working on a subroutine that I need some help with.  I have the following logic so far.

Subroutine WhereIf(Result, dynamic.array, boolean.array)
*  -----------------------------------------------------------------------
*  Name        : WhereIf
*  Description : Return multivalues/subvalues using boolean array
*  -----------------------------------------------------------------------
*
*  Notes
*  -----
*  This subroutine is designed to be used within an I-Descriptor dictionary.
*  Subroutine based on the !MATCHES subroutine on Universe
*
*  Use the WhereIf subroutine to return each element of one dynamic
*  array based on the boolean value in the elements of the second
*  dynamic array.  Each element of dynamic.array is compared
*  with the corresponding element of boolean.array. If the
*  element in boolean.array is true, then the corresponding element in
*  dynamic.array is returned in Result array.  If the element from
*  boolean.array is not true then no value is returned in the Result array.
*
*  Syntax
*  CALL WhereIf(Result, dynamic.array, boolean.array)
*
*  -----------------------------------------------------------------------
    Equate DefaultA TO ''
    Equate DefaultB TO ''

    Result = ''

    * Check for reuse of dynamic.array and boolean.array
    Reuse.AA = Reusing(dynamic.array) ;* QM Version
    Reuse.BB = Reusing(boolean.array) ;* QM Version

    * Reset Remove pointer for incoming variables
    dynamic.array = dynamic.array
    boolean.array = boolean.array

    Remove AA From dynamic.array Setting ALim
    Remove BB From boolean.array Setting BLim

    Loop
        Mark = If ALim >= BLim Then ALim Else BLim
        Delim = Char(256-Mark)

        If (BB = 1) Then Result := AA : Delim

        Begin Case
            Case ALim EQ BLim
                If ALim EQ 0 Then Exit
                Remove AA From dynamic.array Setting ALim
                Remove BB From boolean.array Setting BLim

            Case ALim > BLim
                If Not(Reuse.BB) Then BB = DefaultB
                Remove AA From dynamic.array Setting ALim

            Case ALim < BLim
                If Not(Reuse.AA) Then AA = DefaultA
                Remove BB From boolean.array Setting BLim
        End Case
    Repeat

    Result = Result[1,Len(Result)-1]
    Return
End


My problem is that the delimiter is not working correctly.  Essentially I am trying to leverage the ability of eqs, nes, lts, and other similar functions to return a filtered array.

So, with the following code

arr = '1,,,2,3]]],]]]4,]]]5]]],6]]7,,8,]]]],9,,'
convert ',]' to @AM:@VM in arr
Deffun WhereIf(array, array)
crt WhereIf(arr, nes(arr, reuse('')))


**commas are attribute marks and brackets are value marks.
What I am getting is this:  1,2,3]4,5]6]7,8,9
But what I am hoping to get is this:  1,2,3,4,5,6]7,8,9

Any idea what I am doing wrong?  It has been really difficult to navigate the arrays using the reuse logic so I am hoping for some assistance.  With the current code, the values are correct, but the delimiters are wrong in some instances.


Joseph

Martin Phillips

unread,
Apr 7, 2022, 11:03:41 AM4/7/22
to ope...@googlegroups.com

Hi Joseph,

 

I am a little confused about what you are trying to achieve here, however, I don’t think that the standard multivalue functions are going to give the desired result as they all preserve the multivalue structure whereas you appear to want to omit completely the blank items.

 

You may need to walk through the dynamic array using the REMOVE operation and copy only the desired items to an output string. A useful thing to know about REMOVE is that you can determine whether the item returned is a field, value or subvalue by looking at the delimiters either side of it. The item type corresponds to the lower of the two delimiters.

 

 

Martin

 

From: ope...@googlegroups.com <ope...@googlegroups.com> On Behalf Of josephv...@gmail.com
Sent: 07 April 2022 14:07
To: OpenQM <ope...@googlegroups.com>
Subject: Help creating subroutine

 

EXTERNAL EMAIL




--
You received this message because you are subscribed to the Google Groups "OpenQM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openqm+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openqm/eeb79dc8-457d-43ad-bd41-46859552f83bn%40googlegroups.com.

================================
Rocket Software, Inc. and subsidiaries ■ 77 Fourth Avenue, Waltham MA 02451 ■ Main Office Toll Free Number: +1 855.577.4323
Contact Customer Support: https://my.rocketsoftware.com/RocketCommunity/RCEmailSupport
Unsubscribe from Marketing Messages/Manage Your Subscription Preferences - http://www.rocketsoftware.com/manage-your-email-preferences
Privacy Policy - http://www.rocketsoftware.com/company/legal/privacy-policy
================================

This communication and any attachments may contain confidential information of Rocket Software, Inc. All unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify Rocket Software immediately and destroy all copies of this communication. Thank you.

josephv...@gmail.com

unread,
Apr 7, 2022, 11:13:23 AM4/7/22
to OpenQM
I'm using the boolean.array variable to pass the results of potentially complex selection criteria using a mix of ands, ors, eqs, nes, etcetera.  I then am essentially using remove to navigate the structures and return every component of dynamic.array where the corresponding element of boolean.array is a 1.  That way I can use this function to remove empty values, or I can return only values that are greater than X but less than Y, etcetera.  The purpose of this function is to use in a I-Type dictionary without the need to write a program for every combination of checks.  I know the standard multivalue functions do not give me what I am looking for and that is why I have created this function.  The function itself works for an array of a single depth, but having the depth poses a complication to the logic.

If what I am looking to accomplish is not possible, then that's fine but since I am getting the correct values but not the preserved structure, I thought I would ask for help.

Reply all
Reply to author
Forward
0 new messages