0% found this document useful (0 votes)
2K views

Using Checkbox in Alv Grid Display

The document describes creating an ALV grid display in SAP with checkboxes to select records for processing. It retrieves work order data from multiple tables and combines it into a final table for display. Checkboxes are added to select records, which are then stored in a separate table to be processed. The user can trigger an action to display the selected records in another ALV grid or use their own code to process the records.

Uploaded by

jeet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Using Checkbox in Alv Grid Display

The document describes creating an ALV grid display in SAP with checkboxes to select records for processing. It retrieves work order data from multiple tables and combines it into a final table for display. Checkboxes are added to select records, which are then stored in a separate table to be processed. The user can trigger an action to display the selected records in another ALV grid or use their own code to process the records.

Uploaded by

jeet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 36

using Checkbox in alv grid display

BALVBT01

1. REPORT Z_TEST_GRID .
2.
3.
4. *Data Declaration
5. *----------------
6. DATA: BEGIN OF T_EKKO,
7. EBELN TYPE EKPO-EBELN,
8. EBELP TYPE EKPO-EBELP,
9. FLAG TYPE C,
10. END OF T_EKKO.
11.
12. <b> DATA: GD_REPID LIKE SY-REPID, "Exists
13. REF_GRID TYPE REF TO CL_GUI_ALV_GRID. "new</b>
14.
15. DATA: BEGIN OF IT_EKKO OCCURS 0.
16. INCLUDE STRUCTURE T_EKKO.
17. DATA: END OF IT_EKKO.
18.
19. DATA: BEGIN OF IT_BACKUP OCCURS 0.
20. INCLUDE STRUCTURE T_EKKO.
21. DATA: END OF IT_BACKUP.
22. *ALV data declarations
23. TYPE-POOLS: SLIS. "ALV Declarations
24. DATA: FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
25. GD_LAYOUT TYPE SLIS_LAYOUT_ALV.
26.
27.
28. ************************************************************************
29. *Start-of-selection.
30. START-OF-SELECTION.
31.
32. PERFORM DATA_RETRIEVAL.
33. PERFORM BUILD_FIELDCATALOG.
34. PERFORM BUILD_LAYOUT.
35. IT_BACKUP[] = IT_EKKO[].
36. PERFORM DISPLAY_ALV_REPORT.
37.
38.
39. *&--------------------------------------------------------------------*
40. *& Form build_fieldcatalog
41. *&--------------------------------------------------------------------*
42. * text
43. *---------------------------------------------------------------------*
44. FORM BUILD_FIELDCATALOG.
45. REFRESH FIELDCATALOG.
46. CLEAR FIELDCATALOG.
47. *
48. FIELDCATALOG-FIELDNAME = 'FLAG'.
49. FIELDCATALOG-SELTEXT_M = 'Check'.
50. FIELDCATALOG-INPUT = 'X'.
51. FIELDCATALOG-EDIT = 'X'.
52. fieldcatalog-checkbox = 'X'.
53. FIELDCATALOG-COL_POS = 1.
54. APPEND FIELDCATALOG.
55. CLEAR FIELDCATALOG.
56.
57. FIELDCATALOG-FIELDNAME = 'EBELN'.
58. FIELDCATALOG-SELTEXT_M = 'Purchase Order'.
59. FIELDCATALOG-INPUT = 'X'.
60. FIELDCATALOG-EDIT = 'X'.
61. FIELDCATALOG-COL_POS = 2.
62. APPEND FIELDCATALOG.
63. CLEAR FIELDCATALOG.
64.
65. FIELDCATALOG-FIELDNAME = 'EBELP'.
66. FIELDCATALOG-SELTEXT_M = 'PO Item'.
67. FIELDCATALOG-COL_POS = 3.
68. APPEND FIELDCATALOG.
69. CLEAR FIELDCATALOG.
70.
71. ENDFORM. " BUILD_FIELDCATALOG
72.
73.
74. *&---------------------------------------------------------------------*
75. *& Form BUILD_LAYOUT
76. *&---------------------------------------------------------------------*
77. * Build layout for ALV grid report
78. *----------------------------------------------------------------------*
79. FORM BUILD_LAYOUT.
80. "Permet d'ajuster les colonnes au text
81. * gd_layout-colwidth_optimize = 'X'.
82. * GD_LAYOUT-TOTALS_TEXT = 'Totals'(201).
83.
84. * gd_layout-box_fieldname = 'SELECT'.
85. * gd_layout-box_tabname = 'IT_EKKO'.
86.
87. ENDFORM. " BUILD_LAYOUT
88.
89.
90. *&---------------------------------------------------------------------*
91. *& Form DISPLAY_ALV_REPORT
92. *&---------------------------------------------------------------------*
93. * Display report using ALV grid
94. *----------------------------------------------------------------------*
95. FORM DISPLAY_ALV_REPORT .
96. <b>GD_REPID = SY-REPID.</b>
97.
98.
99. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
100. EXPORTING
101. I_CALLBACK_PROGRAM = GD_REPID
102. * i_callback_top_of_page = 'TOP-OF-PAGE'
103. I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
104. I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
105. * i_grid_title = 'My Title'
106. IS_LAYOUT = GD_LAYOUT
107. IT_FIELDCAT = FIELDCATALOG[]
108. TABLES
109. T_OUTTAB = IT_EKKO
110. EXCEPTIONS
111. PROGRAM_ERROR = 1
112. OTHERS = 2.
113.
114. IF SY-SUBRC <> 0.
115. WRITE:/ SY-SUBRC.
116. ENDIF.
117.
118. ENDFORM. " DISPLAY_ALV_REPORT
119.
120.
121. *&---------------------------------------------------------------------*
122. *& Form DATA_RETRIEVAL
123. *&---------------------------------------------------------------------*
124. * Retrieve data form EKPO table and populate itab it_ekko
125. *----------------------------------------------------------------------*
126. FORM DATA_RETRIEVAL.
127. SELECT EBELN EBELP
128. UP TO 10 ROWS
129. FROM EKPO
130. INTO CORRESPONDING FIELDS OF TABLE IT_EKKO.
131. ENDFORM. " DATA_RETRIEVAL
132.
133.
134. *----------------------------------------------------------------------*
135. * FORM SET_PF_STATUS *
136. *----------------------------------------------------------------------*
137. FORM SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
138. SET PF-STATUS 'STANDARD_FULLSCREEN1' EXCLUDING RT_EXTAB.
139. ENDFORM. "set_pf_status
140.
141.
142. *&--------------------------------------------------------------------*
143. *& Form user_command
144. *&--------------------------------------------------------------------*
145. * text
146. *---------------------------------------------------------------------*
147. * -->R_UCOMM text
148. * -->RS_SELFIELDtext
149. *---------------------------------------------------------------------*
150. FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
151. RS_SELFIELD TYPE SLIS_SELFIELD.
152.
153.
154.
155.
156. *then insert the following code in your USER_COMMAND routine...
157.
158.
159. <b> IF REF_GRID IS INITIAL.
160. CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
161. IMPORTING
162. E_GRID = REF_GRID.
163. ENDIF.
164.
165. IF NOT REF_GRID IS INITIAL.
166. CALL METHOD REF_GRID->CHECK_CHANGED_DATA
167. .
168. ENDIF.</b>
169.
170. *modify
171.
172. CASE R_UCOMM.
173. WHEN '&IC1'.
174. CHECK RS_SELFIELD-TABINDEX > 0.
175. IF RS_SELFIELD-VALUE EQ '6000000001'.
176. CALL TRANSACTION 'ZDF2'.
177. ENDIF.
178. WHEN 'REFRESH'.
179.
180. READ TABLE IT_EKKO INDEX RS_SELFIELD-TABINDEX.
181. IF SY-SUBRC = 0.
182. READ TABLE IT_BACKUP INDEX RS_SELFIELD-TABINDEX.
183. IF SY-SUBRC = 0.
184. IF IT_EKKO <> IT_BACKUP.
185. * then do your check
186. ENDIF.
187. ENDIF.
188. ENDIF.
189.
190. PERFORM DATA_RETRIEVAL.
191. RS_SELFIELD-REFRESH = 'X'.
192.
193. ENDCASE.
194. ENDFORM. "user_command
ALV Grid Display with checkbox to process selected
records at runtime
Skip to end of metadata
 Created by Tarun Gambhir, last modified by Anonymous on Jul 04, 2012
