Application Development and Automation 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: 
Read only

simple code for reteriving data

Former Member
0 Likes
1,841

Hi,

I want to make a code using ABAP Objects i.e. i want to fetch the data from mara table.

plzz provide me guidelines how to do using oops concept.

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,781

Hello Ricx

You may have a look at class CL_IBASE_R3_MATERIAL:


DATA: go_material   TYPE REF TO cl_ibase_r3_material,
           gs_mara       TYPE mara.

CREATE OBJECT go_material
  EXPORTING
     i_matnr = p_matnr.

gs_mara = go_material->get_mara( ).

Regards

Uwe

17 REPLIES 17
Read only

former_member585060
Active Contributor
0 Likes
1,781

Hi,

Sample code for simple list display

<< Unformatted code removed - please post smaller (less than 5,000 characters) replies. >>

Regards

Bala Krishna

Edited by: Bala Krishna on Apr 1, 2009 3:08 PM

Edited by: Rob Burbank on Apr 2, 2009 2:54 PM

Read only

0 Likes
1,781

can please provide me d code in a proper format as it is difficult to understand.

Read only

0 Likes
1,781

Sorry i have put the code with code options only but still it is displaying in that format

you will find sample programs in SE38 in Package SALV_OBJECTS

Edited by: Bala Krishna on Apr 1, 2009 3:20 PM

Edited by: Bala Krishna on Apr 1, 2009 3:21 PM

Read only

0 Likes
1,781

the example mentioned above doesnot work properly please provide me some other example of it.

Thanks in advance.

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,782

Hello Ricx

You may have a look at class CL_IBASE_R3_MATERIAL:


DATA: go_material   TYPE REF TO cl_ibase_r3_material,
           gs_mara       TYPE mara.

CREATE OBJECT go_material
  EXPORTING
     i_matnr = p_matnr.

gs_mara = go_material->get_mara( ).

Regards

Uwe

Read only

0 Likes
1,781
PARAMETERS: p_matnr TYPE matnr.


*----------------------------------------------------------------------*
*       CLASS Mara_fetch DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS mara_fetch DEFINITION.
  PUBLIC SECTION.
    DATA:BEGIN OF fs_mara,
         matnr TYPE mara-matnr,
         ersda TYPE ersda,
         ernam TYPE ernam,
         END OF fs_mara.
    DATA: t_mara LIKE STANDARD TABLE OF fs_mara.
    DATA: w_matnr TYPE matnr.

    METHODS fetch_data
            IMPORTING w_matnr TYPE matnr.

ENDCLASS.                    "mara_fetch DEFINITION

DATA:cl_mara TYPE REF TO mara_fetch.

CREATE OBJECT cl_mara.

CALL METHOD cl_mara->fetch_data
  EXPORTING
    w_matnr = p_matnr.

*----------------------------------------------------------------------*
*       CLASS mara_fetch IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS mara_fetch IMPLEMENTATION.
  METHOD fetch_data.
    SELECT matnr
           ersda
           ernam
           FROM mara
           INTO TABLE t_mara
           WHERE matnr = w_matnr.

    LOOP AT t_mara INTO fs_mara.
    write :/ fs_mara-matnr,fs_mara-ersda,fs_mara-ernam.
    ENDLOOP.
  ENDMETHOD.                    "fetch_data
ENDCLASS.                    "mara_fetch IMPLEMENTATION

regards,

Gurpreet

Read only

0 Likes
1,781

hi,

this is the example of fetching the data from 1 table i.e. and i had tried to fetch the data form the makt table ,it is not able to fetch the data from table makt. i tried using the conncept of Inner join ,it did not worked.

plzz provide me guidelines how to fetch the data form 2 tables.

Read only

0 Likes
1,781
PARAMETERS: p_matnr TYPE matnr.


*----------------------------------------------------------------------*
*       CLASS Mara_fetch DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS mara_fetch DEFINITION.
  PUBLIC SECTION.
    DATA:BEGIN OF fs_mara,                " Structure for both tables fields
         matnr TYPE mara-matnr,            
         ersda TYPE ersda,
         ernam TYPE ernam,
         maktx type makt-maktx,             " Material description
         END OF fs_mara.
    DATA: t_mara LIKE STANDARD TABLE OF fs_mara.
    DATA: w_matnr TYPE matnr.

    METHODS fetch_data
            IMPORTING w_matnr TYPE matnr.

ENDCLASS.                    "mara_fetch DEFINITION

DATA:cl_mara TYPE REF TO mara_fetch.

CREATE OBJECT cl_mara.

CALL METHOD cl_mara->fetch_data
  EXPORTING
    w_matnr = p_matnr.

*----------------------------------------------------------------------*
*       CLASS mara_fetch IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS mara_fetch IMPLEMENTATION.
  METHOD fetch_data.
    SELECT a~matnr
           a~ersda
           a~ernam
           b~maktx
           FROM mara as a inner join makt as b          " Joins
           on a~matnr = b~matnr
           INTO TABLE t_mara
           WHERE a~matnr = w_matnr.

    LOOP AT t_mara INTO fs_mara.
    write :/ fs_mara-matnr,fs_mara-maktx,fs_mara-ersda,fs_mara-ernam.
    ENDLOOP.
  ENDMETHOD.                    "fetch_data
ENDCLASS.                    "mara_fetch IMPLEMENTATION

regards,

Gurpreet

Read only

0 Likes
1,781

hi,

thanks for example,but use inner joins in the oops concept going to effect the performance of it ?

I had tried to implement select-options instead of parameter as we do in w/o oops concpet but it is not working.

here's d code:-

TABLES: MARA.

*PARAMETERS: p_matnr TYPE matnr.

SELECT-OPTIONS: P_MATNR FOR MATNR.

----


  • CLASS Mara_fetch DEFINITION

----


*

----


CLASS mara_fetch DEFINITION.

PUBLIC SECTION.

DATA:BEGIN OF fs_mara,

matnr TYPE mara-matnr,

mtart TYPE mara-mtart,

MATKL TYPE mara-matkl,

MEINS TYPE MARA-MEINS,

MAKTX type makt-MAKTX,

END OF fs_mara.

DATA: t_mara LIKE STANDARD TABLE OF fs_mara.

DATA: w_matnr TYPE matnr.

METHODS fetch_data

IMPORTING w_matnr TYPE matnr.

ENDCLASS. "mara_fetch DEFINITION

DATA:cl_mara TYPE REF TO mara_fetch.

CREATE OBJECT cl_mara.

CALL METHOD cl_mara->fetch_data

EXPORTING

w_matnr = p_matnr.

----


  • CLASS mara_fetch IMPLEMENTATION

----


*

----


CLASS mara_fetch IMPLEMENTATION.

METHOD fetch_data.

SELECT a~matnr

a~MTART

a~MATKL

a~MEINS

b~MAKTX

  • ersda

  • ernam

FROM mara as a INNER JOIN makt as b

on bmatnr = amatnr

INTO TABLE t_mara

WHERE a~matnr = w_matnr.

LOOP AT t_mara INTO fs_mara.

write 😕 fs_mara-matnr,fs_mara-maktx,fs_mara-MTART,fs_mara-MATKL,fs_mara-MEINS.

ENDLOOP.

ENDMETHOD. "fetch_data

ENDCLASS. "mara_fetch IMPLEMENTATION

Edited by: ricx .s on Apr 2, 2009 12:35 PM

Read only

0 Likes
1,781

Hello Ricx


DATA: go_material   TYPE REF TO cl_ibase_r3_material,
           gs_mara       TYPE mara,
           gs_makt       TYPE makt.

 
CREATE OBJECT go_material
  EXPORTING
     i_matnr = p_matnr.
 
gs_mara = go_material->get_mara( ).
gs_makt = go_material->get_makt( ).

Regards

Uwe

Read only

0 Likes
1,781

Use FOR ALL ENTRIES:

Tables : mara.

*PARAMETERS: p_matnr TYPE matnr.
Select-options: s_matnr for mara-matnr.              " SELECT OPTIONS......
data: r_matnr type range of mara-matnr.

move s_matnr[] to r_matnr.
*----------------------------------------------------------------------*
*       CLASS Mara_fetch DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS mara_fetch DEFINITION.
  PUBLIC SECTION.
    DATA:BEGIN OF fs_mara,
         matnr TYPE mara-matnr,
         ersda TYPE ersda,
         ernam TYPE ernam,
         END OF fs_mara.

    data: begin of fs_makt,
          matnr TYPE mara-matnr,
          maktx type makt-maktx,
          end of fs_makt.

    DATA: t_mara LIKE STANDARD TABLE OF fs_mara.
    DATA: t_makt LIKE STANDARD TABLE OF fs_makt.
    DATA: w_matnr TYPE matnr.
    data : p_matnr type range of mara-matnr.

    METHODS fetch_data
            changing w_matnr type any table.
ENDCLASS.                    "mara_fetch DEFINITION

DATA:cl_mara TYPE REF TO mara_fetch.

CREATE OBJECT cl_mara.

CALL METHOD cl_mara->fetch_data
changing
    w_matnr = r_matnr.

*----------------------------------------------------------------------*
*       CLASS mara_fetch IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS mara_fetch IMPLEMENTATION.
  METHOD fetch_data.
    SELECT matnr
           ersda
           ernam
           FROM mara
           INTO TABLE t_mara
           WHERE matnr in w_matnr.

     SELECT matnr
            maktx
            from makt
            into table t_makt
            for all entries in t_mara
            where matnr = t_mara-matnr.

    LOOP AT t_makt INTO fs_makt.
    write :/ fs_makt-matnr,fs_makt-maktx.
    ENDLOOP.
  ENDMETHOD.                    "fetch_data
