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

Reg: Obj. Based ALV Reports

Former Member
0 Likes
781

I have developed a ALV Report using objects

I have deactivated some fields (Key Fields ) in the table using field catlog .

Now the thing is that i want to insert a New row in the table I dont have problem appending a row but how am i going to activate the deactivated fields in the table for the PERTICULAR newly added row keeping all the other rows deactive ..?

Plz Plz ....Answer....

6 REPLIES 6
Read only

uwe_schieferstein
Active Contributor
0 Likes
679

Hello Deshmukh

You need to define the input status at cell level => see sample report BCALV_EDIT_02

This report is quite well documented in its header section.

Regards

Uwe

Read only

0 Likes
679

i want to activate a specific row in my alv and rest i have to keep in active and after insertion of new row i will deactivate it too...

Read only

0 Likes
679

Hello Deshmukh

According to my sample report prepare two CELLTAB's having the following contents:


DATA:
  gt_celltab_enabled   TYPE lvc_t_styl,
  gt_celltab_disabled  TYPE lvc_t_styl.

...
DATA: ls_cell  TYPE lvc_s_styl.

REFRESH: gt_celltab_enabled, gt_celltab_disabled.
LOOP AT gt_fcat INTO ls_fcat.
  ls_cell-fieldname = ls_fcat-fieldname.

  ls_cell-style = cl_gui_alv_grid=>mc_style_enabled.
  INSERT ls_cell INTO TABLE gt_celltab_enabled.
*
  ls_cell-style = cl_gui_alv_grid=>mc_style_disabled.
  INSERT ls_cell INTO TABLE gt_celltab_disabled.

ENDLOOP.

Now you can use GT_CELLTAB_ENABLED to make your specific row editable. GT_CELLTAB_DISABLED is used to inactive all other rows.

In order to change the fieldcatalog during runtime you have the methods GET_FRONTEND_FIELDCATALOG and SET_FRONTEND_FIELDCATALOG available. For a sample report please refer to BCALV_FIELDCAT_TEST.

Regards

Uwe

Read only

uwe_schieferstein
Active Contributor
0 Likes
679

Hello Deshmukh

Perhaps sample report ZUS_SDN_ALVGRID_EDITABLE_8A may be useful for you.


*&---------------------------------------------------------------------*
*& ZUS_SDN_ALVGRID_EDITABLE_8A
*&
*&---------------------------------------------------------------------*
*& Thread: Reg: Obj. Based ALV Reports
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1164981"></a>
*&
*& Thread: Insert a row in ALV
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1105097"></a>
*&
*& Thread: Blanking values on ALV Grid Row Duplicate
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1057161"></a>
*&
*& Thread: Delete line event in ALV
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="945471"></a>
*&---------------------------------------------------------------------*

REPORT  zus_sdn_alvgrid_editable_8a.

TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE knb1.
TYPES celltab   TYPE lvc_t_styl.  " SORTED table type !!!
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab    TYPE STANDARD TABLE OF ty_s_outtab
                      WITH DEFAULT KEY.
DATA:
  gd_okcode        TYPE ui_func,
  gd_repid         TYPE syst-repid,
*
  gt_celltab       TYPE lvc_t_styl,
  gt_fcat          TYPE lvc_t_fcat,
  gs_layout        TYPE lvc_s_layo,
  gs_variant       TYPE disvariant,
  go_docking       TYPE REF TO cl_gui_docking_container,
  go_grid          TYPE REF TO cl_gui_alv_grid.


DATA:
  gt_outtab        TYPE ty_t_outtab.



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

  PUBLIC SECTION.
    CLASS-DATA:
      mt_sel_rows     TYPE lvc_t_row.

    CLASS-METHODS:
      handle_toolbar
        FOR EVENT toolbar OF cl_gui_alv_grid
        IMPORTING
          e_object
          sender,

      handle_user_command
        FOR EVENT user_command OF cl_gui_alv_grid
        IMPORTING
          e_ucomm
          sender.

ENDCLASS.                    "lcl_eventhandler DEFINITION


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

  METHOD handle_toolbar.
* define local data
    DATA: ls_button     TYPE stb_button.

    LOOP AT e_object->mt_toolbar INTO ls_button.
      CASE ls_button-function.
        WHEN cl_gui_alv_grid=>mc_fc_loc_insert_row.
          ls_button-function = 'INSERT_ROW'.
          MODIFY e_object->mt_toolbar FROM ls_button INDEX syst-tabix.

        WHEN cl_gui_alv_grid=>mc_fc_loc_delete_row.
          ls_button-function = 'DELETE_ROW'.
          MODIFY e_object->mt_toolbar FROM ls_button INDEX syst-tabix.

        WHEN cl_gui_alv_grid=>mc_fc_loc_copy_row OR
             cl_gui_alv_grid=>mc_fc_loc_copy.
          ls_button-function = 'COPY_ROW'.
          MODIFY e_object->mt_toolbar FROM ls_button INDEX syst-tabix.
        WHEN OTHERS.
          CONTINUE.
      ENDCASE.

    ENDLOOP.

  ENDMETHOD.                    "handle_toolbar

  METHOD handle_user_command.
