Skip to Content
0
Former Member
Jul 30, 2007 at 11:50 AM

Problem with message

20 Views

Hi. I have a small problem. I'd like the MESSAGE when there are no records returned by SELECT statement. It works, but when message is of type 'E', some empty screen is generated and nothing is going on. When message is of type 'S', the msg appears but program goes further and I don't want it.

I'd like like the msg to appears on the selection screen. Can You tell me how to make it? Greetings. P.

REPORT ZWOP_SKLADY LINE-SIZE 300
NO STANDARD PAGE HEADING.

TABLES: ekko, ekpo, mvke, mara, mbew, t001w, s032, mkpf.

DATA: sum   TYPE i.
DATA: stuf  TYPE mvke-sstuf.
DATA: maktx(20).

DATA: BEGIN OF werkstab_,
        werks TYPE ekpo-werks,
        menge TYPE mseg-menge,
      END OF werkstab_.
DATA: werkstab LIKE werkstab_ OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF itab_,
        matnr TYPE ekpo-matnr,
        werks TYPE ekpo-werks,
        maktx TYPE maktx,
        sstuf TYPE mvke-sstuf,
        ekgrp TYPE ekko-ekgrp,
        menge TYPE mseg-menge,
        matkl TYPE matkl,
        lifnr TYPE ekko-lifnr,
      END OF itab_.
DATA: itab LIKE itab_ OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF printtab OCCURS 0,
        matnr TYPE ekpo-matnr,
        maktx TYPE maktx,
        sstuf TYPE mvke-sstuf,
        sum_total TYPE mseg-menge,
        werkstab LIKE werkstab_ OCCURS 0,
        matkl TYPE matkl,
        lifnr TYPE ekko-lifnr,
      END OF printtab.
DATA: line LIKE LINE OF werkstab.


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
  SELECTION-SCREEN BEGIN OF BLOCK x WITH FRAME.
    PARAMETERS ekorg LIKE ekko-ekorg DEFAULT '1200'.
    SELECT-OPTIONS werks FOR ekpo-werks DEFAULT '1204'
                                        TO      '1206'.
  SELECTION-SCREEN END OF BLOCK x.
  SELECTION-SCREEN BEGIN OF BLOCK y WITH FRAME.
    SELECT-OPTIONS budat FOR mkpf-budat DEFAULT '20070501'
                                        TO      '20070530'.
    SELECT-OPTIONS lifnr FOR ekko-lifnr.
  SELECTION-SCREEN END OF BLOCK y.
  SELECTION-SCREEN BEGIN OF BLOCK z WITH FRAME.
    SELECT-OPTIONS matnr FOR s032-matnr.
    SELECT-OPTIONS lgort FOR s032-lgort DEFAULT '0005'.
    SELECT-OPTIONS sstuf FOR mvke-sstuf.
*   SELECT-OPTIONS ekgrp FOR ekko-ekgrp.
    SELECT-OPTIONS matkl FOR mara-matkl.
    SELECT-OPTIONS saity FOR mara-saity.
  SELECTION-SCREEN END OF BLOCK z.
SELECTION-SCREEN END OF BLOCK b1.

PERFORM get_werkslist.
PERFORM get_movement.
PERFORM prepare_content.
PERFORM print_content.

*&---------------------------------------------------------------------*
*&      Form  get_werkslist
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_werkslist.

SELECT werks FROM t001w
INTO werkstab-werks
WHERE werks IN werks AND 
      ekorg EQ ekorg.
APPEND werkstab.
ENDSELECT.

ENDFORM.                    " get_werkslist

*&---------------------------------------------------------------------*
*&      Form  get_movement
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_movement.

SELECT mseg~matnr mseg~werks mseg~menge mvke~sstuf
       mara~matkl
FROM mseg
  JOIN mvke ON mvke~matnr = mseg~matnr
           AND mvke~vkorg = ekorg
  JOIN mara ON mara~matnr = mseg~matnr
  JOIN zmatlif_dnes ON zmatlif_dnes~matnr = mseg~matnr
  JOIN t001w ON  t001w~werks = mseg~werks
  JOIN mkpf ON mkpf~mblnr = mseg~mblnr
INTO (itab-matnr, itab-werks, itab-menge, itab-sstuf,
      itab-matkl)
WHERE t001w~werks IN werks        AND
      mkpf~budat IN budat         AND
      shkzg = 'S'                 AND
      lgort In lgort              AND
      mseg~matnr IN matnr         AND
      zmatlif_dnes~lifnr IN lifnr AND
      mara~saity IN saity         AND
      mara~matkl IN matkl         AND
      mvke~sstuf IN sstuf
      .
  APPEND itab.
ENDSELECT.

IF sy-subrc <> 0.
  MESSAGE S000(ZWOP_MSG) WITH 'aaa'.
ENDIF.

ENDFORM.                    " get_movement

*&---------------------------------------------------------------------*
*&      Form  prepare_content
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM prepare_content.

SORT itab BY matnr werks.
LOOP AT itab.
  stuf = itab-sstuf.
  AT NEW matnr.
    CLEAR printtab.
    printtab-matnr = itab-matnr.
    printtab-sstuf = stuf.
    LOOP AT werkstab.
      CLEAR werkstab-menge.
      MODIFY werkstab.
    ENDLOOP.
    CLEAR maktx.
    SELECT SINGLE maktx INTO maktx FROM makt
    WHERE matnr = itab-matnr AND spras = sy-langu.
    printtab-maktx = maktx.
    CLEAR sum.
  ENDAT.

  READ TABLE werkstab WITH KEY werks = itab-werks.
  werkstab-menge = werkstab-menge + itab-menge.
  MODIFY werkstab TRANSPORTING menge WHERE werks = itab-werks.
  sum = sum + werkstab-menge.

  printtab-matkl = itab-matkl.
  printtab-lifnr = itab-lifnr.
  AT END OF matnr.
    LOOP AT werkstab.
      APPEND werkstab TO printtab-werkstab.
    ENDLOOP.
    printtab-sum_total = sum.
    APPEND printtab.
  ENDAT.
ENDLOOP.

SORT printtab BY matnr.


ENDFORM.                    " prepare_content
*&---------------------------------------------------------------------*
*&      Form  print_content
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM print_content.

WRITE: (55) ' ', '|'.
LOOP AT werkstab.
  WRITE: (4) werkstab-werks RIGHT-JUSTIFIED, '|'.
ENDLOOP.

LOOP AT printtab.
  WRITE: /(10) printtab-matnr, '|'.
  WRITE: (5) printtab-sstuf, '|'.
  WRITE: (20) printtab-maktx, '|'.
  WRITE: (5) printtab-matkl, '|'.
  WRITE: (3) printtab-sum_total, '|'.
  LOOP AT printtab-werkstab INTO line.
    IF line-menge EQ 0.
      WRITE: (4) line-menge COLOR 6 INVERSE ON DECIMALS 0, '|'.
    ELSEIF line-menge GT 0.
      WRITE: (4) line-menge COLOR 6 INVERSE OFF DECIMALS 0, '|'.
    ENDIF.
  ENDLOOP.
ENDLOOP.

SET LEFT SCROLL-BOUNDARY COLUMN 58.

ENDFORM.                    " print_content