Skip to end of metadata
Go to start of metadata

This code provides the functionality of dynamic selection-screen. User can choose the input criterion according to their needs.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT purchase_data.

TABLES:
    ekko,
    ekpo,
    sbook,
    sscrfields.

*" Type declarations................................................
*"--------------------------------------------------------------------*
*  Type declaration of the structure to Purchase data         *
*"--------------------------------------------------------------------*

TYPE-POOLS icon.

TYPES:
  BEGIN OF types_s_tab,
    ebeln TYPE ekko-ebeln,                                           " Purchasing Document Number
    ebelp TYPE ekpo-ebelp,                                          " Purchasing Document Item
    bsart TYPE  ekko-bsart,                                          " Purchasing Document type
    bukrs TYPE ekko-bukrs,                                          " Company Code
    aedat TYPE ekko-aedat,                                        " Date on which record created
    matnr TYPE ekpo-matnr,                                        " Material Number
    meins TYPE ekpo-meins,                                        " Order Unit
    menge TYPE ekpo-menge,                                     " Purchase Order Quantity
    netwr TYPE ekpo-netwr,                                        " Net Order Value in PO Currency
    wert TYPE ekpo-zwert,                                          " Currency
    CUKY TYPE SBOOK-LOCCURKEY,                          " Currency
  END OF types_s_tab.

*" Data declarations................................................
*"--------------------------------------------------------------------*
* Field String to hold Checkbox statu.                                  *
*"--------------------------------------------------------------------*

DATA:
        fs_mark TYPE c.

*"--------------------------------------------------------------------*
* Field String to hold Function Button value.                        *
*"--------------------------------------------------------------------*
DATA:
      functxt TYPE smp_dyntxt.
*"--------------------------------------------------------------------*
* Field String to hold internal table data for Purchase Data.*
*"--------------------------------------------------------------------*

DATA:
      fs_tab TYPE types_s_tab.

*"--------------------------------------------------------------------*
* Field String to hold flaged data field value.        .              *
*"--------------------------------------------------------------------*

DATA:
      fl_flag TYPE ekko-ebeln.
*"--------------------------------------------------------------------*
* Internal Table to hold The Purchase Order Data.              *
*"--------------------------------------------------------------------*

DATA:
      t_tab TYPE
   STANDARD TABLE
         OF types_s_tab.

*" Selection-Screen ...............................................
*"--------------------------------------------------------------------------------*
* Selection Screen for the Purchase order Number for user input.      *
*"--------------------------------------------------------------------------------*

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

SELECT-OPTIONS:
  s_docnum FOR ekko-ebeln  MODIF ID abc.              " Document Number

SELECT-OPTIONS:
  s_docitm FOR ekpo-ebelp  MODIF ID def.              " Document Item

SELECT-OPTIONS:
 s_docty FOR ekko-bsart  MODIF ID ghi.                " Purchasing Document type

SELECT-OPTIONS:
s_comco FOR ekko-bukrs  MODIF ID jkl.                 " Company Code

SELECT-OPTIONS:
  s_date FOR ekko-aedat  MODIF ID mno.                " Date on which record created

SELECT-OPTIONS:
  s_matno FOR ekpo-matnr  MODIF ID pqr.               " Material Number

SELECT-OPTIONS:
s_orunit FOR ekpo-meins  MODIF ID stu.                " Net Order Value in PO Currency

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN: FUNCTION KEY 1.

SELECTION-SCREEN BEGIN OF SCREEN 9000 AS WINDOW TITLE txtblk03.
PARAMETERS:
  pdocnum AS CHECKBOX DEFAULT 'X',                   " Purchasing Document Number
  pdocitm AS CHECKBOX DEFAULT 'X',                   " Purchasing Document Item
  pdocty AS CHECKBOX,                                " Purchasing Document type,
  pcomco AS CHECKBOX,                                " Company Code
  pdate AS CHECKBOX,                                 " Date on which record created
  pmatno AS CHECKBOX,                                " Material Number
  porunit AS CHECKBOX.                               " Net Order Value in PO Currency
SELECTION-SCREEN END OF SCREEN 9000.

