‎2006 Aug 01 5:12 AM
Hi,
I would like to enquire is there anyway that i can improve the performance for table BKPF from the ABAP code point of view.
Because we have customise one program to generate report for the asset master listing.
one of the select statement are show as below:
SELECT SINGLE * FROM BKPF WHERE BUKRS = ANEP-BUKRS
AND GJAHR = ANEP-GJAHR
AND AWKEY = AWKEYUS.
I would like to know how it different from the select statemene below:
SELECT SINGLE * FROM BKPF INTO CORRESPONDING FIELDS OF T_BKPF
WHERE
BUKRS = ANEP-BUKRS
AND GJAHR = ANEP-GJAHR
AND AWKEY = AWKEY.
Which of the select statements above can enhance report,because currently we have face quite bad issue on this report.
Can i post the ABAP code on this forum.
Hope someone can help me on this. thank you.
‎2006 Aug 01 7:21 AM
Hi,
As much as possible use the primary keys of BKPF which is BUKRS, BELNR and GJAHR. Also, select only the records which are needed so to increase performance. Please look at the code below:
DATA: lv_age_of_rec TYPE p.
FIELD-SYMBOLS: <fs_final> LIKE LINE OF it_final.
LOOP AT it_final ASSIGNING <fs_final>.
get records from BKPF
SELECT SINGLE bukrs belnr gjahr budat bldat xblnr bktxt FROM bkpf
INTO (bkpf-bukrs, bkpf-belnr, bkpf-gjahr, <fs_final>-budat,
<fs_final>-bldat, <fs_final>-xblnr, <fs_final>-bktxt)
WHERE bukrs = <fs_final>-bukrs
AND belnr = <fs_final>-belnr
AND gjahr = <fs_final>-gjahr.
if <fs_final>-shkzg = 'H', multiply dmbtr(amount in local currency)
by negative 1
IF <fs_final>-shkzg = 'H'.
<fs_final>-dmbtr = <fs_final>-dmbtr * -1.
ENDIF.
combine company code(bukrs), accounting document number(belnr),
fiscal year(gjahr) and line item(buzei) to get long text.
CONCATENATE: <fs_final>-bukrs <fs_final>-belnr
<fs_final>-gjahr <fs_final>-buzei
INTO it_thead-tdname.
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = '0001'
language = sy-langu
name = it_thead-tdname
object = 'DOC_ITEM'
ARCHIVE_HANDLE = 0
LOCAL_CAT = ' '
IMPORTING
HEADER =
TABLES
lines = it_lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
if successful, split long text into start and end date
IF sy-subrc = 0.
READ TABLE it_lines TRANSPORTING tdline.
IF sy-subrc = 0.
SPLIT it_lines-tdline AT '-' INTO
<fs_final>-s_dat <fs_final>-e_dat.
ENDIF.
ENDIF.
get vendor name from LFA1
SELECT SINGLE name1 FROM lfa1
INTO <fs_final>-name1
WHERE lifnr = <fs_final>-lifnr.
lv_age_of_rec = p_budat - <fs_final>-budat.
condition for age of deposits
IF lv_age_of_rec <= 30.
<fs_final>-amount1 = <fs_final>-dmbtr.
ELSEIF lv_age_of_rec > 30 AND lv_age_of_rec <= 60.
<fs_final>-amount2 = <fs_final>-dmbtr.
ELSEIF lv_age_of_rec > 60 AND lv_age_of_rec <= 90.
<fs_final>-amount3 = <fs_final>-dmbtr.
ELSEIF lv_age_of_rec > 90 AND lv_age_of_rec <= 120.
<fs_final>-amount4 = <fs_final>-dmbtr.
ELSEIF lv_age_of_rec > 120 AND lv_age_of_rec <= 180.
<fs_final>-amount5 = <fs_final>-dmbtr.
ELSEIF lv_age_of_rec > 180.
<fs_final>-amount6 = <fs_final>-dmbtr.
ENDIF.
CLEAR: bkpf, it_lines-tdline, lv_age_of_rec.
ENDLOOP.
Hope this helps...
P.S. Please award points for useful answers.
‎2006 Aug 01 5:14 AM
SELECT SINGLE * FROM BKPF INTO table T_BKPF
WHERE
BUKRS = ANEP-BUKRS
AND GJAHR = ANEP-GJAHR
AND AWKEY = AWKEY.
1) select only those field which are required..
2)arrenge field order same in internal table as u fetch in select query( to avoid CORRESPONDING FIELDS ).
‎2006 Aug 01 7:29 AM
Hello,
Try this way,
SELECT SINGLE * FROM BKPF INTO table T_BKPF
WHERE AWKEY = AWKEY
and AWTYP = 'some type'.
This query will use the index of awkey and awtyp to it will fatch your data very fast.
regards,
Naimesh
‎2006 Aug 01 7:12 AM
It is better to use a secondary index for BKPF, otherwise no matter what you do it is bound to take a lot of time.
Usually posting key (AWKEY) is combination of 1 or 2 fields of the reference document.
Try to use XBLNR field of BKPF, this will generally be the reference document number for ex: BKPF-XBLNR = RSEG-BELNR.
This way you can use the Secondary index BKPF~1 which is combination of BUKRS, BSTAT, XBLNR.
‎2006 Aug 01 7:21 AM
Hi,
As much as possible use the primary keys of BKPF which is BUKRS, BELNR and GJAHR. Also, select only the records which are needed so to increase performance. Please look at the code below:
DATA: lv_age_of_rec TYPE p.
FIELD-SYMBOLS: <fs_final> LIKE LINE OF it_final.
LOOP AT it_final ASSIGNING <fs_final>.
get records from BKPF
SELECT SINGLE bukrs belnr gjahr budat bldat xblnr bktxt FROM bkpf
INTO (bkpf-bukrs, bkpf-belnr, bkpf-gjahr, <fs_final>-budat,
<fs_final>-bldat, <fs_final>-xblnr, <fs_final>-bktxt)
WHERE bukrs = <fs_final>-bukrs
AND belnr = <fs_final>-belnr
AND gjahr = <fs_final>-gjahr.
if <fs_final>-shkzg = 'H', multiply dmbtr(amount in local currency)
by negative 1
IF <fs_final>-shkzg = 'H'.
<fs_final>-dmbtr = <fs_final>-dmbtr * -1.
ENDIF.
combine company code(bukrs), accounting document number(belnr),
fiscal year(gjahr) and line item(buzei) to get long text.
CONCATENATE: <fs_final>-bukrs <fs_final>-belnr
<fs_final>-gjahr <fs_final>-buzei
INTO it_thead-tdname.
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = '0001'
language = sy-langu
name = it_thead-tdname
object = 'DOC_ITEM'
ARCHIVE_HANDLE = 0
LOCAL_CAT = ' '
IMPORTING
HEADER =
TABLES
lines = it_lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
if successful, split long text into start and end date
IF sy-subrc = 0.
READ TABLE it_lines TRANSPORTING tdline.
IF sy-subrc = 0.
SPLIT it_lines-tdline AT '-' INTO
<fs_final>-s_dat <fs_final>-e_dat.
ENDIF.
ENDIF.
get vendor name from LFA1
SELECT SINGLE name1 FROM lfa1
INTO <fs_final>-name1
WHERE lifnr = <fs_final>-lifnr.
lv_age_of_rec = p_budat - <fs_final>-budat.
condition for age of deposits
IF lv_age_of_rec <= 30.
<fs_final>-amount1 = <fs_final>-dmbtr.
ELSEIF lv_age_of_rec > 30 AND lv_age_of_rec <= 60.
<fs_final>-amount2 = <fs_final>-dmbtr.
ELSEIF lv_age_of_rec > 60 AND lv_age_of_rec <= 90.
<fs_final>-amount3 = <fs_final>-dmbtr.
ELSEIF lv_age_of_rec > 90 AND lv_age_of_rec <= 120.
<fs_final>-amount4 = <fs_final>-dmbtr.
ELSEIF lv_age_of_rec > 120 AND lv_age_of_rec <= 180.
<fs_final>-amount5 = <fs_final>-dmbtr.
ELSEIF lv_age_of_rec > 180.
<fs_final>-amount6 = <fs_final>-dmbtr.
ENDIF.
CLEAR: bkpf, it_lines-tdline, lv_age_of_rec.
ENDLOOP.
Hope this helps...
P.S. Please award points for useful answers.
‎2006 Aug 01 7:34 AM
The primary key fields for BKPF, as pointed out earlier, as BUKRS, BELNR, and GJAHR. In your select you have specified, the BELNR is missing, and hence the system would be forced to do a select on BUKRS alone (if hitting the primary index), and then sort based on the other 2 criteria.
Keeping this in mind, your selection would be greatly improved if you could also specify the BELNR in the select.
Or, try hitting other secondary indexes (there is one with AWTYP and AWKEY), and then delete values from the itab based on the BUKRS.
The INTO CORRESPONDING FIELDS has a slight performance disadvantage as the system needs to look for matching fields in the structure T_BKPF, and then move the values into those. A better statement would be INTO TABLE t_bkpf.
Hope this helps.
Sudha
‎2006 Aug 01 7:37 AM
Hi,
As per your logic you are trying to select single with out full primary key. The Primary keys for BKPF are BUKRS, BELNR and GJAHR. If you can populate the full primary key then only use select sigle otherwise you can go for 2nd one with a bit of modification.
SELECT * FROM BKPF INTO CORRESPONDING FIELDS OF T_BKPF
<b>UPTO 1 ROW</b>
WHERE
BUKRS = ANEP-BUKRS
AND GJAHR = ANEP-GJAHR
AND AWKEY = AWKEY.
ENDSELECT.Hope It Helps
Anirban