Salesforce

ABL to add a new variable extent to database areas when the last extent is 1.8 GB

« Go Back

Information

 
TitleABL to add a new variable extent to database areas when the last extent is 1.8 GB
URL Name4GL-script-to-add-a-new-variable-extent-to-database-areas-where-the-last-extent-is-bigger-than-1-8-gb
Article Number000140699
EnvironmentProduct: OpenEdge
Version: All Supported Versions
OS: Windows
Question/Problem Description
4GL script to add a new variable extent to database areas where the last extent is bigger than 1.8 gb
Steps to Reproduce
Clarifying Information
Error Message
Defect Number
Enhancement Number
Cause
Resolution
The following code example is useful in database environments that:
  • do not use an Enterprise database license or
  • where the largefiles feature has not been enabled or
  • where variable filesizes need to be monitored.

This ABL code needs to be executed against a running OpenEdge database, since it is generating and executing commands like 'prostrct addonline databaseName add.st' to add additional extents to the OpenEdge database. 

The code also assumes it is executed in the same directory as where the <dbname>.db file is located.
  • The prostrct command generated only uses the name of the database not the full path to the database
This code script is based on the ABL code from the following Articles which uses the _areastatus._areastatus-lastextent VST to determine the current filesize. It can be further modified for site-specific requirements:   
DEFINE VARIABLE vlast-ext AS CHAR FORMAT "x(14)" NO-UNDO.
DEFINE VARIABLE last-string AS CHAR NO-UNDO.
DEFINE VARIABLE last-ext-num AS INT NO-UNDO.
DEFINE VARIABLE ext-left AS INT NO-UNDO.
DEFINE VARIABLE ext-warning AS CHAR FORMAT "x(4)" NO-UNDO.
DEFINE VARIABLE comm-line AS CHARACTER NO-UNDO FORMAT "x(70)".
DEFINE BUFFER buf FOR _Area.
DEFINE VARIABLE rindx AS INTEGER NO-UNDO.
DEFINE VARIABLE hasExtentsBiggerThanWanted AS LOGICAL.

hasExtentsBiggerThanWanted = FALSE.

        OS-COMMAND SILENT VALUE("del add.st").
        OS-COMMAND SILENT VALUE("copy NUL add.st").

FOR EACH _areastatus NO-LOCK
    WHERE _areastatus-areanum >= 6 AND NOT _areastatus._areastatus-areaname BEGINS "After Image":
    vlast-ext = _areastatus._areastatus-lastextent.
    IF LENGTH(vlast-ext) > 14
        THEN
    DO WHILE INDEX(vlast-ext,"/") NE 0:
        vlast-ext = SUBSTRING(vlast-ext,INDEX(vlast-ext,"/") + 1).
    END.
    last-string = SUBSTRING(vlast-ext,INDEX(vlast-ext,".") + 1).
    IF last-string = "db"
        THEN last-ext-num = 1.
    ELSE last-ext-num = int(SUBSTRING(last-string,2)).
    ASSIGN
        ext-left    = (_areastatus._areastatus-extents - last-ext-num)
        ext-warning = (IF ext-left = 0 THEN "****"
ELSE IF ext-left = 1 THEN "*"
ELSE "").

    DEFINE VARIABLE temp1 AS CHARACTER.
    temp1 = vlast-ext .
    DEFINE VARIABLE temp2 AS CHARACTER.
    temp2 = '.' .
    rindx = R-INDEX(temp1, temp2).

    DEFINE VARIABLE endStrLength AS INTEGER.
    endStrLength = LENGTH(SUBSTRING(vlast-ext,rindx)).

    SUBSTRING(vlast-ext,rindx).

    DEFINE VARIABLE theFile AS CHARACTER.
    theFile = REPLACE(vlast-ext, SUBSTRING(vlast-ext,rindx), "") + ".d" + STRING(_areastatus._areastatus-extents) .
    FILE-INFO:FILE-NAME = theFile .

    DEFINE VARIABLE clusterSize AS CHARACTER.
    FOR EACH buf WHERE _Area-number = _areastatus-areanum :
        clusterSize = STRING(_Area-clustersize) .
    END.

    FIND _Area WHERE _Area._Area-number = _areastatus-areanum.

    DEFINE VARIABLE NumRecordsPerBlock AS INT.
    NumRecordsPerBlock = EXP(2, _Area._Area-Recbits).

  IF (FILE-INFO:FILE-SIZE > 1800000000) THEN // 1800000000 is about 1,8 GB

    DO:

        hasExtentsBiggerThanWanted = TRUE.
        DEFINE STREAM addExtent.
        OUTPUT STREAM addExtent TO "add.st" APPEND.
        PUT STREAM addExtent UNFORMATTED
            "d ~"" _areastatus._areastatus-areaname "~":" _areastatus._areastatus-areanum "," NumRecordsPerBlock ";" clusterSize " " REPLACE(vlast-ext, SUBSTRING(vlast-ext,rindx), "") ".d" (_areastatus._areastatus-extents + 1)
            SKIP .
        OUTPUT STREAM addExtent CLOSE.

        DEFINE VARIABLE v-datetime AS DATETIME NO-UNDO.
        ASSIGN
            v-datetime = NOW.
    END.

END.

IF (hasExtentsBiggerThanWanted = TRUE) THEN
DO:
    comm-line = "call prostrct addonline " + DBNAME + " add.st >> "+ REPLACE(REPLACE(REPLACE(REPLACE(STRING(v-datetime),' ','_'),'/','_'),':','_'),'.','_')+ "_log.txt" .
    OS-COMMAND SILENT VALUE(comm-line).
END.

 
Workaround
Notes
Keyword Phrase
Last Modified Date11/20/2020 7:04 AM

Powered by