Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

OOPS ALV help needed

Hi guruji's,

I have to develop an ALV report using oops, so that it would contain a selection screen of MATNR , POSNR , and ADNRK, and i am using mast, makt, stpo table, also i need to give different color to the cells depending on MATNR.

The third one is i have to print a comany logo, in the title bar,

also there must be a way to to change the grid layout, means the size of the cells, and the size of the header. Can somebody give me the exact code for this?

Tags:
Former Member
Former Member replied

Following report is the sample report for OOPS Alv report.

type-pools : slis.
include <icon>.
TABLES : EKKO,EKPO,MAKT.
 
DATA : BEGIN OF IEKKO OCCURS 0,
       EBELN LIKE EKKO-EBELN,
       AEDAT LIKE EKKO-AEDAT,
       BEDAT LIKE EKKO-BEDAT,
       END OF IEKKO.
 
DATA : BEGIN OF IEKPO OCCURS 0,
       EBELN LIKE EKPO-EBELN,
       EBELP LIKE EKPO-EBELP,
       MATNR LIKE EKPO-MATNR,
       MENGE LIKE EKPO-MENGE,
       END OF IEKPO.
 
DATA : BEGIN OF IMAKT OCCURS 0,
       MATNR LIKE MAKT-MATNR,
       MAKTX LIKE MAKT-MAKTX,
       END OF IMAKT.
 
DATA : BEGIN OF IFINAL OCCURS 0,
       BOX,
       EBELN LIKE EKKO-EBELN,
       EBELP LIKE EKPO-EBELP,
       AEDAT LIKE EKKO-AEDAT,
       BEDAT LIKE EKKO-BEDAT,
       MATNR LIKE EKPO-MATNR,
       MENGE LIKE EKPO-MENGE,
       MAKTX LIKE MAKT-MAKTX,
       END OF IFINAL.
*DATA : IFINALFUL LIKE STANDARD TABLE OF
DATA : OKCODE LIKE SY-UCOMM,
       CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
       GRID TYPE REF TO CL_GUI_ALV_GRID,
       text TYPE sdydo_text_element,
       o_dd_doc TYPE REF TO cl_dd_document,
       o_top type ref to cl_gui_container,
       split1 type ref to cl_gui_easy_splitter_container.
 
data : split type ref to cl_gui_splitter_container,
       contaner1 type ref to cl_gui_container,
       contaner2 type ref to cl_gui_container,
       contaner3 type ref to cl_gui_container,
       contaner4 type ref to cl_gui_container,
       grid2     type ref to cl_gui_alv_grid.
 
 
 
CLASS lcl_event_receiver DEFINITION DEFERRED.
 
DATA: o_event_receiver TYPE REF TO lcl_event_receiver.
 
DATA : IFIELDCAT TYPE LVC_T_FCAT,
       WFIELDCAT TYPE LVC_S_FCAT,
       ILAYOUT   TYPE LVC_S_LAYO,
       ISORT     TYPE LVC_T_SORT,
       WSORT     TYPE LVC_S_SORT.
 
data : ilist type slis_t_listheader,
       wlist type slis_listheader.
 
SELECT-OPTIONS : S_AEDAT FOR EKKO-AEDAT.
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_top_of_page FOR EVENT top_of_page OF cl_gui_alv_grid
IMPORTING e_dyndoc_id,
handle_user_command for event user_command of cl_gui_alv_grid importing e_ucomm,
handle_toolbar for event toolbar of cl_gui_alv_grid importing e_object e_interactive.
ENDCLASS.
 
 
CLASS lcl_event_receiver IMPLEMENTATION.
 
METHOD handle_top_of_page.
 
text = 'Test Top of page'.
 
CALL METHOD e_dyndoc_id->add_text
EXPORTING text = text
sap_fontsize = 'LARGE'
sap_color   = 'LIST_KEY_INV'
*sap_fontstyle = 'LIST_HEADING'
*sap_style = 'HEADING'
.
 
CALL METHOD E_DYNDOC_ID->UNDERLINE
    .
 
