Application Development 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: 

Problem in the code

Former Member
0 Kudos

Hi,

I had made a report in which half of the data is coming and half is not.

i dont why it is happening ? when i check in the debug mode it is disaplying the data in ITAB but when i have to assign the value of itab in itfinal it is displaying nothing. here's d code:-

LOOP AT ITBKPF.

READ TABLE ITMKPF

WITH KEY MBLNR = ITBKPF-AWKEY(10)

MJAHR = ITBKPF-AWKEY+10(4).

READ TABLE ITAB

WITH KEY BELNR = ITBKPF-BELNR

GJAHR = ITBKPF-GJAHR

BUKRS = ITBKPF-BUKRS.

ITFINAL-BELNR = ITBKPF-BELNR.

ITFINAL-GJAHR = ITBKPF-GJAHR.

ITFINAL-AWKEY = ITBKPF-AWKEY.

ITFINAL-AUGBL = ITAB-AUGBL.

ITFINAL-AUGDT = ITAB-AUGDT.

ITFINAL-WRBTR = ITAB-WRBTR.

ITFINAL-LIFNR = ITAB-LIFNR.

APPEND ITFINAL.

ENDLOOP.

LOOP AT ITFINAL.

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

ENDLOOP.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,


LOOP AT ITBKPF.


READ TABLE ITMKPF
WITH KEY MBLNR = ITBKPF-AWKEY(10)
MJAHR = ITBKPF-AWKEY+10(4).

READ TABLE ITAB
WITH KEY BELNR = ITBKPF-BELNR
GJAHR = ITBKPF-GJAHR
BUKRS = ITBKPF-BUKRS.

ITFINAL-BELNR = ITBKPF-BELNR.
ITFINAL-GJAHR = ITBKPF-GJAHR.
ITFINAL-AWKEY = ITBKPF-AWKEY.
ITFINAL-AUGBL = ITAB-AUGBL.
ITFINAL-AUGDT = ITAB-AUGDT.
ITFINAL-WRBTR = ITAB-WRBTR.
ITFINAL-LIFNR = ITAB-LIFNR.

APPEND ITFINAL.

ENDLOOP.

LOOP AT ITFINAL.
WRITE: / ITFINAL-BELNR , ITFINAL-GJAHR, ITFINAL-AWKEY ,ITFINAL-AUGBL ,ITFINAL-AUGDT ,ITFINAL-WRBTR ,ITFINAL-LIFNR .
ENDLOOP.

In your case, the number of entries would be restricted to the number that are there in the table ITBKPF. As you are looping on ITBKPF, for only those records of ITBKPF, your ITFINAL gets populated.

If this is what is wanted then your code should be working fine.

I have some suggestions for you in ur current code though,

1) Please use CLEAR ITFINAL, after APPEND ITFINAL.

2) Check for SY-SUBRC after READ statements.

Reward points if this helps,

Kiran

19 REPLIES 19

Former Member
0 Kudos

Hi,


LOOP AT ITBKPF.


READ TABLE ITMKPF
WITH KEY MBLNR = ITBKPF-AWKEY(10)
MJAHR = ITBKPF-AWKEY+10(4).

READ TABLE ITAB
WITH KEY BELNR = ITBKPF-BELNR
GJAHR = ITBKPF-GJAHR
BUKRS = ITBKPF-BUKRS.

ITFINAL-BELNR = ITBKPF-BELNR.
ITFINAL-GJAHR = ITBKPF-GJAHR.
ITFINAL-AWKEY = ITBKPF-AWKEY.
ITFINAL-AUGBL = ITAB-AUGBL.
ITFINAL-AUGDT = ITAB-AUGDT.
ITFINAL-WRBTR = ITAB-WRBTR.
ITFINAL-LIFNR = ITAB-LIFNR.

APPEND ITFINAL.

ENDLOOP.

LOOP AT ITFINAL.
WRITE: / ITFINAL-BELNR , ITFINAL-GJAHR, ITFINAL-AWKEY ,ITFINAL-AUGBL ,ITFINAL-AUGDT ,ITFINAL-WRBTR ,ITFINAL-LIFNR .
ENDLOOP.

In your case, the number of entries would be restricted to the number that are there in the table ITBKPF. As you are looping on ITBKPF, for only those records of ITBKPF, your ITFINAL gets populated.

If this is what is wanted then your code should be working fine.

