Skip to Content
0
Former Member
Nov 14, 2013 at 08:45 AM

2 ALV Grid in one screen

4482 Views

Hi Experts,

I need to show two alv grids in one screen.

I have searched through the net, but i think i have a different approach with my alv grid that's why i cant make it work.

can you help me on how i can show the two alv grids?

I need to show the it_final and it_pernr into two alv grids.

Here is my code:

TABLES: t015m.

DATA: BEGIN OF it_pernr OCCURS 0,

pernr LIKE pa0000-pernr,

begda LIKE pa0000-begda,

persk LIKE pa0001-persk.

DATA: END OF it_pernr.

DATA: wa_pernr LIKE it_pernr.

DATA: BEGIN OF it_skilled OCCURS 0,

pernr LIKE pa0000-pernr,

begda LIKE pa0000-begda,

persk LIKE pa0001-persk.

DATA: END OF it_skilled.

DATA: wa_skilled LIKE it_skilled.

DATA: BEGIN OF it_prof OCCURS 0,

pernr LIKE pa0000-pernr,

begda LIKE pa0000-begda,

persk LIKE pa0001-persk.

DATA: END OF it_prof.

DATA: BEGIN OF it_final OCCURS 0,

position LIKE hrp1000-stext,

active TYPE i,

promoted TYPE i,

total TYPE i,

percentage TYPE p DECIMALS 2.

DATA: END OF it_final.

DATA: wk_month(2),

PREPWORDS(30),

zdate like sy-datum,

STARTDATEWORDS(30),

ENDDATEWORDS(30),

date_lo TYPE string,

date_hi TYPE string.

"<---------------------------------DATA FOR ALV---------------------------->

TYPE-POOLS: sdydo, icon, slis.

TYPES: BEGIN OF t_header,

line01(555) TYPE c,

line02(555) TYPE c,

END OF t_header.

DATA: BEGIN OF it_pos OCCURS 0,

stext LIKE hrp1000-stext.

* objid LIKE hrp1000-objid.

DATA: END OF it_pos.

* FOR ALV HEADER

DATA: gw_header TYPE t_header.

* ALV required data objects.

DATA: w_title TYPE lvc_title,

w_repid TYPE sy-repid,

w_comm TYPE slis_formname,

w_status TYPE slis_formname,

x_layout TYPE slis_layout_alv,

ls_events TYPE LINE OF slis_t_event,

t_events TYPE slis_t_event,

t_fieldcat TYPE slis_t_fieldcat_alv,

x_sort type LINE OF slis_t_sortinfo_alv,

t_sort TYPE slis_t_sortinfo_alv,

ls_heading TYPE slis_listheader,

t_heading TYPE slis_t_listheader,

ls_fieldcat TYPE slis_fieldcat_alv,

gs_variant LIKE disvariant.

DATA: is_print TYPE slis_print_alv,

gset TYPE lvc_s_glay,

%runmode TYPE aqlimode.

data: it_sortcat type slis_sortinfo_alv occurs 1,

wa_sort like line of it_sortcat.

************************END OF DATA FOR ALV**********************

"for selection screen

PARAMETERS curdate TYPE sy-datum DEFAULT sy-datum OBLIGATORY.

SELECT-OPTIONS date FOR sy-datum DEFAULT sy-datum TO sy-datum OBLIGATORY.

SELECTION-SCREEN SKIP. "add a blank line

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

PARAMETERS: Skilled AS CHECKBOX USER-COMMAND UC MODIF ID fir,

Prof AS CHECKBOX USER-COMMAND UC MODIF ID fir.

SELECTION-SCREEN END OF BLOCK B1.

AT SELECTION-SCREEN.

IF date-high > sy-datum.

MESSAGE 'Enter Valid Date' TYPE 'E'.

ENDIF.

START-OF-SELECTION.

PERFORM get_datewords.

PERFORM get_data.

PERFORM display_report.

FORM get_data.

SELECT pa0000~pernr pa0001~persk MAX( pa0000~BEGDA )

INTO CORRESPONDING FIELDS OF TABLE it_pernr

FROM PA0000

INNER JOIN pa0001

ON pa0000~pernr EQ pa0001~pernr

WHERE pa0000~BEGDA BETWEEN date-low AND date-high

AND stat2 EQ '3'

AND ( pa0001~persk EQ 'H1' OR pa0001~persk EQ 'H2'

OR pa0001~persk EQ 'H3' OR pa0001~persk EQ 'H4'

OR pa0001~persk EQ 'H5' OR pa0001~persk EQ 'I1'

OR pa0001~persk EQ 'A1' OR pa0001~persk EQ 'B1'

OR pa0001~persk EQ 'C1' OR pa0001~persk EQ 'C2'

OR pa0001~persk EQ 'D1' OR pa0001~persk EQ 'D2'

OR pa0001~persk EQ 'E1' OR pa0001~persk EQ 'E2'

OR pa0001~persk EQ 'F1' OR pa0001~persk EQ 'F2'

OR pa0001~persk EQ 'G1' OR pa0001~persk EQ 'G1' )

GROUP BY pa0000~PERNR pa0001~persk.

IF skilled EQ 'X'.

DELETE it_pernr WHERE ( persk EQ 'A1' OR persk EQ 'B1'

OR persk EQ 'C1' OR persk EQ 'C2'

OR persk EQ 'D1' OR persk EQ 'D2'

OR persk EQ 'E1' OR persk EQ 'E2'

OR persk EQ 'F1' OR persk EQ 'F2'

OR persk EQ 'G1' OR persk EQ 'G2' ).

ELSEIF prof EQ 'X'.

