Application Development and Automation 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: 
Read only

Select stmt

abdulazeez12
Active Contributor
0 Likes
374

I have a task this way:

I need to fetch some records based on a logic from CATSDB table. After applying a series of conditions, I have the final data. For this data, I need to fetch the name, personnel number, payroll area (SNAME, WERKS, ABKRS) from infotype 1. I am using the following logic:

select PERNR

BEGDA

SNAME

WERKS

ABKRS

from PA0001 into corresponding fields of table GT_PA0001

for all entries in GT_FINAL

where PERNR = GT_FINAL-pernr AND

BEGDA <= SP_ENDDA AND

ENDDA >= SP_BEGDA.

LOOP AT GT_FINAL.

read table gt_pa0001 with key pernr = gt_final-pernr

binary search.

if sy-subrc = 0.

GT_FINAL-SNAME = GT_PA0001-SNAME.

GT_FINAL-WERKS = GT_PA0001-WERKS.

GT_FINAL-ABKRS = GT_PA0001-ABKRS.

MODIFY GT_FINAL.

endif.

ENDLOOP.

Here, GT_FINAL is the final output to be displayed. It has the following fields:

PERNR

COUNTER

WORKDATE

CATSHOURS

AWART

PRAKN

ZZPSPNR

RNPLNR

RKOSTL

ZZALTC1

ERNAM

ERSDA

AENAM

LAEDA

SNAME

WERKS

ABKRS.

Now, I am not getting the correct logic to append the employee personnel area/payroll area depending upon the begda and endda of selection screen.

Secondly, how to update the gt_final internal table with the data of gt_pa0001? i also want performance.

Can anyone help. It is very urgent.

Thanks.

2 REPLIES 2
Read only

dani_mn
Active Contributor
0 Likes
344

HI,

why are you filling 'GT_PA0001' can can get values directly from table pa0001 into gt_final. in this way you can save an Extra loop.

like this.

<b>

LOOP AT gt_final.
select 
SNAME
WERKS
ABKRS
from PA0001 into corresponding fields of GT_final
where PERNR = GT_FINAL-pernr AND 
BEGDA <= SP_ENDDA AND
ENDDA >= SP_BEGDA.

MODIFY gt_final.

ENDOOP.

</b>

Regards,

Read only

Former Member
0 Likes
344

Hi,

use SORT gt_pa0001 by PERNR, since you are using binary search..

Check if the internal table is not initial before using the FOR ALL ENTRIES..

IF NOT GT_FINAL[] IS INITIAL.

SELECT...FROM ..PA0001.

ENDIF.

Regards

Naren