Remove Duplicate values in a variable

 
  • How to remove the duplicate values in a variables ($!COLL[$!A])

    var !coll COLL all ATTA with matchwILD(NAME,'*valv*') EQ T FOR $!REF
    DO !A FROM 1 TO !COLL.SIZE()
    $!COLL[$!A]
  • Hi Chiyashadab,

    You can use the ".unique()" method to remove duplicates:


    [COLOR=#333333]var !coll COLL all ATTA with matchwild(NAME,'*valv*') FOR $!REF
    [/COLOR]!coll.unique()
  • var !coll COLL all ATTA with matchwILD(NAME,'*SST*') EQ T FOR $!REF
    DO !A FROM 1 TO !COLL.SIZE()
    $!COLL[$!A]
    VAR !HEIS NAME
    !HEIA = !HEIS.BEFORE ('/DATUM')
    !HEIB = !HEIA.BEFORE ('/SREF')
    !HEIC = !HEIB.BEFORE ('.')



    $P $!HEIC

    [COLOR=#333333]How to remove the duplicate values in a variables ([/COLOR]$!HEIC[COLOR=#333333])[/COLOR]
  • In your example, !HEIC is a String.

    I'm not sure to understand what you are trying to do.

    Can you explain with an example of the content of !HEIC, and the result you expect please ?
  • IF BELOW ARE THE !COLL VARIABLES

    $!COLL[1] = SST-00053/DATUM
    $!COLL[2] = SST-00053/SREF
    $!COLL[3] = SST-00054/DATUM
    $!COLL[4] = SST-00054.1
    $!COLL[5] = SST-00055.1
    $!COLL = SST-00058.1
    $!COLL[7] = SST-00056.1
    $!COLL[7] = SST-00058/DATUM


    My result should be
    SST-00053
    SST-00054
    SST-00055
    SST-00056
    SST-00058
  • In your loop you can try:


    [COLOR=#3E3E3E]VAR !heis NAMN[/COLOR]

    If !heis.matchwild('*/*') Then
        !firstPart = !heis.before('/')
    Elseif !heis.matchwild('*.*') Then
        !firstPart = !heis.before('.')
    Else
        !firstPart = !heis
    Endif

    $p $!firstPart


    But if you can, it is cleaner to use the parent's name or the name of a reference linked to the element.
  • thanks
    if is use your PML result will be as below

    $!firstpart
    [COLOR=#333333]SST-00053[/COLOR]
    [COLOR=#333333]SST-00053[/COLOR][/U]
    [COLOR=#333333]SST-00054[/COLOR]
    [COLOR=#333333]SST-00054[/COLOR][/U]
    [COLOR=#333333]SST-00055
    [/COLOR][COLOR=#333333]SST-00058[/COLOR]
    [COLOR=#333333]SST-00056
    [/COLOR][COLOR=#333333]SST-00058[/U]



    My requirement is to remove the duplicate from variable $!firstpart  only non duplicated name to reported [/COLOR]
  • There are two ways to do this:

    1) Store all your values in an Array, and remove duplicates from this Array with ".unique()" method:


    !data = ARRAY()
    var !coll COLL all ATTA with matchwild(NAME,'*SST*') FOR $!REF

    Do !i index !coll
    !heis = NAME OF $!coll[$!i]
    If !heis.matchwild('*/*') Then
    !firstPart = !heis.before('/')
    Elseif !heis.matchwild('*.*') Then
    !firstPart = !heis.before('.')
    Else
    !firstPart = !heis
    Endif
    [COLOR=#3E3E3E]!data.append(!firstPart)
    Enddo

    !data.unique()

    q var !data
    [/COLOR]


    2) Add the value if it has never been found:


    !data= ARRAY()
    var !coll COLL all ATTA with matchwild(NAME,'*SST*') FOR $!REF

    Do !i index !coll
    !heis = NAME OF $!coll[$!i]
    If !heis.matchwild('*/*') Then
    !firstPart = !heis.before('/')
    Elseif !heis.matchwild('*.*') Then
    !firstPart = !heis.before('.')
    Else
    !firstPart = !heis
    Endif

    If !
    data.findfirst(!firstPart).unset() Then
    !data.append(!firstpart)
    Endif
    [COLOR=#3E3E3E]
    Enddo

    q var !data

    [/COLOR]
  • Thank you L  
    its is working
    by changing this line

    [COLOR=#333333]!heis = NAME OF $!coll[$!i]

    AS

    [/COLOR][COLOR=#333333]!heis = NAMN OF $!coll[$!i]


    [/COLOR]
  • I have many comment atta with different locations and different STEXT. But in some case stext  is duplicate how to delete the duplicate one and make it unique.