home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
LAYOUT.ZIP
/
LAYOUT.CMD
next >
Wrap
OS/2 REXX Batch file
|
1991-05-17
|
12KB
|
295 lines
/* ------------------------------------------------------------------------------- */
/* REXX Record Layout Prodecure */
/* */
/* This REXX procedure will create a COBOL Record Layout from an OS/2 EE Database. */
/* The Record Layout will be printed and will also create an ASCII file on your */
/* hard drive which can be uploaded or used in MicroFocus COBOL. Enjoy */
/* */
/* Written by Jonathan Schafer with help from IBM manuals */
/* */
/* ------------------------------------------------------------------------------- */
ARG struct /* input structure name */
IF LENGTH(struct) = 0 THEN /* Check to see if structure name was entered */
signal ERROR1
ELSE
NOP
IF RxFuncQuery('SQLDBS') <> 0 THEN /* Add Database Services DLL's to REXX */
rcy = RxFuncAdd('SQLDBS', 'SQLAR', 'SQLDBS')
ELSE
NOP
IF RxFuncQuery('SQLEXEC') <> 0 THEN /* Add Query Manager DLL's to REXX */
rcy = RxFuncAdd('SQLEXEC', 'SQLAR', 'SQLEXEC')
ELSE
NOP
nmrdd_rc = 0 /* Set return Code */
CALL SQLDBS 'START DATABASE MANAGER' /* Start Database Manager */
IF SQLCA.SQLCODE <> -1026 & SQLCA.SQLCODE <> 0 THEN
signal ERROR
ELSE
NOP
CALL SQLDBS 'START USING DATABASE nmrdd' /* Start using database - DB = nmrdd */
IF SQLCA.SQLCODE <> 0 THEN
DO
IF SQLCA.SQLCODE = -1013 THEN
say 'Database not found...Please contact your Systems Administrator'
ELSE
DO
IF SQLCA.SQLCODE = -1015 THEN
DO
say SQLMSG
say 'Restarting the database'
CALL SQLDBS 'RESTART DATABASE nmrdd'
IF SQLCA.SQLCODE <> 0 THEN
signal ERROR
ELSE
DO
say 'Starting the Database...Please wait'
CALL SQLDBS 'START USING DATABASE nmrdd'
END
END
END
END
ELSE
NOP
nmrdd_rc = structqry(struct) /* Call to Structure subroutine */
ERROR: /* Database Error subroutine */
nmrdd_rc = SQLCA.SQLCODE
say SQLMSG
signal FINISH
ERROR1: /* REXX Error subroutine */
nmrdd_rc = -1
say 'You must enter a Structure name'
signal FINISH
ERROR2: /* REXX DISK Error subroutine */
nmrdd_rc = -2
say 'Error writing to disk'
signal FINISH
FINISH: /* Ending subroutine */
IF nmrdd_rc = -1 THEN
NOP
ELSE
CALL SQLDBS 'STOP USING DATABASE'
say 'Record Layout finished with rc = 'nmrdd_rc
rcy = RxFuncdrop('SQLEXEC') /* Release Database DLL's */
rcy = RxFuncdrop('SQLDBS') /* Release Query Manager DLL's */
exit nmrdd_rc
structqry: procedure /* Structure subroutine */
ARG struct /* Input structure name */
fn = struct||'.ASC' /* File name for structure */
'@ERASE 'fn '1>NUL 2>NUL' /* Erases structure file if file currently exists */
CALL SQLEXEC 'DECLARE c1 CURSOR for s1' /* Cursor declaration */
IF SQLCA.SQLCODE <> 0 THEN
signal ERROR
ELSE
NOP
/* This is the dynamic SQL statement which retrieves data from the database */
sel_layout = 'SELECT DISTINCT element_level, prefix, element_name,',
'element_picture, element_value, element_position, a.structure_name',
'FROM srs.structure a, srs.element_structure b',
'WHERE (a.structure_name = b.structure_name )',
'ORDER BY element_position'
CALL SQLEXEC 'PREPARE s1 FROM :sel_layout' /* This statement creates the actual SQL used by QM */
IF SQLCA.SQLCODE <> 0 THEN
signal ERROR
ELSE
NOP
CALL SQLEXEC 'OPEN c1' /* Opens the cursor */
IF SQLCA.SQLCODE <> 0 THEN
signal ERROR
ELSE
NOP
DO WHILE SQLCA.SQLCODE = 0 /* Performs loop until no more data */
CALL SQLEXEC 'FETCH c1', /* Retrieves first data row from cursor */
'INTO :level:level1,',
':prefix:prefix1,',
':name:name1,',
':picture:picture1,',
':value:value1,',
':position:position1,',
':structure:structure1'
CALL null_check /* Dynamic SQL requires INDICATOR Variables as well as */
/* HOST Variables if the Tables allow NULL values. This */
/* procedure checks for NULL values and sets the field */
/* blanks if NULLS are found. */
IF SQLCA.SQLCODE = 0 THEN
DO
IF structure = struct THEN /* structure must match INPUT Structure name or record */
DO /* is ignored. */
ilevel = indent_level(level, previous_level); /* calls Indent Level subroutine */
apic = align_pic(level, previous_level, picture); /* calls Align PIC clause subrtne */
cvalue = check_value(value); /* calls the VALUE check subroutine */
line = ilevel' 'prefix || name' 'apic' 'cvalue; /* These three lines */
line = strip(line, 'T'); /* put the period at */
line = line || '.'; /* the end of the line */
checkpos = lastpos('VALUE', cvalue); /* Checks for a VALUE clause */
IF checkpos <> 0 THEN /* If a value clause is found, the */
DO /* line is split into two. The */
valpos = lastpos('VALUE', line); /* second line will contain the */
first_line = substr(line, 1, valpos - 1); /* word 'VALUE' and the value */
/* clause. */
CALL print fn, first_line; /* Performs the print subroutine */
num_spaces = pos(level,line); /* Formats the Value line */
spaces = substr(line, 1, num_spaces -1);
second_line = spaces || ' ' || substr(line, valpos);
CALL print fn, second_line; /* Performs the print subroutine */
END
ELSE
CALL print fn, line; /* Performs the print subroutine */
IF level <> '88' THEN /* Sets the previous level variable used */
previous_level = level /* in the Align Picture and Indent Level */
ELSE /* subroutines. */
NOP
END
END
END
IF SQLCA.SQLCODE <> 100 THEN
signal ERROR
ELSE
NOP
CALL SQLEXEC 'CLOSE s1' /* Closes the cursor */
'@TYPE ' fn '1> LPT2' /* Prints the Record layout to the printer */
nmrdd_rc = 0 /* Sets the return code */
return nmrdd_rc /* Returns to the main function */
indent_level: procedure /* Indent Level subroutine */
/* This subroutine compares the Level (ex. 05, 10, 88, etc) and compares it to the previous level. */
/* It then determines the appropriate amount of indenting and returns the value to the calling routine. */
ARG level, previous_level /* Input arguments passed from calling routine */
spaces = ' '
IF level = '88' THEN
times = (previous_level / 5) + 1
ELSE
times = level / 5
DO index = 1 to times
level = spaces || level
END
ilevel = level
return ilevel
align_pic: procedure /* Align Picture subroutine */
/* This subroutine realigns the PIC clauses after the Indent Level procedure makes them non-aligned. */
ARG level, previous_level, picture /* Input arguments passed from the calling routine */
IF level = '88' THEN
level = previous_level
ELSE
NOP
IF level = 05 THEN
picture = ' ' || picture
ELSE
IF level = 10 THEN
picture = ' ' || picture
ELSE
IF level = 15 THEN
picture = ' ' || picture
ELSE
picture = ' ' || picture
apic = picture
return apic
check_value: procedure /* Check Value subroutine */
/* This subroutine checks to see if a value exists in the VALUE field. If a value exists, the word 'VALUE */
/* is Concatenated to the beginning of the value. */
ARG value /* Input argument passed from calling routine */
IF length(strip(value,'B',' ')) <> 0 THEN
cvalue = 'VALUE '|| value
ELSE
cvalue = value
return cvalue
null_check: /* Null check subroutine */
/* This subroutine checks the value of the indicator variable. If a value retrieved from the database is */
/* NULL (does not exist), the indicator variable will be -1. This routine then initializes the variable if */
/* the indicator variable is set. */
IF level1 = -1 THEN
level = ' '
ELSE
NOP
IF name1 = -1 THEN
name = ' '
ELSE
NOP
IF picture1 = -1 THEN
picture = ' '
ELSE
NOP
IF value1 = -1 THEN
value = ' '
ELSE
NOP
return
print: procedure /* Print subroutine */
ARG fn, line /* Input arguments from the calling routine */
x = lineout(fn, line)
IF x = 0 THEN
NOP
ELSE
signal ERROR2
return