‎2007 Jun 19 10:19 AM
Hi,
i am using the following stmt .but i am not using the primary key to fetch record from vbkd table. so it takes more time to run the program. the code i am using is
SELECT SINGLE vbeln posnr
INTO (v_vbeln,v_posnr)
FROM vbkd
WHERE bstkd = i_bsid-xref1
and posnr = i_bsid-buzei.
SELECT SINGLE arktx
INTO i_tab-arktx
FROM vbap
WHERE vbeln = v_vbeln
and posnr = v_posnr.
can anybody fine tune the code i am using.
thanks
Madhu
‎2007 Jun 19 10:40 AM
Hi
This statament is wrong because the field POSNR (sales order item) is not linked to field BUZEI (FI invoice item)
*SELECT SINGLE vbeln posnr
*INTO (v_vbeln,v_posnr)
*FROM vbkd
*WHERE bstkd = i_bsid-xref1
*and posnr = i_bsid-buzei.
So, try this:
* Get header data
SELECT SINGLE * FROM BKPF WHERE BUKRS = I_BSID-BUKRS
AND BELNR = I_BSID-BELNR
AND GJAHR = I_BSID-GJAHR.
* Get original document
IF BKPF-AWTYP = 'VBRK'.
* Get the bill number
BILL_NUMBER = BKPF-AWKEY(10).
* The sales order and item are in VBRP table:
DATA: BEGIN OF T_VBRP OCCURS 0,
VGBEL TYPE VBAP-VBELN,
VGPOS TYPE VBAP-POSNR,
END OF T_VBAP.
SELECT VGBEL VGPOS FROM VBRP INTO TABLE T_VBRP
WHERE VBELN = BILL_NUMBER.
DATA: BEGIN OF T_MATNR OCCURS 0,
ARTKX LIKE VBAP-ARTKX
END OF T_MATNR.
SELECT ARTKX FROM VBRP INTO TABLE T_MATNR
FOR ALL ENTRIES IN T_VBRP
WHERE VBELN = T_VBRP-VGBEL
AND POSNR = T_VBRP-VGPOS.
READ TABLE T_MATNR INDEX 1.
IT_ITAB-ARKTX.
ENDIF.
Anyway you can get the material definition from bill items, you don't need to read the sales order data:
* Get header data
SELECT SINGLE * FROM BKPF WHERE BUKRS = I_BSID-BUKRS
AND BELNR = I_BSID-BELNR
AND GJAHR = I_BSID-GJAHR.
* Get original document
IF BKPF-AWTYP = 'VBRK'.
* Get the bill number
BILL_NUMBER = BKPF-AWKEY(10).
SELECT ARTKX FROM VBRP INTO IT_ITAB-ARKTX.
WHERE VBELN = BILL_NUMBER.
EXIT.
ENDSELECT.
ENDIF.
Max
‎2007 Jun 19 4:30 PM
Another thing you can do is to avoid the statement SELECT SINGLE and do it as SELECt .... UP TO 1 ROWS.