Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Edit Specific Cell in ALV

Former Member
0 Kudos

Hello All,

I am using the FM 'REUSE_ALV_GRID_DISPLAY'. When the user selects a specific row in the grid, one cell on that row will be capable of being edited. For example, Row 12 is selected and only the cell located on row 12 column 4 will be open for editing. Is there a way to specify how to do this using the FM? Thanks.

John

4 REPLIES 4

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

I would suggest move to the OO alv grid. It will be better in the long run. Check out the example program BCALV_EDIT_02 to see how to make cells editable.

Regards,

RIch Heilman

Former Member
0 Kudos

hi,

we can do this as follows

1) take all selected records from the output

& call again ALV grid display,

this will display a new alv output with the selected

records.

2) while calling this 2nd grid display,

change your field catalog sothat which field you want to edit , put INPUT = 'x'.

all those fields with INPUT = 'X' will appear as Input enabled,

then use USER-COMMAND, to capture this.

if understood from this its ok. else i will send the code. you can go thru this.

thanks

srikanth

0 Kudos

Hello Srikanth,

Could you please provide the sample code? I am not sure if I completely follow what you are suggesting. Thanks for your help.

John

Former Member
0 Kudos

Hi,

check this program,

you concentrate on ALV_GRID_DISPALY

What i am doing here is

i am displaying basic list with checkbox as the first field & all other fields. i also displaying "MODIFY" button if user selects MODIFY radio button on the selection screen.

after that i am taking all selected records to another internal table & calling ALV_GRID_DISPLAY again.

here we have to change INPUT = 'X' for field in the Fieldcatalog.

REPORT Z0AP_MPS_RPT_WO_DETAILS NO STANDARD PAGE HEADING.

----


  • T Y P E D E C L A R A T I O N S

----


TYPE-POOLS : SLIS.

TYPES : BEGIN OF T_ZBCAR50 ,

REC_TYPE TYPE ZBCAR50-REC_TYPE , "Record type

LOCATION TYPE ZBCAR50-LOCATION , "Manufacturing department

PRODUCT TYPE ZBCAR50-PRODUCT , "product

LOTNUM TYPE ZBCAR50-LOTNUM , "Batch

NETQTY TYPE ZBCAR50-NETQTY , "Net Qty for closed orders

ORDQTY TYPE ZBCAR50-ORDQTY , "Odr Qty/inventory pstg Qty

RDATE TYPE ZBCAR50-RDATE , "Record Date

STATUS TYPE ZBCAR50-STATUS , "Record status

CDATE TYPE ZBCAR50-CDATE , "Data record created in APO

  • CTIME TYPE ZBCAR50-CTIME , "Time record created in APO

REC_SEL TYPE C , "Record selection indicator

END OF T_ZBCAR50.

----


  • D A T A D E C L A R A T I O N S

----


----


  • V A R I A B L E S

----


DATA: V_REPID LIKE SY-REPID.

CONSTANTS :

C_X(1) TYPE C VALUE 'X',

C_PF_STATUS TYPE SLIS_FORMNAME VALUE 'F_SET_PF_STATUS',

C_FC_DELETE(6) TYPE C VALUE 'DELETE',

C_FC_MODIFY(6) TYPE C VALUE 'MODIFY',

C_USER_COMMAND TYPE SLIS_FORMNAME VALUE 'F_USER_COMMAND',

C_USER_COMMAND_MODIFY TYPE SLIS_FORMNAME

VALUE 'F_USER_COMMAND_MODIFY',

C_ICON_DELETE TYPE ICON-NAME VALUE 'ICON_DELETE', " Icon,Delete'

C_ICON_CANCEL TYPE ICON-NAME VALUE 'ICON_CANCEL', " Icon,Cancel'

C_FC_SAVE(4) TYPE C VALUE 'SAVE'.

----


  • I N T E R N A L T A B L E D E C L A R A T I O N S

----


*--Internal table to hold the ZBCAR50 contents

DATA : IT_ZBCAR50 TYPE STANDARD TABLE OF T_ZBCAR50 WITH HEADER LINE ,

*--Internal table to store Records to be deleted from ZBCAR50

IT_ZBCAR50_TEMP TYPE STANDARD TABLE OF

ZBCAR50 WITH HEADER LINE ,

*--ALV Internal Tables.

*--Field Catalog

IT_FIELDCAT TYPE STANDARD TABLE OF

SLIS_FIELDCAT_ALV WITH HEADER LINE,

*--Layout