CALL METHOD E_DYNDOC_ID->NEW_LINE
*  EXPORTING
*    REPEAT =
    .
 
clear text.
text = 'Test Top of page 2nd line & space'.
 
CALL METHOD e_dyndoc_id->add_text
EXPORTING text = text
sap_fontsize = 'LARGE'
sap_color   = 'LIST_KEY_INV'.
 
CALL METHOD e_dyndoc_id->display_document
EXPORTING parent = CONTANER3.
 
 
ENDMETHOD. "handle_top_of_page
 
method handle_user_command.
 case e_ucomm.
 when 'DETAIL'.
   DATA : LT_ROWS TYPE LVC_T_ROW.
   CALL METHOD GRID->GET_SELECTED_ROWS
     IMPORTING
       ET_INDEX_ROWS = LT_ROWS
*       ET_ROW_NO     =
       .
   IF SY-SUBRC NE 0.
     CALL FUNCTION 'POPUP_TO_INFORM'
       EXPORTING
         TITEL         = 'Message'
         TXT1          = 'Please choose a row'
         TXT2          = ''
*        TXT3          = ' '
*        TXT4          = ' '
               .
 
   ENDIF.
  endcase.
endmethod.
 
method handle_toolbar.
data : wtoolbar type stb_button.
clear wtoolbar.
wtoolbar-butn_type = 3.
append wtoolbar to e_object->mt_toolbar.
clear wtoolbar.
wtoolbar-function = 'DETAIL'.
wtoolbar-ICON = ICON_OVERVIEW.
wtoolbar-QUICKINFO = 'Detail list'.
wtoolbar-TEXT = 'Detail list'.
append wtoolbar to e_object->mt_toolbar.
endmethod.
 
ENDCLASS. "lcl_application_f4 IMPLEMENTATION
 
 
 
START-OF-SELECTION.
  PERFORM FILL_EKKO.
  PERFORM FILL_EKPO.
  PERFORM FILL_MAKT.
  PERFORM BUILD_FINALTAB.
  PERFORM BUILD_FIELDCAT.
  PERFORM BUILD_SORT.
  PERFORM BUILD_LAYOUT.
  CALL SCREEN 100.
*&---------------------------------------------------------------------*
*&      Form  fill_ekko
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FILL_EKKO .
  SELECT EBELN AEDAT BEDAT INTO TABLE IEKKO FROM EKKO WHERE AEDAT IN S_AEDAT.
ENDFORM.                    " fill_ekko
*&---------------------------------------------------------------------*
*&      Form  fill_ekpo
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FILL_EKPO .
  IF NOT IEKKO[] IS INITIAL.
    SELECT EBELN EBELP MATNR MENGE INTO TABLE IEKPO FROM EKPO FOR ALL ENTRIES IN IEKKO
                                        WHERE EBELN = IEKKO-EBELN.
  ENDIF.
ENDFORM.                    " fill_ekpo
*&---------------------------------------------------------------------*
*&      Form  fill_makt
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FILL_MAKT .
  IF NOT IEKPO[] IS INITIAL.
    SELECT MATNR MAKTX FROM MAKT INTO TABLE IMAKT FOR ALL ENTRIES IN IEKPO WHERE
                                                  MATNR = IEKPO-MATNR.
  ENDIF.
ENDFORM.                    " fill_makt
*&---------------------------------------------------------------------*
*&      Form  BUILD_FINALTAB
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BUILD_FINALTAB .
LOOP AT IEKPO.
  IFINAL-MATNR = IEKPO-MATNR.
  IFINAL-MENGE = IEKPO-MENGE.
  IFINAL-EBELP = IEKPO-EBELP.
  IFINAL-EBELN = IEKPO-EBELN.
  READ TABLE IEKKO WITH KEY EBELN = IEKPO-EBELN.
   IF SY-SUBRC = 0.
     IFINAL-AEDAT = IEKKO-AEDAT.
     IFINAL-BEDAT = IEKKO-BEDAT.
   ENDIF.
  READ TABLE IMAKT WITH KEY MATNR = IEKPO-MATNR.
   IF SY-SUBRC = 0.
    IFINAL-MAKTX = IMAKT-MAKTX.
   ENDIF.
  APPEND IFINAL.
  CLEAR : IFINAL,IEKKO,IMAKT,IEKPO.
