Inner join condition with 3
tables
REPORT ZREPORT7.
TABLES: MAST, STKO, STPO.
DATA: BEGIN OF WA,
MATNR TYPE MAST-MATNR,
WERKS TYPE MAST-WERKS,
STLAN TYPE MAST-STLAN,
ANDAT TYPE MAST-ANDAT,
STLNR TYPE MAST-STLNR,
STLAL TYPE STKO-STLAL,
DATUV TYPE STKO-DATUV,
STLST TYPE STKO-STLST,
STLTY TYPE STPO-STLTY,
STLKN TYPE STPO-STLKN,
END OF WA.
DATA: ITAB LIKE STANDARD TABLE OF WA.
WRITE:
'|','MATERIAL NUMBER', 23 '|',
'PLANT', 29'|',
'BOM USAGE', 42'|',
'CREATED ON', 56'|',
'BOM',68'|',
'ALT BOM',79'|',
'VALID FROM',91'|',
'STATUS',102'|',
'CATEGORY',115'|',
'ITEM NODER',130'|'.
ULINE.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_MATNR FOR MAST-MATNR,
S_WERKS FOR MAST-WERKS NO-EXTENSION,
S_STLNR FOR STKO-STLNR NO INTERVALS.
SELECTION-SCREEN END OF BLOCK B1.
SELECT K~MATNR K~WERKS K~STLAN K~ANDAT K~STLNR
B~STLAL B~DATUV B~STLST
C~STLTY C~STLKN INTO CORRESPONDING FIELDS OF WA
FROM ( ( MAST AS K INNER JOIN STKO AS B
ON B~STLNR = K~STLNR )
INNER JOIN STPO AS C ON B~STLNR = C~STLNR )
WHERE K~MATNR IN S_MATNR
AND K~WERKS IN S_WERKS
AND K~STLNR IN S_STLNR.
APPEND WA TO ITAB.
ENDSELECT.
LOOP AT ITAB INTO WA.
WRITE:
'|',05 WA-MATNR, 23 '|', "MATERIAL NUMBER
WA-WERKS, 29 '|', "PLANT
WA-STLAN, 42 '|', "BOM USAGE
WA-ANDAT, 56 '|', "DATE RECORD CREATED ON
WA-STLNR, 68 '|', "BILL OF MATERIAL
WA-STLAL, 79 '|', "ALTERNATIVE BOM
WA-DATUV, 91 '|', "VALID FROM DATE
WA-STLST, 102 '|', "BOM STATUS
WA-STLTY, 115 '|', "BOM CATEGORY
WA-STLKN, 130 '|'. "BOM ITEM NODE NUMBER
ULINE.
ENDLOOP.
IF SY-SUBRC NE 0.
SKIP.
ULINE.
WRITE : '|', 'DATA NOT FOUND FOR GIVEN CRITERIA' COLOR 7 INVERSE ON , 130 '|'.
ENDIF.
TABLES: MAST, STKO, STPO.
DATA: BEGIN OF WA,
MATNR TYPE MAST-MATNR,
WERKS TYPE MAST-WERKS,
STLAN TYPE MAST-STLAN,
ANDAT TYPE MAST-ANDAT,
STLNR TYPE MAST-STLNR,
STLAL TYPE STKO-STLAL,
DATUV TYPE STKO-DATUV,
STLST TYPE STKO-STLST,
STLTY TYPE STPO-STLTY,
STLKN TYPE STPO-STLKN,
END OF WA.
DATA: ITAB LIKE STANDARD TABLE OF WA.
WRITE:
'|','MATERIAL NUMBER', 23 '|',
'PLANT', 29'|',
'BOM USAGE', 42'|',
'CREATED ON', 56'|',
'BOM',68'|',
'ALT BOM',79'|',
'VALID FROM',91'|',
'STATUS',102'|',
'CATEGORY',115'|',
'ITEM NODER',130'|'.
ULINE.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_MATNR FOR MAST-MATNR,
S_WERKS FOR MAST-WERKS NO-EXTENSION,
S_STLNR FOR STKO-STLNR NO INTERVALS.
SELECTION-SCREEN END OF BLOCK B1.
SELECT K~MATNR K~WERKS K~STLAN K~ANDAT K~STLNR
B~STLAL B~DATUV B~STLST
C~STLTY C~STLKN INTO CORRESPONDING FIELDS OF WA
FROM ( ( MAST AS K INNER JOIN STKO AS B
ON B~STLNR = K~STLNR )
INNER JOIN STPO AS C ON B~STLNR = C~STLNR )
WHERE K~MATNR IN S_MATNR
AND K~WERKS IN S_WERKS
AND K~STLNR IN S_STLNR.
APPEND WA TO ITAB.
ENDSELECT.
LOOP AT ITAB INTO WA.
WRITE:
'|',05 WA-MATNR, 23 '|', "MATERIAL NUMBER
WA-WERKS, 29 '|', "PLANT
WA-STLAN, 42 '|', "BOM USAGE
WA-ANDAT, 56 '|', "DATE RECORD CREATED ON
WA-STLNR, 68 '|', "BILL OF MATERIAL
WA-STLAL, 79 '|', "ALTERNATIVE BOM
WA-DATUV, 91 '|', "VALID FROM DATE
WA-STLST, 102 '|', "BOM STATUS
WA-STLTY, 115 '|', "BOM CATEGORY
WA-STLKN, 130 '|'. "BOM ITEM NODE NUMBER
ULINE.
ENDLOOP.
IF SY-SUBRC NE 0.
SKIP.
ULINE.
WRITE : '|', 'DATA NOT FOUND FOR GIVEN CRITERIA' COLOR 7 INVERSE ON , 130 '|'.
ENDIF.
No comments:
Post a Comment