I have some suggestions for you in ur current code though,

1) Please use CLEAR ITFINAL, after APPEND ITFINAL.

2) Check for SY-SUBRC after READ statements.

Reward points if this helps,

Kiran

Former Member
0 Kudos

LOOP AT ITBKPF.

READ TABLE ITMKPF

WITH KEY MBLNR = ITBKPF-AWKEY(10)

MJAHR = ITBKPF-AWKEY+10(4).

if sy-subrc = 0.

endif.

READ TABLE ITAB

WITH KEY BELNR = ITBKPF-BELNR

GJAHR = ITBKPF-GJAHR

BUKRS = ITBKPF-BUKRS.

if sy-subrc = 0.

endif.

ITFINAL-BELNR = ITBKPF-BELNR.

ITFINAL-GJAHR = ITBKPF-GJAHR.

ITFINAL-AWKEY = ITBKPF-AWKEY.

ITFINAL-AUGBL = ITAB-AUGBL.

ITFINAL-AUGDT = ITAB-AUGDT.

ITFINAL-WRBTR = ITAB-WRBTR.

ITFINAL-LIFNR = ITAB-LIFNR.

APPEND ITFINAL.

ENDLOOP.

check u sy-subrc = 0 r not.....

try to use workarea.........

if it is usefull

Plz Reward

Regards

Anbu

Former Member
0 Kudos

Hi!

You just check the status of documents which are missing whether they exist or reversed, so that the corrrsponding records might be missing from ITAB table.

kesavadas_thekkillath
Active Contributor
0 Kudos

check the comment and revert

LOOP AT ITBKPF.

READ TABLE ITMKPF "THIS ITAB IS USED NO WHERE BELOW 
WITH KEY MBLNR = ITBKPF-AWKEY(10)
MJAHR = ITBKPF-AWKEY+10(4).

READ TABLE ITAB
WITH KEY BELNR = ITBKPF-BELNR
GJAHR = ITBKPF-GJAHR
BUKRS = ITBKPF-BUKRS.

ITFINAL-BELNR = ITBKPF-BELNR.
ITFINAL-GJAHR = ITBKPF-GJAHR.
ITFINAL-AWKEY = ITBKPF-AWKEY.
ITFINAL-AUGBL = ITAB-AUGBL.
ITFINAL-AUGDT = ITAB-AUGDT.
ITFINAL-WRBTR = ITAB-WRBTR.
ITFINAL-LIFNR = ITAB-LIFNR.

APPEND ITFINAL.

ENDLOOP.

LOOP AT ITFINAL.
WRITE: / ITFINAL-BELNR , ITFINAL-GJAHR, ITFINAL-AWKEY ,ITFINAL-AUGBL ,ITFINAL-AUGDT ,ITFINAL-WRBTR ,ITFINAL-LIFNR .
ENDLOOP.

Former Member
0 Kudos

Hi,

I think that the code should be written in this manner for better understanding.....

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

LOOP AT ITBKPF.

ITFINAL-BELNR = ITBKPF-BELNR.

ITFINAL-GJAHR = ITBKPF-GJAHR.

ITFINAL-AWKEY = ITBKPF-AWKEY.

READ TABLE ITMKPF

WITH KEY MBLNR = ITBKPF-AWKEY(10)

MJAHR = ITBKPF-AWKEY+10(4).

READ TABLE ITAB

WITH KEY BELNR = ITBKPF-BELNR

GJAHR = ITBKPF-GJAHR

BUKRS = ITBKPF-BUKRS.

ITFINAL-AUGBL = ITAB-AUGBL.

ITFINAL-AUGDT = ITAB-AUGDT.

ITFINAL-WRBTR = ITAB-WRBTR.

ITFINAL-LIFNR = ITAB-LIFNR.

APPEND ITFINAL.

ENDLOOP.

LOOP AT ITFINAL.

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

ENDLOOP.

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

In this code i think there is no data which satisfies the second read condition i.e

READ TABLE ITAB

WITH KEY BELNR = ITBKPF-BELNR

GJAHR = ITBKPF-GJAHR

BUKRS = ITBKPF-BUKRS.

so its not fetching the data from ITAB table .....

So check in debugging mode whether ITAB has any data in it or not.

Reward if helpful.

Regards,

Syed

Former Member
0 Kudos

Hi,

