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: 

ALV editable & reading it aagain

Former Member
0 Kudos

Hi All,

How to make ALV grid field editable & how to make that field obligatory. How to read that whole grid into our internal table after entering the values in editable field?

Regards,

Dilip

Message was edited by: Diliip Gupchup

1 ACCEPTED SOLUTION

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

DATA: i_fieldcat TYPE slis_t_fieldcat_alv.

DATA: line_fieldcat TYPE slis_fieldcat_alv.

CLEAR line_fieldcat.

line_fieldcat-fieldname = 'CHK'.

line_fieldcat-tabname = 'I_DATA'.

line_fieldcat-seltext_l = 'Checkbox'.

line_fieldcat-checkbox = 'X'. " Display this field as a checkbox

line_fieldcat-edit = 'X'. " This option ensures that you can

" edit the checkbox. Else it will

" be protected.

APPEND line_fieldcat TO i_fieldcat.

24 REPLIES 24

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

DATA: i_fieldcat TYPE slis_t_fieldcat_alv.

DATA: line_fieldcat TYPE slis_fieldcat_alv.

CLEAR line_fieldcat.

line_fieldcat-fieldname = 'CHK'.

line_fieldcat-tabname = 'I_DATA'.

line_fieldcat-seltext_l = 'Checkbox'.

line_fieldcat-checkbox = 'X'. " Display this field as a checkbox

line_fieldcat-edit = 'X'. " This option ensures that you can

" edit the checkbox. Else it will

" be protected.

APPEND line_fieldcat TO i_fieldcat.

0 Kudos

Thanks Jayanthi,

Now the column is editable but after user enters the values how should I get these values into my internal table.

Regards,

Dilip

0 Kudos

Thanks Jayanthi,

How to read the grid again into my intetrnal table.

Regards,

Dilip

0 Kudos

Hi,

Here is the sample code.SInce I don't know,where you need to read the table,I just did it after that FM.So if you pressed back button,it will display the entire output with changed data.

&----


*& Report ZZZ_JAYTEST1 *

*& *

&----


*& *

*& *

&----


REPORT ZZZ_JAYTEST1 .

TYPE-POOLS: slis.

DATA: report_id LIKE sy-repid.

DATA: ws_title TYPE lvc_title VALUE 'An ALV Report'.

DATA: i_layout TYPE slis_layout_alv.

DATA: i_fieldcat TYPE slis_t_fieldcat_alv.

types : begin of ty,

pernr type pa0001-pernr,

SEQNR type pa0001-seqnr,

end of ty.

data itab type standard table of ty.

data wa type ty.

select pernr seqnr from pa0001 into table itab.

report_id = sy-repid.

PERFORM f1000_layout_init CHANGING i_layout.

PERFORM f2000_fieldcat_init CHANGING i_fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = report_id

i_grid_title = ws_title

is_layout = i_layout

it_fieldcat = i_fieldcat

<b>i_save = 'A'</b>

TABLES

t_outtab = itab

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.

<b>loop at itab into wa.

write : / wa-pernr, wa-seqnr.

endloop.</b>

FORM f1000_layout_init USING i_layout TYPE slis_layout_alv.

CLEAR i_layout.

i_layout-colwidth_optimize = 'X'.

<b> i_layout-edit = 'X'.</b>

ENDFORM.

FORM f2000_fieldcat_init CHANGING i_fieldcat TYPE slis_t_fieldcat_alv.

DATA: line_fieldcat TYPE slis_fieldcat_alv.

CLEAR line_fieldcat.

line_fieldcat-fieldname = 'PERNR'. " The field name and the table

line_fieldcat-tabname = 'ITAB'. " name are the two minimum req.

line_fieldcat-key = 'X'. " Specifies the column as a key (Blue)

line_fieldcat-seltext_m = 'Personal No.'. " Column Header

APPEND line_fieldcat TO i_fieldcat.

CLEAR line_fieldcat.

line_fieldcat-fieldname = 'SEQNR'.

line_fieldcat-tabname = 'ITAB'.

line_fieldcat-seltext_l = 'No. of records with same key'.