Go to start of metadata
*&---------------------------------------------------------------------*
*& Report ZPM_WO
*&---------------------------------------------------------------------*
*& Author : Tarun Gambhir
*& Description : To generate an ALV report display to track
*& damage-type work orders and pending completion status
*& whose order status is PM01 or PM02 in order to ensure
*& timely completions.
*&---------------------------------------------------------------------*
*& Display records in first screen in ALV Grid Display with checkboxes
*& appended with each record and perform an user action to display the
*& selected records into another ALV Gird
*& or user can use their own code as per their requirements
*&---------------------------------------------------------------------*

REPORT zpm_wo NO STANDARD PAGE HEADING MESSAGE-ID zmsg_wo.

*&---------------------------------------------------------------------*
* TYPE POOLS
*&---------------------------------------------------------------------*
TYPE-POOLS : slis. " used for ALV output

*&---------------------------------------------------------------------*
* TYPE DECLARATION
*&---------------------------------------------------------------------*
TYPES :
* for table aufk (work order details)
BEGIN OF t_aufk,
aufnr TYPE aufk-aufnr, " order number
ktext TYPE aufk-ktext, " description
objnr TYPE aufk-objnr, " object number
END OF t_aufk,

* for table jest (object status details)


BEGIN OF t_jest,
objnr TYPE jest-objnr, " object number
END OF t_jest,

* for table afko (basic finish date details)


BEGIN OF t_afko,
aufnr TYPE afko-aufnr, " order number
gltrp TYPE afko-gltrp, "basic finish date
END OF t_afko,
* for table qmel (notification number details)
BEGIN OF t_qmel,
aufnr TYPE qmel-aufnr, " order number
qmnum TYPE qmel-qmnum, " notification number
END OF t_qmel,

* final table from which the records need to be displayed


BEGIN OF t_final,
aufnr TYPE aufk-aufnr, " order number
ktext TYPE aufk-ktext, " description
qmnum TYPE qmel-qmnum, " notification number
flag(1), " for selection of records
END OF t_final,

* table which contains the selected records to be processed


BEGIN OF t_process,
aufnr TYPE aufk-aufnr, " order number
ktext TYPE aufk-ktext, " description
qmnum TYPE qmel-qmnum, " notification number
END OF t_process,

* table for messages


BEGIN OF t_message,
aufnr TYPE aufk-aufnr, "order number
msg(200), "message text
END OF t_message.

*&---------------------------------------------------------------------*
* CONTANTS DECLARATION
*&---------------------------------------------------------------------*
CONSTANTS : c_check(1) VALUE 'X', " value used to set X for a field
c_langu(1) VALUE 'E', " language used
c_ustat(4) VALUE 'TECO'. " object status description

*&---------------------------------------------------------------------*
* RANGES DECLARATION
*&---------------------------------------------------------------------*
* RANGE VALUE TO BE USED FOR THE ORDER TYPE
*&---------------------------------------------------------------------*
RANGES : r_auart FOR aufk-auart. "for order type

*&---------------------------------------------------------------------*
* PARAMETERS FOR SELECTION-SCREEN
*&---------------------------------------------------------------------*
* SELECTION SCREEN BLOCK FOR THE VARIANT NAME
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_var TYPE disvariant-variant. " variant parameter
SELECTION-SCREEN END OF BLOCK b1.

*&---------------------------------------------------------------------*
* VARIABLE DECLARATIONS
*&---------------------------------------------------------------------*
DATA : v_rep_id TYPE sy-repid, " report id
v_istat TYPE tj02t-istat, " order status
v_cdate TYPE sy-datum, " current system date
v_line_count TYPE i, " number of lines in final internal table
v_filename TYPE string. " path for download error log

*&---------------------------------------------------------------------*
* INTERNAL TABLE & WORK AREA DECLARATIONS
*&---------------------------------------------------------------------*
* TYPE OF T_AUFK
* internal table to select records for damaged order types
DATA : it_aufk TYPE STANDARD TABLE OF t_aufk,
* work area for damaged order types
wa_aufk TYPE t_aufk.

* TYPE OF T_JEST
* internal table to select object number based upon user status
DATA : it_jest TYPE STANDARD TABLE OF t_jest,
* work area to select object number based upon user status
wa_jest TYPE t_jest.

* TYPE OF T_AFKO
* internal table to select the basic finish date corresopnding to work order
DATA : it_afko TYPE STANDARD TABLE OF t_afko,
* work area to select the basic finish date corresopnding to work order
wa_afko TYPE t_afko.

* TYPE OF T_QMEL
* internal table to select the notification number corresopnding to object number
DATA : it_qmel TYPE STANDARD TABLE OF t_qmel,
* work area to select the notification number corresopnding to object number
wa_qmel TYPE t_qmel.

* TYPE OF T_FINAL
* final internal table to select final records to be displayed
DATA : it_final TYPE STANDARD TABLE OF t_final,
* final work area to select final records to be displayed
wa_final TYPE t_final.

* TYPE OF T_PROCESS
* final internal table to select final records to be displayed
DATA : it_process TYPE STANDARD TABLE OF t_process,
* final work area to select final records to be displayed
wa_process TYPE t_process.

