/* #####################################################
Description: Common application Package for all custom method's
####################################################### */
class ReportBase
method ReportBase();
method GetFieldValue(&Record_Name As string, &Rec_Field As string, &Key1 As string, &Key2 As string, &Key3 As string, &Key4 As string, &Key5 As string) Returns string;
method getjobfieldvalue(&Rec_Field As string, &Key1 As string) Returns string;
method GetName(&Emplid As string) Returns string;
method println_to_stdout(&message As string);
method println_to_stderr(&message As string);
method redirect_stderr(&fileName As string);
method redirect_stdout(&fileName As string);
method FIND_SPECIAL_CHARS(&VALUE As string) Returns boolean;
method Validate_Name(&Name As string) Returns boolean;
end-class;
method ReportBase
end-method;
method getjobfieldvalue
/+ &Rec_Field as String, +/
/+ &Key1 as String +/
/+ Returns String +/
Local string &fldvalue;
SQLExec("SELECT " | &Rec_Field | " FROM PS_JOB A WHERE A.EFFDT =(SELECT MAX(A_ED.EFFDT) FROM PS_JOB A_ED WHERE A.EMPLID = A_ED.EMPLID AND A.EMPL_RCD = A_ED.EMPL_RCD AND A_ED.EFFDT <= SUBSTRING(CONVERT(CHAR,GETDATE(),121), 1, 10)) AND A.EFFSEQ =(SELECT MAX(A_ES.EFFSEQ) FROM PS_JOB A_ES WHERE A.EMPLID = A_ES.EMPLID AND A.EMPL_RCD = A_ES.EMPL_RCD AND A.EFFDT = A_ES.EFFDT) AND A.EMPLID=:1", &Key1, &fldvalue);
Return &fldvalue;
end-method;
/* GetFieldValue method will take record name,field name,key values as input and returns the specified field value */
method GetFieldValue
/+ &Record_Name as String, +/
/+ &Rec_Field as String, +/
/+ &Key1 as String, +/
/+ &Key2 as String, +/
/+ &Key3 as String, +/
/+ &Key4 as String, +/
/+ &Key5 as String +/
/+ Returns String +/
Local Record &RCD = CreateRecord(@("Record." | &Record_Name));
Local string &str = "";
Local string &Rec_Name = "";
Local string &Field_Name = "";
Local number &Counter = 0;
Local string &Descr = "";;
Local string &Cnt = "";
Local string &SqlExec_Eff, &SqlExec_No_Eff;
Local boolean &flag;
Local string &Where = "";
Local string &Eff_SQL = "SELECT %firstrows(1) A." | &Rec_Field | " FROM %Table(:1) A WHERE %EffDtCheck(:1 B, A, %CurrentDateIn) /*AND A.EFF_STATUS = 'A'*/";
Local string &No_Eff_SQL = "SELECT %firstrows(1) A." | &Rec_Field | " FROM %Table(:1) A WHERE 1=1 ";
Local SQL &SQL1 = CreateSQL("SELECT DISTINCT RECNAME,FIELDNAME,FIELDNUM+1 FROM PSRECFIELD WHERE RECNAME=:1 AND USEEDIT & 1 > 0 ORDER BY 3", &Record_Name);
While &SQL1.Fetch(&Rec_Name, &Field_Name, &Cnt)
If &Field_Name = "EFFDT" Then
&flag = True;
Else
&flag = False;
&str = " AND " | &Field_Name | "=:" | &Cnt;
&Where = &Where | &str;
&Counter = &Counter + 1;
End-If;
End-While;
Local string &Final_Eff_SQL = &Eff_SQL | &Where;
Local string &Final_No_Eff_SQL = &No_Eff_SQL | &Where;
Evaluate &Counter
When 1
If &flag Then
SQLExec(&Final_Eff_SQL, &RCD, &Key1, &Descr);
Else
SQLExec(&Final_No_Eff_SQL, &RCD, &Key1, &Descr);
End-If;
Break;
When 2
If &flag Then
SQLExec(&Final_Eff_SQL, &RCD, &Key1, &Key2, &Descr);
Else
SQLExec(&Final_No_Eff_SQL, &RCD, &Key1, &Key2, &Descr);
End-If;
Break;
When 3
If &flag Then
SQLExec(&Final_Eff_SQL, &RCD, &Key1, &Key2, &Key3, &Descr);
Else
SQLExec(&Final_No_Eff_SQL, &RCD, &Key1, &Key2, &Key3, &Descr);
End-If;
Break;
When 4
If &flag Then
SQLExec(&Final_Eff_SQL, &RCD, &Key1, &Key2, &Key3, &Key4, &Descr);
Else
SQLExec(&Final_No_Eff_SQL, &RCD, &Key1, &Key2, &Key3, &Key4, &Descr);
End-If;
Break;
When 5
If &flag Then
SQLExec(&Final_Eff_SQL, &RCD, &Key1, &Key2, &Key3, &Key4, &Key5, &Descr);
Else
SQLExec(&Final_No_Eff_SQL, &RCD, &Key1, &Key2, &Key3, &Key4, &Key5, &Descr);
End-If;
Break;
When-Other
Error "Unexpected Parameters Passed"
End-Evaluate;
Return &Descr;
end-method;
method GetName
/+ &Emplid as String +/
/+ Returns String +/
Local string &Name;
SQLExec("SELECT FIRST_NAME + ' ' + LAST_NAME FROM PS_PERSON_NAME WHERE EMPLID = :1", &Emplid, &Name);
Return &Name
end-method;
/* * Print a line of text to stdout */
method println_to_stdout
/+ &message as String +/
Local JavaObject &jSystem = GetJavaClass("java.lang.System");
Local JavaObject &jOutStream = &jSystem.out;
Local JavaObject &jCls = GetJavaClass("java.lang.Class");
Local JavaObject &jStringClass = &jCls.forName("java.lang.String");
Local JavaObject &jPrintStreamCls = &jOutStream.getClass();
Local JavaObject &jPrintlnArgTypes = CreateJavaObject("java.lang.Class[]", &jStringClass);
Local JavaObject &jPrintlnMethod = &jPrintStreamCls.getDeclaredMethod("println", &jPrintlnArgTypes);
&jPrintlnMethod.invoke(&jOutStream, CreateJavaObject("java.lang.Object[]", &message));
rem ** I didn't find flushing necessary, but here is where you would flush the buffer if desired;
&jOutStream.flush();
end-method;
/* * Print a line of text to stderr */
method println_to_stderr
/+ &message as String +/
Local JavaObject &jSystem = GetJavaClass("java.lang.System");
Local JavaObject &jOutStream = &jSystem.err;
Local JavaObject &jCls = GetJavaClass("java.lang.Class");
Local JavaObject &jStringClass = &jCls.forName("java.lang.String");
Local JavaObject &jPrintStreamCls = &jOutStream.getClass();
Local JavaObject &jPrintlnArgTypes = CreateJavaObject("java.lang.Class[]", &jStringClass);
Local JavaObject &jPrintlnMethod = &jPrintStreamCls.getDeclaredMethod("println", &jPrintlnArgTypes);
&jPrintlnMethod.invoke(&jOutStream, CreateJavaObject("java.lang.Object[]", &message));
&jOutStream.flush();
end-method;
rem If you want to use the PrintStream.print
rem ** I didn't find flushing necessary, but here is where you would flush the buffer if desired;
/* * Redirect stdout to file */
method redirect_stdout
/+ &fileName as String +/
Local JavaObject &jSystem = GetJavaClass("java.lang.System");
Local JavaObject &jfos_out = CreateJavaObject("java.io.FileOutputStream", &fileName, True);
Local JavaObject &jps_out = CreateJavaObject("java.io.PrintStream", &jfos_out, True);
&jSystem.setOut(&jps_out);
end-method;
/* * Redirect stderr to file */
method redirect_stderr
/+ &fileName as String +/
Local JavaObject &jSystem = GetJavaClass("java.lang.System");
Local JavaObject &jfos_out = CreateJavaObject("java.io.FileOutputStream", &fileName, True);
Local JavaObject &jps_out = CreateJavaObject("java.io.PrintStream", &jfos_out, True);
&jSystem.setErr(&jps_out);
end-method;
method FIND_SPECIAL_CHARS
/+ &VALUE as String +/
/+ Returns Boolean +/
Local number &LENGTH = Len(&VALUE);
Local number &I;
For &I = 1 To &LENGTH
Local number &pos = &I;
Local string &char = Substring(&VALUE, &I, 1);
Local any &ASCII = Code(&char);
Evaluate &ASCII
When > 127
Return True;
Break;
When = 13
When = 10
Break;
When < 32
Return True;
Break;
End-Evaluate;
End-For;
Return False;
end-method;
method Validate_Name
/+ &Name as String +/
/+ Returns Boolean +/
Local number &len = Len(&Name);
Local number &I;
Local boolean &rflag = True;
For &I = 1 To &len
Local number &pos = &I;
Local string &char = Substring(&Name, &I, 1);
Local any &ASCII = Code(&char);
If (&ASCII >= 65 And
&ASCII <= 90) Or
(&ASCII >= 97 And
&ASCII <= 122) Then
Else
&rflag = False;
End-If;
End-For;
Return &rflag;
end-method;
Description: Common application Package for all custom method's
####################################################### */
class ReportBase
method ReportBase();
method GetFieldValue(&Record_Name As string, &Rec_Field As string, &Key1 As string, &Key2 As string, &Key3 As string, &Key4 As string, &Key5 As string) Returns string;
method getjobfieldvalue(&Rec_Field As string, &Key1 As string) Returns string;
method GetName(&Emplid As string) Returns string;
method println_to_stdout(&message As string);
method println_to_stderr(&message As string);
method redirect_stderr(&fileName As string);
method redirect_stdout(&fileName As string);
method FIND_SPECIAL_CHARS(&VALUE As string) Returns boolean;
method Validate_Name(&Name As string) Returns boolean;
end-class;
method ReportBase
end-method;
method getjobfieldvalue
/+ &Rec_Field as String, +/
/+ &Key1 as String +/
/+ Returns String +/
Local string &fldvalue;
SQLExec("SELECT " | &Rec_Field | " FROM PS_JOB A WHERE A.EFFDT =(SELECT MAX(A_ED.EFFDT) FROM PS_JOB A_ED WHERE A.EMPLID = A_ED.EMPLID AND A.EMPL_RCD = A_ED.EMPL_RCD AND A_ED.EFFDT <= SUBSTRING(CONVERT(CHAR,GETDATE(),121), 1, 10)) AND A.EFFSEQ =(SELECT MAX(A_ES.EFFSEQ) FROM PS_JOB A_ES WHERE A.EMPLID = A_ES.EMPLID AND A.EMPL_RCD = A_ES.EMPL_RCD AND A.EFFDT = A_ES.EFFDT) AND A.EMPLID=:1", &Key1, &fldvalue);
Return &fldvalue;
end-method;
/* GetFieldValue method will take record name,field name,key values as input and returns the specified field value */
method GetFieldValue
/+ &Record_Name as String, +/
/+ &Rec_Field as String, +/
/+ &Key1 as String, +/
/+ &Key2 as String, +/
/+ &Key3 as String, +/
/+ &Key4 as String, +/
/+ &Key5 as String +/
/+ Returns String +/
Local Record &RCD = CreateRecord(@("Record." | &Record_Name));
Local string &str = "";
Local string &Rec_Name = "";
Local string &Field_Name = "";
Local number &Counter = 0;
Local string &Descr = "";;
Local string &Cnt = "";
Local string &SqlExec_Eff, &SqlExec_No_Eff;
Local boolean &flag;
Local string &Where = "";
Local string &Eff_SQL = "SELECT %firstrows(1) A." | &Rec_Field | " FROM %Table(:1) A WHERE %EffDtCheck(:1 B, A, %CurrentDateIn) /*AND A.EFF_STATUS = 'A'*/";
Local string &No_Eff_SQL = "SELECT %firstrows(1) A." | &Rec_Field | " FROM %Table(:1) A WHERE 1=1 ";
Local SQL &SQL1 = CreateSQL("SELECT DISTINCT RECNAME,FIELDNAME,FIELDNUM+1 FROM PSRECFIELD WHERE RECNAME=:1 AND USEEDIT & 1 > 0 ORDER BY 3", &Record_Name);
While &SQL1.Fetch(&Rec_Name, &Field_Name, &Cnt)
If &Field_Name = "EFFDT" Then
&flag = True;
Else
&flag = False;
&str = " AND " | &Field_Name | "=:" | &Cnt;
&Where = &Where | &str;
&Counter = &Counter + 1;
End-If;
End-While;
Local string &Final_Eff_SQL = &Eff_SQL | &Where;
Local string &Final_No_Eff_SQL = &No_Eff_SQL | &Where;
Evaluate &Counter
When 1
If &flag Then
SQLExec(&Final_Eff_SQL, &RCD, &Key1, &Descr);
Else
SQLExec(&Final_No_Eff_SQL, &RCD, &Key1, &Descr);
End-If;
Break;
When 2
If &flag Then
SQLExec(&Final_Eff_SQL, &RCD, &Key1, &Key2, &Descr);
Else
SQLExec(&Final_No_Eff_SQL, &RCD, &Key1, &Key2, &Descr);
End-If;
Break;
When 3
If &flag Then
SQLExec(&Final_Eff_SQL, &RCD, &Key1, &Key2, &Key3, &Descr);
Else
SQLExec(&Final_No_Eff_SQL, &RCD, &Key1, &Key2, &Key3, &Descr);
End-If;
Break;
When 4
If &flag Then
SQLExec(&Final_Eff_SQL, &RCD, &Key1, &Key2, &Key3, &Key4, &Descr);
Else
SQLExec(&Final_No_Eff_SQL, &RCD, &Key1, &Key2, &Key3, &Key4, &Descr);
End-If;
Break;
When 5
If &flag Then
SQLExec(&Final_Eff_SQL, &RCD, &Key1, &Key2, &Key3, &Key4, &Key5, &Descr);
Else
SQLExec(&Final_No_Eff_SQL, &RCD, &Key1, &Key2, &Key3, &Key4, &Key5, &Descr);
End-If;
Break;
When-Other
Error "Unexpected Parameters Passed"
End-Evaluate;
Return &Descr;
end-method;
method GetName
/+ &Emplid as String +/
/+ Returns String +/
Local string &Name;
SQLExec("SELECT FIRST_NAME + ' ' + LAST_NAME FROM PS_PERSON_NAME WHERE EMPLID = :1", &Emplid, &Name);
Return &Name
end-method;
/* * Print a line of text to stdout */
method println_to_stdout
/+ &message as String +/
Local JavaObject &jSystem = GetJavaClass("java.lang.System");
Local JavaObject &jOutStream = &jSystem.out;
Local JavaObject &jCls = GetJavaClass("java.lang.Class");
Local JavaObject &jStringClass = &jCls.forName("java.lang.String");
Local JavaObject &jPrintStreamCls = &jOutStream.getClass();
Local JavaObject &jPrintlnArgTypes = CreateJavaObject("java.lang.Class[]", &jStringClass);
Local JavaObject &jPrintlnMethod = &jPrintStreamCls.getDeclaredMethod("println", &jPrintlnArgTypes);
&jPrintlnMethod.invoke(&jOutStream, CreateJavaObject("java.lang.Object[]", &message));
rem ** I didn't find flushing necessary, but here is where you would flush the buffer if desired;
&jOutStream.flush();
end-method;
/* * Print a line of text to stderr */
method println_to_stderr
/+ &message as String +/
Local JavaObject &jSystem = GetJavaClass("java.lang.System");
Local JavaObject &jOutStream = &jSystem.err;
Local JavaObject &jCls = GetJavaClass("java.lang.Class");
Local JavaObject &jStringClass = &jCls.forName("java.lang.String");
Local JavaObject &jPrintStreamCls = &jOutStream.getClass();
Local JavaObject &jPrintlnArgTypes = CreateJavaObject("java.lang.Class[]", &jStringClass);
Local JavaObject &jPrintlnMethod = &jPrintStreamCls.getDeclaredMethod("println", &jPrintlnArgTypes);
&jPrintlnMethod.invoke(&jOutStream, CreateJavaObject("java.lang.Object[]", &message));
&jOutStream.flush();
end-method;
rem If you want to use the PrintStream.print
rem ** I didn't find flushing necessary, but here is where you would flush the buffer if desired;
/* * Redirect stdout to file */
method redirect_stdout
/+ &fileName as String +/
Local JavaObject &jSystem = GetJavaClass("java.lang.System");
Local JavaObject &jfos_out = CreateJavaObject("java.io.FileOutputStream", &fileName, True);
Local JavaObject &jps_out = CreateJavaObject("java.io.PrintStream", &jfos_out, True);
&jSystem.setOut(&jps_out);
end-method;
/* * Redirect stderr to file */
method redirect_stderr
/+ &fileName as String +/
Local JavaObject &jSystem = GetJavaClass("java.lang.System");
Local JavaObject &jfos_out = CreateJavaObject("java.io.FileOutputStream", &fileName, True);
Local JavaObject &jps_out = CreateJavaObject("java.io.PrintStream", &jfos_out, True);
&jSystem.setErr(&jps_out);
end-method;
method FIND_SPECIAL_CHARS
/+ &VALUE as String +/
/+ Returns Boolean +/
Local number &LENGTH = Len(&VALUE);
Local number &I;
For &I = 1 To &LENGTH
Local number &pos = &I;
Local string &char = Substring(&VALUE, &I, 1);
Local any &ASCII = Code(&char);
Evaluate &ASCII
When > 127
Return True;
Break;
When = 13
When = 10
Break;
When < 32
Return True;
Break;
End-Evaluate;
End-For;
Return False;
end-method;
method Validate_Name
/+ &Name as String +/
/+ Returns Boolean +/
Local number &len = Len(&Name);
Local number &I;
Local boolean &rflag = True;
For &I = 1 To &len
Local number &pos = &I;
Local string &char = Substring(&Name, &I, 1);
Local any &ASCII = Code(&char);
If (&ASCII >= 65 And
&ASCII <= 90) Or
(&ASCII >= 97 And
&ASCII <= 122) Then
Else
&rflag = False;
End-If;
End-For;
Return &rflag;
end-method;
No comments:
Post a Comment