由于bseg表很大,而且表的索引字段是:
BUKRS - Company Code
BELNR - Accounting Document Number
GJAHR - Fiscal Year
BUZEI - Line Item Number
代码如下:
注意:该程序包含了各种条件的查询,程序员可以根据自己应用需求选择对应一个的子程序来读取公司和凭证号。
REPORT ztest_select.
* Tables ***************************************************************
TABLES: bkpf, bseg,
* Global Data **********************************************************
TYPES: BEGIN OF doc,
END
DATA: doc_int
doc_wa
w_repid
no_lines TYPE sy-tabix.
* Selection Screen *****************************************************
PARAMETERS: p_gjahr TYPE covp-refgj OBLIGATORY.
SELECTION-SCREEN SKIP.
PARAMETERS: p_kokrs TYPE csks-kokrs OBLIGATORY,
SELECTION-SCREEN SKIP.
PARAMETERS: p_bukrs TYPE bsis-bukrs OBLIGATORY,
SELECTION-SCREEN SKIP.
PARAMETERS: p_vbeln TYPE vbak-vbeln.
SELECTION-SCREEN SKIP.
PARAMETERS: p_matnr TYPE vapma-matnr.
SELECTION-SCREEN SKIP.
PARAMETERS: p_fikrs TYPE fmifiit-fikrs,
SELECTION-SCREEN ULINE.
PARAMETERS: p_hbkid TYPE payr-hbkid,
START-OF-SELECTION.
* Retrieve document numbers based on different requirements
* Posting Date (用日期做查询条件)
USING p_bukrs
* Cost Center
USING p_kokrs
* GL Account
USING p_bukrs
* Vendor
USING p_bukrs
* Customer
USING p_bukrs
* Purchase Order
USING p_ebeln.
* Sales Order
USING p_vbeln.
* Order
USING p_aufnr
* Fund/Fund Center
USING p_fikrs
* Profit Center
USING p_kokrs
* Material
USING p_matnr
* Cheque number
USING p_hbkid
*&---------------------------------------------------------------------*
*& Form
*&---------------------------------------------------------------------*
*
* document number
*----------------------------------------------------------------------*
FORM posting_date_actuals
budat.
* Uses index BKPF~2 (4.7)
INTO TABLE doc_int
UP TO 100 ROWS
FROM bkpf
WHERE bukrs = bukrs
* Normally, you would probably only want normal documents, that is
* documents with BSTAT = ' '. So you would change the next line.
* On the other hand, you might want documents for all values of BSTAT,
* but not want to hardcode the values. In that case, you can retrieve
* values from the domain of BSTAT and put them in a range table and
* use the range table in the next line.
TABLES doc_int
USING 'Posting date'
ENDFORM.
*&---------------------------------------------------------------------*
*& Form
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM cost_center_actuals
kostl
gjahr.
* Uses primary index (4.7)
FROM csks
INTO csks-objnr
WHERE kokrs = kokrs
AND kostl = kostl.
* COVP is a view. This uses index COEP~1 (4.7)
FROM covp
INTO TABLE doc_int
UP TO 100 ROWS
WHERE lednr = '00'
AND objnr = csks-objnr
AND gjahr = gjahr
AND wrttp IN ('04', '11')
AND versn = '000'.
EXPORTING
input
IMPORTING
output = disp_cc.
TABLES doc_int
USING 'Cost Center'
ENDFORM.
*&---------------------------------------------------------------------*
*& Form
*&---------------------------------------------------------------------*
*
*
*
*
*
*
*
*
*----------------------------------------------------------------------*
FORM gl_actuals
hkont
gjahr.
* Uses primary index (4.7)
FROM bsis
INTO TABLE doc_int
UP TO 100 ROWS
WHERE bukrs = bukrs
AND hkont = hkont
AND gjahr = gjahr.
* Uses primary index (4.7)
FROM bsas
APPENDING TABLE doc_int
UP TO 100 ROWS
WHERE bukrs = bukrs
AND hkont = hkont
AND gjahr = gjahr.
EXPORTING
input
IMPORTING
output = disp_gl.
TABLES doc_int
USING 'GL Account'
ENDFORM.
*&---------------------------------------------------------------------*
*& Form
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM vendor_actuals
lifnr
gjahr.
* Uses primary index (4.7)
FROM bsik
INTO TABLE doc_int
UP TO 100 ROWS
WHERE bukrs = bukrs
AND lifnr = lifnr
AND gjahr = gjahr.
* Uses primary index (4.7)
FROM bsak
APPENDING TABLE doc_int
UP TO 100 ROWS
WHERE bukrs = bukrs
AND lifnr = lifnr
AND gjahr = gjahr.
EXPORTING
input
IMPORTING
output = disp_vendor.
TABLES doc_int
USING 'Vendor'
ENDFORM.
*&---------------------------------------------------------------------*
*& Form
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM customer_actuals
kunnr
gjahr.
* Uses primary index (4.7)
FROM bsid
INTO TABLE doc_int
UP TO 100 ROWS
WHERE bukrs = bukrs
AND kunnr = kunnr
AND gjahr = gjahr.
* Uses primary index (4.7)
FROM bsad
APPENDING TABLE doc_int
UP TO 100 ROWS
WHERE bukrs = bukrs
AND kunnr = kunnr
AND gjahr = gjahr.
EXPORTING
input
IMPORTING
output = disp_customer.
TABLES doc_int
USING 'Customer'
ENDFORM.
*&---------------------------------------------------------------------*
*& Form
*&---------------------------------------------------------------------*
*
*
*----------------------------------------------------------------------*
FORM po_actuals
belnr TYPE ekbe-belnr,
gjahr TYPE ekbe-gjahr,
END
* Uses primary index (4.7)
FROM ekbe
INTO TABLE ekbe_int
UP TO 100 ROWS
WHERE ebeln = ebeln
AND vgabe IN ('1', '2').
v_objectkey+00(10) = ekbe_wa-belnr.
v_objectkey+10(10) = ekbe_wa-gjahr.
IF ekbe_wa-vgabe = '1'.
v_reference = 'MKPF'.
ELSE.
v_reference = 'RMRP'.
ENDIF.
* Uses index BKPF~4 (4.7)
SELECT SINGLE bukrs belnr gjahr
FROM bkpf
INTO doc_wa
WHERE awtyp =
IF sy-subrc = 0.
APPEND doc_wa TO doc_int.
ENDIF.
EXPORTING
input
IMPORTING
output = disp_po.
TABLES doc_int
USING 'Purchase Order'
ENDFORM.
*&---------------------------------------------------------------------*
*& Form
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM so_actuals
vbeln TYPE vbfa-vbeln,
END
* Uses primary index (4.7)
FROM vbfa
UP TO 100 ROWS
WHERE vbelv
AND vbtyp_n = 'P'. "Debit memo
v_objectkey+00(10) = vbfa_wa-vbeln. "BELNR
v_reference
* Uses index BKPF~4 (4.7)
SELECT SINGLE bukrs belnr gjahr
FROM bkpf
INTO doc_wa
WHERE awtyp =
IF sy-subrc = 0.
APPEND doc_wa TO doc_int.
ENDIF.
EXPORTING
input
IMPORTING
output = disp_so.
TABLES doc_int
USING 'Sales Document'
ENDFORM.
*&---------------------------------------------------------------------*
*& Form
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM order_actuals
gjahr.
* Uses primary index (4.7)
FROM aufk
INTO aufk-objnr
WHERE aufnr = aufnr.
* COVP is a view. This uses index COEP~1 (4.7)
FROM covp
INTO TABLE doc_int
UP TO 100 ROWS
WHERE lednr = '00'
AND objnr = aufk-objnr
AND gjahr = gjahr
AND wrttp IN ('04', '11')
AND versn = '000'.
EXPORTING
input
IMPORTING
output = disp_order.
TABLES doc_int
USING 'Order'
ENDFORM.
*&---------------------------------------------------------------------*
*& Form
*&---------------------------------------------------------------------*
*
*
*----------------------------------------------------------------------*
FORM fm_actuals
gjahr
fistl
fonds.
* Uses index FMIFIIT~3 (4.7)
FROM
INTO TABLE doc_int
UP TO 100 ROWS
WHERE
AND fonds
EXPORTING
input
IMPORTING
output = disp_cfc.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
IMPORTING
TABLES doc_int
USING 'Fund Center'
ENDFORM.