RPG to MySQL Migration

SQLines tools can help you convert IBM RPG routines and programs to MySQL stored procedures and functions.

./sqlines -sl=rpg -s=db2 -t=mysql -in=file.rpg

Migration Reference

Language Elements

Converting language elements:

RPG MySQL
1 // comment text Single line comment -- comment text
2 string + string2 + … String concatenation CONCAT(string, string2, …)

Data Types

Converting data types:

RPG MySQL
1 30A Fixed-length character string CHAR(30)
2 30A VARYING Variable-length character string VARCHAR(30)
3 5I Integer number INT
4 10P 0 Fixed-point number DECIMAL(10, 0)

Built-in Functions

Converting string functions:

RPG MySQL
1 %SCAN(substr : string) Get position of substring LOCATE(substr, string)
2 %SUBST(string, start, len) Get a substring SUBSTR(string, start, len)
3 %TRIM(string [: chars]) Remove leading and trailing characters TRIM(string)

Routines

Converting standalone routines:

RPG MySQL
1 P name B Routine start DROP FUNCTION IF EXISTS name;
DELIMITER //
CREATE FUNCTION name
2 D param 100A Input parameter (param CHAR(100))
3 D name PI 20A VARYING Return data type RETURS VARCHAR(20)
BEGIN
4 P name E Routine end END; //
DELIMITER ;

Local variable declaration:

RPG MySQL
1 D var S 5I 0 INZ Integer variable DECLARE var INT DEFAULT 0;

Assignment statement:

RPG MySQL
1 var = expr; Variable assignment SET var = expr;

Flow of control statements

RPG MySQL
1 DOU condition; statements ENDDO; Do until loop WHILE condition DO statements END WHILE;
2 IF condition; statements ENDIF; IF statement IF condition THEN statements END IF;

Directives

Converting compiler directives:

RPG MySQL
1 /FREE Start of code block BEGIN
2 /END-FREE End of code block END