Wednesday, April 25, 2012

BLOCKED ALV :

Here is a code to implement Blocked ALV display. I hope this code will help u.


*&---------------------------------------------------------------------*
*& Report  ZALV_BLOCKED
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZALV_BLOCKED.

include ZALV_BLOCKED_TOP.
include ZALV_BLOCKED_SEL.
include ZALV_BLOCKED_SUB.

INITIALIZATION.

PERFORM LIST_INIT.

START-OF-SELECTION.

PERFORM FETCH_MARD CHANGING I_MARD.

PERFORM FETCH_MARC USING I_MARD CHANGING I_MARC.

PERFORM FETCH_MARA USING I_MARD CHANGING I_MARA.

PERFORM BUILD_FIELDCAT1 CHANGING I_FIELDCAT.

PERFORM BUILD_FIELDCAT2 CHANGING I_FIELDCAT1.

PERFORM BUILD_FIELDCAT3 CHANGING I_FIELDCAT2.

PERFORM DISPLAY_MARA USING I_MARA.

PERFORM DISPLAY_MARC USING I_MARC.

PERFORM DISPLAY_MARD USING I_MARD.

PERFORM DISPLAY_BLOCK.


TYPE-POOLS : SLIS.

TYPES : BEGIN OF TY_MARA,
        MATNR TYPE MATNR,
        MTART TYPE MTART,
        MBRSH TYPE MBRSH,
        MATKL TYPE MATKL,
        END OF TY_MARA,
      TY_T_MARA TYPE STANDARD TABLE OF TY_MARA,
        BEGIN OF TY_MARC,
          MATNR TYPE MATNR,
          WERKS TYPE WERKS_D,
          EKGRP TYPE EKGRP,
        END OF TY_MARC,
      TY_T_MARC TYPE STANDARD TABLE OF TY_MARC,
        BEGIN OF TY_MARD,
          MATNR TYPE MATNR,
          WERKS TYPE WERKS_D,
          LGORT TYPE LGORT_D,
          LABST TYPE LABST,
        END OF TY_MARD,
      TY_T_MARD TYPE STANDARD TABLE OF TY_MARD.

DATA : I_MARA TYPE TY_T_MARA,
       I_MARC TYPE TY_T_MARC,
       I_MARD TYPE TY_T_MARD.

DATA : GV_MATNR TYPE MATNR.

DATA : I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
       I_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV,
       I_FIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV.

DATA: I_EVENTS TYPE SLIS_T_EVENT,
      W_EVENT TYPE SLIS_ALV_EVENT.

DATA : I_LAYOUT TYPE SLIS_LAYOUT_ALV.


*&---------------------------------------------------------------------*
*&  Include           ZALV_BLOCKED_SEL
*&---------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

  SELECT-OPTIONS : S_MATNR FOR GV_MATNR.

SELECTION-SCREEN END OF BLOCK B1.


*&---------------------------------------------------------------------*
*&  Include           ZALV_BLOCKED_SUB
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  FETCH_MARA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_I_MARA  text
*----------------------------------------------------------------------*
FORM FETCH_MARA USING FP_I_MARD TYPE TY_T_MARD
                CHANGING FP_I_MARA TYPE TY_T_MARA.

IF NOT FP_I_MARD IS INITIAL.
SELECT MATNR
       MTART
       MBRSH
       MATKL
  INTO TABLE FP_I_MARA
  FROM MARA
  FOR ALL ENTRIES IN FP_I_MARD
  WHERE MATNR = FP_I_MARD-MATNR.

ENDIF.

ENDFORM. " FETCH_MARA
*&---------------------------------------------------------------------*
*&      Form  FETCH_MARC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_MARA  text
*      <--P_I_MARC  text
*----------------------------------------------------------------------*
FORM FETCH_MARC USING FP_I_MARD TYPE TY_T_MARD
                 CHANGING FP_I_MARC TYPE TY_T_MARC.

  IF NOT FP_I_MARD IS INITIAL.
    SELECT MATNR
           WERKS
           EKGRP
      INTO TABLE FP_I_MARC
      FROM MARC
      FOR ALL ENTRIES IN FP_I_MARD
      WHERE MATNR = FP_I_MARD-MATNR.
  ENDIF.

ENDFORM. " FETCH_MARC
*&---------------------------------------------------------------------*
*&      Form  FETCH_MARD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_I_MARD  text
*      <--P_PERFORM  text
*      <--P_FETCH_MARA  text
*      <--P_I_MARA  text
*----------------------------------------------------------------------*
FORM FETCH_MARD CHANGING FP_I_MARD TYPE TY_T_MARD.

  SELECT MATNR
         WERKS
         LGORT
         LABST
    INTO TABLE FP_I_MARD
    FROM MARD
    WHERE MATNR IN S_MATNR.

ENDFORM. " FETCH_MARD
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_I_FIELDCAT  text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT1 CHANGING FP_I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

  DATA : W_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

w_fieldcat-col_pos = 1.
w_fieldcat-tabname = 'ty_t_mara'.
w_fieldcat-fieldname = 'MATNR'.
w_fieldcat-seltext_m = 'MATERIAL NUMBER'.

append w_fieldcat to i_fieldcat.
clear w_fieldcat.

w_fieldcat-col_pos = 2.
w_fieldcat-tabname = 'ty_t_final'.
w_fieldcat-fieldname = 'MTART'.
w_fieldcat-seltext_m = 'MATERIAL TYPE'.

append w_fieldcat to i_fieldcat.
clear w_fieldcat.

w_fieldcat-col_pos = 3.
w_fieldcat-tabname = 'ty_t_final'.
w_fieldcat-fieldname = 'MBRSH'.
w_fieldcat-seltext_m = 'INDUSTRY SECTOR'.

