How to call a function in a form from another form?
I created amap.services.yml  

services:
  listenrolments:
    class: Drupal\amap\ListEnrolments
    arguments: []


and ListEnrolments.php  

&lt;?php
namespace Drupal\amap;
class ListEnrolments {
  public function __construct() {
  }
  public function list() {
    some code...
    return $rows;
    }
}


and in my two forms, inserted  

$rows = \Drupal::service('listenrolments')-&gt;list();


at the right place.
And it works!