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: 

Making ALV ineditable for a field conditionally

Former Member
0 Kudos

Hai All,

I have a column in ALV which is editable.I want to make that as ineditable mode based on some conditions.

Thanks in advance

kiran I

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

R u using FM for grid display or .......

If so based on condition..

IF.....

here you need to delete EDIT option in FIELDCATLOG.

                • ls_fieldcat-fieldname = 'ACTDT'.

ls_fieldcat-col_pos = 18.

ls_fieldcat-seltext_l = 'Activation Date'.

ls_fieldcat-outputlen = 8.

  • ls_fieldcat-just = 'C'.

*****

ls_fieldcat-edit = 'X'

*****

append ls_fieldcat to header.

CLEAR ls_fieldcat.

**********OR*************

DATA ls_listrow LIKE LINE OF pt_list .

DATA ls_stylerow TYPE lvc_s_styl .

DATA lt_styletab TYPE lvc_t_styl .

LOOP AT pt_list INTO ls_listrow .

****Here Field is not EDITABLE**********

IF ls_listrow-carrid = 'XY' .

ls_stylerow-fieldname = 'SEATSMAX' .

ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled .

APPEND ls_stylerow TO lt_styletab .

ENDIF .

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

IF ls_listrow-connid = '02' .

ls_stylerow-fieldname = 'PLANETYPE' .

ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled .

APPEND ls_stylerow TO lt_styletab .

ENDIF .

INSERT LINES OF lt_styletab INTO ls_listrow-cellstyles .

MODIFY pt_list FROM ls_listrow .

ENDLOOP .

I hope this wil help you.

Thanks.

If your issue is solved award points and close the thread.

21 REPLIES 21

Former Member
0 Kudos

Hi Kiran,

Have and additional field in the internal table as flag based on the condition which satisfies your condition pass value x to the field and modify the field cat for the corresponding flag.

0 Kudos

Hi Prabhu,

could you send me sample code for that.

Former Member
0 Kudos

Hi,

R u using FM for grid display or .......

If so based on condition..

IF.....

here you need to delete EDIT option in FIELDCATLOG.

                • ls_fieldcat-fieldname = 'ACTDT'.

ls_fieldcat-col_pos = 18.

ls_fieldcat-seltext_l = 'Activation Date'.

ls_fieldcat-outputlen = 8.

  • ls_fieldcat-just = 'C'.

*****

ls_fieldcat-edit = 'X'

*****

append ls_fieldcat to header.

CLEAR ls_fieldcat.

**********OR*************

DATA ls_listrow LIKE LINE OF pt_list .

DATA ls_stylerow TYPE lvc_s_styl .

DATA lt_styletab TYPE lvc_t_styl .

LOOP AT pt_list INTO ls_listrow .

****Here Field is not EDITABLE**********

IF ls_listrow-carrid = 'XY' .

ls_stylerow-fieldname = 'SEATSMAX' .

ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled .

APPEND ls_stylerow TO lt_styletab .

ENDIF .

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

IF ls_listrow-connid = '02' .

ls_stylerow-fieldname = 'PLANETYPE' .

ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled .

APPEND ls_stylerow TO lt_styletab .

ENDIF .

INSERT LINES OF lt_styletab INTO ls_listrow-cellstyles .

MODIFY pt_list FROM ls_listrow .

ENDLOOP .

I hope this wil help you.

Thanks.

If your issue is solved award points and close the thread.

0 Kudos

Hi Deepak,

Iam not using classes ,i am using reuse_alv_grid_display

.

0 Kudos

Hi,

Then see my earlier code Example 1.

Example:

If itab-matnr = ' '......some thing your logic/condition.

here you disable your EDIT in FEILDCAT to which you wish to Delete EDIT option.

then pass this to FM.

If not i agree with PRABHU that one FLAG field will serve your purpose.

Thanks.

0 Kudos

Hi,

Check this link which also discusses the same thing and kindly reward points by clicking the star on the left of reply,if it helps.

0 Kudos

Hi deepak,

