Exercise 02
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
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
ABAP is easy.
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
- 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
7) Write a program to display the decimal equivalent values of the following hexadecimal numbers.
The
A01
BDF
12345
1F80
8) Write a program to display the hexadecimal equivalent values of the following decimal numbers.
The
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.
b) I1 type I.
c) I2 type I value 9.
d) F2 type F.
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.
- Page - Page 4 of of 8 - -
b) F2(6) type C
c) F3(10) type C
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
b) TEXT (10),
c) FLOAT TYPE F,
Do the following using WRITE TO statement with above variables and explain the output.
- Page - Page 5 of of 8 - -
Move NUMBER to FLOAT with formatting option EXPONENT 2and display both the variables.
Move NUMBER to PACK using the MOVE statement and display both the variables.
TARGET(11)
Display the output ‘PBC INDIA’ by using only TARGET field in WRITE statement. (Don’t use MOVE)
Fill the FULL_NAME field with ‘Robert James Smith’ and display. (Don’t use MIDDLE_NAME field
while
‘Rollingstonegathersnomoss’
HAVE A nIcEdAy.
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.
STRING (20),
- 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.
Move NUMBER to STRING at position 8 length 12 CENTERED and display NUMBER & STRING.
Move NUMBER to STRING at position 8 length 12 RIGHT JUSTIFIED and display NUMBER &
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
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:
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
DATA: PI TYPE P ,
PI = 22 / 7.
WRITE:/ AREA.
Alter the output of the above program without making any changes to the code.
DATE TYPE D,
TIME TYPE T.
- Page - Page 7 of of 8 - -
27) Display the date and time after PI days from now. Output the current date, current time, future
date
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
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
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
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
38) Write a program to accept a number ‘N’ from the user and display the first ‘N’ numbers of the
- 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”,
A1C
AC1
1CA
1AC
CA1
C1A.
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
Accept the number from the user. For the given number 5 the following output is obtained.
12345
5432
234
43