‎2022 Jan 12 9:07 AM

Hi Guys,
from MSEG table i want to pick up MBLNR having movement type 101...but at the same time these MBLNR's should not be cancelled with 102.
In short how can i pick up uncancelled MBLNR from MSEG with movement type 101 . in the screenshot as shown i want only last record.
PLzz help it is urgent.
‎2022 Jan 12 9:11 AM
Hello,
which is the issue? I cannot understand the problem: you have a lot of solutions, from pure SQL to handling internal tables.
‎2022 Jan 12 9:54 AM
simone.milesi, I think you need also a Crystal ball !
rahul_1996 Use the transaction ST05 to make a trace, find in the trace where the line 102 is added in the table. in this transaction you could see the corresponding code. In the editor you could set a break point
And restart the creation, and debug to find, yourself, why it creates 101 & 102
‎2022 Jan 12 10:02 AM
frdric.girod I think you are giving him wrong directions: the OP is asking how to retrieve the last valid Good Entry document, for what i understand.
And it's a quite common request.
I'd go for a select into table from MSEG, loop on internal table, then if LFBJA - LFBNR - LFPOS are initial, check if there is any record with LFBJA - LFBNR - LFPOS = MJAHR - MBLNR - ZEILE and if i find none, then the record is valid.
‎2022 Jan 12 10:20 AM
‎2022 Jan 12 10:28 AM
‎2022 Jan 12 10:49 AM
hi yasin ,
my problem is that i want to show the data in alv report which is not reversed.
‎2022 Jan 12 10:41 AM
Hi guys ,
thanks for your precious time i already solved the problem.
thank you
‎2022 Jan 12 10:43 AM
‎2022 Jan 12 10:52 AM
FORM GET_DATA.
*BREAK-POINT.
SELECT MBLNR
MJAHR
BUDAT
FROM MKPF INTO TABLE IT_MKPF WHERE MBLNR IN PO_NO AND BUDAT IN S_BUDAT.
IF IT_MKPF IS NOT INITIAL .
SELECT MBLNR
MJAHR
ZEILE
BWART
MATNR
WERKS
DMBTR
MENGE
LFBNR
LFPOS
SJAHR
SMBLN
SMBLP
EBELN
EBELP
FROM MSEG INTO TABLE IT_MSEG FOR ALL ENTRIES IN IT_MKPF
WHERE MBLNR = IT_MKPF-MBLNR
AND BWART IN ('101' , '102' )
ENDIF .
ENDFORM.
FORM F_PROCESS_DATA.
SORT IT_MSEG BY MBLNR.
IT_REV[] = IT_MSEG[].
DELETE IT_MSEG WHERE BWART EQ '102'.
DELETE IT_REV WHERE BWART EQ '101'.
LOOP AT IT_MSEG INTO WA_MSEG .
*
READ TABLE IT_REV INTO WA_REV WITH KEY SMBLN = WA_MSEG-MBLNR
SMBLP = WA_MSEG-ZEILE.
IF SY-SUBRC EQ 0.
DELETE IT_MSEG.
CONTINUE.
ENDIF.
WA_FINAL-MBLNR = WA_MSEG-MBLNR.
WA_FINAL-EBELN = WA_MSEG-EBELN.
WA_FINAL-MATNR = WA_MSEG-MATNR.
WA_FINAL-WERKS = WA_MSEG-WERKS.
WA_FINAL-BWART = WA_MSEG-BWART.
WA_FINAL-MENGE = WA_MSEG-MENGE.
WA_FINAL-DMBTR = WA_MSEG-DMBTR.
READ TABLE IT_MKPF INTO WA_MKPF WITH KEY MBLNR = WA_MSEG-MBLNR.
IF SY-SUBRC EQ 0.
WA_FINAL-BUDAT = WA_MKPF-BUDAT.
ENDIF.
APPEND WA_FINAL TO IT_FINAL.
CLEAR : WA_FINAL,WA_MSEG.
ENDLOOP .
‎2022 Jan 12 11:13 AM
why you marked it as answer ? while you still asking am confused.
‎2022 Jan 12 10:59 AM
hana Sql Code to get the value
select "Mat. Doc." from MSEG
minus
select "Mat. Doc." from MSEG as m1 // this gives cancelled material doc
where MBLNR = '102'
ABap method
take MSEG in internal table LT_mseg
loop at internal table LT_mseg
where MBLNR = '102'
delete the "Mat. Doc." from LT_mseg// delete cancelled material doc
endloop.
‎2022 Jan 12 11:04 AM
‎2022 Jan 12 11:05 AM
check my code it is working fine any idea where i can make changes according to you
‎2022 Jan 12 11:16 AM
You need to consider SHKZG and do minus. by deleting other Movement types like 102 from the query your report will not be accurate and you will get in troubles.
sometimes there will be return not cancel only.
‎2022 Jan 12 11:21 AM
hi yasin can you update my code and post it so i can understand.
‎2022 Jan 13 5:40 AM