WA_LAYOUT TYPE SLIS_LAYOUT_ALV,

*--Sort

IT_SORT TYPE SLIS_T_SORTINFO_ALV,

WA_SORT TYPE SLIS_SORTINFO_ALV ,

*--Events

  • IT_EVENTS TYPE SLIS_T_EVENT,

  • WA_EVENT LIKE LINE OF IT_EVENTS,

**-Structure for excluding function codes

WA_EXTAB TYPE SLIS_EXTAB,

**-To hold function codes to be excluded in ALV toolbar

IT_EXTAB TYPE SLIS_T_EXTAB.

*----


  • SELECTION-SCREEN

*----


SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME

TITLE TEXT-001.

PARAMETERS : P_PLNVR(3) TYPE C DEFAULT '000'. "Warehouse #

SELECT-OPTIONS :

S_MATNR FOR ZBCAR50-PRODUCT , "Product

S_WERKS FOR ZBCAR50-LOCATION , "Location

S_RTYP FOR ZBCAR50-REC_TYPE NO INTERVALS, "Record type

S_RSTATS FOR ZBCAR50-STATUS NO INTERVALS, "Record Status

S_DATE FOR ZBCAR50-RDATE . "Date

SELECTION-SCREEN END OF BLOCK B1 .

*--Radio buttons to select either Display/Delete/Modify

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME

TITLE TEXT-002.

SELECTION-SCREEN : BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(20) TEXT-003.

PARAMETERS: P_DISP RADIOBUTTON GROUP RAD1 DEFAULT 'X'.

SELECTION-SCREEN : END OF LINE.

SELECTION-SCREEN : BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(20) TEXT-005.

PARAMETERS: P_UPD RADIOBUTTON GROUP RAD1.

SELECTION-SCREEN : END OF LINE.

SELECTION-SCREEN : BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(20) TEXT-004.

PARAMETERS: P_DEL RADIOBUTTON GROUP RAD1.

SELECTION-SCREEN : END OF LINE.

SELECTION-SCREEN ULINE.

SELECTION-SCREEN : BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(20) TEXT-006.

PARAMETERS: P_BAKGRD TYPE C AS CHECKBOX DEFAULT SPACE .

SELECTION-SCREEN : END OF LINE.

SELECTION-SCREEN END OF BLOCK B2 .

*----


  • INITIALIZATION

*----


INITIALIZATION.

*----


  • AT SELECTION SCREEN

*----


AT SELECTION-SCREEN .

*----


  • START OF SELECTION

*----


START-OF-SELECTION.

*--Clear the Internal tables to be used

CLEAR : IT_ZBCAR50,

IT_ZBCAR50[].

*--Get Data from Tables

PERFORM GET_DATA.

*--Check if Background job Checkbox is X or not.

IF P_BAKGRD = C_X.

*--delete the selected from Database.

LOOP AT IT_ZBCAR50.

*--Move Corresponding records to temp table, To delete

MOVE-CORRESPONDING IT_ZBCAR50 TO IT_ZBCAR50_TEMP.

IT_ZBCAR50_TEMP-MANDT = SY-MANDT.

APPEND IT_ZBCAR50_TEMP.

CLEAR IT_ZBCAR50_TEMP.

ENDLOOP.

DELETE ZBCAR50 FROM TABLE IT_ZBCAR50_TEMP.

IF SY-SUBRC = 0.

*--Successfully selected records Deleted.

COMMIT WORK AND WAIT.

*--Display completed work information to the user

MESSAGE I000 WITH SY-DBCNT

' Record(s) deleted Successfully'.

*--Reselects entries from Database again & display in ALV

CLEAR : IT_ZBCAR50,

IT_ZBCAR50[],

IT_ZBCAR50_TEMP,

IT_ZBCAR50_TEMP[].

ELSE.

*--Error occured

MESSAGE I000 WITH 'Error occured in Deleting the Record(s)'.

ENDIF.

ENDIF.

*----


  • END OF SELECTION

*----


END-OF-SELECTION.

IF IT_ZBCAR50[] IS INITIAL.

*--No records selected,Display Message

MESSAGE I000 WITH

'No Records found for the given Selection Criteria'(006).

ELSE.

*--DO ALV Process

V_REPID = SY-REPID.

*--Sort the Output Fields

PERFORM SORT_FIELDS.

*--Build Field catalog for the Output fields

PERFORM BUILD_FIELDCAT.

*--Set the Layout for ALV

PERFORM SET_LAYOUT.

*--Exclude any Buttons on the Appn tool bar