* FOR VARIANT
DATA : wa_variant TYPE disvariant.
* FOR VARIANT IMPORT
DATA : wa_i_variant TYPE disvariant.

*&---------------------------------------------------------------------*
* ALV INTERNAL TABLE & WORK AREA DECLARATIONS
*&---------------------------------------------------------------------*
* FIELD CATALOG
DATA : it_field TYPE slis_t_fieldcat_alv, "internal table for field catalog
wa_field TYPE slis_fieldcat_alv. "work area for field catalog

* SORTING INFO
DATA : it_sort TYPE slis_t_sortinfo_alv, "internal table for sorting field
wa_sort TYPE slis_sortinfo_alv. "work area for sorting field

* FOR LAYOUT OF ALV GRID


DATA : wa_layout TYPE slis_layout_alv. "work area for layout design

*&---------------------------------------------------------------------*
* ALV INTERNAL TABLE & WORK AREA DECLARATIONS
*&---------------------------------------------------------------------*
* FIELD CATALOG
DATA : it_field1 TYPE slis_t_fieldcat_alv, "internal table for field catalog
wa_field1 TYPE slis_fieldcat_alv. "work area for field catalog

* SORTING INFO
DATA : it_sort1 TYPE slis_t_sortinfo_alv, "internal table for sorting field
wa_sort1 TYPE slis_sortinfo_alv. "work area for sorting field

* FOR LAYOUT OF ALV GRID


DATA : wa_layout1 TYPE slis_layout_alv. "work area for layout design

*&---------------------------------------------------------------------*
* INITIALIZATION
*&---------------------------------------------------------------------*
* TO INITIALIZE ALL THE VARIABLES TO BE USED
* IN THE PROGRAM
*&---------------------------------------------------------------------*
INITIALIZATION.
v_rep_id = sy-repid. " report id
r_auart-sign = 'I'. " for inclusive
r_auart-option = 'BT'. " for between operator
r_auart-low = 'PM01'. " order type(low value)
r_auart-high = 'PM02'. " order type(high value)
APPEND r_auart. " append values for range
v_cdate = sy-datum - 7. " take date 7 days before current date
wa_variant-report = v_rep_id. " report for using variants

*&---------------------------------------------------------------------*
* AT SELECTION-SCREEN OUTPUT
*&---------------------------------------------------------------------*
* TO CLEAR THE VALUE OF THE VARIANT PARAMETER WHEN USER
* RETURNS FROM THE OUTPUT SCREEN TO THE SELECTION SCREEN
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
CLEAR p_var. "clear variant value

*&---------------------------------------------------------------------*
* AT-SELECTION SCREEN ON VALUE REQUEST
*&---------------------------------------------------------------------*
* TO GET THE F4 HELP FOR EXISTING VARIANTS
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_var.
PERFORM f4_variant_help USING p_var.

*&---------------------------------------------------------------------*
* AT-SELECTION SCREEN
*&---------------------------------------------------------------------*
* TO PASS THE DEFAULT VALUE OF THE VARIANT IF THE PARAMETER
* FOR VARIANT IS LEFT AS BLANK
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN.
*&---------------------------------------------------------------------*
* IF THE USER DOESN'T ENTERS ANY VALUE FOR VARIANT
* THEN THE DEFAULT VARIANT SHOULD BE USED TO DISPLAY
*&---------------------------------------------------------------------*
IF p_var EQ ' '.
PERFORM get_default_variant USING p_var.

*&---------------------------------------------------------------------*
* IF THE USER ENTERS SOME VARIANT NAME FOR THE SELECTION
* SCREEN WHICH NEED TO BE VALIDATED AGAINST THE EXISTING
* VARIANTS
*&---------------------------------------------------------------------*
ELSE.
PERFORM check_variant_existence USING p_var.

ENDIF.

*&---------------------------------------------------------------------*
* START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.

*&---------------------------------------------------------------------*
* CLEAR ALL THE CONTENTS OF ALL INTERBAL TABLES
*&---------------------------------------------------------------------*
REFRESH it_jest.
REFRESH it_aufk.
REFRESH it_afko.
REFRESH it_qmel.
REFRESH it_final.
*&---------------------------------------------------------------------*
* select user status from TJ02T for TXT04(status of an object)
* into variable V_ISTAT
*&---------------------------------------------------------------------*
SELECT SINGLE
istat
FROM tj02t
INTO (v_istat)
WHERE
txt04 EQ c_ustat AND
spras EQ c_langu.

*&---------------------------------------------------------------------*
* select object number based upon the user status selected
*&---------------------------------------------------------------------*
SELECT
objnr
FROM jest
INTO TABLE it_jest
WHERE
stat EQ v_istat.
IF sy-subrc <> 0.
MESSAGE e003.
ELSE.
*&---------------------------------------------------------------------*
* select into it_aufk table: object number, description and
* object number based on object number selected and order type
* in PM01 and PM02
*&---------------------------------------------------------------------*
SELECT
aufnr
ktext
objnr
FROM aufk
INTO TABLE it_aufk
FOR ALL ENTRIES IN it_jest
WHERE
objnr EQ it_jest-objnr AND
auart IN r_auart.

IF sy-subrc <> 0.
MESSAGE e002.
ELSE.
*&---------------------------------------------------------------------*
* select into it_afko table: order number and basic finish date
* based upon order number selected and basic finish date as
* v_cdate variable
*&---------------------------------------------------------------------*
SELECT
aufnr
gltrp
FROM afko
INTO TABLE it_afko
FOR ALL ENTRIES IN it_aufk
WHERE
aufnr EQ it_aufk-aufnr AND
gltrp LE v_cdate.
*&---------------------------------------------------------------------*
* select into it_qmel table: order number and notification
* number based on the order number selected
*&---------------------------------------------------------------------*
SELECT
aufnr
qmnum
FROM qmel
INTO TABLE it_qmel
FOR ALL ENTRIES IN it_aufk
WHERE
aufnr EQ it_aufk-aufnr.
ENDIF.
ENDIF.

*&---------------------------------------------------------------------*
* READ THE RECORDS FOMR THE ABOVE POPULATED INTERNAL TABLE
* INTO WORK AREA AND THEN POPULATE THE FINAL INTERNAL
* TABLE
*&---------------------------------------------------------------------*
* read internal table it_jest into work area wa_jest
LOOP AT it_jest INTO wa_jest.

* read it_aufk based on object number from wa_jest


