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

Relation between purchase orders and material documents



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ
View previous topic :: View next topic  
Author Message
vga
Мастер
Мастер


Age: 70
Joined: 04 Oct 2007
Posts: 1218
Location: Санкт-Петербург

PostPosted: Sat Mar 27, 2010 2:49 pm    Post subject: Relation between purchase orders and material documents Reply with quote

Code:
*----------------------------------------------------------------------*
* Program Name          : ZFISRHZ09                                    *
* Purpose               :                                              *
* Created by            : Stonemason                                   *
* Create on             : 2007-10-25                                   *
* T code                : zfir009                                      *
* Functional Consultant :                                              *
* Description           : ???                                       *
*----------------------------------------------------------------------*
*    Modification Log                                                  *
*Date        Programmer     Corr. #       Description                  *
*2006/MM/DD  xxxxxxxxxx     xxxxxxxxxx   Initial pgm dev               *
*----------------------------------------------------------------------*
REPORT  zfisrhz09.
TYPE-POOLS:slis.
TABLES:lfa1,lfb1,mseg,mkpf,mara,marc,makt,resb,ekbe.
*********globle data*******
DATA:BEGIN OF itab_mseg OCCURS 0,
       mblnr LIKE mseg-mblnr,"????
       zeile LIKE mseg-zeile,
       matnr LIKE mseg-matnr,"????
       ebeln LIKE mseg-ebeln,"????
       smbln LIKE mseg-smbln,"????
       meins LIKE mseg-meins,"??
       menge LIKE mseg-menge,"??
       dmbtr LIKE mseg-dmbtr,"???
     END OF itab_mseg.
DATA:BEGIN OF itab_mseg1 OCCURS 0,
       mblnr LIKE mseg-mblnr,"????
       zeile LIKE mseg-zeile,
       matnr LIKE mseg-matnr,"????
       ebeln LIKE mseg-ebeln,"????
       smbln LIKE mseg-smbln,"????
       meins LIKE mseg-meins,"??
       maktx LIKE makt-maktx,"????
       danj  TYPE p DECIMALS 4,
       menge LIKE mseg-menge,"??
       dmbtr LIKE mseg-dmbtr,"???
       bldat  LIKE mkpf-bldat,
       budat  LIKE mkpf-budat,
     END OF itab_mseg1.
DATA:BEGIN OF itab_ekbe OCCURS 0,
       ebeln   LIKE mseg-ebeln,"????
       ebelp   LIKE ekbe-ebelp,"?????????
       belnr   LIKE ekbe-belnr,"????
       bwart   LIKE ekbe-bwart,"????
       budat   LIKE ekbe-budat,"????
       menge   LIKE mseg-menge,"??
       dmbtr   LIKE mseg-dmbtr,"??????
       wrbtr   LIKE ekbe-wrbtr,"????
       waers   LIKE ekbe-waers,"????
       txz01   LIKE ekpo-txz01,
       matnr   LIKE ekbe-matnr,"??
*       maktx   LIKE makt-maktx,"????
       meins LIKE mseg-meins,"??
       lifnr   LIKE mseg-lifnr,
       shkzg   LIKE mseg-shkzg,
     END OF itab_ekbe.
DATA:BEGIN OF itab_ekbe1 OCCURS 0,
       ebeln   LIKE mseg-ebeln,"????
       ebelp   LIKE ekbe-ebelp,"?????????
       belnr   LIKE ekbe-belnr,"????
       budat   LIKE ekbe-budat,"????
       danj    TYPE p DECIMALS 4,
       menge   LIKE mseg-menge,"??
       dmbtr   LIKE mseg-dmbtr,"??????
       wrbtr   LIKE ekbe-wrbtr,"????
       waers   LIKE ekbe-waers,"????
       txz01   LIKE ekpo-txz01,
       matnr   LIKE ekbe-matnr,"??
       maktx   LIKE makt-maktx,"????
       meins   LIKE mseg-meins,
       lifnr   LIKE mseg-lifnr,
     END OF itab_ekbe1.
