package
cobolprogramclasses;
/************************************************************************
**This file automatically generated from Cobol
program CBLEX in source file EXEC-SQL1.COB
**Generated at time 17:45:16.29 on Thursday,
02/04/10
************************************************************************/
import
coboldataclasses.cblex.Rpt1;
import
coboldataclasses.cblex.Rpt2;
import
coboldataclasses.cblex.Sqlca;
import
coboldataclasses.cblex.Rpt1Headers;
import
coboldataclasses.cblex.Rpt2Headers;
import
coboldataclasses.cblex.Rpt1Data;
import
coboldataclasses.cblex.Rpt2Data;
import
com.res.java.lib.*;
import
java.math.BigDecimal;
import
java.sql.SQLException;
public class
Cblex extends Program {
//****************************************************************
//* A sample program which updates the
salaries for those *
//* employees whose current commission
total is greater than or *
//* equal to the value of COMMISSION. The
salaries of those who *
//* qualify are increased by the value of
PERCENTAGE retroactive *
//* to RAISE-DATE. A report is generated
showing the projects *
//* which these employees have contributed
to ordered by the *
//* project number and employee ID. A
second report shows each *
//* project having an end date
occurring after RAISE-DATE *
//* (i.e. potentially affected by the
retroactive raises ) with *
//* its total salary expenses and a count
of employees who *
//* contributed to the project. *
//****************************************************************
//@CobolSourceFile("EXEC-SQL1.COB",35,8)
//01
PRINT-RECORD PIC X(132).
public String getPrintRecord() {
return super.toString(0,132);
}
public
void setPrintRecord(String val) {
super.valueOf(0,132,val);
}
public static FieldFormat printRecordFmt_
= new FieldFormat("printRecord","X(132)");
private CobolFile printfile = new
CobolFile("PRINTER-QPRINT",132);
//@CobolSourceFile("EXEC-SQL1.COB",38,8)
// //77 WORK-DAYS PIC S9(4) BINARY VALUE 253.
private int workDays;
public int getWorkDays() {
return workDays;
}
public
void setWorkDays(int val) {
workDays=(int)
super.normalizeBinary(val,4,true);
}
//@CobolSourceFile("EXEC-SQL1.COB",39,8)
// //77 RAISE-DATE PIC X(11) VALUE
"1982-06-01".
private String raiseDate= new String();
public String getRaiseDate() {
return raiseDate;
}
public
void setRaiseDate(String val) {
raiseDate=val;
}
//@CobolSourceFile("EXEC-SQL1.COB",40,8)
// //77 PERCENTAGE PIC S999V99 PACKED-DECIMAL.
private BigDecimal percentage =
BigDecimal.ZERO;
public BigDecimal getPercentage() {
return percentage;
}
public
void setPercentage(BigDecimal val) {
percentage=val;
}
//@CobolSourceFile("EXEC-SQL1.COB",41,8)
// //77 COMMISSION PIC S99999V99 PACKED-DECIMAL VALUE
2000.00.
private BigDecimal commission =
BigDecimal.ZERO;
public BigDecimal getCommission() {
return commission;
}
public
void setCommission(BigDecimal val) {
commission=val;
}
//***************************************************************
//*
Structure for report 1. *
//***************************************************************
//@CobolSourceFile("EXEC-SQL1.COB",47,8)
// //01 RPT1.
private Rpt1 rpt1 = new Rpt1();
public byte[] getRpt1() {
return rpt1.getBytes();
}
public void setRpt1(byte[] val) {
rpt1.valueOf(val);
}
//***************************************************************
//*
Structure for report 2. *
//***************************************************************
//@CobolSourceFile("EXEC-SQL1.COB",59,8)
// //01 RPT2.
private Rpt2 rpt2 = new Rpt2();
public byte[] getRpt2() {
return rpt2.getBytes();
}
public void setRpt2(byte[] val) {
rpt2.valueOf(val);
}
//*
EXEC SQL
//* INCLUDE SQLCA
//*
END-EXEC.
//@CobolSourceFile("EXEC-SQL1.COB",67,8)
// //01
SQLCA.
private Sqlca sqlca = new Sqlca();
public byte[] getSqlca() {
return sqlca.getBytes();
}
public void setSqlca(byte[] val) {
sqlca.valueOf(val);
}
//@CobolSourceFile("EXEC-SQL1.COB",107,9)
// //77 CODE-EDIT PIC ---99.
private int codeEdit;
public int getCodeEdit() {
return codeEdit;
}
public
void setCodeEdit(int val) {
codeEdit=(int)
super.normalizeBinary(val,4,false);
}
public static FieldFormat codeEditFmt_ =
new FieldFormat("codeEdit","---99");
//***************************************************************
//*
Headers for reports. *
//***************************************************************
//@CobolSourceFile("EXEC-SQL1.COB",113,8)
// //01 RPT1-HEADERS.
private Rpt1Headers rpt1Headers = new
Rpt1Headers();
public byte[] getRpt1Headers() {
return rpt1Headers.getBytes();
}
public void setRpt1Headers(byte[] val) {
rpt1Headers.valueOf(val);
}
//@CobolSourceFile("EXEC-SQL1.COB",123,8)
// //01 RPT2-HEADERS.
private Rpt2Headers rpt2Headers = new
Rpt2Headers();
public byte[] getRpt2Headers() {
return rpt2Headers.getBytes();
}
public void setRpt2Headers(byte[] val) {
rpt2Headers.valueOf(val);
}
//@CobolSourceFile("EXEC-SQL1.COB",138,8)
// //01 RPT1-DATA.
private Rpt1Data rpt1Data = new
Rpt1Data();
public byte[] getRpt1Data() {
return rpt1Data.getBytes();
}
public void setRpt1Data(byte[] val) {
rpt1Data.valueOf(val);
}
//@CobolSourceFile("EXEC-SQL1.COB",147,8)
// //01 RPT2-DATA.
private Rpt2Data rpt2Data = new
Rpt2Data();
public byte[] getRpt2Data() {
return rpt2Data.getBytes();
}
public void setRpt2Data(byte[] val) {
rpt2Data.valueOf(val);
}
public static void main(String[] args) {
Cblex instance_ = new Cblex();
instance_.execute(); System.exit(0);
}
public void execute() {
initialize();
doCobolGotoStart();
}
Paragraph a000Main=new Paragraph(this) {
public CobolMethod run() {
//@CobolSourceFile("EXEC-SQL1.COB",160,12)
// //MOVE
1.04 TO PERCENTAGE
setPercentage(new BigDecimal(1.04));
//@CobolSourceFile("EXEC-SQL1.COB",161,12)
//OPEN OUTPUT PRINTFILE
try {
printfile.openOutput();
} catch(java.io.IOException ioe) {
ioe.printStackTrace();
}
//***************************************************************
//* Update the selected employees by
the new percentage. If an *
//* error occurs during the update,
ROLLBACK the changes, *
//***************************************************************
//@CobolSourceFile("EXEC-SQL1.COB",168,13)
//EXEC SQL
//
WHENEVER SQLERROR
//END-EXEC
if (false) {
//@CobolSourceFile("EXEC-SQL1.COB",169,35)
//GO TO E010-UPDATE-ERROR
return e010UpdateError;
}
//@CobolSourceFile("EXEC-SQL1.COB",171,13)
//EXEC SQL
//
UPDATE CORPDATA/EMPLOYEE
// SET SALARY = SALARY * :PERCENTAGE
// WHERE COMM >= :COMMISSION
//END-EXEC
try {
__dao().prepareStatement("UPDATE
CORPDATA/EMPLOYEE"+
"SET SALARY = SALARY *
?"+
"WHERE COMM >=
?") ;
__dao().getStatement().setBigDecimal(1,getPercentage());
__dao().getStatement().setBigDecimal(2,getCommission());
} catch(SQLException se) {
se.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
System.exit(1); }
//***************************************************************
//*
Commit changes. *
//***************************************************************
//@CobolSourceFile("EXEC-SQL1.COB",181,13)
//EXEC SQL
//
COMMIT
//END-EXEC
try {
__dao().commit();
} catch(SQLException se) {
se.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
System.exit(1); }
//@CobolSourceFile("EXEC-SQL1.COB",185,12)
//EXEC SQL
// WHENEVER SQLERROR
//END-EXEC
if (false) {
//@CobolSourceFile("EXEC-SQL1.COB",186,35)
//GO TO E020-REPORT-ERROR
return e020ReportError;
}
//***************************************************************
//*
Report the updated statistics for each employee receiving *
//*
a raise and the projects that s/he participates in *
//***************************************************************
//***************************************************************
//*
Write out the header for Report 1. *
//***************************************************************
//@CobolSourceFile("EXEC-SQL1.COB",198,12)
//write print-record from
rpt1-header1
// before advancing 2 lines
try {
printfile.write(rpt1Headers.getRpt1Header1());
} catch(java.io.IOException ioe) {
ioe.printStackTrace(); }
//@CobolSourceFile("EXEC-SQL1.COB",200,12)
//write print-record from
rpt1-header2
// before advancing 1 line
try {
printfile.write(rpt1Headers.getRpt1Header2());
} catch(java.io.IOException ioe) {
ioe.printStackTrace(); }
//@CobolSourceFile("EXEC-SQL1.COB",202,13)
//exec sql
//
declare c1 cursor for
// SELECT DISTINCT projno, empprojact.empno,
// lastname||",
"||firstnme ,salary
// from corpdata/empprojact,
corpdata/employee
// where empprojact.empno =employee.empno
and
// comm >= :commission
// order by projno, empno
//end-exec
try {
__dao().declareCursor("C1","SELECT
DISTINCT projno, empprojact.empno,"+
"lastname||\",
\"||firstnme ,salary "+
"from
corpdata/empprojact, corpdata/employee "+
"where empprojact.empno
=employee.empno and"+
"comm >= ?") ;
__dao().getStatement().setBigDecimal(1,getCommission());
} catch(SQLException se) {
se.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
System.exit(1); }
//@CobolSourceFile("EXEC-SQL1.COB",211,13)
//EXEC SQL
//
OPEN C1
//END-EXEC
try {
__dao().executeStatement("C1");
} catch(SQLException se) {
se.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
System.exit(1); }
//@CobolSourceFile("EXEC-SQL1.COB",215,12)
//PERFORM B000-GENERATE-REPORT1 THRU
B010-GENERATE-REPORT1-EXIT
//
UNTIL SQLCODE NOT EQUAL TO ZERO
while(sqlca.getSqlcode() == 0) {
doCobolPerform(b000GenerateReport1,b010GenerateReport1Exit);
};
return doCobolExit();
}
};
Paragraph a100Done1=new Paragraph(this) {
public CobolMethod run() {
//@CobolSourceFile("EXEC-SQL1.COB",218,12)
//EXEC SQL
// CLOSE C1
//END-EXEC
try {
__dao().close("C1");
} catch(SQLException se) {
se.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
System.exit(1); }
//*************************************************************
//*
For all projects ending at a date later than the RAISE- *
//*
DATE ( i.e. those projects potentially affected by the *
//*
salary raises generate a report containing the project *
//*
project number, project name, the count of employees *
//*
participating in the project and the total salary cost *
//*
for the project *
//*************************************************************
//***************************************************************
//*
Write out the header for Report 2. *
//***************************************************************
//@CobolSourceFile("EXEC-SQL1.COB",236,12)
//MOVE SPACES TO PRINT-RECORD
setPrintRecord(printRecordFmt_.format("
"));
//@CobolSourceFile("EXEC-SQL1.COB",237,12)
//WRITE PRINT-RECORD BEFORE
ADVANCING 2 LINES
try {
printfile.write(getPrintRecord().getBytes());
} catch(java.io.IOException ioe) {
ioe.printStackTrace(); }
//@CobolSourceFile("EXEC-SQL1.COB",238,12)
//WRITE PRINT-RECORD FROM
RPT2-HEADER1
// BEFORE ADVANCING 2 LINES
try {
printfile.write(rpt2Headers.getRpt2Header1());
} catch(java.io.IOException ioe) {
ioe.printStackTrace(); }
//@CobolSourceFile("EXEC-SQL1.COB",240,12)
//WRITE PRINT-RECORD FROM
RPT2-HEADER2
// BEFORE ADVANCING 1 LINE
try {
printfile.write(rpt2Headers.getRpt2Header2());
} catch(java.io.IOException ioe) {
ioe.printStackTrace(); }
//@CobolSourceFile("EXEC-SQL1.COB",242,12)
//WRITE PRINT-RECORD FROM
RPT2-HEADER3
// BEFORE ADVANCING 2 LINES
try {
printfile.write(rpt2Headers.getRpt2Header3());
} catch(java.io.IOException ioe) {
ioe.printStackTrace(); }
//@CobolSourceFile("EXEC-SQL1.COB",245,12)
//EXEC SQL
// DECLARE C2 CURSOR FOR
// SELECT EMPPROJACT.PROJNO, PROJNAME,
COUNT(*),
// SUM (
(DAYS(EMENDATE)-DAYS(EMSTDATE)) *
// EMPTIME * DECIMAL((SALARY /
:WORK-DAYS),8,2))
// FROM CORPDATA/EMPPROJACT,
CORPDATA/PROJECT,
// CORPDATA/EMPLOYEE
// WHERE EMPPROJACT.PROJNO=PROJECT.PROJNO
AND
// EMPPROJACT.EMPNO =EMPLOYEE.EMPNO
AND
// PRENDATE > :RAISE-DATE
// GROUP BY EMPPROJACT.PROJNO, PROJNAME
// ORDER BY 1
//END-EXEC
try {
__dao().declareCursor("C2","SELECT
EMPPROJACT.PROJNO, PROJNAME, COUNT(*),"+
"SUM (
(DAYS(EMENDATE)-DAYS(EMSTDATE)) *"+
"EMPTIME *
DECIMAL((SALARY / ?),8,2)) "+
"FROM
CORPDATA/EMPPROJACT, CORPDATA/PROJECT,"+
"CORPDATA/EMPLOYEE
"+
"WHERE
EMPPROJACT.PROJNO=PROJECT.PROJNO AND"+
"EMPPROJACT.EMPNO
=EMPLOYEE.EMPNO AND"+
"PRENDATE > ? "+
"GROUP
BY EMPPROJACT.PROJNO, PROJNAME") ;
__dao().getStatement().setInt(1,getWorkDays());
__dao().getStatement().setString(2,getRaiseDate());
} catch(SQLException se) {
se.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
System.exit(1); }
//@CobolSourceFile("EXEC-SQL1.COB",258,12)
//EXEC SQL
// OPEN C2
//END-EXEC
try {
__dao().executeStatement("C2");
} catch(SQLException se) {
se.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
System.exit(1); }
//@CobolSourceFile("EXEC-SQL1.COB",262,12)
//PERFORM C000-GENERATE-REPORT2 THRU
C010-GENERATE-REPORT2-EXIT
// UNTIL SQLCODE NOT EQUAL TO ZERO
while(sqlca.getSqlcode() == 0) {
doCobolPerform(c000GenerateReport2,c010GenerateReport2Exit);
};
return doCobolExit();
}
};
Paragraph a200Done2=new Paragraph(this) {
public CobolMethod run() {
//@CobolSourceFile("EXEC-SQL1.COB",266,12)
//EXEC SQL
// CLOSE C2
//END-EXEC
try {
__dao().close("C2");
} catch(SQLException se) {
se.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
System.exit(1); }
return doCobolExit();
}
};
Paragraph a900MainExit=new Paragraph(this)
{
public CobolMethod run() {
//***************************************************************
//*
All done.
*
//***************************************************************
//@CobolSourceFile("EXEC-SQL1.COB",275,12)
//CLOSE PRINTFILE
try {
printfile.close();
} catch(java.io.IOException ioe) {
ioe.printStackTrace(); }
//@CobolSourceFile("EXEC-SQL1.COB",276,12)
//STOP RUN
System.exit(0);
return doCobolExit();
}
};
Paragraph b000GenerateReport1=new
Paragraph(this) {
public CobolMethod run() {
//***************************************************************
//*
Fetch and write the rows to PRINTFILE. *
//***************************************************************
//@CobolSourceFile("EXEC-SQL1.COB",282,13)
//EXEC SQL
//
WHENEVER NOT FOUND
//END-EXEC
if (false) {
//@CobolSourceFile("EXEC-SQL1.COB",283,36)
//GO TO A100-DONE1
return a100Done1;
}
//@CobolSourceFile("EXEC-SQL1.COB",285,13)
//EXEC SQL
//
FETCH C1 INTO :RPT2.PROJNO, :RPT1.EMPNO,
// :RPT1.NAME, :RPT1.SALARY
//END-EXEC
try {
__dao().fetchCursor("C1");
if(__dao().resultExists()) {
rpt2.setProjno(__dao().getResult().getString(1));
rpt1.setEmpno(__dao().getResult().getString(2));
rpt1.setName(__dao().getResult().getString(3));
rpt1.setSalary(__dao().getResult().getBigDecimal(4));
}
} catch(SQLException se) {
se.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
System.exit(1); }
//@CobolSourceFile("EXEC-SQL1.COB",289,12)
//MOVE CORRESPONDING RPT1 TO
RPT1-DATA
//* MOVE PROJNO OF RPT1 TO PROJNO OF RPT1-DATA.
//@CobolSourceFile("EXEC-SQL1.COB",291,12)
//WRITE PRINT-RECORD FROM RPT1-DATA
// BEFORE ADVANCING 1 LINE
try {
printfile.write(getRpt1Data());
} catch(java.io.IOException ioe) {
ioe.printStackTrace(); }
return doCobolExit();
}
};
Paragraph b010GenerateReport1Exit=new
Paragraph(this) {
public CobolMethod run() {
return doCobolExit();
}
};
Paragraph c000GenerateReport2=new
Paragraph(this) {
public CobolMethod run() {
//***************************************************************
//*
Fetch and write the rows to PRINTFILE. *
//***************************************************************
//@CobolSourceFile("EXEC-SQL1.COB",302,12)
//EXEC SQL
// WHENEVER NOT FOUND
//END-EXEC
if (false) {
//@CobolSourceFile("EXEC-SQL1.COB",303,36)
//GO TO A200-DONE2
return a200Done2;
}
//@CobolSourceFile("EXEC-SQL1.COB",305,13)
//EXEC SQL
//
FETCH C2 INTO :RPT2
//END-EXEC
try {
__dao().fetchCursor("C2");
if(__dao().resultExists()) {
setRpt2(__dao().getResult().getBytes(1));
}
} catch(SQLException se) {
se.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
System.exit(1); }
//@CobolSourceFile("EXEC-SQL1.COB",308,12)
//MOVE CORRESPONDING RPT2 TO
RPT2-DATA
//@CobolSourceFile("EXEC-SQL1.COB",309,12)
//WRITE PRINT-RECORD FROM RPT2-DATA
// BEFORE ADVANCING 1 LINE
try {
printfile.write(getRpt2Data());
} catch(java.io.IOException ioe) {
ioe.printStackTrace(); }
return doCobolExit();
}
};
Paragraph c010GenerateReport2Exit=new
Paragraph(this) {
public CobolMethod run() {
return doCobolExit();
}
};
Paragraph e010UpdateError=new
Paragraph(this) {
public CobolMethod run() {
//***************************************************************
//*
Error occured while updating table.
Inform user and *
//*
rollback changes. *
//***************************************************************
//@CobolSourceFile("EXEC-SQL1.COB",321,13)
//EXEC SQL
//
WHENEVER SQLERROR
//END-EXEC
if (false) {
//@CobolSourceFile("EXEC-SQL1.COB",322,35)
//CONTINUE
}
//@CobolSourceFile("EXEC-SQL1.COB",324,12)
//MOVE SQLCODE TO CODE-EDIT
setCodeEdit(sqlca.getSqlcode());
//@CobolSourceFile("EXEC-SQL1.COB",325,12)
//STRING "*** ERROR Occurred
while updating table. SQLCODE="
// CODE-EDIT DELIMITED BY SIZE INTO
PRINT-RECORD
setPrintRecord("*** ERROR
Occurred while updating table.
SQLCODE="+codeEditFmt_.format(getCodeEdit()));
//@CobolSourceFile("EXEC-SQL1.COB",327,12)
//WRITE PRINT-RECORD
try {
printfile.write(getPrintRecord().getBytes());
} catch(java.io.IOException ioe) {
ioe.printStackTrace(); }
//@CobolSourceFile("EXEC-SQL1.COB",328,13)
//EXEC SQL
//
ROLLBACK
//END-EXEC
//@CobolSourceFile("EXEC-SQL1.COB",331,12)
//STOP RUN
System.exit(0);
return doCobolExit();
}
};
Paragraph e020ReportError=new
Paragraph(this) {
public CobolMethod run() {
//***************************************************************
//*
Error occured while generating reports.
Inform user and *
//*
exit.
*
//***************************************************************
//@CobolSourceFile("EXEC-SQL1.COB",339,12)
//MOVE SQLCODE TO CODE-EDIT
setCodeEdit(sqlca.getSqlcode());
//@CobolSourceFile("EXEC-SQL1.COB",340,12)
//STRING "*** ERROR Occurred
while generating reports. SQLCODE="
CODE-EDIT DELIMITED BY SIZE INTO PRINT-RECORD
setPrintRecord("*** ERROR
Occurred while generating reports.
SQLCODE="+codeEditFmt_.format(getCodeEdit()));
//@CobolSourceFile("EXEC-SQL1.COB",341,12)
//WRITE PRINT-RECORD
try {
printfile.write(getPrintRecord().getBytes());
} catch(java.io.IOException ioe) {
ioe.printStackTrace(); }
//@CobolSourceFile("EXEC-SQL1.COB",342,12)
//STOP RUN
System.exit(0);
return doCobolExit();
}
};
private Cblex() {
}
private void initialize() {
setWorkDays(253);
setRaiseDate("1982-06-01");
setCommission(new
BigDecimal(2000.00));
rpt1.initialize();
rpt2.initialize();
sqlca.initialize();
rpt1Headers.initialize();
rpt2Headers.initialize();
rpt1Data.initialize();
rpt2Data.initialize();
}
}