Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Exercise 02.

01 - ABAP Basics

Data Handling

Exercise 02.01 ABAP Basics – Data Handling

- Page - Page 2 of of 8 - -

Note: All the following objects to be created should follow the naming convention – YEMPID_##$$%
%.

##$$ indicates the exercise number (02.01 for this assignment) and %% indicates the question
number in

the exercise. EMPID indicates the Employee ID.

1) Which of the following are invalid data object names and why?

a) InterestPaid

b) A1234bCDef

c) Si-int

d) percent.

e) SPACE

f) Dist in km

g) Ot+pay

h) Na,me

i) DATA:OBJECT

2) Evaluate the following expressions and show the operator hierarchy.

a) g = big / 2 + big * 4 / big – big + abc / 3.

(abc = 1.5, big = 3, assume g to be float)

b) on = ink * act / 2+ 3 /2 * act + 2 +tig.

(ink = 3, act = 2, tig = 3.2, assume on to be an int)

c) s = qui * add / 4 – 6 / 2 + 2 / 3 * 6 / god.

(qui = 2, add = 4, god = 3, assume s to be an int)

3) What is the maximum permissible length for data object names?

4) Write a program to display the following output:

ABAP is easy.

This text is displayed on a new line.

After the symbol ‘/’, text appears on a new line.

5) Write a program to display the date, month and year of the current date on separate lines. For
example if the current date is December 5, 2000, then the output should be as follows:

Date : 05

Month : 12

Year : 2000

Re-write the above program using user-defined data types.

Exercise 02.01 ABAP Basics – Data Handling

- Page - Page 3 of of 8 - -

6) Write a program to display the hours, minutes and seconds components of the current time on

separate lines. For example if the current time is 10:20:43, then the output should be as follows:

Hours : 10

Minutes : 20

Seconds : 43

Re-write the above program using user-defined data types.

7) Write a program to display the decimal equivalent values of the following hexadecimal numbers.
The

output should be as follows:

Hexadecimal value Decimal equivalent

A01

BDF

12345

1F80

Conversion Rules for Elementary Data Types

Re-write the above program using user-defined data types.

8) Write a program to display the hexadecimal equivalent values of the following decimal numbers.
The

output should be as follows:

Decimal value Hexadecimal equivalent

984601

21589

2642345

15680
Re-write the above program using user-defined data types.

9) What is the maximum permissible value for a hexadecimal data object with length 4?

FFFFFFFF.

10) Write a program to display the last day of the next month and display it in

DD/MM/YYYY format.

11) Declare the following variables.

a) F1 type F value ‘9.99’.

b) I1 type I.

c) I2 type I value 9.

d) F2 type F.

e) C1(6) type C value ‘1A2B3C’.

f) C2(3) type C.

g) N1(6) type N.

h) P1 type p.

i) P2 type p decimals 2.

Using the above variables, do the following and explain the output.

 Move F1 to I1 and display both the variables.

 Move I2 to F2 and display both the variables.

Exercise 02.01 ABAP Basics – Data Handling

- Page - Page 4 of of 8 - -

 Move C1 to C2 and display both the variables.

 Move C1 to N1 and display both the variables.

 Move F1 to P1 and display both the variables.

 Move F1 to P2 and display both the variables.

12) Write a program to declare the following variables.

a) F1(8) type C value 'ABCDEFGH'

b) F2(6) type C

c) F3(10) type C

Using the above variables, do the following.

 Move F1 to F2 and display F1 & F2

 Clear the contents of F2


 Move the value “EF” in F1 to F2 at position 3 and display F2

 Move the value “CD” in F1 to F2 at position 1 and display F2

 Move the value “A” in F1 to F3 at position 0 and display F3

 Move the value “H” in F1 to F3 at position 9 and display F3

 Move F2 to F3 at position 2 and display F3

Finding Character Strings

13) Write a program to declare the following field strings.

ADDRESS

FIRSTNAME(20) type C

SURNAME(20) type C

INITIALS(4) type C

STREET(20) type C

NUMBER type I

POSTCODE type N

CITY(20) type C

NAME

SURNAME(20) type C

FIRSTNAME(20) type C

POSTCOD type N

INITIALS(4) type C

TITLE(10) type C

CITY(20) type C

Initialize the field string ADDRESS with the respective data and fill the corresponding fields in field

string NAME and display both the field strings.

14) Declare the following variables.

a) NUMBER TYPE F VALUE '4.3',

b) TEXT (10),

c) FLOAT TYPE F,

d) PACK TYPE P DECIMALS 1.

Do the following using WRITE TO statement with above variables and explain the output.

 Move NUMBER to TEXT and display both the variables.


Exercise 02.01 ABAP Basics – Data Handling

- Page - Page 5 of of 8 - -

 Move NUMBER to FLOAT with formatting option EXPONENT 2and display both the variables.

 Move NUMBER to PACK and display both the variables.

 Move NUMBER to PACK using the MOVE statement and display both the variables.

15) Declare the following variables.

NAME(4) VALUE 'PBC',

SOURCE(5) VALUE 'INDIA',

TARGET(11)

Display the output ‘PBC INDIA’ by using only TARGET field in WRITE statement. (Don’t use MOVE)

16) DATA: FIELD_NAME (11),

MIDDLE_NAME(5) VALUE 'James',

FULL_NAME(18) VALUE 'Robert Smith',

Fill the FULL_NAME field with ‘Robert James Smith’ and display. (Don’t use MIDDLE_NAME field
while

moving the contents to FULL_NAME)

17) DATA: A(35) TYPE C VALUE ‘ Rolling stone gathers’,

B(2) TYPE C VALUE ‘no’,

C(4) TYPE C VALUE ‘moss’.

