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: 

EKBE table data

Former Member
0 Kudos

Acutally I am fetching data from EKBE table for a given EBELN. Here I am getting all the GR and IR number for a EBELN. I have to fileter those GR which have IR. It means for a BELNR if the IR is raised, then the reference document (LFBNR) will be GR no. When I am going to ouput I am getting the IR and GR. I want to bring want to get oneline. If the IR is not raised for GR then it has to dispaly one line item.

Ex: EBELN - BELNR - BWETP - LFBNR

4100000000 - 5000000200 - E - 5000000200

4100000000 - 5000000201 - E - 5000000201

4100000000 - 5100000501 - Q - 5000000200

4100000000 - 5100000502 - Q - 5000000200

OUTPUT EXPECTED:

4100000000 - 5000000201 - E - 5000000201

4100000000 - 5100000501 - Q - 5000000200

4100000000 - 5100000502 - Q - 5000000200

E - GR & Q - IR.

for an E if IR is not there, it has to pick. See the Belnr 5000000201

This is my Prob.

Regards

Ram

1 ACCEPTED SOLUTION

Former Member
0 Kudos

HI ,

Try this .

Loop at it1.
 read table it1 into wa_1 with key BWETP = 'Q' 
                                  LFBNR = it1-lfbnr.
if sy-subrc = 0.
it2[] = it1[].
delete it2 where BWETP <> 'Q' and
                       LFBNR <> it1-lfbnr.
append lines of  it2 to it_result.
delete it1 where BWETP = 'Q' and
                       LFBNR = it1-lfbnr.

else.
* If no matching record is found.
append it_1 to it_result.
endif.

Endloop.

Regars

Arun

5 REPLIES 5

Former Member
0 Kudos

for GR EKBE-VGBEL = 1

for IR EKBE-VGBEL = 2.

Regards

Prabhu

Former Member
0 Kudos

HI ,

Try this .

Loop at it1.
 read table it1 into wa_1 with key BWETP = 'Q' 
                                  LFBNR = it1-lfbnr.
if sy-subrc = 0.
it2[] = it1[].
delete it2 where BWETP <> 'Q' and
                       LFBNR <> it1-lfbnr.
append lines of  it2 to it_result.
delete it1 where BWETP = 'Q' and
                       LFBNR = it1-lfbnr.

else.
* If no matching record is found.
append it_1 to it_result.
endif.

Endloop.

Regars

Arun

Former Member
0 Kudos

itab2[] = itab1[].

loop at itab2.

if itab2-bwetp = 'E'.

read table itab1 with key lfbnr = itab2-belnr bwetp = 'Q'.

if sy-subrc eq 0.

delete itab1 where lfbnr = itab2-belnr and bwetp = 'E'.

endif.

endif.

endloop.

try this

regards

shiba dutta

former_member404244
Active Contributor
0 Kudos

Hi shriram,

first u need to get all the data for GR and IR into one table .Then u need to split the data by using two different internal tables one for GR and another for IR.Please look the below code.I_ekbe wil have both GR and IR values

LOOP AT i_ekbe INTO lwa_ekbe.

*->> Move the GR's & IR's in to there respective tables

IF lwa_ekbe-vgabe = c_1.

MOVE : lwa_ekbe-ebeln TO wa_gr-ebeln,

lwa_ekbe-ebelp TO wa_gr-ebelp.

wa_gr-dmbtr = lwa_ekbe-dmbtr.

wa_gr-menge = lwa_ekbe-menge.

ENDIF.

COLLECT wa_gr INTO i_gr.

ELSEIF lwa_ekbe-vgabe = c_2.

MOVE : lwa_ekbe-ebeln TO wa_ir-ebeln,

lwa_ekbe-ebelp TO wa_ir-ebelp,

lwa_ekbe-menge TO wa_ir-menge,

lwa_ekbe-dmbtr TO wa_ir-dmbtr.

COLLECT wa_ir INTO i_ir.

ENDIF. "IF lwa_ekbe-vgabe = c_1.

ENDLOOP. " LOOP AT i_ekbe INTO lwa_ekbe.

now u wil have two different internal tables one with GR nad second with IR.Now u can do what ever u want.

regards,

Nagaraj

Former Member
0 Kudos

HI

try with this code

data : begin of wa_pur_itm occurs 0,

ebeln like ekpo-ebeln,

ebelp like ekpo-ebelp,

loekz like ekpo-loekz,

aedat like ekpo-aedat,

matkl like ekpo-matkl,

matnr like ekbe-matnr,

shkzg like ekbe-shkzg,

bewtp like ekbe-bewtp,

bwart like ekbe-bwart,

wrbtr like ekbe-wrbtr,

waers like ekbe-waers,

belnr like ekbe-belnr,

menge like ekbe-menge,

buzei like ekbe-buzei,

lfbnr like ekbe-lfbnr,

hkont like bseg-hkont,

xncop like bseg-xncop,

maktx type makt-maktx,

BEWTK type T163C-bewtk,

end of wa_pur_itm.

DATA : t_pur_itm like wa_pur_itm occurs 0 with header line,

t_pur_itm1 like wa_pur_itm occurs 0 with header line,

t_pur_itm2 like wa_pur_itm occurs 0 with header line,

t_pur_itm3 like wa_pur_itm occurs 0 with header line.

select aebeln aebelp aloekz aaedat amatkl amatnr

bshkzg bbewtp bbwart bwrbtr bwaers bbelnr

bmenge bbuzei b~lfbnr

