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

ALV an using Object Oriented ABAP and containers.

Former Member
0 Likes
1,276

hi all,

i am displaying employee details from some table using ALV grid display..and on clicking F4 on editable field i want to display some values from where user will select one of the values..

an two employees are assigned to same project.. an if the third employee also assigned the same project it should check this on F4 and give an error message..

1 ACCEPTED SOLUTION
Read only

anversha_s
Active Contributor
0 Likes
974

hi,

chk this pgm.

<b>BCALV_EDIT_08</b> This report implements an ALV Grid Control with an application specific F4 help. The following aspects

are dealt with:

(1) how to replace the standard f4 help

(2) how to pass the selected value to the ALV Grid Control

(3) how to build an f4 help, whose value range depend on a value of another cell.

Regards

Anver

hi,

chk this pgm.

<b>BCALV_EDIT_08</b> This report implements an ALV Grid Control with an application specific F4 help. The following aspects

are dealt with:

(1) how to replace the standard f4 help

(2) how to pass the selected value to the ALV Grid Control

(3) how to build an f4 help, whose value range depend on a value of another cell.

Regards

Anver

6 REPLIES 6
Read only

anversha_s
Active Contributor
0 Likes
975

hi,

chk this pgm.

<b>BCALV_EDIT_08</b> This report implements an ALV Grid Control with an application specific F4 help. The following aspects

are dealt with:

(1) how to replace the standard f4 help

(2) how to pass the selected value to the ALV Grid Control

(3) how to build an f4 help, whose value range depend on a value of another cell.

Regards

Anver

Read only

Former Member
0 Likes
974

Use the event onf4 for putting f4 help. To do validations use the event data_changed_finished.

In this event u can give ur messages.

CLASS lcl_event_handler DEFINITION .

PUBLIC SECTION.

METHODS handle_onf4 FOR EVENT onf4 OF cl_gui_alv_grid IMPORTING

e_fieldname es_row_no.

METHODS handle_data_changed_finished FOR EVENT data_changed_finished OF cl_gui_alv_grid importing e_modified.

ENDCLASS.

*-----Class implementation

CLASS lcl_event_handler IMPLEMENTATION.

*----F4 help

METHOD handle_onf4.

PERFORM handle_onf4 USING e_fieldname es_row_no.

ENDMETHOD. "handle_onf4

METHOD handle_data_changed_finished.

PERFORM handle_data_changed_finished USING e_modified.

ENDMETHOD.

ENDCLASS.

FORM handle_onf4 USING e_fieldname TYPE lvc_fname

es_row_no TYPE lvc_s_roid.

IF e_fieldname = 'ZSHELLTYP'.

DATA: it_f4 TYPE lvc_t_f4 WITH HEADER LINE.

it_f4-fieldname = 'fieldname'.

it_f4-register = 'X'.

it_f4-getbefore = 'X'.

it_f4-chngeafter = 'X'.

APPEND it_f4.

CALL METHOD o_alvgrid->register_f4_for_fields

EXPORTING

it_f4 = it_f4[].

ENDIF.

ENDFORM. " handle_onf4

FORM handle_data_changed using ir_data_changed TYPE REF TO cl_alv_changed_protocol.

data: ls_mod_cell TYPE lvc_s_modi,

lv_value type lvc_value.

CALL method

ir_data_changed->get_cell_value

exporting i_row_id = ls_mod_cell -row_id

i_fieldname = 'fieldname'

importing e_value = lv_value.

IF lv_value = 'TRY' AND ls_mod_cell-value > '300'.

CALL METHOD ir_data_changed ->add_protocol_entry

EXPORTING

i_msg_id = 'SU'

i_msg_no ='000'

i_msgty = 'E'

i_msgv1 = 'THIS no cannot exceed 300'

i_fieldname = ls_mod_cell-fieldname

i_row_id = ls_mod_cell-row_id.

ENDIF.

ENDFORM.

Try it out.

Read only

Former Member
0 Likes
974

Use the event onf4 for putting f4 help. To do validations use the event data_changed_finished.

In this event u can give ur messages.

CLASS lcl_event_handler DEFINITION .

PUBLIC SECTION.

METHODS handle_onf4 FOR EVENT onf4 OF cl_gui_alv_grid IMPORTING

e_fieldname es_row_no.

METHODS handle_data_changed_finished FOR EVENT data_changed_finished OF cl_gui_alv_grid importing e_modified.

ENDCLASS.

*-----Class implementation

CLASS lcl_event_handler IMPLEMENTATION.

*----F4 help