Display the following output using the above fields:

‘Rolling stone gathers no moss’

‘Rollingstonegathersnomoss’

18) DATA : A(16) TYPE C VALUE ‘Have a nice day’,

B(4) TYPE C VALUE ‘good’,

C(17) TYPE C VALUE ‘ 2 4 6 0 1 3 5’.

Display the following output using the above fields:

have a nice day.

HAVE A NICE DAY.

HAVE A nIcEdAy.

Have a good day.

H2v4 6 0i1e3d5y
19) Write a program to achieve the following output.

Name Salary

Abc 1000

Xyz 2000

Total 3000

Output the above data and print the sum of salary under the salary statement without using position

in write statement.

20) Write a program to declare the following variables.

STRING (20),

NUMBER (8) TYPE C VALUE '123456',

Exercise 02.01 ABAP Basics – Data Handling

- Page - Page 6 of of 8 - -

Using the above variables and the WRITE TO statement, do the following.

 Move NUMBER to STRING at position 8 length 12 LEFT JUSTIFIED and display NUMBER &

STRING.

 Clear the contents of STRING.

 Move NUMBER to STRING at position 8 length 12 CENTERED and display NUMBER & STRING.

 Clear the contents of STRING

 Move NUMBER to STRING at position 8 length 12 RIGHT JUSTIFIED and display NUMBER &

STRING

 Clear the contents of STRING

21) Implement the following piece of code in ABAP with the following values for the data objects

W_FLOAT1 and W_FLOAT2. What are your observations and justify the results.

W_FLOAT1 W_FLOAT2

9.6 3.2

-9.6 3.2

9.6 -3.2

-9.6 -3.2

DATA: W_FLOAT1 TYPE F,

W_FLOAT2 TYPE F,

W_RESULT TYPE I.
W_RESULT = W_FLOAT1 DIV W_FLOAT2.

WRITE:/ W_RESULT.

__________

22) Write a program to find and display the Celsius temperatures where the corresponding
Fahrenheit

temperature is:

a) Equal to the Celsius temperature,

b) Double the Celsius temperature, and

c) Half the Celsius temperature

Also display the corresponding Fahrenheit temperatures.

23) Write a program to accept a number from the user and print it out digit by digit as a series of
words.

For example: 1253 – One thousand two hundred and fifty three.

24) Write a program to accept a string and identify and print all the distinct characters in the string in
the

order of their appearance. For Example - PROGRAMMING IS FUN, PRINT AS POSFU

25) Observe the following program:

DATA: PI TYPE P ,

RADIUS TYPE I VALUE 10,

AREA TYPE P DECIMALS 2.

PI = 22 / 7.

AREA = PI * RADIUS * RADIUS.

WRITE:/ AREA.

Alter the output of the above program without making any changes to the code.

26) Write and execute the following piece of code in ABAP.

DATA: PACK TYPE P VALUE 1000,

DATE TYPE D,

TIME TYPE T.

DATE = TIME = PACK.

Exercise 02.01 ABAP Basics – Data Handling

- Page - Page 7 of of 8 - -

WRITE:/ DATE, TIME.


Explain the results.

27) Display the date and time after PI days from now. Output the current date, current time, future
date

and future time. (PI = 22 / 7). Explain the result.

28) What are all the data types that are right justified in the output?

29) Using only assignment operators and starting with the float value 45.2347, get the following
outputs.

a) ***

b) 45234700

c) 000045

d) 34700001

____________________

30) Write a program to find and display the greatest prime number less than the number entered by
the

user. Optimize the program so that the run time is less.

31) Write a program to convert a given number from the specified source number system to the
specified

target number system. Take the source number, source number system and target number system
as

inputs.

32) Given a string of numerals, write a program that calculates and displays the maximum number

possible using those numerals.

For example, if the string entered is 368824, the output should be 886432.

33) Given an integer, write a program to output the number with the digits reversed.

For example, if the number entered is 23987446, the output should be 64478932.

34) Write a program to accept a number range and an exception range (in the form of 4
parameters).

Display the numbers in the given range excluding those specified in the exception range.

For example, if the user enters 23, 69, 26 and 67 then the output should be 23, 24, 25, 68 and 69.

35) Write a program to accept a string and a character from the user and display the total number of

times that character appears in the string. Also display the position and word in which the character

appears.
36) Write a program to find the sum & product of the first “N” Armstrong numbers. The user should

enter a value for “N”. (Word of caution: See that the user should not enter a value for “N” which is

more than 5).

37) Accept a string from the user and for each character of the string, display the character that is

immediately next to it in the alphabet and form another string. For example, if the user enters

“HELLO”, then the output should be “IFMMP”.

38) Write a program to accept a number ‘N’ from the user and display the first ‘N’ numbers of the

fibonacci series. Sample - Fibonacci series: 1, 1, 2, 3, 5, 8, 13, 21, 34…

39) Write a program to find out the factorial of a given number.

Exercise 02.01 ABAP Basics – Data Handling

- Page - Page 8 of of 8 - -

40) Write a program to accept a string from the user and display all the possible string combinations
that

can be made using the characters of the given string. For example if the user enters a string “A1C”,

then the program should display

A1C

AC1

1CA

1AC

CA1

C1A.

41) Write a program to get the following output.

Accept a character from the user. For the given character ‘I’ the following output is obtained.

ABCDEFGHIHGFEDCBA

ABCDEFGHHGFEDCBA

ABCDEFGGFEDCBA

ABCDEFFEDCBA

ABCDEEDCBA

ABCDDCBA

ABCCBA

ABBA
AA

42) Write a program to generate the following output.

Accept the number from the user. For the given number 5 the following output is obtained.

12345

5432

234

43

You might also like