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

coding problem

Former Member
0 Likes
1,059

Hi Gurus , in this code , when sy-subrc = 4 , still the Insert code is not running.

i.e. if sy-subrc ne 0. is not getting called.

select * from zvr_st_inv_forms where vbeln = it_itab-vbeln.

if sy-subrc eq 0.

modify zvr_st_inv_forms from it_itab2.

CLEAR ZVR_ST_INV_FORMS.

clear it_itab2.

endif.

if sy-subrc ne 0.

INSERT ZVR_ST_INV_FORMS from it_itab2.

CLEAR ZVR_ST_INV_FORMS.

clear it_itab2.

endif.

endselect.

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
0 Likes
1,031

Within a SELECT... ENDSELECT it makes NO sense to check the value of sy-subrc immediately after the SELECT statement. Also, sy-subrc can change value within your first IF, so you could end up with the second running also clauses running.

It looks like you're checking whether a record exists in your Z table. If it doesn't, then you want to insert the records, otherwise, you want to change them.

Have a look at the keywords UPDATE, MODIFY and INSERT. The MODIFY statement inserts one or several lines specified in source in the database table specified in target, or overwrites existing lines.

So you could possibly, simply:

MODIFY zvr_st_inv_forms FROM it_itab2.

Otherwise use:

select SINGLE * from zvr_st_inv_forms where vbeln = it_itab-vbeln.

if sy-subrc eq 0.

UPDATE zvr_st_inv_forms from it_itab2.

CLEAR ZVR_ST_INV_FORMS.

clear it_itab2.

ELSE.

INSERT ZVR_ST_INV_FORMS from it_itab2.

CLEAR ZVR_ST_INV_FORMS.

clear it_itab2.

endif.

Regards

matt

9 REPLIES 9
Read only

Former Member
0 Likes
1,031

hi,

in your code in select statemnet it_tab is there ,i think that is it_itab2

Read only

former_member404244
Active Contributor
0 Likes
1,031

Hi,

Try like this

select * from zvr_st_inv_forms where vbeln = it_itab-vbeln.

if sy-subrc eq 0.

modify zvr_st_inv_forms from it_itab2.

CLEAR ZVR_ST_INV_FORMS.

clear it_itab2.

else.

INSERT ZVR_ST_INV_FORMS from it_itab2.

CLEAR ZVR_ST_INV_FORMS.

clear it_itab2.

endif.

endselect.

Regards,

Nagaraj

Read only

Former Member
0 Likes
1,031

Hi rahul,

Command is

INSERT dbtab [CLIENT SPECIFIED] FROM TABLE itab. or INSERT (dbtabname) [CLIENT SPECIFIED] FROM TABLE itab.

INSERT ZVR_ST_INV_FORMS from it_itab2.

Change it to

INSERT ZVR_ST_INV_FORMS from TABLE it_itab2.

Check your table after the whole execution of the code or Use COMMIT WORK after the insert command if you are checkin in the debugging mode

Read only

Former Member
0 Likes
1,031

Rahul,

1. From where you are getting the it_Itab2

values.

2.it_Itab2 must have same structure like your

database table (zvr_st_inv_forms).

Don't forget to reward if useful...

Read only

nivin_varkey
Active Participant
0 Likes
1,031

friend! u need to change the code to this.

select * from zvr_st_inv_forms where vbeln = it_itab-vbeln.

endselect.

if sy-subrc eq 0.

modify zvr_st_inv_forms from it_itab2.

CLEAR ZVR_ST_INV_FORMS.

clear it_itab2.

else.

INSERT ZVR_ST_INV_FORMS from it_itab2.

CLEAR ZVR_ST_INV_FORMS.

clear it_itab2.

endif.

but if zvr_st_inv_forms has multiple entries for it_tab-vbeln ..then u might be in a soup..

Edited by: Nivin Joseph Varkey on Jan 22, 2008 10:22 AM

Read only

0 Likes
1,031

hii friends , it_itab and ii_itab are same , so that will not matter .

tell me we can if & else in select - endselect?

its running only first if , not the second if.

i tried IF - ELSE also.

but it didnt worked.

Read only

matt
Active Contributor
0 Likes
1,032

Within a SELECT... ENDSELECT it makes NO sense to check the value of sy-subrc immediately after the SELECT statement. Also, sy-subrc can change value within your first IF, so you could end up with the second running also clauses running.

It looks like you're checking whether a record exists in your Z table. If it doesn't, then you want to insert the records, otherwise, you want to change them.

Have a look at the keywords UPDATE, MODIFY and INSERT. The MODIFY statement inserts one or several lines specified in source in the database table specified in target, or overwrites existing lines.

So you could possibly, simply:

MODIFY zvr_st_inv_forms FROM it_itab2.

Otherwise use:

select SINGLE * from zvr_st_inv_forms where vbeln = it_itab-vbeln.

if sy-subrc eq 0.

UPDATE zvr_st_inv_forms from it_itab2.

CLEAR ZVR_ST_INV_FORMS.

clear it_itab2.

ELSE.

INSERT ZVR_ST_INV_FORMS from it_itab2.

CLEAR ZVR_ST_INV_FORMS.

clear it_itab2.

endif.

Regards

matt

Read only

Former Member
0 Likes
1,031

hi rahul,

we can write the if else in between the select endselect statement.

but the condition you are having in your code is related with that select statement.

means when the data is selected then sy-subrc =0 right,and not selected then it is 4.

But the data not select form the select query the the execution will not goes into the select statements body so the else part of your code is not get executed.

so according to me try the sy-subrc = 4 code out of the select endselect body.

thanks

Dharmishta

Read only

0 Likes
1,031

Thanks Matthew and Dharmishta for answer..points r given...