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: 

FOR all entries of 3 standard table without inner join and alv grid display

0 Kudos
REPORT ZPR_COMBINE_TABLE_AS2 NO STANDARD PAGE HEADING.
TABLES: MARA,
        MARC,
        MBEW.

"type declaration
TYPES: BEGIN OF TY_MARA,
  MATNR TYPE MATNR,
  MTART TYPE MTART,
  MBRSH TYPE MBRSH,
  BISMT TYPE BISMT,
  MEINS TYPE MEINS,
END OF TY_MARA.

TYPES: BEGIN OF TY_MARC,
  MATNR TYPE MATNR,
  WERKS TYPE WERKS,
  DISMM TYPE DISMM,
  DISPO TYPE DISPO,
  KZDIE TYPE KZDIE,
  KZPPV TYPE KZPPV,
  MPDAU TYPE MPDAU,
END OF TY_MARC.

TYPES: BEGIN OF TY_MBEW,
  MATNR TYPE MATNR,
  BWKEY TYPE BWKEY,
  BWTAR TYPE BWTAR_D,
  STPRV TYPE STPRV,
  LAEPR TYPE LAEPR,
  ZKPRS TYPE DZKPRS,
  ZKDAT TYPE DZKDAT,
END OF TY_MBEW.

TYPES: BEGIN OF TY_FINAL,
  MATNR TYPE N LENGTH 13,
  MTART TYPE C LENGTH 15,
  MBRSH TYPE C LENGTH 16,
  BISMT TYPE N LENGTH 20,
  MEINS TYPE N LENGTH 21,
  WERKS TYPE C LENGTH 6,
  DISMM TYPE C LENGTH 9,
  DISPO TYPE C LENGTH 15,
  KZDIE TYPE C LENGTH 35,
  KZPPV TYPE C LENGTH 30,
  MPDAU TYPE N LENGTH 25,
  BWKEY TYPE C LENGTH 15,
  BWTAR TYPE C LENGTH 15,
  STPRV TYPE N LENGTH 16,
  LAEPR TYPE N LENGTH 26,
  ZKPRS TYPE N LENGTH 13,
  ZKDAT TYPE N LENGTH 36,
END OF TY_FINAL.

DATA: T_FINAL TYPE TY_FINAL.
DATA: ITAB LIKE STANDARD TABLE OF T_FINAL WITH HEADER LINE.

" Data and Work Area
DATA:  T_MARA TYPE STANDARD TABLE OF TY_MARA,
       WA_MARA TYPE                  TY_MARA,
       T_MARC TYPE STANDARD TABLE OF TY_MARC,
       WA_MARC TYPE                  TY_MARC,
       T_MBEW TYPE STANDARD TABLE OF TY_MBEW,
       WA_MBEW TYPE                  TY_MBEW.



 "selection screen
SELECTION-SCREEN BEGIN OF BLOCK part1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS   s_matnr FOR mara-matnr OBLIGATORY.
SELECT-OPTIONS   s_WERKS FOR MARC-WERKS.
SELECT-OPTIONS   s_BWKEY FOR MBEW-BWKEY.
SELECT-OPTIONS   s_BWTAR FOR MBEW-BWTAR.
SELECTION-SCREEN END OF BLOCK part1.

START-OF-SELECTION.
"Select query
   SELECT  MATNR
           MTART
           MBRSH
           BISMT
           MEINS
  FROM mara INTO TABLE T_mara
  WHERE matnr IN s_matnr.

IF t_mara is NOT INITIAL.
    SELECT MATNR
           WERKS
           DISMM
           DISPO
           KZDIE
           KZPPV
           MPDAU
  FROM marc INTO TABLE t_marc
      FOR ALL ENTRIES IN t_mara
  WHERE matnr = t_mara-matnr
      AND werks IN s_werks.

 SELECT   MATNR
          BWKEY
          BWTAR
          STPRV
          LAEPR
          ZKPRS
          ZKDAT
  FROM mbew INTO TABLE t_mbew
   for ALL ENTRIES IN t_mara
  WHERE matnr = t_mara-matnr
   AND bwkey IN s_bwkey
   AND bwtar IN s_bwtar.
   endif.
END-OF-SELECTION.
PERFORM PUT_OUTPUT.


FORM put_mara.
  IF sy-subrc ne 0.
    MESSAGE 'Material Doesn''t Exist.' TYPE 'I'.
    LEAVE LIST-PROCESSING.
  ENDIF.