* define local data
    DATA: lt_rows       TYPE lvc_t_row,
          ls_row        TYPE lvc_s_row.


    REFRESH: mt_sel_rows.

    CASE e_ucomm.
      WHEN 'INSERT_ROW'.

      WHEN 'DELETE_ROW'.

      WHEN 'COPY_ROW'.

      WHEN OTHERS.
        RETURN.
    ENDCASE.


    "   User wants to delete or copy rows => store them in class attribute
    "   and trigger PAI afterwards where we actually delete /copy the rows
    "   and do the recalculations (in case of deletion)
    CALL METHOD sender->get_selected_rows
      IMPORTING
        et_index_rows = mt_sel_rows
*        et_row_no     =
        .


*   Trigger PAI
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = e_ucomm
*      IMPORTING
*        rc       =
        .

  ENDMETHOD.                    "user_command

ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION



PARAMETERS:
  p_bukrs      TYPE bukrs  DEFAULT '2000'  OBLIGATORY.




START-OF-SELECTION.

  SELECT  * FROM  knb1 INTO CORRESPONDING FIELDS OF TABLE gt_outtab
         UP TO 15 ROWS
         WHERE  bukrs  = p_bukrs.


  PERFORM init_controls.

  SET HANDLER:
    lcl_eventhandler=>handle_toolbar      FOR go_grid,
    lcl_eventhandler=>handle_user_command FOR go_grid.

  " Used to replace standard toolbar function code with custom FC
  go_grid->set_toolbar_interactive( ).


* Link the docking container to the target dynpro
  gd_repid = syst-repid.
  CALL METHOD go_docking->link
    EXPORTING
      repid                       = gd_repid
      dynnr                       = '0100'
*      CONTAINER                   =
    EXCEPTIONS
      OTHERS                      = 4.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* ok-code field = GD_OKCODE
  CALL SCREEN '0100'.


END-OF-SELECTION.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS_0100'.
*  SET TITLEBAR 'xxx'.

**      CALL METHOD go_grid1->refresh_table_display
***        EXPORTING
***          IS_STABLE      =
***          I_SOFT_REFRESH =
**        EXCEPTIONS
**          FINISHED       = 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.

ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

  CASE gd_okcode.
    WHEN 'BACK' OR
         'END'  OR
         'CANC'.
      SET SCREEN 0. LEAVE SCREEN.

    WHEN 'INSERT_ROW'.
      PERFORM insert_row.

    WHEN 'DELETE_ROW'.
      PERFORM delete_rows.

    WHEN 'COPY_ROW'.
      PERFORM copy_rows.


    WHEN OTHERS.
  ENDCASE.

  CLEAR: gd_okcode.

  CALL METHOD go_grid->refresh_table_display
*      EXPORTING
*        IS_STABLE      =
*        I_SOFT_REFRESH =
    EXCEPTIONS
      finished       = 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.

ENDMODULE.                 " USER_COMMAND_0100  INPUT




*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG_KNB1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_fieldcatalog_knb1 .
* define local data
  DATA:
    ls_fcat        TYPE lvc_s_fcat.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
*     I_BUFFER_ACTIVE              =
      i_structure_name             = 'KNB1'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_BYPASSING_BUFFER           =
*     I_INTERNAL_TABNAME           =
    CHANGING
      ct_fieldcat                  = gt_fcat
    EXCEPTIONS
      inconsistent_interface       = 1
      program_error                = 2
      OTHERS                       = 3.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* Only non-key fields are editable
**  ls_fcat-edit = 'X'.
**  MODIFY gt_fcat FROM ls_fcat
**    TRANSPORTING edit
**    WHERE ( key NE 'X' ).


ENDFORM.                    " BUILD_FIELDCATALOG_KNB1


*&---------------------------------------------------------------------*
*&      Form  SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM set_layout_and_variant .

  CLEAR: gs_layout,
         gs_variant.

  gs_variant-report = syst-repid.
  gs_variant-handle = 'GRID'.

  gs_layout-cwidth_opt = abap_true.
  gs_layout-stylefname = 'CELLTAB'.
  gs_layout-edit        = abap_true.  " entire grid editable
ENDFORM.                    " SET_LAYOUT_AND_VARIANT


