Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Initializing Instance Attributes of a Class

Former Member
0 Likes
3,877

Dear Experts,

I want to know how can i initialize the instance attributes of a ZClass?

I have copied the standard class "CL_WB_MIME_REPOSITORY" into my ZClass as "ZCL_WB_MIME_REPOSITORY".

In the standard class we have private instance attributes as "HTML_VIEWER" and "KW_EXPLORER" and these gets initialized

automatically when i run the standard tcode SE80.

Now, when i am running my ZTcode having my ZClass, these attributes are not initialized and are NULL.

Can you please tell me how should i initialize these attributes in my ZClass and where should i write the code and what will be that code?

Thanks a lot,

Praveen

14 REPLIES 14
Read only

uwe_schieferstein
Active Contributor
0 Likes
2,674

Hello Praveen

Instance attributes are initialized within the CONSTRUCTOR method.

Static attributes can be set within the CLASS_CONSTRUCTOR method.


*---------------------------------------------------------------------*
*       METHOD constructor                                            *
*---------------------------------------------------------------------*
* stores the new object instance in class variable
*---------------------------------------------------------------------*
METHOD constructor .

  cl_wb_mime_repository=>instance = me.

ENDMETHOD.                    "constructor of CL_WB_MIME_REPOSITORY

The attribute HTML_VIEWER is instantiated in method TOGGLE_PREVIEW:


...
* Make sure HTML viewer control is created
  IF me->html_viewer IS INITIAL.
    DATA: l_html_container TYPE REF TO cl_gui_container.

* Get container for the HTML Viewer
    CALL METHOD me->splitter->get_container
      EXPORTING
        row       = wbmr_c_splitter_row_preview
        column    = 1
      RECEIVING
        container = l_html_container
      EXCEPTIONS
        OTHERS    = 1.
    IF sy-subrc <> 0.
      MESSAGE i002(mimes)
        RAISING error_occured.
*   Fehler im Control Framework
      RETURN.
    ENDIF.

* Create HTML Viewer Control
...

Regards

Uwe

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,674

Hello,

The attribute "KW_EXPLORER" is being initialised in the method PROCESS_WB_REQUEST of the associated interface IF_WB_PROGRAM. See this:


IF me->kw_explorer IS INITIAL.
        CALL METHOD me->create_kw_explorer
          EXPORTING
            i_window_id   = p_window_id
            name_space    = l_name_space
            application   = l_application
          EXCEPTIONS
            error_occured = 1.
ELSE.
 ............
ENDIF.

Similarly check how the attribute "HTML_VIEWER" is being instantiated.

Although i've not worked with the class CL_WB_MIME_REPOSITORY, what i understand is the class exposes itself to the external user via the associated IFs. (Most of the methods of the class are PRIVATE!!)

BR,

Suhas

Read only

Former Member
0 Likes
2,674

Hi Uwe, Suhas,

Thanks for the quick reply.

In the standard code of "CREATE_KW_EXPLORER" method of standard class, the below interface and method gets auto initialized when i run the Tcode SE80.

  • Initialize container

call method me->if_wb_program~wb_manager->get_window exporting

p_window_id = i_window_id

receiving

p_window = lv_window_ref

exceptions

window_not_existing = 1.

if sy-subrc ne 0.

message i001(mimes) with 'GET_WINDOW'

'CL_MIME_REPOSITORY->CREATE_KW_EXPLORER'

raising error_occured.

return.

endif.

Now, when i copy and use the Zclass with the same above code, the interface comes as NULL and the program gives me a dump saying that object is NULL.

Can you please tell me how and where should i initialize these interfaces?

Thanks,

Praveen

Read only

Former Member
0 Likes
2,674

Dear Experts,

I have debug the standard code of SE80 and got struck at a point.

In the standard code, whenever we run SE80 an object of the class "CL_WB_MIME_REPOSITORY" gets created and in that we have an interface as "IF_WB_PROGRAM" with an attribute "WB_MANAGER".

Now this interface gets initialized somewhere in the standard code and the rest of the code is based on this and it works perfect.

I am unable to find out where this interface is getting initialized, because when i am running my ZClass code this interface is coming as NULL and my ZProgram gives me a DUMP.

Can you please tell me how and where should i initialize this interface in my ZClass so that my code works similar to that of the standard one?

Thanks,

Praveen

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,674

Hello Praveen,

Did you read my response thoroughly? Have a look & in case of have any more questions feel free to shoot!

BR,

Suhas

PS: You don't have to debug to understand the basic functionality of the class;-) All the elements are so closely knit in the class builder that mere navigation gives you sufficient idea.

Read only

Former Member
0 Likes
2,674

Hi Suhas,

Thanks for the reply.

I did read through your eariler post and understood where "HTML_VIEWER" and "KW_EXPLORER" are being initialized.

All of this logic for initializing the objects is based on the interface "IF_WB_PROGRAM~WB_PROGRAM".

Now when i am using the same interface in my ZClass, this interface is coming as NULL, while this comes auto initialized for the standard class "CL_WB_MIME_REPOSITORY" with the object value = "".

Can you please tell me how should i update my ZClass so that this interface will not be NULL?

Thanks,

Praveen

Read only

naimesh_patel
Active Contributor
0 Likes
2,674

Looks like you have copied the class CL_WB_MIME_REPOSITORY to your Z class, but didn't change the use of all Static Variables of the class CL_WB_MIME_REPOSITORY. In your Z class search the string CL_WB_MIME_REPOSITORY. You may find occurrence where your Z class is still using the static variables of the CL_WB_MIME_REPOSITORY. If you may want to replace them and try again!

Regards,

Naimesh Patel

Read only

0 Likes
2,674

Hi Naimesh,

Thanks for the reply.

I have already commented all the occurences of "CL_WB_MIME_REPOSITORY" in my ZClass.

Can you exaplain your point about static variables in more details?

Thanks & Regards,

Praveen

Read only

0 Likes
2,674

Hi Experts,

I would also like to tell you that, the standard class is being used in "SE80" Tcode i.e. Workbench Navigator.

My ZClass which is a copy of standard class is used in my ZTcode only.

I think there must be some relation of interface "IF_WB_PROGRAM" in Tcode "SE80" which is missing in my ZTcode.

Can you please help me out on this?

Thanks,

Praveen

Read only

0 Likes
2,674

Based on your questions I'd like to know one thing: why are you copying and trying to change the standard class, what is your requirement? Based on your questions I think you don't have enough understanding of ABAP OO, and to do this copy you should have this understanding and do an analysis beforehand.

Maybe you're trying to achieve your requirement by copying when you could use an enhancement or something simpler...

Just an idea.

Regards

Read only

0 Likes
2,674

Hi Alejandro,

My requirement is to open the MIME content which i save in SE80 on my ZScreen just similar to the "PREVIEW" option that we have in SE80 for MIME Repository.

When i have checked the code of SE80, its using the class "CL_WB_MIME_REPOSITORY" and the method "PREVIEW_MIME" to show the MIME object in the previewer.

I want the same logic of showing the MIME content in my ZScreen.

I dont think we have any User Exit or anything else for this.

I hope my question is clear to you now.

Can you tell me how can we achieve this?

Thanks,

Praveen

Read only

0 Likes
2,674

I did a quick look at the method and it seems the core funcionality is in the SKWF_PHIO_LOAD_CONTENT function module...then I did a usage reference an it's used from lots of places, including the class CL_MIME_REPOSITORY_API which seems to be a good candidate for you to USE (not copy).

You should handle in your program your own instance of an HTML viewer (CL_GUI_HTML_VIEWER) and then use the above class to load the contents...

Hope this helps.

Regards

Read only

0 Likes
2,674

Hi Alejandro,

Thanks for the help on this.

I have created a new object of container as "MYCONTAINER" with object value = "".

One thing i noticed in this, the " CUR_EVENT" which is a public attribute comes as "INITIAL" and "PARENT" which is a public instance attribute comes as "INITIAL".

Now when i am trying to create an object of html viewer as "my_html_viewer" passing the below parameteres, it gives me an exception as below.

create object my_html_viewer

exporting

CLSID = SAP.HTMLControl.1

PARENT =

Exception:-

Short text

Access via 'NULL' object reference not possible.

What happened?

Error in the ABAP Application Program

The current ABAP program "CL_GUI_CFW====================CP" had to be

terminated because it has

come across a statement that unfortunately cannot be executed.

Error analysis

You attempted to use a 'NULL' object reference (points to 'nothing')

access a component (variable: " ").

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.

Trigger Location of Runtime Error

Program CL_GUI_CFW====================CP

Include CL_GUI_CFW====================CCIMP

Row 393

Module type (METHOD)

Module Name LCL_GET_SHELLID

Source Code Extract

Line SourceCde

363 ENDCLASS.

364 CLASS LCL_DRAGDROPHELPER IMPLEMENTATION.

365 METHOD GET_DROP_EVT_PARAM.

366 STATICS : PARAMHELPER TYPE REF TO LCL_LOCAL_DDPARAMS.

367

368 CLEAR DRAGDROPPARAM.

369 CREATE OBJECT PARAMHELPER.

370 CALL METHOD PARAMHELPER->GETPARAMS.

371 IF SY-SUBRC NE 0.

372 RAISE ERROR_GET_OBJ.

373 ENDIF.

374 DRAGDROPPARAM = PARAMHELPER.

375 ENDMETHOD.

376

377 METHOD CLEAR_DROP_EVT_PARAM.

378 CLEAR DRAGDROPPARAM.

379 ENDMETHOD.

380

381 ENDCLASS.

382 class lcl_friend_of_gui_control implementation.

383 method get_reg_events_internal.

384 call method control->get_registered_events_ex

385 importing eventtab = events

386 exceptions cntl_error = 1

387 others = 2.

388 if sy-subrc ne 0.

389 raise cntl_error.

390 endif.

391 endmethod.

392 METHOD LCL_GET_SHELLID.

>>>>> SHELLID = REF->H_CONTROL-SHELLID.

394 ENDMETHOD.

395 endclass.

396 class lcl_dynpro implementation.

397

398 method constructor.

399 move: program to me->program,

400 DYNNR to me->dynnr,

401 TOP_PARENTID to me->TOP_PARENT

402 STACKLEVEL to me->stacklevel

403 endmethod.

404

405 method get_total_extensions.

406 x = total_extension-x.

407 y = total_extension-y.

408 endmethod.

409

410 method set_total_extensions.

411 total_extension-x = x.

412 total_extension-y = y.

Can you please help me out with this?

Thanks,

Praveen

Read only

0 Likes
2,674

Dear Experts,

I solved this problem at my end only.

Thanks for all the help.

Thanks,

Praveen