Application Development and Automation 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: 
Read only

Validation on ALV screen

Former Member
0 Likes
1,102

Hi All,

Iam using ALV grid display in my program.

I have two columns say A and B botha rre numeric.

A can be modified where as B cannot.

I will enter some value in A say 5 where as B is 3.

Then we will save that layout ,while saving i want apopup saying you cant enter more than B.

Is it possible to know which row he ahs changed.

is that possible in REUSE_ALV_GRID_DISPLAY.

With Regards,

Kiran I

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,078

you can compare the data, in SAVE sy-ucomm, and then give pop up based on your condition...

<b>selfield TYPE slis_selfield.</b>

Using SELFIELD you can find index and fieldname also,

but your case use index and read record then give pop up according to your requirement

you can compare the data, in SAVE sy-ucomm, and then give pop up based on your condition...

<b>selfield TYPE slis_selfield.</b>

Using SELFIELD you can find index and fieldname also,

but your case use index and read record then give pop up according to your requirement

9 REPLIES 9
Read only

Former Member
0 Likes
1,078
gd_repid LIKE sy-repid, "Exists
ref_grid TYPE REF TO cl_gui_alv_grid. "new

then insert the following code in your USER_COMMAND routine...

FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.

IF ref_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
* ET_EXCLUDING =
* E_FLG_NO_HTML =
* E_REPID =
e_grid = ref_grid
* ES_LAYOUT_KKBLO =
.
ENDIF.

IF NOT ref_grid IS INITIAL.
CALL METHOD ref_grid->check_changed_data
* IMPORTING
* E_VALID =
* CHANGING
* C_REFRESH = 'X'
.
ENDIF.

Note try to take backup before calling FM, and then using that you can compare the data,

Read only

Former Member
0 Likes
1,079

you can compare the data, in SAVE sy-ucomm, and then give pop up based on your condition...

<b>selfield TYPE slis_selfield.</b>

Using SELFIELD you can find index and fieldname also,

but your case use index and read record then give pop up according to your requirement

Read only

0 Likes
1,078

Hi Vijay,

can you please send me the sample code for that

with regards,

kiran i

Read only

0 Likes
1,078
REPORT  ZTESTDFALV1                             .

*Data Declaration
*----------------
DATA: BEGIN OF T_EKKO,
  SELECT(1),
  EBELN TYPE EKPO-EBELN,
  EBELP TYPE EKPO-EBELP,
 END OF T_EKKO.

DATA: BEGIN OF IT_EKKO OCCURS 0.
        INCLUDE STRUCTURE T_EKKO.
DATA: END OF IT_EKKO.

*ALV data declarations
TYPE-POOLS: SLIS.                                 "ALV Declarations
DATA: FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
      GD_LAYOUT    TYPE SLIS_LAYOUT_ALV,
      GD_REPID     LIKE SY-REPID.


************************************************************************
*Start-of-selection.
START-OF-SELECTION.

  PERFORM DATA_RETRIEVAL.
  PERFORM BUILD_FIELDCATALOG.
  PERFORM BUILD_LAYOUT.
  PERFORM DISPLAY_ALV_REPORT.


*&--------------------------------------------------------------------*
*&      Form  build_fieldcatalog
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM BUILD_FIELDCATALOG.
  REFRESH FIELDCATALOG.
  CLEAR FIELDCATALOG.
*
  FIELDCATALOG-FIELDNAME   = 'SELECT'.
  FIELDCATALOG-SELTEXT_M   = 'Select please'.
  FIELDCATALOG-CHECKBOX    = 'X'.
  FIELDCATALOG-EDIT        = 'X'.
  FIELDCATALOG-INPUT       = 'X'.
  FIELDCATALOG-COL_POS     = 1.
  APPEND FIELDCATALOG.
  CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME   = 'EBELN'.
  FIELDCATALOG-SELTEXT_M   = 'Purchase Order'.
  FIELDCATALOG-HOTSPOT     = 'X'.
  FIELDCATALOG-COL_POS     = 2.
  APPEND FIELDCATALOG.
  CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME   = 'EBELP'.
  FIELDCATALOG-SELTEXT_M   = 'PO Item'.
  FIELDCATALOG-COL_POS     = 3.
  APPEND FIELDCATALOG.
  CLEAR  FIELDCATALOG.

ENDFORM.                    " BUILD_FIELDCATALOG


*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       Build layout for ALV grid report
*----------------------------------------------------------------------*
FORM BUILD_LAYOUT.
  "Permet d'ajuster les colonnes au text
*  gd_layout-colwidth_optimize = 'X'.
  GD_LAYOUT-TOTALS_TEXT       = 'Totals'(201).

*  gd_layout-box_fieldname = 'SELECT'.
*  gd_layout-box_tabname   = 'IT_EKKO'.

