Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

logic needed pls help

Former Member
0 Likes
639

hi

i need to update and the data base table using fiel symbol and i need to count the records

following is the code. pls hepl me.

FIELD-SYMBOLS : <fs_op> TYPE zfifn_op .

SELECT * FROM zfifn_op INTO TABLE zfifn_op_upd

WHERE opbel = itab_custom-opbel

AND bukrs = itab_custom-bukrs.

SORT zfifn_op_upd BY opbel.

LOOP AT zfifn_op_upd ASSIGNING <fs_op>.

READ TABLE itab_custom WITH KEY opbel = <fs_op>-opbel.

IF sy-subrc = 0.

<fs_op>-opbel = itab_custom-opbel.

ENDIF.

ENDLOOP.

UPDATE zfifn_op

FROM TABLE zfifn_op_upd.

COMMIT WORK AND WAIT.

Points will be reward

1 ACCEPTED SOLUTION
Read only

former_member416498
Active Participant
0 Likes
620

Hi please see this sample code, might be useful.

1. For selecting data using field symbol.

SELECT * FROM

<db table name> INTO TABLE <fs_itab>.

2. Modify database table using field symbol.

MODIFY <db table name> FROM TABLE <fs_itab>.

Note: <fs_itab> is a field symbol of type any table.

Please get back if you need some more info.

5 REPLIES 5
Read only

JozsefSzikszai
Active Contributor
0 Likes
620

hi Kumar,

while LOOPing the internal table you don't write back the changed values.

DATA : lv_tabix TYPE sy-tabix.

LOOP AT zfifn_op_upd ASSIGNING <fs_op>.

lv_tabix = sy-tabix.

READ TABLE itab_custom WITH KEY opbel = <fs_op>-opbel.

IF sy-subrc = 0.

<fs_op>-opbel = itab_custom-opbel.

MODIFY TABLE zfifn_op_upd FROM <fs_op> INDEX lv_tabix.

ENDIF.

ENDLOOP.

New lines are in bold.

hope this helps

ec

Read only

0 Likes
620

Hi

I dont want to update the table one by one.

for example my file having 100,000 records means it ll affect performance. first i need to update structure. then i need to update data base table

Read only

0 Likes
620

Kumar,

the changes I suggested only updates the internal table, other part of the source code has to remain the same (I just did not include them), only the LOOP is changed. this means the DB update will be in one go, like before. Pls. give it a try!

ec

Read only

0 Likes
620

Your code looks absolutely correct. I tried following code bundle and it is working.

data: zfifn_op_upd like ztest125 occurs 0 with header line.

FIELD-SYMBOLS : <fs_op> TYPE ztest125 .

SELECT * FROM ztest125 INTO TABLE zfifn_op_upd

WHERE matnr = '22510G'.

SORT zfifn_op_upd BY matnr.

LOOP AT zfifn_op_upd ASSIGNING <fs_op>.

<fs_op>-mtart = 'HM01'.

ENDLOOP.

UPDATE ztest125

FROM TABLE zfifn_op_upd.

COMMIT WORK AND WAIT.

Thanks and regards,

Atanu

Read only

former_member416498
Active Participant
0 Likes
621

Hi please see this sample code, might be useful.

1. For selecting data using field symbol.

SELECT * FROM

<db table name> INTO TABLE <fs_itab>.

2. Modify database table using field symbol.

MODIFY <db table name> FROM TABLE <fs_itab>.

Note: <fs_itab> is a field symbol of type any table.

Please get back if you need some more info.