Skip to Content
author's profile photo Former Member
Former Member

DiSplaying Records

Hi,

This is my program.

I wnat to display top3 records, records which are at odd position and top3 records with highest salary.

REPORT ZAC_TAB10.

*LINE TYPE:

TYPES:

BEGIN OF TY_EMP,

EMPID(4) TYPE N,

ENAME(20) TYPE C,

DEPT(4) TYPE C,

SALARY TYPE I,

END OF TY_EMP.

DATA:

FS_EMP TYPE TY_EMP,

IT_EMP TYPE TABLE OF TY_EMP.

FS_EMP-EMPID = 1010.

FS_EMP-ENAME = 'XX'.

FS_EMP-DEPT = 'D100'.

FS_EMP-SALARY = 10000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 1011.

FS_EMP-ENAME = 'YY'.

FS_EMP-DEPT = 'D100'.

FS_EMP-SALARY = 11000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 1001.

FS_EMP-ENAME = 'ZZ'.

FS_EMP-DEPT = 'D200'.

FS_EMP-SALARY = 12000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 1008.

FS_EMP-ENAME = 'XY'.

FS_EMP-DEPT = 'D200'.

FS_EMP-SALARY = 10000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 1002.

FS_EMP-ENAME = 'XZ'.

FS_EMP-DEPT = 'D300'.

FS_EMP-SALARY = 8000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 1005.

FS_EMP-ENAME = 'YX'.

FS_EMP-DEPT = 'D300'.

FS_EMP-SALARY = 9500.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 1002.

FS_EMP-ENAME = 'YZ'.

FS_EMP-DEPT = 'D300'.

FS_EMP-SALARY = 9500.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 1007.

FS_EMP-ENAME = 'AA'.

FS_EMP-DEPT = 'D100'.

FS_EMP-SALARY = 10500.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 1003.

FS_EMP-ENAME = 'BB'.

FS_EMP-DEPT = 'D200'.

FS_EMP-SALARY = 12000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 1006.

FS_EMP-ENAME = 'CC'.

FS_EMP-DEPT = 'D100'.

FS_EMP-SALARY = 15000.

APPEND FS_EMP TO IT_EMP.

LOOP AT IT_EMP INTO FS_EMP.

WRITE:/ FS_EMP-EMPID,FS_EMP-ENAME,FS_EMP-DEPT,FS_EMP-SALARY.

