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: 

abap oo

Former Member
0 Kudos

how to create report using oop?

4 REPLIES 4

Former Member
0 Kudos

If u need that in ALV ,chk program <b>BCALV_EDIT_05</b>

Former Member
0 Kudos

hi,

check this program,i am displaying fields from 2 diff. tables MARA and MARD,

for simple oops program you need to know just one thing,

if you are displaying data froms ingle DBtable and fetching all the fields,

then just specify the STRUCTURE parameter as dbtablename and pass your internal table to the FM set_table_for_first_display

if you are displaying specific fields (not all the fields) either from 1 or more than one dbtables then you have to create a fieldcatalog and pass as the parameter instead of STRUCTURE parameter.

Ex:

data:g_cont1 type ref to cl_gui_custom_container,

g_grid1 type ref to cl_gui_alv_grid,

ok_code like sy-ucomm,

fcat type lvc_t_fcat,

w_fcat type lvc_s_fcat.

data: itab1 type standard table of mara with header line,

itab2 type standard table of mard with header line.

types:begin of ty_it_final,

matnr like mara-matnr,

mtart like mara-mtart,

werks like mard-werks,

end of ty_it_final.

data:it_final type standard table of ty_it_final with header line.

start-of-selection.

set screen 100.

select matnr mtart from mara

into corresponding fields of table itab1.

select matnr werks from mard

into corresponding fields of table itab2

for all entries in itab1

where matnr = itab1-matnr.

loop at itab1.

it_final-matnr = itab1-matnr.

it_final-mtart = itab1-mtart.

read table itab2 with key matnr = itab1-matnr.

it_final-werks = itab2-werks.

append it_final.

endloop.

w_fcat-col_pos = 1.

w_fcat-fieldname = 'MATNR'.

w_fcat-tabname = 'MARA'.

w_fcat-coltext = 'Material No.'.

append w_fcat to fcat.

w_fcat-col_pos = 2.

w_fcat-fieldname = 'MTART'.

w_fcat-tabname = 'MARA'.

w_fcat-coltext = 'Material Type'.

append w_fcat to fcat.

w_fcat-col_pos = 3.

w_fcat-fieldname = 'WERKS'.

w_fcat-tabname = 'MARD'.

w_fcat-coltext = 'Plant'.

append w_fcat to fcat.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


module status_0100 output.

set pf-status 'PF1'.

  • SET TITLEBAR 'xxx'.

if g_cont1 is initial.

create object g_cont1

exporting

container_name = 'CONTAINER1'.

create object g_grid1

exporting

i_parent = g_cont1.

<b>call method g_grid1->set_table_for_first_display

changing

it_outtab = it_final

it_fieldcatalog = fcat

.</b>

endif.

endmodule. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


module user_command_0100 input.

call method cl_gui_cfw=>dispatch.

ok_code = sy-ucomm.

case ok_code.

when 'BACK'.

leave program.

endcase.

clear ok_code.

endmodule. " USER_COMMAND_0100 INPUT

in the other case if your fetching all the fields from single table,

your FM should be

<b>CALL METHOD g_grid1->set_table_for_first_display

EXPORTING

I_STRUCTURE_NAME = 'SFLIGHT'

CHANGING

it_outtab = it_sflight.</b>

Regards,

Hope it helps you

Former Member
0 Kudos

hi,

Check out hte program.


REPORT  ZRICHA1.

INCLUDE ZRICHA_cl.

*-- Selection Values : Block1
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS s_ccode FOR v_bukrs MATCHCODE OBJECT dbukn OBLIGATORY.
PARAMETERS     p_ccode TYPE ty_bukrs OBLIGATORY.
PARAMETERS     p_ledger TYPE rldnr MATCHCODE OBJECT zled OBLIGATORY.
PARAMETERS     p_table  TYPE char30.
PARAMETERS     p_fyear TYPE gjahr OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

  DATA : o_merger TYPE REF TO lcl_merger.
  CREATE OBJECT o_merger.

  CALL METHOD o_merger->get_data
                            EXPORTING  e_table = p_table
                                       e_ccode  = s_ccode[]
                                       e_ledger = p_ledger
                                       e_fyear  = p_fyear
                            IMPORTING  i_subrc = v_subrc.

END-OF-SELECTION.

  IF v_subrc = 0.
    CALL METHOD o_merger->write_data
  ENDIF.
*******************************************
***INCLUDE ZFGLI004_CL .
CLASS lcl_merger DEFINITION.

  PUBLIC SECTION.
    DATA : v_table     TYPE char30,       "Table Name
           v_lines     TYPE i,            "Number of Detail Record
           v_tabix     TYPE sy-tabix.    "Internal table index
    DATA : it_record     TYPE TABLE OF ty_record. 
    METHODS :

    get_data     IMPORTING e_table TYPE char30
                           e_ccode TYPE tt_bukrs
                           e_ledger TYPE rldnr
                           e_fyear  TYPE ryear
                 EXPORTING i_subrc TYPE sy-subrc ,

    process_data.

ENDCLASS.
CLASS lcl_merger IMPLEMENTATION.

  METHOD get_data.

    CLEAR : it_record[], x_record, it_ckey[], x_ckey.

    SELECT..........
      IF sy-subrc = 0.
        i_subrc = sy-subrc.
      ENDIF.
  ENDMETHOD.
  METHOD process_data.
    WRITE : / 'Number of records downloaded :'(004),v_count.
    WRITE :/,,,,,,,,,,
            ....................
  ENDMETHOD.
ENDCLASS.

This is a report using object oriented programming concepts. Hope this example helps.

Regards,

Richa