In my internal table i have a lights column where if light is yellow only i have to make it editable otherwise no.now how to code for this .do you want me to do changes conditionally in field catalog or in table that we pass to alv FM.

Thanks

Kiran I

0 Kudos

Hi,

In your final Internal table in LIGHTS column check which value will come to YELLOW.

That is when yellow comes it will get one value like 0,1, or some thing.

Find out the value which coming for yellow.

Then...

if itab-field(lights field) = '0'. " say yellow

Ls_fieldcat-EDIT = 'X'.

append...

pass this to FM(grid) display.

Thanks.

Message was edited by: Deepak333 k

0 Kudos

Hi Deepak,

That means i have to loop at that internal table and conditiaonally i have to append the field catalog.

or while populating field catalog i have to check this condition.

Thanks

kiran i

0 Kudos

Exactly..........

I hope now you are on right track....

Thanks.

If your issue is solved reward points and close thread.

Message was edited by: Deepak333 k

0 Kudos

Hi deepak,

iam doing looping the internal table and appending the field catalog.

but iam getting alv as unedittable ,but iwant some data to be uneditable .

Thanks

kiran

0 Kudos

Hi Kiran,

check this code.

*&---------------------------------------------------------------------*
*& Report  ZTESTV2                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

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.

data: begin of it_chg occurs 0,
      index type sy-tabix,
      end of it_chg.
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.
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.

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'.
X_FIELDCAT-EDIT = 'X'.
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
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.

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
*----------------------------------------------------------------------*
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 + 1 for labels.
  DO L_LINES TIMES.
    read table it_chg with key INDEX = 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 ITAB-NAME INPUT OFF.
      ENDIF.
    ENDIF.
  ENDDO.

ENDFORM.                    "MODIFY_LIST

regards

vijay

Message was edited by: Vijay Babu Dudla

0 Kudos

Hi,

Check the consistency of your data.

I mean check the color code with which you are restricting.

I hope now you got the logic so that you can manipulate now in anyway.

Thanks.

0 Kudos

Hi Kiran,

If you are going for ALV list then Check above code

that will solve ur Problem.

Regards

Vijay

0 Kudos

Hi vijay,

Iam using ALV grid.

Regards,

kirani

0 Kudos

If you Still Need the Help

I will Help You Out.

Regards

Vijay

0 Kudos

yes Vijay,

I think you have understand my issue.i want to make one column of output to be editable ehat too conditionally. say for example in your program when zterm is A only i want to make NAME field editable otherwise no.

this is my issue.

thanks in advance

kiran i

0 Kudos

You Need To Do Few Steps.

Add one extra Field in your Output table.

that is <b>HANDLE_STYLE TYPE LVC_T_STYL</b>

and in layout set the stylename.

<b>GS_LAYOUT-STYLEFNAME = 'HANDLE_STYLE'.</b>

after that Before calling method display

  DATA: LS_EDIT TYPE LVC_S_STYL,
        LT_EDIT TYPE LVC_T_STYL.

data: v_index type sy-tabix.

<b>**I m setting flag for my condition

**I added a flag field in my table

**if ZTERM = 'A' i am setting flag in my final table

**where ever flag is 'X' i am changing/disabling the edit</b>

 LOOP AT IT_FINAL INTO LS_OUTTAB WHERE FLAG = 'X'.
    V_INDEX = SY-TABIX.
    LS_EDIT-FIELDNAME = 'MATNR'.
    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 = 'WERKS'.
    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 .

  ENDLOOP.

0 Kudos

hi Vijay,

Iam not using classes.iam using FM reuse_alv_grid_display.

0 Kudos

Hi Kiran,

Either You Convert From GRID to list or

GRID to Grid Control That will solve your Problem.

if Grid to List then Above code will work.

Regards

Vijay

Message was edited by: Vijay Babu Dudla

Former Member
0 Kudos

Hi use the 'edit' option from the field catalog in ur code.

this will help u.

like ls_fieldcat-edit = 'X'

Satish