SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Отчет о движении материала на заводе



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Thu May 29, 2008 4:35 pm    Post subject: Отчет о движении материала на заводе Reply with quote

Code:
*&---------------------------------------------------------------------*
*& Report  ZERO_REP_PMOVE                                              *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZERO_REP_PMOVE                .

tables: ekko, ekpo, mara, marc, mseg, mkpf, eina.
data: g_fcat    TYPE LVC_T_FCAT with header line.

TYPES: BEGIN OF xtable_type,
        EBELN TYPE MSEG-EBELN,
        EBELP TYPE MSEG-EBELP,
        IDNLF TYPE EINA-IDNLF,
        MATNR TYPE MSEG-MATNR,
        MFRPN TYPE MARA-MFRPN,
        prcntr TYPE char2,
        BUDAT TYPE MKPF-BUDAT,
        MENGE TYPE MSEG-MENGE,
        MEINS TYPE MSEG-MEINS,
        ntm_i TYPE char1,
        trans TYPE char1,
      END OF xtable_type.

data xtable TYPE xtable_type OCCURS 0.

SELECT-OPTIONS: p_AEDAT for EKKO-AEDAT.
PARAMETER p_werks like EKPO-WERKS OBLIGATORY.
SELECT-OPTIONS: p_BESKZ for MARC-BESKZ.
SELECT-OPTIONS: p_LGORT for EKPO-LGORT.
SELECT-OPTIONS: p_MTART for EKPO-MTART.
SELECT-OPTIONS: p_MATKL for EKPO-MATKL.
*SELECT-OPTIONS: p_BWART for MSEG-BWART.

SELECTION-SCREEN BEGIN OF BLOCK 0 WITH FRAME TITLE TEXT-001.
PARAMETERS: p_prcntr type char2 default '7E',
            p_trans type char1 default 'N',
            p_deb LIKE MSEG-BWART DEFAULT '101',
            p_cred LIKE MSEG-BWART DEFAULT '102'.
SELECTION-SCREEN END OF BLOCK 0.

*AT SELECTION-SCREEN.
INCLUDE ZERO_REP_PMOVE_GRID.

START-OF-SELECTION.

  perform data_selection.
  data nrow TYPE i.
  DESCRIBE TABLE xtable LINES nrow.
  if nrow = 0.
    MESSAGE s789(M7). "No data selected
  else.

    READ TABLE xtable INDEX 1 TRANSPORTING NO FIELDS.

    IF sy-subrc = 0.
      refresh g_fcat.
      clear g_fcat.
      PERFORM g_fcatalog.
      call screen '0100'.
    ELSE.
      IF NOT sy-calld IS INITIAL.
        LEAVE.
      ELSE.
        LEAVE TO TRANSACTION sy-tcode.
      ENDIF.
    ENDIF.
  endif.

END-OF-SELECTION.

*---------------------------------------------------------------------*
*       FORM data_selection                                           *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM data_selection.

  refresh xtable.

  TYPES: BEGIN of data_type,
            EBELN like MSEG-EBELN,
            EBELP like MSEG-EBELP,
            IDNLF like EINA-IDNLF,
            MATNR like MSEG-MATNR,
            MFRPN like MARA-MFRPN,
            prcntr TYPE char2,
            BUDAT like MKPF-BUDAT,
            MENGE like MSEG-MENGE,
            MEINS like MSEG-MEINS,
            ntm_i TYPE char1,
            trans TYPE char1,
            MENGE1 like MSEG-MENGE,
            MENGE2 like MSEG-MENGE,
            mblnr like mseg-mblnr,
  END of data_type.

  data data_t TYPE data_type OCCURS 0 with header line.

  clear data_t.

  SELECT   m1~EBELN m1~EBELP m1~MBLNR
            ze~IDNLF
            m1~MATNR ze~MFRPN
            m1~WERKS
            m1~MENGE as MENGE1
            m2~MENGE as MENGE2
            m1~MEINS
            mk~BUDAT
  INTO  CORRESPONDING FIELDS OF TABLE data_t
  FROMEKKO as e
    INNER JOIN EKPO as ze ON e~ebeln = ze~ebeln
    INNER JOIN MSEG as m1 ON ze~ebeln = m1~ebeln and
            ze~ebelp = m1~ebelp and
            m1~BWART = p_deb and m1~werks = p_werks
    INNER JOIN MKPF as mk ON mk~MBLNR = m1~MBLNR and
                              mk~MJAHR = m1~MJAHR
    INNER JOIN MARA as mr ON mr~MATNR = ze~MATNR
    INNER JOIN MARC as mc ON mc~MATNR = ze~matnr and mc~werks = p_werks
    INNER JOIN EINA as ei ON ei~INFNR = ze~INFNR
    LEFT JOIN MSEG as m2 ON m1~MJAHR = m2~SJAHR
       AND m1~MBLNR = m2~SMBLN and  m1~zeile = m2~SMBLP
       AND m2~BWART = p_cred
   WHERE e~AEDAT in p_AEDAT and
         ze~WERKS = p_WERKS and ze~LGORT IN p_LGORT and
         mc~BESKZ in p_BESKZ and
        ze~MTART in p_MTART and ze~MATKL in p_MATKL
  ORDER BY m1~ebeln m1~ebelp m1~MBLNR
        .

  LOOP at data_t.
    data_t-prcntr = p_prcntr.
    data_t-trans = p_trans.
    IF NOT ( data_t-menge2 is INITIAL ).
      data_t-menge = data_t-menge1 - data_t-menge2.
    else.
      data_t-menge = data_t-menge1.
    endif.
    modify data_t.
    if not ( data_t-menge is initial ).
      APPEND data_t TO xtable.
    endif.
  ENDLOOP.