READ TABLE it_aufk INTO wa_aufk WITH KEY objnr = wa_jest-objnr.
* if records found
IF sy-subrc EQ 0.
* read it_afko for order number and description based on order number
READ TABLE it_afko INTO wa_afko WITH KEY aufnr = wa_aufk-aufnr.
* if records found
IF sy-subrc EQ 0.
wa_final-aufnr = wa_afko-aufnr. "move order number to it_final
wa_final-ktext = wa_aufk-ktext. "move description to it_final
ELSE.
* if no record found then move to next loop pass
CONTINUE.
ENDIF.
ELSE.
* if no record found then move to next loop pass
CONTINUE.
ENDIF.

* read it_qmel for description based on the order number selected above
READ TABLE it_qmel INTO wa_qmel WITH KEY aufnr = wa_final-aufnr.
* if records found
IF sy-subrc EQ 0.
wa_final-qmnum = wa_qmel-qmnum. "move notification number to it_final
ENDIF.

* finally append the records into the final internal table


APPEND wa_final TO it_final. "append wa_final into it_final
CLEAR wa_final. "clear work area
CLEAR wa_aufk. "clear work area
CLEAR wa_qmel. "clear work area

ENDLOOP.

*&---------------------------------------------------------------------*
* TO COUNT THE NUMBER OF RECORDS IN THE FINAL INTERNAL
* TABLE AND RETURN TO SELECTION SCREEN
* IF NO RECORDS EXISTS THEN AN INFORMATION MESSGE IS DISPLAYED
*&---------------------------------------------------------------------*
DESCRIBE TABLE it_final
LINES v_line_count.
IF ( v_line_count EQ 0 ).
MESSAGE i002. "error message
EXIT.
ENDIF.

*&---------------------------------------------------------------------*
* END-OF-SELECTION
*&---------------------------------------------------------------------*
END-OF-SELECTION.
*&---------------------------------------------------------------------*
* FIELD CATALOG FOR FIRST GRID DISPLAY
*&---------------------------------------------------------------------*
PERFORM field_catalog.

*&---------------------------------------------------------------------*
* SORT W.R.T. WORK ORDER NUMBER FOR FIRST GRID DISPLAY
*&---------------------------------------------------------------------*
PERFORM sort_field.

*&---------------------------------------------------------------------*
* FOR LAYOUT FOR FIRST GRID DISPLAY
*&---------------------------------------------------------------------*
PERFORM set_layout.

*&---------------------------------------------------------------------*
* DISPLAY RECORDS IN ALV GRID FOR FIRST GRID DISPLAY
*&---------------------------------------------------------------------*
PERFORM alv_display.

*&---------------------------------------------------------------------*
*& SUBROUTINE DEFINITIONS
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Form FIELD_CATALOG
*&---------------------------------------------------------------------*
* SUB-ROUTINE FIELD_CATALOG USED TO SET THE COLUMNS FOR
* THE ALV GRID (OUTPUT FORMAT)
* SETS THE COLUMN NAME AND THE OUTPUT LENGTH FOR THE FIELDS
*----------------------------------------------------------------------*
FORM field_catalog .
wa_field-fieldname = 'FLAG'. " name of field from internal table
wa_field-tabname = 'IT_FINAL'. " internal table name
wa_field-outputlen = 2. " output length on screen
wa_field-checkbox = c_check. " print as checkbox
wa_field-edit = c_check. " make field open for input
wa_field-seltext_l = ' '. " header information
APPEND wa_field TO it_field. " append field catalog internal table
CLEAR wa_field. " clear field catalog work area

wa_field-fieldname = 'AUFNR'. " name of field from internal table


wa_field-tabname = 'IT_FINAL'. " internal table name
wa_field-outputlen = 20. " output length on screen
wa_field-seltext_l = text-003. " header information
APPEND wa_field TO it_field. " append field catalog internal table
CLEAR wa_field. " clear field catalog work area

wa_field-fieldname = 'KTEXT'. " name of field from internal table


wa_field-tabname = 'IT_FINAL'. " internal table name
wa_field-outputlen = 45. " output length on screen
wa_field-seltext_l = text-004. " header information
APPEND wa_field TO it_field. " append field catalog internal table
CLEAR wa_field. " clear field catalog work area

wa_field-fieldname = 'QMNUM'. " name of field from internal table


wa_field-tabname = 'IT_FINAL'. " internal table name
wa_field-outputlen = 22. " output length on screen
wa_field-seltext_l = text-005. " header information
APPEND wa_field TO it_field. " append field catalog internal table
CLEAR wa_field. " clear field catalog work area

ENDFORM. " FIELD_CATALOG


*&---------------------------------------------------------------------*
*& Form SORT_FIELD
*&---------------------------------------------------------------------*
* SUB-ROUTINE SORT_FIELD IS USED TO SORT THE RECORDS IN THE
* INTERNAL TABLE BASED ON THE GIVEN FIELD AND NATURE OF
* SORTING TO BE DONE (ASCENDING OR DESCENDING)
*----------------------------------------------------------------------*
FORM sort_field .

wa_sort-spos = 1. " sort priority


wa_sort-fieldname = 'AUFNR'. " field on which records sorted
wa_sort-tabname = 'IT_FINAL'. " internal table name
wa_sort-up = c_check. " sort ascending
APPEND wa_sort TO it_sort. " append sort info internal table
CLEAR wa_sort. " clear sort info work area

ENDFORM. " SORT_FIELD


*&---------------------------------------------------------------------*
*& Form SET_LAYOUT
*&---------------------------------------------------------------------*
* SUB-ROUTINE SET_LAYOUT IS USED TO SET THE DISPLAY OF THE
* ALV GRID LINES IN ALTERNATIVE COLOURS
*----------------------------------------------------------------------*
FORM set_layout .

wa_layout-zebra = c_check. " so set colors of line alternatively

ENDFORM. " SET_LAYOUT

*&---------------------------------------------------------------------*
*& Form ALV_DISPLAY
*&---------------------------------------------------------------------*
* SUB-ROUTINE ALV_DISPLAY IS USED TO SET THE PARAMETERS
* FOR THE FUNCTION MODULE REUSE_ALV_GRID_DISPLAY
* AND PASS THE INTERNAL TABLE EXISTING THE RECORDS TO BE
* DISPLAYED IN THE GRID FORMAT
*----------------------------------------------------------------------*
FORM alv_display .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK =''
* I_BYPASSING_BUFFER =''
* I_BUFFER_ACTIVE =''
i_callback_program = v_rep_id " report id
i_callback_pf_status_set = 'PF' " for PF-STATUS
i_callback_user_command = 'USER_COMMAND' " for User-Command
* I_CALLBACK_TOP_OF_PAGE =''
* I_CALLBACK_HTML_TOP_OF_PAGE =''
* I_CALLBACK_HTML_END_OF_LIST =''
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID =''
* I_GRID_TITLE =
* I_GRID_SETTINGS =
is_layout = wa_layout " for layout
it_fieldcat = it_field " field catalog
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
it_sort = it_sort " sort info
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* i_save = 'A'
* is_variant = wa_variant " variant name
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN =0
* I_SCREEN_START_LINE =0
* I_SCREEN_END_COLUMN =0
* I_SCREEN_END_LINE =0
* I_HTML_HEIGHT_TOP =0
* I_HTML_HEIGHT_END =0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it_final " internal table
EXCEPTIONS
program_error =1
OTHERS = 2.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