PERFORM CHANGE_DEFAULT_PF_STATUS.

*--Display ALV output

PERFORM LIST_DISPLAY TABLES IT_ZBCAR50

USING C_USER_COMMAND.

ENDIF.

&----


*& Form GET_DATA

&----


  • text : Get Data from table ZBCAR50

----


FORM GET_DATA .

SELECT REC_TYPE

LOCATION

PRODUCT

LOTNUM

NETQTY

ORDQTY

RDATE

STATUS

CDATE

INTO TABLE IT_ZBCAR50

FROM ZBCAR50

WHERE REC_TYPE IN S_RTYP

AND LOCATION IN S_WERKS

AND PRODUCT IN S_MATNR

AND STATUS IN S_RSTATS

AND RDATE IN S_DATE.

IF SY-SUBRC <> 0.

*--No records selected,leave processing

STOP.

ENDIF.

SORT IT_ZBCAR50.

ENDFORM. " GET_DATA

&----


*& Form SORT_FIELDS

&----


  • text : sort the Output fields

----


FORM SORT_FIELDS .

CLEAR WA_SORT.

WA_SORT-FIELDNAME = 'REC_TYPE'.

WA_SORT-SPOS = '1'.

WA_SORT-UP = 'X'.

APPEND WA_SORT TO IT_SORT.

CLEAR WA_SORT.

WA_SORT-FIELDNAME = 'LOCATION'.

WA_SORT-SPOS = '2'.

WA_SORT-UP = 'X'.

APPEND WA_SORT TO IT_SORT.

CLEAR WA_SORT.

WA_SORT-FIELDNAME = 'PRODUCT'.

WA_SORT-SPOS = '3'.

WA_SORT-UP = 'X'.

APPEND WA_SORT TO IT_SORT.

CLEAR WA_SORT.

WA_SORT-FIELDNAME = 'LOTNUM'.

WA_SORT-SPOS = '4'.

WA_SORT-UP = 'X'.

APPEND WA_SORT TO IT_SORT.

ENDFORM. " SORT_FIELDS

&----


*& Form BUILD_FIELDCAT

&----


  • text : Build field catalog for ALV

----


FORM BUILD_FIELDCAT .

IT_FIELDCAT-COL_POS = '1'.

IT_FIELDCAT-FIELDNAME = 'REC_TYPE'.

IT_FIELDCAT-KEY = 'X'.

IT_FIELDCAT-OUTPUTLEN = '15'.

IT_FIELDCAT-SELTEXT_L = 'Record type'(007).

APPEND IT_FIELDCAT.

CLEAR IT_FIELDCAT.

IT_FIELDCAT-COL_POS = '2'.

IT_FIELDCAT-FIELDNAME = 'LOCATION'.

IT_FIELDCAT-KEY = 'X'.

IT_FIELDCAT-OUTPUTLEN = '13'.

IT_FIELDCAT-SELTEXT_L = 'Location'(008).

APPEND IT_FIELDCAT.

CLEAR IT_FIELDCAT.

IT_FIELDCAT-COL_POS = '3'.

IT_FIELDCAT-FIELDNAME = 'PRODUCT'.

IT_FIELDCAT-KEY = 'X'.

IT_FIELDCAT-OUTPUTLEN = '18'.

IT_FIELDCAT-SELTEXT_L = 'Product'(009).

APPEND IT_FIELDCAT.

CLEAR IT_FIELDCAT.

IT_FIELDCAT-COL_POS = '4'.

IT_FIELDCAT-FIELDNAME = 'LOTNUM'.

IT_FIELDCAT-KEY = 'X'.

IT_FIELDCAT-OUTPUTLEN = '10'.

IT_FIELDCAT-SELTEXT_L = 'Lot No'(010).

APPEND IT_FIELDCAT.

CLEAR IT_FIELDCAT.

IT_FIELDCAT-COL_POS = '5'.

IT_FIELDCAT-FIELDNAME = 'NETQTY'.

IT_FIELDCAT-OUTPUTLEN = '13'.

IT_FIELDCAT-SELTEXT_L = 'Net Quantity'(011).

APPEND IT_FIELDCAT.

CLEAR IT_FIELDCAT.

IT_FIELDCAT-COL_POS = '6'.

IT_FIELDCAT-FIELDNAME = 'ORDQTY'.

IT_FIELDCAT-OUTPUTLEN = '18'.

IT_FIELDCAT-SELTEXT_L = 'Ord Quantity'(012).

APPEND IT_FIELDCAT.

