Tuesday, 23 July 2013

JULY 23


Studied about system variables with example program , assignment statements and its types.

Working with System Variables:

There are 176 system variables available within every ABAP/4 program. we do not have to define them; they are automatically defined and are always available.
To display a list of system variables, we can display the DDIC structure syst. we can also display it by using the Dictionary: Initial Screen (se11), or by double-clicking on the name of any system variable in our program.

List of Commonly Used System Variables

Name
Description
sy-datum
Current date
sy-uzeit
Current time
sy-uname
Current user id
sy-subrc
Last return code
sy-mandt
Logon client
sy-pagno
Current output page number
sy-colno
Current output column number
sy-linno
Current output list line number
sy-vline
Vertical line
sy-uline
Horizontal line
sy-repid
Current report name
sy-cprog
Main program name
sy-tcode
Current transaction code
sy-dbcnt
Within a select, contains the current iteration counter. After the endselect, contains number of rows that match the where clause.
Example program displaying use of system variables.
Example-1:

Using Basic System Variables
 1 report ztx0901.
 2 tables ztxlfa1.
 3 parameters `land1 like ztxlfa1-land1 obligatory default 'US'.
 4 write: / 'Current date:', sy-datum,
 5        / 'Current time:', sy-uzeit,
 6        / 'Current user:', sy-uname,
 7        / 'Vendors having country code', `land1,
 8        /.
 9 select * from ztxlfa1
