‎2007 Jul 17 8:55 PM
Hi Experts,
I have single screen having following six fields..
table1-field1
table1-field2
table1-field3,
table2-field1,
table2-field1,
table1-field3,
And have save button, When i user click on save. Data shud entered in table1 and table2 respectively.
Can anybody give me sample coding for above situation
Thanks in advance.
Pages: 1
Back to Thread List
‎2007 Jul 17 10:30 PM
data: i_table1 like table1 occurs 0 with header line,
i_table2 like table2 occurs 0 with header line.
In your PAI USER_COMMAND routine
WHEN 'SAVE'.
move: table1-field1 to i_table1-field1,
table1-field2 to i_table1-field2,
table1-field3 to i_table1-field3.
append i_table1.
similarly do it for table2 and then you can save it to the database as follows
modify table1 from table i_table1.
‎2007 Jul 17 10:30 PM
data: i_table1 like table1 occurs 0 with header line,
i_table2 like table2 occurs 0 with header line.
In your PAI USER_COMMAND routine
WHEN 'SAVE'.
move: table1-field1 to i_table1-field1,
table1-field2 to i_table1-field2,
table1-field3 to i_table1-field3.
append i_table1.
similarly do it for table2 and then you can save it to the database as follows
modify table1 from table i_table1.
‎2007 Jul 18 1:43 AM
I'd structure it something along the following lines:
Assuming in top include you have something like:
tables:
zmy_table1,
zmy_table2,
data:
begin of gs_table1,
field1 like zmy_table1-field1,
field2 like zmy_table1-field2,
field3 like zmy_table1-field3,
end of gs_table1,
begin of gs_table2
field1 like zmy_table2-field1,
field2 like zmy_table2-field2,
field3 like zmy_table2-field3,
end of gs_table2.and you have a "perform d9999_user_command" in your PAI:
*&---------------------------------------------------------------------*
*& Form d9999_user_command
*&---------------------------------------------------------------------*
form d9999_user_command.
* Process use actions
case sy-ucomm.
when 'ZSAVE'.
perform d9999_validate_screen. "make sure data is clean
perform d9999_save_data. "insert in database
when 'ZCHECK'
perform d9999_validate_screen. "make sure data is clean
* etc etc
endcase.
*&---------------------------------------------------------------------*
*& Form d9999_save_data
*&---------------------------------------------------------------------*
form d9999_save_data.
* Add to database
data:
ls_table1 like zmy_table1,
ls_table2 like zmy_table2.
* ZMY_TABLE1:
* Move screen to local structure that matches DB table
move-corresponding gs_table1 to ls_table1.
* fill in any gaps in table e.g. Created By & Date
ls_table1-cr_user = sy-uname.
ls_table1-cr_date = sy-datum.
insert ls_table1 into zmy_table1. "attempt DB insert
if not sy-subrc is initial. "handle exceptions
rollback work.
message s398(00) with 'Data insert error!' space space space.
exit.
endif.
*
* ZMY_TABLE2:
* Move screen to local structure that matches DB table
move-corresponding gs_table2 to ls_table2.
* fill in any gaps in table e.g. Created By & Date
ls_table2-cr_user = sy-uname.
ls_table2-cr_date = sy-datum.
insert ls_table2 into zmy_table2. "attempt DB insert
if not sy-subrc is initial. "handle exceptions
rollback work.
message s398(00) with 'Data insert error!' space space space.
exit.
endif.
commit work and wait.
message s398(00) with 'Data saved!' space space space.
endform. "d9999_user_command
‎2007 Jul 18 11:54 PM