Skip to Content
0
Former Member
Feb 06, 2009 at 12:21 PM

Making selected rows to display mode in ALV grid

105 Views

I Have program with ALV grid display, which has check box as the first field.

The requirement is like.

When i select some rows in the grid display with the check box and click on a button , then the selected

rows shud change to display mode and others rows shud be in edit mode as before.

&----


*& Report ZSRI_CHCKBOX_ITAB_UPDATE

*&

&----


*&

*&

&----


REPORT ZSRI_CHCKBOX_ITAB_UPDATE.

TYPE-POOLS: SLIS.

DATA: BEGIN OF ITAB OCCURS 0,

CHK TYPE C,

VBELN TYPE VBAP-VBELN,

POSNR TYPE VBAP-POSNR,

MATNR TYPE VBAP-MATNR,

MATWA TYPE VBAP-MATWA,

MATKL TYPE VBAP-MATKL,

END OF ITAB.

DATA: T_FCAT TYPE SLIS_T_FIELDCAT_ALV,

W_FCAT TYPE SLIS_FIELDCAT_ALV,

RT TYPE SLIS_SELFIELD,

W_LAYOUT TYPE SLIS_LAYOUT_ALV .

PARAMETERS: S_VBELN TYPE VBAK-VBELN.

DATA: WA LIKE LINE OF ITAB.

DATA: G_GRID_REFERENCE TYPE REF TO CL_GUI_ALV_GRID.

DATA: BEGIN OF ITAB1 OCCURS 0,

CHK TYPE C,

VBELN TYPE VBAP-VBELN,

POSNR TYPE VBAP-POSNR,

MATNR TYPE VBAP-MATNR,

MATWA TYPE VBAP-MATWA,

MATKL TYPE VBAP-MATKL,

END OF ITAB1.

DATA: T_FCAT1 TYPE SLIS_T_FIELDCAT_ALV.

DATA: W_FCAT1 TYPE SLIS_FIELDCAT_ALV.

START-OF-SELECTION.

SELECT VBELN POSNR MATNR MATWA MATKL FROM VBAP

INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE VBELN EQ S_VBELN.

W_FCAT-COL_POS = 1.

W_FCAT-FIELDNAME = 'CHK'.

W_FCAT-TABNAME = 'ITAB'.

W_FCAT-CHECKBOX = 'X'.

W_FCAT-EDIT = 'X'.

W_FCAT-SELTEXT_L = 'CHECK'.

APPEND W_FCAT TO T_FCAT.

CLEAR W_FCAT.

W_FCAT-COL_POS = 2.

W_FCAT-FIELDNAME = 'VBELN'.

W_FCAT-TABNAME = 'ITAB'.

W_FCAT-SELTEXT_L = 'SALES'.

W_FCAT-EDIT = 'X'.

APPEND W_FCAT TO T_FCAT.

CLEAR W_FCAT.

W_FCAT-COL_POS = 3.

W_FCAT-FIELDNAME = 'POSNR'.

W_FCAT-TABNAME = 'ITAB'.

W_FCAT-SELTEXT_L = 'ITEM'.

W_FCAT-EDIT = 'X'.

APPEND W_FCAT TO T_FCAT.

CLEAR W_FCAT.

W_FCAT-COL_POS = 4.

W_FCAT-FIELDNAME = 'MATNR'.

W_FCAT-TABNAME = 'ITAB'.

W_FCAT-SELTEXT_L = 'MATERIAL'.

W_FCAT-EDIT = 'X'.

APPEND W_FCAT TO T_FCAT.

CLEAR W_FCAT.

W_FCAT-COL_POS = 5.

W_FCAT-FIELDNAME = 'MATWA'.

W_FCAT-TABNAME = 'ITAB'.

W_FCAT-SELTEXT_L = 'MATERIAL QTY'.

W_FCAT-OUTPUTLEN = 20.

W_FCAT-EDIT = 'X'.

APPEND W_FCAT TO T_FCAT.

CLEAR W_FCAT.

W_FCAT-COL_POS = 6.

W_FCAT-FIELDNAME = 'MATKL'.

