Application Development 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: 

How to create instance :

Former Member
0 Kudos
198

Hai gurues,

I have one modification project, in that one line is declared like this.

go_infty = cl_hrsen_read_infotype_fmri=>get_instance( ).

Here i don't know about which one is instance and how it's act etc.

*"----


""Local Interface:

*" IMPORTING

*" VALUE(EMPLOYEE_NO) TYPE P_PERNR

*" TABLES

*" ET_EMP_QUALIFICATION STRUCTURE ZEMP_QUALIFICATION OPTIONAL

*"----


DATA: go_infty TYPE REF TO if_hrsen_read_infotype.

DATA: gt_prelp_tab TYPE prelp_tab .

DATA: gt_0024 TYPE TABLE OF p0024,

wa_p0024 TYPE p0024,

lt_t574b TYPE TABLE OF t574b,

wa_t574b TYPE t574b,

lt_t777q TYPE TABLE OF t777q,

wa_t777q TYPE t777q.

go_infty = cl_hrsen_read_infotype_fmri=>get_instance( ).

*---- Fetch the data from p0024----


CALL METHOD go_infty->read

EXPORTING

pernr = employee_no

infty = '0024'

begda = '18000101'

endda = '99991231'

no_auth_check = space

IMPORTING

infotype_tab = gt_prelp_tab

EXCEPTIONS

e_assertion = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

*----


Type conversion of Pnnnn structures into PRELP

CALL METHOD cl_hr_pnnnn_type_cast=>prelp_to_pnnnn_tab

EXPORTING

prelp_tab = gt_prelp_tab

IMPORTING

pnnnn_tab = gt_0024.

*----


Qualification Names -


IF gt_0024[] IS NOT INITIAL.

SELECT * FROM t574b INTO TABLE lt_t574b

FOR ALL ENTRIES IN gt_0024

WHERE quali = gt_0024-quali AND

langu = sy-langu.

ENDIF.

*----


Proficiency Texts -


IF gt_0024[] IS NOT INITIAL.

SELECT * FROM t777q INTO TABLE lt_t777q

FOR ALL ENTRIES IN gt_0024

WHERE chara = gt_0024-auspr AND

langu = sy-langu.

ENDIF.

LOOP AT gt_0024 INTO wa_p0024.

READ TABLE lt_t574b INTO wa_t574b

WITH KEY quali = wa_p0024-quali

langu = sy-langu BINARY SEARCH.

READ TABLE lt_t777q INTO wa_t777q

WITH KEY chara = wa_p0024-auspr

langu = sy-langu BINARY SEARCH .

et_emp_qualification-employeeno = wa_p0024-pernr.

et_emp_qualification-startdate = wa_p0024-begda.

et_emp_qualification-enddate = wa_p0024-endda.

  • ET_EMP_QUALIFICATION-QUALI_KEY = wa_p0024-QUALI.

et_emp_qualification-quali_text = wa_t574b-qtext.

et_emp_qualification-proficiency = wa_t777q-chara_text.

APPEND et_emp_qualification TO et_emp_qualification

SORTED BY startdate .

ENDLOOP.

ENDFUNCTION.

1 ACCEPTED SOLUTION

matt
Active Contributor
0 Kudos
80

go_infty is your instance.

and it's created by:

go_infty = cl_hrsen_read_infotype_fmri=>get_instance( ).

It's used in your program by:

CALL METHOD go_infty->read
EXPORTING
pernr = employee_no
infty = '0024'
begda = '18000101'
endda = '99991231'
no_auth_check = space
IMPORTING
infotype_tab = gt_prelp_tab
EXCEPTIONS
e_assertion = 1
OTHERS = 2.

What's the problem?

matt

2 REPLIES 2

matt
Active Contributor
0 Kudos
81

go_infty is your instance.

and it's created by:

go_infty = cl_hrsen_read_infotype_fmri=>get_instance( ).

It's used in your program by:

CALL METHOD go_infty->read
EXPORTING
pernr = employee_no
infty = '0024'
begda = '18000101'
endda = '99991231'
no_auth_check = space
IMPORTING
infotype_tab = gt_prelp_tab
EXCEPTIONS
e_assertion = 1
OTHERS = 2.

What's the problem?

matt

Former Member
0 Kudos
80

Hi There,

I think your question is that you do not write anywhere CREATE OBJECT and then how is the instance created or where does it come from?

If it is so, then it is a singleton concept where the method get_instance make sure that only one instance of the class is returned and you do not end up creating multiple instances.

1. If you look at the attribute of the classs you should find a ref object to its own class.

2. In the method get_instance you will see that it checks if this attribute is bound or not and depending on it, it creates/returns the instance.

I hope this clarifies your doubt.

Regards,

Saurabh