CLEAR IT_FIELDCAT.

IT_FIELDCAT-COL_POS = '7'.

IT_FIELDCAT-FIELDNAME = 'RDATE'.

IT_FIELDCAT-OUTPUTLEN = '18'.

IT_FIELDCAT-SELTEXT_L = 'Record Date'(013).

APPEND IT_FIELDCAT.

CLEAR IT_FIELDCAT.

IT_FIELDCAT-COL_POS = '8'.

IT_FIELDCAT-FIELDNAME = 'STATUS'.

IT_FIELDCAT-OUTPUTLEN = '10'.

IT_FIELDCAT-SELTEXT_L = 'Status'(014).

APPEND IT_FIELDCAT.

CLEAR IT_FIELDCAT.

IT_FIELDCAT-COL_POS = '9'.

IT_FIELDCAT-FIELDNAME = 'CDATE'.

IT_FIELDCAT-OUTPUTLEN = '15'.

IT_FIELDCAT-SELTEXT_L = 'Rec crn Date'(015).

APPEND IT_FIELDCAT.

CLEAR IT_FIELDCAT.

IT_FIELDCAT-FIELDNAME = 'REC_SEL'.

IT_FIELDCAT-NO_OUT = C_X.

APPEND IT_FIELDCAT.

CLEAR IT_FIELDCAT.

ENDFORM. " BUILD_FIELDCAT

&----


*& Form LIST_DISPLAY

&----


  • text : Display ALV Output

----


FORM LIST_DISPLAY TABLES P_ZBCAR50

USING P_USER_COMMAND.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = V_REPID

I_CALLBACK_PF_STATUS_SET = C_PF_STATUS

I_CALLBACK_USER_COMMAND = P_USER_COMMAND

IS_LAYOUT = WA_LAYOUT

IT_FIELDCAT = IT_FIELDCAT[]

IT_EXCLUDING = IT_EXTAB[]

IT_SORT = IT_SORT[]

TABLES

T_OUTTAB = P_ZBCAR50

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. " LIST_DISPLAY

&----


*& Form F_SET_PF_STATUS

&----


  • Set PF_STATUS STANDARD modifying the standard toolbar

  • by excluding some buttons

----


  • -->P_IT_EXTAB -- TABLE OF EXCLUDING FUNCTIONS

----


FORM F_SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.

CLEAR : WA_EXTAB,

IT_EXTAB.

*--Set the Modified PF status for the ALV.

SET PF-STATUS 'STATUS_01' EXCLUDING RT_EXTAB.

ENDFORM. " SET_PF_STATUS

&----


*& Form f_user_command

&----


  • Handle user action on ALV toolbar

----


FORM F_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM

RS_SELFIELD TYPE SLIS_SELFIELD.

DATA : L_ANSWER TYPE C.

RS_SELFIELD-REFRESH = C_X.

IF R_UCOMM = C_FC_MODIFY.

*--If user selects MODIFY button.

  • CLEAR : P_UPD, P_DEL, P_DISP.

READ TABLE IT_ZBCAR50 WITH KEY REC_SEL = C_X.

*--check user selected at least 1 record to MODIFY or not

IF SY-SUBRC <> 0.

MESSAGE I000 WITH 'No record(s) Selected to Modify'.

EXIT.

ELSE.

CLEAR : IT_ZBCAR50_TEMP,

IT_ZBCAR50_TEMP[].

LOOP AT IT_ZBCAR50 WHERE REC_SEL = C_X.

MOVE-CORRESPONDING IT_ZBCAR50 TO

IT_ZBCAR50_TEMP.

IT_ZBCAR50_TEMP-MANDT = SY-MANDT.

APPEND IT_ZBCAR50_TEMP.

CLEAR : IT_ZBCAR50_TEMP.

ENDLOOP.

*--Change the Existing Field catalog

READ TABLE IT_FIELDCAT WITH KEY FIELDNAME = 'STATUS'.

IT_FIELDCAT-INPUT = C_X.

MODIFY IT_FIELDCAT INDEX SY-TABIX TRANSPORTING INPUT.

  • READ TABLE IT_FIELDCAT WITH KEY FIELDNAME = 'REC_SEL'.

  • IT_FIELDCAT-NO_OUT = SPACE.

  • MODIFY IT_FIELDCAT INDEX SY-TABIX TRANSPORTING NO_OUT.

*--Change PF status for this new ALV list.

PERFORM CHANGE_PF_STATUS_AGAIN.

*--Call ALV LIST DISPLAY with this new values.