ENDFORM. " ALV_DISPLAY

*&---------------------------------------------------------------------*
*& Form pf
*&---------------------------------------------------------------------*
* SUB-ROUTINE PF IS USED TO SET THE PF-STATUS OF THE SCREEN
* ON WHICH THE ALV GRID IS DISPLAYED
*----------------------------------------------------------------------*
* -->RT_EXTAB
*----------------------------------------------------------------------*
FORM pf USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZTG_STAT'.
ENDFORM. "pf

*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* SUB-ROUTINE USER_COMMAND IS USED TO HANDLE THE USER ACTION
* AND EXECUTE THE APPROPIATE CODE
*----------------------------------------------------------------------*
* -->LV_OKCODE used to capture the function code
* of the user-defined push-buttons
* -->L_SELFIELD text
*----------------------------------------------------------------------*
FORM user_command USING lv_okcode LIKE sy-ucomm l_selfield TYPE slis_selfield.

* assign the function code to variable v_okcode


lv_okcode = sy-ucomm.

* handle the code execution based on the function code encountered


CASE lv_okcode.
* when the function code is EXECUTE then process the selected records
WHEN 'EXECUTE'.

* refresh it_process when user processes selected records


REFRESH it_process.

* to reflect the data changed into internal table


DATA : ref_grid TYPE REF TO cl_gui_alv_grid. "new

IF ref_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref_grid.
ENDIF.

IF NOT ref_grid IS INITIAL.


CALL METHOD ref_grid->check_changed_data.
ENDIF.

*----------------------------------------------------------------------*
* sort the internal table by flag descending so that the selected
* records are appended at the beginning of internal table
*----------------------------------------------------------------------*
SORT it_final BY flag DESCENDING.

*----------------------------------------------------------------------*
* move the selected records from final internal table into another
* internal table so that they can be processed
*----------------------------------------------------------------------*
LOOP AT it_final INTO wa_final WHERE flag = 'X'.
wa_process-aufnr = wa_final-aufnr.
wa_process-ktext = wa_final-ktext.
wa_process-qmnum = wa_final-qmnum.
APPEND wa_process TO it_process.
ENDLOOP.

* refresh the ALV Grid output from internal table


l_selfield-refresh = c_check.

* now all the selected records by the user at run-time are appended into
* into a new internal table which can now be used to processed as per the
* user requirements
DATA : line_count1 TYPE i.

DESCRIBE TABLE it_process


LINES line_count1.
IF line_count1 GE 1.
PERFORM user_action.
ELSE.
MESSAGE e002.
ENDIF.

WHEN 'SEL_ALL'.
* to select all the records displayed in ALV Grid
LOOP AT it_final INTO wa_final.
wa_final-flag = 'X'.
MODIFY it_final FROM wa_final.
ENDLOOP.
* refresh the ALV Grid output from internal table
l_selfield-refresh = c_check.

WHEN 'DESEL_ALL'.
* to deselect all the records displayed in ALV Grid
LOOP AT it_final INTO wa_final.
wa_final-flag = ' '.
MODIFY it_final FROM wa_final.
ENDLOOP.
* refresh the ALV Grid output from internal table
l_selfield-refresh = c_check.

ENDCASE.

ENDFORM. "USER_COMMAND
*&---------------------------------------------------------------------*
*& Form F4_VARIANT_HELP
*&---------------------------------------------------------------------*
* SUB-ROUTINE f4_variant_help TO GET A F4 HELP FOR VARIANT
* SELECTION AND DISPLAY DATA ACCORDINGLY
*----------------------------------------------------------------------*
* <--P_P_VAR text
*----------------------------------------------------------------------*
FORM f4_variant_help USING p_p_var.

CALL FUNCTION 'REUSE_ALV_VARIANT_F4'


EXPORTING
is_variant = wa_variant " export variant
* I_TABNAME_HEADER =
* I_TABNAME_ITEM =
* IT_DEFAULT_FIELDCAT =
i_save = 'A' " layout for all users
i_display_via_grid = 'X' " grid view of variants
IMPORTING
* E_EXIT =
es_variant = wa_i_variant " import variant
EXCEPTIONS
not_found =1
program_error =2
OTHERS = 3.
IF sy-subrc = 0.
* PASS THE SELECTED VARIANT TO THE SELECTION SCREEN FIELD
p_p_var = wa_i_variant-variant.
ELSEIF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " F4_VARIANT_HELP
*&---------------------------------------------------------------------*
*& Form GET_DEFAULT_VARIANT
*&---------------------------------------------------------------------*
* SUB-ROUTINE GET_DEFAULT_VARIANT TO PASS THE DEFAULT VARIANT
* IF USER DOESN'T ENTERS ANY VALUE FOR THE VARIANT
*----------------------------------------------------------------------*
* <--P_P_VAR variant name
*----------------------------------------------------------------------*
FORM get_default_variant USING l_p_var.

CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'


EXPORTING
i_save = 'A'
CHANGING
cs_variant = wa_variant "variant name
EXCEPTIONS
wrong_input = 1
not_found =2
program_error = 3
OTHERS = 4.
* IF DEFAULT VARIANT FOUND
IF sy-subrc = 0.
* PASS THE DEFAULT VARIANT TO THE SELECTION SCREEN FIELD
l_p_var = wa_variant-variant.
ELSEIF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

ENDFORM. " GET_DEFAULT_VARIANT


*&---------------------------------------------------------------------*
*& Form CHECK_VARIANT_EXISTENCE
*&---------------------------------------------------------------------*
* SUB-ROUTINE CHECK_VARIANT_EXISTENCE TO VALIDATE THE VARIANT
* NAME ENTERED BY THE USER
* IF VARIANT FOUND THEN EXECUTE
* ELSE DISPLAY ERROR MESSAGE
*----------------------------------------------------------------------*
* <--P_P_VAR variant name
*----------------------------------------------------------------------*
FORM check_variant_existence USING l_p_var.

*&---------------------------------------------------------------------*
* ASSIGN THE VALUE OF THE VARIANT ENTERED BY USER TO THE
* WORK AREA FIELD AND CHECK FOR ITS EXISTENCE
*&---------------------------------------------------------------------*
wa_variant-variant = l_p_var.
*&---------------------------------------------------------------------*
* TO CHECK THE EXISTENCE FOR VARIANT CORRESPONDING TO
* EXISTING VARIANT IF THE USER ENTERS SOME VALUE FOR
* THE PARAMETER
*&---------------------------------------------------------------------*
CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
EXPORTING
i_save = 'A'
CHANGING
cs_variant = wa_variant " variant name
EXCEPTIONS
wrong_input = 1
not_found =2
program_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE e001.
ENDIF.

