Last active
July 14, 2016 16:50
-
-
Save greghelton/9cccf6dec4a03831fa8f8177f1f77041 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.ibm.as400.access.*; | |
public class CallSrvPgm { | |
String firstName; | |
String lastName; | |
int ssn; | |
void getNextBySocialSecurityNumber(int ssn) throws Exception { | |
AS400 as400 = new AS400("machine", "userid", "password"); | |
ServiceProgramCall pgm = new ServiceProgramCall(as400); | |
ProgramParameter[] parameters = new ProgramParameter[3]; | |
AS400Bin4 bin4 = new AS400Bin4(); | |
byte[] ssnBytes = bin4.toBytes(ssn); | |
parameters[0] = new ProgramParameter(ProgramParameter.PASS_BY_REFERENCE, ssnBytes, 9); | |
parameters[1] = new ProgramParameter(ProgramParameter.PASS_BY_REFERENCE, 20); | |
parameters[2] = new ProgramParameter(ProgramParameter.PASS_BY_REFERENCE, 20); | |
pgm.setProgram("/QSYS.LIB/GAH285.LIB/CALLSRVPGM.SRVPGM", parameters); | |
pgm.setProcedureName("getNextEmployeeBySSN"); | |
if (pgm.run()) { | |
this.ssn = bin4.toInt(parameters[0].getOutputData()); | |
AS400Text text400 = new AS400Text(20); | |
this.firstName = text400.toObject(parameters[1].getOutputData()).toString(); | |
this.lastName = text400.toObject(parameters[2].getOutputData()).toString(); | |
} | |
} | |
public static void main(String[] args) throws Exception { | |
CallSrvPgm csp = new CallSrvPgm(); | |
csp.ssn = 0; | |
do { | |
csp.getNextBySocialSecurityNumber(csp.ssn); | |
System.out.println("Name for ssn:" + csp.ssn + " is " + csp.firstName + " " + csp.lastName); | |
} while (csp.ssn > 0); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ctl-opt nomain option(*srcstmt:*nodebugio:*nounref); | |
// CRTSRVPGM SRVPGM(GAH285/CALLSRVPGM) MODULE(GAH285/CALLSRVPGM) EXPORT(*ALL) | |
dcl-f EMPLOYEE usage(*input) keyed extfile('GAH285/EMPLOYEE'); | |
dcl-pr getNextEmployeeBySSN extproc(*DCLCASE); | |
dcl-parm socialSecNumber INT(10); | |
dcl-parm firstName CHAR(20); | |
dcl-parm lastName CHAR(20); | |
end-pr; | |
dcl-proc getNextEmployeeBySSN EXPORT; | |
dcl-pi *N; | |
dcl-parm socialSecNumber INT(10); | |
dcl-parm firstName CHAR(20); | |
dcl-parm lastName CHAR(20); | |
end-pi; | |
EmpSSN = SocialSecNumber; | |
setgt EmpSSN Employee; | |
read Employee; | |
if %EOF(Employee); | |
socialSecNumber = -1; | |
else; | |
socialSecNumber = EmpSsn; | |
firstName = EmpFirst; | |
lastName = EmpLast; | |
endif; | |
end-proc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table gah285.Employee (EmpSsn Integer PRIMARY KEY, | |
EmpFirst CHAR(20), | |
EmpLast CHAR(20)) rcdfmt REMPLOYEE | |
insert into gah285.employee values(100100101, 'Greg', 'Helton') | |
insert into gah285.employee values(100100102, 'Bill', 'Gates' ) | |
insert into gah285.employee values(100100107, 'Steve', 'Jobs' ) | |
insert into gah285.employee values(100100112, 'Thomas','Jefferson') | |
insert into gah285.employee values(100100115, 'Betsy','Ross') | |
insert into gah285.employee values(100100121, 'Abigail', 'Adams') | |
insert into gah285.employee values(100100126, 'George', 'Washington') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\Users\gah285\dev\src\java>javac -cp .;jt400.jar CallSrvPgm.java | |
C:\Users\gah285\dev\src\java>java -cp .;jt400.jar CallSrvPgm | |
Name for ssn:100100101 is Greg Helton | |
Name for ssn:100100102 is Bill Gates | |
Name for ssn:100100107 is Steve Jobs | |
Name for ssn:100100112 is Thomas Jefferson | |
Name for ssn:100100115 is Betsy Ross | |
Name for ssn:100100121 is Abigail Adams | |
Name for ssn:100100126 is George Washington | |
Name for ssn:-1 is | |
C:\Users\gah285\dev\src\java> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment