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: 

Set initial value in a table field

Former Member
0 Kudos

HI all,

I have to test some programs and want to clear values in tables to check the behavior of a program when dealing with initial values.

I using this code:

parameters: p_pernr type pa0105-pernr,

p_val type pa0105-usrid.

data: ls_pa0105 type pa0105.

select single * from pa0105 into ls_pa0105

where subty = '0001'

and pernr = p_pernr.

if sy-subrc = 0.

if p_val is initial.

clear ls_pa0105-usrid.

else.

ls_pa0105-usrid = p_val.

endif.

modify pa0105 from ls_pa0105.

endif.

This works if I put a value in p_val but it does nothing if I leave p_val initial.

Even if I clear the field, when I execute the modify, nothing has change in the table.

Thanks for any help.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

try the below code.

select single * from pa0105 into ls_pa0105

where subty = '0001'

and pernr = p_pernr.

if sy-subrc = 0.

if p_val is initial.

clear ls_pa0105-usrid.

else.

ls_pa0105-usrid = p_val.

endif.

modify pa0105 from ls_pa0105 TRANSPORTING USRID.

endif.

Hope it helps.

Regards

Shruti

6 REPLIES 6

Former Member
0 Kudos

Hi

try this code.



if sy-subrc = 0 .
clear ls_pa0105-usrid.
else.
ls_pa0105-usrid = p_val.
endif.

Modify pa0105 from ls_pa0105.

0 Kudos

Hi,

It's the same code has I have tried, except for the p_val checking.

Checking p_val is not the problem, I debug the program and it goes through the clearing and modify part of the program.

In the debugger I can see that the usrid field is empty, but this does nothing in the table itself.

Former Member
0 Kudos

Hi,

try the below code.

select single * from pa0105 into ls_pa0105

where subty = '0001'

and pernr = p_pernr.

if sy-subrc = 0.

if p_val is initial.

clear ls_pa0105-usrid.

else.

ls_pa0105-usrid = p_val.

endif.

modify pa0105 from ls_pa0105 TRANSPORTING USRID.

endif.

Hope it helps.

Regards

Shruti

Former Member
0 Kudos

Hello,

This works only for an internal table, I'm updating a database table.

If I put this I get a syntax error.

Former Member
0 Kudos

Hi,

I have tried implementing this in my system with the code below, which seems to work fine. Here, the table tbl5 has 2 columns PARAMNAME and PARAMVALUE. The PARAMVALUE initially has the value 'X' which is cleared in the program and the database table is modified corretly.

Please check if you are missing out something by refering this.

DATA: wa_tbl5 type tbl5.

select single * from tbl5 into wa_tbl5

where paramname = 'param1'.

clear wa_tbl5-PARAMVALUE.

modify tbl5 from tbl5.

if sy-subrc EQ 0.

write: 'success'.

else.

write:/ 'fail'.

endif.

Thanks,

Sowmiya M

Former Member
0 Kudos

How silly of me,

I had multiple rows in that table so I was actually writing to one row and the other program was reading the other row!

My code was working all this time.

Thanks all for your help.