We can display ALV Grid by using Module Pool. Here for
the Selection Screen we have to make a custom screen (Like 9001). The Grid
display will be on another screen (Like 9002). The Selection Screen contains a
sub screen (100) for the Select Option.
On the selection screen we have created two button
DISPLAY (FCT code = DISP) and CLEAR (FCT code = CLR). The sub screen 100 will
contain the Parameter of Company code and Select option of Project Definition.
Hence for the sub screen we call sub screen including
program name and screen number (100) in PBO of screen 9001. Now in PAI we call
the sub screen again to pass the value entered in the screen to the program.
To display two ALV Grids we have created two Custom
Containers which are referenced to CL_GUI_CUSTOM_CONTAINER class in PBO of
screen 9002. We also have created two Grids, referenced to CL_GUI_ALV_GRID.
After creating these objects we have to call method
SET_TABLE_FOR_FIRST_DISPLAY by Grid object in PBO of screen 9002. In this
method we have passed the Layout, Field catalog and the Internal Table. Here
the Grid display is displayed on the screen 9002.
After displaying the Grid in screen 9002 if we click on
BACK / EXIT / CANCEL button then the program will come to screen 9001 which is
Selection Screen. Hence in the PAI of screen 9002, we have to call method
REFRESH_TABLE_DISPLAY to refresh the ALV Grid and FREE to refresh the Custom
Container. Here we also have cleared the screen fields and internal tables
used.
Following is the code of the program:
Screen - 9001:
PROCESS BEFORE OUTPUT.
MODULE status_9001.
"Calling the Sub Screen by using Program name & Screen
CALL SUBSCREEN sub_sel
INCLUDING sy-repid '100'.
PROCESS AFTER INPUT.
"Calling the Sub Screen to pass the value
"from Sub Screen to Program
CALL SUBSCREEN sub_sel.
MODULE user_command_9001.
Screen - 9002:
PROCESS BEFORE OUTPUT.
MODULE status_9002.
PROCESS AFTER INPUT.
MODULE user_command_9002.
Include for PBO:
*&---------------------------------------------------------------------*
*& Include ZSR_O01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_9001 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9001 OUTPUT.
SET PF-STATUS 'GUI_9001'.
SET TITLEBAR 'TITLE_9001'.
ENDMODULE. " STATUS_9001 OUTPUT
*&---------------------------------------------------------------------*
*& Module STATUS_9002 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9002 OUTPUT.
SET PF-STATUS 'GUI_9002'.
SET TITLEBAR 'TITLE_9002'.
PERFORM create_object.
PERFORM grid_method.
ENDMODULE. " STATUS_9002 OUTPUT
Include for PAI:
*&---------------------------------------------------------------------*
*& Include ZSR_I01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9001 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9001 INPUT.
IF ok_code_sel IS NOT INITIAL.
CASE ok_code_sel.
WHEN 'BACK'.
LEAVE PROGRAM.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'CANCEL'.
LEAVE PROGRAM.
WHEN 'DISP'.
PERFORM display_project_wbs.
WHEN 'CLR'.
PERFORM clear_screen.
ENDCASE.
ENDIF.
ENDMODULE. " USER_COMMAND_9001 INPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9002 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9002 INPUT.
IF ok_code_pro IS NOT INITIAL.
CASE ok_code_pro.
WHEN 'BACK'.
PERFORM leave_alv.
WHEN 'EXIT'.
PERFORM leave_alv.
WHEN 'CANCEL'.
PERFORM leave_alv.
ENDCASE.
ENDIF.
ENDMODULE. " USER_COMMAND_9002 INPUT
Include for Subroutine:
*&---------------------------------------------------------------------*
*& Include ZSR_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form CLEAR_SCREEN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM clear_screen .
CLEAR: s_pspid, p_vbukr.
REFRESH s_pspid[].
ENDFORM. " CLEAR_SCREEN
*&---------------------------------------------------------------------*
*& Form DISPLAY_PROJECT_WBS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_project_wbs .
TYPES: BEGIN OF ty_psphi,
psphi TYPE prps-psphi,
END OF ty_psphi.
DATA: "Work Area & Table to get converted PSPHI -
"Project Definition Internal Version
lw_psphi TYPE ty_psphi,
lt_psphi TYPE STANDARD TABLE OF ty_psphi.
SELECT pspnr pspid objnr ernam
erdat vbukr vgsbr vkokr
FROM proj INTO TABLE it_proj
WHERE pspid IN s_pspid
AND vbukr = p_vbukr.
IF sy-subrc = 0.
SORT it_proj BY pspid.
REFRESH lt_psphi.
LOOP AT it_proj INTO wa_proj.
CALL FUNCTION 'CONVERSION_EXIT_KONPD_INPUT'
EXPORTING
input = wa_proj-pspid
IMPORTING
output = lw_psphi
* PROJWA =
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF lw_psphi IS NOT INITIAL.
"Making the table of Project definition Internal Version
APPEND lw_psphi TO lt_psphi.
ENDIF.
CLEAR: wa_proj, lw_psphi.
ENDLOOP.
ELSE.
MESSAGE 'Project doesn''t exist' TYPE 'I'.
ENDIF.
IF lt_psphi IS NOT INITIAL.
SELECT pspnr posid psphi poski
pbukr pgsbr pkokr
FROM prps INTO TABLE it_prps
FOR ALL ENTRIES IN lt_psphi
WHERE psphi = lt_psphi-psphi.
IF sy-subrc = 0.
SORT it_prps BY posid.
CALL SCREEN 9002.
ELSE.
MESSAGE 'WBS Elements don''t exist' TYPE 'I'.
ENDIF.
ENDIF.
ENDFORM. " DISPLAY_PROJECT_WBS
*&---------------------------------------------------------------------*
*& Form FCAT_PROJ
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fcat_proj .
CLEAR wa_fcat_proj.
REFRESH it_fcat_proj.
DATA lv_col TYPE i.
lv_col = 1 + lv_col.
wa_fcat_proj-col_pos = lv_col.
wa_fcat_proj-fieldname = 'PSPNR'.
wa_fcat_proj-tabname = 'IT_PROJ'.
wa_fcat_proj-reptext = 'Project Definition (Internal)'.
APPEND wa_fcat_proj TO it_fcat_proj.
CLEAR wa_fcat_proj.
lv_col = 1 + lv_col.
wa_fcat_proj-col_pos = lv_col.
wa_fcat_proj-fieldname = 'PSPID'.
wa_fcat_proj-tabname = 'IT_PROJ'.
wa_fcat_proj-reptext = 'Project Definition'.
APPEND wa_fcat_proj TO it_fcat_proj.
CLEAR wa_fcat_proj.
lv_col = 1 + lv_col.
wa_fcat_proj-col_pos = lv_col.
wa_fcat_proj-fieldname = 'OBJNR'.
wa_fcat_proj-tabname = 'IT_PROJ'.
wa_fcat_proj-reptext = 'Object Number'.
APPEND wa_fcat_proj TO it_fcat_proj.
CLEAR wa_fcat_proj.
lv_col = 1 + lv_col.
wa_fcat_proj-col_pos = lv_col.
wa_fcat_proj-fieldname = 'ERNAM'.
wa_fcat_proj-tabname = 'IT_PROJ'.
wa_fcat_proj-reptext = 'Name'.
APPEND wa_fcat_proj TO it_fcat_proj.
CLEAR wa_fcat_proj.
lv_col = 1 + lv_col.
wa_fcat_proj-col_pos = lv_col.
wa_fcat_proj-fieldname = 'ERDAT'.
wa_fcat_proj-tabname = 'IT_PROJ'.
wa_fcat_proj-reptext = 'Date'.
APPEND wa_fcat_proj TO it_fcat_proj.
CLEAR wa_fcat_proj.
lv_col = 1 + lv_col.
wa_fcat_proj-col_pos = lv_col.
wa_fcat_proj-fieldname = 'VBUKR'.
wa_fcat_proj-tabname = 'IT_PROJ'.
wa_fcat_proj-reptext = 'Comapany Code'.
APPEND wa_fcat_proj TO it_fcat_proj.
CLEAR wa_fcat_proj.
lv_col = 1 + lv_col.
wa_fcat_proj-col_pos = lv_col.
wa_fcat_proj-fieldname = 'VGSBR'.
wa_fcat_proj-tabname = 'IT_PROJ'.
wa_fcat_proj-reptext = 'Business Area'.
APPEND wa_fcat_proj TO it_fcat_proj.
CLEAR wa_fcat_proj.
lv_col = 1 + lv_col.
wa_fcat_proj-col_pos = lv_col.
wa_fcat_proj-fieldname = 'VKOKR'.
wa_fcat_proj-tabname = 'IT_PROJ'.
wa_fcat_proj-reptext = 'Controlling Area'.
APPEND wa_fcat_proj TO it_fcat_proj.
CLEAR wa_fcat_proj.
ENDFORM. " FCAT_PROJ
*&---------------------------------------------------------------------*
*& Form FCAT_PRPS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fcat_prps .
CLEAR wa_fcat_prps.
REFRESH it_fcat_prps.
DATA lv_col TYPE i VALUE 0.
lv_col = 1 + lv_col.
wa_fcat_prps-col_pos = lv_col.
wa_fcat_prps-fieldname = 'PSPNR'.
wa_fcat_prps-tabname = 'IT_PRPS'.
wa_fcat_prps-reptext = 'WBS Element'.
APPEND wa_fcat_prps TO it_fcat_prps.
CLEAR wa_fcat_prps.
lv_col = 1 + lv_col.
wa_fcat_prps-col_pos = lv_col.
wa_fcat_prps-fieldname = 'POSID'.
wa_fcat_prps-tabname = 'IT_PRPS'.
wa_fcat_prps-reptext = 'WBS Element'.
APPEND wa_fcat_prps TO it_fcat_prps.
CLEAR wa_fcat_prps.
lv_col = 1 + lv_col.
wa_fcat_prps-col_pos = lv_col.
wa_fcat_prps-fieldname = 'PSPHI'.
wa_fcat_prps-tabname = 'IT_PRPS'.
wa_fcat_prps-reptext = 'Project Definition'.
APPEND wa_fcat_prps TO it_fcat_prps.
CLEAR wa_fcat_prps.
lv_col = 1 + lv_col.
wa_fcat_prps-col_pos = lv_col.
wa_fcat_prps-fieldname = 'POSKI'.
wa_fcat_prps-tabname = 'IT_PRPS'.
wa_fcat_prps-reptext = 'WBS Identification'.
APPEND wa_fcat_prps TO it_fcat_prps.
CLEAR wa_fcat_prps.
lv_col = 1 + lv_col.
wa_fcat_prps-col_pos = lv_col.
wa_fcat_prps-fieldname = 'PBUKR'.
wa_fcat_prps-tabname = 'IT_PRPS'.
wa_fcat_prps-reptext = 'WBS Company Code'.
APPEND wa_fcat_prps TO it_fcat_prps.
CLEAR wa_fcat_prps.
lv_col = 1 + lv_col.
wa_fcat_prps-col_pos = lv_col.
wa_fcat_prps-fieldname = 'PGSBR'.
wa_fcat_prps-tabname = 'IT_PRPS'.
wa_fcat_prps-reptext = 'WBS Business Area'.
APPEND wa_fcat_prps TO it_fcat_prps.
CLEAR wa_fcat_prps.
lv_col = 1 + lv_col.
wa_fcat_prps-col_pos = lv_col.
wa_fcat_prps-fieldname = 'PKOKR'.
wa_fcat_prps-tabname = 'IT_PRPS'.
wa_fcat_prps-reptext = 'WBS Controlling Area'.
APPEND wa_fcat_prps TO it_fcat_prps.
CLEAR wa_fcat_prps.
ENDFORM. " FCAT_PRPS
*&---------------------------------------------------------------------*
*& Form LEAVE_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM leave_alv .
"Calling method to refresh the ALV Grid with Container
"Refresh_table_display refreshes the ALV Grid
"FREE clears the Custom Container to generate new records
CALL METHOD: obj_grid_proj->refresh_table_display, "FREE - another method
obj_grid_prps->refresh_table_display, "FREE - another method
obj_cust_proj->free,
obj_cust_prps->free.
CLEAR: s_pspid, p_vbukr.
REFRESH: it_proj, it_prps, s_pspid[],
it_fcat_proj, it_fcat_prps.
CLEAR: ok_code_sel, ok_code_pro.
LEAVE TO SCREEN 0.
ENDFORM. " LEAVE_ALV
*&---------------------------------------------------------------------*
*& Form CREATE_OBJECT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_object .
CLEAR: obj_cust_proj, obj_cust_prps,
obj_grid_proj, obj_grid_prps.
"Creating the Container object for Header PROJ
CREATE OBJECT obj_cust_proj
EXPORTING
container_name = 'CONT_PROJ'.
"Creating the Container object for Item PRPS
CREATE OBJECT obj_cust_prps
EXPORTING
container_name = 'CONT_PRPS'.
"Creating the ALV Grid Object for Header PROJ
CREATE OBJECT obj_grid_proj
EXPORTING
i_parent = obj_cust_proj.
"Creating the ALV Grid Object for Item PRPS
CREATE OBJECT obj_grid_prps
EXPORTING
i_parent = obj_cust_prps.
ENDFORM. " CREATE_OBJECT
*&---------------------------------------------------------------------*
*& Form GRID_METHOD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM grid_method .
PERFORM fcat_proj. "Field Catalog for PROJ
PERFORM alv_layout. "ALV Layout
CALL METHOD obj_grid_proj->set_table_for_first_display
EXPORTING
* i_buffer_active =
* i_bypassing_buffer =
* i_consistency_check =
* i_structure_name =
* is_variant =
* i_save =
* i_default = 'x'
is_layout = wa_layout
* is_print =
* it_special_groups =
* it_toolbar_excluding =
* it_hyperlink =
* it_alv_graphics =
* it_except_qinfo =
* ir_salv_adapter =
CHANGING
it_outtab = it_proj
it_fieldcatalog = it_fcat_proj
* it_sort =
* it_filter =
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
PERFORM fcat_prps. "Field Catalog for PRPS
CALL METHOD obj_grid_prps->set_table_for_first_display
EXPORTING
* i_buffer_active =
* i_bypassing_buffer =
* i_consistency_check =
* i_structure_name =
* is_variant =
* i_save =
* i_default = 'x'
is_layout = wa_layout
* is_print =
* it_special_groups =
* it_toolbar_excluding =
* it_hyperlink =
* it_alv_graphics =
* it_except_qinfo =
* ir_salv_adapter =
CHANGING
it_outtab = it_prps
it_fieldcatalog = it_fcat_prps
* it_sort =
* it_filter =
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
ENDFORM. " GRID_METHOD
*&---------------------------------------------------------------------*
*& Form ALV_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM alv_layout .
wa_layout-zebra = 'X'.
wa_layout-cwidth_opt = 'X'.
wa_layout-sel_mode = 'X'.
ENDFORM. " ALV_LAYOUT
Top Include:
*&---------------------------------------------------------------------*
*& Include ZSR_TOP Module Pool ZSR_MOD
*&
*&---------------------------------------------------------------------*
PROGRAM zsr_mod.
TABLES: proj, prps.
TYPES: BEGIN OF ty_proj,
pspnr TYPE proj-pspnr,
pspid TYPE proj-pspid,
objnr TYPE proj-objnr,
ernam TYPE proj-ernam,
erdat TYPE proj-erdat,
vbukr TYPE proj-vbukr,
vgsbr TYPE proj-vgsbr,
vkokr TYPE proj-vkokr,
END OF ty_proj,
BEGIN OF ty_prps,
pspnr TYPE prps-pspnr,
posid TYPE prps-posid,
psphi TYPE prps-psphi,
poski TYPE prps-poski,
pbukr TYPE prps-pbukr,
pgsbr TYPE prps-pgsbr,
pkokr TYPE prps-pkokr,
END OF ty_prps.
DATA: ok_code_sel TYPE sy-ucomm,
ok_code_pro TYPE sy-ucomm.
DATA: wa_proj TYPE ty_proj,
wa_prps TYPE ty_prps,
it_proj TYPE STANDARD TABLE OF ty_proj,
it_prps TYPE STANDARD TABLE OF ty_prps.
DATA: wa_layout TYPE lvc_s_layo,
wa_fcat_proj TYPE lvc_s_fcat,
wa_fcat_prps TYPE lvc_s_fcat,
it_fcat_proj TYPE STANDARD TABLE OF lvc_s_fcat,
it_fcat_prps TYPE STANDARD TABLE OF lvc_s_fcat.
DATA: obj_cust_proj TYPE REF TO cl_gui_custom_container,
obj_cust_prps TYPE REF TO cl_gui_custom_container,
obj_grid_proj TYPE REF TO cl_gui_alv_grid,
obj_grid_prps TYPE REF TO cl_gui_alv_grid.
SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
PARAMETERS p_vbukr TYPE proj-vbukr.
SELECT-OPTIONS s_pspid FOR proj-pspid.
SELECTION-SCREEN END OF SCREEN 100.
The output is as follows:
Screen - 9001:
Screen - 9002:
10 comments:
Really your posts are very useful for sap abap learners thanks for continuing this blog
Thank u .that awesome blog
thanks a ton brother
Good Explanation very useful for Beginners, Thank you.
Hi, This is shalini from Chennai learned SAP Training in Chennai from mr.karthick. The training really was good and i got selected in leading mnc company as SAP Consultant.
You can contact 8122241286 for Best SAP Training in Chennai or reach www.thecreatingexperts.com
SAP Success Factors Real Time Hands on Training in Chennai...
Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..
http://thecreatingexperts.com/sap-successfactors-training-in-chennai/
If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trainer MR.Karthick
CONTACT:8122241286
Both Classroom/Online Training is Available!!!!!!
sare topic ke step step by step bta rkha h , to iska q nhi,
alv report display using module pool,
but not done,
this is not right program,
copy paist mar rkha h ye program to.
Thank you for sharing the great blog. BEST SAP ABAP TRAINING IN HYDERABAD
Hi Sandip,
Thanks For the Information.
Could you Please Mention that What is the Requirement for this scenario means why it has been developed through Module Pool Screens ?
Regards ,
Kiran
Post a Comment