Skip to Content
avatar image
Former Member

abap objects

hi,

how we can write a code in abap objects for retrievin the data from database table..the follwing code contains error..help me please..

TABLES:MARA.

SELECT-OPTIONS:SMATNR FOR MARA-MATNR.

CLASS SELECT DEFINITION.

PUBLIC SECTION.

DATA:BEGIN OF ITAB,

matnr like mara-matnr,

ersda like mara-ersda,

END OF ITAB.

data:itab1 like standard table of itab .

*data:wa like itab1.

METHODS:READ.

ENDCLASS.

CLASS SELECT IMPLEMENTATION.

METHOD READ.

SELECT matnr ersda FROM MARA INTO TABLE itab1

WHERE MATNR IN SMATNR.

*loop at itab1 .

write:itab1-matnr,itab1-ersda.

*endloop.

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

DATA OBJ TYPE REF TO SELECT.

CREATE OBJECT OBJ.

CALL METHOD OBJ->read.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Aug 21, 2007 at 06:00 AM

    hi,

    check this code.

    REPORT ZZTEST2.

    TABLES:MARA.

    SELECT-OPTIONS:SMATNR FOR MARA-MATNR.

    CLASS SELECT DEFINITION.

    PUBLIC SECTION.

    types: BEGIN OF ty_mara,

    matnr type matnr,

    matkl type matkl,

    end of ty_mara.

    data:itab type standard table of ty_mara INITIAL SIZE 0,

    wa_mara type ty_mara.

    *data:wa like itab1.

    METHODS:READ.

    ENDCLASS.

    CLASS SELECT IMPLEMENTATION.

    METHOD READ.

    SELECT matnr matkl FROM MARA INTO TABLE itab

    WHERE MATNR IN SMATNR.

    *loop at itab1 .

    loop at itab into wa_mara.

    write:wa_mara-matnr,wa_mara-matkl.

    endloop.

    *endloop.

    ENDMETHOD.

    ENDCLASS.

    START-OF-SELECTION.

    DATA OBJ TYPE REF TO SELECT.

    CREATE OBJECT OBJ.

    CALL METHOD OBJ->read.

    Rewards points if it is useful

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 21, 2007 at 05:59 AM

    HI Manjula,

    Check out the link for sample codes in OOABAP.

    http://www.sap-img.com/abap-function.htm

    Hope this helps.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 21, 2007 at 06:28 AM

    hi

    change the code to following

    u should use types insted of data stt for declaration and work area also u should declare beacuse internal table has no header line .

    TABLES:MARA.

    SELECT-OPTIONS:SMATNR FOR MARA-MATNR.

    CLASS SELECT DEFINITION.

    PUBLIC SECTION.

    types:begiN OF ITAB,

    matnr like mara-matnr,

    ersda like mara-ersda,

    END OF ITAB.

    data:itab1 type standard table of itab .

    data:wa type itab.

    METHODS:READ.

    ENDCLASS.

    CLASS SELECT IMPLEMENTATION.

    METHOD READ.

    SELECT matnr ersda FROM MARA INTO TABLE itab1

    WHERE MATNR IN SMATNR.

    loop at itab1 into wa .

    write:wa-matnr,wa-ersda.

    endloop.

    ENDMETHOD.

    ENDCLASS.

    START-OF-SELECTION.

    DATA OBJ TYPE REF TO SELECT.

    CREATE OBJECT OBJ.

    CALL METHOD OBJ->read.

    Reward if useful

    sandhya

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 21, 2007 at 06:33 AM

    your response is so much helpful to me..thank u

    Add comment
    10|10000 characters needed characters exceeded