 
/*------------------------------------------------------------------------
   File        : queryHandler
   Purpose     : 
   Syntax      : 
   Description : 
   Author(s)   : walter.riechsteiner
   Created     : Wed Jul 10 18:09:37 CEST 2024
   Notes       : 
 ----------------------------------------------------------------------*/

USING Progress.Json.ObjectModel.JsonObject FROM PROPATH.

USING OpenEdge.Web.IWebRequest             FROM PROPATH.

CLASS utilities.utilitiesHandler: 

PROCEDURE GetUserNameA EXTERNAL "advapi32.dll":
    DEFINE OUTPUT       PARAMETER lpUserName   AS MEMPTR.
    DEFINE INPUT-OUTPUT PARAMETER nChars       AS LONG.
    DEFINE RETURN       PARAMETER bool         AS SHORT.
END PROCEDURE.

    DEFINE VARIABLE i1       AS INTEGER   NO-UNDO.
    DEFINE VARIABLE i2       AS INTEGER   NO-UNDO.
    DEFINE VARIABLE cProgram AS CHARACTER NO-UNDO.
    
    // DEFINE VARIABLE hBuffer  AS HANDLE    NO-UNDO.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC VOID createErrorBox(
        INPUT  oJsonIdent      AS JsonObject,
        INPUT  cErrorNumber    AS CHARACTER ,
        INPUT  cParameter      AS CHARACTER ,
        OUTPUT oJsonMessageBox AS JsonObject
        ):

        DEFINE VARIABLE lcMessage    AS LONGCHAR NO-UNDO.
        DEFINE VARIABLE iLanguage_id AS INTEGER  NO-UNDO.
        DEFINE VARIABLE lcTitle      AS LONGCHAR NO-UNDO.
        
        iLanguage_Id = oJsonIdent:GetInteger('language_id').
        getErrorMessage(
            INPUT  '2012'       ,
            INPUT  ilanguage_id ,
            INPUT  ''           ,
            OUTPUT lcTitle  
            ).
            
        getErrorMessage(
            INPUT  cErrorNumber,
            INPUT  ilanguage_id,
            INPUT  cParameter  ,
            OUTPUT lcMessage
            ).
          
        oJsonMessageBox = NEW JsonObject().
        oJsonMessageBox:ADD('type' , 'info').
        oJsonMessageBox:ADD('title', lcTitle   ).
        oJsonMessageBox:ADD('text' , lcMessage ).
        
        RETURN.


    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC VOID createInfoBox(
        INPUT  oJsonIdent      AS JsonObject,
        INPUT  cErrorNumber    AS CHARACTER ,
        INPUT  cParameter      AS CHARACTER ,
        OUTPUT oJsonMessageBox AS JsonObject
        ):
            
        DEFINE VARIABLE lcMessage    AS LONGCHAR NO-UNDO.
        DEFINE VARIABLE iLanguage_id AS INTEGER  NO-UNDO.
        DEFINE VARIABLE lcTitle      AS LONGCHAR NO-UNDO.
        
        iLanguage_Id = oJsonIdent:GetInteger('language_id').
        getErrorMessage(
            INPUT  '2013'       ,
            INPUT  ilanguage_id ,
            INPUT  ''           ,
            OUTPUT lcTitle  
            ).
        getErrorMessage(
            INPUT  cErrorNumber,
            INPUT  ilanguage_id,
            INPUT  cParameter  ,
            OUTPUT lcMessage
            ).
          
        oJsonMessageBox = NEW JsonObject().
        oJsonMessageBox:ADD('type' , 'info').
        oJsonMessageBox:ADD('title', lcTitle   ).
        oJsonMessageBox:ADD('text' , lcMessage ).
        
        RETURN.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC VOID createLockMessage(
        INPUT  oJsonIdent      AS JsonObject,
        INPUT  rRecid          AS RECID     ,
        OUTPUT oJsonMessageBox AS JsonObject
        ):
            
        DEFINE VARIABLE lFound       AS LOGICAL   NO-UNDO INIT FALSE.
        DEFINE VARIABLE cFileName    AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cLockName    AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cLockUser    AS INTEGER   NO-UNDO.
        DEFINE VARIABLE lcMessage    AS LONGCHAR  NO-UNDO.
        DEFINE VARIABLE iLanguage_id AS INTEGER   NO-UNDO.
        DEFINE VARIABLE lcTitle      AS LONGCHAR  NO-UNDO.

        DO WHILE NOT lFound:            
            FIND FIRST Ge_MIS._Lock NO-LOCK
                WHERE Ge_MIS._Lock._Lock-RecId = INT64(rRecid) NO-ERROR.
            IF NOT AVAILABLE Ge_MIS._Lock THEN LEAVE.
            
            FIND Ge_MIS._File NO-LOCK
                WHERE Ge_MIS._File._File-Number = Ge_MIS._Lock._Lock-Table.
            ASSIGN  
                cFileName = Ge_MIS._File._File-Name
                cLockName = Ge_MIS._Lock._Lock-Name
                cLockUser = Ge_MIS._Lock._Lock-Usr.
            lFound = TRUE.
            LEAVE.
        END.
        
        DO WHILE NOT lFound:            
            FIND FIRST FRAMEWORK._Lock NO-LOCK
                WHERE FRAMEWORK._Lock._Lock-RecId = INT64(rRecid) NO-ERROR.
            IF NOT AVAILABLE FRAMEWORK._Lock THEN LEAVE.
            
            FIND FRAMEWORK._File NO-LOCK
                WHERE FRAMEWORK._File._File-Number = FRAMEWORK._Lock._Lock-Table.
            ASSIGN  
                cFileName = FRAMEWORK._File._File-Name
                cLockName = FRAMEWORK._Lock._Lock-Name
                cLockUser = FRAMEWORK._Lock._Lock-Usr.
            lFound = TRUE.
            LEAVE.
        END.
        iLanguage_id = oJsonIdent:GetInteger('language_id').
        
        getErrorMessage(
            INPUT  '2013'       ,
            INPUT  ilanguage_id ,
            INPUT  ''           ,
            OUTPUT lcTitle  
            ).
        getErrorMessage(
            INPUT  '2006',
            INPUT  ilanguage_id,
            INPUT  SUBSTITUTE('&1;&2;&3', cFileName, cLockName, cLockUser),
            OUTPUT lcMessage
            ).
        
        oJsonMessageBox = NEW JsonObject().
        oJsonMessageBox:ADD('type' , 'info').
        oJsonMessageBox:ADD('title', lcTitle   ).
        oJsonMessageBox:ADD('text' , lcMessage ).
        
        RETURN.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC VOID createQuestionBox(
        INPUT  oJsonIdent      AS JsonObject,
        INPUT  cErrorNumber    AS CHARACTER ,
        INPUT  cParameter      AS CHARACTER ,
        INPUT  cFields         AS CHARACTER ,
        INPUT  cValues         AS CHARACTER ,
        INPUT  hBuffer         AS HANDLE    ,  
        OUTPUT oJsonMessageBox AS JsonObject
        ):
            
        DEFINE VARIABLE lcMessage    AS LONGCHAR   NO-UNDO.
        DEFINE VARIABLE iLanguage_id AS INTEGER    NO-UNDO.
        DEFINE VARIABLE lcTitle      AS LONGCHAR   NO-UNDO.
        DEFINE VARIABLE ii           AS INTEGER    NO-UNDO.
        DEFINE VARIABLE cField       AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cValue       AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE hField       AS HANDLE     NO-UNDO.
        DEFINE VARIABLE cType        AS CHARACTER  NO-UNDO.
        
        DEFINE VARIABLE oJsonUpdate  AS JsonObject.
        
        iLanguage_Id = oJsonIdent:GetInteger('language_id').
        getErrorMessage(
            INPUT  '2011'       ,
            INPUT  ilanguage_id ,
            INPUT  ''           ,
            OUTPUT lcTitle  
            ).
        getErrorMessage(
            INPUT  cErrorNumber,
            INPUT  ilanguage_id,
            INPUT  cParameter  ,
            OUTPUT lcMessage
            ).
          
        oJsonMessageBox = NEW JsonObject().
        oJsonMessageBox:ADD('type' , 'question').
        oJsonMessageBox:ADD('title', lcTitle   ).
        oJsonMessageBox:ADD('text' , lcMessage ).
        
        oJsonUpdate = NEW JsonObject().
        DO ii = 1 TO NUM-ENTRIES(cFields, ';'):
            cField = ENTRY(ii, cFields, ';')   .
            cValue = ENTRY(ii, cValues, CHR(01)).
            hField = hBuffer:BUFFER-FIELD(cField):HANDLE.
            cType  = hField:DATA-TYPE.
            CASE ctype:
                WHEN 'logical'  THEN oJsonUpdate:ADD(cField, LOGICAL(cValue)                    ).
                WHEN 'integer'  THEN oJsonUpdate:ADD(cField, INTEGER(cValue)                    ).
                WHEN 'decimal'  THEN oJsonUpdate:ADD(cField, DECIMAL(cValue)                    ).
                WHEN 'date'     THEN oJsonUpdate:ADD(cField, STRING(DATE(cValue),'99.99.9999')  ).
                OTHERWISE            oJsonUpdate:ADD(cField, cValue                             ).
            END CASE.
        END.

        oJsonMessageBox:ADD('fieldUpdate', oJsonUpdate).
        
        RETURN.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC LONGCHAR createWordindex(
        INPUT hBuffer AS HANDLE
        ):
        
        DEFINE VARIABLE cWordIndex AS LONGCHAR  NO-UNDO.
        
        DEFINE VARIABLE cWords     AS CHARACTER NO-UNDO.
        DEFINE VARIABLE ii         AS INTEGER   NO-UNDO.
        DEFINE VARIABLE cDatatype  AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cWord      AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cField     AS CHARACTER NO-UNDO.
        DEFINE VARIABLE hField     AS HANDLE    NO-UNDO.
        DEFINE VARIABLE iNumerisch AS INT64     NO-UNDO.
        DEFINE VARIABLE cBuffValue AS CHARACTER NO-UNDO.
        DEFINE VARIABLE i1         AS INTEGER   NO-UNDO.
        DEFINE VARIABLE dDate      AS DATE      NO-UNDO.
        DEFINE VARIABLE nValue     AS DECIMAL   NO-UNDO.

        cWords = ''.
        DO ii = 1 TO hBuffer:NUM-FIELDS:
            hField = hBuffer:BUFFER-FIELD(ii):HANDLE.
            IF hField:EXTENT > 0                   THEN NEXT.
            IF INDEX(hField:NAME, 'SHA')      > 0  THEN NEXT.
            IF INDEX(hField:NAME, 'word')     > 0  THEN NEXT.
            IF INDEX(hField:NAME, 'updated_') > 0  THEN NEXT.
            IF INDEX(hField:NAME, 'created_') > 0  THEN NEXT.
            
            cDatatype = hField:DATA-TYPE.
            IF cDatatype = 'logical' THEN NEXT.
            
            cBuffValue = hField:BUFFER-VALUE.
            IF  cBuffValue = ''  OR
                cBuffValue = '0' OR
                cBuffValue = ?   THEN NEXT.

            DO i1 = 1 TO NUM-ENTRIES(cBuffValue, ' '):
                cWord = ENTRY(i1, cBuffValue, ' ').
                
                CASE cDatatype:
                    WHEN 'date' THEN 
                        DO:
                            dDate = DATE(cWord) NO-ERROR.
                            IF ERROR-STATUS:ERROR THEN NEXT.
                            cWord = STRING(dDate,'99.99.9999').
                        END.
                    WHEN 'integer' OR 
                    WHEN 'in64'    OR 
                    WHEN 'decimal' THEN 
                        DO:
                            cWord = SUBSTITUTE('&1&2&1', CHR(01), cWord).
                        END.
                    OTHERWISE 
                    DO:
                        nValue = DECIMAL(cWord) NO-ERROR.
                        IF NOT ERROR-STATUS:ERROR THEN 
                        DO:
                            cWord = TRIM(STRING(nValue,'->>>>>>>>>9.999999')).
                            cWord = REPLACE(cWord, '.000000', '').
                            cWord = SUBSTITUTE('&1&2&1', CHR(01), cWord).
                        END.
                    END.
                END.
                IF LOOKUP(cWord, cWords, ' ') > 0 THEN NEXT.
                
                cWords = cWords + (IF cWords = '' THEN '' ELSE ' ') + cWord.
            END.
        END.
        
        cWords     = TRIM(cWords).
        cWords     = REPLACE(cWords, '  ', ' ').
        cWordIndex = TRIM(cWords).

        RETURN cWordIndex.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC CHARACTER createWordindexFromTable(
        INPUT hBuffer AS HANDLE
        ):
        
        DEFINE VARIABLE cWordIndex AS CHARACTER NO-UNDO.
        
        DEFINE VARIABLE cWords     AS CHARACTER NO-UNDO.
        DEFINE VARIABLE ii         AS INTEGER   NO-UNDO.
        DEFINE VARIABLE cDatatype  AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cWord      AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cField     AS CHARACTER NO-UNDO.
        DEFINE VARIABLE hField     AS HANDLE    NO-UNDO.
        DEFINE VARIABLE iNumerisch AS INT64     NO-UNDO.
        DEFINE VARIABLE cBuffValue AS CHARACTER NO-UNDO.
        DEFINE VARIABLE i1         AS INTEGER   NO-UNDO.
        DEFINE VARIABLE dDate      AS DATE      NO-UNDO.
        DEFINE VARIABLE nValue     AS DECIMAL   NO-UNDO.
        
        DEFINE VARIABLE hQuery     AS HANDLE    NO-UNDO.

        CREATE QUERY hQuery.
        hQuery:SET-BUFFERS(hBuffer).
        hQuery:QUERY-PREPARE ('FOR EACH ttWordIndexTable NO-LOCK ').
        hQuery:QUERY-OPEN ().
        hQuery:GET-FIRST () NO-ERROR.
        cWords = ''.
        DO WHILE NOT hQuery:QUERY-OFF-END:
            cDatatype  = hBuffer::cDataType.
            cBuffValue = hBuffer::cValue.
            cField     = hBuffer::cFieldName.

            DO WHILE TRUE:
                IF  cBuffValue = ''  OR
                    cBuffValue = '0' OR
                    cBuffValue = ?   THEN LEAVE.

                cBuffValue = REPLACE(cBuffValue, '  '   , ' '). 
                cBuffValue = REPLACE(cBuffValue, CHR(10), ' '). 
                cBuffValue = REPLACE(cBuffValue, CHR(13), ' '). 
                DO i1 = 1 TO NUM-ENTRIES(cBuffValue, ' '):
                    cWord = ENTRY(i1, cBuffValue, ' ').
                
                    CASE cDatatype:
                        WHEN 'date' THEN 
                            DO:
                                dDate = DATE(cWord) NO-ERROR.
                                IF ERROR-STATUS:ERROR THEN NEXT.
                                cWord = STRING(dDate,'99.99.9999').
                            END.
                        WHEN 'integer' OR 
                        WHEN 'in64'    OR 
                        WHEN 'decimal' THEN 
                            DO:
                                cWord = SUBSTITUTE('&1&2&1', CHR(01), cWord).
                            END.
                        OTHERWISE 
                        DO:
                            nValue = DECIMAL(cWord) NO-ERROR.
                            IF NOT ERROR-STATUS:ERROR THEN 
                            DO:
                                cWord = TRIM(STRING(nValue,'->>>>>>>>>9.999999')).
                                cWord = REPLACE(cWord, '.000000', '').
                                cWord = SUBSTITUTE('&1&2&1', CHR(01), cWord).
                            END.
                        END.
                    END CASE.

                    IF LOOKUP(cWord, cWords, ' ') > 0 THEN NEXT.
                
                    cWords = cWords + (IF cWords = '' THEN '' ELSE ' ') + cWord.
                END.
                LEAVE.
            END.
            hQuery:GET-NEXT ().
        END.
        
        cWords     = TRIM(cWords).
        cWords     = REPLACE(cWords, '  ', ' ').
        cWordIndex = TRIM(cWords).
        
        DELETE OBJECT hQuery.

        RETURN cWordIndex.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC CHARACTER date2iso(
        INPUT dDate AS DATE
        ):
        
        DEFINE VARIABLE cisoDate AS CHARACTER NO-UNDO.
        
        cisoDate = SUBSTITUTE('&1-&2-&3', STRING(YEAR(dDate),'9999'), STRING(MONTH(dDate),'99'), STRING(DAY(dDate),'99')).

        RETURN cisoDate.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC LOGICAL evaluateErrorStatus(
        INPUT hError AS HANDLE
        ):
        
        DEFINE VARIABLE iNumMessages AS INTEGER   NO-UNDO.
        DEFINE VARIABLE cMessage     AS CHARACTER NO-UNDO.
            
        IF NOT hError:ERROR THEN RETURN FALSE.
        
        cMessage = 'ERROR: '.
        DO iNumMessages = 1 TO hError:NUM-MESSAGES :
            cMessage = cMessage + hError:GET-MESSAGE(iNumMessages) + CHR(10) + '       '.
        END.
        MESSAGE cMessage.
        
        RETURN TRUE.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC VOID evaluateFile(
        INPUT-OUTPUT oJsonIdent      AS JsonObject,
        OUTPUT       cFileName       AS CHARACTER,
        OUTPUT       lCompany        AS LOGICAL  ,
        OUTPUT       lActive         AS LOGICAL  ,
        OUTPUT       lWordindex      AS LOGICAL  ,
        INPUT-OUTPUT httKeyFields    AS HANDLE   , 
        INPUT-OUTPUT httPrimaryIndex AS HANDLE 
        ):
            
        DEFINE VARIABLE cDBFileName      AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cDBName          AS CHARACTER NO-UNDO.
        DEFINE VARIABLE hBuffer          AS HANDLE    NO-UNDO.
        DEFINE VARIABLE hField           AS HANDLE    NO-UNDO.
        DEFINE VARIABLE hDictFile        AS HANDLE    NO-UNDO.
        DEFINE VARIABLE hDictField       AS HANDLE    NO-UNDO.
        DEFINE VARIABLE rRecid           AS RECID     NO-UNDO.
        DEFINE VARIABLE cWhere           AS CHARACTER NO-UNDO.
        DEFINE VARIABLE lOK              AS LOGICAL   NO-UNDO.
        
        DEFINE VARIABLE ccompany         AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cuser_name       AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cActiveSelection AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cFormId          AS CHARACTER NO-UNDO.
        
        DEFINE VARIABLE rPrimeIndex      AS RECID     NO-UNDO.
        DEFINE VARIABLE rField           AS RECID     NO-UNDO.
        DEFINE VARIABLE hQuery           AS HANDLE    NO-UNDO.
        DEFINE VARIABLE cKeyField        AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cField           AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cFieldName       AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cValue           AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cFieldNames      AS CHARACTER NO-UNDO EXTENT.
        DEFINE VARIABLE cKeyFieldReplace AS CHARACTER NO-UNDO.

        ccompany   = oJsonIdent:GetCharacter('company'  ) NO-ERROR.            
        cuser_name = oJsonIdent:GetCharacter('user_name') NO-ERROR.            
        cprogram   = oJsonIdent:GetCharacter('program'  ) NO-ERROR.
        cFormId    = oJsonIdent:GetCharacter('formId'   ) NO-ERROR.
        IF oJsonIdent:HAS('file_name') THEN cFileName = oJsonIdent:GetCharacter('file_name').
        ELSE 
        DO:
            cFileName = ENTRY(1, cFormId, '_').
            oJsonIdent:ADD('file_name', cFileName).
        END.

        ASSIGN 
            lCompany   = FALSE
            lActive    = FALSE
            lWordIndex = FALSE.
            
        DO WHILE TRUE:
            cDBName = 'Ge_MIS'.
            cDBFileName = SUBSTITUTE('&1.&2', cDBName, cFileName).
            CREATE BUFFER hBuffer FOR TABLE cDBFileName NO-ERROR.
            IF VALID-HANDLE(hBuffer) THEN LEAVE.
            
            cDBName = 'FRAMEWORK'.
            DELETE OBJECT hBuffer NO-ERROR.
            cDBFileName = SUBSTITUTE('&1.&2', cDBName, cFileName).
            CREATE BUFFER hBuffer FOR TABLE cDBFileName NO-ERROR.
            IF VALID-HANDLE(hBuffer) THEN LEAVE.
            
            RETURN.
        END.
        
        oJsonIdent:ADD('DBName', cDBName).
        
        hField = hBuffer:BUFFER-FIELD('active') NO-ERROR.
        IF  NOT ERROR-STATUS:ERROR AND
            VALID-HANDLE(hField) THEN lActive = TRUE.
        DELETE OBJECT hField NO-ERROR.
                
        hField = hBuffer:BUFFER-FIELD('wordindex') NO-ERROR.
        IF  NOT ERROR-STATUS:ERROR AND
            VALID-HANDLE(hField) THEN lWordIndex = TRUE.
        DELETE OBJECT hField NO-ERROR.
                
        hField = hBuffer:BUFFER-FIELD('company') NO-ERROR.
        IF  NOT ERROR-STATUS:ERROR AND
            VALID-HANDLE(hField) THEN lCompany = TRUE.
        //
        //  Dictionary _File Buffer ermitteln 
        //        
        cDBFileName = SUBSTITUTE('&1._File', cDBName).
        CREATE BUFFER hDictFile FOR TABLE cDBFileName NO-ERROR.

        cWhere = SUBSTITUTE('WHERE _File-Name = &1 ', QUOTER(cFileName)).
        lOK = hDictFile:FIND-FIRST (cWhere) NO-ERROR.
        rRecid      = hDictFile:RECID.
        rPrimeIndex = hDictFile::_Prime-Index.

        DO WHILE lCompany:
            //
            //  ermitteln RECID von Field company
            //
            cDBFileName = SUBSTITUTE('&1._Field', cDBName).
            CREATE BUFFER hDictField FOR TABLE cDBFileName NO-ERROR.
            cWhere = SUBSTITUTE('WHERE _File-Recid = &1 AND _Field-Name = "company" ', rRecid) .
            lOK = hDictField:FIND-FIRST(cWhere, NO-LOCK) NO-ERROR.
            rField = hDictField:RECID.
            DELETE OBJECT hDictField NO-ERROR.
            //
            //  is Field company ein Index-Feld ? -> Wenn nicht, Flag lCompany auf FALSE setzen
            //
            cDBFileName = SUBSTITUTE('&1._Index-Field', cDBName).
            CREATE BUFFER hDictField FOR TABLE cDBFileName NO-ERROR.
            cWhere = SUBSTITUTE('WHERE _Field-Recid = &1 ', rField) .
            lOK = hDictField:FIND-FIRST(cWhere) NO-ERROR.
            IF NOT lOK THEN lCompany = FALSE.
            
            DELETE OBJECT hDictField.
            
            LEAVE.
        END.
        
        IF lCompany THEN 
        DO:
            httKeyFields:BUFFER-CREATE ().
            ASSIGN
                httKeyFields::iIndex     = 1
                httKeyFields::cLongName  = SUBSTITUTE('&1_&2_&3', 'keyField', cFileName, 'company')
                httKeyFields::cFieldName = 'company'
                httKeyFields::cFileName  = cFileName
                httKeyFields::cValue     = ccompany
                httKeyFields::cDataType  = 'character'
                httKeyFields::lKeyfield  = TRUE.
        END.
        IF lActive THEN 
        DO:
            getActiveSelection(
                INPUT  oJsonIdent,
                INPUT  cFileName ,
                OUTPUT cActiveSelection
                ) NO-ERROR.

            CASE cActiveSelection:
                WHEN 'activeOnly' THEN 
                    cActiveSelection = 'true'.
                WHEN 'inactiveOnly' THEN 
                    cActiveSelection = 'false'.
                OTHERWISE 
                cActiveSelection = ''.
            END CASE.
            
            httKeyFields:BUFFER-CREATE ().
            ASSIGN
                httKeyFields::iIndex     = 99
                httKeyFields::cLongName  = SUBSTITUTE('&1_&2_&3', 'keyField', cFileName, 'active')
                httKeyFields::cFieldName = 'active'
                httKeyFields::cFileName  = cFileName
                httKeyFields::cValue     = cActiveSelection
                httKeyFields::cDataType  = 'logical'
                httKeyFields::lKeyfield  = TRUE.
        END.
        //
        //  restlichen Keyfelder in Tabelle schreiben
        //
        CREATE BUFFER hField FOR TABLE SUBSTITUTE('&1._Field', cDBName).
        cFieldNames      = oJsonIdent:getNames().
        cKeyFieldReplace = SUBSTITUTE ('keyField_&1_', cFileName).
        DO i1 = 1 TO EXTENT(cFieldNames):
            IF NOT cFieldNames[i1] BEGINS 'keyfield'          THEN NEXT.
            
            cFieldName = cFieldNames[i1].
            IF NOT ENTRY(2, cFieldName, '_') = cFileName THEN ENTRY(2, cFieldName, '_') = cFileName.
            
            cKeyField = cFieldNames[i1].
            cField    = REPLACE(cFieldName, cKeyFieldReplace, '').

            cWhere = SUBSTITUTE('WHERE cFieldName = &1 ', QUOTER(cField) ).
            lOK = httKeyFields:FIND-FIRST(cWhere, NO-LOCK) NO-ERROR.
            IF lOK THEN 
            DO:
                cValue = oJsonIdent:GetCharacter(cKeyField) NO-ERROR.
                httKeyFields::cvalue = cValue.
                NEXT.
            END.

            cValue    = oJsonIdent:GetCharacter(cKeyField) NO-ERROR.
            cWhere    = SUBSTITUTE('WHERE &1._File-recid = &2 AND &1._Field-Name = &3', '_Field', rRecid, QUOTER(cField)).
            hField:FIND-FIRST(cWhere, NO-LOCK).
            httKeyFields:BUFFER-CREATE().
            ASSIGN 
                httKeyFields::iIndex     = i1 + 1
                httKeyFields::cLongName  = cKeyField
                httKeyFields::cFieldName = cField
                httKeyFields::cFileName  = cFileName
                httKeyFields::cValue     = cValue
                httKeyFields::cDataType  = hField::_Data-Type
                httKeyFields::lKeyfield  = TRUE. 
        END.
        //
        //  Filterfelder
        //
        cKeyFieldReplace = SUBSTITUTE ('filter_&1_', cFileName).
        DO i1 = 1 TO EXTENT(cFieldNames):
            IF NOT cFieldNames[i1] BEGINS 'filter_' THEN NEXT.
            cKeyField = cFieldNames[i1].
            cField    = REPLACE(cKeyField, cKeyFieldReplace, '').
            
            cWhere = SUBSTITUTE('WHERE cFieldName = &1 ', QUOTER(cField) ).
            lOK = httKeyFields:FIND-FIRST(cWhere, NO-LOCK) NO-ERROR.
            IF lOK THEN NEXT.
            
            cValue    = oJsonIdent:GetCharacter(cKeyField).
            cWhere    = SUBSTITUTE('WHERE &1._File-recid = &2 AND &1._Field-Name = &3', '_Field', rRecid, QUOTER(cField)).
            hField:FIND-FIRST(cWhere, NO-LOCK).
            httKeyFields:BUFFER-CREATE().
            ASSIGN 
                httKeyFields::iIndex     = i1 + 20
                httKeyFields::cLongName  = cKeyField
                httKeyFields::cFieldName = cField
                httKeyFields::cFileName  = cFileName
                httKeyFields::cValue     = cValue
                httKeyFields::cDataType  = hField::_Data-Type
                httKeyFields::lKeyfield  = FALSE.
        END.
        //
        //  Primary Index Felder ermitteln
        //
        cDBFileName = SUBSTITUTE('&1._Index-Field', cDBName).
        CREATE BUFFER hDictField FOR TABLE cDBFileName NO-ERROR.
        CREATE QUERY hQuery.
        hQuery:SET-BUFFERS(hDictField).
        cWhere = SUBSTITUTE('FOR EACH _Index-Field WHERE _Index-Recid = &1 BY _Index-Field._Index-Seq ', rPrimeIndex) .
        hQuery:QUERY-PREPARE (cWhere).
        hQuery:QUERY-OPEN ().
        hQuery:GET-FIRST () NO-ERROR.
        
        cDBFileName = SUBSTITUTE('&1._Field', cDBName).
        CREATE BUFFER hField FOR TABLE cDBFileName.
         
        DO WHILE NOT hQuery:QUERY-OFF-END:
            rRecid = hDictField::_Field-Recid.
            cWhere = SUBSTITUTE('WHERE RECID(&1) = &2 ', hField:NAME, rRecid).
            hField:FIND-UNIQUE (cWhere, NO-LOCK).
            httPrimaryIndex:BUFFER-CREATE().
            ASSIGN 
                httPrimaryIndex::iIndex     = hDictField::_Index-Seq
                httPrimaryIndex::cFileName  = cFileName
                httPrimaryIndex::cFieldName = hField::_Field-Name
                httPrimaryIndex::cDataType  = hField::_DATA-TYPE  
                .
            hQuery:GET-NEXT().
        END. 
        hQuery:QUERY-CLOSE ().
        
        DELETE OBJECT hBuffer    NO-ERROR.
        DELETE OBJECT hField     NO-ERROR.           
        DELETE OBJECT hDictField NO-ERROR.
        DELETE OBJECT hDictFile  NO-ERROR.
        
        httKeyFields   :WRITE-JSON('File', 'C:\TEMP\ttKeyFields.json'   , TRUE).
        httPrimaryIndex:WRITE-JSON('File', 'C:\TEMP\ttPrimaryIndex.json', TRUE).
        
        RETURN.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC LOGICAL evaluatePageNumber(
        INPUT-OUTPUT oJsonIdent AS JsonObject,
        INPUT        cWhere     AS CHARACTER,
        INPUT        rRecid     AS RECID    ,
        INPUT        cStatus    AS CHARACTER 
        ):
        
        DEFINE VARIABLE lRetVal       AS LOGICAL   NO-UNDO INIT FALSE.
        DEFINE VARIABLE hQuery        AS HANDLE    NO-UNDO.
        DEFINE VARIABLE hBuffer       AS HANDLE    NO-UNDO.
        
        DEFINE VARIABLE iMaxRecords   AS INTEGER   NO-UNDO.
        DEFINE VARIABLE cFileName     AS CHARACTER NO-UNDO.
        DEFINE VARIABLE iCurrentPos   AS INTEGER   NO-UNDO.
        DEFINE VARIABLE iPage         AS INTEGER   NO-UNDO.
        DEFINE VARIABLE iIndex        AS INTEGER   NO-UNDO.
        DEFINE VARIABLE iTotalRecords AS INTEGER   NO-UNDO.
        DEFINE VARIABLE rBefore       AS RECID     NO-UNDO.

        cFileName      = oJsonIdent:GetCharacter('file_name'). 
        iPage          = 1.       
        iMaxRecords    = 25.
        iCurrentPos    = 0.
        IF oJsonIdent:HAS('limit') THEN 
        DO:
            iMaxRecords = (IF  oJsonIdent:getType('limit') = 1
                THEN INTEGER(oJsonIdent:GetCharacter('limit'))
                ELSE oJsonIdent:GetInteger('limit')) NO-ERROR.
        END.
        cWhere = SUBSTITUTE(' PRESELECT EACH &1 &2 NO-LOCK ', cFileName, cWhere).
