× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I have a developer who is running this JAVA script as an SQL stored
procedure. It can be called hundreds of times for one request. What
exactly does it do? I am not a JAVA programmer and this causes our
iSeries to have hundreds of JVMs active, one for each web user. I am
wondering if a simple RPG or C program can do the same thing without
starting up a JVM.



import java.text.DecimalFormat;



import COM.ibm.db2.app.StoredProc;



/*

*

* javac -verbose -d /qibm/userdata/os400/sqllib/function
/home/JavaSource/DocKeyUDF.java

*

*/



/**

* @author chrisw

*

* TODO To change the template for this generated type comment go to

* Window - Preferences - Java - Code Style - Code Templates

*/

public class DocKeyUDF extends StoredProc {



public void generateDocKey(

String storeID,

String sessionID,

String newDocKey)
throws Exception {



String dk =
DocKey_V2(storeID,sessionID);

set(3,dk);

return;

}



private String DocKey_V2(String vID, String sessionID) {

String sTmp;

String DocKey_V2 = "";

String sessionIDNumericOnly = "";



int i = 0;

for (i = 0; i <= sessionID.length();
i++) {

try {

int x =
Integer.parseInt(sessionID.substring(i, i + 1));


sessionIDNumericOnly =


sessionIDNumericOnly + Integer.toString(x);

} catch (Exception e) {

}

}

if (sessionIDNumericOnly.length() < 6) {

for
(i=sessionIDNumericOnly.length(); i <= 6; i++) {


sessionIDNumericOnly =


sessionIDNumericOnly + "9";

}

}



try {

int length = 0;

int position = 0;

int nID = 0;



try {

nID =
Integer.valueOf(vID).intValue() * 3;

} catch (Exception e) {

nID = 0;

}



DecimalFormat df = new
DecimalFormat("00");

double sessionLength =
sessionIDNumericOnly.length();

String storeString =
Integer.toString(nID);

double storeIDLength =
storeString.length();



sTmp = "2" +
df.format(sessionLength) + df.format(storeIDLength);



for (position = 0;

length
<= (sessionLength + storeIDLength);


length++) {

if
(!(position >= sessionLength)) {


sTmp =


sTmp


+ sessionIDNumericOnly.substring(


position,


position + 1);

}

if
(!(position >= storeIDLength)) {


sTmp = sTmp + storeString.substring(position, position + 1);

}

position
= position + 1;



}



java.util.Calendar c =

new
java.util.GregorianCalendar(1899, 11, 30);

long millis =
c.getTimeInMillis();

long milliseconds =
System.currentTimeMillis();

//long newDate =
milliseconds - millis + 600000;

long newDate =
milliseconds - millis;

long dateInVBFormat =
(newDate / 864000);

sTmp = sTmp +
Long.toString(dateInVBFormat);

DocKey_V2 =
MakeMOD10(sTmp);

} catch (Exception _e_) {

DocKey_V2 = null;

}

return DocKey_V2;

}



private boolean IsMOD10(String sValue) {

boolean IsMOD10 = false;

try {

int nDx = 0;

int nTotal = 0;

int nVal = 0;



nTotal = 0;

for (nDx = 0; nDx <
sValue.length(); nDx++) {

if
(sValue.substring(nDx, nDx + 1).compareTo("0") < 0) {


char c = sValue.charAt(nDx);


nVal = c;

} else {


if (sValue.substring(nDx, nDx + 1).compareTo("9") > 0) {


char c = sValue.charAt(nDx);


nVal = c;


} else {


nVal =


Integer


.valueOf(sValue.substring(nDx, nDx + 1))


.intValue();


}

}

nTotal =
nTotal + nVal;

}

IsMOD10 = (nTotal % 10)
== 0;

} catch (Exception e) {


System.out.println("Error with MOD10");

return false;

}

return IsMOD10;

}



private String MakeMOD10(String sValue) {

String MakeMOD10 = "";

try {

int nDx = 0;



for (nDx = 0; nDx <= 9;
nDx++) {

if
(IsMOD10(sValue + nDx)) {


break;

}

}

MakeMOD10 = sValue +
nDx;

} catch (Exception e) {


System.out.println("Error with MOD10");

}

return MakeMOD10;

}

}





Chris Bipes
Director of Information Services
CrossCheck, Inc.






As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.