Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

constants use

Former Member
0 Kudos

hi ,

when we use constants???

can anyone explain with example..

regards,

2 REPLIES 2

Former Member
0 Kudos

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

Former Member
0 Kudos

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,