Add a comment
10|10000 characters needed characters exceeded

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jul 12, 2007 at 08:36 AM

    Here is the porgram for all

    <b>1.top3 records,

    2.records which are at odd position and

    3. top3 records with highest salary.</b>

    REPORT ZAC_TAB10.
    *LINE TYPE:
    TYPES:
    
    BEGIN OF TY_EMP,
    EMPID(4) TYPE N,
    ENAME(20) TYPE C,
    DEPT(4) TYPE C,
    SALARY TYPE I,
    END OF TY_EMP.
    
    
    DATA:
    FS_EMP TYPE TY_EMP,
    IT_EMP TYPE TABLE OF TY_EMP.
    FS_EMP-EMPID = 1010.
    FS_EMP-ENAME = 'XX'.
    FS_EMP-DEPT = 'D100'.
    FS_EMP-SALARY = 10000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1011.
    FS_EMP-ENAME = 'YY'.
    FS_EMP-DEPT = 'D100'.
    FS_EMP-SALARY = 11000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1001.
    FS_EMP-ENAME = 'ZZ'.
    FS_EMP-DEPT = 'D200'.
    FS_EMP-SALARY = 12000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1008.
    FS_EMP-ENAME = 'XY'.
    FS_EMP-DEPT = 'D200'.
    FS_EMP-SALARY = 10000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1002.
    FS_EMP-ENAME = 'XZ'.
    FS_EMP-DEPT = 'D300'.
    FS_EMP-SALARY = 8000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1005.
    FS_EMP-ENAME = 'YX'.
    FS_EMP-DEPT = 'D300'.
    FS_EMP-SALARY = 9500.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1002.
    FS_EMP-ENAME = 'YZ'.
    FS_EMP-DEPT = 'D300'.
    FS_EMP-SALARY = 9500.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1007.
    FS_EMP-ENAME = 'AA'.
    FS_EMP-DEPT = 'D100'.
    FS_EMP-SALARY = 10500.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1003.
    FS_EMP-ENAME = 'BB'.
    FS_EMP-DEPT = 'D200'.
    FS_EMP-SALARY = 12000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1006.
    FS_EMP-ENAME = 'CC'.
    FS_EMP-DEPT = 'D100'.
    FS_EMP-SALARY = 15000.
    APPEND FS_EMP TO IT_EMP.
    
    LOOP AT IT_EMP INTO FS_EMP.
    if sy-tabix le  3 .
    if sy-tabix eq  1 .
    Write  : ' Top 3  Records   ' .
    endif .
    WRITE:/ FS_EMP-EMPID,FS_EMP-ENAME,FS_EMP-DEPT,FS_EMP-SALARY.
    endif .
    endloop .
    
    skip  2.
    data  :  a  like   sy-tabix .
    LOOP AT IT_EMP INTO FS_EMP.
    if sy-tabix eq  1 .
    Write  : ' Odd records   ' .
    endif .
    a = ( sy-tabix mod 2 ) .
    if  a =  1.
    WRITE:/ FS_EMP-EMPID,FS_EMP-ENAME,FS_EMP-DEPT,FS_EMP-SALARY.
    endif .
    
    endloop .
    
    skip  2.
    
    sort IT_EMP  by SALARY   DESCENDING .
    LOOP AT IT_EMP INTO FS_EMP.
    if sy-tabix le  3 .
    if sy-tabix eq  1 .
    Write  : ' Top 3  salaries  ' .
    endif .
    WRITE:/ FS_EMP-EMPID,FS_EMP-ENAME,FS_EMP-DEPT,FS_EMP-SALARY.
    endif .
    endloop .

    reward points if it is usefull.....

    Girish

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 12, 2007 at 08:13 AM

    hi,

    Use sort table IT_EMP by salary descending.

    data: a type i.

    loop at it_emp.

    a = sy-tabix / 2.

    if a <> 0.

    Display it.

    endif.

    endloop.

    Reward if useful!

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 12, 2007 at 08:17 AM

    Hi,

    Sort the internal table in descending order.

    LOOP AT IT_EMP INTO FS_EMP.

    If sy-tabix = 4.

    exit.

    endif.

    WRITE:/ FS_EMP-EMPID,FS_EMP-ENAME,FS_EMP-DEPT,FS_EMP-SALARY.

    ENDLOOP.

    Reward if helpful.

    Regards,

    Umasankar.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 12, 2007 at 08:14 AM

    Hi,

    REPORT ZAC_TAB10.

    *LINE TYPE:

    TYPES:

    BEGIN OF TY_EMP,

    EMPID(4) TYPE N,

    ENAME(20) TYPE C,

    DEPT(4) TYPE C,

    SALARY TYPE I,

    END OF TY_EMP.

    DATA:

    FS_EMP TYPE TY_EMP,

    IT_EMP TYPE TABLE OF TY_EMP.

    FS_EMP-EMPID = 1010.

    FS_EMP-ENAME = 'XX'.

    FS_EMP-DEPT = 'D100'.

    FS_EMP-SALARY = 10000.

    APPEND FS_EMP TO IT_EMP.

    FS_EMP-EMPID = 1011.

    FS_EMP-ENAME = 'YY'.

    FS_EMP-DEPT = 'D100'.

    FS_EMP-SALARY = 11000.

    APPEND FS_EMP TO IT_EMP.

    FS_EMP-EMPID = 1001.

    FS_EMP-ENAME = 'ZZ'.

    FS_EMP-DEPT = 'D200'.

    FS_EMP-SALARY = 12000.

    APPEND FS_EMP TO IT_EMP.

    FS_EMP-EMPID = 1008.

    FS_EMP-ENAME = 'XY'.

    FS_EMP-DEPT = 'D200'.

    FS_EMP-SALARY = 10000.

    APPEND FS_EMP TO IT_EMP.

    FS_EMP-EMPID = 1002.

    FS_EMP-ENAME = 'XZ'.

    FS_EMP-DEPT = 'D300'.

    FS_EMP-SALARY = 8000.

    APPEND FS_EMP TO IT_EMP.

    FS_EMP-EMPID = 1005.

    FS_EMP-ENAME = 'YX'.

    FS_EMP-DEPT = 'D300'.

    FS_EMP-SALARY = 9500.

    APPEND FS_EMP TO IT_EMP.

    FS_EMP-EMPID = 1002.

    FS_EMP-ENAME = 'YZ'.

    FS_EMP-DEPT = 'D300'.

    FS_EMP-SALARY = 9500.

    APPEND FS_EMP TO IT_EMP.

    FS_EMP-EMPID = 1007.

    FS_EMP-ENAME = 'AA'.

    FS_EMP-DEPT = 'D100'.

    FS_EMP-SALARY = 10500.

    APPEND FS_EMP TO IT_EMP.

    FS_EMP-EMPID = 1003.

    FS_EMP-ENAME = 'BB'.

    FS_EMP-DEPT = 'D200'.

    FS_EMP-SALARY = 12000.

    APPEND FS_EMP TO IT_EMP.

    FS_EMP-EMPID = 1006.

    FS_EMP-ENAME = 'CC'.

    FS_EMP-DEPT = 'D100'.

    FS_EMP-SALARY = 15000.

    APPEND FS_EMP TO IT_EMP.

    LOOP AT IT_EMP INTO FS_EMP.

    WRITE:/ FS_EMP-EMPID,FS_EMP-ENAME,FS_EMP-DEPT,FS_EMP-SALARY.

    <b>*FOR TOP 3 SALARY RECORDS</b>

    <b>SORT IT_EMP BY SALARY DESCENDING.

    LOOP AT IT_EMP INTO FS_EMP FROM 1 TO 3.

    WRITE:/ FS_EMP-EMPID,FS_EMP-ENAME,FS_EMP-DEPT,FS_EMP-SALARY.

    ENDLOOP.</b>

    <b>FOR ODD RECORDS.

    LOOP AT IT_EMP INTO FS_EMP.

    DATA a type i.

    a = sy-tabix mod 2.

    if a > 0.

    WRITE:/ FS_EMP-EMPID,FS_EMP-ENAME,FS_EMP-DEPT,FS_EMP-SALARY.

    endif.

    ENDLOOP.</b></b>

    Regards,

    Sesh

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 12, 2007 at 08:17 AM

    TRY THIS

    TYPES:
    
    BEGIN OF TY_EMP,
    EMPID(4) TYPE N,
    ENAME(20) TYPE C,
    DEPT(4) TYPE C,
    SALARY TYPE I,
    END OF TY_EMP.
    
    
    DATA:
    FS_EMP TYPE TY_EMP,
    IT_EMP TYPE TABLE OF TY_EMP.
    DATA : RES TYPE I,
           COUNT TYPE I.
    
    
    FS_EMP-EMPID = 1010.
    FS_EMP-ENAME = 'XX'.
    FS_EMP-DEPT = 'D100'.
    FS_EMP-SALARY = 10000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1011.
    FS_EMP-ENAME = 'YY'.
    FS_EMP-DEPT = 'D100'.
    FS_EMP-SALARY = 11000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1001.
    FS_EMP-ENAME = 'ZZ'.
    FS_EMP-DEPT = 'D200'.
    FS_EMP-SALARY = 12000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1008.
    FS_EMP-ENAME = 'XY'.
    FS_EMP-DEPT = 'D200'.
    FS_EMP-SALARY = 10000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1002.
    FS_EMP-ENAME = 'XZ'.
    FS_EMP-DEPT = 'D300'.
    FS_EMP-SALARY = 8000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1005.
    FS_EMP-ENAME = 'YX'.
    FS_EMP-DEPT = 'D300'.
    FS_EMP-SALARY = 9500.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1002.
    FS_EMP-ENAME = 'YZ'.
    FS_EMP-DEPT = 'D300'.
    FS_EMP-SALARY = 9500.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1007.
    FS_EMP-ENAME = 'AA'.
    FS_EMP-DEPT = 'D100'.
    FS_EMP-SALARY = 10500.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1003.
    FS_EMP-ENAME = 'BB'.
    FS_EMP-DEPT = 'D200'.
    FS_EMP-SALARY = 12000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1006.
    FS_EMP-ENAME = 'CC'.
    FS_EMP-DEPT = 'D100'.
    FS_EMP-SALARY = 15000.
    APPEND FS_EMP TO IT_EMP.
    
    SORT IT_EMP BY SALARY DESCENDING.
    LOOP AT IT_EMP INTO FS_EMP.
    COMPUTE RES = SY-TABIX MOD 2.
    IF RES NE 0.
    COUNT = COUNT + 1.
    WRITE:/ FS_EMP-EMPID,FS_EMP-ENAME,FS_EMP-DEPT,FS_EMP-SALARY.
    ENDIF.
    IF COUNT = 3.
    EXIT.
    ENDIF.
    endloop.
    
    

    REGARDS

    SHIBA DUTTA

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.