//MESSAGE 'cWhere =' cWhere 'Filename =' cFileName.
        CREATE QUERY hQuery.
        CREATE BUFFER hBuffer FOR TABLE cFileName.
        hQuery:SET-BUFFERS (hBuffer).
        hQuery:QUERY-PREPARE (cWhere).
        hQuery:QUERY-OPEN ().
        iTotalRecords = hQuery:NUM-RESULTS.
        
        hQuery:GET-FIRST (NO-LOCK) NO-ERROR.
        DO WHILE NOT hQuery:QUERY-OFF-END:
            iCurrentPos = iCurrentPos + 1.
            IF hBuffer:RECID = rRecid THEN LEAVE.
            rBefore     = hBuffer:RECID.
            hQuery:GET-NEXT (NO-LOCK) NO-ERROR.
        END.
        hQuery:QUERY-CLOSE ().
        
        DELETE OBJECT hBuffer.
        DELETE OBJECT hQuery.
        
        IF cStatus = 'before' THEN iCurrentPos = iCurrentPos - 1.
        IF cStatus = 'after'  THEN iCurrentPos = iCurrentPos + 1.
        
        iIndex = (iCurrentPos MOD iMaxRecords).
        IF iIndex = 0 THEN 
        DO:
            iPage  = iCurrentPos / iMaxRecords.
            iIndex = iMaxRecords - 1.   //  Java ist Index 0 der erste Satz
        END.
        ELSE 
        DO:
            iPage  = ((iCurrentPos - iIndex) / iMaxRecords) + 1.
            iIndex = iIndex - 1.
        END. 
        IF (iPage * iMaxRecords) > iTotalRecords THEN iMaxRecords = iMaxRecords - ((iPage * iMaxRecords) - iTotalRecords).
        IF oJsonIdent:HAS('recordCount')
            THEN oJsonIdent:SET('recordCount', iMaxRecords).
        ELSE oJsonIdent:ADD('recordCount', iMaxRecords).

        IF oJsonIdent:HAS('page')
            THEN oJsonIdent:SET('page', iPage).
        ELSE     oJsonIdent:ADD('page', iPage).
        IF oJsonIdent:HAS('index')
            THEN oJsonIdent:SET('index', iIndex).
        ELSE     oJsonIdent:ADD('index', iIndex).
        IF oJsonIdent:HAS('totalRecords')
            THEN oJsonIdent:SET('totalRecords', iTotalRecords).
        ELSE     oJsonIdent:ADD('totalRecords', iTotalRecords).
