Feedback
Did this article resolve your question/issue?

   

Article

How to convert ABL database trigger to Java SQL stored procedure?

« Go Back

Information

 
TitleHow to convert ABL database trigger to Java SQL stored procedure?
URL NameHow-to-convert-ABL-database-trigger-to-Java-SQL-stored-procedure
Article Number000110547
EnvironmentProduct: OpenEdge
Version: 11.6.3
OS: All Supported Operating Systems
Question/Problem Description
How to convert ABL database trigger to Java SQL stored procedure?
How to convert  4GL trigger to SQL stored procedure?
How to call SQL stored procedure from mobile app which cannot read 4GL trigger?
 
Steps to Reproduce
Clarifying Information
Sample code for 4GL trigger :
TRIGGER PROCEDURE FOR CREATE OF cdw.cust. 
DEF VAR conumber AS CHAR NO-UNDO. 
IF CONNECTED("POS") THEN 
FIND pos.system WHERE pos.system.rec EQ 1 NO-LOCK NO-ERROR. 
conumber = IF AVAILABLE pos.system THEN STRING(pos.system.co-number,'9999') ELSE '0001'. 

ASSIGN cdw.cust.systemid = STRING(YEAR(TODAY),"9999") 
+ STRING(conumber,'9999') 
+ STRING(NEXT-VALUE(Next-cust-num,cdw),"99999999").

 
Error Message
Defect Number
Enhancement Number
Cause
Resolution
Using sqlexp run the following SQL stored procedure :

Sample code for Procedure and Trigger : 

Steps to run procedure and Trigger :

1.Create two table sptr and sptr2.

2. Start the database using the following command:
     proserve sports2000 -H hostname -S portnumber

3. sqlexp sports2000 -H hostname -S portnumber

4. Run the procedure using following command :
   @run procedure_filename.sql;

5. Run the Trigger using following command :
   @run trigger_filename.sql



PROCEDURE :
DROP PROCEDURE insert_sptr;
COMMIT;
CREATE PROCEDURE insert_sptr( )
BEGIN
SQLIStatement insert_stmt = new SQLIStatement  ("INSERT INTO pub.sptr values ('b','b',20)") ;
insert_stmt.execute();
END
COMMIT;

TRIGGER :
DROP TRIGGER test_sptr;
COMMIT;
CREATE TRIGGER  test_sptr AFTER INSERT on pub.sptr
REFERENCING  NEWROW
FOR EACH ROW 
IMPORT 
	import java.sql.*;
	import java.util.Calendar;
	import java.io.*;
BEGIN
	try {
		String myStr;
		Calendar now = Calendar.getInstance();
		Integer icompnumber;
		Integer iscurrvalue;
	         SQLCursor compcursor = new SQLCursor ("SELECT col3, pub.secsptr.CURRVAL FROM pub.sptr WHERE col1 = 'b'" ) ;
        	compcursor.open ();
		compcursor.fetch ();

   		icompnumber = (Integer) compcursor.getValue (1, INTEGER);
		iscurrvalue = (Integer) compcursor.getValue (2, INTEGER);
		compcursor.close();
		SQLIStatement  insert_stmt = new SQLIStatement (" insert into pub.sptr2 values (1)");
		insert_stmt.execute();
		myStr = "test : " + 9 + " " + now.get(Calendar.YEAR) + " " + Integer.toString(88) + " " + Integer.toString(icompnumber) + " " + Integer.toString(iscurrvalue);
		
		FileWriter mystream= new FileWriter("trigger.log",true);
            	mystream.write(myStr);
            	mystream.close();        
		


	}
	catch(Exception e)
  		{
			System.err.println("Caught Exception: " + e.getMessage());
		}

END;
commit;


 
Workaround
Notes
Last Modified Date1/2/2021 7:19 PM
Attachment 
Files
Disclaimer The origins of the information on this site may be internal or external to Progress Software Corporation (“Progress”). Progress Software Corporation makes all reasonable efforts to verify this information. However, the information provided is for your information only. Progress Software Corporation makes no explicit or implied claims to the validity of this information.

Any sample code provided on this site is not supported under any Progress support program or service. The sample code is provided on an "AS IS" basis. Progress makes no warranties, express or implied, and disclaims all implied warranties including, without limitation, the implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample code is borne by the user. In no event shall Progress, its employees, or anyone else involved in the creation, production, or delivery of the code be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample code, even if Progress has been advised of the possibility of such damages.