ENDFORM. " CHECK_VARIANT_EXISTENCE


*&---------------------------------------------------------------------*
*& Form USER_ACTION
*&---------------------------------------------------------------------*
* SUB-ROUTINE USER_ACTION CAN BE USED AS PER THE USER REQUIREMENT
* TO PROCESS THE SELECTED RECORDS IN ALV GRID DISPLAY
*----------------------------------------------------------------------*
FORM user_action.
* user code to process selected records in internal table
* it_process

*&---------------------------------------------------------------------*
* FIELD CATALOG FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
PERFORM field_catalog1.

*&---------------------------------------------------------------------*
* SORT W.R.T. WORK ORDER NUMBER FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
PERFORM sort_field1.

*&---------------------------------------------------------------------*
* FOR LAYOUT FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
PERFORM set_layout1.

*&---------------------------------------------------------------------*
* DISPLAY RECORDS IN ALV GRID FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
PERFORM alv_display1.

ENDFORM. " F4_FILE_REQUEST


*&---------------------------------------------------------------------*
*& Form FIELD_CATALOG1 FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
* SUB-ROUTINE FIELD_CATALOG USED TO SET THE COLUMNS FOR
* THE ALV GRID (OUTPUT FORMAT)
* SETS THE COLUMN NAME AND THE OUTPUT LENGTH FOR THE FIELDS
*----------------------------------------------------------------------*
FORM field_catalog1 .

REFRESH it_field1.
CLEAR wa_field1.

wa_field1-fieldname = 'AUFNR'. " name of field from internal table


wa_field1-tabname = 'IT_PROCESS'. " internal table name
wa_field1-outputlen = 20. " output length on screen
wa_field1-seltext_l = text-003. " header information
APPEND wa_field1 TO it_field1. " append field catalog internal table
CLEAR wa_field1. " clear field catalog work area

wa_field1-fieldname = 'KTEXT'. " name of field from internal table


wa_field1-tabname = 'IT_PROCESS'. " internal table name
wa_field1-outputlen = 45. " output length on screen
wa_field1-seltext_l = text-004. " header information
APPEND wa_field1 TO it_field1. " append field catalog internal table
CLEAR wa_field1. " clear field catalog work area

wa_field1-fieldname = 'QMNUM'. " name of field from internal table


wa_field1-tabname = 'IT_PROCESS'. " internal table name
wa_field1-outputlen = 22. " output length on screen
wa_field1-seltext_l = text-005. " header information
APPEND wa_field1 TO it_field1. " append field catalog internal table
CLEAR wa_field1. " clear field catalog work area

ENDFORM. " FIELD_CATALOG1


*&---------------------------------------------------------------------*
*& Form SORT_FIELD1 FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
* SUB-ROUTINE SORT_FIELD IS USED TO SORT THE RECORDS IN THE
* INTERNAL TABLE BASED ON THE GIVEN FIELD AND NATURE OF
* SORTING TO BE DONE (ASCENDING OR DESCENDING)
*----------------------------------------------------------------------*
FORM sort_field1.

wa_sort1-spos = 1. " sort priority


wa_sort1-fieldname = 'AUFNR'. " field on which records sorted
wa_sort1-tabname = 'IT_PROCESS'. " internal table name
wa_sort1-up = c_check. " sort ascending
APPEND wa_sort1 TO it_sort1. " append sort info internal table
CLEAR wa_sort1. " clear sort info work area

ENDFORM. " SORT_FIELD1


*&---------------------------------------------------------------------*
*& Form SET_LAYOUT1 FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
* SUB-ROUTINE SET_LAYOUT IS USED TO SET THE DISPLAY OF THE
* ALV GRID LINES IN ALTERNATIVE COLOURS
*----------------------------------------------------------------------*
FORM set_layout1 .

wa_layout1-zebra = c_check. " so set colors of line alternatively

ENDFORM. " SET_LAYOUT1


*&---------------------------------------------------------------------*
*& Form ALV_DISPLAY1 FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
* SUB-ROUTINE ALV_DISPLAY IS USED TO SET THE PARAMETERS
* FOR THE FUNCTION MODULE REUSE_ALV_GRID_DISPLAY
* AND PASS THE INTERNAL TABLE EXISTING THE RECORDS TO BE
* DISPLAYED IN THE GRID FORMAT
*----------------------------------------------------------------------*
FORM alv_display1.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK =''
* I_BYPASSING_BUFFER =''
* I_BUFFER_ACTIVE =''
i_callback_program = v_rep_id " report id
* i_callback_pf_status_set =''
* i_callback_user_command =''
* I_CALLBACK_TOP_OF_PAGE =''
* I_CALLBACK_HTML_TOP_OF_PAGE =''
* I_CALLBACK_HTML_END_OF_LIST =''
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID =''
* I_GRID_TITLE =
* I_GRID_SETTINGS =
is_layout = wa_layout1 " for layout
it_fieldcat = it_field1 " field catalog
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
it_sort = it_sort1 " sort info
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* i_save =''
* is_variant =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN =0
* I_SCREEN_START_LINE =0
* I_SCREEN_END_COLUMN =0
* I_SCREEN_END_LINE =0
* I_HTML_HEIGHT_TOP =0
* I_HTML_HEIGHT_END =0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it_process " internal table
EXCEPTIONS
program_error =1
OTHERS = 2.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

ENDFORM. " ALV_DISPLAY1

Output Display Screen-shots:-


Selection screen for variant
selection:-

F4 help provided for variant selection.

If no input for variant selection, then DEFAULT variant used.


Report based on the variant
used:-

If no records selected and user click EXECUTE button, error message 'NO RECORDS SELECTED' displayed

Else If records selected and EXECUTE button is pressed, the seleected records to be displayed in another ALV
Grid.

These selected records can also be processed as per user requirements.


 No labels

3 Comments

1.
gopi krishna macha
Hi..

my requirement also same like this, but in 1st column of grid i displayed all the checkboxes and in 2nd column i have order number.

when order number repeates i don't have to print check box in 1st column. how can i do it any idea..
o Aug 31, 2011

2.
Former Member
HI,

you could try to merge the cells - there is a coding example on http://www.tricktresor.de/content/index.php?navID=523&aID=464 (sorry
it's on german)

Ivo
o Oct 19, 2011

3.
Sergiy Levchenko
An error in FORM fieldcatalog for the field "flag". Have to be

wa_field-input = c_check. " make field open for input

Regards

