2.1 ABAP Basics Data Handling 1

You might also like

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

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 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. 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: Date : 05 Month : 12 Year : 2000 Re-write the above program using user-defined data 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 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 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?

- 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 type 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 variables. 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 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 13) Write a program to declare the following 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 type C 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) a) b) c) d) Declare the following variables. NUMBER TYPE F VALUE '4.3', TEXT (10), FLOAT TYPE F, 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. 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.

- 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 display. (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. Display the following output using the above fields: Rolling stone gathers no moss Rollingstonegathersnomoss 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 nIcE dAy. Have a good day. H2v4 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 without using position in write statement. 20) Write a program to declare the following variables. STRING (20), NUMBER (8) TYPE C VALUE '123456', 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 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. AREA = PI * RADIUS * RADIUS. WRITE:/ AREA. Alter the output of the above program without 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, current 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 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. 30) 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. 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 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. 33) 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. 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 not enter a value for N which is more than 5). 35) Write a program to find out whether 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 graph based on the numeric string entered by the user. For example if the user enters, 7084542593 then the output should be as follows:

37) 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. 38) 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 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 following output. Accept the number from the user. For the given number 5 the following output is obtained. 1 5 2 4 3 2345 432 34 3

- Page 10 of 10 -

You might also like