W_FCAT-TABNAME = 'ITAB'.

W_FCAT-SELTEXT_L = 'MATERIAL GROUP'.

W_FCAT-OUTPUTLEN = 20.

W_FCAT-EDIT = 'X'.

APPEND W_FCAT TO T_FCAT.

CLEAR W_FCAT.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

I_CALLBACK_PF_STATUS_SET = 'STATUS1'

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

IS_LAYOUT = W_LAYOUT

IT_FIELDCAT = T_FCAT[]

TABLES

T_OUTTAB = ITAB[].

&----


*& Form STATUS1

&----


FORM STATUS1 USING P_EXTAB TYPE SLIS_T_EXTAB.

SET PF-STATUS 'STATUS1' EXCLUDING P_EXTAB.

ENDFORM. "PF_STATUS_SET

&----


*& Form USER_COMMAND

&----


FORM USER_COMMAND USING R_UCOMM TYPE SY-UCOMM

R_SELFIELD TYPE SLIS_SELFIELD.

CASE R_UCOMM.

WHEN 'READ'.

R_SELFIELD-REFRESH = 'X'.

CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

IMPORTING

E_GRID = G_GRID_REFERENCE.

CALL METHOD G_GRID_REFERENCE->CHECK_CHANGED_DATA.

LOOP AT ITAB INTO WA WHERE CHK = 'X'.

APPEND WA TO ITAB1.

ENDLOOP.

W_FCAT1-COL_POS = 1.

W_FCAT1-FIELDNAME = 'CHK'.

W_FCAT1-TABNAME = 'ITAB'.

W_FCAT1-CHECKBOX = 'X'.

W_FCAT1-SELTEXT_L = 'CHECK'.

APPEND W_FCAT1 TO T_FCAT1.

CLEAR W_FCAT1.

W_FCAT1-COL_POS = 2.

W_FCAT1-FIELDNAME = 'VBELN'.

W_FCAT1-TABNAME = 'ITAB'.

W_FCAT1-SELTEXT_L = 'SALES'.

APPEND W_FCAT1 TO T_FCAT1.

CLEAR W_FCAT1.

W_FCAT1-COL_POS = 3.

W_FCAT1-FIELDNAME = 'POSNR'.

W_FCAT1-TABNAME = 'ITAB'.

W_FCAT1-SELTEXT_L = 'ITEM'.

APPEND W_FCAT1 TO T_FCAT1.

CLEAR W_FCAT1.

W_FCAT1-COL_POS = 4.

W_FCAT1-FIELDNAME = 'MATNR'.

W_FCAT1-TABNAME = 'ITAB'.

W_FCAT1-SELTEXT_L = 'MATERIAL'.

W_FCAT-OUTPUTLEN = 20.

APPEND W_FCAT1 TO T_FCAT1.

CLEAR W_FCAT1.

W_FCAT1-COL_POS = 5.

W_FCAT1-FIELDNAME = 'MATWA'.

W_FCAT1-TABNAME = 'ITAB'.

W_FCAT1-SELTEXT_L = 'MATERIAL TYPE'.

W_FCAT-OUTPUTLEN = 20.

APPEND W_FCAT1 TO T_FCAT1.

CLEAR W_FCAT1.

W_FCAT1-COL_POS = 6.

W_FCAT1-FIELDNAME = 'MATKL'.

W_FCAT1-TABNAME = 'ITAB'.

W_FCAT1-SELTEXT_L = 'MATERIAL GROUP'.

W_FCAT-OUTPUTLEN = 20.

APPEND W_FCAT1 TO T_FCAT1.

CLEAR W_FCAT1.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

IT_FIELDCAT = T_FCAT1[]

IS_LAYOUT = W_LAYOUT

TABLES

T_OUTTAB = ITAB[].

CLEAR ITAB1.

CLEAR ITAB1[].

CLEAR T_FCAT1.

CLEAR T_FCAT1[].

ENDCASE.

ENDFORM. "USER_COMMAND

Edited by: dharmaji Srinivasu on Feb 6, 2009 1:22 PM