Sergii
FORM user_command USING r_ucomm LIKE sy-ucomm
REFRESH : it_data1.
CASE r_ucomm.
WHEN 'CHECK'.
IF alv_list IS NOT INITIAL.
LOOP AT it_data INTO wa_data WHERE mark = 'X'.
r_refno = wa_data-refno.
LOOP AT it_data INTO wa_data2 WHERE refno = r_refno and MARK NE 'X'.
wa_data2-mark = 'X'.
MODIFY it_data INDEX sy-tabix FROM wa_data2.
ENDLOOP.
ENDLOOP.
From Excel, you certainly know the functionality of connecting
cells. Thus, several cells can be combined, for example, to center a
heading over several columns. This is not possible in the ALV
grid. Edwin knew how to do it ...
Here we show you in two steps what it takes to connect cells. First,
the class CL_GUI_ALV_GRID must be inherited. Thereafter,
methods must be inserted that allow the joining of cells.
In the second step, we present you the demo program that gives a
good overview of the functionality of the new class.

Action
Class ZCL_GUI_ALV_GRID_MERGE
Create class ZCL_GUI_ALV_GRID_MERGE with SE80 or
transaction SE24. Then inherit the class CL_GUI_ALV_GRID and
implement the following methods:
 Z_SET_MERGE_HORIZ
 Z_SET_MERGE_VERT
 Z_DISPLAY
 Z_SET_CELL_STYLE
 Z_SET_FIXED_COL_ROW
 Z_INIT_CELL_STYLES

demo program
*&---------------------------------------------------------------------*
*& (c) Edwin Leippi Software-Entwicklung *
*& Email : info@leippi.de *
*& Datum : 01.03.2008 *
*& *
*& Der Autor �bernimmt keine Haftung f�r Sch�den, *
*& die durch den Einsatz dieses Programmes entstehen k�nnen *
*&---------------------------------------------------------------------*
*& http://www.tricktresor.de
*&---------------------------------------------------------------------*
REPORT zz_alv_merge_cells.

* *** Allgemeines ****************************************************


INCLUDE <cl_alv_control>.
INCLUDE <icon>.
DATA retc TYPE sy-subrc. .
DATA ok_code TYPE sy-ucomm.
DATA it_grp TYPE lvc_t_sgrp.
DATA it_fil TYPE lvc_t_filt.
DATA wa_fil TYPE lvc_s_filt.

* **** ALV_GRID ****************************************************


TYPES: BEGIN OF t_check_styles,
field01(20),
field02(20),
field03(20),
field04(20),
field05(20),
field06(20),
field07(20),
field08(20),
field09(20),
field10(20),
field11(20),
field12(20).
TYPES END OF t_check_styles.

DATA it_styles TYPE t_check_styles OCCURS 0.


DATA wa_styles TYPE t_check_styles.
FIELD-SYMBOLS <fs_styles> TYPE t_check_styles.
DATA : lt_fieldcatalog TYPE lvc_t_fcat.
DATA : ls_fieldcatalog TYPE lvc_t_fcat.
DATA : wa_cat TYPE lvc_s_fcat.
DATA : fieldname(40).
DATA : fieldnr(2) TYPE n.

FIELD-SYMBOLS <fs_cat> TYPE lvc_s_fcat.

DATA lt_iinfo TYPE lvc_t_info.


DATA wa_iinfo TYPE lvc_s_info.
DATA lt_idata TYPE lvc_t_data.
DATA wa_idata TYPE lvc_s_data.

DATA it_col_merge TYPE lvc_t_co01.


DATA wa_col_merge TYPE lvc_s_co01.
DATA: g_container TYPE scrfname VALUE 'CU_CON'.
DATA: g_custom_container TYPE REF TO cl_gui_custom_container.
DATA g_alv_grid TYPE REF TO zcl_gui_alv_grid_merge.
CLASS cl_gui_cfw DEFINITION LOAD.

DATA: x_save, "for Parameter I_SAVE


gs_variant TYPE disvariant. "for parameter IS_VARIANT
DATA gs_layout TYPE lvc_s_layo. " Layout
DATA wa_style TYPE lvc_s_styl.

* **** ALV_GRID ****************************************************


START-OF-SELECTION.
CALL SCREEN 0200.

END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0200 OUTPUT.

** Status und Titel setzen


SET PF-STATUS '0200'.
SET TITLEBAR '001'.

** Objekte instanzieren und zuordnen: Grid


IF g_custom_container IS INITIAL.

CREATE OBJECT g_custom_container


EXPORTING
container_name = g_container.

CREATE OBJECT g_alv_grid


EXPORTING
i_parent = g_custom_container.

gs_layout-stylefname = 'CELL'.
gs_layout-no_headers = 'X'.
gs_layout-cwidth_opt = ' '.
gs_layout-no_toolbar = 'X'.

** Feldkatalog erzeugen
REFRESH lt_fieldcatalog.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'


EXPORTING
i_internal_tabname = 'IT_STYLES'
CHANGING
ct_fieldcat = lt_fieldcatalog
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.

REFRESH lt_fieldcatalog.
REFRESH lt_iinfo.

DO 12 TIMES.
CLEAR wa_cat.
fieldnr = sy-index.
wa_cat-col_pos = sy-index.
CONCATENATE 'FIELD' fieldnr INTO fieldname.
wa_cat-fieldname = fieldname.
wa_cat-tabname = '1'.
wa_cat-datatype = 'CHAR'.
wa_cat-inttype = 'C'.
wa_cat-intlen = 20.
IF sy-index > 1.
wa_cat-outputlen = 6.
ELSE.
wa_cat-outputlen = 20.
ENDIF.
wa_cat-reptext = fieldname.
wa_cat-scrtext_l = fieldname.
wa_cat-scrtext_m = fieldname.
wa_cat-scrtext_s = fieldname.
wa_cat-scrtext_l = fieldname.
APPEND wa_cat TO lt_fieldcatalog.
ENDDO.

* 1 Zeile
CLEAR wa_styles.
wa_styles-field01 = 'TRICKTRESOR'.
wa_styles-field03 = 'F'.
wa_styles-field04 = 'P'.
wa_styles-field09 = 'M'.
wa_styles-field10 = 'K'.
APPEND wa_styles TO it_styles.
* 2 Zeile
CLEAR wa_styles.
wa_styles-field03 = 'HQ'.
wa_styles-field04 = 'HC'.
wa_styles-field08 = 'HW'.
wa_styles-field09 = 'HC'.
wa_styles-field10 = 'HC'.
wa_styles-field12 = 'HW'.
APPEND wa_styles TO it_styles.
* 3-Zeile
CLEAR wa_styles.
wa_styles-field01 = 'Bezeichnung'.
wa_styles-field02 = 'Radius'.
wa_styles-field03 = 'WPX 12'.
wa_styles-field04 = 'WAP 25'.
wa_styles-field05 = 'WAP 35'.
wa_styles-field06 = 'WTP 35'.
wa_styles-field07 = 'WXP 45'.
wa_styles-field08 = 'WPM'.
wa_styles-field09 = 'WXM 35'.
wa_styles-field10 = 'WAK 15'.
wa_styles-field11 = 'WAK 25'.
wa_styles-field12 = 'WKM'.
APPEND wa_styles TO it_styles.

