Skip to Content
1
Former Member
Jul 28, 2007 at 04:26 AM

start-of-selection.

28 Views

hi.

please look at this code. its working fine only thing is some time it is displaying same result 2 time. if i run again then it will display correct ANS. please help me.

please look at start-of-selection statment is that giving problem.

REPORT YPMANDAY MESSAGE-ID AOD. .

TABLES : ZATTM,ZEMP2.

DATA : BEGIN OF I_ZATTM OCCURS 0.

INCLUDE STRUCTURE ZATTM.

DATA : TO_DAY TYPE P DECIMALS 2,

LEDAY TYPE P DECIMALS 2,

IOD TYPE I,

ICO TYPE I,

IH TYPE P DECIMALS 2,

IPC TYPE I,

ITOT TYPE P DECIMALS 2,

MANDAY TYPE I,

NAME(30) TYPE C,

IADAY TYPE I,

END OF I_ZATTM.

DATA : BEGIN OF T_ZATTM OCCURS 0.

INCLUDE STRUCTURE ZATTM.

DATA : NAME(30) TYPE C,

END OF T_ZATTM.

DATA : BEGIN OF p_ZATTM OCCURS 0.

INCLUDE STRUCTURE ZATTM.

DATA : ITOT TYPE P DECIMALS 2,

P_MAN TYPE I,

END OF p_ZATTM.

DATA : BEGIN OF M_ZATTM OCCURS 0.

INCLUDE STRUCTURE ZATTM.

DATA : ITOT TYPE P DECIMALS 2,

END OF M_ZATTM.

DATA : MANDAY TYPE I.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS : PLANT FOR T_ZATTM-DIVN,

ECODE FOR T_ZATTM-ECOD,

DATE FOR T_zATTM-CDAT OBLIGATORY.

SELECTION-SCREEN END OF BLOCK B1.

*SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.

*PARAMETERS : G1 RADIOBUTTON GROUP P1,

  • G2 RADIOBUTTON GROUP P1.

*SELECTION-SCREEN END OF BLOCK B2.

***********************for total manday***********************

*DATA : PMAN TYPE I.

*SELECT * FROM ZATTM INTO TABLE M_ZATTM WHERE CDAT IN

*DATE AND ECOD = 1145.

*LOOP AT M_ZATTM.

*MANDAY = MANDAY + 1.

*ENDLOOP.

*********************************************************************

AT SELECTION-SCREEN.

  • date field for one month only******************

data : dt1 type sy-datum,

dt2 type sy-datum.

dt1 = date-low+0(6).

dt2 = date-high+0(6).

if dt1 <> dt2 .

message E002 with 'PLEASE ENTER ONLY ONE MONTH IN DATE FIELD'.

endif.

****************************************************************

SELECT FECOD FDIVN FSTA1 PNAME INTO (T_ZATTM-ECOD, T_ZATTM-DIVN,

T_ZATTM-STA1, T_ZATTM-NAME) FROM ZATTM AS F INNER JOIN ZEMP2 AS P ON

FECOD = PECOD WHERE FECOD IN ECODE AND FCDAT IN DATE AND F~DIVN IN

PLANT.

APPEND T_ZATTM.

ENDSELECT.

sort T_ZATTM by ECOD.

DATA : PCODE TYPE ZATTM-ECOD.

DATA : TMDAY TYPE P DECIMALS 2,

OD TYPE I,

CO TYPE I,

H TYPE P DECIMALS 2,

PC TYPE I,

ITOT TYPE P DECIMALS 2,

DIVN TYPE ZATTM-DIVN,

ADAY TYPE I,

LDAY TYPE P DECIMALS 2.

LOOP AT T_ZATTM.

IF PCODE = 0.

PCODE = T_ZATTM-ECOD.

ENDIF.

IF PCODE <> T_ZATTM-ECOD.

PCODE = T_ZATTM-ECOD.

I_ZATTM-IOD = OD.

I_ZATTM-IH = H.

I_ZATTM-IPC = PC.

I_ZATTM-ICO = CO.

I_ZATTM-TO_DAY = TMDAY.

I_ZATTM-LEDAY = LDAY.

I_ZATTM-MANDAY = MANDAY.

I_ZATTM-IADAY = ADAY.

APPEND I_ZATTM.

CLEAR TMDAY.

CLEAR LDAY.

CLEAR : OD, H, PC, CO,ADAY.

I_ZATTM-ECOD = T_ZATTM-ECOD.

I_ZATTM-DIVN = T_ZATTM-DIVN.

I_ZATTM-NAME = T_ZATTM-NAME.

IF T_ZATTM-STA1 = 'P'.

TMDAY = TMDAY + 1.

ENDIF.

IF T_ZATTM-STA1 = 'H'.