<b>line_fieldcat-edit = 'X'.</b> APPEND line_fieldcat TO i_fieldcat.

ENDFORM. " f2000_fieldcat_init

Kindly reward points by clicking the star on the left of reply,if it helps you and close the thread if your problem is solved.

Message was edited by: Jayanthi Jayaraman

0 Kudos

Thanks Jayanthi,

Thanks for the answer it helps me a lot. But now the requirement is that I have to show popup for the date column for a particular condition.

Currently I am allowing the user to modify the whole column. The requirement is that only that field to be editable which meets the requirement & there I should give popup to select date.

Regards,

Dilip

0 Kudos

Hi Dilip,

COuld you just tell the thanks in SDN way by rewarding points against the replies which helped you.It saves the time of those who reply for the queries.

And let me know whether you want a single cell to be editable?

0 Kudos

Hello Jayanthi,

Sorry for the inconvince.

Currently I am displaying my data in grid. There is ZTERM is A the date field should be GRAYED & if other than A it should be editable & show popup to select date.

Instead of showing the whole column I want the particular records which are editable.

Regards,

Dilip

0 Kudos

use handle style field in ur Internal table decalre it like this.

TYPES: HANDLE_STYLE TYPE LVC_T_STYL,

and set the layout for this handle syle.

GS_LAYOUT-STYLEFNAME = 'HANDLE_STYLE'.

after that in your itab u take one flag.

based on some conditions to edit u set the falg to X.

now u modify the output table

then pass it to display method u will see only few records will be editable.

LOOP AT IT_FINAL INTO LS_OUTTAB WHERE FLAG = 'X'.

V_INDEX = SY-TABIX.

LS_EDIT-FIELDNAME = 'ZZOCHOLDRC'.

LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.

LS_EDIT-STYLE2 = SPACE.

LS_EDIT-STYLE3 = SPACE.

LS_EDIT-STYLE4 = SPACE.

LS_EDIT-MAXLEN = 8.

INSERT LS_EDIT INTO TABLE LT_EDIT.

LS_EDIT-FIELDNAME = 'ZZRCDESC'.

LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.

LS_EDIT-STYLE2 = SPACE.

LS_EDIT-STYLE3 = SPACE.

LS_EDIT-STYLE4 = SPACE.

LS_EDIT-MAXLEN = 8.

INSERT LS_EDIT INTO TABLE LT_EDIT.

LS_EDIT-FIELDNAME = 'ZZPROMDT'.

LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.

LS_EDIT-STYLE2 = SPACE.

LS_EDIT-STYLE3 = SPACE.

LS_EDIT-STYLE4 = SPACE.

LS_EDIT-MAXLEN = 8.

INSERT LS_EDIT INTO TABLE LT_EDIT.

INSERT LINES OF LT_EDIT INTO TABLE LS_OUTTAB-HANDLE_STYLE.

MODIFY IT_FINAL INDEX V_INDEX FROM LS_OUTTAB TRANSPORTING

HANDLE_STYLE DROP_DOWN_HANDLE.

regards

vijay

0 Kudos

Dear Vijay,

I am using REUSE_ALV_GRID_DISPLAY. Kindly tell me is it possible to display F4 help there.

Regards,

Dilip

0 Kudos

WHy not .

If the field u are populating is having Search help u can give.

while populating fieldcatalog

X_FIELDCAT-SELTEXT_M = 'Mat Num'.

X_FIELDCAT-FIELDNAME = 'MATNR'.

X_FIELDCAT-TABNAME = 'IT_FINAL'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-OUTPUTLEN = '18'.

X_FIELDCAT-INPUT = 'X'.

<b> x_fieldcat-ref_fieldname = 'MATNT'.

x_fieldcat-ref_tabname = 'MARA'.</b>

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

it will get the search help of the MATNR

when i click on it.

if it is the date u have to in similar way.

like

<b> x_fieldcat-ref_fieldname = 'DATUM'.

x_fieldcat-ref_tabname = 'SYST'.</b>

Regards

Vijay

0 Kudos

for date pop up

