06-10-2014 4:50 PM
Hello Experts!
I am a beginner in ABAP programming and I have problem with one of my task.
I would like to get all users first and last names from infotype p0002. I've created a class, and method but only thing I've found in the Internet was something like this:
DATA: lt_data TYPE REF TO data,
return LIKE sy-subrc.
FIELD-SYMBOLS: <table> TYPE STANDARD TABLE.
CREATE DATA lt_data TYPE STANDARD TABLE OF PA0002.
ASSIGN lt_data->* TO <table>.
CALL FUNCTION 'HR_READ_INFOTYPE'
EXPORTING
pernr = '3'
infty = '0002'
begda = '18000101'
endda = '99991231'
IMPORTING
subrc = return
TABLES
infty_tab = <table>
EXCEPTIONS
infty_not_found = 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.
ELSE.
me_it = <table>.
ENDIF.
any suggestions how I can use it for all users and how to get data from the result? or is it useless for this task? help please
06-11-2014 5:31 AM
Hi Andrew,
Below mentioned field(s), you need to fetch to fufill the requirement.
PA0002 - NACHN = Last Name
PA0002 - VORNA = First Name
PA0002 - MIDNM = Middle Name
PA0002 - NAMZU = Suffix
Now fetch the above data based on PERNR, INFOTYPE, BEGDA, ENDDA.
Please validate the same at your end as well, let me know in case you require any further inputs.
BR/Thanks
Pranav Agrawal
06-11-2014 5:15 AM
Dear Andrew,
Please find the following code to retrive the value from P0002 Infotype.
Structure Declaration:
TYPES: Begin of ty_pa0002,
pernr type pernr_d,
begda type begda,
endda type endda,
nchmc type char25,
vnamc type char25,
end of ty_pa0002.
Data: it_pa0002 type table of pa0002, "IT for PA0002
wa_pa0002 type pa0002. "WA for PA0002
"Retrive the records from P0002 Infotype
select pernr
begda
endda
nchmc
vnamc
from pa0002
into table it_pa0002
where endda = '99991231'.
Regards
Rajkumar Narasimman
06-11-2014 8:46 AM
Dear Rajkumar,
First of all I would like to thank You for Your quick answer. Second of all I tried to use Your code but there're couple of problems and questions...
- what do I need ty_pa0002 type if it's not used after declaration?
- what for is wa_pa0002 (what 'WA' stands for? I know it is internal table, but wa?)
- when I use select query, the one You've written I get warnings that work area it_pa0002 has more fields than selected and also that database field begda and the component pernr of it_pa0002 are not compatible. When I ignore those warnings, at the end (after running my method in the test environment) I get an exception CX_SY_NO_HANDLER triggered.
I tried to remove unused types and data and get sth like this:
DATA: it_pa0002 TYPE TABLE OF pa0002.
SELECT * FROM pa0002 INTO TABLE it_pa0002.
But when I run it I get table with 0 entities. What's wrong?
Best regards
Andrew K
06-11-2014 5:31 AM
Hi Andrew,
Below mentioned field(s), you need to fetch to fufill the requirement.
PA0002 - NACHN = Last Name
PA0002 - VORNA = First Name
PA0002 - MIDNM = Middle Name
PA0002 - NAMZU = Suffix
Now fetch the above data based on PERNR, INFOTYPE, BEGDA, ENDDA.
Please validate the same at your end as well, let me know in case you require any further inputs.
BR/Thanks
Pranav Agrawal
06-11-2014 8:50 AM
Hello Pranav,
Thank You for Your reply. I found all fields that I need using t-code PM01 and exploring db table. I just can't figure it out how to write on screen or even fetch into table all names of all available users.
Got any clue?
I am really new in ABAP programming although I have some experience in other object-oriented programming and programming languages like C# and Java. I can't get the idea of how ABAP works. Where I should find all needed information etc. It's hard to find it by myself... that's what i know for sure...
Best regards
Andrew K
06-11-2014 10:17 AM
Hi Andrew,
There is absolutely no problem with the query i.e. everyone have a beginning and it is upon us how we take it to final stage.
Leave things apart, the answer to your query is suggested below.
Structure:
TYPES: Begin of typ_pa0002,
pernr type pernr_d, "Personnel No.
begda type begda, "Begin Date
endda type endda, "End Date
nachn type PAD_NACHN, "Last Name
vorna type PAD_VORNA, "First Name
namzu type namzu, "Salutation
end of typ_pa0002,
typ_t_pa0002 type standard table of typ_pa0002 initial size 0. "Table Type Definition
Data: l_it_pa0002 type typ_t_pa0002, "IT for PA0002 " Internal Table Definiton
lv_pernr type pernr,
lv_begda type sy-datum,
lv_endda type sy-datum.
"Data Declaration
lv_pernr = '3'.
lv_begda =.'18000101'.
lv_endda = '99991231'.
"Data Retieval from PA0002 DB Table
select pernr
begda
endda
nachn
vorna
namzu
from pa0002
into table it_pa0002
where pernr = lv_pernr
and endda GE lv_endda
and begda LE lv_begda.
Please validate the same at your end and let me know in case you require any further inputs from my end.
BR/Thanks
Pranav Agrawal
06-11-2014 11:54 AM
That works!
Thank You very much for Your support. I changed Your code a little bit so that I am returning all records, not just one with pernr = 3. Also I changed the structure and select query to return only first and last names. Anyway thanks to You I get the idea how it works. Thx.