2005 Sep 13 5:23 PM
hai friends,
I am facing a problem regarding the modification of displayed record.
My requirement is i have to show records with checkbox option. now the records been printed with checkbox. now when i select the checkbox and click the modify button the the record should be modified in the database. now how can i catch the record in the do..endloop. where i have used 'read line sy-index field value chk'. plz suggest me some help regarding this.
2005 Sep 13 5:29 PM
READ LINE will work if the line index is that of the output, not your internal table. In your output, you might have started writing the records from line 4 onwards, which means READ LINE 4 will give you the first record of your internal table. Hope you understood the logic.
Srinivas
Hi Ateeq,
you can do something like
update zq_ord set aenam = sy-uname where vbeln = wa_itab-vbeln.
No : after set.
Kindly reward points if you find this as useful.If you need clarifications,kindly get back.
2005 Sep 13 5:29 PM
Hi,
If your check box is on first cloumn .
DO COUNT TIMES.
READ LINE SY-INDEX.
IF SY-LISEL(1) EQ 'X'.
CLEAR WA_ITAB.
READ TABLE ITAB INDEX SY_INDEX .
MODIFY DBTAB FROM ITAB.
ENDIF.
ENDDO.
Itab is internal table used to display . DBTAB is dataabse table. If check box is on some other column change SY-LISEL(1) accordingly .
Cheers
2005 Sep 13 5:29 PM
READ LINE will work if the line index is that of the output, not your internal table. In your output, you might have started writing the records from line 4 onwards, which means READ LINE 4 will give you the first record of your internal table. Hope you understood the logic.
Srinivas
2005 Sep 13 5:30 PM
2005 Sep 13 5:32 PM
Hi
You should know the link between the record of table and the line of output. Do you know it?
DATA: CHECK.
DO.
read line sy-index field value check.
if check = 'X'.
Here you should insert code to get out record index.
endif.
ENDDO.
A solution could be store the number of line while writing.
DATA: BEGIN OF ITAB OCCURS 0.
INCLUDE STRUCTURE <TABLE>.
DATA: LINE LIKE SY-LINNO,
END OF ITAB.
LOOP AT ITAB.
WRITE: / CHECK AS CHECKBOX,
ITAB.
ITAB-LINE = SY-LINNO.
MODIFY ITAB.
ENDLOOP.
So now:
DO.
read line sy-index field value check.
if sy-subrc <> 0. exit. endif.
if check = 'X'.
Here you should insert code to get out record index.
read table itab with key line = sy-index.
if sy-subrc = 0.
update <table> from itab.
endif.
endif.
ENDDO.
Max
2005 Sep 13 6:25 PM
hi bianchi,
i had followed as u had written. u had written something as
update <table> from itab.
but the itab is having different structure i.e., line is added in the itab. so it had gone into the dump. can u suggest how to rectify this.
2005 Sep 13 6:32 PM
Hi Ateeq
If you have a dump, you use a work area as you database table.
DATA: WA TYPE <DATABASE>.
MOVE-CORRESPONDING ITAB TO WA.
UPDATE <TABLE> FROM WA.
IF the names of fields of internal table are not called like fields names of dictionary table, you should do a MOVE for ech field:
MOVE ITAB-FIELD1 TO WA-FIELD1,
...........
UPDATE <TABLE> FROM WA.
Depend on you have declareted your internal table
Max
Message was edited by: max bianchi
2005 Sep 13 7:04 PM
hi bianchi,
in my itab there are 4 records... but when i am checking it in do..enddo it is showing sy-index due to this it is not updating the record.
do.
read line sy-index field value chk
if sy-subrc ne 0.
exit.
endif.
if chk = 'X' .
read table itab into wa_itab with key line = sy-index.
update zq_ord set: aenam = sy-uname
where vbeln = wa_itab-vbeln.
endif.
enddo.
2005 Sep 13 9:54 PM
Hi Ateeq
If you use UPDATE, you have to be sure the record is in your database.
So if the statament "update zq_ord set: aenam = sy-uname
where vbeln = wa_itab-vbeln" fails, it means there isn't a record where vbeln = wa_itab-vbeln
Max
2005 Sep 16 6:41 AM
Hi Ateeq,
you can do something like
update zq_ord set aenam = sy-uname where vbeln = wa_itab-vbeln.
No : after set.
Kindly reward points if you find this as useful.If you need clarifications,kindly get back.
2005 Sep 13 6:29 PM
Hi,
You need to define a work area similar to your database table. Populate the key fields nad otehr fields which you want to update from ITab. Then use
data wa like <DBTAB>.
Move itab-field1 to wa-field1.
....
....
update <dbtab> from wa.
Cheers
2005 Sep 13 6:56 PM
Hi Ateeq,
Define your internal table as similar to that of the database table. Have another internal table that has the key fields of the database table and two additional fields, one for line number and another for page number.
So the tables are as follows
DATA: BEGIN OF db_itab OCCURS 0.
INCLUDE STRUTURE <your db table name here>.
DATA: END OF db_itab.
DATA: BEGIN OF itab_out OCCURS 0,
key1 LIKE <your db table key field 1>
key2 LIKE <your db table key field 2>
.... as many fields as the key fields of your db tab
linno like sy-linno,
pagno like sy-pagno.
DATA: END OF itab_out.
Now when you are writing the output, you will fill the itab_out as follows.
LOOP AT db_itab.
WRITE:/ v_check as checkbox,
db_itab-key1,
db_itab-key2,
..... whatever db_itab-field
MOVE-CORRESPONDING db_itab to itab_out.
MOVE: sy-linno TO itab_out-linno,
sy-pagno TO itab_out-pagno.
APPEND itab_out.
ENDLOOP.Now after the button modify is pressed, you will need to do the following
LOOP AT db_itab.
CLEAR itab_out.
READ TABLE itab_out WITH KEY key1= db_itab-key1
key2 = db_itab-key2.
CHECK sy-subrc = 0.
READ LINE itab_out-linno OF PAGE itab_out-pagno.
CHECK sy-subrc = 0.
IF sy-lisel+0(1) <> 'X'.
*-- box not checked
DELETE db_itab.
ENDIF.
*--your position where you wrote the checkbox, in my
* case I wrote it at 1st position. So my offset will be
* 0(1).
ENDLOOP.After this loop you will have only the records that the user checked for modification. So use the following statement to update the database table now.
MODIFY <your db table> FROM TABLE db_itab.
If this helps, please close the post.
Srinivas
2005 Sep 14 7:52 AM
You can also use "MODIFY" command. It will act as update if record exist else it will craete a new record.
Cheers
2005 Sep 16 4:16 AM
Did the answers help you? Can you please close the post if resolved?
Thanks,
Srinivas
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |