Skip to Content
author's profile photo Former Member
Former Member

constants use

Hi Freinds,

why we are using constants in prg...

pls.. explain any one with EXAMPLE...

REGARDS,

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Posted on Dec 03, 2007 at 06:47 PM

    Hi,

    Constants are data objects that you can create statically in the program using that statement

    constants : c_x type c value 'X'.
    

    It cannot subsequently be changed. The value of a constant cannot be changed during the execution of the program.

    constants : c_x type c value 'X'.
    if v_value eq c_x.
       " Here you are check v_value = 'X' using constant c_x.
    endif.
    

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 01:16 AM

    Hi,

    If the client requirement is fixed for a particular thing..you use Constants...

    For eg U have a report to list materials for specific plant lets say 'C'

    U can give this plant 'C' as constant in ur where condition .

    select matnr from MARA into table itab where werks = c_plant .

    Where c_plant = 'C' .

    praveen

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 03:10 AM

    <b>Constants </b>

    Constants are named data objects that you create statically using a declarative statement. They allow you to store data under a particular name within the memory area of a program. The value of a constant must be defined when you declare it. It cannot subsequently be changed. The value of a constant cannot be changed during the execution of the program. If you try to change the value of a constant, a syntax error or runtime error occurs.

    CONSTANTS: BEGIN OF myaddress,

    name TYPE c LENGTH 20 VALUE 'Fred Flintstone',

    street TYPE c LENGTH 20 VALUE 'Cave Avenue',

    number TYPE p VALUE 11,

    postcode TYPE n LENGTH 5 VALUE 98765,

    city TYPE c LENGTH 20 VALUE 'Bedrock',

    END OF myaddress.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 04, 2007 at 04:45 AM

    Hi venu,

    You can use a constant when you need to include the same literal many times in a program. You can define a constant with the same value as the literal and use the constant in the body of the program in place of the literal. After some time, if you want to change the values means, you can simply change the value where you define the constant.

    ABAP/4 has one pre-defined constant: SPACE ( You can use ' ' this also both are same ).

    It is a constant having a value equal to spaces.

    Defining constants:

    --> CONSTANTS C_EX(4) TYPE C VALUE 'VENU'.

    --> CONSTANTS C_EX LIKE C VALUE 'BB'.

    --> CONSTANTS C_NUM TYPE I VALUE 5.

    --> CONSTANTS C_DATE LIKE SY-DATUM VALUE '19970305'.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 12:17 PM

    Variants:

    1. CONSTANTS c. ... VALUE [ val | IS INITIAL ].

    2. CONSTANTS c(len) ... VALUE [ val | IS INITIAL ].

    3. CONSTANTS: BEGIN OF crec,

    ...

    END OF crec.

    Effect

    The CONSTANTS statement defines global and local constants. By using constants, you can read statically declared data objects, since they always have a particular data type. You can use constants in any position where fields are allowed, and also in the following positions:

    To specify length in a DATA STATICS, CONSTANTS, PARAMETERS, or TYPES statement.

    As a DECIMALS value in a DATA, STATICS, CONSTANTS, PARAMETERS, or TYPES statement.

    As an OCCURS value in a DATA, STATICS, RANGES, or TYPES statement.

    In the VALUE addition of a DATA, STATICS, or CONSTANTS statement.

    As an offset or length specification in a field specification.

    As a value for an exception (EXCEPTIONS) in the CALL FUNCTION statement.

    Constants always have a defined data type. Data types and data objects are integral parts of the ABAP type concept.

    In contrast to variables defined with the DATA statement, you cannot change the value of a constant once it has been defined.

    Apart from the additions ... TYPE typ OCCURS n, ... LIKE f1 OCCURS n and WITH HEADER LINE, all the additions used with the DATA statement are allowed. However, in contrast to the DATA statement, the addition ... VALUE val or VALUE IS INITIAL is obligatory with variants 1 and 2. See additions with DATA.

    Example

    CONSTANTS CHAR1 VALUE 'X'.

    CONSTANTS INT TYPE I VALUE 99.

    CONSTANTS: BEGIN OF CONST_REC,

    C(2) TYPE I VALUE 'XX',

    N(2) TYPE N VALUE '12',

    X TYPE X VALUE 'FF',

    I TYPE I VALUE 99,

    P TYPE P VALUE 99,

    F TYPE F VALUE '9.99E9',

    D TYPE D VALUE '19950101',

    T TYPE T VALUE '235959',

    END OF CONST_REC.

    Note

    You cannot declare XSTRINGs, references and internal tables - or structures that include internal tables - as constants.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.