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.