04-10-2009 3:36 AM
Hello experts,
I have a code piece as follows:
*************************************************
REPORT z_obj_emp.
INCLUDE z_class_emp.
*************************************************
z_class_emp is another z report.
When I compile the report z_obj_emp, I get an syntax error:
"Each ABAP program can contain only one "REPORT", "PROGRAM", "FUNCTION-POOL" statement."
Could you please help me out to rectify this issue?
Thanks,
Mohit.
04-10-2009 4:55 AM
What is the requirement is that z_class_emp used to refer for definitions of data, types and forms .
Then what you can do is declare an include program by copying that piece of code.
This include you can mention in you report.
if you want to execute the report then what you can do is
submit program or call transaction
Regards,
Lalit Mohan Gupta.
04-10-2009 3:59 AM
Hi Mohit,
*************************************************
REPORT z_obj_emp.
INCLUDE z_class_emp.
*************************************************
In this, z_class_emp has the type as 'Executable'.
Already z_obj_emp is a report. So when u compile this one, then it executes report statement of the report z_obj_emp and also it executes report statement of report z_class_emp (It has a report statement as u said its a report).
So u need to have z_class_emp is a include and not a report. You can change type of z_class_emp from report to include. For this Goto ---> Attributes and here change type from 'executable' to 'include'.
Regards,
Sachin
04-10-2009 4:52 AM
Hello Sachin,
Thanks for the reply. I have done as you have mentioned. Now when I execute the report z_obj_emp,
I get a syntax error at the line:
create object obj_emp.
It says: "Statement is not accessible."
The whole code of z_obj_emp is:
REPORT Z_OBJ_EMP.
INCLUDE Z_CLASS_EMP.
data: p_name type string,
p_designation type string,
obj_emp type ref to c_employee.
create object obj_emp.
p_name = 'EMP1'.
p_designation = 'ACCOUNTANT'.
call method obj_emp->set_attributes exporting
im_name = p_name,
im_designation = p_designation.
call method obj_emp->display_attributes.
call method c_employee=>display_count.
***************************************************************************************
The code of include z_class_emp is:
&----
*& Include Z_CLASS_EMP
&----
class c_employee definition.
defining the access specifiers.
public section.
constants: position type i value 30.
parameterized method
methods: set_attributes importing im_name type string
im_designation type string.
method
methods: display_attributes.
static method.
class-methods: display_count.
private section.
data: name type string,
designation type string.
static variable.
class-data: st_count type i.
endclass.
class Implementation
class c_employee Implementation.
presenting the logic the methods.
method set_attributes.
name = im_name.
designation = im_designation.
st_count = st_count + 1.
endmethod.
method display_attributes.
write: / 'Name of Employee: '(001), at position name.
/ u2018Designation:'(002), at position designation.
endmethod.
method display_count.
write: / 'Total Number of Employees ',
at position st_count left-justified.
endmethod.
endclass.
Could you please let me know what the problem is now?
Thanks,
Mohit.
04-10-2009 4:17 AM
Hi Mohit,
*************************************************
REPORT z_obj_emp.
INCLUDE z_class_emp.
*************************************************
Every ABAP should have a REPORT/PROGRAM. and not more than one. Even if it has 100 includes only one report should be used. So delete the report line in include or
Now if you really need z_class_emp Program to be used in z_obj_emp, You can use Submit and Return command.
Ex: In Program z_obj_emp
REPORT z_obj_emp.
-
-
SUBMIT z_class_emp
USING SELECTION-SET 'VARIANT1'
AND RETURN.
And IMPORT from memory ID.
Hope this solves your doubts & errors clearly.
Thanks & regards,
Dileep .C
04-10-2009 4:19 AM
Check some where in the code, you have another REPORT <rep name>. comment that out.. that should fix ur issue.
04-10-2009 4:55 AM
What is the requirement is that z_class_emp used to refer for definitions of data, types and forms .
Then what you can do is declare an include program by copying that piece of code.
This include you can mention in you report.
if you want to execute the report then what you can do is
submit program or call transaction
Regards,
Lalit Mohan Gupta.
04-10-2009 5:00 AM
Hello Lalit,
I have already mentioned that include program name z_class_emp in the main report z_obj_emp.
Still its not working.
Thanks,
Mohit.
04-10-2009 5:30 AM
Hi Mohit,
This will surely solve your problem.....
just write the code of the main program under start-of-selection....
copy and paste the code given below in your main program...
REPORT Z_OBJ_EMP.
INCLUDE Z_CLASS_EMP.
data: p_name type string,
p_designation type string,
obj_emp type ref to c_employee.
START-OF-SELECTION.
create object obj_emp.
p_name = 'EMP1'.
p_designation = 'ACCOUNTANT'.
call method obj_emp->set_attributes
EXPORTING
im_name = p_name
im_designation = p_designation.
call method obj_emp->display_attributes.
call method c_employee=>display_count.
Regards,
Siddarth
04-10-2009 5:33 AM
1. is type of z_class_emp include??
if yes then you can use include z_class_emp in your report.
2. Is the type of z_class_emp executable?
if yes then you can use submit z_class_emp.
you can also call using call transaction.
Regards,
Lalit Mohan Gupta.
04-10-2009 5:43 AM
Hello Siddharth,
Thanks a lot for the reply. I am still wondering how I could miss such a small thing. This is really a very big silly mistake. The problem is solved now.
Thanks,
Mohit.