TMDAY = TMDAY + ( 5 / 10 ).

LDAY = LDAY + ( 5 / 10 ).

H = H + 1.

ENDIF.

IF T_ZATTM-STA1 = 'PC'.

TMDAY = TMDAY + 1.

PC = PC + 1.

ENDIF.

IF T_ZATTM-STA1 = 'OD'.

TMDAY = TMDAY + 1.

OD = OD + 1.

ENDIF.

IF T_ZATTM-STA1 = 'CO'.

CO = CO + 1.

ENDIF.

IF T_ZATTM-STA1 = 'A'.

ADAY = ADAY + 1.

LDAY = LDAY + 1.

ENDIF.

ELSE.

I_ZATTM-ECOD = T_ZATTM-ECOD.

I_ZATTM-DIVN = T_ZATTM-DIVN.

I_ZATTM-NAME = T_ZATTM-NAME.

IF T_ZATTM-STA1 = 'P'.

TMDAY = TMDAY + 1.

ENDIF.

IF T_ZATTM-STA1 = 'H'.

TMDAY = TMDAY + ( 5 / 10 ).

LDAY = LDAY + ( 5 / 10 ).

H = H + 1.

ENDIF.

IF T_ZATTM-STA1 = 'PC'.

TMDAY = TMDAY + 1.

PC = PC + 1.

ENDIF.

IF T_ZATTM-STA1 = 'OD'.

TMDAY = TMDAY + 1.

OD = OD + 1.

ENDIF.

IF T_ZATTM-STA1 = 'CO'.

CO = CO + 1.

ENDIF.

IF T_ZATTM-STA1 = 'A'.

LDAY = LDAY + 1.

ADAY = ADAY + 1.

ENDIF.

ENDIF.

ENDLOOP.

I_ZATTM-IOD = OD.

I_ZATTM-IH = H.

I_ZATTM-IPC = PC.

I_ZATTM-ICO = CO.

I_ZATTM-TO_DAY = TMDAY.

I_ZATTM-LEDAY = LDAY.

I_ZATTM-MANDAY = MANDAY.

I_ZATTM-IADAY = ADAY.

APPEND I_ZATTM.

CLEAR TMDAY.

CLEAR LDAY.

CLEAR : OD, H, PC, CO,ADAY.

**************************************************************

  • ALV REPORT *************************

***************************************************************

TYPE-POOLS: slis.

<b>START-OF-SELECTION</b>.

DATA: alv_fcat TYPE slis_t_fieldcat_alv,

alv_layout TYPE slis_layout_alv,

alv_incid LIKE sy-repid VALUE 'YPMANDAY',

alv_repid LIKE sy-repid VALUE 'YPMANDAY',

alv_title TYPE lvc_title,

alv_print TYPE slis_print_alv,

alv_sort TYPE slis_t_sortinfo_alv,

csort TYPE slis_sortinfo_alv,

alv_top_of_page TYPE slis_t_listheader,

gs_line TYPE slis_listheader,

alv_events TYPE slis_t_event,

alv_variant TYPE disvariant.

FORMAT COLOR 3 INTENSIFIED ON.

  • IF G1 = 'X'.

PERFORM init_alv_layout.

PERFORM eventtab_build CHANGING alv_events.

PERFORM comment_build CHANGING alv_top_of_page.

PERFORM init_alv_fcat.

PERFORM display_alv.

  • PERFORM top_of_page.

  • ENDIF.

*IF G2 = 'X'.

*

*SORT I_ZATTM.

*LOOP AT I_ZATTM.

*IF DIVN = ''.

*DIVN = I_ZATTM-DIVN.

*ENDIF.

*

*

*

*IF DIVN <> I_ZATTM-DIVN.

*P_ZATTM-DIVN = DIVN.

*P_ZATTM-P_MAN = PMAN.

*

*P_ZATTM-ITOT = ITOT.

*APPEND P_ZATTM.

*CLEAR : ITOT,PMAN.

*PMAN = PMAN + MANDAY.

*ITOT = ITOT + I_ZATTM-TO_DAY.

*DIVN = I_ZATTM-DIVN.

*ELSE.

*DIVN = I_ZATTM-DIVN.

*P_ZATTM-DIVN = I_ZATTM-DIVN.

*PMAN = PMAN + MANDAY.

*ITOT = ITOT + I_ZATTM-TO_DAY.

*ENDIF.

*ENDLOOP.

*

*P_ZATTM-DIVN = I_ZATTM-DIVN.

*P_ZATTM-P_MAN = PMAN.

*

*P_ZATTM-ITOT = ITOT.

*APPEND P_ZATTM.

*CLEAR : ITOT, PMAN.

*LOOP AT P_ZATTM.

*

**WRITE : / P_ZATTM-DIVN, P_ZATTM-ITOT.