// MESSAGE 'page =' iPage 'index =' iIndex 'totalRecords =' iTotalRecords 'Max Records =' iMaxRecords 'Current Pos =' iCurrentPos.
// oJsonIdent:WriteFile('C:\TEMP\evaluatePageNumber_jsonIdent.json', TRUE).
        lRetVal = TRUE.
        RETURN lRetVal.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC VOID generateHash(
        INPUT ipAlgorithm  AS CHARACTER,
        INPUT ipPhrase     AS CHARACTER,
        INPUT ipKey        AS CHARACTER,   
        OUTPUT opERROR     AS LOGICAL,
        OUTPUT opMESSAGE   AS CHARACTER,
        OUTPUT opHash      AS CHARACTER
        ):
        
        ASSIGN  
            opERROR   = FALSE 
            opMessage = ''
            opHash    = ''.
            
        IF ipPhrase = '' OR ipPhrase = ? THEN 
        DO:
            ASSIGN 
                opERROR   = TRUE
                opMESSAGE = 'Input Error. Value not correct'.
            RETURN.
        END.
    
        opHash = HEX-ENCODE (MESSAGE-DIGEST (ipAlgorithm, ipPhrase, ipKey)).
        
        RETURN.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC VOID getActiveSelection(
        INPUT  oJsonIdent       AS JsonObject,
        INPUT  cFileName        AS CHARACTER ,
        OUTPUT cActiveSelection AS CHARACTER 
        ):
            
        DEFINE VARIABLE ccompany   AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cuser_name AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cProgram   AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cUsers     AS CHARACTER NO-UNDO.
        
        ASSIGN 
            ccompany   = oJsonIdent:GetCharacter('company')
            cuser_name = oJsonIdent:GetCharacter('user_name')
            cProgram   = oJsonIdent:GetCharacter('program').
            
        FIND userdata NO-LOCK
            WHERE userdata.user_name   = cuser_name
            AND   userdata.company     = ccompany
            AND   userdata.branch      = '0000'
            AND   userdata.record_type = 'active'
            AND   userdata.section     = cFileName 
            AND   userdata.key_type    = cProgram NO-ERROR.
              
        IF AVAILABLE userdata THEN cActiveSelection = userdata.cfield_1.
        ELSE                       cActiveSelection = ''.   

        RELEASE userdata.

        RETURN.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC CHARACTER getBoxFieldText(
        INPUT oJsonIdent  AS JsonObject,
        INPUT cField      AS CHARACTER ,
        INPUT cFieldValue AS CHARACTER 
        ):
        
        DEFINE VARIABLE cText AS CHARACTER NO-UNDO.
        
        FIND selections NO-LOCK 
            WHERE selections.company     = oJsonIdent:GetCharacter('company')
            AND   selections.table_name  = 'table'
            AND   selections.user_name   = oJsonIdent:GetCharacter('user_name')
            AND   selections.language_id = oJsonIdent:GetInteger('language_id')
            AND   selections.field_name  = cField
            AND   selections.field_value = cFieldValue NO-ERROR.
        cText = (IF AVAILABLE selections THEN selections.field_show ELSE '').
        RETURN cText.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC CHARACTER getBufferFieldValue( INPUT iphfield_name AS HANDLE, OUTPUT oplQuoter AS LOGICAL ):
        
        DEFINE VARIABLE cfield_nameInhalt AS CHARACTER NO-UNDO.

        cfield_nameInhalt = ''.
        oplQuoter   = FALSE.
        CASE iphfield_name:DATA-TYPE:
            WHEN 'CHARACTER' THEN
                ASSIGN  
                    cfield_nameInhalt = iphfield_name:BUFFER-VALUE(0)
                    oplQuoter         = TRUE.
            WHEN 'DECIMAL' OR
            WHEN 'INTEGER' THEN 
                cfield_nameInhalt = TRIM(STRING(INTEGER(iphfield_name:BUFFER-VALUE),'>>>>>>>>9')).
            WHEN 'DATE' THEN 
                cfield_nameInhalt = STRING(DATE(iphfield_name:BUFFER-VALUE),'99.99.9999').
            OTHERWISE  
            cfield_nameInhalt = iphfield_name:BUFFER-VALUE.
        END CASE.
        
        IF cfield_nameInhalt = ? THEN cfield_nameInhalt = ''. 
        
        RETURN cfield_nameInhalt.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC CHARACTER getCharDateTime(
        INPUT ipdDateTime AS DATETIME
        ):
        
        DEFINE VARIABLE cReturnValue AS CHARACTER NO-UNDO.
        DEFINE VARIABLE dDateTime    AS DATETIME  NO-UNDO.
        DEFINE VARIABLE cDateTime    AS CHARACTER NO-UNDO.

        dDateTime    = ipdDateTime. 
        cDateTime    = STRING(dDateTime,'99-99-9999THH:MM:SS').
        cReturnValue =
            STRING(YEAR(dDateTime),'9999')
            + '-'
            + STRING(MONTH(dDateTime),'99')
            + '-'
            + STRING(DAY(dDateTime),'99')
            + SUBSTRING(cDateTime,11).
            
        RETURN cReturnValue.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC HANDLE getData(
        INPUT ipoJsonIdent   AS JsonObject,
        INPUT ipcFileName    AS CHARACTER,
        INPUT ipcWherePaires AS CHARACTER 
        ):
            
        DEFINE VARIABLE cWhere      AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cWherePaire AS CHARACTER NO-UNDO.
        DEFINE VARIABLE lCompany    AS LOGICAL   NO-UNDO.
        DEFINE VARIABLE lActive     AS LOGICAL   NO-UNDO.
        DEFINE VARIABLE lWhere      AS LOGICAL   NO-UNDO INIT TRUE.
        
        DEFINE VARIABLE hBuffer     AS HANDLE    NO-UNDO.
        DEFINE VARIABLE ttTable     AS HANDLE    NO-UNDO.
        DEFINE VARIABLE httBuffer   AS HANDLE    NO-UNDO.
        DEFINE VARIABLE hQuery      AS HANDLE    NO-UNDO.
        DEFINE VARIABLE lOK         AS LOGICAL   NO-UNDO.
        
        lOK = FALSE.
        DO WHILE TRUE:
            FIND FIRST Ge_MIS._File NO-LOCK 
                WHERE Ge_MIS._File._File-Name = ipcFileName NO-ERROR.
            IF NOT AVAILABLE Ge_MIS._File THEN LEAVE.
            
            FIND FIRST Ge_MIS._Field OF Ge_MIS._File WHERE Ge_MIS._Field._Field-Name = 'company' NO-ERROR.
            lCompany = (IF AVAILABLE _Field THEN TRUE ELSE FALSE).
            FIND FIRST Ge_MIS._Field OF Ge_MIS._File WHERE Ge_MIS._Field._Field-Name = 'active' NO-ERROR.
            lActive  = (IF AVAILABLE _Field THEN TRUE ELSE FALSE).
            
            lOK = TRUE.
            LEAVE.
        END.
        
        DO WHILE NOT lOK:
            FIND FIRST FRAMEWORK._File NO-LOCK 
                WHERE FRAMEWORK._File._File-Name = ipcFileName NO-ERROR.
            IF NOT AVAILABLE FRAMEWORK._File THEN LEAVE.
            
            FIND FIRST FRAMEWORK._Field OF FRAMEWORK._File WHERE FRAMEWORK._Field._Field-Name = 'company' NO-ERROR.
            lCompany = (IF AVAILABLE _Field THEN TRUE ELSE FALSE).
            FIND FIRST FRAMEWORK._Field OF FRAMEWORK._File WHERE FRAMEWORK._Field._Field-Name = 'active' NO-ERROR.
            lActive  = (IF AVAILABLE _Field THEN TRUE ELSE FALSE).
            
            lOK = TRUE.
            LEAVE.
        END.
        
        CREATE BUFFER hBuffer FOR TABLE ipcFileName.
        CREATE TEMP-TABLE ttTable.
        ttTable:CREATE-LIKE (hBuffer).
        ttTable:TEMP-TABLE-PREPARE ('ttTable').
        httBuffer = ttTable:DEFAULT-BUFFER-HANDLE.
        
        DO i1 = 1 TO httBuffer:NUM-FIELDS:
            httBuffer:BUFFER-FIELD(i1):SERIALIZE-NAME = SUBSTITUTE('&1_&2', ipcFileName, hBuffer:BUFFER-FIELD(i1):NAME). 
        END.
        
        cWhere = SUBSTITUTE('FOR EACH &1 NO-LOCK ', ipcFileName).
        IF lCompany THEN 
        DO:
            cWhere = cWhere + (IF lWhere THEN 'WHERE ' ELSE 'AND ' ).
            cWhere = cWhere + SUBSTITUTE('&1.company = &2 ', ipcFileName, QUOTER(ipoJsonIdent:GetCharacter('company'))).
            lWhere = FALSE.
        END.
        DO i1 = 1 TO NUM-ENTRIES(ipcWherePaires, ';'):
            cWherePaire = ENTRY(i1, ipcWherePaires, ';').
            cWhere = cWhere + (IF lWhere THEN 'WHERE ' ELSE 'AND ' ) + cWherePaire + ' '.
            lWhere = FALSE.
        END.
        IF lActive THEN 
        DO:
            cWhere = cWhere + (IF lWhere THEN 'WHERE ' ELSE 'AND ' ).
            cWhere = cWhere + SUBSTITUTE('&1.active = &2 ', ipcFileName, 'TRUE').
            lWhere = FALSE.
        END.
        MESSAGE 'cWhere = ' cWhere.
        CREATE QUERY hQuery.
        hQuery:SET-BUFFERS(hBuffer).
        hQuery:QUERY-PREPARE (cWhere).
        hQuery:QUERY-OPEN ().
        hQuery:GET-FIRST ().
        DO WHILE NOT hQuery:QUERY-OFF-END:
            httBuffer:BUFFER-CREATE ().
            httBuffer:BUFFER-COPY(hBuffer).
            hQuery:GET-NEXT ().
        END.
        hQuery:QUERY-CLOSE ().
        
        DELETE OBJECT hQuery  NO-ERROR.
        DELETE OBJECT hBuffer NO-ERROR.

        RETURN httBuffer.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC VOID getErrorMessage(
        INPUT  cFehlerNo    AS CHARACTER,
        INPUT  ilanguage_id AS INTEGER,
        INPUT  cParam       AS CHARACTER,  
        OUTPUT cMessage     AS LONGCHAR 
        ):
             
        DEFINE VARIABLE lcJsonString AS CHARACTER NO-UNDO.
        DEFINE VARIABLE ii           AS INTEGER   NO-UNDO.
        DEFINE VARIABLE iNo          AS INTEGER   NO-UNDO.
        DEFINE VARIABLE cString      AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cParameter   AS CHARACTER NO-UNDO EXTENT 5.
        
        cParam = REPLACE(cParam, ',', ';').
        DO ii = 1 TO NUM-ENTRIES(cParam, ';'):
            cParameter[ii] = ENTRY(ii, cParam, ';').
            IF ii = 5 THEN LEAVE.
        END.
        lcJsonString = '(&1) ->  &2'.
        cFehlerNo = REPLACE(cFehlerNo, ',', ';').
        DO ii = 1 TO NUM-ENTRIES(cFehlerNo, ';'):
            iNo = INTEGER(ENTRY(ii, cFehlerNo, ';')).
            FIND messages NO-LOCK 
                WHERE messages.message_no  = iNo
                AND   messages.language_id = ilanguage_id NO-ERROR.
            IF NOT AVAILABLE messages THEN 
            DO:
                FIND FIRST messages NO-LOCK 
                    WHERE messages.message_no  = iNo NO-ERROR.
            END.
        
            IF NOT AVAILABLE messages THEN 
            DO:
                cString = cString
                    + (IF cString = '' THEN '' ELSE ' ')
                    + 'Systemfehler, Administrator benachrichtigen !'.
            END.
            ELSE 
            DO:
                cString = cString
                    + (IF cString = '' THEN '' ELSE ' ')
                    + messages.message_text.
            END.
        END.
        cString = SUBSTITUTE(cString, cParameter[01], cParameter[02], cParameter[03], cParameter[04], cParameter[05]).
        
        cMessage = cString.              
        
        RETURN.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC CHARACTER getHeader(
        INPUT httInput  AS HANDLE
        ):
        
        DEFINE VARIABLE cHeader AS CHARACTER NO-UNDO.

        FIND FIRST labeltexte NO-LOCK 
            WHERE labeltexte.company     = httInput::company
            AND   labeltexte.user_name   = httInput::user_name
            AND   labeltexte.program     = httInput::program
            AND   labeltexte.field_name  = 'KOPF'
            AND   labeltexte.language_id = INTEGER(httInput::language_id) NO-ERROR.
        IF NOT AVAILABLE labeltexte THEN 
        DO: 
            FIND FIRST labeltexte NO-LOCK 
                WHERE labeltexte.company     = httInput::company
                AND   labeltexte.program     = httInput::program
                AND   labeltexte.field_name  = 'KOPF'
                AND   labeltexte.language_id = INTEGER(httInput::language_id) NO-ERROR.
        END.
        
        cHeader = (IF AVAILABLE labeltexte THEN labeltexte.sidelabel ELSE httInput::program).
        
        RETURN cHeader.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC LOGICAL getHeaderData(
        INPUT  poRequest     AS IWebRequest ,
        OUTPUT ccompany      AS CHARACTER   ,
        OUTPUT cuser_name    AS CHARACTER   ,
        OUTPUT cAnzeigeName  AS CHARACTER   ,
        OUTPUT iLanguage_id  AS INTEGER     ,
        OUTPUT cSessionToken AS CHARACTER   ,
        OUTPUT cFunction     AS CHARACTER   , 
        OUTPUT oJsonIdent    AS JsonObject
        ):
        
        DEFINE VARIABLE oHeader      AS OpenEdge.Net.HTTP.HttpHeader NO-UNDO.
        
        DEFINE VARIABLE lRetVal      AS LOGICAL                      NO-UNDO.
        DEFINE VARIABLE ii           AS INTEGER                      NO-UNDO.
        DEFINE VARIABLE cQueryPairs  AS CHARACTER                    NO-UNDO.
        DEFINE VARIABLE cQueryKey    AS CHARACTER                    NO-UNDO.
        DEFINE VARIABLE cQueryValue  AS CHARACTER                    NO-UNDO.
        DEFINE VARIABLE cQueryString AS CHARACTER                    NO-UNDO.
        
        DEFINE VARIABLE cFormId      AS CHARACTER                    NO-UNDO.
        DEFINE VARIABLE cClassName   AS CHARACTER                    NO-UNDO.
        DEFINE VARIABLE cFilename    AS CHARACTER                    NO-UNDO.

        oHeader      = poRequest:GetHeader('X-COMPANY').
        ccompany     = oHeader:VALUE.
        
        oHeader      = poRequest:GetHeader('X-USER-NAME').
        cuser_name    = oHeader:VALUE.
        
        oHeader      = poRequest:GetHeader('X-DISPLAY-NAME').
        cAnzeigeName = oHeader:VALUE.
        
        oHeader = poRequest:GetHeader('X-LANGUAGE-ID').
        ilanguage_id  = INTEGER(oHeader:VALUE).
        
        oHeader = poRequest:GetHeader('X-SESSION-TOKEN').
        cSessionToken = oHeader:VALUE.
        
        cQueryString = STRING(poRequest:GetContextValue("QUERY_STRING")) NO-ERROR.
        cQueryString = OpenEdge.Net.URI:Decode(cQueryString).
