Skip to content

Instantly share code, notes, and snippets.

@cverbiest
Last active July 14, 2017 17:40
Show Gist options
  • Save cverbiest/feb807d0784ff01a7c66 to your computer and use it in GitHub Desktop.
Save cverbiest/feb807d0784ff01a7c66 to your computer and use it in GitHub Desktop.
&scoped db
&scoped-define dfin WZ-DFIN
def var WZ-DFIN as char form "x(65)" init '{&db}.df'.
&scoped-define dfout WZ-DFOUT
def var WZ-DFOUT as char form "x(65)" init '{&db}area.df'.
update WZ-DFIN WZ-DFOUT.
&scoped csvfile '{&db}area.csv'
&scoped filefield 1
&scoped areafield 2
&scoped numfields 2
&scoped delim ";"
&scoped header no
def var l-line as char no-undo form "x(78)".
def var l-fields as char extent {&numfields} no-undo.
def temp-table t-filearea
field file-name as char form "x(20)"
field table-area as char form "x(20)"
field index-area as char form "x(20)"
field lob-area as char form "x(20)"
index t-filearea1 is unique primary file-name.
def stream sdfin.
def stream sdfout.
procedure createFileArea:
def input param i-file as char.
def input param i-area as char.
create t-filearea.
assign
t-filearea.file-name = i-file
t-filearea.table-area = subst("&1 tables", i-area)
t-filearea.index-area = subst("&1 indexes", i-area)
t-filearea.lob-area = subst("&1 lobs", i-area)
.
end.
input from value({&csvfile}).
if {&header}
then import unformatted l-line.
repeat:
import delimiter {&delim} l-fields.
run createFileArea(l-fields[{&filefield}], l-fields[{&areafield}]).
end.
input close.
def var l-file as char form "x(20)" no-undo.
def var l-type as char no-undo.
pause 0 before-hide.
input stream sdfin from value({&dfin}).
output stream sdfout to value({&dfout}).
repeat:
import stream sdfin unformatted l-line.
disp l-file l-type l-line.
if trim(l-line) = ""
then do:
release t-filearea.
l-file = "".
l-type = "".
disp l-file l-type.
end.
else if l-line begins "ADD "
then do:
l-line = trim(l-line).
l-type = entry(2, l-line, " ").
disp l-type.
if lookup(l-type, "SEQUENCE") = 0
then do:
if l-type = "FIELD"
then l-file = trim(entry(5, l-line, " "), '"').
else l-file = trim(entry(num-entries(l-line, " "), l-line, " "), '"').
disp l-file.
find t-filearea where t-filearea.file-name = l-file no-error.
if not avail t-filearea
then run createFileArea(l-file, "TRANS").
find t-filearea where t-filearea.file-name = l-file.
end.
end.
else if l-line begins " AREA"
then do:
case l-type:
when "TABLE" then l-line = subst(' AREA "&1"', t-filearea.table-area).
when "INDEX" then l-line = subst(' AREA "&1"', t-filearea.index-area).
otherwise message "No area for " l-type.
end case.
end.
else if l-line begins " LOB-AREA"
then do:
l-line = subst(' LOB-AREA "&1"', t-filearea.lob-area).
end.
disp l-line.
if l-line = ""
then put stream sdfout unformatted l-line skip(1).
else put stream sdfout unformatted l-line skip.
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment