Skip to Content
0

How to display Custom Field catalog in OOPS ALV Docking container using of LVC_fieldcatalog_merge

Dec 28, 2016 at 06:10 AM

246

avatar image

Hi Friends,

I am working on Oops_ALV with docking container FM, but I want to generate automatic Custom field catalog using of LVC_field catalog_merge FM, but it's displaying all fields of table in output instead of my giving custom field catalog.

Please find below code and screenshot
*&---------------------------------------------------------------------*
*& Report  ZOOPS_ALV_TWO_SCREEN
*&

REPORT  ZOOPS_ALV_TWO_SCREEN.
TABLES: mara, marc.
TYPES: BEGIN OF ty_mara,
       matnr TYPE mara-matnr,
       ersda TYPE mara-ersda,
       ernam TYPE mara-ernam,
       mtart TYPE mara-mtart,
       matkl TYPE mara-matkl,
       meins TYPE mara-meins,
      end of ty_mara.

TYPES: BEGIN OF ty_marc,
       matnr TYPE marc-matnr,
       werks TYPE marc-werks,
       ekgrp TYPE marc-ekgrp,
       basmg TYPE marc-basmg,
       strgr TYPE marc-strgr,
end of ty_marc.


DATA: o_docking TYPE REF TO cl_gui_docking_container,
      o_grid TYPE REF TO cl_gui_alv_grid,

      o_docking1 TYPE REF TO cl_gui_docking_container,
      o_grid1 TYPE REF TO cl_gui_alv_grid,

*      it_fcat_mara TYPE STANDARD TABLE OF lvc_s_fcat,
       it_fcat_mara TYPE lvc_t_fcat,
       wa_fcat_mara TYPE lvc_s_fcat,
*      it_fcat_marc TYPE STANDARD TABLE OF lvc_s_fcat,
       it_fcat_marc TYPE lvc_t_fcat,
       wa_fcat_marc TYPE lvc_s_fcat,

       wa_layo TYPE lvc_s_layo,

      it_mara TYPE TABLE OF ty_mara,
      it_marc TYPE TABLE OF ty_marc,
      wa_mara TYPE  ty_mara,
      wa_marc TYPE ty_marc,

      w_variant TYPE disvariant.

SELECT-OPTIONS: s_matnr FOR mara-matnr no-EXTENSION.

START-OF-SELECTION.
  SELECT
        matnr ersda
        ernam mtart
        matkl meins FROM mara into CORRESPONDING FIELDS OF TABLE it_mara
                              WHERE matnr in s_matnr.

  if it_mara is NOT INITIAL.
    SELECT
          matnr werks
          ekgrp basmg
          strgr FROM marc INTO CORRESPONDING FIELDS OF TABLE it_marc
          FOR ALL ENTRIES IN it_mara
          WHERE matnr = it_mara-matnr.
  endif.

  call SCREEN 1004.

*----------------------------------------------------------------------*
*  MODULE status_1004 OUTPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE status_1004 OUTPUT.
  set PF-STATUS 'ZSP'.
*  set TITLEBAR 'MATERIAL'.
  PERFORM populate_cat USING 'MATNR' 'MATERIAL'.
  PERFORM populate_cat USING 'ERSDA' 'DATE'.
  PERFORM populate_cat USING 'ERNAM' 'NAME'.
  PERFORM populate_cat USING 'MTART' 'MAT TYPE'.
  PERFORM populate_cat USING 'MATKL' 'MAT DESC'.
  PERFORM populate_cat USING 'MEINS' 'AMOUNT'.

  PERFORM populate_cat1 USING 'MATNR' 'MATERIAL'.
  PERFORM populate_cat1 USING 'WERKS' 'PLANT'.
  PERFORM populate_cat1 USING 'EKGRP' 'PO GRP'.
  PERFORM populate_cat1 USING 'BASMG' 'iii'.
  PERFORM populate_cat1 USING 'STRGR' 'iii'.


  CREATE OBJECT O_DOCKING
    EXPORTING
    RATIO                       = 40
    REPID                       = SY-REPID
    DYNNR                       = '1004'
*    SIDE                        = CL_GUI_DOCKING_CONTAINER=>DOCK_AT_LEFT
    name                        = 'O_DOCKING'
    EXTENSION                   = 100.

  CREATE OBJECT O_GRID
      EXPORTING
        I_PARENT          =  O_DOCKING
       EXCEPTIONS
         ERROR_CNTL_CREATE = 1
         ERROR_CNTL_INIT   = 2
         ERROR_CNTL_LINK   = 3
         ERROR_DP_CREATE   = 4
         others            = 5
        .

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
   EXPORTING
*     I_BUFFER_ACTIVE              =
      I_STRUCTURE_NAME             = 'MARA'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_BYPASSING_BUFFER           =