// MESSAGE 'cQueryYString =' cQueryString.
        oJsonIdent = NEW JsonObject().
        oJsonIdent:ADD('H_company'     , ccompany     )   NO-ERROR.
        oJsonIdent:ADD('H_user_name'   , cuser_name   )   NO-ERROR.
        oJsonIdent:ADD('H_language_id' , iLanguage_id )   NO-ERROR.
        oJsonIdent:ADD('H_display_name', cAnzeigeName )   NO-ERROR.
        oJsonIdent:ADD('sessionToken'  , cSessionToken)   NO-ERROR.
        //
        //  Alle Parameter aus dem Query-String lesen und im Object oJsonIdent ergänzenz
        //
        DO ii = 1 TO NUM-ENTRIES(cQueryString, '&'):
            cQueryPairs = ENTRY(ii, cQueryString, '&').
            cQueryKey   = ENTRY(1 , cQueryPairs , '=').
            cQueryValue = ENTRY(2 , cQueryPairs , '=').
            IF oJsonIdent:HAS(cQueryKey) THEN oJsonIdent:SET(cQueryKey, cQueryValue) NO-ERROR.
            ELSE                              oJsonIdent:ADD(cQueryKey, cQueryValue) NO-ERROR.
        END.
        
        IF NOT oJsonIdent:HAS('company'    ) THEN oJsonIdent:ADD('company'    , oJsonIdent:GetCharacter('H_company'    )).
        IF NOT oJsonIdent:HAS('user_name'  ) THEN oJsonIdent:ADD('user_name'  , oJsonIdent:GetCharacter('H_user_name'  )).
        IF NOT oJsonIdent:HAS('language_id') THEN oJsonIdent:ADD('language_id', oJsonIdent:GetJsonText ('H_language_id')).
        
        //  language_id soll immer ein Interger-Wert sein
        oJsonIdent:SET('language_id', INTEGER(oJsonIdent:GetJsonText('language_id'))).
        
        IF oJsonIdent:HAS('formId') THEN 
        DO:
            cFormId   = oJsonIdent:GetCharacter('formId').
            cFileName = ENTRY(1, cFormId, '_'). 
            IF NOT oJsonIdent:HAS('file_name') THEN oJsonIdent:ADD('file_name', cFileName).
        
