Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Engineering

Example Macro for Collecting and Deleting Old Commands

Example Macro for Collecting and Deleting Old Commands

  • Last UpdatedJun 28, 2022
  • 2 minute read

The PML Function below allows transactions older than a specified number of days to be deleted. This is an alternative to using Transactions Merge/Purge in Automatic Merging and Purging of a Transaction Database. This function must be copied into PMLLIB (under Global\functions). It may be run using !!purgeTransaction(value) where value is the number of days to retain:

define function !!PurgeTransaction(!days is REAL)

  if (!days gt 28) then

    !!Alert.error('Maximum purge time is 28 days')

    return

  endif

  if (not !!Alert.Confirm('The local daemon must be shut down before you
  can continue with the purge/merge operation.   Do you wish to continue?').Boolean()) then

    return

  endif

  $P Searching for complete transactions...

  !monlengths = '31,28,31,30,31,30,31,31,30,31,30,31'

  !today = object DATETIME()

  !year = !today.year()

  !month = !today.month()

  !day = !today.date()

  !hour = !today.hour()

  !minute = !today.minute()

  !second = !today.second()

  !day = !day - !days

  if (!day lt 1) then

    !month = !month - 1

    if (!month lt 1) then

      !year = !year - 1

      !month = 12

    endif

    if (!month eq 2) then

      !leaptest = (!year - 2000) / 4

      if (!leaptest eq !leaptest.int()) then

        !day = 29 + !day

      else

        !day = 28 + !day

      endif

    else

      !day = !monlengths.split(',')[!month].real() + !day

    endif

  endif

  !date = object DATETIME(!year,!month,!day,!hour,!minute,!second)

  !collection = object COLLECTION()

  GOTO FRSTW TRAN

  !collection.scope(!!ce)

  !filter = object EXPRESSION('upc(TSTATE) eq |COMPLETE|')

  !collection.filter(!filter)

  !collection.type('TRINCO')

  !trincos = !collection.results()

  !promptstr = 'Found ' & !trincos.size().string() & ' complete transactions...'

  $P $!promptstr

  !promptstr = 'Deleting obsolete transactions more than ' & !days.string( & ' days old...'

  $P $!promptstr

  !numdel = 0

  !numh = 0

  do !trinco values !trincos

    !datecm = object DATETIME(!trinco.datecm)

    !datend = object DATETIME(!trinco.datend)

    if (!trinco.incsta.upcase() eq 'PROCESSED' and !datecm.lt(!date) or !trinco.incsta.upcase().inset('TIMED OUT','CANCELLED','REDUNDANT') and !datend.lt(!date)) then

      !numdel = !numdel + 1

      !!CE = !trinco

      DELETE TRINCO

      if (!!CE.members.size() eq 0) then

        DELETE TRLOC

        !numh = !numh + 1

        if (!!CE.members.size() eq 0) then

          DELETE TRUSER

          !numh = !numh + 1

          if (!!CE.members.size() eq 0) then

            DELETE TRDAY

            !numh = !numh + 1

            if (!!CE.members.size() eq 0) then

              DELETE TRMONT

              !numh = !numh + 1

              if (!!CE.members.size() eq 0) then

                DELETE TRYEAR

                !numh = !numh + 1

              endif

            endif

          endif

        endif

      endif

    endif

  enddo

  $P  $!numdel obsolete transactions deleted

  $P  $!numh associated hierarchy elements deleted

  if (!numdel eq 0) then

    $P No merge necessary

    !!Alert.Message('No obsolete transactions found')

  else

    !cs = CURRENT SESSION

    !locrf = !cs.locationname.dbref()

    !transdbstr = 'TRANSACTION/' & !locrf.locid

    !promptstr = 'Merging all sessions of transaction DB ' & !transdbstr & '...'

    $P $!promptstr

    MERGE CHANGES $!transdbstr

    $P Merge complete

    !!Alert.Message(!numdel.string() & ' obsolete transactions deleted - transaction database purge/merge complete')

  endif

endfunction

TitleResults for “How to create a CRG?”Also Available in