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

Finance Docs and Related MM Docs



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



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Mon Sep 03, 2007 11:30 pm    Post subject: Finance Docs and Related MM Docs Reply with quote

Some poor souls in your finance department might use this report for auditing...
This program lists accounting documents that were automatically created from MM, and also lists the MM source documents. It can take several minutes to run, depending on the amount of data in the database, because it has to access (slow) cluster tables.
Accounting Docs Automatically Created from MM

Code:
*&---------------------------------------------------------------------*
*& Report ZFIMMDOC *
*& Listing of accounting docs and the material docs from which they *
*& were automatically created. *
*&---------------------------------------------------------------------*
REPORT zfimmdoc MESSAGE-ID z1 LINE-COUNT 65 NO STANDARD PAGE HEADING.

TABLES: bkpf, mseg, mkpf, t001, bsim, t001k, mara, bseg, skat,
        makt, t156t.
INCLUDE: zfimmtop. "types mymseg_type

PARAMETERS: companyc LIKE bkpf-bukrs OBLIGATORY, " default '1101',
            year LIKE bkpf-gjahr OBLIGATORY, " default '1998'.
            postdate LIKE bkpf-budat OBLIGATORY.
SELECT-OPTIONS: val_area FOR bsim-bwkey NO-DISPLAY,
                s_mblnr FOR mseg-mblnr NO-DISPLAY,
                s_belnr FOR bseg-belnr NO-DISPLAY.
DATA: mybutxt LIKE t001-butxt,
      lines TYPE i,
      previous_belnr LIKE bkpf-belnr,
      previous_awkey LIKE bkpf-awkey,
      mytxt50 LIKE skat-txt50,
BEGIN OF x001k OCCURS 20.
        INCLUDE STRUCTURE t001k.
DATA: END OF x001k.
DATA: BEGIN OF mybkpf OCCURS 100,
      blart LIKE bkpf-blart, "doc type
      belnr LIKE bkpf-belnr, "doc no
      waers LIKE bkpf-waers, "currency key
      awkey LIKE bkpf-awkey,
END OF mybkpf.
DATA: BEGIN OF mybsim OCCURS 500.
INCLUDE TYPE mybsim_type.
DATA: END OF mybsim.
DATA: BEGIN OF mybseg OCCURS 1200,
      belnr LIKE bseg-belnr,
      buzei LIKE bseg-buzei,
      bschl LIKE bseg-bschl,
      hkont LIKE bseg-hkont,
      wrbtr LIKE bseg-wrbtr,
      shkzg LIKE bseg-shkzg, "debit/credit
END OF mybseg.
DATA: BEGIN OF mymseg OCCURS 500.
      INCLUDE TYPE mymseg_type.
DATA: END OF mymseg.

PERFORM get_bkpf.
PERFORM get_bsim.
PERFORM collect_belnr.
PERFORM get_bseg.
PERFORM collect_mblnr.
PERFORM get_mseg.
SORT mybsim BY belnr.
SORT mymseg BY mblnr zeile.
SORT mybseg BY belnr buzei.
LOOP AT mybsim.
  IF mybsim-shkzg = 'H'. "negative value
    mybsim-dmbtr = ( -1 ) * mybsim-dmbtr.
  ENDIF.
  PERFORM write_bsim_data USING mybsim.
  AT END OF belnr. "new belnr record: get bseg recs
    PERFORM write_bseg_data USING mybsim-belnr.
  ENDAT.
  AT END OF awkey.
    PERFORM write_mseg_data USING mybsim-awkey(10).
  ENDAT.
  WRITE: sy-uline.
ENDLOOP.
WRITE: / 'number of records accessed'.
DESCRIBE TABLE mybkpf LINES lines.
WRITE: / 'bkpf:', lines.
DESCRIBE TABLE mybsim LINES lines.
WRITE: / 'bsim:', lines.
DESCRIBE TABLE mymseg LINES lines.
WRITE: / 'mseg:', lines.
DESCRIBE TABLE mybseg LINES lines.
WRITE: / 'bseg:', lines.

