‎2008 Feb 20 1:10 AM
Hi
anyone pls tell me the following code(BOLD) is correct or not
points will be reward
DATA : lv_tabix TYPE sy-tabix.
FIELD-SYMBOLS : <fs_op> TYPE zfifn_op .
LOOP AT ITAB_CUSTOM.
*SELECT * FROM zfifn_op INTO TABLE zfifn_op_upd*
FOR ALL ENTRIES IN itab_custom
WHERE opbel = itab_custom-opbel
AND bukrs = itab_custom-bukrs.
ENDLOOP.
LOOP AT zfifn_op_upd ASSIGNING <fs_op>.
lv_tabix = sy-tabix.
READ TABLE itab_custom WITH KEY opbel = <fs_op>-opbel binary search.
IF sy-subrc = 0.
<fs_op>-bis = itab_custom-bis.
<fs_op>-tariftyp = itab_custom-tariftyp.
<fs_op>-tarifart = itab_custom-tarifart.
<fs_op>-aklasse = itab_custom-aklasse.
<fs_op>-ab = itab_custom-ab.
MODIFY zfifn_op_upd FROM <fs_op> INDEX lv_tabix.
countb = countb + 1.
ELSE.
countc = countc + 1.
CONCATENATE 'Document Number: ' space itab_zfifn_op-opbel cdelimit
'Company Code:' space itab_zfifn_op-bukrs cdelimit
' does not exist in ZFIFN_OP table. UPDATE FAIL.'
INTO text_record3.
WRITE: /10 text_record3.
ENDIF.
ENDLOOP.
UPDATE zfifn_op
FROM TABLE zfifn_op_upd.
COMMIT WORK AND WAIT.
‎2008 Feb 20 2:38 AM
Hi,
Syntax is correct but our target is wrong.
LOOP AT ITAB_CUSTOM.
*SELECT * FROM zfifn_op INTO TABLE zfifn_op_upd*
FOR ALL ENTRIES IN itab_custom
WHERE opbel = itab_custom-opbel
AND bukrs = itab_custom-bukrs.
ENDLOOP.
You should not write select statement in LOOP.
Beacuse loop will run till the total no. of records present in internal table ITAB_CUSTOM.Each time select statement will run.So performance will get effect.
SORT : ITAB_CUSTOM by opbel.
SELECT * FROM zfifn_op
INTO TABLE zfifn_op_upd
FOR ALL ENTRIES IN itab_custom
WHERE opbel = itab_custom-opbel
AND bukrs = itab_custom-bukrs.
Pls. reward if useful...
‎2008 Feb 20 1:17 AM
HI
SELECT * FROM zfifn_op INTO TABLE zfifn_op_upd*
FOR ALL ENTRIES IN itab_custom
WHERE opbel = itab_custom-opbel
AND bukrs = itab_custom-bukrs.
Before Reading , SORT itab_custom by opbel, for binary search..
READ TABLE itab_custom WITH KEY opbel = <fs_op>-opbel binary search.
Lets us know, after this,
Hope it helps.
Praveen
‎2008 Feb 20 2:38 AM
Hi,
Syntax is correct but our target is wrong.
LOOP AT ITAB_CUSTOM.
*SELECT * FROM zfifn_op INTO TABLE zfifn_op_upd*
FOR ALL ENTRIES IN itab_custom
WHERE opbel = itab_custom-opbel
AND bukrs = itab_custom-bukrs.
ENDLOOP.
You should not write select statement in LOOP.
Beacuse loop will run till the total no. of records present in internal table ITAB_CUSTOM.Each time select statement will run.So performance will get effect.
SORT : ITAB_CUSTOM by opbel.
SELECT * FROM zfifn_op
INTO TABLE zfifn_op_upd
FOR ALL ENTRIES IN itab_custom
WHERE opbel = itab_custom-opbel
AND bukrs = itab_custom-bukrs.
Pls. reward if useful...
‎2008 Feb 20 3:52 AM
Hi Kumar
When you are using FOR ALL ENTRIES , this statement automatically takes care of all the entries in the table you are referring to , in this case it is itan_custom. Hence no need to put the select inside the loop.
Also when you use FOR ALL ENTRIES , make sure that there are entries in table itab_custom. So the first part of your code should have been:
DATA : lv_tabix TYPE sy-tabix.
FIELD-SYMBOLS : <fs_op> STRUCTURE zfifn_op .
IF ( NOT itab_custom[] IS INITIAL ).
SELECT * FROM zfifn_op INTO TABLE zfifn_op_upd
FOR ALL ENTRIES in itab_custom
WHERE opbel = itab_custom-opbel
AND bukrs = itab_custom-bukrs.
ENDIF.
Note: Try to select specific fields instead of all the fields to improve performance.
LOOP AT zfifn_op_upd ASSIGNING <fs_op>.
lv_tabix = sy-tabix.
SORT itab_custom BY OPBEL.
READ TABLE itab_custom WITH KEY opbel = <fs_op>-opbel
binary search.
*Note: Before every READ with Binary search , you should SORT the table otherwise binary search has not meaning.
IF sy-subrc EQ 0.
<fs_op>-bis = itab_custom-bis.
<fs_op>-tariftyp = itab_custom-tariftyp.
<fs_op>-tarifart = itab_custom-tarifart.
<fs_op>-aklasse = itab_custom-aklasse.
<fs_op>-ab = itab_custom-ab.
MODIFY zfifn_op_upd FROM <fs_op> INDEX lv_tabix.
countb = countb + 1.
ELSE.
countc = countc + 1.
CONCATENATE 'Document Number: ' space itab_zfifn_op-opbel cdelimit
'Company Code:' space itab_zfifn_op-bukrs cdelimit
' does not exist in ZFIFN_OP table. UPDATE FAIL.'
INTO text_record3.
WRITE: /10 text_record3.
ENDIF.
ENDLOOP.
UPDATE zfifn_op
FROM TABLE zfifn_op_upd.
Commit work is not required here.
Also you should be sure that you just want to update the records in table
zfifn_op and not add any. If you want to add records , then you will have to use the MODIFY statement instead.
Hope this helps.
Cheers
Shivika