× 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.



DocKey is this:
2xxyyababababababababcccczzzzzzzzzzzm

where 2 is constant, xx is the length (digits only) of the session id
and yy is the length of (the storeid * 3)
a are successive characters (digits only) from the session id
b are successive characters from (the storeid * 3)
c is the rest of the characters from session id (digits only) or (the
storeid * 3) after the other one is done
z is the number of tenths of days since Nov 30 , 1899 (however long that
is)
m is a modulus 10 self check digit

If there are fewer than 6 digits in the session id, 9's are added to
make 6 digits.
If there are fewer characters in the session id (digits only) or (the
storeid * 3) the rest of the characters from the other are used
sequentially until both are exhausted.


-----Original Message-----
From: java400-l-bounces@xxxxxxxxxxxx
[mailto:java400-l-bounces@xxxxxxxxxxxx] On Behalf Of Chris Bipes
Sent: Friday, March 19, 2010 1:09 PM
To: java400-l@xxxxxxxxxxxx
Subject: Can someone translate

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.





--
This is the Java Programming on and around the iSeries / AS400
(JAVA400-L) mailing list To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at http://archive.midrange.com/java400-l.




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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.