In all the Connect EDI document types, the "docid" is passed into the EDI form. In the case of Invoices that would represent the Invoice ID (internal unique number), in the case of A/R Statements the docid is the customer ID. During the report creation process Connect converts "docid" to the correct internal field to pass to the Report itself. So docid becomes cust_id for the report.
Sorry to be so technical, what I'm actually saying is Connect does most of the work for you.
Here's some example SQL that I use in the EDI defiinition to populate the correct values in the accompanying email that has the Statement report attached to it. I've cheated a bit to join to the customer API view to get the billing contact details.
COALESCE(btrim(billing_contact_first), cust_name) AS cust_firstname,
billing_contact_email AS cust_email,
to_char(current_date, 'dd-Mon-YYYY') as statement_date
LEFT JOIN api.customer ON cust_number = customer_number
WHERE cust_id = <? value("docid") ?>