AT SELECTION-SCREEN OUTPUT.

  LOOP AT SCREEN.

    IF screen-group1 = 'ABC'.
      IF pdocnum = 'X'.
        screen-active = 1.
      ELSEIF PDOCNUM NE 'X'
         AND PDOCITM NE 'X'
         AND pdocty NE 'X'
         AND pcomco NE 'X'
         AND pdate NE 'X'
         AND pmatno NE 'X'
         AND porunit NE 'X'.
        screen-active = 1.
        pdocnum = 'X'.
        pdocitm = 'X'.
      ELSE.
        screen-active = 0.
        CLEAR s_docnum.
      ENDIF.                           " IF PDOCNUM

      MODIFY SCREEN.
    ENDIF.                             " IF SCREEN-GROUP

    IF screen-group1 = 'DEF'.

      IF pdocitm = 'X'.
        screen-active = 1.
      ELSEIF PDOCNUM NE 'X'
         AND PDOCITM NE 'X'
         AND pdocty NE 'X'
         AND pcomco NE 'X'
         AND pdate NE 'X'
         AND pmatno NE 'X'
         AND porunit NE 'X'.
        screen-active = 1.
        pdocnum = 'X'.
        pdocitm = 'X'.
      ELSE.
        screen-active = 0.
        CLEAR s_docitm .
      ENDIF.                           " IF PDOCITM

      MODIFY SCREEN.                   " IF SCREEN-GROUP
    ENDIF.

    IF screen-group1 = 'GHI'.
      IF pdocty = 'X'.
        screen-active = 1.
      ELSE.
        screen-active = 0.
        CLEAR s_docty .
      ENDIF.                           " IF PDOCTY

      MODIFY SCREEN.
    ENDIF.                             " IF SCREEN-GROUP1
    IF screen-group1 = 'JKL'.
      IF pcomco = 'X'.
        screen-active = 1.
      ELSE.
        screen-active = 0.
        CLEAR s_comco.
      ENDIF.                           " IF PCOMCO

      MODIFY SCREEN.
    ENDIF.                             " IF SCREEN-GROUP1
    IF screen-group1 = 'MNO'.
      IF pdate = 'X'.
        screen-active = 1.
      ELSE.
        screen-active = 0.
        CLEAR s_date.
      ENDIF.                           " IF PDATE

      MODIFY SCREEN.                   " IF SCREEN-GROUP1
    ENDIF.

    IF screen-group1 = 'PQR'.
      IF pmatno = 'X'.
        screen-active = 1.
      ELSE.
        screen-active = 0.
        CLEAR s_matno.
      ENDIF.                           " IF PMATNO

      MODIFY SCREEN.
    ENDIF.                             " IF SCREEN-GROUP1
    IF screen-group1 = 'STU'.
      IF porunit = 'X'.
        screen-active = 1.
      ELSE.
        screen-active = 0.
        CLEAR s_orunit.
      ENDIF.                           " IF PORUNIT

      MODIFY SCREEN.
    ENDIF.                             " IF SCREEN-GROUP1

  ENDLOOP.                             " LOOP AT SCREEN
  CLEAR fs_tab.

INITIALIZATION.
  MOVE 'Change-Selection'(010) TO sscrfields-functxt_01.
  functxt-icon_id   = icon_alv_variants.
  functxt-quickinfo = 'Selection'(011).
  functxt-icon_text = 'Change-Selection'(010).
  sscrfields-functxt_01 = functxt.

AT SELECTION-SCREEN.
  IF sscrfields-ucomm = 'FC01'.
    CALL SELECTION-SCREEN 9000 STARTING AT 10 05 ENDING AT 40 15.

  ENDIF.                               " IF SSCRFIELDS-SCREEN

START-OF-SELECTION.

  IF pdocnum NE 'X'.
    REFRESH s_docnum.
  ENDIF.
  IF pdocitm NE 'X'.
    REFRESH s_docitm.
  ENDIF.
  IF pdocty  NE 'X'.
    REFRESH s_docnum.
  ENDIF.
  IF pcomco  NE 'X'.
    REFRESH s_docitm.
  ENDIF.
  IF pdocnum NE 'X'.
    REFRESH s_docnum.
  ENDIF.
  IF pdate  NE 'X'.
    REFRESH s_docitm.
  ENDIF.
  IF pmatno  NE 'X'.
    REFRESH s_docitm.
  ENDIF.
  IF porunit  NE 'X'.
    REFRESH s_docitm.
  ENDIF.

  SELECT j0~ebeln
         j1~ebelp
         j0~bsart
         j0~bukrs
         j0~aedat
         j1~matnr
         j1~meins
         j1~menge
         j1~netwr
   INTO  TABLE t_tab
   FROM ( ekko AS j0
          INNER JOIN ekpo AS j1 ON  j0~ebeln = j1~ebeln
                                AND j0~bukrs = j1~bukrs
                                AND j0~aedat = j1~aedat )
    WHERE j0~ebeln IN s_docnum
      AND j1~ebelp IN s_docitm
      AND j0~bsart IN s_docty
      AND j0~bukrs IN s_comco
      AND j0~aedat IN s_date
      AND j1~matnr IN s_matno.

  SET PF-STATUS 'ZPURCHASEDATA'.

  WRITE:/5 'PDocuNum'(001),
        18 'PDocutype'(002),
        30 'Company Code'(003),
        45 'Datcrea'(005),
       /18 'itemNumber'(012),
        30 'MatNum'(006),
        45 'PoQ'(008),
        65 'OrUnit'(007),
        75 'NetOrCurr'(009).
  ULINE.

  LOOP AT t_tab INTO fs_tab.

    IF fl_flag NE fs_tab-ebeln.
      WRITE: /  fs_mark AS CHECKBOX,
                fs_tab-ebeln UNDER text-001 LEFT-JUSTIFIED,
                fs_tab-bsart UNDER text-002 LEFT-JUSTIFIED,
                fs_tab-bukrs UNDER text-003 LEFT-JUSTIFIED,
                fs_tab-aedat UNDER text-005 LEFT-JUSTIFIED.
      fl_flag = fs_tab-ebeln.
    ENDIF.                             " IF FL_FLAG

    SKIP.
    WRITE:  / fs_tab-ebelp UNDER text-012 LEFT-JUSTIFIED,
              fs_tab-matnr UNDER text-006 LEFT-JUSTIFIED,
              fs_tab-meins UNDER text-007 LEFT-JUSTIFIED,
              fs_tab-menge UNDER text-008 LEFT-JUSTIFIED UNIT fs_tab-meins,
              fs_tab-netwr UNDER text-009 LEFT-JUSTIFIED CURRENCY FS_TAB-CUKY.
  ENDLOOP.                             " LOOP AT T_TAB