DELETE it_pernr WHERE ( persk EQ 'H1' OR persk EQ 'H2'

OR persk EQ 'H3' OR persk EQ 'H4'

OR persk EQ 'H5' OR persk EQ 'I1' ).

ENDIF.

LOOP AT it_pernr INTO wa_pernr.

DATA: gv_plans LIKE pa0001-plans,

gv_active TYPE i,

gv_position TYPE stext,

gv_objid LIKE hrp1000-objid,

gv_pernr LIKE pa0001-pernr,

gv_begda LIKE pa0000-begda,

ref_dte LIKE pa0000-begda,

total TYPE p DECIMALS 2.

"For active

SELECT plans

INTO gv_plans

FROM pa0001

WHERE pernr = wa_pernr-pernr.

ENDSELECT.

SELECT stext objid

INTO (gv_position, gv_objid)

FROM hrp1000

WHERE objid = gv_plans

AND plvar = '01'

AND otype = 'S'

AND langu = 'EN'.

ENDSELECT.

IF sy-subrc = 0.

it_final-position = gv_position.

it_final-active = it_final-active + 1.

* SORT it_final BY position.

* COLLECT it_final. CLEAR it_final.

ENDIF.

"For promoted

CLEAR: gv_position, gv_plans.

SELECT begda

INTO gv_begda

FROM pa0000

WHERE massn = 'D6'

AND pernr = wa_pernr-pernr

AND begda BETWEEN date-low AND date-high.

ENDSELECT.

ref_dte = gv_begda - 1.

SELECT plans

FROM pa0001

INTO gv_plans

WHERE endda = ref_dte

AND pernr = wa_pernr-pernr.

ENDSELECT.

SELECT stext

INTO gv_position

FROM hrp1000

WHERE objid = gv_plans

AND plvar = '01'

AND otype = 'S'

AND langu = 'EN'.

ENDSELECT.

IF sy-subrc = 0.

it_final-position = gv_position.

it_final-promoted = it_final-promoted + 1.

ENDIF.

"For total

it_final-total = it_final-active + it_final-promoted.

"For Percentage

If it_final-promoted NE '0'.

* it_final-percentage = ( it_final-promoted / it_final-active ) * 100.

ENDIF.

SORT it_final BY position.

COLLECT it_final. CLEAR it_final.

ENDLOOP.

ENDFORM.

FORM display_report.

is_print-no_print_selinfos = 'X'.

is_print-no_print_listinfos = 'X'.

is_print-print_ctrl = 'X'.

PERFORM pf_write_fieldcat USING:

'POSITION' 'IT_FINAL' 'POSITION' ' ',

'ACTIVE' 'IT_FINAL' 'ACTIVE EMPLOYEE' ' ',

'PROMOTED' 'IT_FINAL' 'PROMOTED' ' ',

'TOTAL' 'IT_FINAL' 'TOTAL' ' ',

'PERCENTAGE' 'IT_FINAL' '%' ' '.

* Layout

x_layout-zebra = 'X'.

x_layout-no_keyfix = ' '.

x_layout-colwidth_optimize = 'X'.

* GUI Status

w_status = 'SET_PF_STATUS'.

w_repid = sy-repid.

* User commands

w_comm = 'USER_COMMAND'.

gs_variant-report = sy-repid.

gs_variant-username = sy-uname.

gset-no_colwopt = 'X'.

* Displays the ALV grid

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-repid

it_fieldcat = t_fieldcat

is_layout = x_layout

"it_sort = t_sort

it_sort = it_sortcat

i_callback_top_of_page = 'TOP-OF-PAGE'

* i_callback_html_end_of_list = 'END-OF-PAGE'

is_variant = gs_variant

i_save = 'A'

is_print = is_print

* it_events = t_events

* i_grid_title = w_title

TABLES

t_outtab = it_final

EXCEPTIONS

program_error = 1

OTHERS = 2.

ENDFORM. " display_report

*&---------------------------------------------------------------------*

*& Form TOP-OF-PAGE

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

FORM top-of-page.

*ALV Header declarations

DATA: t_header TYPE slis_t_listheader,

wa_header TYPE slis_listheader,

t_line LIKE wa_header-info,

ld_lines TYPE i,

ld_linesc(10) TYPE c,

lv_month TYPE string,

dastr TYPE string,

EMPMOVE TYPE STRING,

TOMOVE TYPE STRING,

FROMMOVE TYPE STRING.

DATA: text TYPE sdydo_text_element,

a_right TYPE REF TO cl_dd_area.

text = 'Report - Active vs Promoted'.

wa_header-typ = 'S'.

wa_header-info = text.

APPEND wa_header TO t_header.

CLEAR: wa_header.

gw_header-line01 = text.

IF skilled = 'X'.

text = 'SKILLED'.

wa_header-typ = 'S'.

wa_header-info = text.

APPEND wa_header TO t_header.

CLEAR: wa_header.

gw_header-line01 = text.

ELSEIF PROF = 'X'.

text = 'PROFESSIONAL'.

wa_header-typ = 'S'.

wa_header-info = text.

APPEND wa_header TO t_header.

CLEAR: wa_header.

gw_header-line01 = text.

ENDIF.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = t_header.

ENDFORM. "top-of-page

FORM pf_write_fieldcat USING fname

tname

text

len.

* key

* sum.

ls_fieldcat-fieldname = fname.

ls_fieldcat-tabname = tname.

ls_fieldcat-seltext_l = text.

ls_fieldcat-outputlen = len.

* ls_fieldcat-key = key.

ls_fieldcat-do_sum = 'X'.

IF len = '0'.

ls_fieldcat-outputlen = '1'.

ls_fieldcat-no_out = 'X'.

ENDIF.

APPEND ls_fieldcat TO t_fieldcat.

CLEAR ls_fieldcat.