05/08/2010

Displaying Percentage in ALV


REPORT ZRRSAMPLE.

TYPE-POOLS:slis .

DATA: it_fieldcat TYPE slis_t_fieldcat_alv ,
wa_fieldcat TYPE slis_fieldcat_alv .

DATA: BEGIN OF itab OCCURS 0,
name(10) TYPE c,
marks TYPE i ,
pers TYPE char5, "<---this should be character
grade TYPE char10,
END OF itab .

itab-name = 'IBM'.
itab-marks = 4.
APPEND itab .

itab-name = 'DELL'.
itab-marks = 15.
APPEND itab .

itab-name = 'GOOGLE'.
itab-marks = 21.
APPEND itab .

itab-name = 'MICROSOFT'.
itab-marks = 18.
APPEND itab .

itab-name = 'SUN'.
itab-marks = 9.
APPEND itab .

itab-name = 'SAP'.
itab-marks = 24.
APPEND itab .

LOOP AT itab .

itab-pers = ( itab-marks / 25 ) * 100 .

IF itab-pers LT 35 .
itab-grade = 'Bad'.

ELSEIF itab-pers GE 35 AND itab-pers LT 60 .
itab-grade = 'Average '.

ELSEIF itab-pers GE 60 AND itab-pers LT 80 .
itab-grade = 'Good'.

ELSEIF itab-pers GE 80 AND itab-pers LT 90 .
itab-grade = 'Very Good'.

ELSEIF itab-pers GE 90 AND itab-pers LT 100 .
itab-grade = 'Best'.
ENDIF.

CONCATENATE itab-pers '%' INTO itab-pers.

MODIFY itab.

ENDLOOP.

wa_fieldcat-fieldname = 'NAME'.
wa_fieldcat-seltext_m = 'name'.

APPEND wa_fieldcat TO it_fieldcat .
CLEAR wa_fieldcat .

wa_fieldcat-fieldname = 'MARKS'.
wa_fieldcat-seltext_m = 'marks'.

APPEND wa_fieldcat TO it_fieldcat .
CLEAR wa_fieldcat .

wa_fieldcat-fieldname = 'PERS'.
wa_fieldcat-seltext_m = 'percentage'.

APPEND wa_fieldcat TO it_fieldcat .
CLEAR wa_fieldcat .

wa_fieldcat-fieldname = 'GRADE'.
wa_fieldcat-seltext_m = 'grade'.

APPEND wa_fieldcat TO it_fieldcat .
CLEAR wa_fieldcat .

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = it_fieldcat
TABLES
t_outtab = itab.

Nenhum comentário:

Postar um comentário