// cFileName = SUBSTITUTE ('C:\TEMP\oJsonIdent_getHeaderData_&1.log', cFormId).
// oJsonIdent:WriteFile(cFileName, TRUE).
            FIND FIRST programs NO-LOCK 
                WHERE programs.FormId = cFormId NO-ERROR.
            IF AVAILABLE programs THEN 
            DO:
                oJsonIdent:ADD('class_name', programs.program_class).
                cProgram = programs.program.
// MESSAGE 'programm gefunden mit FormId' cFormId.
            END.
        END.
        
        ccompany     = oJsonIdent:GetCharacter('company').
        cuser_name   = oJsonIdent:GetCharacter('user_name').  
        ilanguage_id = oJsonIdent:GetInteger  ('language_id').
        
        IF oJsonIdent:HAS('function') THEN cFunction = oJsonIdent:GetCharacter('function').

        lRetVal = TRUE.
        RETURN lRetVal.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC LOGICAL getKeyFields(
        INPUT  oJsonIdent AS JsonObject,
        OUTPUT cKeyFields AS CHARACTER ,
        OUTPUT cKeyValues AS CHARACTER 
        ):
        
        DEFINE VARIABLE lRetVal     AS LOGICAL   NO-UNDO.
        
        DEFINE VARIABLE cFieldNames AS CHARACTER NO-UNDO EXTENT.
        DEFINE VARIABLE cFieldName  AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cString     AS CHARACTER NO-UNDO.
        DEFINE VARIABLE lOK         AS LOGICAL   NO-UNDO.
        DEFINE VARIABLE cValue      AS CHARACTER NO-UNDO.
        
        cKeyFields  = ''.
        cKeyValues  = ''.
        cFieldNames = oJsonIdent:getNames().
        DO i1 = 1 TO EXTENT(cFieldNames):
            IF NOT cFieldNames[i1] BEGINS 'keyfield' THEN NEXT.
            cKeyFields = cKeyFields
                + (IF cKeyFields = '' THEN '' ELSE ';')
                + REPLACE(cFieldNames[i1], 'keyfield_', '').
            cValue = oJsonIdent:GetCharacter(cFieldNames[i1]).
            cKeyValues = cKeyValues
                + (IF cKeyValues = '' THEN '' ELSE CHR(01))
                + cValue. 
        END.
        lOK = TRUE.
        DO i1 = 1 TO NUM-ENTRIES(cKeyFields, ';'):
            cString    = ENTRY(i1, cKeyFields, ';').
            cString    = ENTRY(1, cString, '_') + '_'.
            cFieldName = REPLACE(ENTRY(i1, cKeyFields, ';'), cString, '').
            
            DO WHILE lOK:
                FIND FIRST Ge_MIS._Field NO-LOCK 
                    WHERE Ge_MIS._Field._Field-Name = cFieldname NO-ERROR.
                IF NOT AVAILABLE Ge_MIS._Field THEN 
                DO:
                    lOK = FALSE.
                    LEAVE.
                END.
                
                CASE Ge_MIS._Field._Data-Type:
                    WHEN 'character' THEN 
                        ENTRY(i1, cKeyValues, CHR(01)) = QUOTER(ENTRY(i1, cKeyValues, CHR(01))).
                    WHEN 'logical'   THEN 
                        ENTRY(i1, cKeyValues, CHR(01)) = STRING(ENTRY(i1, cKeyValues, CHR(01)),"TRUE/FALSE").
                END CASE.
            
                LEAVE.
            END.
            
            DO WHILE NOT lOK:
                FIND FIRST FRAMEWORK._Field NO-LOCK 
                    WHERE FRAMEWORK._Field._Field-Name = cFieldname NO-ERROR.
                IF NOT AVAILABLE FRAMEWORK._Field THEN 
                DO:
                    lOK = FALSE.
                    LEAVE.
                END.
                
                CASE FRAMEWORK._Field._Data-Type:
                    WHEN 'character' THEN 
                        ENTRY(i1, cKeyValues, CHR(01)) = QUOTER(ENTRY(i1, cKeyValues, CHR(01))).
                    WHEN 'logical'   THEN 
                        ENTRY(i1, cKeyValues, CHR(01)) = STRING(ENTRY(i1, cKeyValues, CHR(01)),"TRUE/FALSE").
                END CASE.
            
                LEAVE.
            END.
        END.

        lRetVal = TRUE.
        RETURN lRetVal.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC CHARACTER getLogicalDBName(
        INPUT ipcFilename AS CHARACTER 
        ):
        
        DEFINE VARIABLE cLogicalDBName AS CHARACTER NO-UNDO.
        
        DEFINE VARIABLE hDictBuffer    AS HANDLE    NO-UNDO.
        DEFINE VARIABLE cFileName      AS CHARACTER NO-UNDO.
        
        cFileName = SUBSTITUTE('Ge_MIS.&1', ipcFilename) NO-ERROR.
        CREATE BUFFER hDictBuffer FOR TABLE cFileName NO-ERROR.

        cLogicalDBName = (IF VALID-HANDLE(hDictBuffer) THEN 'Ge_MIS' ELSE 'FRAMEWORK').
        
        DELETE OBJECT hDictBuffer NO-ERROR.
        
        RETURN cLogicalDBName.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC CHARACTER getProgramName(
        INPUT        oJsonIdent    AS JsonObject,
        INPUT        cUsers        AS CHARACTER ,
        OUTPUT       cFormUser     AS CHARACTER ,
        OUTPUT       cFormColumns  AS CHARACTER ,
        INPUT-OUTPUT iItemsPerPage AS INTEGER   ,
        INPUT-OUTPUT cMaxHeight    AS CHARACTER
        ):
        
        DEFINE VARIABLE ccompany     AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cFormId      AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cProgramUser AS CHARACTER NO-UNDO.

        cProgram = ''.
        ccompany = oJsonIdent:GetCharacter('company').
        cFormId  = oJsonIdent:GetCharacter('formId' ).
        
        DO i1 = 1 TO NUM-ENTRIES(cUsers, ','): 
            cProgramUser = ENTRY(i1, cUsers).
            FIND FIRST htmldokumente NO-LOCK 
                WHERE htmldokumente.company   = ccompany
                AND   htmldokumente.user_name = cProgramUser
                AND   htmldokumente.FormId    = cFormId NO-ERROR.
            IF NOT AVAILABLE htmldokumente THEN NEXT. 

            ASSIGN 
                cProgram      = htmldokumente.program
                cFormUser     = cProgramUser
                iItemsPerPage = htmldokumente.itemsPerPage
                cMaxHeight    = htmldokumente.tableMaxHeight
                cFormColumns  = htmldokumente.formColumns. 
            LEAVE.
        END.
        
        RETURN cProgram.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC CHARACTER iso2date(
        INPUT  cIsoDate  AS CHARACTER
        ):
            
        DEFINE VARIABLE cDate AS CHARACTER NO-UNDO.
        
        IF  cIsoDate = '' OR
            cIsoDate = ?  THEN RETURN cDate.    
        cDate = SUBSTITUTE('&1/&2/&3', ENTRY(2, cIsoDate, '-'), ENTRY(3, cIsoDate, '-'), ENTRY(1, cIsoDate, '-') ). 
        
        RETURN cDate.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC VOID readLastcWhere(
        INPUT  oJsonIdent  AS JsonObject,
        INPUT  cFileName   AS CHARACTER ,
        OUTPUT cWhere      AS CHARACTER 
        ):
        
        FIND userdata
            WHERE userdata.user_name   = oJsonIdent:GetCharacter('user_name')
            AND   userdata.company     = oJsonIdent:GetCharacter('company')
            AND   userdata.branch      = '0000'
            AND   userdata.record_type = 'where'
            AND   userdata.section     = cFileName 
            AND   userdata.key_type    = 'last' NO-ERROR.
              
        IF AVAILABLE userdata THEN cWhere = userdata.cfield_1. 
        RELEASE userdata.

        RETURN.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC LOGICAL readLastRecord(
        INPUT  oJsonIdent       AS JsonObject,
        OUTPUT cWhere           AS CHARACTER
        ):

        FIND userdata NO-LOCK
            WHERE userdata.user_name   = oJsonIdent:GetCharacter('user_name')
            AND   userdata.company     = oJsonIdent:GetCharacter('company')
            AND   userdata.branch      = '0000'
            AND   userdata.record_type = 'lastrecord'
            AND   userdata.section     = oJsonIdent:GetCharacter('file_name') 
            AND   userdata.key_type    = '' NO-ERROR.
              
        IF NOT AVAILABLE userdata THEN RETURN FALSE.
             
        cWhere = userdata.cfield_1.
        RELEASE userdata.
        
        RETURN TRUE.
        
    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC VOID readSortFields(
        INPUT  oJsonIdent  AS JsonObject,
        INPUT  cFileName   AS CHARACTER ,
        OUTPUT cSortField  AS CHARACTER ,
        OUTPUT cDirection  AS CHARACTER 
        ):
            
        DEFINE VARIABLE cCompany   AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cUser_Name AS CHARACTER NO-UNDO.
            
        cSortField = ''.
        cDirection = ''.
        cCompany   = oJsonIdent:GetCharacter('company'  ).
        cUser_Name = oJsonIdent:GetCharacter('user_name').
        FIND userdata NO-LOCK
            WHERE userdata.user_name   = cUser_Name
            AND   userdata.company     = cCompany
            AND   userdata.branch      = '0000'
            AND   userdata.record_type = 'sortField'
            AND   userdata.section     = cFileName 
            AND   userdata.key_type    = '' NO-ERROR.
        IF AVAILABLE userdata THEN 
            ASSIGN
                cSortField = userdata.cfield_1
                cDirection = (IF userdata.cfield_2 BEGINS 'asc' THEN '' ELSE userdata.cfield_2).
        
        RETURN.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC CHARACTER getPrimaryIndexFields(
        INPUT ipctable AS CHARACTER
        ):
        
        DEFINE VARIABLE cFields    AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cDBNames   AS CHARACTER NO-UNDO INIT 'Ge_MIS;FRAMEWORK'.
        DEFINE VARIABLE cDBName    AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cFileName  AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cFieldName AS CHARACTER NO-UNDO.
        DEFINE VARIABLE ix         AS INTEGER   NO-UNDO.
        
        DEFINE VARIABLE hBuffer    AS HANDLE    NO-UNDO.
        
        DO ix = 1 TO NUM-ENTRIES(cDBNames, ';'):
            cDBName   = ENTRY(ix, cDBNames, ';').
            cFileName = SUBSTITUTE('&1.&2', cDBName, ipcTable).
            CREATE BUFFER hBuffer FOR TABLE cFileName NO-ERROR.
            IF  NOT ERROR-STATUS:ERROR    AND
                VALID-HANDLE(hBuffer)     THEN LEAVE. 

            DELETE OBJECT hBuffer NO-ERROR.
            cDBName = ''.
        END.
        DELETE OBJECT hBuffer NO-ERROR.

        cFields = ''.               
        CASE cDBName:
            WHEN 'Ge_MIS' THEN 
                DO:
                    FIND FIRST Ge_MIS._File NO-LOCK 
                        WHERE Ge_MIS._File._File-Name = ipctable NO-ERROR.
                    FOR EACH Ge_MIS._Index-Field NO-LOCK 
                        WHERE Ge_MIS._Index-Field._Index-Recid = Ge_MIS._File._Prime-Index,
                        
                        FIRST Ge_MIS._Field NO-LOCK
                        WHERE RECID(Ge_MIS._Field) = Ge_MIS._index-Field._Field-recid
                        
                        BY Ge_MIS._Index-Field._Index-Seq:
                            
                        cFields = cFields 
                            + (IF cFields = '' THEN '' ELSE ';')
                            + Ge_MIS._Field._Field-Name.
                    END. 
                END.
            WHEN 'FRAMEWORK' THEN 
                DO:
                    FIND FIRST FRAMEWORK._File NO-LOCK 
                        WHERE FRAMEWORK._File._File-Name = ipctable NO-ERROR.
                    FOR EACH FRAMEWORK._Index-Field NO-LOCK 
                        WHERE FRAMEWORK._Index-Field._Index-Recid = FRAMEWORK._File._Prime-Index,
                        
                        FIRST FRAMEWORK._Field NO-LOCK
                        WHERE RECID(FRAMEWORK._Field) = FRAMEWORK._index-Field._Field-recid
                        
                        BY FRAMEWORK._Index-Field._Index-Seq:
                            
                        cFields = cFields 
                            + (IF cFields = '' THEN '' ELSE ';')
                            + FRAMEWORK._Field._Field-Name.
                    END. 
                END.
        END CASE.

        RETURN cFields.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC CHARACTER getSysUser(  ):

        DEFINE VARIABLE mBen  AS MEMPTR    NO-UNDO.
        DEFINE VARIABLE iLeng AS INTEGER   INIT 100 NO-UNDO.
        DEFINE VARIABLE fok   AS INTEGER   NO-UNDO.
        DEFINE VARIABLE cBen  AS CHARACTER NO-UNDO.

        SET-SIZE(mBen) = iLeng.
        RUN GetUserNameA( OUTPUT mBen, INPUT-OUTPUT iLeng, OUTPUT fok ) NO-ERROR.
        ASSIGN 
            cBen = GET-STRING(mBen,1) NO-ERROR.

        SET-SIZE(mBen) = 0.

        RETURN cBen.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC LOGICAL readInputDatenFromJson(
        INPUT oJsonObject       AS JsonObject,
        INPUT hbttInput         AS HANDLE,
        INPUT-OUTPUT hbttTemp   AS HANDLE
        ):
        
        DEFINE VARIABLE lcJsonString AS LONGCHAR   NO-UNDO.
        DEFINE VARIABLE lcOriginal   AS LONGCHAR   NO-UNDO.
        
        DEFINE VARIABLE ctable       AS CHARACTER  NO-UNDO.
        
        DEFINE VARIABLE jsonttTemp   AS jsonObject NO-UNDO.
        
        DEFINE VARIABLE lRetVal      AS LOGICAL    NO-UNDO INIT FALSE.
        DEFINE VARIABLE cString      AS CHARACTER  NO-UNDO.
        
        jsonttTemp = NEW JsonObject().
        jsonttTemp = oJsonObject:GetJsonObject('ttTemp').
        lRetVal    = hbttTemp:READ-JSON ('JsonObject', jsonttTemp).
        hbttTemp:FIND-FIRST ().
        
        hbttTemp:WRITE-JSON('longchar', lcJsonString, FALSE).