i suppose the following piece of code needs to be added to your code.

LOOP AT ITBKPF.

READ TABLE ITMKPF

WITH KEY MBLNR = ITBKPF-AWKEY(10)

MJAHR = ITBKPF-AWKEY+10(4).

if sy-subrc is initial.

move-corresponding itmkpf to itfinal..

endif.

READ TABLE ITAB

WITH KEY BELNR = ITBKPF-BELNR

GJAHR = ITBKPF-GJAHR

BUKRS = ITBKPF-BUKRS.

if sy-subrc is initial.

move-corresponding itab to itfinal..

endif.

ITFINAL-BELNR = ITBKPF-BELNR.

ITFINAL-GJAHR = ITBKPF-GJAHR.

ITFINAL-AWKEY = ITBKPF-AWKEY.

ITFINAL-AUGBL = ITAB-AUGBL.

ITFINAL-AUGDT = ITAB-AUGDT.

ITFINAL-WRBTR = ITAB-WRBTR.

ITFINAL-LIFNR = ITAB-LIFNR.

APPEND ITFINAL..

endloop.

rgds

Umakanth

Former Member
0 Kudos

hi,

i had checked in the debug mode that when the loop at ITBKPF gets start then data is present in the ITMKPF and ITAB. BUT when the i have to assign the values to the ITFINAL it doesnot accept the value from the ITAB ,it might be occuring due to the looping is done on ITBKPF. But this should not happen bcoz the read statement is written there. guys ,plz provide me some guidelines.

0 Kudos

first answer my qn above: or else post the whole code...

0 Kudos

Hi Keshu,

i had already posted the code above check out

former_member182346
Active Contributor
0 Kudos

Hiiii...plz check this.....

LOOP AT ITBKPF.

*Whats the need of this read ??? U r not using the ITMKPF inside the loop.

READ TABLE ITMKPF

WITH KEY MBLNR = ITBKPF-AWKEY(10)

MJAHR = ITBKPF-AWKEY+10(4).

ITFINAL-BELNR = ITBKPF-BELNR.

ITFINAL-GJAHR = ITBKPF-GJAHR.

ITFINAL-AWKEY = ITBKPF-AWKEY.

READ TABLE ITAB

WITH KEY BELNR = ITBKPF-BELNR

GJAHR = ITBKPF-GJAHR

BUKRS = ITBKPF-BUKRS.

if sy-subrc = 0

ITFINAL-AUGBL = ITAB-AUGBL.

ITFINAL-AUGDT = ITAB-AUGDT.

ITFINAL-WRBTR = ITAB-WRBTR.

ITFINAL-LIFNR = ITAB-LIFNR.

endif.

if ITFINAL is not initial.

APPEND ITFINAL.

endif.

ENDLOOP.

LOOP AT ITFINAL.

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

ENDLOOP.

Thanks & Regards

vinsee

0 Kudos

hi VINOD,

Here's d code i am using in the report:-

TABLES: BKPF,MKPF,BSAK.

DATA: BEGIN OF ITBKPF OCCURS 0,

BUKRS LIKE BKPF-BUKRS,

BELNR LIKE BKPF-BELNR,

GJAHR LIKE BKPF-GJAHR,

AWTYP LIKE BKPF-AWTYP,

AWKEY LIKE BKPF-AWKEY,

BUDAT LIKE BKPF-BUDAT,

END OF ITBKPF.

DATA: BEGIN OF ITMKPF OCCURS 0,

MBLNR LIKE MKPF-MBLNR,

MJAHR LIKE MKPF-MJAHR,

END OF ITMKPF.

DATA: BEGIN OF ITAB OCCURS 0,

AUGBL LIKE BSAK-AUGBL,

AUGDT LIKE BSAK-AUGDT,

BELNR LIKE BSAK-BELNR,

WRBTR LIKE BSAK-WRBTR,

LIFNR LIKE BSAK-LIFNR,

BUKRS LIKE BSAK-BUKRS,

GJAHR LIKE BSAK-GJAHR,

END OF ITAB.

DATA: BEGIN OF ITFINAL OCCURS 0,

BUKRS LIKE BKPF-BUKRS,

BELNR LIKE BKPF-BELNR,

GJAHR LIKE BKPF-GJAHR,

AWTYP LIKE BKPF-AWTYP,

AWKEY LIKE BKPF-AWKEY,

AUGBL LIKE BSAK-AUGBL,

AUGDT LIKE BSAK-AUGDT,

WRBTR LIKE BSAK-WRBTR,

LIFNR LIKE BSAK-LIFNR,

END OF ITFINAL.

SELECT-OPTIONS: P_BUKRS FOR BKPF-BUKRS,

P_GJAHR FOR BKPF-GJAHR.

SELECT ABUKRS ABELNR AGJAHR AAWTYP AAWKEY ABUDAT INTO TABLE ITBKPF FROM BKPF AS A

WHERE AAWTYP = 'MKPF' AND ABUKRS IN P_BUKRS AND A~GJAHR IN P_GJAHR.

IF NOT ITBKPF[] IS INITIAL.

SELECT AMBLNR AMJAHR INTO TABLE ITMKPF FROM MKPF AS A FOR ALL ENTRIES IN ITBKPF WHERE A~MBLNR = ITBKPF-AWKEY(10).

ENDIF.

SELECT AAUGBL AAUGDT ABELNR AWRBTR ALIFNR ABUKRS A~GJAHR FROM BSAK AS A INTO TABLE ITAB.

  • FOR ALL ENTRIES IN ITBKPF

  • WHERE

  • A~BUKRS = ITBKPF-BUKRS.

SORT ITAB BY BELNR.

LOOP AT ITBKPF.

CLEAR ITMKPF.

READ TABLE ITMKPF

WITH KEY MBLNR = ITBKPF-AWKEY(10)

MJAHR = ITBKPF-AWKEY+10(4).

if sy-subrc = 0.

endif.

ITFINAL-BELNR = ITBKPF-BELNR.

ITFINAL-GJAHR = ITBKPF-GJAHR.

ITFINAL-AWKEY = ITBKPF-AWKEY.

READ TABLE ITAB

WITH KEY BELNR = ITBKPF-BELNR

GJAHR = ITBKPF-GJAHR

BUKRS = ITBKPF-BUKRS.

if sy-subrc = 0.

endif.

ITFINAL-AUGBL = ITAB-AUGBL.

ITFINAL-AUGDT = ITAB-AUGDT.

ITFINAL-WRBTR = ITAB-WRBTR.

ITFINAL-LIFNR = ITAB-LIFNR.

APPEND ITFINAL.

CLEAR ITFINAL.

ENDLOOP.

LOOP AT ITFINAL.

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

ENDLOOP.

Edited by: abaper2008 on May 28, 2008 7:39 AM

0 Kudos

SELECT ABUKRS ABELNR AGJAHR AAWTYP AAWKEY ABUDAT INTO TABLE ITBKPF FROM BKPF AS A

WHERE AAWTYP = 'MKPF' AND ABUKRS IN P_BUKRS AND A~GJAHR IN P_GJAHR.

IF NOT ITBKPF[] IS INITIAL.

SELECT AMBLNR AMJAHR INTO TABLE ITMKPF FROM MKPF AS A FOR ALL ENTRIES IN ITBKPF WHERE A~MBLNR = ITBKPF-AWKEY(10).

ENDIF.

while fetching data into itmkpf ur using for all entries of the itbkpf and in the where condition ur giving itbkpf-awkey(10).

its not accepting that length as 10 to write. if we remove also we r not able as the length of the mblnr does not match. did u check that?

0 Kudos

hi chandrika,

can u plzz tell me what should i do? plzz u know i am trying to complete it from yesterday. try to understand my problem.

Edited by: abaper2008 on May 28, 2008 8:17 AM

0 Kudos

Hi,

with the code which u sent i am able to append data into itfinal and display the output.

small changes but nothing change with the processing.

no need of check of sy-subrc in the loop.

we r not geeting any data from itab in the read statement depending on the conditions. but it is appending the blank fields only.

no problem with ur code. i got the output without changing anything in ur code.

0 Kudos

HI,

did ur problem solved.

Reward if helpful.

0 Kudos

HI CHANDRIKA,

no my problem is not solved . u sai dthe data from itab is not coming . it is not coming bcoz the loop is on ITBKPF and in the ITFINAL it shows the data of IT BKPF and when i change the loop to the ITAB then it shows the data in ITFINAL of only ITab.

WHAT should i do now. how should i solve dis problem?

0 Kudos

i said that there is no data satisfying the conditions u have given in the read statement in my server ok.

