*&---------------------------------------------------------------------*
*& Report ZTR_DEMO_REPORT4 *
*& *
*&Report : Join method 1 *
*&This Report is use ful to joined two table *
*& *
*&---------------------------------------------------------------------*
REPORT ZTR_DEMO_REPORT4 .
TABLES : YEMP , YSAL .
*Type Declaration
TYPES : BEGIN OF ST_JOIN ,
EMP_NO LIKE YEMP-EMP_NO ,
EMP_NAME LIKE YEMP-EMP_NAME,
SALARY LIKE YSAL-SALARY,
SALARY_UNIT LIKE YSAL-SALARY_UNIT,
END OF ST_JOIN,
BEGIN OF ST_SAL ,
EMP_NO LIKE YEMP-EMP_NO ,
SALARY LIKE YSAL-SALARY,
SALARY_UNIT LIKE YSAL-SALARY_UNIT,
END OF ST_SAL,
BEGIN OF ST_EMP,
EMP_NO LIKE YEMP-EMP_NO ,
EMP_NAME LIKE YEMP-EMP_NAME,
END OF ST_EMP.
*Data Declaration
***Work Area Declaration
DATA : WA_JOIN TYPE ST_JOIN ,
WA_EMP TYPE ST_EMP,
WA_SAL TYPE ST_SAL.
***Internal Table Declaration
DATA : IT_JOIN LIKE STANDARD TABLE OF WA_JOIN,
IT_SAL LIKE STANDARD TABLE OF WA_SAL,
IT_EMP LIKE STANDARD TABLE OF WA_EMP.
*Select data from YEMP
SELECT EMP_NO EMP_NAME FROM YEMP INTO TABLE IT_EMP .
IF SY-SUBRC EQ 0 .
*Select Record from YSAL table using YEMP table with For all Entries
*Concept
SELECT EMP_NO SALARY SALARY_UNIT
FROM YSAL
INTO
TABLE IT_SAL
FOR ALL ENTRIES IN IT_EMP
WHERE EMP_NO EQ IT_EMP-EMP_NO .
ENDIF.
*Append Selectd Record into Joined Table i.e ( IT_JOIN )
LOOP AT IT_SAL INTO WA_SAL .
MOVE : WA_SAL-EMP_NO TO WA_JOIN-EMP_NO ,
WA_SAL-SALARY TO WA_JOIN-SALARY,
WA_SAL-SALARY_UNIT TO WA_JOIN-SALARY_UNIT.
APPEND WA_JOIN TO IT_JOIN .
ENDLOOP .
*Read Emp name from YEMP table and Modify IT_JOINED table .
LOOP AT IT_JOIN INTO WA_JOIN .
READ TABLE IT_EMP INTO WA_EMP WITH KEY EMP_NO = WA_JOIN-EMP_NO .
IF SY-SUBRC EQ 0 .
MOVE : WA_EMP-EMP_NAME TO WA_JOIN-EMP_NAME.
MODIFY IT_JOIN FROM WA_JOIN .
ENDIF.
ENDLOOP .
*Sort IT_JOIN table in ascending Order .
SORT IT_JOIN ASCENDING BY EMP_NO.
*Display the record from IT_JOIN table.
LOOP AT IT_JOIN INTO WA_JOIN .
WRITE :/5 WA_JOIN-EMP_NO ,
20 WA_JOIN-EMP_NAME,
45 WA_JOIN-SALARY,
60 WA_JOIN-SALARY_UNIT.
ENDLOOP.
No comments:
Post a Comment