*ENDLOOP.

*

*

*

  • PERFORM init_alv_layout.

  • PERFORM eventtab_build CHANGING alv_events.

  • PERFORM comment_build CHANGING alv_top_of_page.

  • PERFORM init_alv_fcat_T.

  • PERFORM display_alv_T.

  • ENDIF.

START-OF-SELECTION.

*----


  • Form init_alv_layout

*----


  • text

*----


FORM init_alv_layout .

alv_layout-colwidth_optimize = 'X'.

alv_title = 'MAN DAYS'.

ENDFORM. "init_alv_layout

*----


  • Form init_alv_fcat

*----


  • text

*----


FORM init_alv_fcat .

PERFORM init_alv_first.

ENDFORM. "init_alv_fcat

*----


  • Form display_alv

*----


  • text

*----


FORM display_alv .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = alv_repid

i_structure_name = 'I_ZATTM'

is_layout = alv_layout

  • i_background_id = 'ALV_BACKGROUND'

it_fieldcat = alv_fcat

it_sort = alv_sort

it_events = alv_events

is_print = alv_print

i_grid_title = alv_title

i_default = 'X'

is_variant = alv_variant

i_save = 'A'

TABLES

t_outtab = I_ZATTM.

ENDFORM. " display_alv

*----


  • Form eventtab_build

*----


  • text

*----


  • -->LT_EVENTS text

*----


FORM eventtab_build CHANGING lt_events TYPE slis_t_event.

CONSTANTS:

gc_formname_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.

DATA: ls_event TYPE slis_alv_event.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = lt_events.

READ TABLE lt_events WITH KEY name = slis_ev_top_of_page

INTO ls_event.

IF sy-subrc = 0.

MOVE gc_formname_top_of_page TO ls_event-form.

APPEND ls_event TO lt_events.

ENDIF.

ENDFORM. " eventtab_build

*----


  • Form comment_build

*----


  • text

*----


  • -->ALV_TOP_OF_text

*----


FORM comment_build CHANGING alv_top_of_page TYPE slis_t_listheader.

DATA : v_heading(60).

DATA : v_date(10).

CLEAR gs_line.

  • gs_line-typ = 'S'.

  • gs_line-key = 'Plant :'.

  • gs_line-info = divn.

  • append gs_line to alv_top_of_page.

v_heading = date+9(2).

concatenate v_heading '.' date7(2) '.' date3(4) into v_heading.

gs_line-typ = 'S'.

gs_line-key = 'From : '.

gs_line-info = v_heading.

append gs_line to alv_top_of_page.

v_heading = date+17(2).

concatenate v_heading '.' date15(2) '.' date11(4) into v_heading.

gs_line-typ = 'S'.

gs_line-key = 'To : '.

gs_line-info = v_heading.

append gs_line to alv_top_of_page.

*

  • CONCATENATE v_heading 'Month Pay Details' INTO v_heading.

*

ENDFORM. " comment_build

*----


  • Form top_of_page

*----


  • text

*----


FORM top_of_page.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = alv_top_of_page

ENDFORM. "top_of_page

*----


  • Form init_alv_first

*----


  • text

*----


FORM init_alv_first .

DATA v_loc_fcat TYPE slis_fieldcat_alv.

DATA : v_pos TYPE i VALUE 1.

DATA : v_text(20).

DATA: total TYPE i VALUE 0.

*************************1**********************

v_loc_fcat-fieldname = 'ECOD'.

v_loc_fcat-seltext_l = 'E CODE'.

v_loc_fcat-tabname = 'I_ZATTM'.

v_loc_fcat-key = 'X'.

APPEND v_loc_fcat TO alv_fcat.

CLEAR v_loc_fcat-key.

**************************2**********************

v_loc_fcat-fieldname = 'NAME'.

v_loc_fcat-seltext_l = 'NAME'.

v_loc_fcat-tabname = 'I_ZATTM'.

v_loc_fcat-key = 'X'.

*v_loc_fcat-edit = 'X'.

APPEND v_loc_fcat TO alv_fcat.

CLEAR v_loc_fcat-key.

v_loc_fcat-fieldname = 'DIVN'.

v_loc_fcat-seltext_l = 'DCODE'.

v_loc_fcat-tabname = 'I_ZATTM'.

v_loc_fcat-key = 'X'.

*v_loc_fcat-edit = 'X'.

APPEND v_loc_fcat TO alv_fcat.

CLEAR v_loc_fcat-key.

**************************3**********************

  • v_loc_fcat-fieldname = 'MANDAY'.

  • v_loc_fcat-tabname = 'I_ZATTM'.

  • v_loc_fcat-seltext_l = 'TOT M.DAYS '.

  • v_loc_fcat-key = 'X'.

  • APPEND v_loc_fcat TO alv_fcat.

  • CLEAR v_loc_fcat-key.

