You'll need to know how to develop ABAP coding for this. Assuming that you know this, you should try to extend the input structures of the form and add the necessary selection logic to the supplying program. If this is not possible, you can add code to the form, but that's not recommended for various reasons.
EDIT:
If you do know how to code ABAP, it's even harder to understand your question. I assume you have taken a look at the excellent online doumentation. If you inspect the header entries of a form, you'll note stuff like global definitions and initialization coding. If you take a closer look at the elements you can insert in a form, you'll discover program lines. So this is one way to embed ABAP code in a form that will select data from the database. You'd print it out like any other field.
However, this is a bad idea. It will generally slow your form processing down and is a nightmare to maintain if used too widely. Instead, you should take a look at the parameters of the form and the program that is calling the form. If possible, edit the appropriate structure or use an append structure to add the additional fields. Then, use a BAdI, user exit or an implicit enhancement to fill the fields in the calling program. The advantage of this is that the data will be passed to all forms and you won't have to copy the logic throughout multiple forms. (Also, it will be easier to port this to Interactive Forms if you'll ever have to).