// MESSAGE 'Daten zweiter Buffer -> ' STRING(lcJsonString). 

        lRetVal = TRUE.
        RETURN lRetVal.
        
    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC VOID readPosition(
        INPUT  oJsonIdent       AS JsonObject ,
        INPUT  cFileName        AS CHARACTER  ,
        OUTPUT iCurrentPosition AS INTEGER    ,
        OUTPUT iStartPage       AS INTEGER    ,
        OUTPUT iMaxRecords      AS INTEGER   
        ):
            
        REPEAT TRANSACTION ON ERROR UNDO, LEAVE:  
            FIND userdata
                WHERE userdata.user_name   = oJsonIdent:GetCharacter('user_name')
                AND   userdata.company     = oJsonIdent:GetCharacter('company')
                AND   userdata.branch      = '0000'
                AND   userdata.record_type = 'position'
                AND   userdata.section     = cFileName 
                AND   userdata.key_type    = '' NO-ERROR.
            IF AVAILABLE userdata THEN 
            DO:
                ASSIGN               
                    iCurrentPosition = userdata.ifield_1
                    iStartPage       = userdata.ifield_2
                    iMaxRecords      = userdata.ifield_3.
            END.
            ELSE 
            DO:
                ASSIGN               
                    iCurrentPosition = 1
                    iStartPage       = 1
                    iMaxRecords      = 25.
            END.
            RELEASE userdata.
            LEAVE.
        END.
        
        RETURN.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC VOID readStartcWhere(
        INPUT  oJsonIdent  AS JsonObject,
        INPUT  cFileName   AS CHARACTER ,
        OUTPUT cWhere      AS CHARACTER 
        ):
        
        FIND userdata
            WHERE userdata.user_name   = oJsonIdent:GetCharacter('user_name')
            AND   userdata.company     = oJsonIdent:GetCharacter('company')
            AND   userdata.branch      = '0000'
            AND   userdata.record_type = 'where'
            AND   userdata.section     = cFileName 
            AND   userdata.key_type    = 'start' NO-ERROR.
              
        IF AVAILABLE userdata THEN cWhere = userdata.cfield_1. 
        RELEASE userdata.

        RETURN.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC VOID setActiveSelection(
        INPUT  oJsonIdent       AS JsonObject,
        INPUT  cFileName        AS CHARACTER ,
        INPUT  cActiveSelection AS CHARACTER 
        ):
            
        DEFINE VARIABLE ccompany   AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cuser_name AS CHARACTER NO-UNDO.
        
        ASSIGN 
            ccompany   = oJsonIdent:GetCharacter('company')
            cuser_name = oJsonIdent:GetCharacter('user_name')
            cProgram   = oJsonIdent:GetCharacter('program').
 
        REPEAT TRANSACTION ON ERROR UNDO, LEAVE:
            FIND userdata 
                WHERE userdata.user_name   = cuser_name
                AND   userdata.company     = ccompany
                AND   userdata.branch      = '0000'
                AND   userdata.record_type = 'active'
                AND   userdata.section     = cFileName 
                AND   userdata.key_type    = cProgram NO-ERROR.
            IF NOT AVAILABLE userdata THEN 
            DO:
                CREATE userdata.
                ASSIGN
                    userdata.user_name     = cuser_name
                    userdata.company       = ccompany
                    userdata.branch        = '0000'
                    userdata.record_type   = 'active'
                    userdata.section       = cFileName 
                    userdata.key_type      = cProgram
                    userdata.creation_date = NOW NO-ERROR.
            END.
            ELSE 
            DO:
                userdata.access_date = NOW.
            END.
            userdata.cfield_1    = cActiveSelection.
            RELEASE userdata.
            LEAVE.
        END.   

        RETURN.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC LONGCHAR trimStructure(
        INPUT oJsonInput AS JsonObject
        ):

        DEFINE VARIABLE lcResult AS LONGCHAR NO-UNDO.
        DEFINE VARIABLE ii       AS INTEGER  NO-UNDO.
        
        lcResult = TRIM(oJsonInput:GetJsonText()).
        lcResult = SUBSTRING(lcResult,02).
        ii = LENGTH(lcResult) - 1.
        lcResult = SUBSTRING(lcResult,01, ii).
        
        RETURN lcResult.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC VOID writeLastcWhere(
        INPUT  oJsonIdent  AS JsonObject,
        INPUT  cFileName   AS CHARACTER ,
        INPUT  cWhere      AS CHARACTER 
        ):
        
        REPEAT TRANSACTION ON ERROR UNDO, LEAVE:  
            FIND userdata
                WHERE userdata.user_name   = oJsonIdent:GetCharacter('user_name')
                AND   userdata.company     = oJsonIdent:GetCharacter('company')
                AND   userdata.branch      = '0000'
                AND   userdata.record_type = 'where'
                AND   userdata.section     = cFileName 
                AND   userdata.key_type    = 'last' NO-ERROR.
              
            IF NOT AVAILABLE userdata THEN 
            DO:
                CREATE  userdata.
                ASSIGN 
                    userdata.user_name   = oJsonIdent:GetCharacter('user_name')
                    userdata.company     = oJsonIdent:GetCharacter('company')
                    userdata.branch      = '0000'
                    userdata.record_type = 'where'
                    userdata.section     = cFileName 
                    userdata.key_type    = 'last' NO-ERROR.
            END.
            ASSIGN  
                userdata.cfield_1 = cWhere.
            RELEASE userdata.
            LEAVE.
        END.

        RETURN.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC LOGICAL writeLastRecord(
        INPUT  oJsonIdent       AS JsonObject,
        INPUT  cWhere           AS CHARACTER
        ):
            
        REPEAT TRANSACTION ON ERROR UNDO, LEAVE:  
            FIND userdata
                WHERE userdata.user_name   = oJsonIdent:GetCharacter('user_name')
                AND   userdata.company     = oJsonIdent:GetCharacter('company')
                AND   userdata.branch      = '0000'
                AND   userdata.record_type = 'lastrecord'
                AND   userdata.section     = oJsonIdent:GetCharacter('file_name') 
                AND   userdata.key_type    = '' NO-ERROR.
              
            IF NOT AVAILABLE userdata THEN 
            DO:
                CREATE  userdata.
                ASSIGN 
                    userdata.user_name     = oJsonIdent:GetCharacter('user_name')
                    userdata.company       = oJsonIdent:GetCharacter('company')
                    userdata.branch        = '0000'
                    userdata.record_type   = 'lastrecord'
                    userdata.section       = oJsonIdent:GetCharacter('file_name') 
                    userdata.key_type      = ''
                    userdata.creation_date = NOW NO-ERROR.
            END.
            ASSIGN  
                userdata.cfield_1    = cWhere
                userdata.access_date = NOW.
            RELEASE userdata.
            LEAVE.
        END.
        
        RETURN TRUE.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC VOID writePosition(
        INPUT  oJsonIdent       AS JsonObject,
        INPUT  cFileName        AS CHARACTER ,
        INPUT  iCurrentPosition AS INTEGER   ,
        INPUT  iStartPage       AS INTEGER   ,
        INPUT  iMaxRecords      AS INTEGER    
        ):
            
        REPEAT TRANSACTION ON ERROR UNDO, LEAVE:  
            FIND userdata
                WHERE userdata.user_name   = oJsonIdent:GetCharacter('user_name')
                AND   userdata.company     = oJsonIdent:GetCharacter('company')
                AND   userdata.branch      = '0000'
                AND   userdata.record_type = 'position'
                AND   userdata.section     = cFileName 
                AND   userdata.key_type    = '' NO-ERROR.
              
            IF NOT AVAILABLE userdata THEN 
            DO:
                CREATE  userdata.
                ASSIGN 
                    userdata.user_name   = oJsonIdent:GetCharacter('user_name')
                    userdata.company     = oJsonIdent:GetCharacter('company')
                    userdata.branch      = '0000'
                    userdata.record_type = 'position'
                    userdata.section     = cFileName 
                    userdata.key_type    = '' NO-ERROR.
            END.
            ASSIGN  
                userdata.ifield_1 = iCurrentPosition
                userdata.iField_2 = iStartPage
                userdata.ifield_3 = iMaxRecords.
            RELEASE userdata.
            LEAVE.
        END.
        
        RETURN.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC VOID writeSortfields(
        INPUT  oJsonIdent  AS JsonObject,
        INPUT  cFileName   AS CHARACTER ,
        INPUT  cSortField  AS CHARACTER ,
        INPUT  cDirection  AS CHARACTER 
        ):
        
        DEFINE VARIABLE cCompany   AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cUser_Name AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cReplace   AS CHARACTER NO-UNDO.
            
        cCompany   = oJsonIdent:GetCharacter('company'  ).
        cUser_Name = oJsonIdent:GetCharacter('user_name').
        cReplace   = SUBSTITUTE('&1_', cFileName).
        cSortField = REPLACE(cSortField, cReplace, '').
        
        REPEAT TRANSACTION ON ERROR UNDO, LEAVE:  
            FIND userdata
                WHERE userdata.user_name   = cUser_Name
                AND   userdata.company     = cCompany
                AND   userdata.branch      = '0000'
                AND   userdata.record_type = 'sortField'
                AND   userdata.section     = cFileName 
                AND   userdata.key_type    = '' NO-ERROR.
              
            IF NOT AVAILABLE userdata THEN 
            DO:
                CREATE  userdata.
                ASSIGN 
                    userdata.user_name   = cUser_Name
                    userdata.company     = cCompany
                    userdata.branch      = '0000'
                    userdata.record_type = 'sortField'
                    userdata.section     = cFileName 
                    userdata.key_type    = '' NO-ERROR.
            END.
            ASSIGN  
                userdata.cfield_1 = cSortfield
                userdata.cfield_2 = cDirection.
            RELEASE userdata.
            LEAVE.
        END.

        RETURN.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC VOID writeStartcWhere(
        INPUT  oJsonIdent  AS JsonObject,
        INPUT  cFileName   AS CHARACTER ,
        INPUT  cWhere      AS CHARACTER 
        ):
        
        REPEAT TRANSACTION ON ERROR UNDO, LEAVE:  
            FIND userdata
                WHERE userdata.user_name   = oJsonIdent:GetCharacter('user_name')
                AND   userdata.company     = oJsonIdent:GetCharacter('company')
                AND   userdata.branch      = '0000'
                AND   userdata.record_type = 'where'
                AND   userdata.section     = cFileName 
                AND   userdata.key_type    = 'start' NO-ERROR.
              
            IF NOT AVAILABLE userdata THEN 
            DO:
                CREATE  userdata.
                ASSIGN 
                    userdata.user_name   = oJsonIdent:GetCharacter('user_name')
                    userdata.company     = oJsonIdent:GetCharacter('company')
                    userdata.branch      = '0000'
                    userdata.record_type = 'where'
                    userdata.section     = cFileName 
                    userdata.key_type    = 'start' NO-ERROR.
            END.
            ASSIGN  
                userdata.cfield_1 = cWhere.
            RELEASE userdata.
            LEAVE.
        END.

        RETURN.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/
    DESTRUCTOR PUBLIC utilitiesHandler ( ):
    /*    MESSAGE 'Destructor utilitiesHandler '.*/
    /*    DELETE OBJECT hQuery NO-ERROR.         */
    /*    DELETE OBJECT hBuffer NO-ERROR.        */
    END DESTRUCTOR.

END CLASS.