ENDFORM.                    " BUILD_LAYOUT


*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*       Display report using ALV grid
*----------------------------------------------------------------------*
FORM DISPLAY_ALV_REPORT.
  GD_REPID = SY-REPID.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            I_CALLBACK_PROGRAM        = GD_REPID
*            i_callback_top_of_page   = 'TOP-OF-PAGE'
            I_CALLBACK_PF_STATUS_SET  = 'SET_PF_STATUS'
            I_CALLBACK_USER_COMMAND   = 'USER_COMMAND'
*            i_grid_title             = 'My Title'
            IS_LAYOUT                 = GD_LAYOUT
            IT_FIELDCAT               = FIELDCATALOG[]
       TABLES
            T_OUTTAB                  = IT_EKKO
       EXCEPTIONS
            PROGRAM_ERROR             = 1
            OTHERS                    = 2.

  IF SY-SUBRC <> 0.
    WRITE:/ SY-SUBRC.
  ENDIF.

ENDFORM.                    " DISPLAY_ALV_REPORT


*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
FORM DATA_RETRIEVAL.
  SELECT EBELN EBELP
   UP TO 10 ROWS
    FROM EKPO
    INTO CORRESPONDING FIELDS OF TABLE  IT_EKKO.
ENDFORM.                    " DATA_RETRIEVAL


*----------------------------------------------------------------------*
*                      FORM SET_PF_STATUS                              *
*----------------------------------------------------------------------*
FORM SET_PF_STATUS USING RT_EXTAB   TYPE  SLIS_T_EXTAB.
  SET PF-STATUS 'STANDARD_FULLSCREEN1' EXCLUDING RT_EXTAB.
ENDFORM.                    "set_pf_status


*&--------------------------------------------------------------------*
*&      Form  user_command
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*      -->R_UCOMM    text
*      -->RS_SELFIELDtext
*---------------------------------------------------------------------*
FORM USER_COMMAND  USING R_UCOMM LIKE SY-UCOMM
                         RS_SELFIELD TYPE SLIS_SELFIELD.


  <b>DATA: GD_REPID LIKE SY-REPID, "Exists
  REF_GRID TYPE REF TO CL_GUI_ALV_GRID. "new

*then insert the following code in your USER_COMMAND routine...


  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.</b>

  CASE R_UCOMM.
    WHEN '&IC1'.
      CHECK RS_SELFIELD-TABINDEX > 0.
      IF RS_SELFIELD-VALUE EQ '6000000001'.
        CALL TRANSACTION 'ZDF2'.
      ENDIF.
    WHEN 'REFRESH'.

      LOOP AT IT_EKKO WHERE SELECT = 'X'.

      ENDLOOP.

      PERFORM DATA_RETRIEVAL.
      RS_SELFIELD-REFRESH = 'X'.

  ENDCASE.
ENDFORM.                    "user_command

Try this in this we can capture the check box value after the edit,

similar way you try ...

regards

vijay

Read only

0 Likes
1,078
REPORT  ZTESTDFALV1                             .

*Data Declaration
*----------------
DATA: BEGIN OF T_EKKO,
  EBELN TYPE EKPO-EBELN,
  EBELP TYPE EKPO-EBELP,
 END OF T_EKKO.

DATA: BEGIN OF IT_EKKO OCCURS 0.
        INCLUDE STRUCTURE T_EKKO.
DATA: END OF IT_EKKO.

DATA: BEGIN OF IT_BACKUP OCCURS 0.
        INCLUDE STRUCTURE T_EKKO.
DATA: END OF IT_BACKUP.
*ALV data declarations
TYPE-POOLS: SLIS.                                 "ALV Declarations
DATA: FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
      GD_LAYOUT    TYPE SLIS_LAYOUT_ALV,
      GD_REPID     LIKE SY-REPID.


************************************************************************
*Start-of-selection.
START-OF-SELECTION.

  PERFORM DATA_RETRIEVAL.
  PERFORM BUILD_FIELDCATALOG.
  PERFORM BUILD_LAYOUT.
  IT_BACKUP[] = IT_EKKO[].
  PERFORM DISPLAY_ALV_REPORT.


*&--------------------------------------------------------------------*
*&      Form  build_fieldcatalog
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM BUILD_FIELDCATALOG.
  REFRESH FIELDCATALOG.
  CLEAR FIELDCATALOG.
*

  FIELDCATALOG-FIELDNAME   = 'EBELN'.
  FIELDCATALOG-SELTEXT_M   = 'Purchase Order'.
  FIELDCATALOG-INPUT     = 'X'.
  FIELDCATALOG-EDIT     = 'X'.
  FIELDCATALOG-COL_POS     = 2.
  APPEND FIELDCATALOG.
  CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME   = 'EBELP'.
  FIELDCATALOG-SELTEXT_M   = 'PO Item'.
  FIELDCATALOG-COL_POS     = 3.
  APPEND FIELDCATALOG.
  CLEAR  FIELDCATALOG.

