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 print only one line item at every page in smart forms in main window .for ex for sales order i will get so many items i need to display only at one page like 1st line at one page and second line at 2nd page .pls answer itttt.
how to transport abap workbench objects
How do you know that data is updated in call transaction
write the codes for how to handle currency and date fields in bdc
how can u write in single program call transaction and session method logic? if u
2 Answers Enteg Technologies, Wipro,
Explain what is runtime analysis?
What is the exact difference between pooled table and cluster table and explain with examples?
what is the standard program to check the consistency of partner profiles?
Internal table itab contains some records. If the code is like this : LOOP AT ITAB. APPEND ITAB. ENDLOOP. What ill be the result??
What is design pattern? Provide example .Why are we using it?
What is the MM Flow with Transaction Codes
1.Which of the following is not an EXIT command? options: BACK, CANCEL, STOP, EXIT? 2.To write certain contents in sap script without skipping to the next page, which command is used? Options: ADDRESS...ENDADDRESS, PROTECT...ENDPROTECT, AT...ENDAT 3. When using a table control in module pool, which statement has to present in both PAI and PBO. options : FIELD, LOOP..ENDLOOP, CHAIN...ENDCHAIN 4. Lock objects are : options : FUNCTION MODULES, PROGRAMS, TABLES
SAP Basis (1262)
SAP ABAP (3939)
SAPScript (236)
SAP SD (Sales & Distribution) (2717)
SAP MM (Material Management) (912)
SAP QM (Quality Management) (99)
SAP PP (Production Planning) (523)
SAP PM (Plant Maintenance) (252)
SAP PS (Project Systems) (138)
SAP FI-CO (Financial Accounting & Controlling) (2766)
SAP HR (Human Resource Management) (1180)
SAP CRM (Customer Relationship Management) (432)
SAP SRM (Supplier Relationship Management) (132)
SAP APO (Advanced Planner Optimizer) (92)
SAP BW (Business Warehouse) (896)
SAP Business Workflow (72)
SAP Security (597)
SAP Interfaces (74)
SAP Netweaver (282)
SAP ALE IDocs (163)
SAP Business One (110)
SAP BO BOBJ (Business Objects) (388)
SAP CPS (Central Process Scheduling) (14)
SAP GTS (Global Trade Services) (21)
SAP Hybris (132)
SAP HANA (700)
SAP PI (Process Integration) (113)
SAP PO (Process Orchestration) (25)
SAP BI (Business Intelligence) (174)
SAP BPC (Business Planning and Consolidation) (38)
SAP BODS (Business Objects Data Services) (49)
SAP BODI (Business Objects Data Integrator) (26)
SAP Ariba (9)
SAP Fiori (45)
SAP EWM (Extended Warehouse Management) (58)
Sap R/3 (150)
SAP FSCM Financial Supply Chain Management (101)
SAP WM (Warehouse Management) (31)
SAP GRC (Governance Risk and Compliance) (64)
SAP MDM (Master Data Management) (0)
SAP MRS (Multi Resource Scheduling) (0)
SAP ESS MSS (Employee Manager Self Service) (13)
SAP CS (Customer Service) (0)
SAP TRM (Treasury and Risk Management) (0)
SAP Web Dynpro ABAP (198)
SAP IBP (Integrated Business Planning) (0)
SAP OO-ABAP (Object Oriented ABAP) (70)
SAP S/4 HANA Finance (Simple Finance) (143)
SAP FS-CD (Collections and Disbursements) (0)
SAP PLM (Product Lifecycle Management) (0)
SAP SuccessFactors (33)
SAP Vistex (0)
SAP ISR (IS Retail) (28)
SAP IdM (Identity Management) (0)
SAP IM (Investment Management) (0)
SAP UI5 (59)
SAP SCM (Supply Chain Management) (51)
SAP XI (Exchange Infrastructure) (49)
SAP Cloud Platform (34)
SAP Testing (89)
SAP SolMan (Solution Manager) (63)
SAP MaxDB (116)
SAP GUI (15)
SAP AllOther (329)