You are on page 1of 11

Exercise 02.

01 - ABAP Basics Data Handling Note: All the following objects to be


created should follow the naming convention YUSERID_##$$%%. ##$$ indicates the
exercise number (02.01 for this assignment) and %% indicates the question number
in the exercise. USERID indicates the network userid. 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 a
n 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 objec
t 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 appea
rs on a new line. on separate lines. For example if the current date is December
5, 2000,
5) Write a program to display the date, month and year of the current date

Exercise 02.01 ABAP Basics Data Handling then the output should be as follows: D
ate : 05 Month : 12 Year : 2000 Re-write the above program using user-defined da
ta types.
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 R
e-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 valu
e Decimal equivalent A01 BDF 12345 1F80 Re-write the above program using user-de
fined 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 Hexade
cimal equivalent 984601 21589 2642345 15680 Re-write the above program using use
r-defined data types. 9) What is the maximum permissible value for a hexadecimal
data object with length 4?
- Page 2 of 10 -

Exercise 02.01 ABAP Basics Data Handling 10) Write a program to display the last
day of the next month and display it in DD/MM/YYYY format. 11) a) b) c) d) e) f
) g) h) i) Declare the following variables. F1 type F value 9.99. I1 type I. I2 ty
pe I value 9. F2 type F. C1(6) type C value 1A2B3C. C2(3) type C. N1(6) type N. P1
type p. P2 type p decimals 2.
Using the above variables, do the following and explain the output. 12) Move F1
to I1 and display both the variables. Move I2 to F2 and display both the variabl
es. 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. 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 abov
e variables, do the following. Move F1 to F2 and display F1 & F2 Clear the conte
nts of F2 Move the value EF in F1 to F2 at position 3 and display F2 Move the valu
e CD in F1 to F2 at position 1 and display F2 Move the value A in F1 to F3 at positi
on 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 13) Write a program to declare the follow
ing field strings.
- Page 3 of 10 -

Exercise 02.01 ABAP Basics Data Handling


ADDRESS FIRSTNAME(20) SURNAME(20) INITIALS(4) STREET(20) NUMBER POSTCODE CITY(20
) NAME SURNAME(20) FIRSTNAME(20) POSTCOD INITIALS(4) TITLE(10) CITY(20)
type C type C type C type C type I type N type C type C type C type N type C typ
e C type C
Initialize the field string ADDRESS with the respective data and fill the corres
ponding fields in field string NAME and display both the field strings. 14) a) b
) c) d) Declare the following variables. NUMBER TYPE F VALUE 4.3 , TEXT (10), F
LOAT TYPE F, PACK TYPE P DECIMALS 1.
Do the following using WRITE TO statement with above variables and explain the o
utput. Move NUMBER to TEXT and display both the variables. 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 statemen
t and display both the variables. 15) Declare the following variables.
- Page 4 of 10 -

Exercise 02.01 ABAP Basics Data Handling


NAME(4) VALUE SOURCE(5) VALUE TARGET(11)
YASH , INDIA ,
Display the output YASH INDIA by using only TARGET field in WRITE statement. (Dont
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 displa
y. (Dont use MIDDLE_NAME field while moving the contents to FULL_NAME) 17) DATA:
A(35) TYPE C VALUE Rolling stone B(2) TYPE C VALUE no, C(4) TYPE C VALUE moss. Displ
ay the following output using the above fields: Rolling stone gathers no moss Rolli
ngstonegathersnomoss DATA : A(16) TYPE C VALUE Have a nice day, B(4) TYPE C VALUE go
od, 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 nIcE dAy. Have a good day. H2v
4 6 0i1e3d5y Write a program to achieve the following output. Name Abc Xyz Total
Salary 1000 2000 3000
- Page 5 of 10 gathers,
18)
19)

Exercise 02.01 ABAP Basics Data Handling


Output the above data and print the sum of salary under the salary statement wit
hout using position in write statement. 20) Write a program to declare the follo
wing variables. STRING (20), NUMBER (8) TYPE C VALUE 123456 , Using the above v
ariables 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 conte
nts of STRING. Move NUMBER to STRING at position 8 length 12 CENTERED and displa
y NUMBER & STRING. Clear the contents of STRING Move NUMBER to STRING at positio
n 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 valu
es for the data objects W_FLOAT1 and W_FLOAT2. What are your observations and ju
stify the results. W_FLOAT1 9.6 -9.6 9.6 -9.6 W_FLOAT2 3.2 3.2 -3.2 -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.
- Page 6 of 10 -

Exercise 02.01 ABAP Basics Data Handling 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) Observe the following program:
DATA: PI TYPE P, RADIUS TYPE I VALUE 10, AREA TYPE P DECIMALS 2. PI = 22 / 7. AR
EA = PI * RADIUS * RADIUS. WRITE:/ AREA. Alter the output of the above program w
ithout making any changes to the code. DATA: PACK TYPE P VALUE 1000, DATE TYPE D
, TIME TYPE T. DATE = TIME = PACK. WRITE:/ DATE, TIME. Explain the results.
24) Write and execute the following piece of code in ABAP.
25) Display the date and time after PI days from now. Output the current date, c
urrent time, future date and future time. (PI = 22 / 7). Explain the result. 26)
What are all the data types that are right justified in the output?
Integer Data Types(All three).
27) Using only assignment operators and starting with the float value
45.2347, get the following outputs. a) *** b) 45234700 c) 000045
- Page 7 of 10 -

Exercise 02.01 ABAP Basics Data Handling d) 34700001 28) 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. 29) Write a program to conve
rt a given number from the specified source number system to the specified targe
t number system. Take the source number, source number system and target number
system as inputs. 30) Given a string of numerals, write a program that calculate
s and displays the maximum number possible using those numerals. For example, if
the string entered is 368824, the output should be 886432. 31) 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. 32) Write a prog
ram 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 excep
tion range. For example, if the user enters 23, 69, 26 and 67 then the output sh
ould be 23, 24, 25, 68 and 69. 33) Write a program to accept a string and a char
acter 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 appear
s. 34) 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 n
ot enter a value for N which is more than 5). 35) Write a program to find out whet
her the given number is a perfect number or not.
- Page 8 of 10 -

Exercise 02.01 ABAP Basics Data Handling 36) Write a program to display a bar gr
aph based on the numeric string entered by the user. For example if the user ent
ers, 7084542593 then the output should be as follows:
37) Write a program to accept a string from the user and display all the possibl
e 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. 38) Write a program to get the following output. Accept a c
haracter from the user. For the given character I the following output is obtained
. ABCDEFGHIHGFEDCBA ABCDEFGH HGFEDCBA ABCDEFG GFEDCBA ABCDEF FEDCBA ABCDE EDCBA
ABCD DCBA ABC CBA AB BA A A
- Page 9 of 10 -

Exercise 02.01 ABAP Basics Data Handling 39) Write a program to generate the fol
lowing output. Accept the number from the user. For the given number 5 the follo
wing output is obtained. 1 5 2 4 3 2345 432 34 3
- Page 10 of 10 -