DATA:BEGIN OF itab_ekbe2 OCCURS 0,
       ebeln   LIKE mseg-ebeln,"????
       ebelp   LIKE ekbe-ebelp,"?????????
       belnr   LIKE ekbe-belnr,"????
       budat   LIKE ekbe-budat,"????
       danj    TYPE p DECIMALS 4,
       menge   LIKE mseg-menge,"??
       dmbtr   LIKE mseg-dmbtr,"??????
       wrbtr   LIKE ekbe-wrbtr,"????
       waers   LIKE ekbe-waers,"????
       txz01   LIKE ekpo-txz01,
       matnr   LIKE ekbe-matnr,"??
       maktx   LIKE makt-maktx,"????
       meins   LIKE mseg-meins,
       danw    LIKE mseg-menge,"????
       xhze    LIKE mseg-dmbtr,"????
       shij    LIKE mseg-dmbtr,"????
       chayi   LIKE mseg-dmbtr,"??
       lifnr   LIKE mseg-lifnr,
       matnr1  LIKE ekbe-matnr,"??
       maktx1  LIKE makt-maktx,"????
     END OF itab_ekbe2.
DATA:BEGIN OF itab_ekpo OCCURS 0,
       ebeln   LIKE ekpo-ebeln,
       ebelp   LIKE ekpo-ebelp,
       txz01   LIKE ekpo-txz01,
       matnr   LIKE ekpo-matnr,
       netpr   LIKE ekpo-netpr,"???
       menge   LIKE ekpo-menge,"??
       netwr   LIKE ekpo-netwr,
     END OF itab_ekpo.
DATA:BEGIN OF itab_resb OCCURS 0,
       rsnum   LIKE resb-rsnum,"??
       matnr   LIKE resb-matnr,
       bdter   LIKE resb-bdter,"????
       baugr   LIKE resb-baugr,"??????
       ebeln   LIKE resb-ebeln,"??????
       bdmng   LIKE resb-bdmng,
       enmng   LIKE resb-enmng,
       sbter   LIKE resb-sbter,
     END OF itab_resb.
DATA:itab_ekbe3 LIKE itab_ekbe OCCURS 0 WITH HEADER LINE.
DATA:itab_resb1 LIKE itab_resb OCCURS 0 WITH HEADER LINE.
DATA:BEGIN OF itab_mkpf OCCURS 0,
      mblnr  LIKE mseg-mblnr,
      bldat  LIKE mkpf-bldat,
      budat  LIKE mkpf-budat,
     END OF itab_mkpf.
DATA:p_grid_title(70) VALUE  '???'.
********selection-screen****
SELECTION-SCREEN BEGIN OF BLOCK handsome WITH FRAME TITLE text-001.
SELECT-OPTIONS::p_bukrs FOR ekbe-werks DEFAULT '2110'."ekbe~werks
PARAMETERS:p_gjahr LIKE mseg-gjahr DEFAULT sy-datum(4).
SELECT-OPTIONS:
               s_lifnr FOR mseg-lifnr,
*               OBLIGATORY,"
               s_mblnr FOR mseg-mblnr,
               s_ebeln FOR mseg-ebeln,
               s_datum FOR sy-datum OBLIGATORY.
*               OBLIGATORY.
PARAMETERS:p_box AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK handsome.
*INITIALIZATION.
*  DATA:gjahr LIKE mseg-mjahr,monat LIKE bkpf-monat,
*       gjahr_1 LIKE sy-datum.
*  gjahr = sy-datum(4).
*  monat = sy-datum+4(2).
*  CONCATENATE gjahr monat '01' INTO gjahr_1.
*  s_datum-low = gjahr_1.
*  s_datum-high = sy-datum.
*  APPEND s_datum.
START-OF-SELECTION.
  IF p_box = ''.