endform.

*----------------------------------------------------------------------*
*   INCLUDE ZERO_REP_PMOVE_GRID                                        *
*----------------------------------------------------------------------*
DATA: OK_CODE LIKE SY-UCOMM,
      G_CONTAINER TYPE SCRFNAME VALUE 'BCALV_GRID',
      GRID1  TYPE REF TO CL_GUI_ALV_GRID,
      G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

*---------------------------------------------------------------------*
*       MODULE PBO OUTPUT                                             *
*---------------------------------------------------------------------*
MODULE PBO OUTPUT.
* preparation grid for display
  SET PF-STATUS 'MAIN100'.
  SET TITLEBAR '100'.
  IF G_CUSTOM_CONTAINER IS INITIAL.
    CREATE OBJECT G_CUSTOM_CONTAINER
           EXPORTING CONTAINER_NAME = G_CONTAINER.
    CREATE OBJECT GRID1
           EXPORTING I_PARENT = G_CUSTOM_CONTAINER.
    CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY
         EXPORTING I_SAVE  = 'A'
         CHANGING  IT_FIELDCATALOG  = G_fcat[]
                   IT_OUTTAB        = xtable[].
  ENDIF.
ENDMODULE.
*---------------------------------------------------------------------*
*       MODULE PAI INPUT                                              *
*---------------------------------------------------------------------*
MODULE PAI INPUT.
*   to react on oi_custom_events:
    call method cl_gui_cfw=>dispatch.
  CASE OK_CODE.
    WHEN 'EXIT'.
      PERFORM EXIT_PROGRAM.
    WHEN OTHERS.
*     do nothing
  ENDCASE.
  CLEAR OK_CODE.
ENDMODULE.
*---------------------------------------------------------------------*
*       FORM EXIT_PROGRAM                                             *
*---------------------------------------------------------------------*
FORM EXIT_PROGRAM.

  IF not G_custom_container is initial.
    CALL METHOD g_custom_container->free.
  ENDIF.

  CALL METHOD cl_gui_cfw=>flush.
  IF sy-subrc ne 0.
* add your handling, for example
    CALL FUNCTION 'POPUP_TO_INFORM'
         EXPORTING
              titel = ''
              txt2  = sy-subrc
              txt1  = 'Error'(500).
  ENDIF.
  set screen 0.
  leave screen.
ENDFORM.

FORM G_fcatalog.
*preparation fieldcatalog for displain field
  CLEAR g_fcat.
  g_fcat-fieldname     = 'EBELN'.
  g_fcat-ref_field     = 'EBELN'.
  g_fcat-tabname       = 'XTABLE'.
  g_fcat-ref_table  = 'MSEG'.
  APPEND g_fcat.

  CLEAR g_fcat.
  g_fcat-fieldname     = 'EBELP'.
  g_fcat-ref_field     = 'EBELP'.
  g_fcat-tabname       = 'XTABLE'.
  g_fcat-ref_table  = 'MSEG'.
  APPEND g_fcat.

  CLEAR g_fcat.
  g_fcat-fieldname     = 'IDNLF'.
  g_fcat-ref_field     = 'IDNLF'.
  g_fcat-tabname       = 'XTABLE'.
  g_fcat-ref_table  = 'EINA'.
  APPEND g_fcat.

  CLEAR g_fcat.
  g_fcat-fieldname     = 'MATNR'.
  g_fcat-ref_field     = 'MATNR'.
  g_fcat-tabname       = 'XTABLE'.
  g_fcat-ref_table   = 'MSEG'.
  APPEND g_fcat.

  CLEAR g_fcat.
  g_fcat-fieldname     = 'MFRPN'.
  g_fcat-ref_field     = 'MFRPN'.
  g_fcat-tabname       = 'XTABLE'.
  g_fcat-ref_table    = 'MARA'.
  APPEND g_fcat.

  CLEAR g_fcat.
  g_fcat-fieldname     = 'PRCNTR'.
  g_fcat-tabname       = 'XTABLE'.
  g_fcat-INTTYPE       = 'CHAR'.
  g_fcat-COLTEXT       = 'Prod.Centre'.

  APPEND g_fcat.
  CLEAR g_fcat.
  g_fcat-fieldname     = 'BUDAT'.
  g_fcat-ref_field     = 'BUDAT'.
  g_fcat-tabname       = 'XTABLE'.
  g_fcat-ref_table  = 'MKPF'.
  APPEND g_fcat.

  CLEAR g_fcat.
  g_fcat-fieldname     = 'MENGE'.
  g_fcat-ref_field     = 'MENGE'.
  g_fcat-tabname       = 'XTABLE'.
  g_fcat-ref_table  = 'MSEG'.
  APPEND g_fcat.

  CLEAR g_fcat.
  g_fcat-fieldname     = 'MEINS'.
  g_fcat-ref_field     = 'MEINS'.
  g_fcat-tabname       = 'XTABLE'.
  g_fcat-ref_table  = 'MSEG'.
  APPEND g_fcat.

  CLEAR g_fcat.
  g_fcat-fieldname     = 'NTM_I'.
  g_fcat-tabname       = 'XTABLE'.
  g_fcat-inttype       = 'CHAR'.
  g_fcat-coltext       = 'NTM test indicator'.
  APPEND g_fcat.

  CLEAR g_fcat.
  g_fcat-fieldname     = 'TRANS'.
  g_fcat-tabname       = 'XTABLE'.
  g_fcat-inttype       = 'CHAR'.
  g_fcat-coltext    = 'Data trans'.
  APPEND g_fcat.

ENDFORM.                               " FELDKATALOG_AUFBAUEN
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.