From a high-level perspective, there are two places to add database retrieval logic for use in a Smart Form:
(1) The print program
(2) The form itself
If you add this logic to the print program, there are two rules:
If you add this logic to the form itself, you can put it either at the top of the form under Global definitions (in 'Initialization' or 'Form routines') or in a 'Program lines' node within the body of the form itself. However, if you go with the second option, there are other rules:
The reason is that the form will generate an ABAP function module. All of its program logic will become part of this code. So basic ABAP programming standards should apply, including efficient database access (e.g. no SELECT statements in nested loops, no retrieval of irrelevant table columns or rows).
To put it another way, avoid accessing the database more than necessary. Program nodes which can be hit multiple times as the form is output should only pull from pre-populated tables passed from the top of the form or from the print program -- not from the database.
Dig Deeper on SAPscript and Smart Forms
Related Q&A from Mark Smithson
An SAP user is working with an SAPscript form to create the form development for an Invoice List, and wants to know if it's possible to migrate the ... Continue Reading
An SAP user is trying to align a barcode in the center of a defined window on an SAP Smart Form. Continue Reading
An SAP user is looking to fix an error with a packing slip print-out in an SAP Smart Form. Continue Reading