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

Update Custom Table which doesnt have maintenance dialog

Former Member
0 Likes
984

Hello,

I used below codes. But my custom table's BUDAT field wasn't updated. Why? Can the problem be that there isnt any maintenance dialog for this custom table? Thaks in advance.

SELECT *

FROM (gv_table)

INTO TABLE <gt_ce>

WHERE vrgar = 'C'

AND rbeln IN s_rbeln

AND timestmp > gv_tmstst AND

timestmp <= gv_tmsten

ORDER BY ('BELNR').

LOOP AT <gt_ce> ASSIGNING <fs_struc>.

lv_tbx = sy-tabix.

ASSIGN COMPONENT 'BUDAT' OF STRUCTURE <fs_struc> TO <fs_budat>.

ASSIGN COMPONENT 'HZDAT' OF STRUCTURE <fs_struc> TO <fs_hzdat>.

ASSIGN COMPONENT 'PALEDGER' OF STRUCTURE <fs_struc> TO <fs_paledger>.

ASSIGN COMPONENT 'VRGAR' OF STRUCTURE <fs_struc> TO <fs_vrgar>.

ASSIGN COMPONENT 'VERSI' OF STRUCTURE <fs_struc> TO <fs_versi>.

ASSIGN COMPONENT 'PERIO' OF STRUCTURE <fs_struc> TO <fs_perio>.

ASSIGN COMPONENT 'PAOBJNR' OF STRUCTURE <fs_struc> TO <fs_paobjnr>.

ASSIGN COMPONENT 'PASUBNR' OF STRUCTURE <fs_struc> TO <fs_pasubnr>.

ASSIGN COMPONENT 'BELNR' OF STRUCTURE <fs_struc> TO <fs_belnr>.

ASSIGN COMPONENT 'POSNR' OF STRUCTURE <fs_struc> TO <fs_posnr>.

<fs_budat> = <fs_hzdat> - 1.

MODIFY <gt_ce> FROM <fs_struc> INDEX lv_tbx.

UPDATE (gv_table) SET BUDAT = <fs_budat> WHERE

paledger = <fs_paledger> AND

vrgar = <fs_vrgar> AND

versi = <fs_versi> AND

perio = <fs_perio> AND

paobjnr = <fs_paobjnr> AND

pasubnr = <fs_pasubnr> AND

belnr = <fs_belnr> AND

posnr = <fs_posnr>.

ENDLOOP.

<< Moderator message - Everyone's problem is important. But the answers in the forum are provided by volunteers. Please do not ask for help quickly. >>

Edited by: Rob Burbank on Feb 4, 2011 10:34 AM

Hello,

I used below codes. But my custom table's BUDAT field wasn't updated. Why? Can the problem be that there isnt any maintenance dialog for this custom table? Thaks in advance.

SELECT *

FROM (gv_table)

INTO TABLE <gt_ce>

WHERE vrgar = 'C'

AND rbeln IN s_rbeln

AND timestmp > gv_tmstst AND

timestmp <= gv_tmsten

ORDER BY ('BELNR').

LOOP AT <gt_ce> ASSIGNING <fs_struc>.

lv_tbx = sy-tabix.

ASSIGN COMPONENT 'BUDAT' OF STRUCTURE <fs_struc> TO <fs_budat>.

ASSIGN COMPONENT 'HZDAT' OF STRUCTURE <fs_struc> TO <fs_hzdat>.

ASSIGN COMPONENT 'PALEDGER' OF STRUCTURE <fs_struc> TO <fs_paledger>.

ASSIGN COMPONENT 'VRGAR' OF STRUCTURE <fs_struc> TO <fs_vrgar>.

ASSIGN COMPONENT 'VERSI' OF STRUCTURE <fs_struc> TO <fs_versi>.

ASSIGN COMPONENT 'PERIO' OF STRUCTURE <fs_struc> TO <fs_perio>.

