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

select statement

Former Member
0 Likes
991

Hi,

if i have to select Doc no.,posting date,material description for the particular Doc no. what is the select Query.

Doc no., is from mseg,

Posting date is from mkpf,

Material description is from makt.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
955

When ever u have to write select statement from 2 table its strongly recommended that you select the values from first header table (here its MKPF table in ur case ) than from the values from segement table (ie mseg in this case ) Than u select values from Makt .

Similarly for PO details selects 1st from EKKO ( header Po table first ) than from the line item table ie ekpo.

Similary from Delivery ir select vales fro LIKP ( delivery header table ) than from the Details table Lips.

Cheers

Niraj Kumar\

Patni Computers Systems

9 REPLIES 9
Read only

Former Member
0 Likes
955

Make a join on MKPF and MSEG, use the materials fetched above and select from MAKT..for material description..

thereby you are using two big tables in a join ,and getting the rest of the info in another select.

Read only

Former Member
0 Likes
955

Hi amit ,

first select MBLNR BUDAT MATNR MENGE from MKPF+ MSEG.

and get the MATNR from that List , and get the MAKTX from MAKT.

SELECT A~MBLNR
         A~MJAHR
         A~VGART
         A~BUDAT
         A~XBLNR
         B~ZEILE
         B~BWART
         B~MATNR
         B~WERKS
         B~KUNNR
         B~SHKZG
         B~MENGE
         B~meins
   FROM  ( MKPF AS A JOIN MSEG AS B
   ON    A~MBLNR = B~MBLNR  AND
         A~MJAHR = B~MJAHR )
   INTO  TABLE T_MSEG
   WHERE A~BUDAT GE S_DATE-LOW     AND
         A~VGART in ('WA' ,'WL')   AND
         B~MATNR in S_MATNR        AND
         B~WERKS IN S_WERKS1       AND
         B~SOBKZ EQ 'V'            AND
         B~KUNNR EQ W_CUST         .

like .

data : r_matnr for makt-matnr.

loop at t_mseg.

r_matnr-sign = 'I'.

r_matnr-option = 'EQ'.

r_matnr-low = t_mseg-matnr.

apppend r_matnr.

endloop.

sort r_matnr by low.

delete adjacent duplicates from r_matnr comparing low.

sort r_matnr by low.

if r_matnr[] is not initial.

select matnr maktx

frm makt

into corresponding fields of table i_makt.

where matnr in r_matnr

and SPRAS eq 'E'.

endif/

in this case no need to check the Performance of report.

Regards

Prabhu

endloop.

Read only

former_member186741
Active Contributor
0 Likes
955

types: begin of ty_m,

mblnr type mkpf-mblnr,

budat type mkpf-budat,

maktx type makt-maktx, end of ty_m.

data it_m type table of ty_m with header line

data w_mblnr type mkpf-mblnr.

select mkpfmblnr mkpfbudat makt~maktx

into corresponding fields of table it_m

from mkpf

join mseg on msegmblnr = mkpfmblnr

join makt on maktmatnr = msegmatnr

and spras = sy-langu

where mkpf~mblnr = w_mblnr.

Read only

Former Member
0 Likes
955

Hi ,

Thank u Can you give me a select query for this.

Read only

Former Member
0 Likes
955

Hi,

use join on mseg ,mkpf ,and use <b>for all entries</b> and get the material description from makt table.

Regards

vijay

Read only

0 Likes
955

Hi,

Can you give me that select statement and the DATA declarations

Message was edited by: amit teja

Read only

0 Likes
955

TABLES : MKPF, MSEG.

DATA : BEGIN OF ITAB.

MBLNR LIKE MKPF-MBLNR,

MJAHR LIKE MKPF-MJAHR,

BUDAT LIKE MKPF-BUDAT,

BLDAT LIKE MKPF-BLDAT,

MATNR LIKE MSEG-MATNR,

WERKS LIKE MSEG-WERKS,

ZEILE LIKE MSEG-ZEILE,

LIFNR LIKE MSEG-LIFNR,

ERFMG LIKE MSEG-ERFMG,

EBELN LIKE MSEG-EBELN,

EBELP LIKE MSEG-EBELP,

END OF ITAB.

Read only

Former Member
0 Likes
955

select amblnr amjahr abudat abldat

bmatnr bwerks bzeile blifnr berfmg bebeln b~ebelp into corresponding fields of table itab

from ( mkpf as a inner join mseg as b

on amblnr = bmblnr and amjahr = bmjahr )

where a~mblnr = mblnr.

or

select * from wb2_v_mkpf_mseg2 where mblnr = mblnr

note : wb2_v_mkpf_mseg2 is database view

Read only

Former Member
0 Likes
956

When ever u have to write select statement from 2 table its strongly recommended that you select the values from first header table (here its MKPF table in ur case ) than from the values from segement table (ie mseg in this case ) Than u select values from Makt .

Similarly for PO details selects 1st from EKKO ( header Po table first ) than from the line item table ie ekpo.

Similary from Delivery ir select vales fro LIKP ( delivery header table ) than from the Details table Lips.

Cheers

Niraj Kumar\

Patni Computers Systems