cancel
Showing results for 
Search instead for 
Did you mean: 

data for same pernr from different infotypes

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

rajkumarnarasimman
Active Contributor

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

Former Member
0 Kudos

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

rajkumarnarasimman
Active Contributor
0 Kudos

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

Answers (1)

Answers (1)

former_member226519
Active Contributor

to read HCM data you should use logical database PNPCE

read documentation of report SAPDBPNPCE