-
Notifications
You must be signed in to change notification settings - Fork 134
/
DeletePDS.groovy
77 lines (65 loc) · 1.94 KB
/
DeletePDS.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
@groovy.transform.BaseScript com.ibm.dbb.groovy.ScriptLoader baseScript
import groovy.transform.*
import groovy.cli.commons.*
import com.ibm.jzos.CatalogSearch;
import com.ibm.jzos.CatalogSearchField;
import com.ibm.jzos.ZFile;
@Field String hlq
@Field String filter
@Field Boolean preview = false
// run setup tasks
setup(args)
// process datasets with provided HLQ
filter = hlq
if (!filter.endsWith(".**"))
filter = filter + ".**"
if (preview)
println("** Searching for all the datasets filtered with HLQ '${hlq}'")
else
println("** Deleting all datasets filtered with HLQ '${hlq}'")
CatalogSearch catalogSearch = new CatalogSearch(filter, 64000);
catalogSearch.addFieldName("ENTNAME");
catalogSearch.search();
def datasetCount = 0
catalogSearch.each { searchEntry ->
CatalogSearch.Entry catalogEntry = (CatalogSearch.Entry) searchEntry;
if (catalogEntry.isDatasetEntry()) {
datasetCount++;
CatalogSearchField field = catalogEntry.getField("ENTNAME");
String dsn = field.getFString().trim();
String qdsn = "'" + dsn + "'"; //Specify that the dsn is fully qualified.
if (ZFile.dsExists(qdsn)) {
if (preview) {
println "*** Found $qdsn"
} else {
println "*** Deleting $qdsn"
ZFile.remove("//$qdsn")
}
}
}
}
if (preview)
println("** Found $datasetCount entries.")
else
println("** Deleted $datasetCount entries.")
/*
setup :
handle cli arguments
*/
def setup(String[] args) {
// parse input arguments
String usage = 'DeletePDS.groovy [options]'
String header = 'options:'
def cli = new CliBuilder(usage:usage,header:header)
cli.h(longOpt:'hlq', args:1, 'High-Level Qualifier of datasets to delete')
cli.p(longOpt:'preview', 'Only lists the datasets without actually deleting them')
def opts = cli.parse(args)
if (!args || !opts) {
cli.usage()
System.exit(1)
}
// update authentication properties with cli options
if (opts.h) hlq = opts.h
if (opts.p) preview = opts.p
assert hlq : "Missing 'hlq' argument"
}