*  PERFORM get_data.
    PERFORM get_data1.
*  IF p_box = ''.
*    PERFORM cut_data.
*  PERFORM chuli_data.
    PERFORM print_alv.
  ELSE.
    SUBMIT zfisrhz09_2
      WITH  p_bukrs IN p_bukrs
      WITH  p_gjahr = p_gjahr
      WITH  s_lifnr IN s_lifnr
      WITH  s_mblnr IN s_mblnr
      WITH  s_ebeln IN s_ebeln
      WITH  s_datum IN s_datum
      AND RETURN.
  ENDIF.
*&---------------------------------------------------------------------*
*&      Form  get_data1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data1 .
  SELECT ekbe~ebeln ekbe~ebelp ekbe~belnr ekbe~bwart ekbe~budat"?????????
         ekbe~menge ekbe~dmbtr ekbe~wrbtr ekbe~waers ekpo~txz01 ekbe~matnr mseg~meins mseg~lifnr mseg~shkzg
       INTO TABLE itab_ekbe FROM ekbe JOIN mseg ON
        mseg~mblnr = ekbe~belnr AND mseg~ebeln = ekbe~ebeln AND"matnr
        mseg~ebelp = ekbe~ebelp AND mseg~matnr = ekbe~matnr
        JOIN ekpo ON mseg~ebelp = ekpo~ebelp AND mseg~ebeln = ekpo~ebeln
        WHERE ekbe~gjahr = p_gjahr
                                AND   ekbe~ebeln IN s_ebeln
                                AND   ekbe~budat IN s_datum
                                AND   ekbe~belnr IN s_mblnr
                                AND   ekbe~werks IN p_bukrs
                                AND   mseg~lifnr IN s_lifnr
                                AND  ekbe~bwart IN ('101','102','121','122','161','162').
*                                AND ( ekbe~bwart = '101' OR
*                                      ekbe~bwart = ' 102').
  SELECT ekbe~ebeln ekbe~ebelp ekbe~belnr ekbe~bwart ekbe~budat"???????
         ekbe~menge ekbe~dmbtr ekbe~wrbtr ekbe~waers ekbe~matnr mseg~meins mseg~lifnr mseg~shkzg
       INTO TABLE itab_ekbe3 FROM ekbe JOIN mseg ON
        mseg~mblnr = ekbe~belnr AND mseg~ebeln = ekbe~ebeln "matnr
        AND mseg~matnr = ekbe~matnr
        WHERE ekbe~gjahr = p_gjahr
                                AND   ekbe~ebeln IN s_ebeln
                                AND   ekbe~belnr IN s_mblnr
                                AND   ekbe~werks IN p_bukrs
                                AND   mseg~lifnr IN s_lifnr
                                AND  ekbe~bwart  IN ('543','544' ).
*                                AND ( ekbe~bwart <> '101' OR
*                                      ekbe~bwart <> '102').

  SELECT ebeln ebelp txz01 matnr netpr menge netwr INTO TABLE itab_ekpo FROM ekpo"???????
  FOR ALL ENTRIES IN itab_ekbe
  WHERE ebeln = itab_ekbe-ebeln
  AND   ebeln IN s_ebeln
  AND   matnr IN s_mblnr
  AND   werks IN p_bukrs
  AND   pstyp = '3'.
  SELECT rsnum matnr bdter baugr ebeln bdmng enmng sbter INTO TABLE itab_resb FROM resb"????
    FOR ALL ENTRIES IN itab_ekbe
*    WHERE   baugr = itab_ekbe-matnr
    WHERE     ebeln = itab_ekbe-ebeln
    AND     werks IN p_bukrs.
