on 02-04-2018 9:48 AM
Hi SAP gurus,
I am totally new to SAP and have been trying to get data from infotypes pa0001 and pa0023. My task is to display the details of the previous employers of a given employee along with his/her name. I am able to get the required data from pa0023 but am not able to get the name of the employee in the same table.
The code I have written adds the employee name as the next row of the table but I want the corresponding columns to be updated. Please help.
Regards,
Pankhuri
Here is the code:
TABLES: pa0001, pa0023 .
DATA :BEGIN OF itab OCCURS 0,
pernr LIKE pa0023-pernr, "employee id
ename LIKE pa0001-ename, "employee name
arbgb LIKE pa0023-arbgb, "prev. employer
yfdate LIKE pa0023-yfdate, "start date at prev employer
ytdate LIKE pa0023-ytdate, "end date at prev employer
yposition LIKE pa0023-yposition, "position at prev employer
END OF itab .
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS:p_pernr LIKE pa0023-pernr . "get employee id
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION .
*get data of prev employer from infotype pa0023
SELECT pernr
arbgb
yfdate
ytdate
yposition
FROM pa0023
INTO CORRESPONDING FIELDS OF TABLE itab
WHERE pernr = p_pernr.
*code to be corrected
SELECT ename
FROM pa0001
APPENDING CORRESPONDING FIELDS OF TABLE itab
FOR ALL ENTRIES IN itab
WHERE pernr = itab-pernr.
SORT itab BY yfdate DESCENDING.
*print data
IF NOT itab[] IS INITIAL.
LOOP AT itab.
WRITE:/ itab-pernr,
itab-ename,
itab-arbgb,
itab-yfdate,
itab-ytdate,
itab-yposition .
ENDLOOP.
ENDIF.
Hi Pankhuri,
*code to be corrected
SELECT ename FROM pa0001 APPENDING CORRESPONDING FIELDS OF TABLE itabFOR ALL ENTRIES IN itabWHERE pernr = itab-pernr.
You already found the statement which was wrong, debug it. Debugging is the best option to analyze the code. Here second select statement contains APPENDING keyword which appends the record into existing table ITAB. You can use inner join concept for the above case. During Coding if you had doubts, always use help.sap.com or press F1 in keywords, ABAP Keyword Documentation will be populated with detailed syntax.
Regards
Rajkumar Narasimman
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rajkumar Sir,
Thank you for your valuable suggestion. There's one more thing I would like to ask.
LOOP AT itab1.
itab-ename = itab1-ename.
MODIFY itab TRANSPORTING ename WHERE pernr = itab1-pernr.
ENDLOOP.
I created another internal table itab1 which fetches pernr and ename from infotype pa0001. And then this code to merge the 2 internal tables. This works fine but is doing an inner join a more efficient way?
Regards,
Pankhuri
Hi Pankhuri,
"I created another internal table itab1 which fetches pernr and ename from infotype pa0001
For your above program Inner join works efficiently. By the time raising questionnaire, you can create two different programs with inner join and without inner join and check performance using runtime tools and that may answer your doubts.
Don't use modify statements inside the loop, instead of that use Field-symbols. we have plenty of discussion in scn.
Regards
Rajkumar Narasimman
to read HCM data you should use logical database PNPCE
read documentation of report SAPDBPNPCE
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
107 | |
12 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.