2008 Dec 24 9:00 AM
Moved to correct forum by moderator.
Hello gurus please give me suggestions to performance the code in a good way.
METHOD if_ex_mb_migo_badi~post_document .
**********************************************************************
*The delivery note number provided by vendor should be unique in migo
Importing it_mseg and is_mkpf
**********************************************************************
DATA : itab_mkpf TYPE TABLE OF mkpf.
DATA : work_mseg TYPE mseg.
DATA : itab1t_mseg TYPE TABLE OF mseg.
DATA : itab1_mseg TYPE TABLE OF mseg.
LOOP AT it_mseg INTO work_mseg.
* Fetching the delivery note if already exists
SELECT mblnr mjahr xblnr FROM mkpf
INTO CORRESPONDING FIELDS OF TABLE itab_mkpf
WHERE xblnr = is_mkpf-xblnr.
IF sy-subrc EQ 0.
IF work_mseg-bwart EQ '103' .
SELECT mblnr lifnr FROM mseg INTO TABLE itab1_mseg
FOR ALL ENTRIES IN itab_mkpf
WHERE mblnr = itab_mkpf-mblnr
AND mjahr = itab_mkpf-mjahr
AND lifnr = work_mseg-lifnr.
IF sy-subrc EQ 0.
MESSAGE 'Delivery note already there for this Vendor' TYPE 'E'.
ENDIF.
ELSEIF work_mseg-bwart EQ '105'.
SELECT mblnr mjahr lifnr ebeln ebelp FROM mseg
INTO CORRESPONDING FIELDS OF TABLE itab1t_mseg
WHERE ebeln = work_mseg-ebeln
AND ebelp = work_mseg-ebelp.
SELECT mblnr mjahr xblnr FROM mkpf
INTO CORRESPONDING FIELDS OF TABLE itab_mkpf
FOR ALL ENTRIES IN itab1t_mseg
WHERE mblnr = itab1t_mseg-mblnr
AND mjahr = itab1t_mseg-mjahr
AND xblnr = is_mkpf-xblnr.
IF sy-subrc = 0.
IF sy-subrc = 0.
SELECT mblnr lifnr ebeln FROM mseg
INTO CORRESPONDING FIELDS OF TABLE itab1_mseg
FOR ALL ENTRIES IN itab_mkpf
WHERE mblnr = itab_mkpf-mblnr
AND mjahr = itab_mkpf-mjahr
AND bwart <> '103'
AND lifnr = work_mseg-lifnr.
IF sy-subrc EQ 0.
MESSAGE 'Delivery note already there for this Vendor' TYPE 'E'.
ENDIF.
ENDIF.
ELSE.
MESSAGE 'Maintain the same delivery note number as maintained for 103 mvt type' TYPE 'E'.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
ENDMETHOD.Edited by: Matt on Dec 24, 2008 7:33 PM - added tags
Moved to correct forum by moderator.
Hello gurus please give me suggestions to performance the code in a good way.
METHOD if_ex_mb_migo_badi~post_document .
**********************************************************************
*The delivery note number provided by vendor should be unique in migo
Importing it_mseg and is_mkpf
**********************************************************************
DATA : itab_mkpf TYPE TABLE OF mkpf.
DATA : work_mseg TYPE mseg.
DATA : itab1t_mseg TYPE TABLE OF mseg.
DATA : itab1_mseg TYPE TABLE OF mseg.
LOOP AT it_mseg INTO work_mseg.
* Fetching the delivery note if already exists
SELECT mblnr mjahr xblnr FROM mkpf
INTO CORRESPONDING FIELDS OF TABLE itab_mkpf
WHERE xblnr = is_mkpf-xblnr.
IF sy-subrc EQ 0.
IF work_mseg-bwart EQ '103' .
SELECT mblnr lifnr FROM mseg INTO TABLE itab1_mseg
FOR ALL ENTRIES IN itab_mkpf
WHERE mblnr = itab_mkpf-mblnr
AND mjahr = itab_mkpf-mjahr
AND lifnr = work_mseg-lifnr.
IF sy-subrc EQ 0.
MESSAGE 'Delivery note already there for this Vendor' TYPE 'E'.
ENDIF.
ELSEIF work_mseg-bwart EQ '105'.
SELECT mblnr mjahr lifnr ebeln ebelp FROM mseg
INTO CORRESPONDING FIELDS OF TABLE itab1t_mseg
WHERE ebeln = work_mseg-ebeln
AND ebelp = work_mseg-ebelp.
SELECT mblnr mjahr xblnr FROM mkpf
INTO CORRESPONDING FIELDS OF TABLE itab_mkpf
FOR ALL ENTRIES IN itab1t_mseg
WHERE mblnr = itab1t_mseg-mblnr
AND mjahr = itab1t_mseg-mjahr
AND xblnr = is_mkpf-xblnr.
IF sy-subrc = 0.
IF sy-subrc = 0.
SELECT mblnr lifnr ebeln FROM mseg
INTO CORRESPONDING FIELDS OF TABLE itab1_mseg
FOR ALL ENTRIES IN itab_mkpf
WHERE mblnr = itab_mkpf-mblnr
AND mjahr = itab_mkpf-mjahr
AND bwart <> '103'
AND lifnr = work_mseg-lifnr.
IF sy-subrc EQ 0.
MESSAGE 'Delivery note already there for this Vendor' TYPE 'E'.
ENDIF.
ENDIF.
ELSE.
MESSAGE 'Maintain the same delivery note number as maintained for 103 mvt type' TYPE 'E'.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
ENDMETHOD.Edited by: Matt on Dec 24, 2008 7:33 PM - added tags
2008 Dec 24 9:01 AM
2008 Dec 24 9:03 AM
Few basic things...
- Dont use selects inside the loop, if possible try and populate your table outside the loop and use the READ statement with Binary search in the loop.
- Instead of INTO CORRESPONDING FIELDS key in the actual field names.
- Also Use key fields in the where condition if available
Rgds
Narendra
2008 Dec 24 9:03 AM
Hi,
don't use the select statements inside the loop...endloop.
select all the data from database and use read statement or loop on the internal tables.
then u can reduce the perfomance issue.
2008 Dec 24 9:08 AM
sorry in my code i msissed one statement.
METHOD if_ex_mb_migo_badi~post_document .
**********************************************************************
*The delivery note number provided by vendor should be unique in migo
Importing it_mseg and is_mkpf
Work = wa
Itab1 = itt
Itab1t = ittt
Itab = ist
**********************************************************************
DATA : itab_mkpf TYPE TABLE OF mkpf.
DATA : work_mseg TYPE mseg.
DATA : itab1t_mseg TYPE TABLE OF mseg.
DATA : itab1_mseg TYPE TABLE OF mseg.
LOOP AT it_mseg INTO work_mseg.
if work_mseg-bukrs = '2122'."here i am checking for only one company code ,if it satisfies then only the rest of the code will execute.so I think using loop here wont degrade the performance
* Fetching the delivery note if already exists
SELECT mblnr mjahr xblnr FROM mkpf
INTO CORRESPONDING FIELDS OF TABLE itab_mkpf
WHERE xblnr = is_mkpf-xblnr.
IF sy-subrc EQ 0.
IF work_mseg-bwart EQ '103' .
SELECT mblnr lifnr FROM mseg INTO TABLE itab1_mseg
FOR ALL ENTRIES IN itab_mkpf
WHERE mblnr = itab_mkpf-mblnr
AND mjahr = itab_mkpf-mjahr
AND lifnr = work_mseg-lifnr.
IF sy-subrc EQ 0.
MESSAGE 'Delivery note already there for this Vendor' TYPE 'E'.
ENDIF.
ELSEIF work_mseg-bwart EQ '105'.
SELECT mblnr mjahr lifnr ebeln ebelp FROM mseg
INTO CORRESPONDING FIELDS OF TABLE itab1t_mseg
WHERE ebeln = work_mseg-ebeln
AND ebelp = work_mseg-ebelp.
SELECT mblnr mjahr xblnr FROM mkpf
INTO CORRESPONDING FIELDS OF TABLE itab_mkpf
FOR ALL ENTRIES IN itab1t_mseg
WHERE mblnr = itab1t_mseg-mblnr
AND mjahr = itab1t_mseg-mjahr
AND xblnr = is_mkpf-xblnr.
IF sy-subrc = 0.
IF sy-subrc = 0.
SELECT mblnr lifnr ebeln FROM mseg
INTO CORRESPONDING FIELDS OF TABLE itab1_mseg
FOR ALL ENTRIES IN itab_mkpf
WHERE mblnr = itab_mkpf-mblnr
AND mjahr = itab_mkpf-mjahr
AND bwart <> '103'
AND lifnr = work_mseg-lifnr.
IF sy-subrc EQ 0.
MESSAGE 'Delivery note already there for this Vendor' TYPE 'E'.
ENDIF.
ENDIF.
ELSE.
MESSAGE 'Maintain the same delivery note number as maintained for 103 mvt type' TYPE 'E'.
ENDIF.
ENDIF.
ENDIF.
Endif.
ENDLOOP.
ENDMETHOD.Edited by: Matt on Dec 24, 2008 7:34 PM
2008 Dec 24 9:16 AM
hi,
all the code what u wrote inside the badi MB_MIGO_BADI is not required....
all the required fields are available in the parameter it_mseg and is_mkpf..
using this 2 parameter's, u can validate and acheive your requirement..
because u wrote soo many codes inside the BADI, this is not neccessary because u can use the parameter directly..
2008 Dec 24 9:49 AM
gurus could anyone please guide me further where exactly i can make the improvements.
Thank you for all the replies
2008 Dec 24 10:53 AM
Hello Madan,
I see that in the code you have 2 selects from MKPF using XBLNR. I had a look @ MKPF & there is no default INDEX on XBLNR.
My suggestion is to check if you have an index on XBLNR, if not create one.
Hope this helps.
BR,
Suhas
2008 Dec 24 6:36 PM
>
> sorry in my code i msissed one statement.
You also missed tags around your code. I've put them in for you. Doesn't it look nicer!
2008 Dec 25 5:28 AM
thank you Matt , now my code looks good so that anyone can understand and help me to change the code.
Gurus please guide where further cahnges are required.
2008 Dec 26 4:59 AM
>
> thank you Matt , now my code looks good so that anyone can understand and help me to change the code.
>
> Gurus please guide where further cahnges are required.
Have you adjust your code based on people advises in here?
Regards,
Abraham
2008 Dec 29 8:42 AM
2008 Dec 29 10:43 AM
I think following three points you need to take care of:
1. Try to remove move-corresponding
2. Select query shouldnt be used in any loop...endloop.
3. If you nned to process for bukrs = '2122' then insted of looping every records use
LOOP AT it_mseg where bukrs = '2122'.
2008 Dec 24 9:06 AM
Remove INTO CORRESPONDING FIELDS
while selecting for all entries take all the key fields in select statment whether u need it or not.
Avoid hitting one table multiple times rather select in one go and use read to filter the data.
Hope this helps.
Regards
Bikas
2008 Dec 24 10:08 AM
Hi,
If you write DB queries inside the loop it will affect the performance.
What you can do is create ranges for fields like
work_mseg-ebeln, work_mseg-ebelp etc then use those ranges in select statement.
Also instead of into corresponding give the field name in the same order as your internal table,
in case ur int tab is same as db tab structure dont use corresponding.
Ex.
RANGES: r_lifnr FOR mkpf-lifnr.
LOOP AT it_mseg INTO work_mseg.
"your conditions
r_lifnr-sign = 'I'.
r_lifnr-option = 'EQ'.
r_lifnr-low = work_mseg-lifnr.
APPEND lr_cust.
"You can fill other ranges here
ENDLOOP.
SELECT mblnr lifnr FROM mseg INTO TABLE itab1_mseg
FOR ALL ENTRIES IN itab_mkpf
WHERE mblnr = itab_mkpf-mblnr
AND mjahr = itab_mkpf-mjahr
AND lifnr IN r_lifnr. "<=use your range hereRegards,
Manoj Kumar P
2008 Dec 29 10:27 AM
Hi Madan,
1) hitting the BSEG with in the loop leads to bad performance. instead select the data from the BSEG and process the records based on your requirement.
2)Don't use the "INTO CORRESPONDING FIELDS " instead take the actual fields.
3) as BSEG is the cluster table u need to use the all the primary key values in the where conditon. other wise data will not select properly.
for the BSEG primary key fields are BUKRS,BELNR,GJAHR,BUZEI.
hope these tips are useful
2008 Dec 29 11:18 AM
Your whole logic is quite strange, please revise completely!
Use a sorted table for it_mseg! otherwise you will always loop the full table:
Then divide into logic for the branches, and be aware that the first select is independent
of the loop.
SELECT mblnr mjahr xblnr FROM mkpf
INTO CORRESPONDING FIELDS OF TABLE itab_mkpf
WHERE xblnr = is_mkpf-xblnr.
LOOP AT it_mseg INTO work_mseg where work_mseg-bwart EQ '103' .
IF NOT itab_mkbf IS INOITIAL.
SELECT mblnr lifnr FROM mseg INTO TABLE itab1_mseg
FOR ALL ENTRIES IN itab_mkpf
WHERE mblnr = itab_mkpf-mblnr
AND mjahr = itab_mkpf-mjahr
AND lifnr = work_mseg-lifnr.
IF sy-subrc EQ 0.
MESSAGE 'Delivery note already there for this Vendor' TYPE 'E'.
ENDIF.
ENDIF.
ENDLOOP
LOOP AT it_mseg INTO work_mseg where work_mseg-bwart EQ '105' .
see below
....
ENDIF.
ENDLOOP
Check whether you can change this into a join!
SELECT mblnr mjahr lifnr ebeln ebelp FROM mseg
INTO CORRESPONDING FIELDS OF TABLE itab1t_mseg
WHERE ebeln = work_mseg-ebeln
AND ebelp = work_mseg-ebelp.
SELECT mblnr mjahr xblnr FROM mkpf
INTO CORRESPONDING FIELDS OF TABLE itab_mkpf
FOR ALL ENTRIES IN itab1t_mseg
WHERE mblnr = itab1t_mseg-mblnr
AND mjahr = itab1t_mseg-mjahr
AND xblnr = is_mkpf-xblnr.
IF sy-subrc = 0.
SELECT mblnr lifnr ebeln FROM mseg
INTO CORRESPONDING FIELDS OF TABLE itab1_mseg
FOR ALL ENTRIES IN itab_mkpf
WHERE mblnr = itab_mkpf-mblnr
AND mjahr = itab_mkpf-mjahr
AND bwart '103'
AND lifnr = work_mseg-lifnr.
Siegfried
2009 Jan 02 12:26 PM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |