Application Development and Automation 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: 
Read only

Movement type 101 and 102

rahul_1996
Participant
0 Likes
6,082

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.

16 REPLIES 16
Read only

SimoneMilesi
Active Contributor
0 Likes
5,434

Hello,

which is the issue? I cannot understand the problem: you have a lot of solutions, from pure SQL to handling internal tables.

Read only

FredericGirod
Active Contributor
0 Likes
5,434

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

Read only

SimoneMilesi
Active Contributor
0 Likes
5,434

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.

Read only

FredericGirod
Active Contributor
0 Likes
5,434

maybe, I didn't clean my crystal ball for a long time 🙂

Read only

Yasin
Active Participant
0 Likes
5,434

Hi,

you need always to consider SHKZG and do minus.

Regards

Read only

0 Likes
5,434

hi yasin ,

my problem is that i want to show the data in alv report which is not reversed.

Read only

rahul_1996
Participant
0 Likes
5,434

Hi guys ,

thanks for your precious time i already solved the problem.

thank you

Read only

FredericGirod
Active Contributor
0 Likes
5,434

Give your answer & close the message

Read only

rahul_1996
Participant
0 Likes
5,434
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 .
Read only

Yasin
Active Participant
0 Likes
5,434

why you marked it as answer ? while you still asking am confused.

Read only

former_member688242
Participant
0 Likes
5,434

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.

Read only

0 Likes
5,434

thanks i will try

Read only

0 Likes
5,434

check my code it is working fine any idea where i can make changes according to you

Read only

Yasin
Active Participant
0 Likes
5,434

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.

Read only

0 Likes
5,434

hi yasin can you update my code and post it so i can understand.

Read only

0 Likes
5,434

Hi Yasin, Help me with my code.