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: 

Craete a simple abap object to select data from a table and display

Former Member
0 Kudos

Hi,

I know the concept of abap objects but i never worked on it,

can any one give me simple example of how to create an abap object to display data from mara table.also please send me documents or info regd ABAP OBJECTS.

I want to write a simple report in terms of abap object

Regards,

Sowjanya

7 REPLIES 7

former_member758419
Active Participant
0 Kudos

Hi,

Go thro the below links,

http://www.erpgenie.com/sap/abap/OO/index.htm

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCABA/BCABA.pdf -- Page 1291

http://help.sap.com/saphelp_nw04/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm

http://www.esnips.com/web/OOP

http://www.esnips.com/SharedFolderAction.ns#files

Goto se24, enter the class name and create ur own class there u can declare methods and attributes and perform ur business logic.

Hope this helps,

Regards,

Sachidanand.B

Pls mark helpful answers

former_member758419
Active Participant
0 Kudos

Hi Sowjanya,

This is a simple example of getting data from sflight table:

Inside class declare internal table itl_sflight in the attribute column

ITL_SFLIGHT INSTANCE ATTRIBUTE PUBLIC TYPE FLIGHTTAB

where flighttab is a table type of table sflight.

In the methods tab create a method DISPLAY:

method display.

select * from sflight

into corresponding fields of itl_sflight

where carrid = '007'.

endmethod.

check, Activate and test.

Hope this helps,

Reward points if helped.

Former Member
0 Kudos

Hi sachidanad,

thanks a lot for you help so far,

but i heard that tables doesn't work in abap objects.

anyway can you send the code completely,

se24 is the transaction for creating abap objects,

am i right,

Thanks,

sowjanya

0 Kudos

Hi,

GOTO se24 --> enter class name --> press create --> select class radio button and save the class.

In the Attribute tab declare the attributes and in method tab declare the methods.

activate and test.

I've given a code for sflight table. U can use tables in ABAP objects.

Abap Objects is just an object oriented extension of normal ABAP.

Regards,

Sachidanand.B

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Here is the simple example of OOPS ALV.Kindly reward points if it helps.This is the simple program without GUI.

CLASS lcl_event_receiver DEFINITION DEFERRED.

class cl_gui_container definition load.

DATA : o_grid TYPE REF TO cl_gui_alv_grid,

o_docking TYPE REF TO cl_gui_docking_container,

w_layout TYPE lvc_s_layo,

  • Enable variant saving

w_variant TYPE disvariant.

DATA : itab TYPE STANDARD TABLE OF MARA,

wa type mara.

select * from mara into table itab up to 10 rows.

call screen 9000<b>."Double click here to create screen

*IN the flow logic uncomment the PBO module</b>

module STATUS_9000 output.

  • This form create the Docking container and the ALV grid.

if o_grid is initial.

CREATE OBJECT o_docking

EXPORTING

ratio = '95'.

CREATE OBJECT o_grid

EXPORTING

i_parent = o_docking.

endif.

w_layout-sel_mode = 'B'.

w_variant-report = sy-repid.

CALL METHOD o_alvgrid->set_table_for_first_display

EXPORTING

I_STRUCTURE_NAME = 'MARA'

is_variant = w_variant

i_save = 'A'

is_layout = w_layout

CHANGING

it_outtab = itab[]

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

endmodule. " STATUS_9000 OUTPUT

Message was edited by:

Jayanthi Jayaraman

Former Member
0 Kudos

hi sachidanand,

thanks for ur answers,

but im doing reportin se38

regards,

Sowjanya

Former Member
0 Kudos

hi,

Here is hte sample program in se38.

 REPORT ZFGLI00003
*-- Include for data declarations and performs
include ZFGLI00003_f01.

*--Include for Classes and their Implementation
include ZFGLI00003_cl.

*----------------------------------------------------------------------*
*                selection-screen                                      *
*----------------------------------------------------------------------*

*-- Selection Values : Block1
selection-screen begin of block b1 with frame title text-001.
*--         Ledger
parameters: p_rldnr  like zzprodnt-rldnr default 'NP'.
*--         Fiscal year
parameters: p_ryear  like zzprodnt-ryear.
*--         Period(month)
parameters: p_rpmax  like zzprodnt-rpmax.
selection-screen end of block b1.

*-- Selection Values : Block2
selection-screen begin of block b2 with frame title text-002.
*--              Company ID's
select-options : s_glcomp  for ZZPRODNT-ROBUKRS .
*--              Profit Center
select-options : s_prctr   for ZZPRODNT-RPRCTR .
*--              Product Assignment
select-options : s_prasn   for ZZPRODNT-RZZWWZ01 .
*--              Corporate Brand
select-options : s_crpbd   for ZZPRODNT-RZZWWZ05 .

selection-screen end of block b2.

