FORALLENTRIES:-
Steps to work for all entries:-
1. Declare one final data internal table which data we want to display & also declare one work area & internal table for each participated data base table.
2. Based on the given input we will fetch the data from data base & filled into data base internal table.
3. Based on the data base internal table data we fill the final internal table data.
Procedure to fill the final internal table: - First we identify the number of primary keys in each participated data base table. If the number of primary keys are ‘1’ that is read. If the number of primary keys is more than ‘1’ that is loop.
Loop the many primary keys data base internal table & read the single primary key internal table & populate the final internal table.
Note: - when ever we are working with for all entries then you must consider higher level internal table having the data. Suppose if you’re not consider & higher level internal table having no data. Then it’ll pick the entire data from next level.
PROGRAM :
Based on the given material numbers display the material numbers, material types, plant numbers, and plant names by using for all entries.
*&---------------------------------------------------------------------*
*& Report ZR_FORALLENTRIES
*&
*&---------------------------------------------------------------------*
REPORT ZR_FORALLENTRIES.
DATA LV_MATNR TYPE MARA-MATNR.
*selection screen
SELECTION-SCREEN BEGIN OF BLOCK Z.
SELECT-OPTIONS SO_MATNR FOR LV_MATNR.
SELECTION-SCREEN END OF BLOCK Z.
*types declaration
TYPES : BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
END OF TY_MARA,
BEGIN OF TY_MARC,
MATNR TYPE MARC-MATNR,
WERKS TYPE MARC-WERKS,
END OF TY_MARC,
BEGIN OF TY_T001W,
WERKS TYPE T001W-WERKS,
NAME1 TYPE T001W-NAME1,
END OF TY_T001W,
BEGIN OF TY_FINAL,
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
WERKS TYPE MARC-WERKS,
NAME1 TYPE T001W-NAME1,
END OF TY_FINAL.
*workarea and internal table declarations
DATA : WA_MARA TYPE TY_MARA,
IT_MARA TYPE TABLE OF TY_MARA,
WA_MARC TYPE TY_MARC,
IT_MARC TYPE TABLE OF TY_MARC,
WA_T001W TYPE TY_T001W,
IT_T001W TYPE TABLE OF TY_T001W,
WA_FINAL TYPE TY_FINAL,
IT_FINAL TYPE TABLE OF TY_FINAL.
*fetch data from database
SELECT MATNR MTART
FROM MARA
INTO TABLE IT_MARA
WHERE MATNR IN SO_MATNR.
IF IT_MARA IS NOT INITIAL.
SELECT MATNR WERKS
FROM MARC
INTO TABLE IT_MARC
FOR ALL ENTRIES IN IT_MARA
WHERE MATNR = IT_MARA-MATNR.
ENDIF.
IF IT_MARC IS NOT INITIAL.
SELECT WERKS NAME1
FROM T001W
INTO TABLE IT_T001W
FOR ALL ENTRIES IN IT_MARC
WHERE WERKS = IT_MARC-WERKS.
ENDIF.
*fill the final internal table
LOOP AT IT_MARC INTO WA_MARC.
WA_FINAL-MATNR = WA_MARC-MATNR.
WA_FINAL-WERKS = WA_MARC-WERKS.
READ TABLE IT_MARA
INTO WA_MARA
WITH KEY MATNR = WA_MARC-MATNR.
WA_FINAL-MTART = WA_MARA-MTART.
READ TABLE IT_T001W
INTO WA_T001W
WITH KEY WERKS = WA_MARC-WERKS.
WA_FINAL-NAME1 = WA_T001W-NAME1.
APPEND WA_FINAL TO IT_FINAL.
CLEAR WA_FINAL.
ENDLOOP.
*display data
LOOP AT IT_FINAL INTO WA_FINAL.
WRITE : / WA_FINAL-MATNR,
WA_FINAL-MTART,
WA_FINAL-WERKS,
WA_FINAL-NAME1.
ENDLOOP.
Steps to work for all entries:-
1. Declare one final data internal table which data we want to display & also declare one work area & internal table for each participated data base table.
2. Based on the given input we will fetch the data from data base & filled into data base internal table.
3. Based on the data base internal table data we fill the final internal table data.
Procedure to fill the final internal table: - First we identify the number of primary keys in each participated data base table. If the number of primary keys are ‘1’ that is read. If the number of primary keys is more than ‘1’ that is loop.
Loop the many primary keys data base internal table & read the single primary key internal table & populate the final internal table.
Note: - when ever we are working with for all entries then you must consider higher level internal table having the data. Suppose if you’re not consider & higher level internal table having no data. Then it’ll pick the entire data from next level.
PROGRAM :
Based on the given material numbers display the material numbers, material types, plant numbers, and plant names by using for all entries.
*&---------------------------------------------------------------------*
*& Report ZR_FORALLENTRIES
*&
*&---------------------------------------------------------------------*
REPORT ZR_FORALLENTRIES.
DATA LV_MATNR TYPE MARA-MATNR.
*selection screen
SELECTION-SCREEN BEGIN OF BLOCK Z.
SELECT-OPTIONS SO_MATNR FOR LV_MATNR.
SELECTION-SCREEN END OF BLOCK Z.
*types declaration
TYPES : BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
END OF TY_MARA,
BEGIN OF TY_MARC,
MATNR TYPE MARC-MATNR,
WERKS TYPE MARC-WERKS,
END OF TY_MARC,
BEGIN OF TY_T001W,
WERKS TYPE T001W-WERKS,
NAME1 TYPE T001W-NAME1,
END OF TY_T001W,
BEGIN OF TY_FINAL,
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
WERKS TYPE MARC-WERKS,
NAME1 TYPE T001W-NAME1,
END OF TY_FINAL.
*workarea and internal table declarations
DATA : WA_MARA TYPE TY_MARA,
IT_MARA TYPE TABLE OF TY_MARA,
WA_MARC TYPE TY_MARC,
IT_MARC TYPE TABLE OF TY_MARC,
WA_T001W TYPE TY_T001W,
IT_T001W TYPE TABLE OF TY_T001W,
WA_FINAL TYPE TY_FINAL,
IT_FINAL TYPE TABLE OF TY_FINAL.
*fetch data from database
SELECT MATNR MTART
FROM MARA
INTO TABLE IT_MARA
WHERE MATNR IN SO_MATNR.
IF IT_MARA IS NOT INITIAL.
SELECT MATNR WERKS
FROM MARC
INTO TABLE IT_MARC
FOR ALL ENTRIES IN IT_MARA
WHERE MATNR = IT_MARA-MATNR.
ENDIF.
IF IT_MARC IS NOT INITIAL.
SELECT WERKS NAME1
FROM T001W
INTO TABLE IT_T001W
FOR ALL ENTRIES IN IT_MARC
WHERE WERKS = IT_MARC-WERKS.
ENDIF.
*fill the final internal table
LOOP AT IT_MARC INTO WA_MARC.
WA_FINAL-MATNR = WA_MARC-MATNR.
WA_FINAL-WERKS = WA_MARC-WERKS.
READ TABLE IT_MARA
INTO WA_MARA
WITH KEY MATNR = WA_MARC-MATNR.
WA_FINAL-MTART = WA_MARA-MTART.
READ TABLE IT_T001W
INTO WA_T001W
WITH KEY WERKS = WA_MARC-WERKS.
WA_FINAL-NAME1 = WA_T001W-NAME1.
APPEND WA_FINAL TO IT_FINAL.
CLEAR WA_FINAL.
ENDLOOP.
*display data
LOOP AT IT_FINAL INTO WA_FINAL.
WRITE : / WA_FINAL-MATNR,
WA_FINAL-MTART,
WA_FINAL-WERKS,
WA_FINAL-NAME1.
ENDLOOP.