into (t_pur_itm1-ebeln, t_pur_itm1-ebelp,

t_pur_itm1-loekz, t_pur_itm1-aedat,

t_pur_itm1-matkl, t_pur_itm1-matnr,

t_pur_itm1-shkzg, t_pur_itm1-bewtp,

t_pur_itm1-bwart, t_pur_itm1-wrbtr,

t_pur_itm1-waers, t_pur_itm1-belnr,

t_pur_itm1-menge, t_pur_itm1-buzei,

t_pur_itm1-lfbnr)

from ekpo as a

inner join ekbe as b

on aebeln eq bebeln and

aebelp eq bebelp

where a~aedat in s_aedat and

a~matkl eq s_matkl and

a~loekz eq space and

a~bstyp eq 'F' and

b~gjahr eq s_gjahr and

b~bewtp eq 'E'.

append t_pur_itm1.

endselect.

loop at t_pur_itm2.

loop at t_pur_itm1 where ebeln eq t_pur_itm2-ebeln and

ebelp eq t_pur_itm2-ebelp and

lfbnr eq t_pur_itm2-lfbnr and

bewtp eq 'E'.

t_pur_itm-ebeln = t_pur_itm1-ebeln.

t_pur_itm-ebelp = t_pur_itm1-ebelp.

t_pur_itm-bewtp = t_pur_itm1-bewtp.

t_pur_itm-loekz = t_pur_itm1-loekz.

t_pur_itm-aedat = t_pur_itm1-aedat.

t_pur_itm-matkl = t_pur_itm1-matkl.

t_pur_itm-matnr = t_pur_itm1-matnr.

t_pur_itm-shkzg = t_pur_itm1-shkzg.

t_pur_itm-bwart = t_pur_itm1-bwart.

  • if t_pur_itm1-bewtp eq 'R'.

  • t_pur_itm-wrbtr = t_pur_itm1-wrbtr.

  • elseif t_pur_itm1-bewtp eq 'Q'.

  • t_pur_itm-wrbtr = - t_pur_itm1-wrbtr.

  • endif.

t_pur_itm-wrbtr = t_pur_itm1-wrbtr.

t_pur_itm-waers = t_pur_itm1-waers.

t_pur_itm-belnr = t_pur_itm1-belnr.

t_pur_itm-menge = t_pur_itm1-menge.

t_pur_itm-buzei = t_pur_itm1-buzei.

t_pur_itm-lfbnr = t_pur_itm1-lfbnr.

append t_pur_itm.

endloop.

endloop.

sort t_pur_itm by ebeln ebelp bewtp belnr buzei.

loop at t_pur_itm1.

loop at t_pur_itm2 where ebeln eq t_pur_itm1-ebeln and

ebelp eq t_pur_itm1-ebelp and

bewtp eq 'Q'.

t_pur_itm-ebeln = t_pur_itm2-ebeln.

t_pur_itm-ebelp = t_pur_itm2-ebelp.

t_pur_itm-bewtp = t_pur_itm2-bewtp.

t_pur_itm-loekz = t_pur_itm2-loekz.

t_pur_itm-aedat = t_pur_itm2-aedat.

t_pur_itm-matkl = t_pur_itm2-matkl.

t_pur_itm-matnr = t_pur_itm2-matnr.

t_pur_itm-shkzg = t_pur_itm2-shkzg.

t_pur_itm-bwart = t_pur_itm2-bwart.

if t_pur_itm2-bewtp eq 'R'.

t_pur_itm-wrbtr = t_pur_itm2-wrbtr.

elseif t_pur_itm2-bewtp eq 'Q'.

t_pur_itm-wrbtr = - t_pur_itm2-wrbtr.

endif.

  • t_pur_itm-wrbtr = t_pur_itm2-wrbtr.

t_pur_itm-waers = t_pur_itm2-waers.

t_pur_itm-belnr = t_pur_itm2-belnr.

t_pur_itm-menge = t_pur_itm2-menge.

t_pur_itm-buzei = t_pur_itm2-buzei.

t_pur_itm-lfbnr = t_pur_itm2-lfbnr.

select single maktx into maktx from makt

where matnr eq t_pur_itm2-matnr and

spras eq 'EN'.

select single bewtk into bewtk from T163C

where bewtp eq t_pur_itm2-bewtp and

spras eq 'EN'.

concatenate t_pur_itm2-belnr s_gjahr into awkey.

select single belnr into t_belnr from bkpf

where awkey eq awkey and

gjahr eq s_gjahr.

concatenate t_belnr s_gjahr into t_zuonr.

select single hkont

into t_pur_itm2-hkont

from bseg

where belnr eq t_belnr and

gjahr eq s_gjahr and

zuonr eq t_zuonr.

t_pur_itm-maktx = maktx.

t_pur_itm-bewtk = bewtk.

t_pur_itm-hkont = t_pur_itm2-hkont.

append t_pur_itm.

endloop.

endloop.

sort t_pur_itm by ebeln ebelp bewtp belnr buzei bwart lfbnr hkont.

DELETE ADJACENT DUPLICATES FROM t_pur_itm.

if s_opt = 'X'.

loop at t_pur_itm.

if t_pur_itm-BEWTP eq 'E'.

move-corresponding t_pur_itm to t_pur_itmE.

append t_pur_itmE.

sort t_pur_itmE by ebeln ebelp bewtp belnr bwart lfbnr hkont.

elseif t_pur_itm-BEWTP eq 'Q'.

move-corresponding t_pur_itm to t_pur_itmQ.

append t_pur_itmQ.

sort t_pur_itmQ by ebeln ebelp bewtp belnr bwart lfbnr hkont.

endif.

endloop.