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: 

Problem in joining tables

Former Member
0 Kudos
113

Hi All,

Here I am facing the problem in Joining table I have S031,s032,makt,marc,I need a field ATWRT field from CAWN table,I did't find any link for this above from tables, any one please help me how to find out.

REPORT ZMMTEST.

tables:s031,s032,makt,marc.

DATA : BEGIN OF itab1 OCCURS 0,

matnr TYPE s031-matnr,

lgort TYPE s031-lgort,

werks TYPE s031-werks,

spmon TYPE s031-spmon,

magbb type S031-magbb,

wagbb type S031-wagbb,

azubb type S031-azubb,

aagbb type S031-aagbb,

END OF itab1.

DATA : BEGIN OF itab2 OCCURS 0,

matnr like makt-matnr,

maktx like makt-maktx,

END OF itab2.

DATA : BEGIN OF itab3 OCCURS 0,

matnr TYPE marc-matnr,

werks type marc-werks,

ekgrp type marc-ekgrp,

END OF itab3.

DATA : BEGIN OF itab4 OCCURS 0 ,

matnr TYPE s032-matnr,

lgort TYPE s032-lgort,

werks TYPE s032-werks,

mbwbest type s032-mbwbest,

wbwbest type s032-wbwbest,

END OF itab4.

data : begin of itab5 occurs 0,

  • objek type ausp-objek,

atwrt type cawn-atwrt,

end of itab5.

DATA : BEGIN OF itab_final1 OCCURS 0,

matnr TYPE s031-matnr,

lgort TYPE s031-lgort,

werks TYPE s031-werks,

spmon TYPE s031-spmon,

magbb type S031-magbb,

wagbb type S031-wagbb,

azubb type S031-azubb,

aagbb type S031-aagbb,

maktx TYPE makt-maktx,

ekgrp type marc-ekgrp,

mbwbest type s032-mbwbest,

wbwbest type s032-wbwbest,

END OF itab_final1.

DATA : BEGIN OF itab_final OCCURS 0,

matnr TYPE s031-matnr,

lgort TYPE s031-lgort,

werks TYPE s031-werks,

spmon TYPE s031-spmon,

magbb type S031-magbb,

wagbb type S031-wagbb,

azubb type S031-azubb,

aagbb type S031-aagbb,

maktx TYPE makt-maktx,

ekgrp type marc-ekgrp,

mbwbest type s032-mbwbest,

wbwbest type s032-wbwbest,

atwrt type cawn-atwrt,

END OF itab_final.

select-options:s_matnr for s031-matnr.

start-of-selection.

select matnr lgort werks spmon magbb wagbb azubb aagbb

from s031 into table itab1

where matnr in s_matnr.

if not itab1[] is initial.

select matnr maktx from makt into table itab2 for all entries in itab1 where matnr = itab1-matnr.

if not itab2[] is initial.

select matnr werks ekgrp from marc into table itab3 for all entries in itab2 where matnr = itab2-matnr.

if not itab3[] is initial.

select matnr werks mbwbest wbwbest from s032 into corresponding fields of table itab4 for all entries in itab3 where matnr = itab3-matnr.

*if not itab4[] is initial.

select atwrt from cawn into corresponding fields of table itab5.*

endif.

endif.

endif.

endif.

end-of-selection.

loop at itab3.

itab_final-matnr = itab3-matnr.

read table itab2 with key matnr = itab3-matnr.

if sy-subrc = 0.

itab_final-maktx = itab2-maktx.

read table itab1 with key matnr = itab2-matnr.

if sy-subrc = 0.

itab_final-lgort = itab1-lgort.

itab_final-werks = itab1-werks.

itab_final-spmon = itab1-spmon.

itab_final-magbb = itab1-magbb.

itab_final-wagbb = itab1-wagbb.

itab_final-azubb = itab1-azubb.

itab_final-aagbb = itab1-aagbb.

endif.

endif.

itab_final-ekgrp = itab3-ekgrp.

read table itab4 with key matnr = itab3-matnr.

if sy-subrc = 0.

itab_final-mbwbest = itab4-mbwbest.

endif.

itab_final-wbwbest = itab4-wbwbest.

append itab_final.

clear itab_final.

endloop.

WRITE: /2 'material', 23 'storagelocation',29 'plant',35 'date',44 'val.stock.issue',66 'val.stock.issue.value',86 'no.of.stock.receipts',97 'no.of.stock.issues',150 'material.des', 160 'pur.group',190 'stock.val',210 'stock.quan'.

ULINE.

loop at itab_final.

WRITE: /2 itab_final-matnr, 23 itab_final-lgort,29 itab_final-werks,35 itab_final-spmon,44 itab_final-magbb,66 itab_final-wagbb,86 itab_final-azubb,97 itab_final-aagbb,

150 itab_final-maktx, 160 itab_final-ekgrp,190 itab_final-wbwbest,210 itab_final-mbwbest,itab_final-atwrt.

ENDLOOP.

Thanks&regds,

Sree.

2 REPLIES 2

Jelena_Perfiljeva
Active Contributor
0 Kudos
80

Try this:

CAWN-ATINN = AUSP-ATINN

CAWN-ATZHL = AUSP-ATZHK where

AUSP-OBJEK = MATNR and AUSP-KLART = '001' (Material)

Former Member
0 Kudos
80

Hi sree,

take join between s031-sptag ,ausp-datuvthen fetch records based on this condition.(itab1)

After retrieve records based on join condition between

ausp-atinn,ausp-adzhl and cawn-atinn,cawn-adzhl.(itab2)

Retrieve records using for all entries bet first join condition and second join condition.

use for all entries between itab1 and itab2.

it will work surely.

reaward points