09-10-2007 6:55 PM
Hello friends,
I am writing a code. My select-option is as follows:
SELECT-OPTIONS: P_LIFNR FOR LFA1-LIFNR
,P_BUKRS FOR LFB1-BUKRS .
Constructor definition ia as follows:
METHODS:
CONSTRUCTOR
IMPORTING VALUE(I_LIFNR) TYPE LFA1-LIFNR
VALUE(I_BUKRS) TYPE LFB1-BUKRS "Buchungskreis auslesen
Now as I creat my object.
data obj type ref to class
START-OF-SELECTION.
CREATE OBJECT OBJ EXPORTING I_LIFNR = P_LIFNR.
I_BUKRS = P_BUKRS.
END-OF-SELECTION.
I am having problem because of Range type.
Message is; I_LIFNR is not type compatable with P_LIFNR. I guess this is becuase of the Range (Select-option). Using parameters: .... Solves the problem but I dont want to use parameters for my input. So how do can I solve this problem.
Blacky
09-10-2007 7:46 PM
Try this.
report zrich_0002 .
tables: lfa1, lfb1.
*---------------------------------------------------------------------*
* CLASS lcl_app DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class lcl_app definition.
public section.
types: t_lifnr type range of lfa1-lifnr.
types: t_bukrs type range of lfb1-bukrs.
methods:
constructor
importing im_lifnr type t_lifnr
im_bukrs type t_bukrs.
endclass.
*---------------------------------------------------------------------*
* CLASS lcl_app IMPLEMENTATION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class lcl_app implementation.
method constructor.
data: x_lifnr like line of im_lifnr,
x_bukrs like line of im_bukrs.
loop at im_lifnr into x_lifnr.
write:/ x_lifnr-sign, x_lifnr-option, x_lifnr-low, x_lifnr-high.
endloop.
loop at im_bukrs into x_bukrs.
write:/ x_bukrs-sign, x_bukrs-option, x_bukrs-low, x_bukrs-high.
endloop.
endmethod.
endclass.
select-options: s_lifnr for lfa1-lifnr,
s_bukrs for lfb1-bukrs .
data: obj type ref to lcl_app.
start-of-selection.
create object obj exporting im_lifnr = s_lifnr[]
im_bukrs = s_bukrs[].
end-of-selection.
Regards,
RIch Heilman
09-10-2007 7:46 PM
Try this.
report zrich_0002 .
tables: lfa1, lfb1.
*---------------------------------------------------------------------*
* CLASS lcl_app DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class lcl_app definition.
public section.
types: t_lifnr type range of lfa1-lifnr.
types: t_bukrs type range of lfb1-bukrs.
methods:
constructor
importing im_lifnr type t_lifnr
im_bukrs type t_bukrs.
endclass.
*---------------------------------------------------------------------*
* CLASS lcl_app IMPLEMENTATION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class lcl_app implementation.
method constructor.
data: x_lifnr like line of im_lifnr,
x_bukrs like line of im_bukrs.
loop at im_lifnr into x_lifnr.
write:/ x_lifnr-sign, x_lifnr-option, x_lifnr-low, x_lifnr-high.
endloop.
loop at im_bukrs into x_bukrs.
write:/ x_bukrs-sign, x_bukrs-option, x_bukrs-low, x_bukrs-high.
endloop.
endmethod.
endclass.
select-options: s_lifnr for lfa1-lifnr,
s_bukrs for lfb1-bukrs .
data: obj type ref to lcl_app.
start-of-selection.
create object obj exporting im_lifnr = s_lifnr[]
im_bukrs = s_bukrs[].
end-of-selection.
Regards,
RIch Heilman
09-11-2007 7:02 AM
Hi Richy,
Thanks very much. You are just too good. I have given max points
Blacky
09-10-2007 8:56 PM
Hello Blacky
If you have just a <u>single </u>select-option you can define an IMPORTING parameter (e.g. IT_SELOPT) of table type <b>RSELOPTION</b>. This table type has RSDSSELOPT (<i>Structure of generic SELECT-OPTION for (dynamic selections)</i>) as line type.
However, if you have <u>multiple </u>select-options (and parameters as well) then the easiest (and probably most elegant) way is to use function module RS_REFRESH_FROM_SELECTOPTIONS.
In the CONSTRUCTOR method of your class you add an EXPORTING parameter IM_CALLING_PROGRAM.
Within the CONSTRUCTOR method you call the function module with the value of the calling program (which is your selection report). The function module returns you all current selection criteria of the report. Within the constructor method you can do the mapping of <b>RSPARAMS </b>values to your actual select-options and parameters.
Have a look at class <b>CL_DBSEL_CATS</b> for a SAP standard example.
Regards
Uwe