ENDLOOP.
ENDFORM.                    " BUILD_FINALTAB
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT .
WFIELDCAT-FIELDNAME = 'EBELN'.
WFIELDCAT-COL_POS   = 1.
WFIELDCAT-OUTPUTLEN = 10.
WFIELDCAT-COLTEXT   = 'Document No'.
APPEND WFIELDCAT TO IFIELDCAT.
CLEAR WFIELDCAT.
 
WFIELDCAT-FIELDNAME = 'EBELP'.
WFIELDCAT-COL_POS   = 2.
WFIELDCAT-OUTPUTLEN = 5.
WFIELDCAT-COLTEXT   = 'Item No'.
APPEND WFIELDCAT TO IFIELDCAT.
CLEAR WFIELDCAT.
 
WFIELDCAT-FIELDNAME = 'AEDAT'.
WFIELDCAT-COL_POS   = 3.
WFIELDCAT-OUTPUTLEN = 8.
WFIELDCAT-COLTEXT   = 'Creatn dat'.
APPEND WFIELDCAT TO IFIELDCAT.
CLEAR WFIELDCAT.
 
WFIELDCAT-FIELDNAME = 'BEDAT'.
WFIELDCAT-COL_POS   = 4.
WFIELDCAT-OUTPUTLEN = 8.
WFIELDCAT-COLTEXT   = 'Delv dat'.
APPEND WFIELDCAT TO IFIELDCAT.
CLEAR WFIELDCAT.
 
WFIELDCAT-FIELDNAME = 'MATNR'.
WFIELDCAT-COL_POS   = 5.
WFIELDCAT-OUTPUTLEN = 18.
WFIELDCAT-COLTEXT   = 'Material no'.
APPEND WFIELDCAT TO IFIELDCAT.
CLEAR WFIELDCAT.
 
WFIELDCAT-FIELDNAME = 'MAKTX'.
WFIELDCAT-COL_POS   = 6.
WFIELDCAT-OUTPUTLEN = 32.
WFIELDCAT-COLTEXT   = 'Material desc.'.
APPEND WFIELDCAT TO IFIELDCAT.
CLEAR WFIELDCAT.
 
WFIELDCAT-FIELDNAME = 'MENGE'.
WFIELDCAT-COL_POS   = 7.
WFIELDCAT-OUTPUTLEN = 16.
wfieldcat-just      = 'L'.
WFIELDCAT-COLTEXT   = 'Quantity'.
WFIELDCAT-DO_SUM = 'X'.
APPEND WFIELDCAT TO IFIELDCAT.
CLEAR WFIELDCAT.
 
 
ENDFORM.                    " BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  BUILD_SORT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BUILD_SORT .
WSORT-FIELDNAME = 'EBELN'.
WSORT-SPOS = 1.
WSORT-UP = 'X'.
WSORT-GROUP = 'UL'.
WSORT-SUBTOT = 'X'.
APPEND WSORT TO ISORT.
ENDFORM.                    " BUILD_SORT
*&---------------------------------------------------------------------*
*&      Module  PBO  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE PBO OUTPUT.
SET PF-STATUS 'ZSPD'.
    CREATE OBJECT CONTAINER
      EXPORTING
*        PARENT                      =
        CONTAINER_NAME              = 'CONTAINER'
*        STYLE                       =
*        LIFETIME                    = lifetime_default
*        REPID                       =
*        DYNNR                       =
*        NO_AUTODEF_PROGID_DYNNR     =
      EXCEPTIONS
        CNTL_ERROR                  = 1
        CNTL_SYSTEM_ERROR           = 2
        CREATE_ERROR                = 3
        LIFETIME_ERROR              = 4
        LIFETIME_DYNPRO_DYNPRO_LINK = 5
        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 OBJECT SPLIT
  EXPORTING