*&---------------------------------------------------------------------*
*&      Form  INIT_CONTROLS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM init_controls .

* Create docking container
  CREATE OBJECT go_docking
    EXPORTING
      parent = cl_gui_container=>screen0
      ratio  = 90
    EXCEPTIONS
      OTHERS = 6.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* Create ALV grid
  CREATE OBJECT go_grid
    EXPORTING
      i_parent = go_docking
    EXCEPTIONS
      OTHERS   = 5.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* Build fieldcatalog and set hotspot for field KUNNR
  PERFORM build_fieldcatalog_knb1.
  PERFORM set_layout_and_variant.

  PERFORM set_editable_at_cell_level.



* Display data
  CALL METHOD go_grid->set_table_for_first_display
    EXPORTING
      i_save          = 'A'
      is_variant      = gs_variant
      is_layout       = gs_layout
    CHANGING
      it_outtab       = gt_outtab
      it_fieldcatalog = gt_fcat
    EXCEPTIONS
      OTHERS          = 4.
  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.                    " INIT_CONTROLS


*&---------------------------------------------------------------------*
*&      Form  delete_rows
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM delete_rows .
* define local data
  DATA: ls_row    TYPE lvc_s_row.

  SORT lcl_eventhandler=>mt_sel_rows BY index DESCENDING. " !!!


  LOOP AT lcl_eventhandler=>mt_sel_rows INTO ls_row.
    DELETE gt_outtab INDEX ls_row-index.
  ENDLOOP.

  " After deleting rows do RE-CALCULATION
*  perform RECALCULATION.

ENDFORM.                    " delete_rows


*&---------------------------------------------------------------------*
*&      Form  COPY_ROWS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM copy_rows .
* define local data
  DATA: ld_next   TYPE i,
        ls_row    TYPE lvc_s_row,
        ls_outtab TYPE ty_s_outtab.


  SORT lcl_eventhandler=>mt_sel_rows BY index DESCENDING. " !!!

  LOOP AT lcl_eventhandler=>mt_sel_rows INTO ls_row.
    READ TABLE gt_outtab INTO ls_outtab INDEX ls_row-index.

    ls_outtab-celltab = gt_celltab.

    CLEAR: ls_outtab-akont. " In your case: clear GUID
    ld_next = ls_row-index + 1.
    INSERT ls_outtab INTO gt_outtab INDEX ld_next.
  ENDLOOP.

ENDFORM.                    " COPY_ROWS


*&---------------------------------------------------------------------*
*&      Form  INSERT_ROW
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM insert_row .
* define local data
  DATA: ld_value1  TYPE spop-varvalue1,
        ls_outtab  TYPE ty_s_outtab.

  CALL FUNCTION 'POPUP_TO_GET_ONE_VALUE'
    EXPORTING
      textline1            = 'Enter Value (4 Chars):'
*     TEXTLINE2            = ' '
*     TEXTLINE3            = ' '
      titel                = 'Enter Value'
      valuelength          = 4
    IMPORTING
*     ANSWER               =
      value1               = ld_value1
    EXCEPTIONS
      titel_too_long       = 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.

  ls_outtab-kunnr = ld_value1.
  ls_outtab-bukrs = ld_value1.

  ls_outtab-celltab = gt_celltab.

  APPEND ls_outtab TO gt_outtab.



ENDFORM.                    " INSERT_ROW

*&---------------------------------------------------------------------*
*&      Form  SET_EDITABLE_AT_CELL_LEVEL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM set_editable_at_cell_level .
* define local data
  DATA: ls_fcat     TYPE lvc_s_fcat,
        ls_cell     TYPE lvc_s_styl,
        ls_outtab   type ty_s_outtab.


  REFRESH: gt_celltab.
  LOOP AT gt_fcat INTO ls_fcat.
    ls_cell-fieldname = ls_fcat-fieldname.
    ls_cell-style = cl_gui_alv_grid=>mc_style_disabled.

    CASE ls_fcat-fieldname.
      WHEN 'ERDAT'  OR
           'ERNAM'.
        ls_cell-style = cl_gui_alv_grid=>mc_style_enabled.

      WHEN OTHERS.
    ENDCASE.

    INSERT ls_cell INTO TABLE gt_celltab.
  ENDLOOP.

  ls_outtab-celltab = gt_celltab.
  modify gt_outtab from ls_outtab
    TRANSPORTING celltab
    where ( table_line is not initial ).

ENDFORM.                    " SET_EDITABLE_AT_CELL_LEVEL

Regards

Uwe

Read only

0 Likes
679

can you give me some lead how to update field catalog during runtime

Read only

Former Member
0 Likes
679

Thanks