Application Development 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: 

can i use classes or grid control (alv) in normal report

Former Member
0 Kudos

Hai,

Can i use Grid control or classes in normal report.If yes what are the steps that i have to go for.

thanks

kiran

9 REPLIES 9

FredericGirod
Active Contributor
0 Kudos

Hello Kiran,

maybe look the transaction DWDM, you will see example

Regards

Frédéric

0 Kudos

Sure... here is a sample of an ALV in a report. All you need to do is call a screen. I believe that there is also a way to do it without having to create a screen.



REPORT ZRICH_0001.


DATA: BEGIN OF I_ALV OCCURS 0,
      MATNR TYPE MARA-MATNR,
      MAKTX TYPE MAKT-MAKTX,
      END OF I_ALV.

DATA: ALV_CONTAINER  TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
DATA: ALV_GRID       TYPE REF TO CL_GUI_ALV_GRID.
DATA: LAYOUT    TYPE LVC_S_LAYO.
DATA: FIELDCAT  TYPE LVC_T_FCAT.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001 .
SELECT-OPTIONS: S_MATNR FOR i_ALV-MATNR.
SELECTION-SCREEN END OF BLOCK B1.

START-OF-SELECTION.

  PERFORM GET_DATA.
  CALL SCREEN 100.

************************************************************************
*      Module  status_0100  OUTPUT
************************************************************************
MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS '0100'.
  SET TITLEBAR '0100'.

  DATA: VARIANT TYPE  DISVARIANT.

  VARIANT-REPORT = SY-REPID.
  VARIANT-USERNAME = SY-UNAME.

* Create Controls
  CREATE OBJECT ALV_CONTAINER
         EXPORTING
               CONTAINER_NAME    = 'ALV_CONTAINER'.

  CREATE OBJECT ALV_GRID
         EXPORTING
               I_PARENT          =  ALV_CONTAINER.

*  ALV Specific. Data selection.
*  Populate Field Catalog
  PERFORM GET_FIELDCATALOG.

  CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
           IS_LAYOUT              = LAYOUT
           IS_VARIANT             = VARIANT
           I_SAVE                 = 'U'
           I_STRUCTURE_NAME       = 'I_ALV'
      CHANGING
           IT_OUTTAB       = I_ALV[]
           IT_FIELDCATALOG = FIELDCAT[].


ENDMODULE.

************************************************************************
*      Module  USER_COMMAND_0100  INPUT
************************************************************************
MODULE USER_COMMAND_0100 INPUT.

  CASE SY-UCOMM.
    WHEN 'BACK' OR 'CANC'.
      IF NOT ALV_CONTAINER IS INITIAL.
        CALL METHOD ALV_CONTAINER->FREE.
        CLEAR: ALV_CONTAINER.
        FREE : ALV_CONTAINER.
      ENDIF.
      IF SY-SUBRC = 0.
        SET SCREEN 0.
        LEAVE SCREEN.
      ELSE.
        LEAVE PROGRAM.
      ENDIF.
    WHEN 'EXIT'.
      IF NOT ALV_CONTAINER IS INITIAL.
        CALL METHOD ALV_CONTAINER->FREE.
        CLEAR: ALV_CONTAINER.
        FREE : ALV_CONTAINER.
      ENDIF.
      LEAVE PROGRAM.
  ENDCASE.

ENDMODULE.

************************************************************************
* FORM GET_DATA
************************************************************************
FORM GET_DATA.

  SELECT * INTO CORRESPONDING FIELDS OF TABLE I_ALV
        FROM MARA
          INNER JOIN MAKT
            ON MARA~MATNR = MAKT~MATNR
               WHERE MARA~MATNR IN S_MATNR
                 AND MAKT~SPRAS = SY-LANGU.

  SORT I_ALV ASCENDING BY MATNR.

ENDFORM.

************************************************************************
*      Form  Get_Fieldcatalog - Set Up Columns/Headers
************************************************************************
FORM GET_FIELDCATALOG.

  DATA: LS_FCAT TYPE LVC_S_FCAT.
  REFRESH: FIELDCAT.

  CLEAR: LS_FCAT.
  LS_FCAT-REPTEXT    = 'Material Number'.
  LS_FCAT-COLTEXT    = 'Material Number'.
  LS_FCAT-FIELDNAME  = 'MATNR'.
  LS_FCAT-REF_TABLE  = 'I_ALV'.
  LS_FCAT-OUTPUTLEN  = '18'.
  LS_FCAT-COL_POS    = 1.
  APPEND LS_FCAT TO FIELDCAT.

  CLEAR: LS_FCAT.
  LS_FCAT-REPTEXT    = 'Material Description'.
  LS_FCAT-COLTEXT    = 'Material Description'.
  LS_FCAT-FIELDNAME  = 'MAKTX'.
  LS_FCAT-REF_TABLE  = 'I_ALV'.
  LS_FCAT-OUTPUTLEN  = '40'.
  LS_FCAT-COL_POS    = 2.
  APPEND LS_FCAT TO FIELDCAT.