**************************5**********************

v_loc_fcat-fieldname = 'IADAY'.

v_loc_fcat-tabname = 'I_ZATTM'.

v_loc_fcat-seltext_l = 'A'.

v_loc_fcat-key = 'X'.

APPEND v_loc_fcat TO alv_fcat.

CLEAR v_loc_fcat-key.

v_loc_fcat-fieldname = 'IH'.

v_loc_fcat-tabname = 'I_ZATTM'.

v_loc_fcat-seltext_l = 'H'.

v_loc_fcat-key = 'X'.

APPEND v_loc_fcat TO alv_fcat.

CLEAR v_loc_fcat-key.

**************************6**********************

v_loc_fcat-fieldname = 'IPC'.

v_loc_fcat-tabname = 'I_ZATTM'.

v_loc_fcat-seltext_l = 'PC'.

APPEND v_loc_fcat TO alv_fcat.

CLEAR v_loc_fcat-key.

**************************7**********************

v_loc_fcat-fieldname = 'ICO'.

v_loc_fcat-seltext_l = 'CO'.

v_loc_fcat-just = 'C'.

v_loc_fcat-tabname = 'I_ZATTM'.

APPEND v_loc_fcat TO alv_fcat.

CLEAR v_loc_fcat-key.

*****************************************************

v_loc_fcat-fieldname = 'IOD'.

v_loc_fcat-seltext_l = 'OD'.

v_loc_fcat-just = 'C'.

v_loc_fcat-tabname = 'I_ZATTM'.

APPEND v_loc_fcat TO alv_fcat.

CLEAR v_loc_fcat-key.

***************************************************8

v_loc_fcat-fieldname = 'LEDAY'.

v_loc_fcat-tabname = 'I_ZATTM'.

v_loc_fcat-seltext_l = 'TOT A.DAYS'.

v_loc_fcat-key = 'X'.

APPEND v_loc_fcat TO alv_fcat.

CLEAR v_loc_fcat-key.

***************************************************8

v_loc_fcat-fieldname = 'TO_DAY'.

v_loc_fcat-tabname = 'I_ZATTM'.

v_loc_fcat-seltext_l = 'TOT P.DAYS'.

v_loc_fcat-key = 'X'.

APPEND v_loc_fcat TO alv_fcat.

CLEAR v_loc_fcat-key.

ENDFORM.

**----


  • Form init_alv_fcat

**----


  • text

**----


*FORM init_alv_fcat_T .

  • PERFORM init_alv_first_T.

*ENDFORM. "init_alv_fcat

*

**----


  • Form display_alv

**----


  • text

**----


*FORM display_alv_T .

*

  • CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

  • EXPORTING

  • i_callback_program = alv_repid

  • i_structure_name = 'P_ZATTM'

  • is_layout = alv_layout

  • it_fieldcat = alv_fcat

  • it_sort = alv_sort

  • it_events = alv_events

  • is_print = alv_print

  • i_grid_title = alv_title

  • i_default = 'X'

  • is_variant = alv_variant

  • i_save = 'A'

  • TABLES

  • t_outtab = P_ZATTM.

*

*ENDFORM. " display_alv

*

*

*

*FORM init_alv_first_T .

  • DATA v_loc_fcat TYPE slis_fieldcat_alv.

  • DATA : v_pos TYPE i VALUE 1.

  • DATA : v_text(20).

  • DATA: total TYPE i VALUE 0.

*

**************************1**********************

  • v_loc_fcat-fieldname = 'DIVN'.

  • v_loc_fcat-seltext_l = 'DIVISION CODE'.

  • v_loc_fcat-tabname = 'P_ZATTM'.

  • v_loc_fcat-key = 'X'.

  • APPEND v_loc_fcat TO alv_fcat.

  • CLEAR v_loc_fcat-key.

***************************2**********************

*

*v_loc_fcat-fieldname = 'P_MAN'.

  • v_loc_fcat-seltext_l = 'TOTAL M.DAY'.

  • v_loc_fcat-tabname = 'P_ZATTM'.

  • v_loc_fcat-key = 'X'.

  • APPEND v_loc_fcat TO alv_fcat.

  • CLEAR v_loc_fcat-key.

*

  • v_loc_fcat-fieldname = 'ITOT'.

  • v_loc_fcat-seltext_l = 'TOTAL WORK DAY'.

  • v_loc_fcat-tabname = 'P_ZATTM'.

  • v_loc_fcat-key = 'X'.

**v_loc_fcat-edit = 'X'.

  • APPEND v_loc_fcat TO alv_fcat.

  • CLEAR v_loc_fcat-key.

*ENDFORM.