Ankündigung

Einklappen
Keine Ankündigung bisher.

PML-Function für DB-Listing ("DATAL") inklusive Fehler-Log

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • [Info] PML-Function für DB-Listing ("DATAL") inklusive Fehler-Log

    Hallo Leute,

    hier eine schöne Funktion für euch: Kurze Erklärung: Ihr macht ein "DATAL" (DB-Listing) von einem Element, ... dieses DB-Listing wird später wieder als "Makro" ($M) eingespielt. Hierbei entstehen ggf. Fehler.
    Diese Funktion hat den Vorteil, die Fehler sauber in einer XLS-Datei zu protokollieren.

    Speichern als: "DBlistingPlus.pmlfnc"

    Aufruf: 2 Arten:
    - "Nur DB-Listing erzeugen" = "!!DBlistingPlus('TXT')"
    - "DB-Listing erzeugen + CE löschen" = "!!DBlistingPlus('DEL')"

    Das DB-Listing wird unter "%PDMSUSER%\DB-Listing_Plus\ABC" abgelegt.
    Das Fehlerprotokoll beim Wiedereinspielen (XLS-Datei) wird unter "%PDMSWK%" (z.B. "C:\Temp") angelegt und immer wieder überschrieben.

    Hier also der Code:
    Code:
    define function !!DBlistingPlus(!Mode is STRING)
     handle (46,68)
      !!alert.error(|Please start function with (STRING) option: "!!DBlistingPlus('del')" or "!!DBlistingPlus('txt')"|)
      RETURN
     endhandle
     
     if !Mode.upcase().eq(|DEL|) then
      if !!ce.lock then
       !!alert.Error(|Aborted! CE is locked! First UNLOCK it to delete it!|)
       RETURN
      endif
     endif
     
     var !pdmsuser evar 'PDMSUSER'
    
     !tdate = object datetime()
     !dateform = object DATEFORMAT('Y')
     !dateform.YEAR(4)
     !DateYear = !dateform.STRING(!tdate)
     !dateform = object DATEFORMAT('M')
     !DateMonth = !dateform.STRING(!tdate)
     !dateform = object DATEFORMAT('D')
     !DateDay = !dateform.STRING(!tdate)
     !DateHour = !tdate.HOUR().STRING()
     if !DateHour.REAL().LT(10) then
      !DateHour = '0' + !DateHour
     endif
     !DateMin = !tdate.MINUTE().STRING()
     if !DateMin.REAL().LT(10) then
      !DateMin = '0' + !DateMin
     endif
     !Date = !DateYear + !DateMonth + !DateDay + 'T' + !DateHour + !DateMin
    
     !cp = CURR PROJ
     !proj = !cp.Code()
     var !projectPath evar '$!proj$nJOB'
     
     !ce = !!ce.name
     !type = !!ce.type
    
     !cen = subs(!ce,2,100)
     !cen = !cen.replace('/','-')
     !cen = !cen.replace('=','-eq-')
     !cen = !cen.replace('<','-lt-')
     !cen = !cen.replace('>','-gt-')
     !cen = !cen.replace('*','-star-')
     !cen = !cen.replace('?','-q-')
     
     var !prev prev
       handle (2,113)
       !prev = 'None'
       endhandle
    
     var !name login
     !login = !name.replace(' ','_')
     var !dbnum dbnum
     var !dbname dbname
    
     !OWNlst = !!ce.OwnLst
     !DDEP1 = ''
     !DDEP2 = ''
     DO !x index !OWNlst
      $!OWNlst[$!x]
      if !!ce.ddep.eq(2) then
        !DDEP2 = !!ce.type + ' ' + !!ce.name
      elseif !!ce.ddep.eq(1) then
        !DDEP1 = !!ce.type + ' ' + !!ce.name
      endif
     ENDDO
     
     
     !filename = string()
     !PATH = object FILE(|$!pdmsuser$n\DB-Listing_Plus\$!proj$n|)
     if !Mode.upcase().eq(|TXT|) then
      !filename = !date + '__' + !proj + '__' + !cen + '__DB-Listing_Plus.txt'
     elseif !Mode.upcase().eq(|DEL|) then
      !filename = !date + '__' + !proj + '__' + !cen + '__DELETED.txt'
     endif
     
     if !PATH.exists().not() then
      syscom 'mkdir $!PATH'
     endif
     
     -- Jump back to "CE"
     $!ce
     
     !ZIELDATEI = object file(|$!PATH$n\$!filename|)
     
     if !ZIELDATEI.exists() then
      !ZIELDATEI.deletefile()
     endif
     !ZIELDATEI.open('OVERWRITE')
      !ZIELDATEI.writerecord(||)
      !ZIELDATEI.writerecord(||)
      !ZIELDATEI.writerecord(|-- Element TYPE: $!type|)
      !ZIELDATEI.writerecord(|-- Element NAME: $!ce|)
     
      if !Mode.upcase().eq(|TXT|) then
       !ZIELDATEI.writerecord(|-- DB-Listing created: $!date  by $!name|)
      elseif !Mode.upcase().eq(|DEL|) then
       !ZIELDATEI.writerecord(|-- Element deleted: $!date  by $!name|)
      endif
     
      !string1 = |$S-|
      !string2 = |$S+|
     
      !ZIELDATEI.writerecord(||)
      !ZIELDATEI.writerecord(|-- Hierarchy:|)
      !ZIELDATEI.writerecord(|-- DB-NAME:   $!dbname|)
      !ZIELDATEI.writerecord(|-- DB-NUMBER: $!dbnum|)
      !ZIELDATEI.writerecord(|--            $!DDEP1|)
      !ZIELDATEI.writerecord(|--            $!DDEP2|)
      !ZIELDATEI.writerecord(|-- (Further) Previous Element: $!prev|)
    
     $p
     $p Starting to create a "DB-Listing Plus":
     
     !filename = 'DBlistingPlus-Error-Log.txt'
     var !pfad evar 'PDMSWK'
     !pfad = !pfad.part(1).trim()
     !PATH = object FILE(!pfad)
     !errorLogFile = object file('$!PATH$n\$!filename')
       
      !ZIELDATEI.writerecord(||)
      !ZIELDATEI.writerecord(||)
      !ZIELDATEI.writerecord(|--########### Start (Part 1/2): Commands for ERROR-Report (XLS) ###########|)
      !ZIELDATEI.writerecord(| !filename = 'DBlistingPlus-Error-Log.txt'|)
      !ZIELDATEI.writerecord(| var !pfad evar 'PDMSWK'|)
      !ZIELDATEI.writerecord(| !pfad = !pfad.part(1).trim()|)
      !ZIELDATEI.writerecord(| !PATH = object FILE(!pfad)|)
      !ZIELDATEI.writerecord(| if !PATH.exists().not() then|)
      !ZIELDATEI.writerecord(|  syscom 'mkdir $!PATH'|)
      !ZIELDATEI.writerecord(| endif|)
      !ZIELDATEI.writerecord(| !errorLogFile = object file('$!PATH$n\$!filename')|)
      !ZIELDATEI.writerecord(| alp log end|)
      !ZIELDATEI.writerecord(|  handle any|)
      !ZIELDATEI.writerecord(|  endhandle|)
      !ZIELDATEI.writerecord(| alp log /$!errorLogFile over|)
      !ZIELDATEI.writerecord(| --# "Synonym Translation OFF"|)
      !ZIELDATEI.writerecord(|  | + !string1)
      !ZIELDATEI.writerecord(| ONERROR CONTINUE|)
      !ZIELDATEI.writerecord(|--########### End (Part 1/2): Commands for ERROR-Report (XLS) ###########|)
      !ZIELDATEI.writerecord(||)
      !ZIELDATEI.writerecord(||)
      !ZIELDATEI.writerecord(|---- Data-Listing ("DB-Listing") - "PASS 1" ("Create"-Commands) ----|)
     !ZIELDATEI.close()
      
     alp file /$!ZIELDATEI append
      OUTPUT pass 1 CE
      handle any
      endhandle
     alp file end
    
     !ZIELDATEI.open('APPEND')
      !ZIELDATEI.writerecord(||)
      !ZIELDATEI.writerecord(||)
      !ZIELDATEI.writerecord(|---- Data-Listing ("DB-Listing") - "PASS 2" (References) ----|)
     !ZIELDATEI.close()
     
     alp file /$!ZIELDATEI append
      OUTPUT pass 2 CE
      handle any
      endhandle
     alp file end
    
     !ZIELDATEI.open('APPEND')
      !ZIELDATEI.writerecord(||)
      !ZIELDATEI.writerecord(||) 
      !ZIELDATEI.writerecord(|--########### Start (Part 2/2): Commands for ERROR-Report (XLS) ###########|)
      !ZIELDATEI.writerecord(| ONERROR RETURN|)
      !ZIELDATEI.writerecord(| --# "Synonym Translation ON"|)
      !ZIELDATEI.writerecord(|  | + !string2)
      !ZIELDATEI.writerecord(| alp log end|)
      !ZIELDATEI.writerecord(| !fileLines = !errorLogFile.readFile(999999)|)
      !ZIELDATEI.writerecord(| !errorARRAY = ARRAY()|)
      !ZIELDATEI.writerecord(| !errorARRAY[1] = ARRAY()|)
      !ZIELDATEI.writerecord(| !errorARRAY[2] = ARRAY()|)
      !ZIELDATEI.writerecord(| !errorARRAY[3] = ARRAY()|)
      !ZIELDATEI.writerecord(| !errorARRAY[4] = ARRAY()|)
      !ZIELDATEI.writerecord(| do !i index !fileLines|)
      !ZIELDATEI.writerecord(|  if !fileLines[!i].part(1).matchwild('(*,*)*') then|)
      !ZIELDATEI.writerecord(|    !errorARRAY[3].append(!fileLines[!i])|)
      !ZIELDATEI.writerecord(|    !lineCount = !i + 1|)
      !ZIELDATEI.writerecord(|    !errorARRAY[1].append('Line ' + !fileLines[!lineCount].part(3))|)
      !ZIELDATEI.writerecord(|    !errorARRAY[4].append(!fileLines[!lineCount].part(6))|)
      !ZIELDATEI.writerecord(|    !lineCount = !i + 2|)
      !ZIELDATEI.writerecord(|    !errorARRAY[2].append(!fileLines[!lineCount])|)
      !ZIELDATEI.writerecord(|  elseif !fileLines[!i].trim().eq('') then|)
      !ZIELDATEI.writerecord(|   break|)
      !ZIELDATEI.writerecord(|  endif|)
      !ZIELDATEI.writerecord(| enddo|)
      !ZIELDATEI.writerecord(| if !errorARRAY[1].compress().size().neq(0) then|)
     !ErrorTableXLS = |$!path$n\DBlistingPlusERRORs.xls|
      !ZIELDATEI.writerecord(|  !ErrorTableXLS = '$!path$n\DBlistingPlusERRORs.xls'|)
      !ZIELDATEI.writerecord(|  !Kopfzeile[1] =  'Line-No. (' + !errorARRAY[4][1] + ')'|)
      !ZIELDATEI.writerecord(|  !Kopfzeile[2] =  'Line-Content'|)
      !ZIELDATEI.writerecord(|  !Kopfzeile[3] =  'ERROR'|)
      !ZIELDATEI.writerecord(|  !Table = ARRAY()|)
      !ZIELDATEI.writerecord(|  Do !i index !errorARRAY[1]|)
      !ZIELDATEI.writerecord(|  !Table[!i] = ARRAY()|)
      !ZIELDATEI.writerecord(|   !Table[!i].append(!errorARRAY[1][!i])|)
      !ZIELDATEI.writerecord(|   !Table[!i].append(!errorARRAY[2][!i])|)
      !ZIELDATEI.writerecord(|   !Table[!i].append(!errorARRAY[3][!i])|)
      !ZIELDATEI.writerecord(|  Enddo|)
      !ZIELDATEI.writerecord(|import 'GridControl'|)
      !ZIELDATEI.writerecord(|handle (1000,0)|)
      !ZIELDATEI.writerecord(|endhandle|)
      !ZIELDATEI.writerecord(|using namespace 'Aveva.Pdms.Presentation'|)
      !ZIELDATEI.writerecord(|!grid = object NETGRIDCONTROL()|)
      !ZIELDATEI.writerecord(|!grid.bindToDataSource(object NETDATASOURCE('DB-Listing_PLUS', !Kopfzeile, !Table))|)
      !ZIELDATEI.writerecord(|if !filename.matchwild('*:*') then|)
      !ZIELDATEI.writerecord(|  !grid.saveGridToExcel(!filename)|)
      !ZIELDATEI.writerecord(|else|)
      !ZIELDATEI.writerecord(|  var !dir EVAR PDMSUSER|)
      !ZIELDATEI.writerecord(|  !totalfilename = !dir & '\' & !filename|)
      !ZIELDATEI.writerecord(|  !grid.saveGridToExcel(!totalfilename)|)
      !ZIELDATEI.writerecord(|endif|)
      !ZIELDATEI.writerecord(|  !!alert.message('Please view & handle the error messages, logged in $!ErrorTableXLS')|)
      !ZIELDATEI.writerecord(|  syscom 'start excel $!ErrorTableXLS &'|)
      !ZIELDATEI.writerecord(| endif|)
      !ZIELDATEI.writerecord(|--########### End (Part 2/2):Commands for ERROR-Report (XLS) ###########|)
     !ZIELDATEI.close()
    
     $!ce
    
     if !Mode.upcase().eq(|DEL|) then
      delete $!type
       $p
       $P Element: $!type $!ce deleted!
       $p
     endif
     
     !!alert.message('"DB-Listing Plus" of $!type  $!ce created! See Command-Window!')
     $p
     $P "DB-Listing Plus" saved as:
     $p $!ZIELDATEI
     $p
     $p
     
     syscom 'START $!ZIELDATEI &'
    
    endfunction
    $.

  • #2
    Vielen Dank
    Der
    Webmaster


    Es gibt keine blöden Fragen, nur blöde Antworten

    Kommentar

    Lädt...
    X