Skip to Content
0

data for same pernr from different infotypes

Feb 04 at 09:48 AM

56

avatar image
Former Member

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Rajkumar Narasimman Feb 04 at 04:33 PM
1

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

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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

0

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

0
Volker Binder Feb 14 at 11:24 AM
1

to read HCM data you should use logical database PNPCE

read documentation of report SAPDBPNPCE

Share
10 |10000 characters needed characters left characters exceeded