Application Development 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: 

updating table.

Former Member
0 Kudos
82

hi,

my issue is updating ztable which i have created . this table gets updated with records after processing a batch session. batch session is for posting FI documents. ztable gets updated with the document number after processing the session. when there is only one transaction per session the ztable is getting updated with the respestive document no. but they r multiple transactions per session i.e multiple FI documents r created its updating the table with only document no. i.e first FI document no.. please help me in resolving this issue.

data : v_bktxt like bkpf-bktxt.

ata: v_cnt(5) type n value 0,

v_cnt1(5) type n value 0.

v_cnt = v_cnt + 1.

loop at t_bseg.

if v_bktxt(1) EQ '1'.

move: v_cnt to zbatch_log-cnt,

v_bktxt+1(10) to zbatch_log-batchid,

t_bseg-belnr to zbatch_log-belnr1.

insert zbatch_log.

endif.

endloop.

This is the basic code. what i was suggested to do is

if v_bktxt ( 1 ) EQ '1'

then check whether batchidno. exists in zbatch_log table

if NO

then move v_cnt, v_bktxt, t_bseg-belnr to zbatch_log table(my ztable).

if YES

then check the last value of v_cnt in zbatch_log table .

store it ina variable .

then move v_bktxt, t_bseg-belnr and increment the stored variable and increment the counter.

i am not getting how to chech the ztable table whether the entries r already there r not please help me with this code.

(in my ztable v_cnt and batchid are primary keys)

4 REPLIES 4

Former Member
0 Kudos
63

Hi,

i need some clarifications,

what is this v_bktxt will it comes from the internal table t_bseg ?

Regards,

Sreeram.

0 Kudos
63

hi,

v_bktxt is not fram the table t_bseg.

former_member589029
Active Contributor
0 Kudos
63

To find out, if there already is an entry in your ztable, do the following:

if v_bktxt(1) EQ '1'.

lv_batchid = v_bktxt+1(10).

select single max( cnt )

from zbatch_log

into lv_max_count

where batchid eq lv_batchid.

if sy-subrc eq 0.

  • there already is an entry and lv_max_count will contain the highest number of the entries - just add one to that number and insert your entry

else.

  • there is no entry yet in your table => insert the first one

endif.

Hope that helps,

Michael

Former Member
0 Kudos
63

Hi,

most of the times code review point of view they will not allow select statement inside the loop.

i think the primary key's of your Ztable are not inthe table t_bseg.

do one thing before your loop at t_bseg, select all entries from your ZTABLE into some internal table ex: T_ZTAB.

NOTE:- sort T_ZTAB by v_cnt batchid DESCENDING.

then

loop at T_BSEG.

read table T_ZTAB with key cnt = v_cnt

batchid = v_bktxt+1(10).

if sy-subrc = 0.

don't insert.

else.

insert that record into your ZTABLE.

endif.

end loop.

Reward if useful.

Thanks,

Sreeram.