*    LINK_DYNNR        =
*    LINK_REPID        =
*    SHELLSTYLE        =
*    LEFT              =
*    TOP               = 3
*    WIDTH             = 5
*    HEIGHT            = 3
*    METRIC            = cntl_metric_dynpro
*    ALIGN             = 15
    PARENT            = container
    ROWS              = 1
    COLUMNS           = 1
*    NO_AUTODEF_PROGID_DYNNR =
*    NAME              =
  EXCEPTIONS
    CNTL_ERROR        = 1
    CNTL_SYSTEM_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.
 
CALL METHOD split->set_border
EXPORTING
border = space.
 
CALL METHOD split->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = contaner1.
 
CALL METHOD split->set_row_height
EXPORTING
id = 1
height = 1
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3 .
 
CREATE OBJECT split1
EXPORTING
parent = contaner1
SASH_POSITION     = 15
with_border = 1
EXCEPTIONS
cntl_error = 1
cntl_system_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.
 
contaner3 = split1->top_left_container.
contaner4 = split1->bottom_right_container.
 
*contaner3 = container->SCREEN0. "DEFAULT_SCREEN." PARENT.
 
CREATE OBJECT GRID
  EXPORTING
*    I_SHELLSTYLE      = 0
*    I_LIFETIME        =
    I_PARENT          = CONTANER4
*    I_APPL_EVENTS     = space
*    I_PARENTDBG       =
*    I_APPLOGPARENT    =
*    I_GRAPHICSPARENT  =
*    I_NAME            =
  EXCEPTIONS
    ERROR_CNTL_CREATE = 1
    ERROR_CNTL_INIT   = 2
    ERROR_CNTL_LINK   = 3
    ERROR_DP_CREATE   = 4
    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.
 
CREATE OBJECT o_event_receiver.
SET HANDLER o_event_receiver->handle_top_of_page FOR GRID.
set handler o_event_receiver->handle_user_command for grid.
set handler o_event_receiver->handle_toolbar for grid.
 
CREATE OBJECT o_dd_doc EXPORTING style = 'ALV_GRID'
no_margins = 'X'.
 
 
CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
  EXPORTING
*    I_BUFFER_ACTIVE               =
*    I_BYPASSING_BUFFER            =
*    I_CONSISTENCY_CHECK           =
*    I_STRUCTURE_NAME              =
*    IS_VARIANT                    =
*    I_SAVE                        =
*    I_DEFAULT                     = 'X'
    IS_LAYOUT                     = ILAYOUT
*    IS_PRINT                      =
*    IT_SPECIAL_GROUPS             =
*    IT_TOOLBAR_EXCLUDING          =
*    IT_HYPERLINK                  =
*    IT_ALV_GRAPHICS               =
*    IT_EXCEPT_QINFO               =
  CHANGING
    IT_OUTTAB                     = IFINAL[]
    IT_FIELDCATALOG               = IFIELDCAT
*    IT_SORT                       = ISORT
*    IT_FILTER                     =
  EXCEPTIONS
    INVALID_PARAMETER_COMBINATION = 1
    PROGRAM_ERROR                 = 2
    TOO_MANY_LINES                = 3
    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.
 
CALL METHOD GRID->SET_TOOLBAR_INTERACTIVE.
 
CALL METHOD GRID->list_processing_events
EXPORTING
i_event_name = 'TOP_OF_PAGE'
i_dyndoc_id = o_dd_doc.
 
 
ENDMODULE.                 " PBO  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  PAI  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE PAI INPUT.
CASE OKCODE.
WHEN 'BACK' OR 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.                 " PAI  INPUT
*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BUILD_LAYOUT .
ILAYOUT-ZEBRA = 'X'.
ILAYOUT-SEL_MODE = 'A'.
ENDFORM.                    " BUILD_LAYOUT

Thanks,

Sankar M

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question