/*------------------------------------------------------------------------
    File        : tellError.p
    Purpose     : 

    Syntax      :

    Description : 

    Author(s)   : 
    Created     : Mon Nov 06 11:58:58 FET 2017
    Notes       :
  ----------------------------------------------------------------------*/

/* ***************************  Definitions  ************************** */

define input  parameter piMsgNum            as integer      no-undo.
define output parameter shortDesc           as character    no-undo.
define output parameter longDesc            as longchar     no-undo.

function getMsgDataFileName returns character
    ( input piMsgNum as integer ) forward.
    
define variable cMsgFile       as character no-undo.
define variable cMsgNumber     as character no-undo 
    format "x(6)".
define variable cLine          as character no-undo
    extent 9 format "x(78)".
define variable cCategory      as character no-undo
    format "xx".
define variable cKnowledgeBase as character no-undo
    format "X(78)".
define variable cEol           as character no-undo.

define variable iCount         as integer   no-undo.
define variable iPosition      as integer   no-undo.

cEol = chr(10).

cMsgFile = GetMsgDataFileName(piMsgNum).

if (cMsgFile gt "") eq true then 
do: /* Process Message File */
    input from value(cMsgFile) no-echo.
    assign 
        iPosition = piMsgNum
        iPosition = (piMsgNum modulo 50) 
        when (piMsgNum modulo 50) > 0.
    
    /* Skip messages until the one that we are interested in */
    do iCount = 1 to iPosition on endkey undo, leave:
        import cMsgNumber shortDesc cLine cCategory cKnowledgeBase.
    end.
    input close.  

    if (shortDesc gt "") ne true then return "No message found to match the number".

    if integer(cMsgNumber) eq piMsgNum and 
        shortDesc ne "Reserved for Seq " then 
    do: /* Process Description */
        iCount = 1.
      
        if cLine[1] eq "syserr" then
            longDesc = 
                "An unexpected system error has occurred. Please do the following:"       + cEol +
                "1. If the error occurred while running an existing application or"       + cEol +
                "   during database admin functions, the error may be due to a"           + cEol +
                "   hardware/system problem, r-code corruption, or data corruption."      + cEol +
                "   Note what was processing during the time the error occurred."         + cEol +
                "   Check your system error logs and Progress database log file for"      + cEol +
                "   any additional errors."                                               + cEol +
                "2. If the error occurred while running a new application or procedure,"  + cEol +
                "   try to reproduce and isolate the code that results in the error."     + cEol +
                "3. Search the on-line Progress knowledgebase for information on the"     + cEol +
                "   error.  The kbase can be accessed via the Progress web site at:"      + cEol +
                "   http://www.progress.com   or"                                         + cEol +
                "   http://www.progress.com/services/techsupport/online.html" .     
                
        repeat:
            if iCount le 9 then 
            do:
                if cLine[iCount] > '' then 
                do:
                    if longDesc eq '' then
                        longDesc = cLine[iCount].
                    else
                        longDesc = longDesc + cEol + cLine[iCount].
                end.
                iCount = iCount + 1.
            end.
            else
                leave.
        end. /* repeat */     

    end. /* Process Description */
end. /* Process Message File */


function getMsgDataFileName returns character ( input piMsgNum as integer ):
    define variable iFileNum  as integer   no-undo.
    define variable cDataFile as character no-undo.

    iFileNum = truncate((piMsgNum - 1) / 50, 0) + 1.
    cDataFile = search("prohelp/msgdata/msg" + string(iFileNum)).

    return cDataFile.
end function.