You can define the function within the same source file as the program that calls it.
Here is an example:
$set preservecase case repository(update ON) id division. function-id. myfunction. linkage section. 01 myparam pic x(5). 01 myresult pic x(5). procedure division using myparam returning myresult. move myparam to myresult goback. end function myfunction. id division. program-id. mytest. environment division. repository. function MYFUNCTION. data division. working-storage section. 01 myparameter pic x(5) value "12345". 01 myresult pic x(5) value spaces. procedure division. move function myfunction(myparameter) to myresult display myresult goback. end program mytest.