Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Display the records

Former Member
0 Kudos

hi,

I want to display the fifth record.

But it is displaying the last record. why it is displaying last record. plz let me know the correct one.

how to display all uniqueempids from the internal table.

This is my program.

*LINE TYPE.

TYPES:

BEGIN OF TY_EMP,

EMPID(4) TYPE C,

ENAME(30) TYPE C,

DEPT(4) TYPE C,

GRADE(1) TYPE C,

SALARY TYPE I,

END OF TY_EMP.

  • TABLE TYPE

DATA:

FS_EMP TYPE TY_EMP,

IT_EMP TYPE TABLE OF TY_EMP.

FS_EMP-EMPID = 'E100'.

FS_EMP-ENAME = 'X'.

FS_EMP-DEPT = 'D100'.

FS_EMP-GRADE = 'A'.

FS_EMP-SALARY = 10000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E200'.

FS_EMP-ENAME = 'Y'.

FS_EMP-DEPT = 'D200'.

FS_EMP-GRADE = 'A'.

FS_EMP-SALARY = 11000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E101'.

FS_EMP-ENAME = 'Z'.

FS_EMP-DEPT = 'D100'.

FS_EMP-GRADE = 'A'.

FS_EMP-SALARY = 12000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E103'.

FS_EMP-ENAME = 'B'.

FS_EMP-DEPT = 'D200'.

FS_EMP-GRADE = 'B'.

FS_EMP-SALARY = 8000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E104'.

FS_EMP-ENAME = 'B'.

FS_EMP-DEPT = 'D200'.

FS_EMP-GRADE = 'B'.

FS_EMP-SALARY = 7000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E105'.

FS_EMP-ENAME = 'C'.

FS_EMP-DEPT = 'D100'.

FS_EMP-GRADE = 'C'.

FS_EMP-SALARY = 5000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E100'.

FS_EMP-ENAME = 'D'.

FS_EMP-DEPT = 'D200'.

FS_EMP-GRADE = 'B'.

FS_EMP-SALARY = 8500.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E200'.

FS_EMP-ENAME = 'E'.

FS_EMP-DEPT = 'D300'.

FS_EMP-GRADE = 'B'.

FS_EMP-SALARY = 9000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E104'.

FS_EMP-ENAME = 'F'.

FS_EMP-DEPT = 'D300'.

FS_EMP-GRADE = 'A'.

FS_EMP-SALARY = 13000.

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-GRADE,FS_EMP-SALARY.

ENDLOOP.

*DISPLAY THE FIFTH RECORD FROM THE INTERNAL TABLE.

ULINE.

IF SY-TABIX = 5.

WRITE: 'DISPLAY RECORDS'.

ENDIF.

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi,

change the code as follows:

loop at IT_EMP to fs_emp.

if sy-tabix eq 5.

WRITE: 'DISPLAY RECORDS'.

ENDIF.

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

endif.

endloop.

regards,

Navneeth K.

6 REPLIES 6

Former Member
0 Kudos

Hi,


TYPES:
BEGIN OF TY_EMP,
EMPID(4) TYPE C,
ENAME(30) TYPE C,
DEPT(4) TYPE C,
GRADE(1) TYPE C,
SALARY TYPE I,
END OF TY_EMP.
* TABLE TYPE
DATA:
FS_EMP TYPE TY_EMP,
IT_EMP TYPE TABLE OF TY_EMP.
FS_EMP-EMPID = 'E100'.
FS_EMP-ENAME = 'X'.
FS_EMP-DEPT = 'D100'.
FS_EMP-GRADE = 'A'.
FS_EMP-SALARY = 10000.
APPEND FS_EMP TO IT_EMP.
FS_EMP-EMPID = 'E200'.
FS_EMP-ENAME = 'Y'.
FS_EMP-DEPT = 'D200'.
FS_EMP-GRADE = 'A'.
FS_EMP-SALARY = 11000.
APPEND FS_EMP TO IT_EMP.
FS_EMP-EMPID = 'E101'.
FS_EMP-ENAME = 'Z'.
FS_EMP-DEPT = 'D100'.
FS_EMP-GRADE = 'A'.
FS_EMP-SALARY = 12000.
APPEND FS_EMP TO IT_EMP.
FS_EMP-EMPID = 'E103'.
FS_EMP-ENAME = 'B'.
FS_EMP-DEPT = 'D200'.
FS_EMP-GRADE = 'B'.
FS_EMP-SALARY = 8000.
APPEND FS_EMP TO IT_EMP.
FS_EMP-EMPID = 'E104'.
FS_EMP-ENAME = 'B'.
FS_EMP-DEPT = 'D200'.
FS_EMP-GRADE = 'B'.
FS_EMP-SALARY = 7000.
APPEND FS_EMP TO IT_EMP.
FS_EMP-EMPID = 'E105'.
FS_EMP-ENAME = 'C'.
FS_EMP-DEPT = 'D100'.
FS_EMP-GRADE = 'C'.
FS_EMP-SALARY = 5000.
APPEND FS_EMP TO IT_EMP.
FS_EMP-EMPID = 'E100'.
FS_EMP-ENAME = 'D'.
FS_EMP-DEPT = 'D200'.
FS_EMP-GRADE = 'B'.
FS_EMP-SALARY = 8500.
APPEND FS_EMP TO IT_EMP.
FS_EMP-EMPID = 'E200'.
FS_EMP-ENAME = 'E'.
FS_EMP-DEPT = 'D300'.
FS_EMP-GRADE = 'B'.
FS_EMP-SALARY = 9000.
APPEND FS_EMP TO IT_EMP.
FS_EMP-EMPID = 'E104'.
FS_EMP-ENAME = 'F'.
FS_EMP-DEPT = 'D300'.
FS_EMP-GRADE = 'A'.
FS_EMP-SALARY = 13000.
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-GRADE,FS_EMP-SALARY.
ENDLOOP.

READ TABLE IT_EMP INTO FS_EMP INDEX 5.   " You need to add this line

*DISPLAY THE FIFTH RECORD FROM THE INTERNAL TABLE.
ULINE.
IF SY-TABIX = 5.
WRITE: 'DISPLAY RECORDS'.
ENDIF.
WRITE:/ FS_EMP-EMPID,FS_EMP-ENAME,FS_EMP-DEPT,FS_EMP-GRADE,FS_EMP-SALARY.

Regards

Sudheer

Former Member
0 Kudos

hi,

change the code as follows:

loop at IT_EMP to fs_emp.

if sy-tabix eq 5.

WRITE: 'DISPLAY RECORDS'.

ENDIF.

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

endif.

endloop.

regards,

Navneeth K.

Former Member
0 Kudos

Hi,

Give Like this,

TYPES:

BEGIN OF TY_EMP,

EMPID(4) TYPE C,

ENAME(30) TYPE C,

DEPT(4) TYPE C,

GRADE(1) TYPE C,

SALARY TYPE I,

END OF TY_EMP.

  • TABLE TYPE

DATA:

FS_EMP TYPE TY_EMP,

IT_EMP TYPE TABLE OF TY_EMP.

FS_EMP-EMPID = 'E100'.

FS_EMP-ENAME = 'X'.

FS_EMP-DEPT = 'D100'.

FS_EMP-GRADE = 'A'.

FS_EMP-SALARY = 10000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E200'.

FS_EMP-ENAME = 'Y'.

FS_EMP-DEPT = 'D200'.

FS_EMP-GRADE = 'A'.

FS_EMP-SALARY = 11000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E101'.

FS_EMP-ENAME = 'Z'.

FS_EMP-DEPT = 'D100'.

FS_EMP-GRADE = 'A'.

FS_EMP-SALARY = 12000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E103'.

FS_EMP-ENAME = 'B'.

FS_EMP-DEPT = 'D200'.

FS_EMP-GRADE = 'B'.

FS_EMP-SALARY = 8000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E104'.

FS_EMP-ENAME = 'B'.

FS_EMP-DEPT = 'D200'.

FS_EMP-GRADE = 'B'.

FS_EMP-SALARY = 7000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E105'.

FS_EMP-ENAME = 'C'.

FS_EMP-DEPT = 'D100'.

FS_EMP-GRADE = 'C'.

FS_EMP-SALARY = 5000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E100'.

FS_EMP-ENAME = 'D'.

FS_EMP-DEPT = 'D200'.

FS_EMP-GRADE = 'B'.

FS_EMP-SALARY = 8500.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E200'.

FS_EMP-ENAME = 'E'.

FS_EMP-DEPT = 'D300'.

FS_EMP-GRADE = 'B'.

FS_EMP-SALARY = 9000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E104'.

FS_EMP-ENAME = 'F'.

FS_EMP-DEPT = 'D300'.

FS_EMP-GRADE = 'A'.

FS_EMP-SALARY = 13000.

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-GRADE,FS_EMP-SALARY.

ENDLOOP.

*DISPLAY THE FIFTH RECORD FROM THE INTERNAL TABLE.

ULINE.

<b>LOOP AT IT_EMP INTO FS_EMP.

IF SY-TABIX = 5.

WRITE: 'DISPLAY RECORDS'.

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

ENDIF.

ENDLOOP.</b>

Regards,

Padmam.

Former Member
0 Kudos

Hi

*DISPLAY THE FIFTH RECORD FROM THE INTERNAL TABLE.

ULINE.

<b>Read table it_emp Index 5.</b>

WRITE: 'DISPLAY RECORDS'.

ENDIF.

WRITE:/ It_EMP-EMPID,it_EMP-ENAME,it_EMP-DEPT,it_EMP-GRADE,it_EMP-SALARY.

Displaying all Unique EMP ids

<b>sort it_emp by empid.

delete adjacent duplicates from it_emp comparing empid.</b>

LOOP AT IT_EMP INTO FS_EMP.

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

ENDLOOP.

<b>Reward points for useful Answers</b>

Regards

Anji

0 Kudos

Hi,

To display unique records i wrote the program like this. but iam getting error.

ULINE:

SORT IT_EMP BY EMPID.

DELETE ADJACENT RECORDS COMPARING EMPID.

LOOP AT IT_EMP INTO FS_EMP.

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

iam getting sort is unknown. plz let me know correct syntax.

0 Kudos

ULINE. <b><-- put a dot not a colon</b>

SORT IT_EMP BY EMPID.

DELETE ADJACENT <b>duplicates</b> COMPARING EMPID.

LOOP AT IT_EMP INTO FS_EMP.

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