Skip to Content
0
Former Member
Jun 07, 2008 at 04:29 AM

Urgent: Problem in Fetching the records from ITAB3

25 Views

hi,

here's d code,and the bold is dere where i am facing the problem i.e. whne i append lines of ITAB2 to ITAB3 it takes 32,234 records but in reality in ITAB2 there are 39 records,ITFINAL contains 45 records which is displaying the coreect data.

But why ITAB3 conatins 32,234 records in it.

it might hit th eperformance of the report.

TABLES: RSEG.

***********DECLARATION OF TABLES*************

************TABLE BKPF - ACCOUNTING HEADER ***********

DATA: BEGIN OF ITBKPF OCCURS 0,

BUKRS LIKE BKPF-BUKRS,

BELNR LIKE BKPF-BELNR,

GJAHR LIKE BKPF-GJAHR,

AWKEY LIKE BKPF-AWKEY,

BUDAT LIKE BKPF-BUDAT,

XBLNR LIKE BKPF-XBLNR,

AWTYP LIKE BKPF-AWTYP,

END OF ITBKPF.

*********TABLE BSIK - ACCOUNTING OPEN ITEMS********

DATA: BEGIN OF ITAB2 OCCURS 0,

LFBNR LIKE RSEG-LFBNR,

BUKRS LIKE BSIK-BUKRS,

GJAHR LIKE BSIK-GJAHR,

BELNR LIKE BSIK-BELNR,

AWKEY LIKE BKPF-AWKEY,

WRBTR LIKE BSIK-WRBTR,

LIFNR LIKE BSIK-LIFNR,

AUGBL LIKE BSAK-AUGBL,

AUGDT LIKE BSAK-AUGDT,

END OF ITAB2.

**********TABLE BSAK - ACCOUNTING CLEAR ITEMS*******

DATA: BEGIN OF ITAB3 OCCURS 0,

LFBNR LIKE RSEG-LFBNR,

BUKRS LIKE BSAK-BUKRS,

GJAHR LIKE BSAK-GJAHR,

BELNR LIKE BSAK-BELNR,

AWKEY LIKE BKPF-AWKEY,

WRBTR LIKE BSIK-WRBTR,

LIFNR LIKE BSIK-LIFNR,

AUGBL LIKE BSAK-AUGBL,

AUGDT LIKE BSAK-AUGDT,

END OF ITAB3.

DATA: BEGIN OF ITDEMO OCCURS 0,

BELNR LIKE RSEG-BELNR,

GJAHR LIKE RSEG-GJAHR,

LFBNR LIKE RSEG-LFBNR,

XBLNR LIKE RSEG-XBLNR,

END OF ITDEMO.

*****FINAL TABLE TO GATHER N DISPLAY OUTPUT*****

DATA: BEGIN OF ITFINAL OCCURS 0,

LFBNR LIKE RSEG-LFBNR,

BUKRS LIKE BKPF-BUKRS,

GJAHR LIKE BKPF-GJAHR,

BELNR LIKE BKPF-BELNR,

AWKEY LIKE BKPF-AWKEY,

WRBTR LIKE BSIK-WRBTR,

LIFNR LIKE BSIK-LIFNR,

AUGBL LIKE BSAK-AUGBL,

AUGDT LIKE BSAK-AUGDT,

END OF ITFINAL.

**********END OF DECLARATIONS*************

SELECT-OPTIONS: P_LFBNR FOR RSEG-LFBNR.

*************FETCHING OF THE DATA*************

START-OF-SELECTION.

  • BKPF

SELECT BUKRS BELNR GJAHR AWKEY BUDAT XBLNR AWTYP

FROM BKPF

INTO (ITBKPF-BUKRS,ITBKPF-BELNR,ITBKPF-GJAHR,

ITBKPF-AWKEY,ITBKPF-BUDAT,ITBKPF-XBLNR,ITBKPF-AWTYP)

WHERE AWTYP EQ 'MKPF' OR AWTYP EQ 'RMRP'.

*

o

+ MKPF*

************BEGIN OF TRY CODE FOR A MATERIAL DOCUMENT************

ITDEMO-BELNR = ITBKPF-AWKEY(10).

ITDEMO-GJAHR = ITBKPF-AWKEY+10(4).

ITDEMO-XBLNR = ITBKPF-XBLNR.

SELECT LFBNR FROM RSEG INTO

(ITDEMO-LFBNR) WHERE

BELNR EQ ITBKPF-AWKEY(10) AND

GJAHR EQ ITBKPF-AWKEY+10(4) AND

XBLNR EQ ITBKPF-XBLNR AND LFBNR > 0.

CHECK SY-SUBRC EQ 0 AND ITDEMO-LFBNR IN P_LFBNR.

************END OF TRY CODE FOR A MATERIAL DOCUMENT***************

ITAB2-BUKRS = ITBKPF-BUKRS.

ITAB2-GJAHR = ITBKPF-GJAHR.

ITAB2-BELNR = ITBKPF-BELNR.

ITAB3-BUKRS = ITBKPF-BUKRS.

ITAB3-GJAHR = ITBKPF-GJAHR.

ITAB3-BELNR = ITBKPF-BELNR.

*

o

+ BSIK*

SELECT WRBTR LIFNR FROM BSIK

INTO (ITAB2-WRBTR, ITAB2-LIFNR)

WHERE BUKRS EQ ITBKPF-BUKRS

AND GJAHR EQ ITBKPF-GJAHR

AND BELNR EQ ITBKPF-BELNR.

APPEND ITAB2.

EXIT.

ENDSELECT.

*

o

+

  1. BSAK*

SELECT WRBTR LIFNR AUGBL AUGDT

FROM BSAK

INTO (ITAB3-WRBTR,ITAB3-LIFNR,ITAB3-AUGBL,ITAB3-AUGDT)

WHERE BUKRS EQ ITBKPF-BUKRS

AND GJAHR EQ ITBKPF-GJAHR

AND BELNR EQ ITBKPF-BELNR.

APPEND ITAB3.

EXIT.

ENDSELECT.

APPEND ITDEMO.

EXIT.

ENDSELECT.

APPEND ITBKPF.

ENDSELECT.

  • Fields Found?

READ TABLE ITBKPF TRANSPORTING NO FIELDS INDEX 1.

IF sy-subrc NE 0.

MESSAGE i000(zmm1) WITH 'No documents found!'.

ENDIF.

  • Prepare Output

LOOP AT ITBKPF.

CLEAR ITAB2.

READ TABLE ITAB2

WITH KEY BUKRS = ITBKPF-BUKRS

BELNR = ITBKPF-BELNR

GJAHR = ITBKPF-GJAHR.

  • CHECK sy-subrc EQ 0?

CLEAR ITAB3.

READ TABLE ITAB3

WITH KEY BUKRS = ITBKPF-BUKRS

BELNR = ITBKPF-BELNR

GJAHR = ITBKPF-GJAHR. .

  • CHECK sy-subrc EQ 0?

READ TABLE ITDEMO

WITH KEY BELNR = ITBKPF-AWKEY(10).

  • CHECK sy-subrc EQ 0?

APPEND LINES OF ITAB2 TO ITAB3.

  • CHECK sy-subrc EQ 0?

ITFINAL-LFBNR = ITDEMO-LFBNR.

ITFINAL-BUKRS = ITBKPF-BUKRS.

ITFINAL-BELNR = ITBKPF-BELNR.

ITFINAL-GJAHR = ITBKPF-GJAHR.

ITFINAL-AWKEY = ITBKPF-AWKEY.

ITFINAL-WRBTR = ITAB3-WRBTR.

ITFINAL-LIFNR = ITAB3-LIFNR.

ITFINAL-AUGBL = ITAB3-AUGBL.

ITFINAL-AUGDT = ITAB3-AUGDT.

DELETE ITFINAL WHERE WRBTR = 0.

APPEND ITFINAL.

CLEAR ITFINAL.

ENDLOOP.

SORT ITFINAL BY AUGBL AUGDT .

****************************************

  • END-OF-SELECTION

****************************************

END-OF-SELECTION.

  • Output

LOOP AT ITFINAL.

WRITE: / ITFINAL-LFBNR,ITFINAL-BELNR, ITFINAL-GJAHR,ITFINAL-AWKEY, ITFINAL-WRBTR, ITFINAL-LIFNR,ITFINAL-AUGBL,ITFINAL-AUGDT.

ENDLOOP.