no that does not change as u cahnge the loop from itab or itbkpf. it depends on the data what we have in the internal table and the conditions what we give while reading. remove the gjahr condition while reading the itab.

i hope ur facing this problem due to lack of data in ur database.first check the database tables do u have teh data with the conditions what ur giving in the program.

0 Kudos

HI,

this is the final code i am using ,and i had removed GJAHR and i am using only BUKRS to satisfy ITAB.

Here's d code:-

TABLES: BKPF,MKPF,BSAK.

DATA: BEGIN OF ITBKPF OCCURS 0,

BUKRS LIKE BKPF-BUKRS,

BELNR LIKE BKPF-BELNR,

GJAHR LIKE BKPF-GJAHR,

AWTYP LIKE BKPF-AWTYP,

AWKEY LIKE BKPF-AWKEY,

BUDAT LIKE BKPF-BUDAT,

END OF ITBKPF.

DATA: BEGIN OF ITMKPF OCCURS 0,

MBLNR LIKE MKPF-MBLNR,

MJAHR LIKE MKPF-MJAHR,

END OF ITMKPF.

DATA: BEGIN OF ITAB OCCURS 0,

AUGBL LIKE BSAK-AUGBL,

AUGDT LIKE BSAK-AUGDT,

BELNR LIKE BSAK-BELNR,

WRBTR LIKE BSAK-WRBTR,

LIFNR LIKE BSAK-LIFNR,

BUKRS LIKE BSAK-BUKRS,

GJAHR LIKE BSAK-GJAHR,

END OF ITAB.

DATA: BEGIN OF ITFINAL OCCURS 0,

BUKRS LIKE BKPF-BUKRS,

BELNR LIKE BKPF-BELNR,

GJAHR LIKE BKPF-GJAHR,

AWTYP LIKE BKPF-AWTYP,

AWKEY LIKE BKPF-AWKEY,

AUGBL LIKE BSAK-AUGBL,

AUGDT LIKE BSAK-AUGDT,

WRBTR LIKE BSAK-WRBTR,

LIFNR LIKE BSAK-LIFNR,

END OF ITFINAL.

SELECT-OPTIONS: P_BUKRS FOR BKPF-BUKRS,

P_GJAHR FOR BKPF-GJAHR.

SELECT ABUKRS ABELNR AGJAHR AAWTYP AAWKEY ABUDAT INTO TABLE ITBKPF FROM BKPF AS A

WHERE AAWTYP = 'MKPF' AND ABUKRS IN P_BUKRS AND A~GJAHR IN P_GJAHR.

IF NOT ITBKPF[] IS INITIAL.

SELECT AMBLNR AMJAHR INTO TABLE ITMKPF FROM MKPF AS A FOR ALL ENTRIES IN ITBKPF WHERE A~MBLNR = ITBKPF-AWKEY(10).

ENDIF.

SELECT AAUGBL AAUGDT ABELNR AWRBTR ALIFNR ABUKRS A~GJAHR FROM BSAK AS A INTO TABLE ITAB

FOR ALL ENTRIES IN ITBKPF

WHERE

A~BUKRS = ITBKPF-BUKRS.

SORT ITAB BY BELNR.

LOOP AT ITBKPF.

CLEAR ITMKPF.

READ TABLE ITMKPF

WITH KEY MBLNR = ITBKPF-AWKEY(10)

MJAHR = ITBKPF-AWKEY+10(4).

if sy-subrc = 0.

endif.

ITFINAL-BELNR = ITBKPF-BELNR.

ITFINAL-GJAHR = ITBKPF-GJAHR.

ITFINAL-AWKEY = ITBKPF-AWKEY.

READ TABLE ITAB

WITH KEY BELNR = ITBKPF-BELNR

GJAHR = ITBKPF-GJAHR

BUKRS = ITBKPF-BUKRS.

if sy-subrc = 0.

endif.

ITFINAL-AUGBL = ITAB-AUGBL.

ITFINAL-AUGDT = ITAB-AUGDT.

ITFINAL-WRBTR = ITAB-WRBTR.

ITFINAL-LIFNR = ITAB-LIFNR.

APPEND ITFINAL.

CLEAR ITFINAL.

ENDLOOP.

LOOP AT ITFINAL.

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

ENDLOOP.

0 Kudos

HI,

i am getting the output by this code. i am not knowing y ur not getting.