-1

How can I read RPG source code into a variable in another RPG program? This is so I can analyze the code to edit it.

jmarkmurphy
  • 11,030
  • 31
  • 59
  • 1
    Please clarify the question. Do you want to open the source code of a program? Or execute it? Or debug to see your variable content? – Dam Oct 19 '22 at 18:00
  • I want to put the source code of a program into 1 variable or read lines for edit it from my new program – Alessandro Magri Oct 19 '22 at 23:32

2 Answers2

1

If your source member is in a FILE/MEMBER you can open and read it with SQL. You have to use an alias because SQL can't directly select from a multi-member file.

CREATE ALIAS lib/youralias FOR lib/filesource (sourcemember);

use a SQLRPGLE with a cursor to read line by line :

SELECT * FROM lib/youralias;

If your source is in the IFS, you can also read it with SQL + cursor :

SELECT * FROM TABLE(QSYS2.IFS_READ('/home/dir/yoursource.rpg'))
Dam
  • 986
  • 1
  • 14
  • 20
0

If you don't want to use SQL, you can also read a source file like any other database file in RPG. To read a specific member, you can use an override, or you can use the EXTMBR() keyword on the F spec.

Here is a link to the docs

jmarkmurphy
  • 11,030
  • 31
  • 59