ENDFORM.

Regards,

Rich Heilman

0 Kudos

Here is an example of an ALV in a report without having to create a dynpro.



report zrich_0001.


data: begin of i_alv occurs 0,
      matnr type mara-matnr,
      maktx type makt-maktx,
      end of i_alv.

data: alv_container  type ref to cl_gui_custom_container.
data: alv_grid       type ref to cl_gui_alv_grid.
data: layout    type lvc_s_layo.
data: fieldcat  type lvc_t_fcat.

selection-screen begin of block b1 with frame title text-001 .
select-options: s_matnr for i_alv-matnr.
selection-screen end of block b1.

selection-screen begin of screen 1010 as window title text-001.
selection-screen end of screen 1010.

start-of-selection.

  perform get_data.

  create object alv_grid
         exporting
               i_parent          =  cl_gui_container=>screen0.

*  Populate Field Catalog
  perform get_fieldcatalog.

  call method alv_grid->set_table_for_first_display
      exporting
           is_layout              = layout
           i_structure_name       = 'I_ALV'
      changing
           it_outtab       = i_alv[]
           it_fieldcatalog = fieldcat[].

  call selection-screen 1010.

************************************************************************
* FORM GET_DATA
************************************************************************
form get_data.

  select * into corresponding fields of table i_alv
        from mara
          inner join makt
            on mara~matnr = makt~matnr
               where mara~matnr in s_matnr
                 and makt~spras = sy-langu.

  sort i_alv ascending by matnr.

endform.

************************************************************************
*      Form  Get_Fieldcatalog - Set Up Columns/Headers
************************************************************************
form get_fieldcatalog.

  data: ls_fcat type lvc_s_fcat.
  refresh: fieldcat.

  clear: ls_fcat.
  ls_fcat-reptext    = 'Material Number'.
  ls_fcat-coltext    = 'Material Number'.
  ls_fcat-fieldname  = 'MATNR'.
  ls_fcat-ref_table  = 'I_ALV'.
  ls_fcat-outputlen  = '18'.
  ls_fcat-col_pos    = 1.
  append ls_fcat to fieldcat.

  clear: ls_fcat.
  ls_fcat-reptext    = 'Material Description'.
  ls_fcat-coltext    = 'Material Description'.
  ls_fcat-fieldname  = 'MAKTX'.
  ls_fcat-ref_table  = 'I_ALV'.
  ls_fcat-outputlen  = '40'.
  ls_fcat-col_pos    = 2.
  append ls_fcat to fieldcat.

endform.

Regards,

Rich Heilman

0 Kudos

Hai Rich,

Thanks for the information.Is it necessary for report to call "call method alv_grid->set_table_for_first_display".

What is the use of this.

Now i want to add a push button to my alv tool bar and a check box to my alv grid.

thanks

kiran

0 Kudos

Yes, you do need to call that method. How else would you tell the grid what your field catalog looks like and what data to show?

Regards,

Rich Heilman

0 Kudos

Kiran,

I am not sure what are you trying to achieve. you have posted two other messages one for the adding buttons and another one for check box column with edit. I think you got all the answers there. Not sure why are you posting the same messages again and again.

Moreover, if I understand it right what you are trying to do is to edit an existing report that is using REUSE function module. You cannot edit function using functions. Please do NOT ask the same questions again and again.

Please look at the examples that have been quoted.

Regards,

Ravi

0 Kudos

Ravi,

Those are two different scenarios which i got one after other. So only i have posted two messages.

Regards,

kiran

0 Kudos

Hi Kiran,

If you are using set_table_for_first_display,then use should create a screen(say 9000).

In your program,

call screen 9000.

Then add the button as I explained you on that thread.Then in PBO ,

you need to call the status.

In PAI,you need to write the coding for the BUTTON.

Kindly reward points if it is useful.Otherwise,get back.

andreas_mann3
Active Contributor
0 Kudos

Hi Kiran,

examples are here:

TA: SE38 - environment - reuse library

regards Andreas