Hi, My question is " How to display 3rd highest salary
record from the internal table. The internal table has 2
fields named emno(Employee number) and salary.".
Send answer to my mail shaiksha.it@gmail.com.
Thanking you.
Answers were Sorted based on User's Feedback
Answer / dileep kumar chinnaiah
READ TABLE gt_emp INTO gw_emp INDEX 3.
Does not work's if two employees has same salaries. So stop
following this procedure.
The Interviewer exactly looking for Control break statements.
use Sort descending by salary & loop internal table. &
maintain a counter under "AT NEW" & catch the value of
employee ID, when your condition triggers.
Is This Answer Correct ? | 15 Yes | 2 No |
Answer / deepak kumar
SORT THE INTERNAL TABLE IN DECENDING ORDER
READ TABLE ITAB INTO WA_ITAB INDEX 3.
WRITE:/ WA_ITAB-FIELDNAME.
Is This Answer Correct ? | 10 Yes | 6 No |
Answer / 7hills
DATA :
BEGIN OF emp,
xcode TYPE STRING,
xname TYPE STRING,
xbasic TYPE P DECIMALS 2,
END OF EMP,
gt_emp LIKE TABLE OF emp,
gw_emp LIKE LINE OF gt_emp.
*EMP 1*
CLEAR gw_emp.
gw_emp-xcode = 'EMP001'.
gw_emp-xname = 'JAMES'.
gw_emp-xbasic = '4500'.
APPEND gw_emp TO gt_emp.
*EMP 2*
CLEAR gw_emp.
gw_emp-xcode = 'EMP002'.
gw_emp-xname = 'TOM'.
gw_emp-xbasic = '2450'.
APPEND gw_emp TO gt_emp.
*EMP 3*
CLEAR gw_emp.
gw_emp-xcode = 'EMP003'.
gw_emp-xname = 'JACK'.
gw_emp-xbasic = '2300'.
APPEND gw_emp TO gt_emp.
*EMP 4*
CLEAR gw_emp.
gw_emp-xcode = 'EMP004'.
gw_emp-xname = 'NAGS'.
gw_emp-xbasic = '2200'.
APPEND gw_emp TO gt_emp.
*EMP 5*
CLEAR gw_emp.
gw_emp-xcode = 'EMP005'.
gw_emp-xname = 'GUNTA'.
gw_emp-xbasic = '2000'.
APPEND gw_emp TO gt_emp.
CLEAR gw_emp.
WRITE : /.
WRITE : / 'Internal table before sorting', /.
LOOP AT gt_emp INTO gw_emp.
WRITE :/ gw_emp-xcode, gw_emp-xname, gw_emp-xbasic.
ENDLOOP.
WRITE : /.
WRITE : / 'Internal table after sorting', /.
SORT gt_emp ASCENDING BY xbasic DESCENDING.
LOOP AT gt_emp INTO gw_emp.
WRITE :/ gw_emp-xcode, gw_emp-xname, gw_emp-xbasic.
ENDLOOP.
WRITE : /.
WRITE : / 'Displaying 3rd highest salary from the itab', /.
CLEAR gw_emp.
READ TABLE gt_emp INTO gw_emp INDEX 3.
WRITE :/ gw_emp-xcode, gw_emp-xname, gw_emp-xbasic.
Is This Answer Correct ? | 4 Yes | 1 No |
Answer / jitendra
TYPES : BEGIN OF TY,
ENO(6) TYPE c,
SAL TYPE LABST,
END OF TY.
DATA : ITAB TYPE STANDARD TABLE OF TY,
WA_IT TYPE TY.
DATA : SAAL TYPE LABST.
WA_IT-ENO = '1000'.
WA_IT-SAL = '10000'.
APPEND WA_IT TO ITAB.
CLEAR WA_IT.
WA_IT-ENO = '1001'.
WA_IT-SAL = '19000'.
APPEND WA_IT TO ITAB.
CLEAR WA_IT.
WA_IT-ENO = '1002'.
WA_IT-SAL = '10500'.
APPEND WA_IT TO ITAB.
CLEAR WA_IT.
WA_IT-ENO = '1003'.
WA_IT-SAL = '10080'.
APPEND WA_IT TO ITAB.
CLEAR WA_IT.
WA_IT-ENO = '1004'.
WA_IT-SAL = '10200'.
APPEND WA_IT TO ITAB.
CLEAR WA_IT.
WA_IT-ENO = '1006'.
WA_IT-SAL = '10400'.
APPEND WA_IT TO ITAB.
CLEAR WA_IT.
WA_IT-ENO = '1005'.
WA_IT-SAL = '10400'.
APPEND WA_IT TO ITAB.
CLEAR WA_IT.
SORT ITAB BY SAL DESCENDING.
READ TABLE ITAB INTO WA_IT INDEX '3'.
SAAL = WA_IT-SAL.
clear wa_it.
LOOP AT ITAB INTO WA_IT where sal eq saal.
*append wa_it to itab1.
write :/ wa_it-eno, 10 wa_it-sal.
ENDLOOP.
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / tiki patra
SORT itab DECENDING salary.
DELETE ADJACENT DUPLICATE COMPARING salary.
READ TABLE itab into wa INDEX 3.
WRITE:/ wa-salary.
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / nandana sai
TYPES : BEGIN OF ty,
eno(6) TYPE c,
sal TYPE labst,
END OF ty.
DATA : itab TYPE STANDARD TABLE OF ty,
wa_it TYPE ty,
itab1 TYPE STANDARD TABLE OF ty,
wa_it1 TYPE ty.
DATA : saal TYPE labst.
wa_it-eno = '1000'.
wa_it-sal = '10000'.
APPEND wa_it TO itab.
CLEAR wa_it.
wa_it-eno = '1001'.
wa_it-sal = '19000'.
APPEND wa_it TO itab.
CLEAR wa_it.
wa_it-eno = '1002'.
wa_it-sal = '10500'.
APPEND wa_it TO itab.
CLEAR wa_it.
wa_it-eno = '1003'.
wa_it-sal = '10080'.
APPEND wa_it TO itab.
CLEAR wa_it.
wa_it-eno = '1004'.
wa_it-sal = '10200'.
APPEND wa_it TO itab.
CLEAR wa_it.
wa_it-eno = '1006'.
wa_it-sal = '10400'.
APPEND wa_it TO itab.
CLEAR wa_it.
wa_it-eno = '1005'.
wa_it-sal = '10400'.
APPEND wa_it TO itab.
CLEAR wa_it.
wa_it-eno = '1007'.
wa_it-sal = '19000'.
APPEND wa_it TO itab.
CLEAR wa_it.
SORT itab BY sal DESCENDING.
itab1 = itab.
DELETE ADJACENT DUPLICATES FROM itab1 COMPARING sal.
READ TABLE itab1 INTO wa_it1 INDEX '3'.
saal = wa_it1-sal.
LOOP AT itab INTO wa_it WHERE sal EQ saal.
WRITE :/ wa_it-eno, 10 wa_it-sal.
ENDLOOP.
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / shaiksha
Extract the content of 2nd field Using... <Select distinct
salary from ztable_emp into .... order by descending.>. Now
you can have all records in it table, exactly 3rd record
itself is highest salary record. Then basing salary extract
entire record using select statement.
Is This Answer Correct ? | 4 Yes | 4 No |
Answer / sivaramakrishna
first sort the internal table and now using do statement
for 3 repetetions using local varieble. inside do
statement use the loop statement for reading the records
from internal table to work area.
Is This Answer Correct ? | 2 Yes | 3 No |
how to create view in bdc..??
Can we display a list in a pop-up screen other than full-size stacked list?
what are performence analysis techniques?
What is meant by read lock? : sap abap data dictionary
Hi guy.. i have to face an interview in a couple of day.. so can you please give me some good and tough question on abap.
what is ASAP methodology? How many phases are there? what is the percentage of each phase?
How will you do implicit enhancement?
What is the significance of hide?
what is table maitainance generator and how to create that? what is transaction code?
how we can take a file from Presentation server to Application server?
What are the errors occurred in a report?
What is the difference between open_form and close_form?