AT SELECTION-SCREEN.
* get company text
  SELECT SINGLE butxt FROM t001 INTO mybutxt
  WHERE bukrs = companyc.
* get valuation areas from company code
  REFRESH val_area. CLEAR val_area.
  SELECT * FROM t001k INTO TABLE x001k
  WHERE bukrs = companyc.
  LOOP AT x001k.
    val_area-sign = 'I'. val_area-option = 'EQ'.
    val_area-low = x001k-bwkey.
    APPEND val_area.
  ENDLOOP.
  READ TABLE val_area INDEX 1.

TOP-OF-PAGE.
  PERFORM write_header.
*&---------------------------------------------------------------------*
*& Form GET_BKPF
*&---------------------------------------------------------------------*
FORM get_bkpf.
* get bkpf records
* should perform authority check here **
  SELECT blart belnr waers awkey
  INTO CORRESPONDING FIELDS OF TABLE mybkpf
  FROM bkpf
  WHERE bukrs = companyc AND gjahr = year AND budat = postdate
  ORDER BY belnr.
ENDFORM. " GET_BKPF
*&---------------------------------------------------------------------*
*& Form GET_BSIM
*----------------------------------------------------------------------*
FORM get_bsim.
  LOOP AT mybkpf.
    mybsim-blart = mybkpf-blart.
    mybsim-belnr = mybkpf-belnr.
    mybsim-waers = mybkpf-waers.
    mybsim-awkey = mybkpf-awkey.
* should perform authority check here **
* select bsim records using conditions gjahr, bwkey, belnr
    SELECT belnr buzei dmbtr matnr budat menge meins
    INTO CORRESPONDING FIELDS OF mybsim
    FROM bsim
    WHERE gjahr = year AND
    belnr = mybkpf-belnr AND
    bwkey IN val_area.
      APPEND mybsim.
    ENDSELECT.
  ENDLOOP.
ENDFORM. " GET_BSIM
*&---------------------------------------------------------------------*
*& Form get_bseg
*&---------------------------------------------------------------------*
FORM get_bseg.
* should perform authority check here **
* select bseg records using conditions bukrs, belnr, gjahr
  SELECT belnr buzei bschl hkont wrbtr shkzg
  INTO CORRESPONDING FIELDS OF TABLE mybseg
  FROM bseg
  WHERE gjahr = year AND
  bukrs = companyc AND
  belnr IN s_belnr.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_MSEG
*&---------------------------------------------------------------------*
FORM get_mseg.
* should perform authority check here **
  SELECT mblnr
  zeile bwart matnr lgort menge meins waers shkzg dmbtr werks
  kostl sobkz kzbew kzzug kzvbr
  INTO CORRESPONDING FIELDS OF TABLE mymseg
  FROM mseg
  WHERE mjahr = year AND mblnr IN s_mblnr.
  WRITE: sy-uline.
ENDFORM. " GET_AND_WRITE_MATDOC
*&---------------------------------------------------------------------*
*& Form WRITE_HEADER
*----------------------------------------------------------------------*
FORM write_header.
  DATA: myoption(11) TYPE c, mysign(7) TYPE c, "explain select criteria
  select_text(60) TYPE c, select_position TYPE i.
  WRITE: text-000,
  text-001. "company and report header
  IF sy-pagno = 1. "**** first page
    WRITE: / 'Company Code', companyc, mybutxt,
    'Accounting Year', year, 'Posting Date:', postdate.
  ENDIF. "**** first page
  WRITE: / 'Generated', sy-datum, sy-uzeit,
  'Page', sy-pagno, sy-uline.
* format for accounting docs
  FORMAT COLOR COL_GROUP.
  WRITE: / 'DT',
        4 'acct doc',
        15 'material',
        25 'item',
        31 'Posted',
        42(12) 'Quantity',
               'Unit',
        61 ' balance'.
  FORMAT COLOR OFF.
  WRITE: / 'item' UNDER 'item', 30 'Code', 35 'Account',
        45 'Description',
        61 ' balance'.