*-- Selection Values : Block3  Download Options
selection-screen begin of block b3 with frame title text-003.
parameters : p_local radiobutton group 1,
             p_unix  radiobutton group 1,
             p_path  like rlgrap-filename obligatory
                     default 'C:P20Z_Formatted.txt'(009).

selection-screen end of block b3.

*----------------------------------------------------------------------*
*            At Selection-Selection on value-request  for file path    *
*----------------------------------------------------------------------*

at selection-screen on value-request for p_path.

  if p_unix <> 'X'.
*-- Getting F4 help for output file
    perform get_filename changing p_path.
  else.
    message i999(zi) with
          'Sorry !! Function not available for UNIX file.'(i01).
  endif.


*-- At selection screen validations
at selection-screen on p_path.
  if p_unix <> 'X'.
*-- Validate local file
    if p_path+1(2) <> ':'.
      message e999(zi) with 'Invalid file path'(006).
    endif.
  else.
*-- Validate unix file
    if p_path+0(1) <> '/'.
      message e999(zi) with 'Invalid file path'(006).
    endif.
  endif.

*---------------------------------------------------------------------*
*                   Initialization                                    *
*---------------------------------------------------------------------*

initialization.
*-- Initialize the period
  perform init_period changing p_rpmax p_ryear.

*---------------------------------------------------------------------*
*                    start-of-selection                               *
*---------------------------------------------------------------------*
start-of-selection.

  data : o_tm1_intf type ref to lcl_tm1_intf.
  create object o_tm1_intf.

*-- Extract the data from ZZPRODNT
  call method o_tm1_intf->get_data exporting e_rldnr  = p_rldnr
                                             e_ryear  = p_ryear
                                             e_rpmax  = p_rpmax
                                             e_glcomp = s_glcomp[]
                                             e_prctr  = s_prctr[]
                                             e_prasn  = s_prasn[]
                                             e_crpbd  = s_crpbd[]
                                   importing i_subrc  = v_subrc.
*----------------------------------------------------------------------*
*   INCLUDE ZFGLI00003_CL                                              *
*----------------------------------------------------------------------*
*---------------------------------------------------------------------*
*       CLASS lcl_tm1_intf IMPLEMENTATION
*---------------------------------------------------------------------*

class lcl_tm1_intf definition.

  public section.

*-- Data Declaration
    data  : lv_date     type sy-datum,       "Date
            lv_time     type sy-uzeit,       "Time
            lv_count    type i,              "Count for total records
            lv_acsline  type zfgl014-acsline,"ACS line code
            lv_amt_curr type zzprodnt-kslvt, "current month amount
            lv_amt_ytd  type zzprodnt-kslvt, "YTD Amount
            lv_check,                        "check if any record is
                                             "downloaded
            lv_msg(100),                     "message
            lv_count_s(5)  ,                 "Count for total(char)
            lv_amt_curr_s(23),               "Current month amount(char)
            lv_amt_ytd_s(23),                "YTD Amount(char)
            lv_ksl_pd(17),                   "KSLxx
            lv_period(2) type n.             "month(period)

*-- Types Declaration
    types : ty_rldnr type zzprodnt-rldnr,    "Type for Ledger
            ty_ryear type zzprodnt-ryear,    "Type for Fiscal Year
            ty_rpmax type zzprodnt-rpmax,    "Type for Period
            ty_glcomp type range of char4,   "Type for company selection
            ty_prctr type range of char10,   "Type for profit center sel
            ty_prasn type range of char6,    "Type for prod assignmt sel
            ty_crpbd type range of char4,    "Type for Corp Brand sel
            begin of ty_file,                "Type for File
              line(150),
            end of ty_file,
            begin of ty_ZZPRODNT,            "Type-ledger summary table
              company       type OBUKR,      "Company
              gl_acct       type RACCT,      "GL Account
              cst_ctr       type KOSTL,      "Cost Center
              prt_ctr       type PRCTR,      "Profit Center
              rfarea        type FKBER,      "Functional Area
              wbs_ele       type PS_POSID,   "WBS Element
              prd_ass       type RKEG_WWZ01, "Product Assignment
              corp_bd       type RKEG_WWZ05, "Corporate Brand
              ksl01         type KSLXX9,     "Total of transactions - 01
              ksl02         type KSLXX9,     "Total of transactions - 02
              ksl03         type KSLXX9,     "Total of transactions - 03
              ksl04         type KSLXX9,     "Total of transactions - 04
              ksl05         type KSLXX9,     "Total of transactions - 05
              ksl06         type KSLXX9,     "Total of transactions - 06
              ksl07         type KSLXX9,     "Total of transactions - 07
              ksl08         type KSLXX9,     "Total of transactions - 08
              ksl09         type KSLXX9,     "Total of transactions - 09
              ksl10         type KSLXX9,     "Total of transactions - 10
              ksl11         type KSLXX9,     "Total of transactions - 11
              ksl12         type KSLXX9,     "Total of transactions - 12
              ksl13         type KSLXX9,     "Total of transactions - 13
              ksl14         type KSLXX9,     "Total of transactions - 14
              ksl15         type KSLXX9,     "Total of transactions - 15
              ksl16         type KSLXX9,     "Total of transactions - 16
            end of ty_ZZPRODNT.

