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

Declaration Error for Object orient Programming

Former Member
0 Likes
802

Hi All,

can any tell me how to export Select-options .This is an object oriented question

include ztest.

select-options : s_werks for marc-werks obligatory,

s_matnr for mara-matnr obligatory.

data : O_object type ref to lcl_test.

start-of-selection.

CREATE OBJECT O_object EXPORTING IM_S_WERKS[] IN S_WERKS[]

IM_S_LGORT[] in s_matnr[].

Above statment is the problem

This is my include ztest.

CLASS lcl_test DEFINITION.

METHODS constructor IMPORTING IMWERKS[] TYPE MARC-WERKS

imLGORT[] TYPE MARD-LGORT.

Above statment is the problem

endclass.

Can anyone tell me how to declare

Thanks

Adi

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
769

Basically this is all you need to do.




REPORT  rich_0001.

*----------------------------------------------------------------------*
*       CLASS lcl_test DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_test DEFINITION.

  PUBLIC SECTION.


    TYPES: t_datum TYPE RANGE OF sy-datum.
    DATA: r_datum TYPE t_datum.

    METHODS: constructor IMPORTING im_datum TYPE t_datum.

ENDCLASS.                    "lcl_test DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_test IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_test IMPLEMENTATION.

  METHOD constructor.

    r_datum = im_datum.

  ENDMETHOD.                    "constructor

ENDCLASS.                    "lcl_test IMPLEMENTATION


SELECT-OPTIONS: s_datum FOR sy-datum.

DATA : o_object TYPE REF TO lcl_test.


START-OF-SELECTION.

  CREATE OBJECT o_object
    EXPORTING
      im_datum = s_datum[].

Regards,

Rich Heilman

6 REPLIES 6
Read only

matt
Active Contributor
0 Likes
769

You have to declare local types (e.g. werks_sel_type and lgort_sel_type) that has the same structure of s_werks and lgort_sel_type as a standard table.

CLASS lcl_test DEFINITION.

METHODS constructor IMPORTING imwerks TYPE werks_sel_type.
imLGORT TYPE lgort_sel_type.

Then

CREATE OBJECT O_object EXPORTING IM_S_WERKS = S_WERKS

IM_S_LGORT = s_matnr.

I suggest you read the ABAP help for select-options to see how they are actually defined internally.

Also look carefully in the ABAP help for how to declare parameters for constructors and methods. [] is not valid!

matt

Read only

Former Member
0 Likes
769

Hi Matthew,

I declared like this

types : begin of iwerks ,

SIGN(2) type c,

OPTION(2) type c,

low(4) type c,

high(4) type c,

end of iwerks.

METHODS constructor IMPORTING IM_S_WERKS TYPE iwerks.

start-of-selection.

CREATE OBJECT O_IMARD EXPORTING IM_S_WERKS = S_WERKS.

This one gives me an error

saying im_s_werks is not compatible with s_werks.

Let me know

Thanks

Read only

Former Member
0 Likes
769

Hi All,

Any Valuable suggestions

Thanks

Adi

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
770

Basically this is all you need to do.




REPORT  rich_0001.

*----------------------------------------------------------------------*
*       CLASS lcl_test DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_test DEFINITION.

  PUBLIC SECTION.


    TYPES: t_datum TYPE RANGE OF sy-datum.
    DATA: r_datum TYPE t_datum.

    METHODS: constructor IMPORTING im_datum TYPE t_datum.

ENDCLASS.                    "lcl_test DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_test IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_test IMPLEMENTATION.

  METHOD constructor.

    r_datum = im_datum.

  ENDMETHOD.                    "constructor

ENDCLASS.                    "lcl_test IMPLEMENTATION


SELECT-OPTIONS: s_datum FOR sy-datum.

DATA : o_object TYPE REF TO lcl_test.


START-OF-SELECTION.

  CREATE OBJECT o_object
    EXPORTING
      im_datum = s_datum[].

Regards,

Rich Heilman

Read only

0 Likes
769

Hi Rich,

This is what i have

start-of-selection.

CREATE OBJECT O_IMARD EXPORTING IM_WERKS = S_WERKS[].

CLASS lcl_par DEFINITION.

public section.

TYPES: t_werks TYPE RANGE OF werks.

DATA: r_werks TYPE t_werks.

*types : begin of iwerks ,

*SIGN(2) type c,

*OPTION(2) type c,

*low(4) type c,

*high(4) type c,

*end of iwerks.

METHODS: constructor IMPORTING im_werks TYPE t_werks.

endclass.

CLASS lcl_par implementation.

METHOD constructor.

r_werks = im_werks.

endmethod.

endclass.

My PROGRAM THROWS AN ERROR SAYINGS

S_WERKS IS NOT COMPATABILE WITH IM_WERKS

Let me know whats the issue in here

Thanks

Adi

Read only

0 Likes
769

Hi Rich,

Thanks Your reply solved my issue.

I awarded full points to You

Thanks

Adi