ENDCLASS.                    "mara_fetch IMPLEMENTATION

CHECK SELECT-OPTIONS it works.....

Regards,

Gurpreet

Edited by: Gurpreet Singh on Apr 2, 2009 12:56 PM

Read only

umashankar_sahu
Active Participant
0 Likes
1,781

&----


*& Report Z_SDN_Q1_SAHU

*&

&----


*&

*&

&----


REPORT Z_SDN_Q1_SAHU NO STANDARD PAGE HEADING.

DATA : IT_MARA TYPE TABLE OF MARA,

R_CONTAINER TYPE REF TO cl_gui_custom_container,

r_grid TYPE REF TO cl_gui_alv_grid.

START-OF-SELECTION.

SELECT * FROM MARA INTO TABLE IT_MARA.

CALL SCREEN '0100'.

&----


*& Module ALV_GRID OUTPUT

&----


  • text

----


MODULE ALV_GRID OUTPUT.

if R_CONTAINER is INITIAL.

CREATE OBJECT R_CONTAINER

EXPORTING

  • PARENT =

CONTAINER_NAME = 'CONTAINER_1'

  • 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.

ENDIF.

CREATE OBJECT R_GRID

EXPORTING

  • I_SHELLSTYLE = 0

  • I_LIFETIME =

I_PARENT = r_container

  • I_APPL_EVENTS = space

  • I_PARENTDBG =

  • I_APPLOGPARENT =

  • I_GRAPHICSPARENT =

  • I_NAME =

  • I_FCAT_COMPLETE = SPACE

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.

CALL METHOD R_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

  • I_BUFFER_ACTIVE =

  • I_BYPASSING_BUFFER =

  • I_CONSISTENCY_CHECK =

I_STRUCTURE_NAME = 'MARA'

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

  • IS_LAYOUT =

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

  • IR_SALV_ADAPTER =

CHANGING

IT_OUTTAB = it_mara

  • IT_FIELDCATALOG =

  • IT_SORT =

  • 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.

may be helpfull for u.

Edited by: umashankar sahu on Apr 2, 2009 9:45 AM

Edited by: umashankar sahu on Apr 2, 2009 9:47 AM

Read only

umashankar_sahu
Active Participant
0 Likes
1,781

hi nicx

may be this will fullfill your reqirement .

REPORT Z_SDN_Q2_SAHU NO STANDARD PAGE HEADING.

include Z_SDN_Q2_SAHU_incl.

DATA : r_mara TYPE REF TO lcl_mara.

data : it_mara TYPE TABLE OF mara,

wa_mara LIKE mara.

START-OF-SELECTION.

CREATE OBJECT r_mara.

r_mara->display_material( ).

***********************AND INCLUDE PROGRAM (include Z_SDN_Q2_SAHU_incl.)*********

CLASS lcl_mara DEFINITION .

PUBLIC SECTION.

METHODs : display_material.

CLASS-METHODS : class_constructor.

PRIVATE SECTION.

CLASS-DATA : it_mara type table of mara,

wa_mara TYPE mara.

ENDCLASS.

CLASS lcl_mara IMPLEMENTATION.

METHOD class_constructor.

SELECT * from mara into TABLE it_mara.

ENDMETHOD.

METHOD display_material.

LOOP AT it_mara into wa_mara .

write : / wa_mara-ERSDA,

wa_mara-ERNAM.

ENDLOOP.

ENDMETHOD.

ENDCLASS.

Read only

Former Member
0 Likes
1,781

hi,

thanks to gurpreet and uwe,i want to know is dere any some gud tutorial or pdf's available. if there are then plzz tell me ,only the simple ones not complicated.

Read only

0 Likes
1,781

Hope this reference would help you and also check F1 help for Classes.

[Reference for Objects|http://tcyang.cs.pu.edu.tw/George/course9701/abap/ABAPObjects_Show.ppt]

Regards,

Gurpreet

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,781

Hello Ricx

The question is: Is there a class available which deals with your business object (here: Material -> MARA).

The class I suggested is not the most comfortable one yet if SAP decides to enhance it in future releases then you have an advantage if you are using this class already in your reports.

Alternatively, you may define your own ZCL_MATERIAL class which provides the required information. In addition, this class may contain a public (read-only) instance attribute of TYPE REF TO cl_ibase_r3_material. In this case you can combine your own logic with the standard logic provided by SAP.

Regards

Uwe

Read only

Former Member
0 Likes
1,781

Thanks to all of you, for help.