PERFORM LIST_DISPLAY TABLES IT_ZBCAR50_TEMP

USING C_USER_COMMAND_MODIFY.

ENDIF.

ENDIF.

ENDFORM. "F_USER_COMMAND

&----


*& Form SET_LAYOUT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM SET_LAYOUT .

IF P_DEL = C_X OR

P_UPD = C_X.

*--Allow Input only if user choose 'UPDATE'/ 'DELETE' radio buttons

WA_LAYOUT-BOX_FIELDNAME = 'REC_SEL'. " Field displayed as checkbox

WA_LAYOUT-BOX_TABNAME = 'IT_ZBCAR50'.

ENDIF.

*--

ENDFORM. " SET_LAYOUT

&----


*& Form CHANGE_DEFAULT_PF_STATUS

&----


  • text

----


FORM CHANGE_DEFAULT_PF_STATUS .

<b>remove those Fcodes you dont want to display in the PF status</b>

IF P_DISP = C_X.

*--Dont Display DELETE & MODIFY buttons on the ALV output.

MOVE C_FC_DELETE TO WA_EXTAB-FCODE. " DELETE button on ALV

APPEND WA_EXTAB TO IT_EXTAB.

MOVE C_FC_MODIFY TO WA_EXTAB-FCODE. " MODIFY button on ALV

APPEND WA_EXTAB TO IT_EXTAB.

ELSEIF P_DEL = C_X.

*--Dont Display MODIFY button on the output.

MOVE C_FC_MODIFY TO WA_EXTAB-FCODE. " MODIFY button on ALV

APPEND WA_EXTAB TO IT_EXTAB.

ENDIF.

MOVE 'SAVE' TO WA_EXTAB-FCODE. " SAVE button on ALV

APPEND WA_EXTAB TO IT_EXTAB.

ENDFORM. " CHANGE_DEFAULT_PF_STATUS

&----


*& Form CHANGE_PF_STATUS_AGAIN

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM CHANGE_PF_STATUS_AGAIN .

MOVE C_FC_DELETE TO WA_EXTAB-FCODE. " DELETE button on ALV

APPEND WA_EXTAB TO IT_EXTAB.

MOVE C_FC_MODIFY TO WA_EXTAB-FCODE. " MODIFY button on ALV

APPEND WA_EXTAB TO IT_EXTAB.

ENDFORM. " CHANGE_PF_STATUS_AGAIN

&----


*& Form f_user_command

&----


  • Handle user action on ALV toolbar

----


FORM F_USER_COMMAND_MODIFY USING R_UCOMM LIKE SY-UCOMM

RS_SELFIELD TYPE SLIS_SELFIELD.

DATA : L_ANSWER TYPE C.

IF R_UCOMM = C_FC_SAVE.

*--User Selected SAVE button. <b>This is for 2nd screen</b>

LOOP AT IT_ZBCAR50_TEMP.

*--Check the entered values are valid or not.

IF NOT ( IT_ZBCAR50_TEMP-STATUS = 'A' OR

IT_ZBCAR50_TEMP-STATUS = 'C' OR

IT_ZBCAR50_TEMP-STATUS = 'E' ).

*--User Entered invalid value for STATUS field,so Display Error Msg

  • CLEAR IT_ZBCAR50_TEMP-STATUS.

  • MODIFY IT_ZBCAR50_TEMP TRANSPORTING STATUS.

  • CLEAR R_UCOMM.

MESSAGE E000 WITH 'Invalid value '''

IT_ZBCAR50_TEMP-STATUS

''' for Status in the Record # '

SY-TABIX.

  • EXIT.

ENDIF.

ENDLOOP.

*--Modify ZBCAR50 Table with the changed values.

MODIFY ZBCAR50 FROM TABLE IT_ZBCAR50_TEMP.

IF SY-SUBRC = 0 .

COMMIT WORK AND WAIT.

*--Display message with Success in Updating database

MESSAGE I000 WITH SY-DBCNT

' Record(s) has been Updated'.

CLEAR :

  • IT_ZBCAR50_TEMP,

  • IT_ZBCAR50_TEMP[],

IT_ZBCAR50,

IT_ZBCAR50[].

*--Get Data again from database.

PERFORM GET_DATA.

  • RS_SELFIELD-REFRESH = C_X.

ELSE.

*--Error occured

MESSAGE I000 WITH 'Error occured in Modifying the database'.

ENDIF.

ENDIF.

ENDFORM. "F_USER_COMMAND_MODIFY