X_FIELDCAT-SELTEXT_M = 'Del Date'.

X_FIELDCAT-FIELDNAME = 'LFDAT'.

X_FIELDCAT-TABNAME = 'IT_FINAL'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-OUTPUTLEN = '10'.

X_FIELDCAT-DATATYPE = 'DATS'.

X_FIELDCAT-INTTYPE = 'D'.

X_FIELDCAT-REF_TABNAME = 'LIKP'.

X_FIELDCAT-REF_FIELDNAME = 'LFDAT'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

try this

0 Kudos

Hi Dilip,

Please revert if u problem solves.

edit u have to disable for few records u said. conditionally then u need to modify the report in end-of-list.

based on the conditions. change the out put editable fields to disable.

regards

vijay

0 Kudos

Dear Vijay,

I am showing my internal table in grid. there if zterm is 'A' there my date field should open for input & in other cases it should be grayed. Is this possible using REUSE_ALV_GRID_DISPLAY ?

Can you give some example.

Regards,

Dilip

0 Kudos

yep

why not

populate event table.

*-End of list

X_EVENTS_DATA-NAME = 'END_OF_LIST'.

X_EVENTS_DATA-FORM = 'LIST_MODIFY_OUPUT'.

APPEND X_EVENTS_DATA TO IT_EVENTS_DATA.

in the form 'LIST_MODIFY_OUPUT'.

write the following code.

while populating it_output table populate it_chg.

it_chg is having only one field is of type sy-tabix.

loop at IT_output .

READ TABLE IT_output WITH KEY zterm = 'A'.

IF SY-SUBRC = 0.

it_chg-ind = sy-tabix + 6.

append it_chg.

clear it_chg.

ENDIF.

ENDloop.

**form

FORM LIST_MODIFY_OUPUT.

data: l_lines type i.

**in this case i am adding 6 because this is having 6 **lines header

DESCRIBE TABLE IT_output LINES L_LINES.

L_LINES = L_LINES + 6.

DO L_LINES TIMES.

read table it_chg with key ind = sy-index.

if sy-subrc = 0.

READ LINE SY-INDEX INDEX SY-LSIND.

IF SY-SUBRC = 0.

MODIFY LINE SY-INDEX INDEX SY-LSIND

FIELD FORMAT IT_output-date INPUT OFF.

ENDIF.

ENDIF.

ENDDO.

ENDFORM.

hope this will solve ur problem.

reward points

regards

vijay

0 Kudos

Hello Vijay,

Thanks for your prompt reply.

I want to modify the field catalog where value of zterm is 'A' & as effect of this the date field will be clear & open for user to input.

Regards,

Dilip

0 Kudos

Hi Field catalog u give for that field is edit = 'X'.

and try modify the output conditionally in end-of-list.

u cannot control fieldcatalog in normal list.

do it in end-of-list.

and what abt the F4 help.

U didn't even reward points for that.

regards

vijay

0 Kudos

Hi Vijay,

I have awarded the points.

Following is my code which is not working kindly suggest where I am missig.

********************

READ TABLE XT_EVENT INTO LS_EVENT

  • WITH KEY NAME = SLIS_EV_TOP_OF_PAGE.

WITH KEY NAME = 'END_OF_LIST'.

IF SY-SUBRC = 0.

  • LS_EVENT-FORM = SLIS_EV_TOP_OF_PAGE.

LS_EVENT-FORM = 'LIST_MODIFY'.

MODIFY XT_EVENT FROM LS_EVENT

TRANSPORTING FORM

  • WHERE NAME = SLIS_EV_TOP_OF_PAGE.

WHERE NAME = 'END_OF_LIST'.

ENDIF.

*********************

FORM LIST_MODIFY.

clear cnt.

loop at ibsid.

cnt = 1.

read table fld_cat into fld with key fieldname = space.

if fld-fieldname = 'ZTERM' and ibsid-zterm = 'A'.

fld-edit = 'X'.

modify fld_cat from fld.

endif.

endloop.

ENDFORM.

0 Kudos

Hi Dilip,

please have a look at the following code.

in bold letters especially.