*  SELECT rsnum matnr bdter baugr ebeln bdmng sbter INTO TABLE itab_resb1 FROM resb"
*    FOR ALL ENTRIES IN itab_ekbe
*    WHERE   matnr = itab_ekbe-matnr
**    AND    ebeln = itab_ekbe-ebeln
*    AND     werks = p_bukrs.
  SORT itab_ekbe BY ebeln ebelp.
  SORT itab_ekpo BY ebeln ebelp.
  DATA:maktx LIKE makt-maktx.
  LOOP AT itab_ekbe.
    IF itab_ekbe-bwart = '122' OR itab_ekbe-bwart = '102' OR  itab_ekbe-bwart = '162' .
      itab_ekbe-menge = -1 * itab_ekbe-menge.
    ENDIF.
    IF itab_ekbe-wrbtr <> 0  AND itab_ekbe-menge <> 0.
      itab_ekbe1-danj = itab_ekbe-wrbtr / itab_ekbe-menge .
    ELSE.
      itab_ekbe1-danj = 0.
    ENDIF.
*    READ TABLE itab_ekpo WITH KEY ebeln = itab_ekbe-ebeln
*                                  ebelp = itab_ekbe-ebelp.
*    IF sy-subrc = 0 .
*      itab_ekbe1-maktx = itab_ekpo-txz01 .
*    ENDIF.
*    SELECT SINGLE maktx INTO maktx FROM makt WHERE matnr = itab_ekbe-matnr.
*
*    itab_ekbe1-maktx = maktx.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
      EXPORTING
        input  = itab_ekbe-matnr
      IMPORTING
        output = itab_ekbe-matnr.
    MOVE-CORRESPONDING itab_ekbe TO itab_ekbe1.
    IF itab_ekbe1-menge < 0.
      itab_ekbe1-dmbtr = -1 * itab_ekbe1-dmbtr .
    ENDIF.
    APPEND itab_ekbe1.
    CLEAR itab_ekbe1.
    CLEAR maktx.
  ENDLOOP.

ENDFORM.                                                    " get_data1
*&---------------------------------------------------------------------*
*&      Form  print_alv
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM print_alv .
  DATA:ls_fieldcat TYPE slis_fieldcat_alv,
       gt_fieldcat TYPE slis_t_fieldcat_alv,"
       gs_layout   TYPE slis_layout_alv.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'EBELN'."EBELN,MBLNR
  ls_fieldcat-seltext_l = '????'.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'BUDAT'.
  ls_fieldcat-seltext_l = '????'.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'BELNR'."KSTAR
  ls_fieldcat-seltext_l = '????'.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'MATNR'.                          "txz01
  ls_fieldcat-seltext_l = '???'.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'TXZ01'.
  ls_fieldcat-seltext_l = '????'.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.

  ls_fieldcat-fieldname = 'WAERS'.
  ls_fieldcat-seltext_l = '????'.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'DANJ'.
  ls_fieldcat-seltext_l = '????'.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'MENGE'."menge
  ls_fieldcat-seltext_l = '??'.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'MEINS'."meins
  ls_fieldcat-seltext_l = '??'.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'DMBTR'."dmbtr
  ls_fieldcat-seltext_l = '??'.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
*  ls_fieldcat-fieldname = 'WKG500'.
*  ls_fieldcat-seltext_l = '??'.
*  APPEND ls_fieldcat TO gt_fieldcat.
*  CLEAR ls_fieldcat.

*????,???????????????????
  gs_layout-zebra = 'X'.
  "??????????????
  gs_layout-colwidth_optimize = 'X'.
  "ALV??????????
  IF itab_ekbe1[] IS INITIAL.
    MESSAGE i000(00) WITH '??????,?????!'.
    STOP.
  ENDIF.
*  DATA:p_grid_title(10) VALUE  '???'.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-cprog
      i_grid_title       = p_grid_title
      is_layout          = gs_layout
      it_fieldcat        = gt_fieldcat[]
      i_save             = 'A'
    TABLES
      t_outtab           = itab_ekbe1
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.
ENDFORM.                    " print_alv

_________________
Молитва - это запрос разработчику на изменение кода программы.
Back to top
View user's profile Send private message Blog Visit poster's website
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.