Dynamic programing can save a lot of 'superfluous' coding.
To assign a variable a type at runtime, use the ABAP statement
ASSIGN with the option TYPE. For instance:
DATA: D_TYPE,
D_FIELD(35).
DATA: D_TEST TYPE P.
FIELD-SYMBOLS: <F>.
D_FIELD = 'D_TEST'.
D_TYPE = 'P'.
ASSIGN (D_FIELD) TO <F> TYPE D_TYPE.
Additionally you can use the option DECIMALS of the ASSIGN
statement if your type is 'P'. You can even change the type at
runtime of previously assigned field symbol like
ASSIGN <F> TO <F> TYPE 'C'.
One more thing for dynamic programing. With the following coding
you can access every DDIC table with the key you want:
SELECT SINGLE * FROM (DF_TNAME) INTO S_TMP WHERE (IF_KEY).
It is very powerful, isn't it !!!
[ Ingo-Willy Raddatz, posted to SAP listserver]
The following code is just a function to loop total pages. To
use from the beginning of your report, you will have to loop
through your report once before display. ABAP does not
provide
an easy "read-ahead" method of doing this, so this is the "cludgy"
way of making it work if needed.
FORM GET_TOTAL_PAGENO.
WRITE SY-PAGNO TO NUM_PAGES_C LEFT-JUSTIFIED.
DO SY-PAGNO TIMES.
READ LINE 2 OF PAGE SY-INDEX.
REPLACE '*****' WITH NUM_PAGES_C INTO SY-LISEL.
MODIFY LINE 2 OF PAGE SY-INDEX.
ENDDO.
ENDFORM. " GET_TOTAL_PAGENO
[found on the Web at http://homepages.tcp.co.uk/~bob866/how_to.html]
| Converted from CHM to HTML with chm2web Standard 2.7 (unicode) |