REPORT  ZTESTV2    NO STANDARD PAGE HEADING.
TYPE-POOLS:SLIS.
DATA: X_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA:IT_EVENTS TYPE SLIS_T_EVENT.
<b>
data: begin of it_chg occurs 0,
      index type sy-tabix,
      end of it_chg.</b>
DATA:  X_EVENTS    TYPE SLIS_ALV_EVENT.
DATA: BEGIN OF ITAB OCCURS 0,
      NAME(10) TYPE C,
      ZTERM TYPE C,
      END OF ITAB.

PERFORM FILL_TABLE.
<b>loop at itab where zterm = 'A'.
it_chg-index = sy-tabix + 3.  
" addition 3 IS FOR FIELD LABELS
append it_chg.
clear it_chg.
endloop.</b>

DATA:L_POS TYPE I VALUE 1.
CLEAR: L_POS.
L_POS = L_POS + 1.
**fieldcatalog
X_FIELDCAT-FIELDNAME = 'NAME'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS    = L_POS.
X_FIELDCAT-OUTPUTLEN = '10'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-FIELDNAME = 'ZTERM'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS    = L_POS.
X_FIELDCAT-OUTPUTLEN = '10'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
**events
<b>REFRESH:IT_EVENTS.
CLEAR:X_EVENTS,IT_EVENTS.
X_EVENTS-NAME = SLIS_EV_END_OF_LIST.
X_EVENTS-FORM = 'MODIFY_LIST'.
APPEND X_EVENTS TO IT_EVENTS.
CLEAR X_EVENTS.</b>

END-OF-SELECTION.
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = SY-REPID
      IT_FIELDCAT        = IT_FIELDCAT
      IT_EVENTS          = IT_EVENTS
    TABLES
      T_OUTTAB           = ITAB
    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.
*&---------------------------------------------------------------------*
*&      Form FILL_TABLE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM FILL_TABLE.
  ITAB-NAME = 'vijay'.
  ITAB-ZTERM = 'A'.
  APPEND ITAB.
  clear itab.

  ITAB-NAME = 'ABC'.
  ITAB-ZTERM = 'B'.
  APPEND ITAB.
  clear itab.

  ITAB-NAME = 'TEST'.
  ITAB-ZTERM = 'C'.
  APPEND ITAB.
  clear itab.

  ITAB-NAME = 'DILIP'.
  ITAB-ZTERM = 'D'.
  APPEND ITAB.
  clear itab.

  ITAB-NAME = '123'.
  ITAB-ZTERM = 'E'.
  APPEND ITAB.
  clear itab.

  ITAB-NAME = 'GEN'.
  ITAB-ZTERM = 'A'.
  APPEND ITAB.
  clear itab.

  ITAB-NAME = 'ALV'.
  ITAB-ZTERM = 'F'.
  APPEND ITAB.
  clear itab.

  ITAB-NAME = 'ALVTEST'.
  ITAB-ZTERM = 'A'.
  APPEND ITAB.
  clear itab.

ENDFORM.                    "FILL_TABLE

*&---------------------------------------------------------------------*
*&      Form  MODIFY_LIST
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
<b>FORM MODIFY_LIST.
data: l_lines type i.

describe table itab lines l_lines.

  L_LINES  = L_LINES + 3.
  "because we have 3 lines extra occupied by lables.
  "if we have header,i mean top of page add the no.of lines
  "how many ever top of page have + 3 for labels.
  DO L_LINES TIMES.
    read table it_chg with key INDEX = sy-index.
    if sy-subrc = 0.
**This code is for reading the out put line
**and modify accordinlg to our requiremnet.
**don't chnage this.
      READ LINE SY-INDEX INDEX SY-LSIND.
      IF SY-SUBRC = 0.
        MODIFY LINE SY-INDEX INDEX SY-LSIND
                   FIELD FORMAT ITAB-NAME INPUT.
      ENDIF.
    ENDIF.
  ENDDO.</b>
<b>ENDFORM.                    "MODIFY_LIST

</b>

Run this code .Please revert back.

If you have any questions on this .

It will solve your problem

Regards

vijay