METHOD handle_onf4.

PERFORM handle_onf4 USING e_fieldname es_row_no.

ENDMETHOD. "handle_onf4

METHOD handle_data_changed_finished.

PERFORM handle_data_changed_finished USING e_modified.

ENDMETHOD.

ENDCLASS.

FORM handle_onf4 USING e_fieldname TYPE lvc_fname

es_row_no TYPE lvc_s_roid.

IF e_fieldname = 'ZSHELLTYP'.

DATA: it_f4 TYPE lvc_t_f4 WITH HEADER LINE.

it_f4-fieldname = 'fieldname'.

it_f4-register = 'X'.

it_f4-getbefore = 'X'.

it_f4-chngeafter = 'X'.

APPEND it_f4.

CALL METHOD o_alvgrid->register_f4_for_fields

EXPORTING

it_f4 = it_f4[].

ENDIF.

ENDFORM. " handle_onf4

FORM handle_data_changed using ir_data_changed TYPE REF TO cl_alv_changed_protocol.

data: ls_mod_cell TYPE lvc_s_modi,

lv_value type lvc_value.

CALL method

ir_data_changed->get_cell_value

exporting i_row_id = ls_mod_cell -row_id

i_fieldname = 'fieldname'

importing e_value = lv_value.

IF lv_value = 'TRY' AND ls_mod_cell-value > '300'.

CALL METHOD ir_data_changed ->add_protocol_entry

EXPORTING

i_msg_id = 'SU'

i_msg_no ='000'

i_msgty = 'E'

i_msgv1 = 'THIS no cannot exceed 300'

i_fieldname = ls_mod_cell-fieldname

i_row_id = ls_mod_cell-row_id.

ENDIF.

ENDFORM.

Try it out.

Read only

uwe_schieferstein
Active Contributor
0 Likes
974

Hello Shabari

A possible solution for your problem could look like this:

- the report should not allow to enter more than two times currency='CHF'

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_BCALV_GRID_DEMO_EDIT
*&
*&---------------------------------------------------------------------*
*&
*& NOTE: copy sample report BCALV_GRID_DEMO (including screen) and
*&       replace entire coding of report.
*& Flow logic of dynpro 100:
*&PROCESS BEFORE OUTPUT.
*&  MODULE PBO.
*&
*&PROCESS AFTER INPUT.
*&  MODULE PAI.
*&
*&---------------------------------------------------------------------*

PROGRAM zus_sdn_bcalv_grid_demo_edit.
DATA: ok_code LIKE sy-ucomm,
      gt_sflight TYPE TABLE OF sflight,
      g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',
      grid1  TYPE REF TO cl_gui_alv_grid,
      g_custom_container TYPE REF TO cl_gui_custom_container.





DATA:
  gd_count  TYPE i,
  gs_fcat   TYPE lvc_s_fcat,
  gt_fcat   TYPE lvc_t_fcat.

*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.

  PUBLIC SECTION.



    CLASS-METHODS:
    handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
      IMPORTING
        er_data_changed
        e_onf4
        e_onf4_before
        e_onf4_after
        e_ucomm
        sender,

    handle_data_changed_finished FOR EVENT
                        data_changed_finished OF cl_gui_alv_grid
      IMPORTING
        e_modified
        et_good_cells
        sender.

ENDCLASS.                    "lcl_eventhandler DEFINITION


*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.



  METHOD handle_data_changed.
  ENDMETHOD.                    "handle_data_changed


  METHOD handle_data_changed_finished.
*   define local data
    DATA:
      ld_count   TYPE i,
      lo_log     TYPE REF TO cl_alv_changed_data_protocol.


*   Check modified cells
    ld_count = 0.
    LOOP AT et_good_cells TRANSPORTING NO FIELDS
            WHERE ( fieldname = 'CURRENCY'  AND
                    value     = 'CHF' ).
      ADD 1 TO ld_count.
    ENDLOOP.


    IF ( ld_count >= 3 ).
    ELSE.
      LOOP AT gt_sflight TRANSPORTING NO FIELDS
           WHERE ( currency = 'CHF' ).
        ADD 1 TO ld_count.
        IF ( ld_count >= 3 ).
          EXIT.
        ENDIF.
      ENDLOOP.
    ENDIF.



    IF ( ld_count >= 3 ).
      CREATE OBJECT lo_log
        EXPORTING
*          I_CONTAINER =
          i_calling_alv = grid1.

      CALL METHOD lo_log->add_protocol_entry
        EXPORTING
          i_msgid     = '00'
          i_msgty     = 'E'
          i_msgno     = '398'
          i_msgv1     = 'Only 2x CHF currency allowed'