*     I_INTERNAL_TABNAME           =  'IT_MARA'
    CHANGING
      CT_FIELDCAT                  =  IT_FCAT_MARA.


      wa_layo-cwidth_opt = 'X'.
      wa_layo-zebra = 'X'.
      wa_layo-grid_title = 'Material data'.

       w_variant-report = sy-repid.

      CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
       EXPORTING
          IS_VARIANT                     = w_variant
           I_SAVE                        = 'X'
         IS_LAYOUT                      = wa_layo
*         I_STRUCTURE_NAME             = 'MARA'
         CHANGING
          IT_OUTTAB                     = IT_MARA
          IT_FIELDCATALOG               = IT_FCAT_MARA.

CREATE OBJECT O_DOCKING1
   EXPORTING
    RATIO                       = 40
    REPID                       = SY-REPID
    DYNNR                       = '1004'
*   SIDE                        = CL_GUI_DOCKING_CONTAINER=>DOCK_AT_RIGHT
    EXTENSION                   = 120.

  CREATE OBJECT O_GRID1
    EXPORTING
      I_PARENT            =  O_DOCKING1.


    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
      EXPORTING
        I_STRUCTURE_NAME       = 'MARC'
      CHANGING
        CT_FIELDCAT            = IT_FCAT_MARC.

        w_variant-report = sy-repid.

      CALL METHOD O_GRID1->SET_TABLE_FOR_FIRST_DISPLAY
         EXPORTING
             IS_VARIANT                    = w_variant
             I_SAVE                        = 'X'
            IS_LAYOUT                      =  wa_layo
          CHANGING
           IT_OUTTAB                      = IT_MARC
           IT_FIELDCATALOG                = IT_FCAT_MARC.

endmodule.              "status_1004 OUTPUT




*----------------------------------------------------------------------*
*  MODULE USER_COMMAND_1004 INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE USER_COMMAND_1004 INPUT.
  data: lv_ucomm TYPE sy-ucomm.
  lv_ucomm = sy-ucomm.

  CASE lv_ucomm.
    WHEN 'CANCEL' OR 'EXIT'.
            PERFORM free_objects.
      LEAVE PROGRAM.
    WHEN 'BACK'.
            PERFORM free_objects.
      set SCREEN 0.
      LEAVE SCREEN.
  ENDCASE.
endmodule.                    "USER_COMMAND_1004 INPUT
*&---------------------------------------------------------------------*
*&      Form  free_objects
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM free_objects .
CALL METHOD O_GRID->FREE.
CALL METHOD O_DOCKING->FREE.
CALL METHOD O_GRID1->FREE.
CALL METHOD O_DOCKING1->FREE.

ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  populate_cat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0198   text
*      -->P_0199   text
*----------------------------------------------------------------------*
FORM populate_cat  USING    VALUE(A)
                            VALUE(B).
   wa_fcat_mara-fieldname = A.
   wa_fcat_mara-tabname   = 'IT_MARA'.
   wa_fcat_mara-coltext = B.
   APPEND wa_fcat_mara to it_fcat_mara.
CLEAR: it_fcat_mara.
ENDFORM.                    " populate_cat
***&---------------------------------------------------------------------*
***&      Form  populate_cat1
***&---------------------------------------------------------------------*
***       text
***----------------------------------------------------------------------*
***      -->P_0228   text
***      -->P_0229   text
***----------------------------------------------------------------------*
FORM populate_cat1  USING    VALUE(A)
                             VALUE(B).
   wa_fcat_marc-fieldname = A.
   wa_fcat_marc-tabname   = 'IT_MARA'.
   wa_fcat_marc-coltext = B.
   APPEND wa_fcat_marc to it_fcat_marc.

CLEAR: it_fcat_marc.

ENDFORM.             " populate_cat1



Thanks and Regards

Sandeepoops-alv-output.png

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Raymond Giuseppi
Jan 02, 2017 at 09:48 AM
0

The LVC merge FM override your catalog with the whole table definition, don't call it if not required.

Also I would suggest you fill the handle or log_group field of the variant parameter to 'segregate' both ALV for catalog, variants, etc. and you manually fill the field catalog with ddic info, so use fieldname, ref_table = 'MARA' or 'MARC', ref_field = fieldname.

Regards,
Raymond

Share
10 |10000 characters needed characters left characters exceeded
Chaouki AKIR Jan 02, 2017 at 08:13 PM
0

Also, in the routine, populate_cat1, remove the instruction :

CLEAR: it_fcat_marc.

Replace it with :

CLEAR: wa_fcat_marc.

Do the same in routine populate_cat, remove the instruction :

CLEAR: it_fcat_mara.

Replace it with :

CLEAR wa_fcat_marc.

BàT,

Chaouki

Share
10 |10000 characters needed characters left characters exceeded