10     where land1 = `land1
11     order by lifnr.
12     write: / sy-dbcnt, ztxlfa1-lifnr.
13     endselect.
14 write: / sy-dbcnt, 'records found'.
15 if sy-subrc <> 0.
16     write: / 'No vendors exist for country', 'land1.
17     endif.

Output:
Current date: 1998/02/22
Current time: 14:38:24
Current user: KENGREENWOOD
Vendors having country code US

         1  1040
         2  1080
         3  1090
         4  2000
         5  V1
         6  V2
         7  V3
         8  V4
         9  V5
        10  V7 
        10 records found

Description:
  • Line 2 defines a field string ztxlfa1 exactly like the table of the same name.
  • Line 3 defines a single input parameter `land1.
  • On lines 4 through 6, the current date, time, and user id are written out from system variables sy-datumsy-uzeit, and sy-uname.
  • Line 7 writes out the country code that was entered in the parameter input field `land1 on the selection screen.
  • Line 8 writes out a blank line.
  • Line 9 selects records from table ztxlfa1 and places them one at a time into field string ztxlfa1.
  • Line 10 restricts the selection of records to only those having a country code equal to the one entered on the selection screen.
  • Line 11 causes the records to be sorted in ascending order by lifnr (vendor number).
  • Line 12 writes out the current iteration number from system variable
    sy-dbcnt and a vendor number from each record.
  • Line 13 marks the end of the select/endselect loop.
  • Line 14 writes out the total number of iterations of the select loop. This is the same as the number of records that matched the where clause using system variable sy-dbcnt.
  • On line 15, the return code from the select, contained in system variable sy-subrc, is tested. If it is zero, records were found. If it is non-zero, no records were found and a message is written out on line 16.

Assignment Statements:

An assignment statement assigns a value to a variable or field string. Three assignment statements are commonly used:
  • clear
  • move
  • move-corresponding

Using the clear Statement

The clear statement sets the value of a variable or a field string to zeros. If the data type is c, the value is instead set to blanks. Blanks and zeros are known as default initial values. It is often said that clear assigns default initial values to variables.

Syntax for the clear Statement

The following is the syntax for the clear statement.
clear v1 [with v2 | with 'A' | with NULL]
where:
  • v1 and v2 are variable or field string names.
  • 'A' is a literal of any length.

Using the move Statement

To move a value from one field to another, use the move statement. The entire contents or a portion thereof can be moved. Instead of move, we can use the assignment operator =, as shown below. They are both referred to as a move statement.

Syntax for the move Statement

The following is the syntax for the move statement. Operators and operands must be separated by spaces. Multiple assignment occurs from right to left.

move v1 to v2.
OR
v2 = v1.
OR
v2 = v1 = vm = vn.....
OR
move v1[+N(L)] to v2[+N(L)].
OR
v2[+N(L)] = v1[+N(L)].

where:
  • v1 is the sending variable or field string.
  • v2 is the receiving variable or field string.
  • N is an offset from the beginning of the variable or field string.
  • L is the number of bytes to move.

Right and Wrong Coding of Assignment

Right
Wrong
f1 = f2.f1=f2.
f1 = f2 = f3.f1=f2=f3.

Using the move-corresponding Statement

To perform a move from one field string to another where the data types and/or lengths do not match, we use the move-corresponding statement. It generates individual move statements for components with matching names. Components in the receiving field string that do not have a matching name in the sending field string are not changed. .

Syntax for the move-corresponding Statement

The following is the syntax for the move statement. Operators and operands must be separated by spaces. Multiple assignment occurs from right to left.
move-corresponding v1 to v2.
where:
  • v1 is the sending variable or field string.
  • v2 is the receiving variable or field string.

Monday, 22 July 2013

JULY 22



Introduction to various types of statement in ABAP/4 with example.

ABAP Statements



Statements and Keywords

Types of statements in ABAP/4:
  • Declarative Statements
  • Modularization Statements
  • Control Statements
  • Call Statements
  • Operational Statements
  • Database Statements

The source code of an ABAP program consists of comments and ABAP statements.

Comments are distinguished by the preceding signs * (at the beginning of a line) and “ (at any

position in a line).

ABAP statements always begin with an ABAP keyword and are always concluded with a period

(.) . Statements can be several lines long; conversely, a line may contain more than one

statement.

ABAP statements use ABAP data types and objects.


The first element of an ABAP statement is the ABAP keyword. This determines the category of

the statements. 

The different statement categories are as follows:
  • Declarative Statements
These statements define data types or declare data objects which are used by the other

statements in a program or routine. The collected declarative statements in a program or routine

make up its declaration part.

Examples of declarative keywords:   TYPES, DATA, TABLES

  • Modularization Statements
These statements define the processing blocks in an ABAP program.

The modularization keywords can be further divided into:

1.     Event Keywords

We use statements containing these keywords to define event blocks. There are no

special statements to conclude processing blocks - they end when the next processing

block is introduced.

Examples of event keywords are: AT SELECTION SCREEN, START-OF-SELECTION, AT USER-COMMAND
    
    2. Defining keywords

we use statements containing these keywords to define subroutines, function modules,

dialog modules and methods. We conclude these processing blocks using the ENDstatements.

Examples of definitive keywords: FORM ..... ENDFORM, FUNCTION ... ENDFUNCTION,
MODULE ... ENDMODULE.


  • Control Statements
we use these statements to control the flow of an ABAP program within a processing block

according to certain conditions.

Examples of control keywords: IF, WHILE, CASE

  • Call Statements
we use these statements to call processing blocks that we have already defined using

modularization statements. The blocks we call can either be in the same ABAP program or in a

different program.

Examples of call keywords: PERFORM, CALL, SET USER-COMMAND, SUBMIT, LEAVE TO

  • Operational Statements

These keywords process the data that we have defined using declarative statements.

Examples of operational keywords: WRITE, MOVE, ADD

  • Database Statements
These statements use the database interface to access the tables in the central database system. 
There are two kinds of database statement in ABAP: Open SQL and Native SQL.

1.     Open SQL

Open SQL is a subset of the standard SQL92 language. It contains only Data Manipulation

Language (DML) statements, such as SELECT, INSERT, and DELETE. It does not contain any

Data Definition Language (DDL) statements (such as CREATE TABLE or CREATE INDEX).

Open SQL contains all of the DML functions from SQL92 that are common to all of the database systems supported by SAP. It also contains a few SAP-specific functions. ABAP programs that use only Open SQL statements to access the database are fully portable. The database interface converts the OPEN SQL commands into commands of the relevant database.

       2.   Native SQL

Native SQL statements are passed directly from the database interface to the database without

first being converted. It allows us to take advantage of all of our database’s characteristics in

your programs. In particular, it allows us to use DDL operations. The ABAP Dictionary uses

Native SQL for tasks such as creating database tables. In ABAP programs that use Native SQL statements are database-specific, because there is no standardized programming interface for SQL92.

Friday, 19 July 2013

JULY 19


Structured Types:Studied about structured types , type pools and their creation  and its implementation in programs.
A user-defined type can be based on the definition of a field string. This is known as a structured type. The following example shows how we can shorten a program using a structured type.

Example:

  Using Structured Types can Reduce Redundancy and Make Maintenance Easier
 1 report ztx0813.
 2 types: begin of address,
 3            street(25),
 4            city(20),
 5            region(7),
 6            country(15),
 7            postal_code(9),
 8            end of address.
 9
10  data: customer_addr type address,
11        vendor_addr   type address,
12        employee_addr type address,
13        shipto_addr   type address.
14
15 customer_addr-street  = '101 Memory Lane'.
16 employee_addr-country = 'Transylvania'.
17
18 write: / customer_addr-street,
19          employee_addr-country.
Description:
Lines 2 through 8 define a data type named address that contains five fields. On lines 10 through 13, four field strings are defined using the new type. Without the new type, these definitions would have used an additional 24 lines of code. Maintenance is also made easier: If a change to the definitions of the address field strings is needed, only the definition of the type needs to be changed. 

Type Groups

types statement can be stored in a type group. A type group (also known as a type pool) is a Data Dictionary object that exists merely to contain one or more types or constants statements. Using the type-poolsstatement in our program, we access types or constants from a type group and use them in our program. Multiple programs can share a type group, giving us the ability to create centralized definitions. 

The following figure illustrates the concept:

Example:
A type-pool Statement Containing Types and Constants 
1 type-pool ztx1.
2 types:     ztx1_dollars(16)         type p decimals 2,
3            ztx1_lira(16)            type p decimals 0.
4 constants: ztx1_warning_threshold   type i value 5000,
5            ztx1_amalgamation_date   like sy-datum value '19970305'.

Description:
Line 1 indicates the beginning of the type group and gives it a name. Lines 2 through 5 define types and constants that can be used in any program.

Using Type Group Reduces Duplication of Code for Easier Maintenance

Program making the use of above created "type-pool" -
 1 report ztx0815.
 2 type-pools ztx1.
 3 data: begin of american_sums,
 4           petty_cash type ztx1_dollars,
 5           pay_outs   type ztx1_dollars,
 6           lump_sums  type ztx1_dollars,
 7           end of american_sums.
 8
 9 american_sums-pay_outs = '9500.03'.
10
11 if american_sums-pay_outs > ztx1_warning_threshold.
12     write: / 'Warning', american_sums-pay_outs,
13              'exceeds threshold', ztx1_warning_threshold.
14     endif.
 Description:
Line 2 includes the definitions from type group ztx1 in the program. Lines 3 through 7 define a field string using type ztx1_dollars from the type group. Line 9 assigns a value to pay_outs, and it is compared with constant ztx1_warning_threshold from the type group on line 11.
If the type group has already been included, subsequent attempts to include it are ignored and they do not cause an error.

NOTE: Type group names can be one to five characters long, and must begin with y or z. Types and constants included in a program using the type-pools statement always have global visibility.


Creating a Type Group

To create a type group:
  1. Begin at the Dictionary: Initial Screen (menu path Tools->ABAP/4 Workbench, Development->ABAP/4 Dictionary).
  2. Type the name of your type group in the Object Name field.
  3. Select the Type Groups radio button.
  4. Press the Create pushbutton. The Type Group xxxx: Create Text screen is displayed.
  5. Type a description of your type group in the Short Text field.
  6. Press the Save button. The Create Object Catalog Entry screen is displayed.
  7. Press the Local Object button. The ABAP/4 Editor: Edit Type Group screen is 
  8. displayed. On the first line, the statement type-pool t. appears, where t is the name of your type group. If it does not appear, you should type it now.
  9. On subsequent lines, type constants and types statements. All names must begin with t_, where t is the name of your type pool.
  10. Press the Save button on the Application toolbar. At the bottom of the window, the message Type group saved is displayed.
  11. Press the Back button on the Application toolbar to return to the Dictionary: Initial Screen.



    To delete a type group, follow steps 1 through 3 of the preceding procedure and then press the Delete button on the Application toolbar.

    Here also we can use T-code se11 ,hence replacing the step 1 and directly moving to the Dictionary: Initial screen.

    Thursday, 18 July 2013

    JULY 18


    Learned about how to create our own data types as well as its examples to implement it.

    Defining Types

    WE can define our own data types using the types statement and base them on existing data types.

    Syntax for the TYPES Statement

    The following is the syntax for defining a type using the types statement.
    types t1[(l)] [type t] [decimals d].
    
    or
    types t1 like v1.
    
    where:
    • t1 is the type name.
    • v1 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).
    Listing below examples of programs that define and use their own data types:
    Example-1:


    Simple Example of a User-Defined Data Type "CHAR2"

    1 report ztx0811.
    2 types char2(2) type c.
    3 data: v1 type char2 value 'AB',
    4       v2 type char2 value 'CD'.
    5
    6 write: v1, v2.
    Output:

    AB CD

    Description:
    Line 2 defines a data type named char2. It is a two-byte char field. On lines 3 and 4, variables v1 and v2 are defined as two-byte char fields using the data type char2. They are given default values and, on line 6, they are written out.

    Example-2:

    Using Types Can Make the Code Clearer and Easier to Read
    1  report ztx0812.
    2  types: dollars(16) type p decimals 2,
    3         lira(16)    type p decimals 0.     "italian lira have no 
            decimals
    4
    5  data: begin of american_sums,
    6             petty_cash type dollars,
    7             pay_outs   type dollars,
    8             lump_sums  type dollars,
    9             end of american_sums,
    10        begin of italian_sums,
    11            petty_cash  type lira,
    12            pay_outs    type lira,
    13            lump_sums   type lira,
    14            end of italian_sums.
    15
    16 american_sums-pay_outs = '9500.03'.       "need quotes when literal 
         contains a decimal
    17 italian_sums-lump_sums = 5141.
    18
    19 write: / american_sums-pay_outs,
    20        / italian_sums-lump_sums.
    Output:
    9,500.00
    5,141
    Description:
    Line 2 defines a data type named dollars as a 16-byte packed decimal field with two decimal places. Line 3 defines a similar data type named lira with 0 decimal places. On lines 5 through 14, two field strings are defined using the new data types. One component of each is assigned a value on lines 16 and 17, and on lines 19 and 20 they are written out.


    •  The same rules apply to types as apply to variables and field strings. Type names, like variable names, are one to 30 characters long, but unlike variables, their names cannot include the characters - < >. 



    Wednesday, 17 July 2013

    JULY 17


    Detailed study of field strings was done today. Brief of it is given below with illustrations.

    Using a Field String as a Variable of Type "char"

    Not only can we address the individual components of a field string, we can also address all components at once as if they were a single variable of type char.  The following example illustrates this concept.
    Example-1:

     Using a Field String as Both Multiple Variables and as a Single Variable of Type CHAR 

     1 report ztx0807.
     2 data: begin of fs1,
     3         c1 value 'A',
     4         c2 value 'B',
     5         c3 value 'C',
     6         end of fs1.
     7
     8 write: / fs1-c1, fs1-c2, fs1-c3,
     9        / fs1.
    10
    11 fs1 = 'XYZ'.
    12
    13 write: / fs1-c1, fs1-c2, fs1-c3,
    14        / fs1.
    Output:
    A B C
    ABC
    X Y Z 

    XYZ 



    Description: 

    Lines 2 through 6 define field string fs1. It has three components, each with a default value. On line 8, each component is written out individually. On line 9, the field string is written out as if it were a single variable. Consequently, the output shows the contents of fs1 as if it were a single variable defined as char 3. On line 11, the value 'XYZ' is assigned to the field string, again treating it as a char variable. The resulting output shows that the individual components reflect the change because they are accessing the same storage.


    Example-2:


    An Example of Assignment Involving Two Field Strings
     1 report ztx0808.
     2 data: begin of fs1,
     3         c1 value 'A',
     4         c2 value 'B',
     5         c3 value 'C',
     6         end of fs1,
     7       fs2 like fs1.
     8
     9 fs2 = fs1.
    10 write: / fs2-c1, fs2-c2, fs2-c3.
    Output: 
    A B C

    Description:
    Lines 2 through 6 define field string fs1. Line 7 defines field string fs2 exactly like fs1. On line 9, fs1 is moved to fs2, just as if it were a single variable of type char. On line 10, the components of fs2 are written out.


    Using the TABLES Statement to Define a Field String:

    A field string defined using the tables statement is a modifiable data object. Field strings defined using the tables statement follow the same rules as field strings defined using the data statement.

    Syntax for Defining a Field String Using the TABLES Statement

    The following is the syntax for defining a field string using the tables statement.
    tables fs1.
    
    where:
    • fs1 is the field string name. A table or structure of the same name must exist in the Data Dictionary.
     Example:
    Field String Defined Using the TABLES Statement
    1 report ztx0809.
    2 tables ztxlfa1.
    3
    4 ztxlfa1-name1 = 'Bugsy'.
    5 ztxlfa1-land1 = 'US'.
    6
    7 write: / ztxlfa1-name1, ztxlfa1-land1.
    Description:
    Line 2 defines field string ztxlfa1. Its definition is exactly like the Data Dictionary table of the same name. On lines 4 and 5, values are given to two of its components, which are written out on line 7.

    Field String Defined Using TABLES Interacting with SELECT:

    The tables statement does more than just define a field string. It does two things:
    • It defines a field string.
    • It gives the program access to a database table of the same name, if one exists.
    Example:
    1 report ztx0810.
    2 tables ztxlfa1.
    3 select * from ztxlfa1 into z lfa1 order by lifnr.
    4     write / z lfa1-lifnr.
    5     endselect.
    
    
    Description:
    Line 2 defines field string ztxlfa1. Its definition is exactly like the Data Dictionary table of the same name. There is also a database table of the same name, so the program is given access to that table, meaning that it can now be used in a select statement. Each time line 3 is executed, a record is read from the database table ztxlfa1 into field string ztxlfa1. For each record, the value of component ztxlfa1-lifnr is written out (line 4).
    
    
    
    

    Tuesday, 16 July 2013

    JULY 16

    Today I learned about constant definition and declaration in ABAP/4 , definition of field strings using DATA statements and various examples to implement the field strings.

    Defining Constants

    A constant is almost identical to a variable except that its value cannot be changed. To define one, we use the constants statement.
    We use a constant when we need to include the same literal multiple times in a program. we 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. Later, if we need to change the value of the literal,we can simply change the value of the constant, causing its value to be updated wherever it is used in the program.
    ABAP/4 has one pre-defined constant: SPACE. It is a constant having a value equal to spaces. we can use it in place of the literal ' '.

    Syntax for the CONSTANTS Statement:

    The following code demonstrates the syntax for defining a constant. It is similar to the data statement; however, the addition value is required. In all other ways, constants conform to the same rules as variables defined using the data statement.

    constants c1[(l)] [type t] [decimals d] value 'xxx'.
    or
    constants c1 like cv value 'xxx'.

    where:
    • c1 is the name of the constant.
    • cv is the name of a previously defined constant or variable, 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 the value of the constant.

    Example illustrating  Definitions of Constants:
    constants c1(2) type c value 'AA'.
    constants c2 like c1 value 'BB'.
    constants error_threshold type i value 5.
    constants amalgamation_date like sy-datum value '19970305'.

    Defining Field Strings


    field string is a type of variable, like a structure, a field string is a series of fields grouped together under a common name. The difference lies mainly in where the definition resides. The term structure in R/3 applies only to a Data Dictionary object containing a collection of fields. The term field string applies to a collection of fields defined in an ABAP/4 program.
    Two statements are usually used to define field strings in an ABAP/4 program:
    • data
    • tables

    Using the DATA Statement to Define a Field String

    A field string defined using the data statement is a modifiable data object. It can have global or local visibility.

    Syntax for Defining a Field String Using the DATA Statement

    The following is the syntax for defining a field string using the data statement.
    data: begin of fs1,
    f1[(l)] [type t] [decimals d] [value 'xxx'],
    f2[(l)] [type t] [decimals d] [value 'xxx'],
    ... end of fs1.
    OR
    data : begin of fs1.
    data f1[(l)] [type t] [decimals d] [value 'xxx'].
    data f2[(l)] [type t] [decimals d] [value 'xxx'].
    ... 
    [include structure st1.] 
    data end of fs1.
    OR
    data fs1 like fs2.
    where:
    • fs1 is the field string name.
    • f1 and f2 are the fields (also called components) of the field string.
    • fs2 is the name of a previously defined field string, or is the name of 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.
    • st1 is the name of a structure or table in the Data Dictionary.


    Field strings follow the same rules as variables defined using the data statement. To refer to an individual component, its name must be prefixed by the name of the field string and a dash (-). For example, to write the number component of the cust_info field string, we would use the statement write cust_info-number.
    The include statement is not part of the data statement; it is a separate statement. Therefore, it cannot be chained to a data statement. The statement before it must be concluded with a period.

    Various programs that define and use field strings are shown in following examples:

    Example-1:

    A Simple Example of a Field String Defined Using the DATA Statement
     1 report ztx0802.
     2 data: begin of totals_1,
     3         region(7)    value 'unknown',
     4         debits(15)   type p,
     5         count        type i,
     6         end of totals_1,
     7       totals_2 like totals_1.
     8
     9 totals_1-debits = 100.
    10 totals_1-count  = 10.
    11 totals_2-debits = 200.
    12
    13 write: / totals_1-region, totals_1-debits, totals_1-count,
    14        / totals_2-region, totals_2-debits, totals_2-count.
     Description:

    Line 2 begins the definition of field string totals_1. It contains three fields, the first of which is initialized with the value 'unknown'. On line 7, field string totals_2 is defined exactly like totals_1. The value of totals_1-region is not propagated to totals_2-region. On lines 9 through 11 values are assigned to components of the field strings, and on lines 13 and 14, the values of all components are written out.

    Example-2:

    Exaample to show a Field String Can Contain Another Field String
     1 report ztx0803.
     2 data: begin of names,
     3         name1        like ztxkna1-name1,
     4         name2        like ztxkna1-name2,
     5         end of names.
     6 data: begin of cust_info,
     7         number(10)   type n,
     8         nm           like names,         "like a field string
     9         end of cust_info.
    10
    11 cust_info-number   = 15.
    12 cust_info-nm-name1 = 'Jack'.
    13 cust_info-nm-name2 = 'Gordon'.
    14
    15 write: / cust_info-number,
    16          cust_info-nm-name1,
    17          cust_info-nm-name2.
    Description: 
    Line 2 begins the definition of field string names. It contains two fields that are defined like fields of table ztxkna1 in the Data Dictionary. They are not given any initial values. On line 8, component cust_info-name is defined like field string names. When it is used on lines 12 and 13, nm is included in the component name.

    Example-3:

     A Field String Can Be Defined Exactly Like a  Structure
     1 report ztx0804.
     2 data: 
     3       my_addr like ztxaddr.         "like a structure in the DDIC
     4
     5 my_lfa1-name1 = 'Andrea Miller'.
     6 my_lfa1-telf1 = '1-243-2746'.
     7 my_addr-land1 = 'CA'.
     8
     9 write: / my_lfa1-name1,
    10          my_lfa1-name2,
    11          my_addr-land1.

    Description:
    On line 3 my_addr is defined like the DDIC structure ztxaddr.

    Example-4:

    If we Use LIKE Instead of INCLUDE, we Get a Different Result. The Names of the Included Fields Are Prefixed by an Intermediate Component Name.
     1 report ztx0806.
     2 data: begin of fs1,
     3         mylfa1 like ztxlfa1,
     4         extra_field(3) type c,
     5         end of fs1.
     6
     7 fs1-mylfa1-lifnr  = 12.
     8 fs1-extra_field    = 'xyz'.
     9
    10 write: / fs1-mylfa1-lifnr,
    11          fs1-extra_field.
     Description:
    Line 2 begins the definition of field string lfa1_with_extra_field. The statement ends with a period because include structure is not part of the data statement; it is a separate statement. On line 3, the structure of table ztxlfa1 is included into the field string. On line 4, another field is included in the field string after the fields of table ztxlfa1. Any number of fields could be included, more structures could be included here as well, or any combination thereof.

    Friday, 12 July 2013

    JULY 12


    On ninth day I was taught about further details for "PARAMETERS " statement and various additions that can be used with it along with an example to implement it.

    The following points also apply to the parameters statement :

    • The default data type is c (character).
    • The default value is 0, except for data type c, which is blank.
    • The value addition accepts a literal, a sy variable, or a variable previously defined in the program.
    • When using the like addition, the parameter 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 parameter a default value. If we do not, it is assigned a default initial value of 0 (or blank for a character data type).
    • Like data, the parameters statement can appear anywhere in a program, but the definition must physically come before the statements that access it.
    • Parameters appear on a selection screen in the same order that they are defined in the program.
    • All parameters statements, no matter where they appear in the program, are collected together by the ABAP/4 interpreter and displayed on the selection screen at the same time. Even if we put a parameter statement in the middle of the program, that parameter will still be displayed on the selection screen before the program executes.
    • The parameters are displayed in an SAP standard format. To modify their appearance, for example, to move the input field left or move the label right, the selection-screen statement is uesd.

    VARIOUS ADDITIONS WITH "PARAMETER" STATEMENTS ARE:

    Using the Addition: lower case

    All values entered into a parameter are translated into uppercase by default. To turn off this translation, use the addition lower case. This addition only applies to character fields.

    Using the Addition: as checkbox

    A check box has only two states: ticked and clear. we use them when we want to present the user with an on/off or true/false type of choice. we can use more than one check box on a screen. If we have multiple check boxes on a screen, they operate completely independently from each another.
    To display a parameter as a check box, use the addition as checkbox. we cannot specify a data type or length; it will default to type c and length 1. The parameter will contain a capital X if the check box is ticked; it will contain a blank if the check box is clear. If the check box should initially contain a tickmark, use a default value of capital X.
    Space and capital X are the only valid values. No other values are valid for a check box.

    Using the Addition: radiobutton group g

    Like check boxes, a radio button also has two states: selected and not selected. Unlike check boxes, radio buttons never operate alone, they operate only in groups. we can have any number of radio buttons in a group, but only one can be selected at a time. They are used when we need to present the user with a list of alternatives in which only one option can be chosen.
    To display a parameter as a radio button, use the addition radiobutton group g. we cannot specify a data type or length; it will default to type c and length 1g is an arbitrary group name one to four characters long. we can have more than one group in a program.
    The parameter will contain a capital X if the radio button is selected; it will contain a blank if it is not selected. To be initially selected, the radio button should contain a default value of capital X. No other values are valid for a radio button.
    The additions to the parameters statement are described in short in the following table:

      Additions to the PARAMETERS Statement and Their Uses

    Addition
    Use
    typeSame as the data statement.
    DecimalsSame as the data statement.
    LikeSame as the data statement.
    DefaultSame as the value addition on the data statement.
    ObligatoryThe user must enter a value into the field before the program will execute.
    lower casePrevents values from being translated into uppercase.
    as checkboxDisplays the input field as a check box.
    Radiobutton groupgDisplays the input field as a radio button belonging to group g.
    A sample program using parameters and to implement the above additions is given below.


     report ztx0706.
      parameters: p1(15) type c,
                 p2  like p1 obligatory lower case,
                  p3  like sy-datum default sy-datum,
                  cb1 as checkbox,
                  cb2 as checkbox,
                  rb1 radiobutton group g1 default 'X',
                  rb2 radiobutton group g1,
                  rb3 radiobutton group g1.
      write: / 'You entered:',
             / '  p1 =', p1,
             / '  p2 =', p2,
             / '  p3 =', p3,
             / '  cb1=', cb1,
             / '  cb2=', cb2,
             / '  rb1=', rb1,
             / '  rb2=', rb2,
             / '  rb3=', rb3.
    
    
    The OUTPUT generated by the above program is:
    
    
    
    
    
    
    
    
    
    
    When the selection screen is shown, obligatory fields contain a question mark. These indicate to the user which fields must be filled in before continuing.