ENDFORM.                    " BUILD_FIELDCATALOG


*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       Build layout for ALV grid report
*----------------------------------------------------------------------*
FORM BUILD_LAYOUT.
  "Permet d'ajuster les colonnes au text
*  gd_layout-colwidth_optimize = 'X'.
  GD_LAYOUT-TOTALS_TEXT       = 'Totals'(201).

*  gd_layout-box_fieldname = 'SELECT'.
*  gd_layout-box_tabname   = 'IT_EKKO'.

ENDFORM.                    " BUILD_LAYOUT


*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*       Display report using ALV grid
*----------------------------------------------------------------------*
FORM DISPLAY_ALV_REPORT.
  GD_REPID = SY-REPID.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            I_CALLBACK_PROGRAM        = GD_REPID
*            i_callback_top_of_page   = 'TOP-OF-PAGE'
            I_CALLBACK_PF_STATUS_SET  = 'SET_PF_STATUS'
            I_CALLBACK_USER_COMMAND   = 'USER_COMMAND'
*            i_grid_title             = 'My Title'
            IS_LAYOUT                 = GD_LAYOUT
            IT_FIELDCAT               = FIELDCATALOG[]
       TABLES
            T_OUTTAB                  = IT_EKKO
       EXCEPTIONS
            PROGRAM_ERROR             = 1
            OTHERS                    = 2.

  IF SY-SUBRC <> 0.
    WRITE:/ SY-SUBRC.
  ENDIF.

ENDFORM.                    " DISPLAY_ALV_REPORT


*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
FORM DATA_RETRIEVAL.
  SELECT EBELN EBELP
   UP TO 10 ROWS
    FROM EKPO
    INTO CORRESPONDING FIELDS OF TABLE  IT_EKKO.
ENDFORM.                    " DATA_RETRIEVAL


*----------------------------------------------------------------------*
*                      FORM SET_PF_STATUS                              *
*----------------------------------------------------------------------*
FORM SET_PF_STATUS USING RT_EXTAB   TYPE  SLIS_T_EXTAB.
  SET PF-STATUS 'STANDARD_FULLSCREEN1' EXCLUDING RT_EXTAB.
ENDFORM.                    "set_pf_status


*&--------------------------------------------------------------------*
*&      Form  user_command
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*      -->R_UCOMM    text
*      -->RS_SELFIELDtext
*---------------------------------------------------------------------*
FORM USER_COMMAND  USING R_UCOMM LIKE SY-UCOMM
                         RS_SELFIELD TYPE SLIS_SELFIELD.


  DATA: GD_REPID LIKE SY-REPID, "Exists
  REF_GRID TYPE REF TO CL_GUI_ALV_GRID. "new

*then insert the following code in your USER_COMMAND routine...


  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.



  CASE R_UCOMM.
    WHEN '&IC1'.
      CHECK RS_SELFIELD-TABINDEX > 0.
      IF RS_SELFIELD-VALUE EQ '6000000001'.
        CALL TRANSACTION 'ZDF2'.
      ENDIF.
    WHEN 'REFRESH'.

      READ TABLE IT_EKKO INDEX  RS_SELFIELD-TABINDEX.
      IF SY-SUBRC = 0.
        READ TABLE IT_BACKUP INDEX RS_SELFIELD-TABINDEX.
        IF SY-SUBRC = 0.
          IF IT_EKKO <> IT_BACKUP.
*  then do your check
          ENDIF.
        ENDIF.
      ENDIF.

      PERFORM DATA_RETRIEVAL.
      RS_SELFIELD-REFRESH = 'X'.

  ENDCASE.
ENDFORM.                    "user_command

hi This will Have Input Edit field check this also..

regards

vijay

Read only

0 Likes
1,078

Hi

Please see the above Code, For Helpful Answers Please reward points.

regards

vijay

Read only

Former Member
0 Likes
1,078

If you need any thing further please let me know,

I hope this will solve your Problem..

regards

vijay

Read only

Former Member
0 Likes
1,078

Hi kiran,

when 'SAVE'

Data ref1 type ref to cl_gui_alv_grid.

CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

IMPORTING

E_GRID = ref1.

call method ref1->check_changed_data

Loop at itab.

if itab-cola Gt colb.

use FM for POP UP

endif.

endloop.

Read only

Former Member
0 Likes
1,078

When 'SAVE'

CALL METHOD W_GRID->CHECK_CHANGED_DATA

IMPORTING

E_VALID = L_VALID.

*l_valid will return X if any data is changed on grid

IF L_VALID = 'X'.

loop at itab.

if col A GT col B.

use the FM to get popup(will give u if needed).

endif.

endloop.

endif.