ā2013 Jun 28 11:43 AM
Hi,
In the below code I appended 2 lines to with_item. I want to fetch all the columns of with_item for bsik.
Attached is for ur reference.
LOOP AT it_with_item.
READ TABLE it_bsik WITH KEY bukrs = it_with_item-bukrs belnr = it_with_item-belnr.
IF sy-subrc = 0.
it_with_item-belnr = it_bsik-belnr.
MODIFY it_with_item TRANSPORTING:belnr.
ENDIF.
DELETE it_bsik WHERE bukrs = it_with_item-bukrs AND belnr = it_with_item-belnr.
ENDLOOP.
APPEND LINES OF it_bsik TO it_with_item.
Regards
Kalpana
ā2013 Jun 28 1:13 PM
LOOP AT it_with_item.
READ TABLE it_bsik WITH KEY bukrs = it_with_item-bukrs belnr = it_with_item-belnr.
IF sy-subrc = 0.
it_with_item-belnr = it_bsik-belnr.
MODIFY it_with_item TRANSPORTING:belnrā2013 Jun 28 11:55 AM
ā2013 Jun 28 12:01 PM
HI,
use use LOOP inside LOOP.
LOOP AT it_with_item.
LOOP AT it_bsik where KEY bukrs = it_with_item-bukrs and belnr = it_with_item-belnr.
it_with_item-belnr = it_bsik-belnr.
MODIFY it_with_item TRANSPORTING:belnr.
APPEND LINES OF it_bsik TO it_with_item.
ENDLOOP.
ENDLOOP.
Regards,
Ams K.
ā2013 Jun 28 12:03 PM
Hi Kalpana,
Your question is not clear. what you want to do exactly???
Thanks,
Jayshree.
ā2013 Jun 28 12:06 PM
Hi,
You means to get the values of it_bsik to be filled in the with_item table?
FIELD-SYMBOLS : <fs_item> LIKE LINE OF it_with_item.
LOOP AT it_with_item ASSIGNING <fs_item>.
READ TABLE it_bsik WITH KEY bukrs = <fs_item>-bukrs
belnr = <fs_item>-belnr.
IF sy-subrc = 0.
MOVE-CORRESPONDING it_bsik TO <fs_item>.
* Or move what ever field values u require
ENDIF.
ENDLOOP.
Thanks & Regards
Bala Krishna
ā2013 Jun 28 12:36 PM
Hi,
In debug mode check the table it_bsik having entries or not after coming out from the loop.
check the types of it_bsik and it_with_item both must be having same type then only append will work.
ā2013 Jun 28 1:08 PM
hi,
use parallel cursor method
data : lv_index type i.
LOOP AT it_with_item.
READ TABLE it_bsik WITH KEY bukrs = it_with_item-bukrs belnr = it_with_item-belnr.
IF sy-subrc = 0.
lv_index = sy-tabix.
endif.
LOOP at it_bsik from lv_index.
if it_bsik-belnr <> it_with_item-belnr.
exit.
else.
it_with_item-belnr = it_bsik-belnr.
it_with_item-buzei = it_bsik-buzei.
MODIFY it_with_item TRANSPORTING:belnr buzei.
ENDIF.
DELETE it_bsik WHERE bukrs = it_with_item-bukrs AND belnr = it_with_item-belnr.
endif.
clear : lv_index.
endloop.
ENDLOOP.
APPEND LINES OF it_bsik TO it_with_item.
Thanks & Regards,
buz_sap
ā2013 Jun 28 1:02 PM
ā2013 Jun 28 1:13 PM
LOOP AT it_with_item.
READ TABLE it_bsik WITH KEY bukrs = it_with_item-bukrs belnr = it_with_item-belnr.
IF sy-subrc = 0.
it_with_item-belnr = it_bsik-belnr.
MODIFY it_with_item TRANSPORTING:belnrā2013 Jun 28 1:22 PM
Don't use a standard table and binary search. Use a SORTED table.
ā2013 Jun 28 1:17 PM
Hi Kalpana,
Sorry, ther is not much clarity in your question.
Assuming that you are trying to filter table IT_WITH_ITEM with respect to the entries in table BSIK.
I would suggest you to try using another internal table [ IT_WITH_ITEM_2 ] with the same type as IT_WITH_ITEM.
LOOP AT it_with_item.
READ TABLE it_bsik WITH KEY bukrs = it_with_item-bukrs belnr = it_with_item-belnr.
IF sy-subrc = 0.
APPEND it_with_item to it_with_item_2 ( this table should be empty, make sure to clear this table whenver needed).
ENDIF.
ENDLOOP.
You can delete ur BSIK if it is not needed anymore.
A much easier way would be to put an INNER JOIN between BSIK and WITH_ITEM(whichever DB table it is fetched from) from some selection parameters.So that u wont need these silly logics to be used in ur program
Thanks,
Harish Mahendran
ā2013 Jun 28 1:21 PM
Give more information, as we don't even know if the internal table have similar structure. Just three remarks :
What is you purpose : matching similar records and adding orphan at the end or ?
Some blogs to read : Asking Good Questions in the SCN Discussion Spaces will help you get Good Answers and The quality of an answer depends significantly on the quality of the question (or: how to ask good q....
Regards,
Raymond
ā2013 Jun 28 1:31 PM
Hi Kalpana,
From the code what I see, the requirement looks like if in it_with_item 'belnr' is not similar to 'belnr' in it_bsik table, then modify the belnr value into it_with_item table. And delete that record in it_bsik table. After the loop, the rest of the records are appended into it_with_item.
The error made here by you is, IF sy-subrc = 0 which should actually be IF sy-subrc NE 0. sy-subrc NE 0 would mean belnr value is not similar and hence modify needs to be made.
Hope the answer helped.
Regards,
Adithi
ā2013 Jun 29 7:40 AM
Hi all,
Thnku for ur suggestions. I solved my problem.
I retrieved all the data by using select single... in a loop.
Actually my problem is I have to append a record(belnr) in it_bsik1 to it_bsik of same type and later I have to retrieve all the data from It_with_item against it_bsik-belnr.
Hope u all can understand..
Regards
Kalpana
ā2013 Jun 29 9:19 AM
Good ...
Then close this thread....
If possible pl. share your code how you resolved your problem....
Regards,
Ramesh.T
ā2013 Jun 29 9:21 AM
You have added a SELECT statement in LOOP statement.....Just check on the performance of the report.
If you want all the matching entries of IT_BSIK in IT_WITH_ITEM, you can try below logic, LT_WITH_ITEM will have all the matching entires.
FIELD-SYMBOLS : <fs_bsik> LIKE LINE OF it_bsik.
DATA : lt_with_item LIKE TABLE OF it_with_item.
SORT it_with_item BY BUKRS BELNR.
SORT it_bsik BY BUKRS BELNR.
LOOP AT it_bsik ASSIGNING <fs_bsik>.
LOOP AT it_with_item WHERE bukrs = <fs_bsik>-bukrs
AND belnr = <fs_bsik>-belnr.
APPEND it_with_item TO lt_with_item.
ENDLOOP.
ENDLOOP.
Thanks & Regards
Bala Krishna
ā2013 Jun 29 10:07 AM
I resolved that problem.. But now Im facing new one regarding this.
I have given gjahr as 2013 in selection. I appended 1 rec from it_bsik1 to it_with_item(final table). For that record Bkpf_budat was showing wrong.
Following is my piece of code.
FORM get_data .
CLEAR:it_with_item,it_bsik,it_bsik1,it_with_item1,it_lfa1,it_j_1imovend,it_bkpf.
REFRESH:it_with_item,it_bsik,it_bsik1,it_with_item1,it_lfa1,it_j_1imovend,it_bkpf.
SELECT bukrs belnr gjahr blart bldat budat xblnr awkey FROM bkpf INTO CORRESPONDING FIELDS OF TABLE it_bkpf
WHERE bukrs IN s_bukrs AND gjahr IN s_gjahr AND budat IN s_budat.
SELECT bukrs belnr gjahr buzei witht wt_withcd wt_qsshh wt_qbshh wt_acco j_1iintchln FROM with_item INTO CORRESPONDING FIELDS OF TABLE it_with_item
FOR ALL ENTRIES IN it_bkpf
WHERE bukrs IN s_bukrs AND gjahr IN s_gjahr AND wt_qbshh NE '0' AND j_1iintchln EQ '' AND belnr = it_bkpf-belnr.
it_with_item1[] = it_with_item[].
SORT:it_with_item1 BY wt_acco.
DELETE ADJACENT DUPLICATES FROM it_with_item1 COMPARING wt_acco.
SELECT bukrs lifnr umskz zuonr gjahr belnr ebeln FROM bsik INTO CORRESPONDING FIELDS OF TABLE it_bsik FOR ALL ENTRIES IN it_with_item
WHERE belnr = it_with_item-belnr AND bukrs = it_with_item-bukrs AND lifnr EQ it_with_item-wt_acco AND gjahr IN s_gjahr.
SELECT bukrs lifnr umskz zuonr gjahr belnr ebeln FROM bsik INTO CORRESPONDING FIELDS OF TABLE it_bsik1 FOR ALL ENTRIES IN it_with_item1 WHERE
bukrs = it_with_item1-bukrs AND lifnr EQ it_with_item1-wt_acco AND umskz = 'A' AND gjahr NOT IN s_gjahr.
SORT:it_bsik BY gjahr belnr.
DELETE ADJACENT DUPLICATES FROM it_bsik COMPARING gjahr belnr.
SORT:it_bsik1 BY gjahr belnr.
DELETE ADJACENT DUPLICATES FROM it_bsik1 COMPARING gjahr belnr.
SELECT lifnr name1 FROM lfa1 INTO CORRESPONDING FIELDS OF TABLE it_lfa1 FOR ALL ENTRIES IN it_with_item WHERE lifnr = it_with_item-wt_acco.
SELECT lifnr j_1ipanno FROM j_1imovend INTO CORRESPONDING FIELDS OF TABLE it_j_1imovend FOR ALL ENTRIES IN it_with_item
WHERE lifnr = it_with_item-wt_acco.
SELECT bukrs zuonr gjahr belnr buzei ebeln FROM bsak INTO CORRESPONDING FIELDS OF TABLE it_bsak FOR ALL ENTRIES IN it_with_item
WHERE belnr = it_with_item-belnr AND buzei = it_with_item-buzei AND bukrs EQ it_with_item-bukrs AND gjahr = it_with_item-gjahr.
ENDFORM. " GET_DATA
*----------------------------------------------------------------------*
FORM display_output .
LOOP AT it_bsik1. "To append lines to with_item
it_with_item-wt_acco = it_bsik1-lifnr.
it_with_item-belnr = it_bsik1-belnr.
SELECT SINGLE bukrs buzei gjahr witht wt_withcd wt_qsshh wt_qbshh j_1iintchln FROM with_item INTO
(it_with_item-bukrs,it_with_item-buzei,it_with_item-gjahr ,it_with_item-witht ,it_with_item-wt_withcd ,it_with_item-wt_qsshh ,it_with_item-wt_qbshh ,it_with_item-j_1iintchln)
WHERE bukrs IN s_bukrs AND wt_qbshh NE '0' AND j_1iintchln EQ '' AND belnr = it_bsik1-belnr.
SELECT SINGLE budat xblnr bldat FROM bkpf INTO (it_with_item-budat,it_with_item-xblnr,it_with_item-bldat)
WHERE bukrs IN s_bukrs AND gjahr IN s_gjahr AND budat IN s_budat.
SELECT SINGLE ebeln FROM ekbe INTO it_with_item-ebeln WHERE gjahr = it_with_item-awkey+10(4) AND belnr = it_with_item-awkey(10).
APPEND it_with_item TO it_with_item.
CLEAR:it_with_item.
ENDLOOP.
LOOP AT it_with_item.
SELECT SINGLE text40 FROM t059u INTO it_with_item-text40 WHERE witht = it_with_item-witht AND spras = 'EN' AND land1 = 'IN'.
MODIFY it_with_item TRANSPORTING:text40.
SELECT SINGLE text40 FROM t059zt INTO it_with_item-text40 WHERE
wt_withcd = it_with_item-wt_withcd AND witht = it_with_item-witht AND spras = 'EN' AND land1 = 'IN'.
READ TABLE it_j_1imovend WITH KEY lifnr = it_with_item-wt_acco.
IF sy-subrc = 0.
it_with_item-j_1ipanno = it_j_1imovend-j_1ipanno.
MODIFY it_with_item TRANSPORTING j_1ipanno.
ENDIF.
CLEAR:it_j_1imovend.
READ TABLE it_lfa1 WITH KEY lifnr = it_with_item-wt_acco.
IF sy-subrc = 0.
it_with_item-name1 = it_lfa1-name1.
MODIFY it_with_item TRANSPORTING name1.
ENDIF.
CLEAR:it_lfa1.
READ TABLE it_bkpf WITH KEY belnr = it_with_item-belnr bukrs = it_with_item-bukrs gjahr = it_with_item-gjahr.
IF sy-subrc = 0.
it_with_item-budat = it_bkpf-budat.
it_with_item-xblnr = it_bkpf-xblnr.
it_with_item-bldat = it_bkpf-bldat.
it_with_item-awkey = it_bkpf-awkey.
it_with_item-blart = it_bkpf-blart.
MODIFY it_with_item TRANSPORTING:budat,xblnr,bldat,blart,awkey.
ENDIF.
CLEAR:it_bkpf.
len = strlen( it_with_item-awkey ).
IF it_with_item-blart EQ 'RE'.
SELECT SINGLE ebeln gjahr belnr
FROM ekbe INTO (it_with_item-ebeln,it_with_item-gjahr1,it_with_item-belnr1)
WHERE gjahr = it_with_item-awkey+10(4) AND belnr = it_with_item-awkey(10).
MODIFY it_with_item TRANSPORTING:ebeln.
ENDIF.
READ TABLE it_bsik WITH KEY bukrs = it_with_item-bukrs belnr = it_with_item-belnr gjahr = it_with_item-gjahr.
IF sy-subrc = 0.
it_with_item-zuonr = it_bsik-ebeln.
MODIFY it_with_item TRANSPORTING:zuonr.
ENDIF.
ENDLOOP.
ENDFORM. " DISPLAY_OUTPUT
ā2013 Jun 29 10:30 AM
Hi Kalpana,
Debug and see the values at every Select. Moreover when using For All Entries, just check whether the table is initial or not.
Eg :-
SELECT bukrs belnr gjahr blart bldat budat xblnr awkey FROM bkpf INTO CORRESPONDINGFIELDS OF TABLE it_bkpf
WHERE bukrs IN s_bukrs AND gjahr IN s_gjahr AND budat IN s_budat.
SELECT bukrs belnr gjahr buzei witht wt_withcd wt_qsshh wt_qbshh wt_acco j_1iintchln FROMwith_item INTO CORRESPONDING FIELDS OF TABLE it_with_item
FOR ALL ENTRIES IN it_bkpf
WHERE bukrs IN s_bukrs AND gjahr IN s_gjahr AND wt_qbshh NE '0' AND j_1iintchln EQ '' ANDbelnr = it_bkpf-belnr.
should be
SELECT bukrs belnr gjahr blart bldat budat xblnr awkey FROM bkpf INTO CORRESPONDINGFIELDS OF TABLE it_bkpf
WHERE bukrs IN s_bukrs AND gjahr IN s_gjahr AND budat IN s_budat.
if it_bkpf is not initial.
SELECT bukrs belnr gjahr buzei witht wt_withcd wt_qsshh wt_qbshh wt_acco j_1iintchln FROMwith_item INTO CORRESPONDING FIELDS OF TABLE it_with_item
FOR ALL ENTRIES IN it_bkpf
WHERE bukrs IN s_bukrs AND gjahr IN s_gjahr AND wt_qbshh NE '0' AND j_1iintchln EQ '' ANDbelnr = it_bkpf-belnr.
endif.
BR.
ā2013 Jul 01 1:40 PM
Hi Kalpana,
I suggest you not to use internal tables with header line. They re obsolete as well as they are confusing at times.
I believe you're assigning the values within the loop in here from bsik1 to it_with_item after which you append the same. Am i right?
Also, i here,
APPEND it_with_item TO it_with_item. --> (If you're using internal table with header line no need to mention the table two times in the Append stmt) Just Append it_with_item would be sufficient.
Also, it is always good to do a SY-SUBRC check after every select statement.
So, change your code this way.
LOOP AT it_bsik1. "To append lines to with_item
it_with_item-wt_acco = it_bsik1-lifnr.
it_with_item-belnr = it_bsik1-belnr.
SELECT SINGLE bukrs
buzei
gjahr
witht
wt_withcd
wt_qsshh
wt_qbshh
j_1iintchln
FROM with_item INTO
(it_with_item-bukrs,
it_with_item-buzei,
it_with_item-gjahr,
it_with_item-witht ,
it_with_item-wt_withcd,
it_with_item-wt_qsshh,
it_with_item-wt_qbshh,
it_with_item-j_1iintchln)
WHERE bukrs IN s_bukrs
AND wt_qbshh NE '0'
AND j_1iintchln EQ '' ------->> Don't know what you're comparing with in here
AND belnr = it_bsik1-belnr.
IF sy-subrc = 0.
SELECT SINGLE budat
xblnr
bldat
FROM bkpf
INTO (it_with_item-budat, --->> Put a break-point in this query and check via-debuggin whether this field is getting fillled
it_with_item-xblnr,
it_with_item-bldat)
WHERE bukrs IN s_bukrs
AND gjahr IN s_gjahr
AND budat IN s_budat.
IF sy-subrc = 0.
SELECT SINGLE ebeln
FROM ekbe
INTO it_with_item-ebeln
WHERE gjahr = it_with_item-awkey+10(4)
AND belnr = it_with_item-awkey(10).
IF sy-subrc =0.
APPEND it_with_item. -----> Just Append like this
CLEAR:it_with_item.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
If you're still stuck with, then put a break-point at the beginning of the loop and debug through your all your select queries. One more information!! Do not use select statments within loops as it would cause repeated DB hits. Results in Performance failure.So, any queries should not be within loops or Do. ENDDOs. So, take care on that. Instead use separate internal tables for the select queries and manipulate them using READ TABLE stmt within your loop.
I believe I could help you better if you can tell me your business requirement in this case.
Thanks,
Harish Mahendran.