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: 

General Logical Question About MKPF & MSEG

Former Member
0 Kudos

Dear Sir,

I wanted to retrive the data from the table MSEG of A MONTH. To do that i m first going into table MKPF and from there i take Material Document(MBLNR) and Fiscal Year (GJAHR) on the basis of Posting date(BUDAT)...

Now my given task is to get the data from the MSEG for a month WITH THE INTERVAL OF 7 DAYS...

To achieve this i am going 4 times into the table MSEG on the basis of MKPF BUDAT ( 0-8, 9-15, 16-22, 23-31) ...

So my question is .. AM I DOING RIGHT THING TO GO INTO MSEG 4 TIMES AS I CAN ONLY GET FIRST WEEK FROM MKPF AND THERE IS NOTHING LIKE BUDAT IN MSEG... OR DO YOU HAVE ANY ANOTHER IDEA TO IMPLEMENT IT?

Best Answer Rewarded with Points...****

Warm Regards,

Nirav Parekh

3 REPLIES 3

Former Member
0 Kudos

why cant u append all data u fetch from MKPF into an internal table and use for all entries to fetch data from MSEG?

former_member386202
Active Contributor
0 Kudos

Hi,

refer this code

&----


*& Form sub_read_mseg

&----


  • text

----


FORM sub_read_mseg .

*--Local Variables

DATA : lv_index LIKE sy-tabix.

IF NOT it_bsis[] IS INITIAL.

LOOP AT it_bsis INTO wa_bsis.

lv_index = sy-tabix.

wa_bsis-mjahr = wa_bsis-budat+0(4).

MODIFY it_bsis FROM wa_bsis INDEX lv_index

TRANSPORTING mjahr.

CLEAR : wa_bsis.

ENDLOOP.

SELECT mblnr

mjahr

lifnr

erfmg

ebeln

ebelp

lfpos

FROM mseg

INTO CORRESPONDING FIELDS OF TABLE it_mseg

FOR ALL ENTRIES IN it_bsis

WHERE mblnr EQ it_bsis-mblnr

AND mjahr EQ it_bsis-mjahr.

IF sy-subrc EQ 0.

SORT it_mseg BY mblnr mjahr lfpos.

ENDIF.

ENDIF.

SORT it_bsis BY mblnr mjahr lfpos.

IF NOT it_mseg[] IS INITIAL.

LOOP AT it_bsis INTO wa_bsis.

lv_index = sy-tabix.

CLEAR : wa_mseg.

READ TABLE it_mseg INTO wa_mseg WITH KEY mblnr = wa_bsis-mblnr

mjahr = wa_bsis-mjahr

lfpos = wa_bsis-lfpos

BINARY SEARCH.

IF sy-subrc EQ 0.

wa_bsis-ebeln = wa_mseg-ebeln.

wa_bsis-ebelp = wa_mseg-ebelp.

ENDIF.

MODIFY it_bsis FROM wa_bsis INDEX lv_index

TRANSPORTING ebeln ebelp.

CLEAR : wa_bsis,

wa_mseg.

ENDLOOP.

ENDIF.

ENDFORM. " sub_read_mseg

&----


*& Form sub_read_mkpf

&----


  • text

----


FORM sub_read_mkpf .

IF NOT it_bsis[] IS INITIAL.

SELECT mblnr

mjahr

usnam

FROM mkpf

INTO TABLE it_mkpf

FOR ALL ENTRIES IN it_bsis

WHERE mblnr EQ it_bsis-mblnr

AND mjahr EQ it_bsis-mjahr.

IF sy-subrc EQ 0.

SORT it_mkpf BY mblnr mjahr.

ENDIF.

ENDIF.

ENDFORM. " sub_read_mkpf

Regards,

Prashant

Former Member
0 Kudos

you can use the view "WB2_V_MKPF_MSEG2"...this will be very helpfull.

reward if usefull......

Regards,

V.Balaji