10-05-2007 7:51 PM
hi ,
when we use constants???
can anyone explain with example..
regards,
10-05-2007 7:56 PM
Hi
To declare a Constant Value we use constants
CONSTANTS: c_vbtyp type vbtyp value 'C'.
select vbeln vbtyp audat from vbak
where vbtyp = c_vbtyp.
This will fetch the records where vbtyp = C (orders)
Regards
Anji
10-05-2007 8:03 PM
Hi,
CONSTANTS are used in place of hardcoded values.
Take for example, you are using a value '123' in a lot of places in your program.
Later you want to change them to '456'.
It is a problem for you to change each and evry occurance of '123' with '456'.
Hence you declare a constant which is declared globally.
Ther you can simply change it at definition level. It would reflect in all other locations where it is used.
Ex:
Constants: c_value(5) type c value '12345'.
The constant is a constant so a variable having a value can't be changed.
The constant are often created to became the program more clear.
Suppose you want to read the first 100 records of an internal table:
CONSTANT MAX_RECORDS TYPE I VALUE 100.
DO.
READ TABLE ITAB INDEX SY-INDEX.
Stop the reading if the table has less than 100 record
IF SY-SUBRC <> 0. EXIT. ENDIF.
Stop the reading if the record 100 was read
IF SY-INDEX = MAX_RECORDS.
EXIT.
ENDIF.
ENDDO.
In this way it's easier to understand the meanining of the control to exit from the loop.
Regards,