* 4..Zeile
CLEAR wa_styles.
wa_styles-field01 = 'SPMW 060304 T - A 27'.
wa_styles-field02 = '0.54'.
wa_styles-field03 = icon_led_green.
wa_styles-field04 = icon_led_yellow.
wa_styles-field05 = icon_led_red.
wa_styles-field08 = icon_led_yellow.
APPEND wa_styles TO it_styles.

CLEAR wa_styles.
wa_styles-field01 = 'SPMW 060304 - A 57'.
wa_styles-field02 = '0.43'.
wa_styles-field03 = icon_led_yellow.
wa_styles-field05 = icon_led_red.
wa_styles-field08 = icon_led_yellow.
wa_styles-field10 = icon_led_yellow.
wa_styles-field11 = icon_led_red.
wa_styles-field12 = icon_led_yellow.
APPEND wa_styles TO it_styles.

CLEAR wa_styles.
wa_styles-field01 = 'SPMW 060304 - D 51'.
wa_styles-field02 = '0.76'.
wa_styles-field04 = icon_led_yellow.
wa_styles-field05 = icon_led_red.
wa_styles-field06 = icon_led_red.
wa_styles-field07 = icon_led_red.
APPEND wa_styles TO it_styles.

CLEAR wa_styles.
wa_styles-field01 = 'SPMW 060304 - F 55'.
wa_styles-field02 = '0.44'.
wa_styles-field03 = icon_led_red.
wa_styles-field05 = icon_led_green.
wa_styles-field06 = icon_led_yellow.
wa_styles-field07 = icon_led_red.
wa_styles-field09 = icon_led_yellow.
wa_styles-field10 = icon_led_green.
wa_styles-field11 = icon_led_yellow.
wa_styles-field12 = icon_led_yellow.
APPEND wa_styles TO it_styles.

*
CALL METHOD g_alv_grid->set_table_for_first_display
EXPORTING
is_variant = gs_variant
i_save = x_save
is_layout = gs_layout
CHANGING
it_fieldcatalog = lt_fieldcatalog
it_outtab = it_styles.

REFRESH it_col_merge.

*** DEMO vertikal verbinden


wa_col_merge-col_id = 1.
wa_col_merge-outputlen = 2.
APPEND wa_col_merge TO it_col_merge.

CALL METHOD g_alv_grid->z_set_merge_vert


EXPORTING
row = 1
CHANGING
tab_col_merge = it_col_merge.
wa_style-style = alv_style_font_bold
+ alv_style_align_center_center
+ alv_style_color_key.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
row = 1
col = 1
style = wa_style-style.

*** VERTIKAL verbinden


CLEAR it_col_merge.

wa_col_merge-col_id = 4.
wa_col_merge-outputlen = 8.
APPEND wa_col_merge TO it_col_merge.

wa_col_merge-col_id = 10.
wa_col_merge-outputlen = 12.
APPEND wa_col_merge TO it_col_merge.

CALL METHOD g_alv_grid->z_set_merge_horiz


EXPORTING
row = 1
CHANGING
tab_col_merge = it_col_merge.

wa_style-style = alv_style_font_bold.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
row = 1
col = 3
style = wa_style-style.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
row = 1
col = 4
style = wa_style-style.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
row = 1
col = 9
style = wa_style-style.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
row = 1
col = 10
style = wa_style-style.

REFRESH it_col_merge.

wa_col_merge-col_id = 4.
wa_col_merge-outputlen = 7.
APPEND wa_col_merge TO it_col_merge.

wa_col_merge-col_id = 10.
wa_col_merge-outputlen = 2.
APPEND wa_col_merge TO it_col_merge.
CALL METHOD g_alv_grid->z_set_merge_horiz
EXPORTING
row = 2
CHANGING
tab_col_merge = it_col_merge.

wa_style-style = alv_style_color_group +
alv_style_align_center_center.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
col = 3
style = wa_style-style.

wa_style-style = alv_style_color_heading +
alv_style_align_center_center.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
col = 4
style = wa_style-style.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
col = 5
style = wa_style-style.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
col = 6
style = wa_style-style.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
col = 7
style = wa_style-style.
CALL METHOD g_alv_grid->z_set_cell_style
EXPORTING
col = 8
style = wa_style-style.

wa_style-style = alv_style_color_total +
alv_style_align_center_center.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
col = 9
style = wa_style-style.

wa_style-style = alv_style_color_negative +
alv_style_align_center_center.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
col = 10
style = wa_style-style.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
col = 11
style = wa_style-style.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
col = 12
style = wa_style-style.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
col = 13
style = wa_style-style.

wa_style-style = alv_style_color_positive +
alv_style_align_center_center.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
col = 14
style = wa_style-style.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
col = 15
style = wa_style-style.

wa_style-style = alv_style_color_int_background +
alv_style_align_center_center.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
col = 16
style = wa_style-style.

wa_style-style = alv_style_color_positive +
alv_style_align_center_center +
alv_style_font_italic.

CALL METHOD g_alv_grid->z_set_cell_style


EXPORTING
row = 4
col = 2
style = wa_style-style.

g_alv_grid->z_set_fixed_col_row(
EXPORTING col = 3
row = 3 ).

g_alv_grid->z_display( ).

ENDIF.
ENDMODULE. "status_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0200 INPUT.
* to react on oi_custom_events:
cl_gui_cfw=>dispatch( ).

CASE ok_code.
WHEN 'BACK'.
SET SCREEN 0. LEAVE SCREEN.
ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT


1. FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
2. RS_SELFIELD TYPE SLIS_SELFIELD.
3.
4. DATA: GD_REPID LIKE SY-REPID, "Exists
5. REF_GRID TYPE REF TO CL_GUI_ALV_GRID.
6. IF REF_GRID IS INITIAL.
7. CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
8. IMPORTING
9. E_GRID = REF_GRID.
10. ENDIF.
11. IF NOT REF_GRID IS INITIAL.
12. CALL METHOD REF_GRID->CHECK_CHANGED_DATA .
13. ENDIF.
14.
15. loop at itab where chk = 'X'.
16. itab-color = 'C300'.
17. modify itab index sy-tabix transporting color.
18. endloop.
19. RS_SELFIELD-refresh = 'X'.
20. break-point.
21.
22. ENDFORM. "USER_COMMAND

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy