Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Function Module

REPORT  zreport                                 .
TABLES:vbap,vbak.

*Declare the internal table in same format as shown below.
DATA:BEGIN OF itab OCCURS 0,
       vbeln LIKE vbak-vbeln,
       bsark LIKE vbak-bsark,
       vtweg LIKE vbak-vtweg,
       spart LIKE vbak-spart,
       vdatu LIKE vbak-vdatu,
     END OF itab .

DATA:BEGIN OF it_vbap OCCURS 0,
       matnr LIKE vbap-matnr,
       netpr LIKE vbap-netpr,
       werks LIKE vbap-werks,
       kbmeng LIKE vbap-kbmeng,
     END OF it_vbap.

DATA:fld(20) TYPE c.
DATA:val(20) TYPE c.

TOP-OF-PAGE.
  WRITE:/1(10) 'ORDER NO', 12'!', 13(10) 'ORDER TYPE', 24'!', 25(12) 'DIST CHANNEL', 38'!',
  39(8) 'DIVISION', 48'!', 49(8) 'DEL DATE'.

TOP-OF-PAGE DURING LINE-SELECTION.
  WRITE:/1(10) 'MAT NO', 12'!', 13(11) 'TOTAL PRICE', 25'!', 26(14) 'DELIVERY PLANT', 41'!',
  42(18) 'CONFIRMED QUANTITY', 61'!'.", 49(8) 'DEL DATE'.

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

  SELECTION-SCREEN:BEGIN OF LINE.
  SELECTION-SCREEN:COMMENT 4(20) text-002.
  SELECT-OPTIONS:s_erdat FOR vbak-erdat.
  SELECTION-SCREEN:END OF LINE.

  SELECTION-SCREEN:BEGIN OF LINE.
  SELECTION-SCREEN:COMMENT 4(20) text-003.
  SELECT-OPTIONS:s_vkorg FOR vbak-vkorg.
  SELECTION-SCREEN:END OF LINE.

  SELECTION-SCREEN:BEGIN OF LINE.
  SELECTION-SCREEN:COMMENT 4(20) text-004.
  SELECT-OPTIONS:s_vtweg FOR vbak-vtweg.
  SELECTION-SCREEN:END OF LINE.

  SELECTION-SCREEN:BEGIN OF LINE.
  SELECTION-SCREEN:COMMENT 4(20) text-005.
  SELECT-OPTIONS:s_bsark FOR vbak-bsark.
  SELECTION-SCREEN:END OF LINE.

  SELECTION-SCREEN:BEGIN OF LINE.
  SELECTION-SCREEN:COMMENT 4(20) text-006.
  SELECT-OPTIONS:s_spart FOR vbak-spart.
  SELECTION-SCREEN:END OF LINE.
  SELECTION-SCREEN:END OF BLOCK b1.

START-OF-SELECTION.

  SELECT vbeln bsark vtweg spart vdatu
         FROM vbak
         INTO CORRESPONDING FIELDS OF TABLE itab
         INTO TABLE ITAB
         WHERE erdat IN s_erdat
               AND vkorg IN s_vkorg
               AND vtweg IN s_vtweg
               AND bsark IN s_bsark
               AND spart IN s_spart.

AT SELECTION-SCREEN.
  PERFORM screen_check.

AT LINE-SELECTION.
  GET CURSOR FIELD fld VALUE val.  "#EC
  IF fld = 'ITAB-VBELN'.
    WINDOW STARTING AT 20 20 ENDING AT 80 80.
    SET PF-STATUS 'ABC'.
    SELECT matnr netpr werks kbmeng
    INTO TABLE it_vbap
    FROM vbap
    WHERE vbeln = itab-vbeln.
    LOOP AT it_vbap.
      WRITE:/1(10) it_vbap-matnr, 12'!', 13(11) it_vbap-netpr, 25'!', 26(14) it_vbap-werks, 41'!', 42(18) it_vbap-kbmeng, 61'!' .
    ENDLOOP.
  ENDIF.

AT USER-COMMAND.
  CASE sy-ucomm.
    WHEN 'BACKK'.
      sy-lsind = sy-lsind - 2.
  ENDCASE.

END-OF-SELECTION .

  LOOP AT itab.
    WRITE:/1(10) itab-vbeln, 12'!', 13(10) itab-bsark, 24'!', 25(12) itab-vtweg, 38'!',
    39(8) itab-spart, 48'!', 49(8) itab-vdatu.
    HIDE itab-vbeln.
  ENDLOOP.

*&---------------------------------------------------------------------*
*&      Form  SCREEN_CHECK
*&---------------------------------------------------------------------*
*   Checking for Selection Screen fields Validation
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM screen_check.

* Validation of Sales Organization
  CLEAR vbak.
*  clear s_vtweg.
  IF NOT s_vkorg-low IS INITIAL.
    SELECT vkorg FROM vbak UP TO 1 ROWS
    INTO vbak-vkorg
    WHERE vkorg IN s_vkorg.
    ENDSELECT.
    IF sy-subrc NE 0.
      MESSAGE e009(zabc). " Invalid Sales Organization
    ENDIF.
  ENDIF.

* Validation of Distribution Channel
  CLEAR vbak.
*  clear s_vkorg.
  IF NOT s_vtweg-low IS INITIAL.
    SELECT vtweg FROM tvtw UP TO 1 ROWS
    INTO vbak-vtweg
    WHERE vtweg IN s_vtweg.
    ENDSELECT.
    IF sy-subrc NE 0.
      MESSAGE e010(zabc). " Invalid Distribution Channel
    ENDIF.
  ENDIF.

* Validation of Division
  CLEAR vbak.
  IF NOT s_spart-low IS INITIAL.
    SELECT spart FROM tspa UP TO 1 ROWS
    INTO vbak-spart
    WHERE spart IN s_spart.
    ENDSELECT.
    IF sy-subrc NE 0.
      MESSAGE e011(zabc). " Invalid Division
    ENDIF.
  ENDIF.

* Validation of delivery
  CLEAR vbak.
  IF NOT s_bsark-low IS INITIAL.
    SELECT bsark FROM vbak UP TO 1 ROWS
    INTO vbak-bsark
    WHERE bsark IN s_bsark.
    ENDSELECT.
    IF sy-subrc NE 0.
      MESSAGE e012(zabc). " Invalid Order Type
    ENDIF.
  ENDIF.

I have created the above report. Now I want to create a function module for this particular report where I have to give the input parameters in the same way as i am giving in the selection screen over here and display the output on basis of that.So,plz anyone tell me the detailed steps how to create this function module.Points will no doubtly be awarded.Plz reply it's urgent.

Message was edited by:

ajaya moharana

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question