I was wondering if there was any way to Is there a way to pass, let's say, a file location and in return it outputs the databases that need to be connected to compile that?
No, although some IDE contexts will store the info (eg. SmartObjects).
Think of it this way: the source file that you wish to test could have been generated by anything including non-Progress editors down to notepad, and may be invalid against any database, or compileable against multiple databases (including ones not intended), and may be a non-Progress source or even a random text or raw file. ".p" guarantees nothing.
You are asking for a function like this:
WhichDBDoesSourceRequire(textFilename)
when the best you can do is:
IsSourceValidAgainstThisDB(dbName, textFileName).
Hence the need to inspect rcode, where the validity has already been proven, and is guaranteed against the references within.
If that makes sense.