‎2007 Apr 20 6:19 AM
In SRM,i have a program to write sth to EXCEL, but when the program call the method as follow,there will happen a exception:
CALL METHOD SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = P_NAME
LEFT = P_COLUMN
TOP = P_ROW
ROWS = 1
COLUMNS = 1
NO_FLUSH = 'X'
UPDATING = UPDATING
SHEETNAME = SHEETNAME
IMPORTING
ERROR = ERROR
RETCODE = RETCODE.
the error information as follows:
Runtime Errors OBJECTS_OBJREF_NOT_ASSIGNED_NO
Exception CX_SY_REF_IS_INITIAL
hort text
Access via 'NULL' object reference not possible.
‎2007 Apr 20 3:24 PM
It seems to me that you haven't created an instance of the class.
eg. CREATE OBJECT SPREADSHEET
It needs to be declared before the call to the method.
Regards,
Dirk.
‎2007 Apr 23 2:36 AM
Follow is my original code:
***********
CALL FUNCTION 'DP_PUBLISH_WWW_URL'
EXPORTING
OBJID = 'ZSRM_TMX_PRINT'
LIFETIME = 'T'
IMPORTING
URL = URL.
CALL METHOD C_OI_CONTAINER_CONTROL_CREATOR=>GET_CONTAINER_CONTROL
IMPORTING
CONTROL = CONTROL
ERROR = ERROR.
CALL METHOD ERROR->RAISE_MESSAGE
EXPORTING
TYPE = 'E'.
CREATE OBJECT CONTAINER
EXPORTING
CONTAINER_NAME = 'VIEW'.
CALL METHOD CONTAINER->SET_VISIBLE
EXPORTING VISIBLE = ' '.
CALL METHOD CONTROL->INIT_CONTROL
EXPORTING
R3_APPLICATION_NAME = 'SRM'
INPLACE_ENABLED = INPLACE
INPLACE_SCROLL_DOCUMENTS = 'X'
PARENT = CONTAINER
REGISTER_ON_CLOSE_EVENT = 'X'
REGISTER_ON_CUSTOM_EVENT = 'X'
NO_FLUSH = 'X'
IMPORTING
ERROR = ERRORS.
APPEND ERRORS.
CALL METHOD CONTROL->GET_DOCUMENT_PROXY
EXPORTING
DOCUMENT_TYPE = 'Excel.Sheet'
IMPORTING
DOCUMENT_PROXY = DOCUMENT
ERROR = ERRORS.
APPEND ERRORS.
CALL METHOD DOCUMENT->OPEN_DOCUMENT
EXPORTING
OPEN_INPLACE = INPLACE
DOCUMENT_URL = URL
IMPORTING
ERROR = ERRORS.
APPEND ERRORS.
CREATE OBJECT SPREADSHEET.
CALL METHOD DOCUMENT->GET_SPREADSHEET_INTERFACE
EXPORTING
NO_FLUSH = ' '
IMPORTING
SHEET_INTERFACE = SPREADSHEET
ERROR = ERRORS.
APPEND ERRORS.
LOOP AT ERRORS.
CALL METHOD ERROR->RAISE_MESSAGE
EXPORTING
TYPE = 'E'.
ENDLOOP.
FREE ERRORS.
......
CALL METHOD SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = P_NAME
LEFT = P_COLUMN
TOP = P_ROW
ROWS = 1
COLUMNS = 1
NO_FLUSH = 'X'
UPDATING = UPDATING
SHEETNAME = SHEETNAME
IMPORTING
ERROR = ERROR
RETCODE = RETCODE.
*******
when i add the code
CREATE OBJECT SPREADSHEET.
the system tell me:
"SPREADSHEET" is not an object reference
‎2007 Apr 23 5:29 AM
hi,
In OOABAP you have to declare an object and then create the object. You can check the class name in the method that is importing spreadsheet.
DATA : spreadsheet TYPE REF TO <class-name> "declaration of object spread sheet which has the class type class-name
CREATE OBJECT spreadsheet. "creation of object.
Hope this helps.
Regards,
Richa
‎2007 Apr 23 4:45 AM
Wei,
In your program did you inclue below code.
include ole2incl.
Don't forget to reward if useful....
‎2007 Apr 23 5:19 AM
Before the create object you please declare the spreadsheet as type ref to the class.
See the class type from FM 's parameters.
then :
spreadsheet type ref to <class name>.
create object spreadsheet.
points please if useful.....
‎2007 Apr 23 5:30 AM
to Richa:
i have declare the SPREADSHEET as follows
DATA: SPREADSHEET TYPE REF TO I_OI_SPREADSHEET.
‎2007 Apr 23 5:34 AM
hi,
It looks like I_OI_SPREADSHEET is not a class, it is an interface. You cannot create instance of any interface. However, you can create your own local class and implement this interface in this class. Then you can create an object of your local class.
Hope this helps.
Regards,
Richa
‎2007 Apr 23 5:36 AM
It seems a little difficult for me, can you give me a example?
Thanks in advanced!
‎2007 Apr 23 5:50 AM
the erro happens when call
CALL METHOD SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = P_NAME
TOP = P_ROW
LEFT = P_COLUMN
ROWS = 1
COLUMNS = 1.
Error detail:
Runtime Errors OBJECTS_OBJREF_NOT_ASSIGNED_NO
Exception CX_SY_REF_IS_INITIAL
You attempted to use a 'NULL' object reference (points to 'nothing')
access a component.
An object reference must point to an object (an instance of a class)
before it can be used to access components.
Either the reference was never set or it was set to 'NULL' using the
CLEAR statement.
‎2007 Apr 23 12:56 PM
Hi,
Maybe following <a href="http://help.sap.com/saphelp_47x200/helpdata/en/21/b53144e1ba11d2bdbe080009b4534c/content.htm">link</a>
could help you.