Application Development and Automation 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: 
Read only

interactive report code check

Former Member
0 Likes
434

Hey fellas,

my req is to make an interactive classical report where i have to fetch matnr from mara and maktx from makt and display it in the first screen report and then when we double click on matnr it should go to the second screen and display werks from marc on the basis of matnr from mara and display matnr and werks.

I know it sound silly to put such a thing in sdn but am a beginner so plz help me with getting the problem solved.

I m providing the code below which i had done plz check it......

************************************************************************
*     T A B L E S                                                      *
************************************************************************

TABLES: mara, marc, makt.

************************************************************************
*     TYPE-POOLS                                                      *
************************************************************************
TYPE-POOLS : slis.

************************************************************************
*                      DATA TYPE DECLARATION                           *
************************************************************************

TYPES : BEGIN OF ty_marc,
         matnr TYPE matnr,          "Material Numberq
         werks TYPE werks_d,        "Plant
       END OF  ty_marc.

TYPES: BEGIN OF ty_makt,
        matnr TYPE matnr,           "Material Numberq
        maktx TYPE maktx,           "Material description
       END OF ty_makt.

TYPES: BEGIN OF ty_mara,
        matnr TYPE matnr,            "Material Numberq
       END OF ty_mara.


TYPES: BEGIN OF ty_md,
      matnr TYPE matnr,            "Material Numberq
      maktx TYPE maktx,              "Material description
      END OF ty_md.

TYPES: BEGIN OF ty_md2,
       matnr TYPE matnr,
       maktx TYPE maktx,              "Material description

       END OF ty_md2.



TYPES : BEGIN OF ty_final,
      matnr TYPE matnr,              "Material Numberq
      werks TYPE werks_d,              "Plant

      maktx TYPE maktx,              "Material description

      END OF ty_final.



************************************************************************
*                       INTERNAL TABLES                                *
************************************************************************
DATA: itab_marc TYPE TABLE OF  ty_marc,
      itab_makt TYPE TABLE OF ty_makt,
      itab_mara TYPE TABLE OF ty_mara,

      itab_md TYPE TABLE OF ty_md,
      itab_md1 TYPE TABLE OF ty_md,
     itab_md2 TYPE STANDARD TABLE OF ty_md2,
      itab_final TYPE TABLE OF ty_final.


************************************************************************
*                       WORK AREA DECLARATION                          *
************************************************************************
DATA: wa_marc TYPE ty_marc,
      wa_makt TYPE ty_makt,
      wa_mara TYPE ty_mara,

      wa_md TYPE ty_md,
      wa_md1 TYPE ty_md,
      wa_md2 TYPE ty_md2,
      wa_final TYPE ty_final.



************************************************************************
*                     SELECTION-SCREEN DECLARATION

************************************************************************


SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.


SELECT-OPTIONS s_matnr FOR mara-matnr.


SELECTION-SCREEN: END OF BLOCK b1.

************************************************************************
*                    INITIALIZATION. DECLARATION

************************************************************************


INITIALIZATION.

  LOOP AT SCREEN.

    IF screen-name = 'S_MATNR'.
      screen-input = '0'.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.

*  SELECT matnr FROM marc INTO TABLE itab_md2 WHERE werks IN s_werks.


AT SELECTION-SCREEN ON  s_matnr.

  PERFORM display_material.


************************************************************************
*                      START-OF-SELECTION.                        *
************************************************************************

START-OF-SELECTION.



*  IF s_matnr IS  INITIAL.

    SELECT matnr
      FROM mara
      INTO TABLE itab_md
    WHERE matnr IN s_matnr.
    IF sy-subrc EQ 0.

      SELECT matnr
             maktx
        FROM makt
        INTO TABLE itab_md1
        FOR ALL ENTRIES IN itab_md
       WHERE matnr EQ itab_md-matnr
        AND spras = c_en_x.
* ENDIF.

LOOP at itab_md1 INTO wa_md.
      WRITE:/ '|', wa_md-matnr,20 '|', wa_md-maktx, 80 '|'.
*      HIDE:wa_md-matnr.
      WRITE:/ sy-uline(80).


    ENDLOOP.

    CLEAR wa_md-matnr.

*  ENDIF.

ENDIF.

*END-OF-SELECTION.

************************************************************************
*                     AT LINE-SELECTION.                      *
************************************************************************



AT LINE-SELECTION.



  CASE sy-lsind.
    WHEN '1'.
    check sy-subrc = 0.
*      IF NOT  wa_md IS INITIAL.
*
*        CLEAR itab_marc.

* GET DATA   MATERIAL NO, PLANT , Plant-Specific Material Status FROM
*MARC

        SELECT matnr
               werks
          FROM marc
          INTO TABLE itab_marc
         WHERE matnr EQ wa_md-matnr.

        IF sy-subrc EQ 0.                  "CHECK SY-SUBRC EQ 0
          SORT itab_marc BY matnr.        "SORT INTERNAL TABLE MARC

*          CLEAR itab_makt.                 "CLEAR INTERNAL TABLE


* take data in wa_final

LOOP AT itab_marc INTO wa_marc.
CLEAR wa_final.
wa_final-matnr = wa_marc-matnr.
wa_final-werks = wa_marc-werks.
CLEAR wa_makt.

READ TABLE itab_makt
 INTO wa_makt
 WITH KEY matnr = wa_mara-matnr. "BINARY SEARCH.


IF sy-subrc EQ 0.
wa_final-maktx = wa_makt-maktx.
ENDIF.

READ TABLE itab_mara
  INTO wa_mara
  WITH KEY matnr = wa_marc-matnr. "BINARY SEARCH.





APPEND wa_final TO itab_final.
ENDLOOP.



*END-OF-SELECTION.


        WRITE:/ .
        WRITE:/ wa_final-matnr,
                  wa_final-werks,

                  wa_final-maktx.




      ENDIF.
*      endif.
  ENDCASE.


************************************************************************
*                   Top-of-page FOR FIRST LIST                  *
************************************************************************


TOP-OF-PAGE.

  IF sy-pagno = '1'.

    WRITE:/ 'DATE:-',sy-datum.

    WRITE:/  'TIME:-',sy-uzeit,sy-uline.

    WRITE: sy-uline(80).
    WRITE:/ '|', ' MATERIAL NO ',20 '|', 'MATERIAL DESCRIPTION ',80 '|'
.
    WRITE:/ sy-uline(80).
  ENDIF.
TOP-OF-PAGE DURING LINE-SELECTION.
  IF sy-lsind = 1.
    WRITE:/ 'MATERIAL NUM','MATERIAL STSTUS','MATERIAL DESCRIPTION'.


  ENDIF.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
407

I wrote my last "classical" report last week, because (a) some sites still run versions of SAP without ALV and (b) multi-sectioned, non-tabular reports are better done without ALV...

But you didn't say the problem you had with this program... the first thing I noticed is that you have commented out "* HIDE:wa_md-matnr."... the hide puts the value into memory so it is available for the drill-down in "at line-selection" (you need to remember to clear it after "at line-selection" so your user doesn't end up drilling into info when they double-click on the page header etc).

Jonathan

2 REPLIES 2
Read only

uwe_schieferstein
Active Contributor
0 Likes
407

Hello Faisal

I wrote the last "classical" report about 8 years ago because most - if not all - of them can be easily replaced by ALV lists which are much easier to develop and they are much more user-friendly.

You may have a look at the following sample reports:

[ZUS_SDN_TWO_ALV_GRIDS|;

[ZUS_SDN_THREE_ALV_GRIDS|;

It should be a piece of cake to adjust these reports to your specific needs.

Regards

Uwe

Read only

Former Member
0 Likes
408

I wrote my last "classical" report last week, because (a) some sites still run versions of SAP without ALV and (b) multi-sectioned, non-tabular reports are better done without ALV...

But you didn't say the problem you had with this program... the first thing I noticed is that you have commented out "* HIDE:wa_md-matnr."... the hide puts the value into memory so it is available for the drill-down in "at line-selection" (you need to remember to clear it after "at line-selection" so your user doesn't end up drilling into info when they double-click on the page header etc).

Jonathan