*-- Structure Declaration

*           Structure for final file
    data  : x_file         type ty_file,
*           Structure for Product Ledger Summary table
            x_ZZPRODNT     type ty_ZZPRODNT,
*           Structure for Functional Area to ACS line mapping
            x_zfgl014      type zfgl014.

*-- Internal Table Declaration

*           Table for records of Product Ledger Summary table
    data  : it_ZZPRODNT     type table of ty_ZZPRODNT,
*           Table for final file
            it_file         type table of ty_file,
*           Table for Functional Area to ACS line mapping
            it_zfgl014      type table of zfgl014.

*-- Method Declaration.
    methods : get_data      importing e_rldnr  type ty_rldnr
                                      e_ryear  type ty_ryear
                                      e_rpmax  type ty_rpmax
                                      e_glcomp type ty_glcomp
                                      e_prctr  type ty_prctr
                                      e_prasn  type ty_prasn
                                      e_crpbd  type ty_crpbd
                            exporting i_subrc type sy-subrc.
endclass.                    "lcl_tm1_intf DEFINITION

*---------------------------------------------------------------------*
*       CLASS lcl_tm1_intf IMPLEMENTATION
*---------------------------------------------------------------------*

class lcl_tm1_intf implementation.

*---------------------------------------------------------------------*
*-- Method get_data selects the North American Product Ledger Summary
*   table data and then maps the Functional Area to ACS line to get
*   the ACS line code
*---------------------------------------------------------------------*
  method get_data.

*-- Local Variable
    DATA: L_ZZPRODNT TYPE TY_ZZPRODNT.

*-- Get the data from North American Product Ledger Summary table
    select robukrs
           racct
           rcntr
           rprctr
           rfarea
           rzzwbs_el
           rzzwwz01
           rzzwwz05
           ksl01
           ksl02
           ksl03
           ksl04
           ksl05
           ksl06
           ksl07
           ksl08
           ksl09
           ksl10
           ksl11
           ksl12
           ksl13
           ksl14
           ksl15
           ksl16
      from zzprodnt
      into table it_ZZPRODNT
     where rldnr    = e_rldnr
       and ryear    = e_ryear
       and rpmax    = e_rpmax
       and ROBUKRS  in e_glcomp
       and RPRCTR   in e_prctr
       and RZZWWZ01 in e_prasn
       and RZZWWZ05 in e_crpbd.
    if sy-subrc = 0.
      loop at it_ZZPRODNT into l_zzprodnt.
        condense l_ZZPRODNT-rfarea no-gaps.
        if l_ZZPRODNT-rfarea is initial.
          delete it_ZZPRODNT.
        endif.
      endloop.
*-- Get the Functional Area to ACS line code mapping data
      select *
        from zfgl014
        into table it_zfgl014
         for all entries in it_ZZPRODNT
       where fkber = it_ZZPRODNT-rfarea .
      if sy-subrc = 0.
      endif.
    endif.
    i_subrc = sy-subrc.
  endmethod.                    "get_data
endclass.                    "lcl_tm1_intf IMPLEMENTATION
*----------------------------------------------------------------------*
*   INCLUDE ZFGLI00003_F01                                             *
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*                             Table
*----------------------------------------------------------------------*
tables : zzprodnt.

*----------------------------------------------------------------------*
*                          Data Declaration
*----------------------------------------------------------------------*
data : v_subrc type sy-subrc.
*&---------------------------------------------------------------------*
*&      Form  get_filename
*&---------------------------------------------------------------------*
*  Description : This subroutine is used for F4 Prompting
*----------------------------------------------------------------------*
form get_filename changing p_path like rlgrap-filename.

*-- Local variables
  data : lv_file  like ibipparms-path, "Local file for upload/download
         lv_repid like syst-cprog,     "ABAP program, caller in external
                                       "procedures
         lv_dynnr type syst-dynnr.     "Current screen No

  lv_repid = syst-cprog.
  lv_dynnr = syst-dynnr.

*-- Function module used for F4 help
  call function 'F4_FILENAME'
       exporting
            program_name  = lv_repid
            dynpro_number = lv_dynnr
       importing
            file_name     = lv_file.

  move lv_file to p_path.

endform.                    " get_filename
*&---------------------------------------------------------------------*
*&      Form  init_period
*&---------------------------------------------------------------------*
FORM init_period changing p_rpmax p_ryear.

  if sy-datum+4(2) = 01.
    p_rpmax = 12.
    p_ryear = sy-datum+0(4) - 1.
  else.
    p_rpmax = sy-datum+4(2) - 1.
    p_ryear = sy-datum+0(4).
  endif.

ENDFORM.                    " init_period

Hope this helps.

Regards,

Richa