Consultor Eletrônico



Kbase P160549: Sample code to dump data?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   22/02/2010
Status: Unverified

GOAL:

Sample code to dump data?

GOAL:

How to dump data programmatically?

GOAL:

Sample code to dump data with runtime license?

FACT(s) (Environment):

Progress 9.x
OpenEdge 10.x
All Supported Operating Systems

FIX:

The following sample code scans the database schema for the table names and generates the dump and load procedures for each table.
Use myexport.p and myimport.p to call the generated procedures.
/* genproc.p */
DEF STREAM ImpStr.
DEF STREAM ExpStr.
DEF VAR cImpFic AS CHAR NO-UNDO.
DEF VAR cExpFic AS CHAR NO-UNDO.
DEF VAR cDotDF AS CHAR NO-UNDO.
FOR EACH _file WHERE _file-num > 0:
cImpFic = SUBSTRING(_file-name,1,8) + "_imp.p".
cExpFic = SUBSTRING(_file-name,1,8) + "_exp.p".
cDotDf = SUBSTRING(_file-name,1,8). /* This can be _Dump-name */
cDotDf = cDotDf + ".d".
/* Create export file */
/* The customer can check if the file already exists or another*/
/* table can produce the same .p file */
OUTPUT STREAM ExpStr TO VALUE(cExpFic).
PUT STREAM ExpStr UNFORMATTED "OUTPUT TO '" cDotDF "'." SKIP.
PUT STREAM ExpStr UNFORMATTED "FOR EACH " _file-name "
NO-LOCK:" SKIP.
PUT STREAM ExpStr UNFORMATTED " EXPORT" SKIP.
/* Create import file */
OUTPUT STREAM ImpStr TO VALUE(cImpFic).
PUT STREAM ImpStr UNFORMATTED "INPUT FROM '" cDotDF "'." SKIP.
PUT STREAM ImpStr UNFORMATTED "REPEAT: " SKIP.
PUT STREAM ImpStr UNFORMATTED " CREATE " _file-name "." SKIP.
PUT STREAM ImpStr UNFORMATTED " IMPORT" SKIP.
FOR EACH _field of _file:
PUT STREAM ExpStr UNFORMATTED " " _field-name SKIP.
PUT STREAM ImpStr UNFORMATTED " " _field-name SKIP.
END.
PUT STREAM ExpStr UNFORMATTED " ." SKIP.
PUT STREAM ImpStr UNFORMATTED " ." SKIP.
PUT STREAM ExpStr UNFORMATTED "END." SKIP.
PUT STREAM ImpStr UNFORMATTED "END." SKIP.
PUT STREAM ExpStr UNFORMATTED "OUTPUT CLOSE." SKIP.
PUT STREAM ImpStr UNFORMATTED "INPUT CLOSE." SKIP.
OUTPUT STREAM ExpStr CLOSE.
OUTPUT STREAM ImpStr CLOSE.
COMPILE VALUE(cImpFic) SAVE.
COMPILE VALUE(cExpFic) SAVE.
END.
/* myexport.p */
FOR EACH _file WHERE _file-num > 0 NO-LOCK:
RUN VALUE(SUBSTRING(_file-name,1,8) + "_exp.p" ).
End.
/* myimport.p */
FOR EACH _file WHERE _file-num > 0 NO-LOCK:
RUN VALUE(SUBSTRING(_file-name,1,8) + "_imp.p" ).
End.