2.1 ABAP Basics Data Handling 1

13
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)

Transcript of 2.1 ABAP Basics Data Handling 1

Page 1: 2.1 ABAP Basics Data Handling 1

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) InterestPaidb) A1234bCDefc) Si-intd) percent.e) SPACEf) Dist in kmg) Ot+payh) Na,mei) 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,

Page 2: 2.1 ABAP Basics Data Handling 1

Exercise 02.01 ABAP Basics – Data Handling

then the output should be as follows:Date : 05Month : 12Year : 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 : 10Minutes : 20Seconds : 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 A01BDF123451F80

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 98460121589264234515680

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 -

Page 3: 2.1 ABAP Basics Data Handling 1

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) 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. 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

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

- Page 3 of 10 -

Page 4: 2.1 ABAP Basics Data Handling 1

Exercise 02.01 ABAP Basics – Data Handling

ADDRESSFIRSTNAME(20) type C SURNAME(20) type CINITIALS(4) type CSTREET(20) type CNUMBER type IPOSTCODE type NCITY(20) type C

NAMESURNAME(20) type CFIRSTNAME(20) type CPOSTCOD type NINITIALS(4) type CTITLE(10) type CCITY(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. 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 'YASH',

- Page 4 of 10 -

Page 5: 2.1 ABAP Basics Data Handling 1

Exercise 02.01 ABAP Basics – Data Handling

SOURCE(5) VALUE 'INDIA',TARGET(11)

Display the output ‘YASH 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 nIcE dAy.Have a good day.H2v4 6 0i1e3d5y

19) Write a program to achieve the following output.

Name SalaryAbc 1000Xyz 2000

Total 3000

- Page 5 of 10 -

Page 6: 2.1 ABAP Basics Data Handling 1

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 W_FLOAT2 9.6 3.2-9.6 3.29.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,

- Page 6 of 10 -

Page 7: 2.1 ABAP Basics Data Handling 1

Exercise 02.01 ABAP Basics – Data Handling

b) Double the Celsius temperature, andc) Half the Celsius temperatureAlso 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.

24) 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.WRITE:/ DATE, TIME.Explain the results.

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) 45234700c) 000045d) 34700001

- Page 7 of 10 -

Page 8: 2.1 ABAP Basics Data Handling 1

Exercise 02.01 ABAP Basics – Data Handling

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.

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:

- Page 8 of 10 -

Page 9: 2.1 ABAP Basics Data Handling 1

Exercise 02.01 ABAP Basics – Data Handling

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 displayA1CAC11CA1ACCA1C1A.

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.

A B C D E F G H I H G F E D C B AA B C D E F G H H G F E D C B AA B C D E F G G F E D C B AA B C D E F F E D C B AA B C D E E D C B AA B C D D C B AA B C C B AA B B AA A

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.

- Page 9 of 10 -

Page 10: 2.1 ABAP Basics Data Handling 1

Exercise 02.01 ABAP Basics – Data Handling

1 2 3 4 55 4 3 22 3 44 33

- Page 10 of 10 -