ENDFORM.
FORM put_output.
   IF T_MARA IS NOT INITIAL.
   LOOP AT T_MARA INTO WA_MARA.
   WRITE: 13 wa_MARA-matnr,
          15 wa_MARA-MTART,
          16 wa_MARA-MBRSH,
          20 wa_MARA-BISMT,
          21 wa_MARA-MEINS,
          6  wa_MARC-WERKS,
          9  wa_MARC-DISMM,
          15 wa_MARC-DISPO,
          35 wa_MARC-KZDIE,
          30 wa_MARC-KZPPV,
          25 wa_MARC-MPDAU,
          15 wa_MBEW-BWKEY,
          15 wa_MBEW-BWTAR,
          16 wa_MBEW-STPRV,
          26 wa_MBEW-LAEPR,
          13 wa_MBEW-ZKPRS,
          36 wa_MBEW-ZKDAT.
      ENDLOOP.
ENDIF.
ENDFORM.

TOP-OF-PAGE.
WRITE: 13 'Material No',
       15 'Material Type',
       16 'Industry Sector',
       20 'Old material number',
       21 'Base Unit of Measure',
       6  'Plant',
       9  'MRP Type',
       15 'MRP Controller',
       35 'Indicator: MRP controller is buyer',
       30 'Indicator for inspection plan',
       25 'Mean inspection duration',
       15 'Valuation Area',
       15 'Valuation Type',
       16 'Previous price',
       26 'Date of the last price change',
       13 'Future price',
       36 'Date as of which the price is valid'.
ULINE.
END-OF-PAGE.

Attached output image for your reference any one please help me with the correct code.

Above is my code here i need to print the output in a table format of selected fields from the standard table of mara marc and mbew table, While opening alv ouput report about is not expected, Kindly let me know the code to get the exact output.

8 REPLIES 8

FredericGirod
Active Contributor

You could remove the FOR ALL ENTRIES, and replace with a simple WHERE clause with

matnr IN s_matnr

your code will go faster

second point:

Where did you make access to table T_MARC, T_MBEW ?

FORM put_output.
   IF T_MARA IS NOT INITIAL.
   LOOP AT T_MARA INTO WA_MARA.
   WRITE: 13 wa_MARA-matnr,
          15 wa_MARA-MTART,
          16 wa_MARA-MBRSH,
          20 wa_MARA-BISMT,
          21 wa_MARA-MEINS,
          6  wa_MARC-WERKS,
          9  wa_MARC-DISMM,
          15 wa_MARC-DISPO,
          35 wa_MARC-KZDIE,
          30 wa_MARC-KZPPV,
          25 wa_MARC-MPDAU,
          15 wa_MBEW-BWKEY,
          15 wa_MBEW-BWTAR,
          16 wa_MBEW-STPRV,
          26 wa_MBEW-LAEPR,
          13 wa_MBEW-ZKPRS,
          36 wa_MBEW-ZKDAT.
      ENDLOOP.
ENDIF.
ENDFORM.

how to merge that t_marc and t_mbew in t_mara to print the output. let me explain through code. I'm new to this skill.

FredericGirod
Active Contributor
   LOOP AT T_MARA INTO WA_MARA.
     LOOP AT T_MARC INTO WA_MARC
          WHERE MATNR EQ WA_MARA-MATNR.
   WRITE: 13 wa_MARA-matnr,
          15 wa_MARA-MTART,
          16 wa_MARA-MBRSH,
          20 wa_MARA-BISMT,
          21 wa_MARA-MEINS,
          6  wa_MARC-WERKS,
          9  wa_MARC-DISMM,
          15 wa_MARC-DISPO,
          35 wa_MARC-KZDIE,
          30 wa_MARC-KZPPV,
          25 wa_MARC-MPDAU,
          15 wa_MBEW-BWKEY,
          15 wa_MBEW-BWTAR,
          16 wa_MBEW-STPRV,
          26 wa_MBEW-LAEPR,
          13 wa_MBEW-ZKPRS,
          36 wa_MBEW-ZKDAT.

        ENDLOOP.
      ENDLOOP.

the link with MBEW is not so simple. You have to find the link between BWKEY & WERKS

To find BWKEY from WERKS look at T001W table.

0 Kudos

Yes raymond.giuseppi !

matt
Active Contributor

Why the artificial constraint in not using a JOIN? Do you want your code to run slowly?

Sandra_Rossi
Active Contributor

Using FOR ALL ENTRIES instead of JOIN when you can is a very "bad" idea.

matt
Active Contributor
0 Kudos

To clarify what Sandra said. It is a very bad idea to use FOR ALL ENTRIES instead of JOIN.

1. It is more error prone

2. It is non-standard SQL

3. It is in most cases slower than JOIN.