10-06-2013 10:39 AM
Hi gurus,
I have the internal table lt_final as shown below.
BKPF(Accounting doc | BSEG(Cost center) | Flag |
0000000259 | ||
0000000259 | N100000002 | |
0000000957 | ||
0000000957 | N100000002 | |
0000000957 | N100000002 | |
0000000958 | ||
0000000958 | ||
0000000958 | ||
0000000959 | ||
0000000959 | N100000002 | |
0000000959 | N100000002 |
For first row 259 (accounting Document ) Cost Center is initial.but second row is having Cost Center value(N100000002 ) so if any one the item is having cost center value all accounting Documents (259 documents) FLAG will be set to 'X'.similarly 957 are having 3 items in which two are having cost center value so all 957 FLAG will be set to 'X'.
But in 958 none of the Item is having cost center so all 958 items will be set to null( no value)
output should be look like this
BKPF(Accounting doc | BSEG(Cost center) | Flag |
0000000259 | X | |
0000000259 | N100000002 | X |
0000000957 | X | |
0000000957 | N100000002 | X |
0000000957 | N100000002 | X |
0000000958 | ||
0000000958 | ||
0000000958 | ||
0000000959 | X | |
0000000959 | N100000002 | X |
0000000959 | N100000002 | X |
i have tried so many logic's but couldn't able to fetch exact results.
kindly help on this ....
Thanks in advance.
Regards,
Ramu
10-06-2013 1:05 PM
Hi Ramu,
Follow this logic.
data : wa like line of it_final,
wa1 like line of it_final.
data : exist.
wa1-flag = 'X'.
sort it_final by bkpf.
clear : wa, exist.
loop at it_final into wa.
if not wa-bseg is INITIAL.
exist = 'X'.
endif.
at end of bkpf.
if exist = 'X'.
MODIFY it_final from wa1 TRANSPORTING flag WHERE bkpf = wa-bkpf .
clear exist.
endif.
endat.
clear wa.
endloop.
10-06-2013 12:50 PM
Hi,
Go through Following code.
data: lt_final_dummy type lt_final.
lt_final_dummy[] = lt_final[].
loop at lt_final_dummy into wa_final_dummy where cost_center is not initial.
loop at lt_final into wa_final where accounting_doc eq wa_final_dummy-accounting_doc.
wa_final- falg = 'X'.
modify lt_final from wa_final.
endloop.
endloop.
Regards
Sajid
10-06-2013 1:05 PM
Hi Ramu,
Follow this logic.
data : wa like line of it_final,
wa1 like line of it_final.
data : exist.
wa1-flag = 'X'.
sort it_final by bkpf.
clear : wa, exist.
loop at it_final into wa.
if not wa-bseg is INITIAL.
exist = 'X'.
endif.
at end of bkpf.
if exist = 'X'.
MODIFY it_final from wa1 TRANSPORTING flag WHERE bkpf = wa-bkpf .
clear exist.
endif.
endat.
clear wa.
endloop.
10-06-2013 2:14 PM
Hi Susmitha,
Thank you very much for your reply its solved my problem...:)
Regards,
Ramu
10-06-2013 1:18 PM
Dear Ramu k,
please try this,
data: BEGIN OF itab OCCURS 0,
belnr type bkpf-belnr,
kostl TYPE bseg-kostl,
flag type c,
END OF itab.
DATA: WA1 LIKE LINE OF ITAB,
WA2 LIKE LINE OF ITAB.
DATA: CHK TYPE C VALUE 'Y'.
DATA: COUNTER TYPE I,
CNT TYPE I.
itab-belnr = '0000000960'.
itab-kostl = ''.
itab-flag = ''.
APPEND itab.
clear: itab.
itab-belnr = '0000000960'.
itab-kostl = ''.
itab-flag = ''.
APPEND itab.
clear: itab.
itab-belnr = '0000000960'.
itab-kostl = ''.
itab-flag = ''.
APPEND itab.
clear: itab.
itab-belnr = '0000000259'.
itab-kostl = ''.
itab-flag = ''.
APPEND itab.
clear: itab.
itab-belnr = '0000000259'.
itab-kostl = 'N100000002'.
itab-flag = ''.
APPEND itab.
clear: itab.
itab-belnr = '0000000957'.
itab-kostl = 'N100000002'.
itab-flag = ''.
APPEND itab.
clear: itab.
itab-belnr = '0000000957'.
itab-kostl = 'N100000002'.
itab-flag = ''.
APPEND itab.
clear: itab.
itab-belnr = '0000000958'.
itab-kostl = ''.
itab-flag = ''.
APPEND itab.
clear: itab.
itab-belnr = '0000000958'.
itab-kostl = ''.
itab-flag = ''.
APPEND itab.
clear: itab.
itab-belnr = '0000000958'.
itab-kostl = ''.
itab-flag = ''.
APPEND itab.
clear: itab.
itab-belnr = '0000000959'.
itab-kostl = 'N100000002'.
itab-flag = ''.
APPEND itab.
clear: itab.
itab-belnr = '0000000959'.
itab-kostl = 'N100000002'.
itab-flag = ''.
APPEND itab.
clear: itab.
LOOP AT itab INTO WA1.
IF WA1-KOSTL IS NOT INITIAL.
CHK = 'X'.
ENDIF.
COUNTER = COUNTER + 1.
AT END OF BELNR.
IF CHK EQ 'X'.
DO COUNTER TIMES.
CNT = CNT + 1.
READ TABLE ITAB INTO WA2 INDEX CNT.
IF SY-SUBRC EQ 0.
WA2-FLAG = 'X'.
MODIFY ITAB INDEX CNT FROM WA2.
CLEAR: WA2.
ENDIF.
ENDDO.
CLEAR: CHK,COUNTER,WA2.
ELSE.
CNT = CNT + COUNTER.
CLEAR: COUNTER.
ENDIF.
ENDAT.
CLEAR: WA1.
ENDLOOP.
SORT ITAB BY BELNR.
LOOP AT ITAB.
WRITE😕 'BELNR = ', ITAB-BELNR, 'KOSTL = ', ITAB-KOSTL, 'FLAG = ', ITAB-FLAG.
ENDLOOP.