Code: Alles auswählen.
CLASS lcl_employee DEFINITION.
PUBLIC SECTION.
METHODS:
constructor IMPORTING value(set_n_o_employees) TYPE i,
set_name IMPORTING set_name TYPE string,
set_firstname IMPORTING set_firstname TYPE string,
set_adresse IMPORTING set_adresse TYPE string,
set_dob IMPORTING set_dob TYPE d,
get_name RETURNING value(get_name) TYPE string,
get_firstname RETURNING value(get_firstname) TYPE string,
get_adresse RETURNING value(get_adresse) TYPE string,
get_dob RETURNING value(get_dob) TYPE d,
get_base_salary RETURNING value(get_base_salary) TYPE i,
"get_salary RETURNING VALUE(get_base_salary TYPE i,
print.
"get_fullname RETURNING VALUE(re_fullname) TYPE string.
DATA:
name TYPE string,
firstname TYPE string,
adresse TYPE string,
dob TYPE d,
base_salary TYPE i.
TYPES:
BEGIN OF str_company,
name TYPE string,
firstname TYPE string,
adresse TYPE string,
dob TYPE d,
base_salary TYPE i,
END OF str_company.
DATA itab_company TYPE STANDARD TABLE OF str_company.
DATA: company TYPE str_company.
CLASS-DATA n_o_employees TYPE i VALUE 0.
PRIVATE SECTION.
METHODS: init_base_salary IMPORTING im_base_salary TYPE i.
ENDCLASS. "lcl_employee DEFINITION
Code: Alles auswählen.
CLASS lcl_employee IMPLEMENTATION.
METHOD set_name.
name = set_name.
ENDMETHOD. "set_name
METHOD set_firstname.
firstname = set_firstname.
ENDMETHOD. "set_firstname
METHOD set_adresse.
adresse = set_adresse.
ENDMETHOD. "set_adresse
METHOD set_dob.
dob = set_dob.
ENDMETHOD. "set_dob
METHOD get_adresse.
get_adresse = adresse.
ENDMETHOD. "get_adresse
METHOD get_name.
get_name = name.
ENDMETHOD. "get_name
METHOD get_firstname.
get_firstname = firstname.
ENDMETHOD. "get_firstname
METHOD get_dob.
get_dob = dob.
ENDMETHOD. "get_dob
METHOD get_base_salary.
get_base_salary = base_salary.
ENDMETHOD. "get_base_salary
* METHOD get_fullname.
* gg_name = name.
* gg_firstname = firstname.
* ENDMETHOD. "get_fullname
METHOD constructor.
IF sy-subrc NE 0.
LEAVE PROGRAM.
ELSE.
set_n_o_employees = n_o_employees + 1.
ENDIF.
ENDMETHOD. "Constructor
METHOD print.
TYPES:
BEGIN OF str_company,
name TYPE string,
firstname TYPE string,
adresse TYPE string,
dob TYPE d,
base_salary TYPE i,
END OF str_company.
DATA itab_company TYPE STANDARD TABLE OF str_company.
DATA: company TYPE str_company.
* LOOP AT itab_company INTO company.
* APPEND company TO itab_company.
* ENDLOOP.
LOOP AT itab_company INTO company.
WRITE: company-name,
company-firstname,
company-adresse,
company-dob,
company-base_salary.
ENDLOOP.
ENDMETHOD. "print
METHOD init_base_salary.
IF base_salary > 0.
WRITE base_salary.
ELSE.
base_salary = '0'.
ENDIF.
ENDMETHOD. "init_base_salary
ENDCLASS. "lcl_employee IMPLEMENTATION
Code: Alles auswählen.
REPORT z_1000_company.
INCLUDE z_1000_company_classes.
PARAMETERS:
p_name(50) TYPE c,
p_fname(50) TYPE c,
p_adr(50) TYPE c,
p_dob TYPE d,
p_bsal TYPE i.
START-OF-SELECTION.
DATA r_employee TYPE REF TO lcl_employee.
DATA n_o_employees TYPE REF TO lcl_employee.
*
CREATE OBJECT r_employee EXPORTING set_n_o_employees = '0'.
r_employee->firstname = p_fname.
r_employee->adresse = p_adr.
r_employee->dob = p_dob.
r_employee->base_salary = p_bsal.
CALL METHOD:
* r_employee->set_name,
* r_employee->set_adresse,
* r_employee->set_firstname,
r_employee->get_name,
r_employee->get_firstname,
r_employee->get_dob,
* r_employee->set_dob,
r_employee->get_adresse,
r_employee->print.
ähm... Könntest du das bitte näher spezifizieren.Trulchen hat geschrieben:SO jetzt will ich innerhalb der print methode die Daten in eine Interne Tabelle aus meinen Parameter ( code folgt unten) auslesen und schreiben.
Code: Alles auswählen.
data: lt_emploee type standard table of ref to lcl_emploee with NON-unique default key.
Name: xxxx Vorname: aaaaaa Adresse: yyyyyy Gehalt: sssssssDamit die Attribute verwendet werden können, müssen aufgrund der Sichtbarkeitsvorgabe entsprechende Methoden geschaffen werden. Implementieren Sie daher als nächstes alle get- und set-Instanzmethoden Die Methode print soll mithilfe der WRITE-Anweisung eine einfache Ausgabe von vollem Namen, Adresse, Gehalt und Alter realisieren.. Erstellen Sie als nächstes eine interne Tabelle mit Referenzen auf Mitarbeiter (it_employees), und fügen Sie den erstellten Mitarbeiter in diese Tabelle ein.
Wie das geht hab ich bereits in meinen ersten Post angeführt. Hinzufügen funktioniet dann ganz normal mit APPEND.Erstellen Sie als nächstes eine interne Tabelle mit Referenzen auf Mitarbeiter (it_employees), und fügen Sie den erstellten Mitarbeiter in diese Tabelle ein.
Code: Alles auswählen.
METHOD print.
TYPES:
BEGIN OF company,
name TYPE string,
firstname TYPE string,
adresse TYPE string,
dob TYPE d,
base_salary TYPE i,
END OF company.
Data: lt_employee type standard table of ref to lcl_employee with NON-unique default key.
DATA company TYPE REF TO lcl_employee.
LOOP AT lt_employee INTO company.
APPEND company to lt_employee.
WRITE: name,
firstname,
adresse,
dob,
base_salary.
ENDLOOP.
ENDMETHOD. "print
Code: Alles auswählen.
REPORT z_1000_company.
INCLUDE z_1000_company_classes.
PARAMETERS:
p_name(50) TYPE c,
p_fname(50) TYPE c,
p_adr(50) TYPE c,
p_dob TYPE d,
p_bsal TYPE i.
START-OF-SELECTION.
DATA r_employee TYPE REF TO lcl_employee.
DATA n_o_employees TYPE REF TO lcl_employee.
*
CREATE OBJECT r_employee EXPORTING set_n_o_employees = '0'.
r_employee->firstname = p_fname.
r_employee->adresse = p_adr.
r_employee->dob = p_dob.
r_employee->base_salary = p_bsal.
CALL METHOD:
r_employee->get_name,
r_employee->get_firstname,
r_employee->get_dob,
r_employee->get_adresse,
r_employee->print.
Code: Alles auswählen.
METHOD print.
WRITE: me->name,
me->firstname,
me->adresse,
me->dob,
me->base_salary.
ENDMETHOD.
Code: Alles auswählen.
PUBLIC SECTION.
METHODS:
constructor IMPORTING set_n_o_employees TYPE i
set_name TYPE c
set_firstname TYPE c
set_adresse TYPE c
set_dob TYPE d,
set_name IMPORTING set_name TYPE c,
set_firstname IMPORTING set_firstname TYPE c,
set_adresse IMPORTING set_adresse TYPE c,
set_dob IMPORTING set_dob TYPE d,
set_base_salary IMPORTING set_base_salary TYPE i,
get_name RETURNING value(get_name) TYPE string,
get_firstname RETURNING value(get_firstname) TYPE string,
get_adresse RETURNING value(get_adresse) TYPE string,
get_dob RETURNING value(get_dob) TYPE d,
get_base_salary RETURNING value(get_base_salary) TYPE i,
"get_salary RETURNING VALUE(get_base_salary TYPE i,
print.
"get_fullname RETURNING VALUE(re_fullname) TYPE string.
PRIVATE SECTION.
DATA:
name TYPE c,
firstname TYPE c,
adresse TYPE c,
dob TYPE d,
base_salary TYPE i.
CLASS-DATA n_o_employees TYPE i VALUE 0.
METHODS: init_base_salary IMPORTING im_base_salary TYPE i.
Code: Alles auswählen.
METHOD print.
WRITE: me->name,
me->firstname,
me->adresse,
me->dob,
me->base_salary.
ENDMETHOD. "print
Code: Alles auswählen.
INCLUDE z_1000_company_classes.
DATA:
name TYPE string.
PARAMETERS:
p_name TYPE c,
p_fname TYPE c,
p_adr TYPE c,
p_dob TYPE d,
p_bsal TYPE i.
START-OF-SELECTION.
DATA r_employee TYPE REF TO lcl_employee.
DATA n_o_employees TYPE REF TO lcl_employee.
*
CREATE OBJECT r_employee EXPORTING set_name = ''.
set_firstname = ''
set_adresse = ''
set_dob = '12.34.56'.
*
CALL METHOD:
r_employee->get_name RECEIVING get_name = p_fname,
r_employee->get_firstname RECEIVING get_firstname = p_fname,
r_employee->get_dob RECEIVING get_dob = p_dob,
r_employee->get_adresse RECEIVING get_adresse = p_adr ,
r_employee->get_base_salary RECEIVING get_base_salary = p_bsal,
r_employee->print.
Code: Alles auswählen.
<Art><Typ>_<Name>
IT_DATA "Importing-Parameter der tabellarisch ist.
ET_TEXT "Exporting-Parameter der tabellarisch ist.
CD_COUNT "Changing-Parameter der ein Datenelement ist.
IR_EMPLOYEE "Importing-Parameter der eine Daten- oder Objektreferenz ist.
GD_NAME "Globale Variable oder Attribut eines Datenelements.
LT_STRING "Lokale Variable die Tabellarisch ist.
Code: Alles auswählen.
CLASS lcl_department DEFINITION.
PUBLIC SECTION.
METHODS:
constructor IMPORTING it_abteilungsname TYPE c,
set_abteilungsname IMPORTING im_abteilungsname TYPE c,
get_abteilungsname RETURNING value(rv_abteilungsname) TYPE string,
add_employee IMPORTING im_employees TYPE c,
print.
PRIVATE SECTION.
DATA:
abteilungsname TYPE c,
it_employees TYPE REF TO lcl_employee.
ENDCLASS.
Eigentlich ist die Aufgabenstellung doch klar und von dir auch richtig umgesetzt. Du kannst nur je eine GET/SET-Methode anlegen, da du auch nur ein privates Klassenmerkmal (Abteilungsname) hast.Trulchen hat geschrieben:Definieren Sie dann zunächst ein Attribut name für den Namen der Abteilung sowie entsprechende get- und set-Methoden (analog zur Mitarbeiterklasse). --> Hier ist die Frage muss ich ALLE get und set übernehmen also auch von lcl_employees ?
Trulchen hat geschrieben:Wie muss die Methode add_employee programmiert werden?
Code: Alles auswählen.
CLASS lcl_department DEFINITION.
PUBLIC SECTION.
METHODS:
constructor IMPORTING iv_abteilungsname TYPE c,
set_abteilungsname IMPORTING iv_abteilungsname TYPE c,
get_abteilungsname RETURNING value(rv_abteilungsname) TYPE string
add_employee IMPORTING ir_employees TYPE REF TO lcl_employee.
PRIVATE SECTION.
DATA:
mv_abteilungsname TYPE c,
mt_employees TYPE REF TO lcl_employee.
*In der Methodeimplementation:
ADD ir_employees TO mt_employees.
Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Include Z_1000_COMPANY_2_CLASSES
*&---------------------------------------------------------------------*
CLASS lcl_employee DEFINITION.
PUBLIC SECTION.
METHODS:
constructor IMPORTING it_name TYPE c
it_firstname TYPE c
it_adresse TYPE c
it_dob TYPE d
it_salary TYPE i,
set_name IMPORTING it_name TYPE c,
set_firstname IMPORTING it_firstname TYPE c,
set_adresse IMPORTING it_adresse TYPE c,
set_dob IMPORTING it_dob TYPE d,
get_fullname RETURNING value(rv_fullname) TYPE string,
get_name RETURNING value(rv_name) TYPE string,
get_firstname RETURNING value(rv_firstname) TYPE string,
get_adresse RETURNING value(rv_adresse) TYPE string,
get_dob RETURNING value(rv_dob) TYPE d,
get_base_salary RETURNING value(rv_base_salary) TYPE i,
get_salary RETURNING value(rv_salary) TYPE i ,
init_base_salary RETURNING value(im_base_salary) TYPE i,
get_n_o_employees RETURNING value(rv_n_o_employees) TYPE i,
print.
PRIVATE SECTION.
DATA:
name(10) TYPE c,
firstname(10) TYPE c,
adresse(30) TYPE c,
dob TYPE d,
base_salary TYPE i,
fullname(20) TYPE c,
salary TYPE i,
heute TYPE sy-datum,
diff TYPE i.
CLASS-DATA n_o_employees TYPE i VALUE 0.
ENDCLASS. "lcl_employee DEFINITION
CLASS lcl_employee IMPLEMENTATION.
METHOD set_name.
name = it_name.
ENDMETHOD. "set_name
METHOD set_firstname.
firstname = it_firstname.
ENDMETHOD. "set_firstname
METHOD set_adresse.
adresse = it_adresse.
ENDMETHOD. "set_adresse
METHOD set_dob.
dob = it_dob.
ENDMETHOD. "set_dob
METHOD get_adresse.
rv_adresse = adresse.
ENDMETHOD. "get_adresse
METHOD get_name.
rv_name = name.
ENDMETHOD. "get_name
METHOD get_firstname.
rv_firstname = firstname.
ENDMETHOD. "get_firstname
METHOD get_dob.
rv_dob = dob.
ENDMETHOD. "get_dob
METHOD get_base_salary.
rv_base_salary = base_salary.
ENDMETHOD. "get_base_salary
METHOD get_salary.
diff = sy-datum - dob.
IF diff > 14600.
salary = base_salary + ( base_salary * '0.05' ).
ELSEIF diff > 18250.
salary = base_salary + ( base_salary * '0.10' ).
ELSE.
salary = base_salary.
ENDIF.
rv_salary = salary.
ENDMETHOD. "get_salary
METHOD get_fullname.
DATA sep(3) TYPE c VALUE ' '.
CONCATENATE name firstname INTO fullname SEPARATED BY sep.
rv_fullname = fullname.
ENDMETHOD. "get_fullname
METHOD constructor.
name = it_name.
firstname = it_firstname.
adresse = it_adresse.
dob = it_dob.
base_salary = it_salary.
n_o_employees = n_o_employees + 1.
ENDMETHOD. "Constructor
METHOD print.
DATA:
ld_fullname TYPE char50, "CHAR damit die Breite in der Ausgabe immer gleich ist
ld_salary TYPE i.
ld_fullname = me->get_fullname( ).
ld_salary = me->get_salary( ).
WRITE: / 'Name:', ld_fullname, 'Adresse:', adresse, 'Geburtstdatum:', dob , 'Gehalt:', ld_salary.
ENDMETHOD. "print
METHOD init_base_salary.
IF salary < 0.
base_salary = 0.
ELSE.
salary = salary.
ENDIF.
ENDMETHOD. "init_base_salary
METHOD get_n_o_employees.
rv_n_o_employees = n_o_employees.
WRITE: 'Es wurden', n_o_employees, 'Objekte erzeugt'.
ENDMETHOD. "get_n_o_employees
ENDCLASS. "lcl_employee IMPLEMENTATION
CLASS lcl_office_employee DEFINITION INHERITING FROM lcl_employee.
PUBLIC SECTION.
METHODS:
constructor IMPORTING it_name TYPE c
it_firstname TYPE c
it_adresse TYPE c
it_dob TYPE d
it_salary TYPE i
im_office TYPE c,
set_office IMPORTING im_office TYPE c,
get_office RETURNING VALUE(rv_office) TYPE string,
print REDEFINITION.
PRIVATE SECTION.
DATA:
office(20) TYPE c.
ENDCLASS.
CLASS lcl_office_employee IMPLEMENTATION.
METHOD constructor.
SUPER->CONSTRUCTOR( it_name = it_name
it_firstname = it_firstname
it_adresse = it_adresse
it_dob = it_dob
it_salary = it_salary ).
office = im_office.
ENDMETHOD.
METHOD set_office.
office = office.
ENDMETHOD. "set_dob
METHOD get_office.
rv_office = office.
ENDMETHOD.
METHOD print.
super->print( ).
WRITE: 'Abteilung:', office.
ENDMETHOD.
ENDCLASS.
CLASS lcl_field_staff DEFINITION INHERITING FROM lcl_employee.
PUBLIC SECTION.
METHODS:
constructor IMPORTING it_name TYPE c
it_firstname TYPE c
it_adresse TYPE c
it_dob TYPE d
it_salary TYPE i
im_percentage TYPE i
im_sales TYPE i,
print REDEFINITION,
set_percentage IMPORTING im_percentage TYPE i,
get_percentage RETURNING VALUE(rv_percentage) TYPE string,
set_sales IMPORTING im_sales TYPE i,
get_sales RETURNING VALUE(rv_sales) TYPE string.
PRIVATE SECTION.
DATA:
percentage TYPE i,
sales TYPE P.
ENDCLASS.
CLASS lcl_field_staff IMPLEMENTATION.
METHOD constructor.
SUPER->CONSTRUCTOR( it_name = it_name
it_firstname = it_firstname
it_adresse = it_adresse
it_dob = it_dob
it_salary = it_salary ).
percentage = im_percentage.
sales = im_sales.
ENDMETHOD.
METHOD set_percentage.
percentage = im_percentage.
ENDMETHOD. "set_dob
METHOD get_percentage.
rv_percentage = percentage.
ENDMETHOD.
METHOD set_sales.
sales = im_sales.
ENDMETHOD. "set_dob
METHOD get_sales.
rv_sales = sales.
ENDMETHOD. "
METHOD print.
super->print( ).
.
WRITE: 'Verkäufe', sales , 'Provision', percentage.
ENDMETHOD.
ENDCLASS.
CLASS lcl_department DEFINITION.
PUBLIC SECTION.
METHODS:
constructor IMPORTING iv_abteilungsname TYPE c,
set_abteilungsname IMPORTING iv_abteilungsname TYPE c,
get_abteilungsname RETURNING value(rv_abteilungsname) TYPE string,
add_employee IMPORTING ir_employees TYPE REF TO lcl_employee,
print.
PRIVATE SECTION.
DATA:
mv_abteilungsname(20) TYPE c,
mt_employees TYPE REF TO lcl_employee.
ENDCLASS. "lcl_department DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_department IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_department IMPLEMENTATION.
METHOD set_abteilungsname.
mv_abteilungsname = iv_abteilungsname.
ENDMETHOD. "set_Abteilungsname
METHOD get_abteilungsname.
rv_abteilungsname = mv_abteilungsname.
ENDMETHOD. "get_Abtelungsname
METHOD add_employee.
"ADD ir_employees TO mt_employees.
ENDMETHOD. "add_employee
METHOD constructor.
mv_abteilungsname = iv_abteilungsname.
ENDMETHOD. "constructor
METHOD print.
WRITE: / 'Mitarbeiter der Abteilung', mv_abteilungsname,
/ .
ENDMETHOD. "print
ENDCLASS. "lcl_department IMPLEMENTATION
Ich bin da jetzt etwas verwirrt, etwender kapiere ich die ganze Aufgebenstellung nicht oder ich weiß nicht....Für diese Berechnung benötigen Sie einen Down-Cast auf die Außendienstmitarbeiter-Klasse, da in der Abteilungsklasse nur über Referenzen der Klasse lcl_employee auf die Mitarbeiterobjekte zugegriffen wird, so jedoch die benötigte get-Methoden zum Zugriff auf die Provision nicht erreicht werden kann.
Code: Alles auswählen.
CLASS lcl_department IMPLEMENTATION.
METHOD get_avg_percentage.
DATA: r_employee TYPE REF TO lcl_employee,
r_außen_employee TYPE REF TO lcl_department.
TRY.
r_außen_employee ?= r_aemployee.
CATCH ????????....
LEAVE PROGRAM.
ENDTRY.