
method search.
loop at guitars assigning field-symbol(<guitar>).
if <guitar>-ref->attributes-builder = i_guitar_to_search->attributes-builder
and <guitar>-ref->attributes-model = i_guitar_to_search->attributes-model
and <guitar>-ref->attributes-type = i_guitar_to_search->attributes-type
and <guitar>-ref->attributes-backwood = i_guitar_to_search->attributes-backwood
and <guitar>-ref->attributes-topwood = i_guitar_to_search->attributes-topwood.
r_found_guitar = <guitar>-ref.
return.
endif.
endloop.
endmethod.
class zcl_guitar_spec definition
public
final
create public .
public section.
types: begin of ty_guitar_attributes,
builder type ref to zcl_enum_builder,
model type z_guitar_model,
type type ref to zcl_enum_guit_type,
backwood type ref to zcl_enum_wood,
topwood type ref to zcl_enum_wood,
end of ty_guitar_attributes.
data: attributes type ty_guitar_attributes read-only.
methods: constructor importing i_attributes type ty_guitar_attributes,
matches importing i_otherspec type ref to zcl_guitar_spec
returning value(r_matches) type abap_bool.
protected section.
private section.
endclass.
method matches.
if me->attributes-builder <> i_otherspec->attributes-builder.
r_matches = abap_false.
return.
endif.
if ( i_otherspec->attributes-model is not initial ) and ( me->attributes-model
<> i_otherspec->attributes-model ).
r_matches = abap_false.
return.
endif.
if me->attributes-backwood <> i_otherspec->attributes-backwood.
r_matches = abap_false.
return.
endif.
if me->attributes-topwood <> i_otherspec->attributes-topwood.
r_matches = abap_false.
return.
endif.
if me->attributes-type <> i_otherspec->attributes-type.
r_matches = abap_false.
return.
endif.
r_matches = abap_true.
return.
endmethod.
class zcl_guitar definition
public
final
create public .
public section.
types: begin of ty_guitar_attributes,
serialnumber type z_serial_number,
price type z_price,
specs type ref to zcl_guitar_spec,
end of ty_guitar_attributes.
data: attributes type ty_guitar_attributes read-only.
"! <p class="shorttext synchronized" lang="en"></p>
"! Creates a guitar object from a guitar structure
"! @parameter i_guitar_record | <p class="shorttext synchronized" lang="en"> Guitar structure </p>
methods constructor
importing
i_guitar_record type ty_guitar_attributes.
protected section.
private section.
endclass.
class zcl_guitar implementation.
method constructor.
me->attributes = i_guitar_record.
endmethod.
endclass.
"! <p class="shorttext synchronized" lang="en"></p>
"! Iterates through the inventory, comparing each property of the i_guitar object with the guitar
"! inside the inventory. Returns a guitar object only if all of the properties match
"! @parameter i_guitar_to_search | <p class="shorttext synchronized" lang="en"> Guitar to search</p>
"! @parameter r_found_guitars | <p class="shorttext synchronized" lang="en">Guitar found in the inventory</p>
methods search
importing
i_guitar_spec type ref to zcl_guitar_spec
returning
value(r_found_guitars) type guitars_tab.
method search.
loop at guitars assigning field-symbol(<guitar>).
data(search_specs) = <guitar>-ref->attributes-specs.
if <guitar>-ref->attributes-specs->matches( search_specs ).
data(found_guitar) = value ty_guitar( serial_number = <guitar>-ref->attributes-serialnumber
ref = <guitar>-ref ).
insert found_guitar into table r_found_guitars.
endif.
endloop.
endmethod.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |