2007 Jan 13 6:32 AM
Hi Guy,
I got a request to require a module program to maintain customer table, the SPEC is:
On the screen there are 2 fields as selection criteria value, after input them and press ENTER, all related record from this table should be list on the table control below, that is easy.
But, I will 1) modify some of listed records
2)add new records (press add new item button below table control to get one line active for input, then ENTER to check the valid of this record and keep it on the screen if it's OK, or get error message, after correct press ENTER again the valid again and keep it on the screen)
3) delete some listed records (press delete item button below table control to delete selected record, then refresh the table control list again)
Then press a UPDATE button to make save/update/delete the database table
How can I do it? Is there is example code?
Thank in Advance
2007 Jan 13 2:24 PM
why don't you use table maint.-generator (in tcode se11) for sm30
A.
2007 Jan 13 2:50 PM
hi i think u need a Module pool program which performs this , check this code it will surely help
Insert a new field CHK at the end of internal table.. of type , this marks the selected records in table control
CHK LIKE DEMO_CONN-MARK
define OK_Code which will capture SY-UCOMM and then in module pool program u can use the following code, if u want the whole thing I can paste it here
CASE OK_CODE.
WHEN 'DELETE'.
READ TABLE IT_ORD WITH KEY CHK = 'X'.
PERFORM RET_BLOCKED_AMOUNT.
<b>
DELETE IT_ORD WHERE CHK = 'X'.
DESCRIBE TABLE IT_ORD LINES TC1-LINES.
</b>
ELSE.
MESSAGE I000(ZZ) WITH 'PLEASE CHECK AN ORDER TO DELETE'.
ENDIF.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'LOGOFF'.
LEAVE PROGRAM.
<b> WHEN 'MODIFY'.
IF IT_ORD-CHK = 'X'.
MODIFY IT_ORD INDEX TC1-CURRENT_LINE.
ENDIF.
or if u are dealing with more than 1 record during editing then u can use
MODIFY IT_ORD WHERE CHK = 'X'.
</b>
ENDCASE.
CLEAR OK_CODE.
ENDMODULE. " USER_COMMAND_1000 INPUT
The above code will only modify the Internal table, u can now define a UPDATE button and then insert the following code
<b> WHEN 'UPDATE'.
MODIFY ZTAB FROM TABLE ITAB.
</b>
Here modify works in 2 ways
this statement modifies records already existing in ZTABLE if its already there otherwise it inserts a new record into it
For deleting multiple records just enable multiple records selection in Table Control properties
for inserting new records into the internal table u can make ur internal table into input mode enabled and then u can some button APPEND which will add records into it
award points if found helpful
2007 Jan 14 8:43 AM
Thanks Rahul,
So, I should created a internal table you describe than make a a table control with this internal table.
After I put select criteria fields, just populate this internal table from database table and list on the screen table. Just maintain data in the screen table and modify the internal table before updating (insert/change/delete) the datbase table.
But no matter the user press ENTER or not before press UPDATE( insert / change / delete), all data records on screen (or internal table) should be validated, if there is some error (article doesn't exist or articel type is invalid), there should be error message and user have to correct all errors before UPDATE can be committed actually.
I hope what I describe make you sense.
Thanks all