append w_fieldcat to i_fieldcat.
clear w_fieldcat.

w_fieldcat-col_pos = 4.
w_fieldcat-tabname = 'ty_t_final'.
w_fieldcat-fieldname = 'MATKL'.
w_fieldcat-seltext_m = 'MATERIAL GROUP'.

append w_fieldcat to i_fieldcat.
clear w_fieldcat.

ENDFORM. " BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_I_FIELDCAT1  text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT2 CHANGING FP_I_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV.

  DATA : W1_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

w1_fieldcat-tabname = 'ty_t_marc'.
w1_fieldcat-fieldname = 'MATNR'.
w1_fieldcat-seltext_m = 'MATERIAL NUMBER'.

append w1_fieldcat to i_fieldcat1.
clear w1_fieldcat.

w1_fieldcat-tabname = 'ty_t_marc'.
w1_fieldcat-fieldname = 'WERKS'.
w1_fieldcat-seltext_m = 'PLANT'.

append w1_fieldcat to i_fieldcat1.
clear w1_fieldcat.

w1_fieldcat-tabname = 'ty_t_marc'.
w1_fieldcat-fieldname = 'EKGRP'.
w1_fieldcat-seltext_m = 'PURCHASING GROUP'.

append w1_fieldcat to i_fieldcat1.
clear w1_fieldcat.

ENDFORM. " BUILD_FIELDCAT2
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT3
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_I_FIELDCAT2  text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT3 CHANGING FP_I_FIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV.

  DATA : W2_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

w2_fieldcat-tabname = 'ty_t_mard'.
w2_fieldcat-fieldname = 'MATNR'.
w2_fieldcat-seltext_m = 'MATERIAL NUMBER'.

append w2_fieldcat to i_fieldcat2.
clear w2_fieldcat.

w2_fieldcat-tabname = 'ty_t_mard'.
w2_fieldcat-fieldname = 'WERKS'.
w2_fieldcat-seltext_m = 'PLANT'.

append w2_fieldcat to i_fieldcat2.
clear w2_fieldcat.

w2_fieldcat-tabname = 'ty_t_mard'.
w2_fieldcat-fieldname = 'LGORT'.
w2_fieldcat-seltext_m = 'STORAGE LOCATION'.

append w2_fieldcat to i_fieldcat2.
clear w2_fieldcat.

w2_fieldcat-tabname = 'ty_t_mard'.
w2_fieldcat-fieldname = 'LABST'.
w2_fieldcat-seltext_m = 'VALUATED STOCK'.

append w2_fieldcat to i_fieldcat2.
clear w2_fieldcat.

ENDFORM. " BUILD_FIELDCAT3
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_MARA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_MARA  text
*----------------------------------------------------------------------*
FORM DISPLAY_MARA USING FP_I_MARA TYPE TY_T_MARA.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
  EXPORTING
    IS_LAYOUT                        = I_LAYOUT
    IT_FIELDCAT                      = I_FIELDCAT
    I_TABNAME                        = 'MARA'
    IT_EVENTS                        = I_EVENTS
*   IT_SORT                          =
*   I_TEXT                           = ' '
  TABLES
    T_OUTTAB                         = FP_I_MARA
* EXCEPTIONS
*   PROGRAM_ERROR                    = 1
*   MAXIMUM_OF_APPENDS_REACHED       = 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.


ENDFORM. " DISPLAY_MARA
*&---------------------------------------------------------------------*
*&      Form  LIST_INIT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM LIST_INIT .

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
  EXPORTING
    I_CALLBACK_PROGRAM             = SY-REPID
*   I_CALLBACK_PF_STATUS_SET       = ' '
*   I_CALLBACK_USER_COMMAND        = ' '
*   IT_EXCLUDING                   =
          .


ENDFORM. " LIST_INIT
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_MARC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_MARC  text
*----------------------------------------------------------------------*
FORM DISPLAY_MARC USING FP_I_MARC TYPE TY_T_MARC.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
    EXPORTING
      IS_LAYOUT                        = I_LAYOUT
      IT_FIELDCAT                      = I_FIELDCAT1
      I_TABNAME                        = 'MARC'
      IT_EVENTS                        = I_EVENTS
*     IT_SORT                          =
*     I_TEXT                           = ' '
    TABLES
      T_OUTTAB                         = FP_I_MARC
*   EXCEPTIONS
*     PROGRAM_ERROR                    = 1
*     MAXIMUM_OF_APPENDS_REACHED       = 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.


ENDFORM. " DISPLAY_MARC
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_MARD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_MARD  text
*----------------------------------------------------------------------*
FORM DISPLAY_MARD USING FP_I_MARD TYPE TY_T_MARD.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
  EXPORTING
    IS_LAYOUT                        = I_LAYOUT
    IT_FIELDCAT                      = I_FIELDCAT2
    I_TABNAME                        = 'MARD'
    IT_EVENTS                        = I_EVENTS
*   IT_SORT                          =
*   I_TEXT                           = ' '
  TABLES
    T_OUTTAB                         = FP_I_MARD
* EXCEPTIONS
*   PROGRAM_ERROR                    = 1
*   MAXIMUM_OF_APPENDS_REACHED       = 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.


ENDFORM. " DISPLAY_MARD
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_BLOCK
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY_BLOCK .

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
* EXPORTING
*   I_INTERFACE_CHECK             = ' '
*   IS_PRINT                      =
*   I_SCREEN_START_COLUMN         = 0
*   I_SCREEN_START_LINE           = 0
*   I_SCREEN_END_COLUMN           = 0
*   I_SCREEN_END_LINE             = 0
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER       =
*   ES_EXIT_CAUSED_BY_USER        =
* 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.


ENDFORM. " DISPLAY_BLOCK

No comments:

Post a Comment