* format for material docs
  FORMAT COLOR COL_TOTAL.
  WRITE: / 'MatrialDoc' UNDER 'acct doc',
          'Posted' UNDER 'Posted', 'Entered' UNDER 'Description',
       76 ' '.
  FORMAT COLOR OFF.
  WRITE: /10 'item',
             'Material' UNDER 'Material',
          25 'Plant',
             'Stor' UNDER 'Code',
             'Mvmt' UNDER 'Account',
       2(12) 'Quantity',
             'Unit',
          61 ' balance',
         /11 'MaterialDesc',
             'MovementType' UNDER 'Quantity',
          60 'CostCtr'.
  WRITE: sy-uline.
ENDFORM. " WRITE_HEADER

*&---------------------------------------------------------------------*
*& Form WRITE_MKPF_DATA
*&---------------------------------------------------------------------*
FORM write_mkpf_data USING f_mseg TYPE mymseg_type
f_maktx LIKE makt-maktx
f_btext LIKE t156t-btext.
  WRITE: / f_mseg-zeile UNDER 'item',
           f_mseg-matnr UNDER 'material',
           f_mseg-werks UNDER 'Plant',
           f_mseg-lgort UNDER 'Stor',
           f_mseg-bwart UNDER 'Mvmt',
       (12)f_mseg-menge UNDER 'Quantity' DECIMALS 2,
           f_mseg-meins UNDER 'Unit',
           f_mseg-dmbtr UNDER ' balance'.
  WRITE: / f_maktx UNDER 'MaterialDesc',
           f_btext UNDER 'MovementType',
           f_mseg-kostl UNDER 'CostCtr'.
ENDFORM. " WRITE_MKPF_DATA

*&---------------------------------------------------------------------*
*& Form WRITE_MKPF_HEADER
*&---------------------------------------------------------------------*
FORM write_mkpf_header USING p_mblnr LIKE mkpf-mblnr.
  DATA: mybudat LIKE mkpf-budat, mycpudt LIKE mkpf-cpudt.
  SELECT SINGLE budat cpudt FROM mkpf
  INTO (mybudat, mycpudt)
  WHERE mblnr = p_mblnr AND mjahr = year.
  IF sy-subrc = 0. "got record
    FORMAT COLOR COL_TOTAL.
    WRITE: / p_mblnr UNDER 'acct doc',
    mybudat UNDER 'Posted',
    mycpudt UNDER 'Entered',
    76 ' '.
    FORMAT COLOR OFF.
  ENDIF.
ENDFORM. " WRITE_MKPF_HEADER

*&---------------------------------------------------------------------*
*& Form WRITE_BSIM_DATA
*&---------------------------------------------------------------------*
FORM write_bsim_data USING f_bsim TYPE mybsim_type.
  FORMAT COLOR COL_GROUP.
  WRITE: / f_bsim-blart UNDER 'DT',
  f_bsim-belnr UNDER 'acct doc',
  f_bsim-matnr UNDER 'material',
  f_bsim-buzei UNDER 'Plant', "item
  f_bsim-budat UNDER 'Posted',
  (12)f_bsim-menge UNDER 'Quantity' DECIMALS 2,
  f_bsim-meins UNDER 'Unit',
  f_bsim-dmbtr UNDER ' balance' RIGHT-JUSTIFIED.
  FORMAT COLOR OFF.
ENDFORM. " WRITE_BSIM_DATA

*&---------------------------------------------------------------------*
*& Form WRITE_BSEG_DATA
*&---------------------------------------------------------------------*
FORM write_bseg_data USING p_belnr.
  LOOP AT mybseg WHERE belnr = p_belnr.
    SELECT SINGLE txt50 INTO mytxt50 FROM skat
    WHERE spras = '1' AND ktopl = 'HFCA' AND
    saknr = mybseg-hkont.
    IF mybseg-shkzg = 'H'. "negative value
      mybseg-wrbtr = ( -1 ) * mybseg-wrbtr.
    ENDIF.
    WRITE: / mybseg-buzei UNDER 'Plant', "item
    mybseg-bschl UNDER 'Code',
    mybseg-hkont UNDER 'Account',
    mytxt50 UNDER 'Description',
    mybseg-wrbtr UNDER ' balance'.
  ENDLOOP.