ASSIGN COMPONENT 'PAOBJNR' OF STRUCTURE <fs_struc> TO <fs_paobjnr>.

ASSIGN COMPONENT 'PASUBNR' OF STRUCTURE <fs_struc> TO <fs_pasubnr>.

ASSIGN COMPONENT 'BELNR' OF STRUCTURE <fs_struc> TO <fs_belnr>.

ASSIGN COMPONENT 'POSNR' OF STRUCTURE <fs_struc> TO <fs_posnr>.

<fs_budat> = <fs_hzdat> - 1.

MODIFY <gt_ce> FROM <fs_struc> INDEX lv_tbx.

UPDATE (gv_table) SET BUDAT = <fs_budat> WHERE

paledger = <fs_paledger> AND

vrgar = <fs_vrgar> AND

versi = <fs_versi> AND

perio = <fs_perio> AND

paobjnr = <fs_paobjnr> AND

pasubnr = <fs_pasubnr> AND

belnr = <fs_belnr> AND

posnr = <fs_posnr>.

ENDLOOP.

<< Moderator message - Everyone's problem is important. But the answers in the forum are provided by volunteers. Please do not ask for help quickly. >>

Edited by: Rob Burbank on Feb 4, 2011 10:34 AM

7 REPLIES 7
Read only

Former Member
0 Likes
942

Maybe you should do some debugging to see what the value of <fs_hzdat> is.

Rob

Read only

0 Likes
942

I debugged but can not see the problem. The field comes correctly and internal table is modified correctly but only problem is update. I can not update the custom table.

Read only

Former Member
0 Likes
942

Man, this is so over-engineered, and you modified FS_BUDAT not sure you actually updated FS_STRUC... consider this simple way to do this (we use field symbols so we don't have to do that MODIFY stuff....!)

SELECT *  FROM (gv_table)
INTO TABLE <gt_ce>
WHERE vrgar = 'C'
AND rbeln IN s_rbeln
AND (  timestmp > gv_tmstst AND
            timestmp <= gv_tmsten ).
sort <gt_ce> by belnr.
LOOP AT <gt_ce> ASSIGNING <fs_struc>.
if <fs_struc> is assigned.
<fs_struc>-budat = <fs_struc>-hzdat - 1.  "debug here to be sure BUDAT and HZDAT contain/do what is expected.
endif.
endloop.
UPDATE (gv_table) from table  <gt_ce>.

Read only

0 Likes
942

I debugged and I am sure that BUDAT field of <fs_struc> is changed correctly and <fs_struc> change internal table correctly. There isn^t any problem to change BUDAT field of <fs_struc> and internal table. I also try again like your advice. but this is dynamic table so I use as <fs_struc> type any. so it gives error that <fs_struc>-budat is not available.

Read only

Former Member
0 Likes
942

Actually, the problem is not soluted yet.

Read only

0 Likes
942

i think the update statement will only work if there is a old record conatains with same key.

simply change your code to modify command. it will work.

thanks

Read only

vinod_vemuru2
Active Contributor
0 Likes
942

Hi,

You didn't tell what is the sy-subrc after the UPDATE statement.

Use COMMIT WORK AND WAIT after the UPDATE statement (If update is success).

Also just check if you have multiple entries matching below criteria. Because UPDATE is used inside the loop. If you have more than one entry matching below criteria, only data of last entry is updated to all. Make sure that you are passing the correct keys in WHERE clause.

To avoid this update the data base table at one shot using MODIFY FROM table statement outside the loop which is good in performance point of view also instead of individual updates in side the loop.


WHERE
paledger = <fs_paledger> AND
vrgar = <fs_vrgar> AND
versi = <fs_versi> AND
perio = <fs_perio> AND
paobjnr = <fs_paobjnr> AND
pasubnr = <fs_pasubnr> AND
belnr = <fs_belnr> AND
posnr = <fs_posnr>.

Thanks,

Vinod.