*            I_MSGV2     =
*            I_MSGV3     =
*            I_MSGV4     =
          i_fieldname = 'CURRENCY'
*            i_row_id    =
*            I_TABIX     =
          .

      lo_log->display_protocol( ).
    ENDIF.


  ENDMETHOD.                    "handle_data_changed_finished


ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION


START-OF-SELECTION.

*---------------------------------------------------------------------*
*       MAIN                                                          *
*---------------------------------------------------------------------*

  SELECT * FROM sflight INTO TABLE gt_sflight.

  CALL SCREEN 100.


*---------------------------------------------------------------------*
*       MODULE PBO OUTPUT                                             *
*---------------------------------------------------------------------*
MODULE pbo OUTPUT.
  SET PF-STATUS 'MAIN100'.
  IF g_custom_container IS INITIAL.
    CREATE OBJECT g_custom_container
           EXPORTING container_name = g_container.

*   Instantiate ALV grid control
    CREATE OBJECT grid1
           EXPORTING i_parent = g_custom_container.
    CALL METHOD grid1->set_table_for_first_display
      EXPORTING
        i_structure_name = 'SFLIGHT'
      CHANGING
        it_outtab        = gt_sflight.


    CALL METHOD grid1->get_frontend_fieldcatalog
      IMPORTING
        et_fieldcatalog = gt_fcat.
    gs_fcat-edit = 'X'.
    MODIFY gt_fcat FROM gs_fcat
      TRANSPORTING edit
      WHERE ( fieldname = 'CURRENCY' ).
    CALL METHOD grid1->set_frontend_fieldcatalog
      EXPORTING
        it_fieldcatalog = gt_fcat.

    grid1->refresh_table_display( ).


*   Set event handlers
    SET HANDLER:
      lcl_eventhandler=>handle_data_changed          FOR grid1,
      lcl_eventhandler=>handle_data_changed_finished FOR grid1.

*§3.Optionally register ENTER to raise event DATA_CHANGED.
*   (Per default the user may check data by using the check icon).
    CALL METHOD grid1->register_edit_event
      EXPORTING
        i_event_id = cl_gui_alv_grid=>mc_evt_enter.
  ENDIF.



ENDMODULE.                    "PBO OUTPUT
*---------------------------------------------------------------------*
*       MODULE PAI INPUT                                              *
*---------------------------------------------------------------------*
MODULE pai INPUT.
*   to react on oi_custom_events:
  CALL METHOD cl_gui_cfw=>dispatch.


  CASE ok_code.
    WHEN 'EXIT'.
      PERFORM exit_program.
    WHEN OTHERS.
      grid1->check_changed_data( ).  " check data changes

      gd_count = 0.
      LOOP AT gt_sflight TRANSPORTING NO FIELDS
              WHERE ( currency = 'CHF' ).
        ADD 1 TO gd_count.
        CHECK ( gd_count < 3 ).
      ENDLOOP.

      IF ( gd_count > 2 ).
        MESSAGE 'Only 2x CHF currency allowed' TYPE 'E'.
      ELSE.
        MESSAGE 'Currencies ok' TYPE 'S'.
      ENDIF.
  ENDCASE.
  CLEAR ok_code.
ENDMODULE.                    "PAI INPUT
*---------------------------------------------------------------------*
*       FORM EXIT_PROGRAM                                             *
*---------------------------------------------------------------------*
FORM exit_program.
*  CALL METHOD G_CUSTOM_CONTAINER->FREE.
*  CALL METHOD CL_GUI_CFW=>FLUSH.
  LEAVE PROGRAM.
ENDFORM.                    "EXIT_PROGRAM

Regards

Uwe

Read only

0 Likes
974

Hi,

how can i display the wrong cells red?

Best regards,

TomSd

Read only

0 Likes
974

You can use this for displaying an error within a cell. I use it within the handle_data_changed method:


DATA: lv_changed TYPE lvc_s_modi,

LOOP AT er_data_changed->mt_good_cells INTO lv_changed

* If you find an error, then: 
      CALL METHOD er_data_changed->add_protocol_entry
           EXPORTING
             i_msgid = 'SU'
             i_msgno = '000'
             i_msgty = 'E'
             i_msgv1 = 'Any message 1''
             i_msgv2 = 'Any message 2'
             i_fieldname = lv_changed-fieldname
             i_row_id = lv_changed-row_id .
endloop.

Edited by: cesarjusto on Feb 3, 2010 11:56 PM