ENDFORM. " WRITE_BSEG_DATA

*&---------------------------------------------------------------------*
*& Form COLLECT_MBLNR
*&---------------------------------------------------------------------*
FORM collect_mblnr.
  SORT mybsim BY awkey.
  s_mblnr-sign = 'I'.
  s_mblnr-option = 'EQ'.
  LOOP AT mybsim.
    AT NEW awkey.
      s_mblnr-low = mybsim-awkey(10).
      APPEND s_mblnr.
    ENDAT.
  ENDLOOP.
  READ TABLE s_mblnr INDEX 1.
ENDFORM. " COLLECT_MBLNR

*&---------------------------------------------------------------------*
*& Form COLLECT_BELNR
*&---------------------------------------------------------------------*
FORM collect_belnr.
  s_belnr-sign = 'I'.
  s_belnr-option = 'EQ'.
  SORT mybsim BY belnr.
  LOOP AT mybsim.
    AT NEW belnr.
      s_belnr-low = mybsim-belnr.
      APPEND s_belnr.
    ENDAT.
  ENDLOOP.
  READ TABLE s_belnr INDEX 1.
ENDFORM. " COLLECT_BELNR

*&---------------------------------------------------------------------*
*& Form WRITE_MSEG_DATA
*&---------------------------------------------------------------------*
FORM write_mseg_data USING p_mblnr LIKE mseg-mblnr.
  DATA: mybtext LIKE t156t-btext,
  mymaktx LIKE makt-maktx.
  PERFORM write_mkpf_header USING p_mblnr.
  LOOP AT mymseg WHERE mblnr = p_mblnr.
    SELECT SINGLE btext INTO mybtext FROM t156t
    WHERE spras = '1' AND
    bwart = mymseg-bwart AND
    sobkz = mymseg-sobkz AND
    kzbew = mymseg-kzbew AND
    kzzug = mymseg-kzzug AND
    kzvbr = mymseg-kzvbr.
    SELECT SINGLE maktx INTO mymaktx FROM makt
    WHERE spras = '1' AND matnr = mymseg-matnr.
    IF mymseg-shkzg = 'H'.
      mymseg-dmbtr = ( -1 ) * mymseg-dmbtr.
    ENDIF.
    PERFORM write_mkpf_data USING mymseg mymaktx mybtext.
  ENDLOOP.
ENDFORM. " WRITE_MSEG_DATA
* end of ZFIMMDOC program *

* begin of ZFIMMTOP include program *
*----------------------------------------------------------------------*
* INCLUDE ZFIMMTOP *
*----------------------------------------------------------------------*
TYPES: BEGIN OF mymseg_type,
      mblnr LIKE mseg-mblnr,
      zeile LIKE mseg-zeile,
      bwart LIKE mseg-bwart,
      matnr LIKE mseg-matnr,
      werks LIKE mseg-werks,
      lgort LIKE mseg-lgort,
      menge LIKE mseg-menge,
      meins LIKE mseg-meins,
      waers LIKE mseg-waers,
      shkzg LIKE mseg-shkzg,
      dmbtr LIKE mseg-dmbtr,
      kostl LIKE mseg-kostl,
      sobkz LIKE mseg-sobkz, " for goods movement text
      kzbew LIKE mseg-kzbew, " for goods movement text
      kzzug LIKE mseg-kzzug, " for goods movement text
      kzvbr LIKE mseg-kzvbr, " for goods movement text
END OF mymseg_type.
TYPES: BEGIN OF mybsim_type,
      blart LIKE bkpf-blart, "doc type
      belnr LIKE bkpf-belnr, "doc no
      waers LIKE bkpf-waers,
      awkey LIKE bkpf-awkey,
      buzei LIKE bsim-buzei, "doc item
      matnr LIKE bsim-matnr,
      budat LIKE bsim-budat,
      menge LIKE bsim-menge, "quantity
      meins LIKE bsim-meins, "unit of measure
      shkzg LIKE bsim-shkzg, "debit/credit
      dmbtr LIKE bsim-dmbtr, "balance amount
END OF mybsim_type.
* end of ZFIMMDOC include *
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 -> FI 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.