I learned about defining modifiable data objects using "DATA" Statement and "PARAMETER" statement and implementing it using programs.
Variables(modifiable data object)
Two statements are commonly used to define
variables in an ABAP/4 program:
·
data
·
parameters
Data Statement to Define Variables
Using data statement, variables can be declared for the program.
Variables defined in the data statement are assigned to a data type and can
also have defaults.
Syntax for
the data Statement
data v1 [(l)] [type t] [decimals d] [value 'xxx'].
or
data v1 like v2 [value 'xxx'].
where:
·
v1 is the variable name.
·
v2 is the name of a variable previously
defined in the program, or is the name of a field that belongs to a table or
structure in the Data Dictionary.
·
(l) is the internal length specification.
·
t is the data type.
·
d is the number of decimal places (used
only with type p).
·
'xxx' is a literal that supplies a default
value.
Examples of Variables Defined with
the DATA Statement
data f1(2) type c.
data f2 like f1.
data max_value type i value 100.
data cur_date type d value '19980211'.
NOTE: Variable names can be 1 to 30 characters
long. They can contain any characters except
( ) + . , : and must contain at least one alphabetic
character. SAP recommends that variable names should
always begin with a character and they should not contain a dash. A dash has
special meaning. Instead of a dash, we should use an underscore ( _ ).
The following points also apply to
the data statement:
·
The
default length depends on the data type.
·
The
default data type is c (character).
·
The
default initial value is 0, except for data type c, which is blank.
·
The value addition only accepts a literal or
constant; we cannot use a variable to supply a default value.
· When using the like addition, the variable being defined obtains its length and data type from the referenced variable. We cannot specify them on the same statement with like.
·
When
using the like addition,
the value is not obtained from the referenced
variable. we can specify the value addition to give the variable a default value. If we
do not, it is assigned a default initial value of 0 (or blank for a character data type).
The data statement can
appear anywhere in a program. The definition for a variable must physically
come before the statements that access it. If we place a data statement
after executable code, the statements above it cannot access the variables it
defines.
Example of a Variable That Is Incorrectly
Accessed Before It Is Defined
report zprogram.
data f1(2) value 'Hi'.
write: f1, f2.
data f2(5) value 'there'.
data f1(2) value 'Hi'.
write: f1, f2.
data f2(5) value 'there'.
The variable F2 is defined on line 4, and the write statement
on line 3 is trying to access it. This will generate a syntax error. The data statement
on line four should be moved before line 3.
Parameters Statement to Define Variables
A parameter is a special type of variable that is defined using the parameters statement. parameters is a lot like the data statement, but when we run the program, the system
will display the parameters as input fields on a selection screen before
the program actually begins to execute. The user can enter or modify their
values and then press the Execute button to begin program execution. we can use
both parameters and data in the same program. The rules for parameter names
are the same as for variable names, except for the following:
- The maximum length is 8 characters instead of 30.
- In addition to literals and constants, you can
also use a variable to supply default a default value.
Syntax for the parameters Statement
parameters p1[(l)] [type t] [decimals d] ...
or
parameters p1 like v1 ...
... [default 'xxx'] [obligatory] [lower case] [as checkbox] [radiobutton
group g].
where:
- v1 is the
name of a previously defined variable or parameter, or is the name of a
field that belongs to a table or structure in the Data Dictionary.
- (l) is
the internal length specification.
- t is the
data type.
- d is the
number of decimal places (used only with type p).
- 'xxx' is
a literal or previously defined variable that supplies a default value.
Examples of parameters defined with
the parameters statement.
parameters p1(2) type c.
parameters p2 like p1.
parameters max_value type i default 100.
parameters cur_date type d default '19980211'.
parameters p2 like p1.
parameters max_value type i default 100.
parameters cur_date type d default '19980211'.
No comments:
Post a Comment