Reward if it solves Your Problem.

0 Kudos

hi Dilip,

Please Revert If Ur Problem Solves.

Regards

Vijay

Former Member
0 Kudos

Hi,

You need to capture the modified cells in the following event.

CLASS lcl_event_handler IMPLEMENTATION .

*--Handle Data Changed METHOD handle_data_changed . PERFORM handle_data_changed USING er_data_changed . ENDMETHOD.

former_member188685
Active Contributor
0 Kudos

hi Dilip,

In ur field catalog U need to specify it as

EDIT = 'X'.

and for getting the changes in editable field.

u need to do couple of things.

----


  • CLASS lcl_event_handler DEFINITION

----


CLASS LCL_EVENT_HANDLER DEFINITION .

PUBLIC SECTION .

METHODS:

**Handler to Check the Data Change

HANDLE_DATA_CHANGED FOR EVENT DATA_CHANGED

OF CL_GUI_ALV_GRID

IMPORTING ER_DATA_CHANGED

E_ONF4

E_ONF4_BEFORE

E_ONF4_AFTER,

HANDLE_TOOLBAR

FOR EVENT TOOLBAR OF CL_GUI_ALV_GRID

IMPORTING E_OBJECT E_INTERACTIVE.

ENDCLASS. "lcl_event_handler DEFINITION

----


  • CLASS lcl_event_handler IMPLEMENTATION

----


CLASS LCL_EVENT_HANDLER IMPLEMENTATION.

**Handle Data Change

METHOD HANDLE_DATA_CHANGED.

DATA: X_CHANGE TYPE LVC_S_MODI,

X_FINAL TYPE T_FINAL,

X_OCRC TYPE ZSD_OC_HOLD,

L_FLAG.

LOOP AT ER_DATA_CHANGED->MT_GOOD_CELLS INTO X_CHANGE.

IF X_CHANGE-FIELDNAME = 'ZZOCHOLDRC'.

READ TABLE IT_FINAL INTO X_FINAL INDEX X_CHANGE-ROW_ID.

IF SY-SUBRC = 0.

READ TABLE IT_OCRC INTO X_OCRC WITH KEY

ZZOCHOLDRC = X_CHANGE-VALUE

TRANSPORTING ZZRCDESC.

IF SY-SUBRC = 0.

X_FINAL-ZZRCDESC = X_OCRC-ZZRCDESC.

MODIFY IT_FINAL FROM X_FINAL INDEX X_CHANGE-ROW_ID

TRANSPORTING ZZRCDESC.

L_FLAG = 'X'.

ENDIF.

ENDIF.

ENDIF.

IF X_CHANGE-FIELDNAME = 'ZZPROMDT'.

READ TABLE IT_FINAL INTO X_FINAL INDEX X_CHANGE-ROW_ID.

IF SY-SUBRC = 0.

X_FINAL-ZZPROMDT = X_CHANGE-VALUE.

MODIFY IT_FINAL FROM X_FINAL INDEX X_CHANGE-ROW_ID

TRANSPORTING ZZPROMDT.

L_FLAG = 'X'.

ENDIF.

ENDIF.

ENDLOOP.

IF L_FLAG = 'X'.

CLEAR V_DATA_CHANGE.

V_DATA_CHANGE = 'X'.

ENDIF.

ENDMETHOD. "data_changed

ENDCLASS. "lcl_event_handler IMPLEMENTATION

and u have to create Handler and set the handler for grid.

and then u have to register the event data modified.

Regards

Vijay

Former Member
0 Kudos

Hi

Apart from the method already explained by lots of people , you can also try using FM REUSE_ALV_TRANSFER_DATA_BACK to get the changed values for the line into internal table.

And for making just one field editable use INPUT = 'X' in the field catalogue.

Regards

Kalpana

0 Kudos

Hi Kalpana,

He is talking about some records with onefield = 'A'.

then he want the field to be input off.

few records he want it to be edit enable based on condition.

Regards

Vijay

0 Kudos

My answer was only for the part that was not answered.

Many of you have already replied for how to edit field on a specific condition.

- Kalpana