06-28-2007 12:39 PM
Hi
I have created a custom t-code for table maintenance of a custom table. This table has a count field which needs to be auto generated during the maintenance (each time a new record is added, the counter is incremented as per the key field value)
Hence I am modifying the PAI of the overview screen to generate the counter value. I have been able to copy the "extract" table into an internal table and modify the count field. But I do not know how to put back these changes to the "extract" table. Any help in this regard would be really helpful.
Below is the module code:
MODULE modify_count INPUT.
TYPES:
BEGIN OF t_gtin,
zzisgtin TYPE zgtinaudit-zzisgtin,
END OF t_gtin,
BEGIN OF t_count,
zzisgtin TYPE zgtinaudit-zzisgtin,
zzcount TYPE zgtinaudit-zzcount,
END OF t_count.
DATA:
primtab_mod TYPE REF TO data ,
i_zgtinaudit TYPE zgtinaudit OCCURS 0,
i_gtin TYPE TABLE OF t_gtin ,
i_count TYPE TABLE OF t_count ,
wa_zgtinaudit TYPE zgtinaudit ,
wa_gtin TYPE t_gtin ,
wa_count TYPE t_count ,
v_zzcount TYPE zgtinaudit-zzcount ,
v_okcode TYPE sy-ucomm ,
v_idx TYPE i.
FIELD-SYMBOLS:
<table_entries> TYPE STANDARD TABLE.
v_okcode = sy-ucomm.
CHECK v_okcode EQ 'SAVE'.
CREATE DATA primtab_mod TYPE TABLE OF (x_header-maintview).
ASSIGN: primtab_mod->* TO <table_entries>.
Move the data in the table control to <table_entries>
LOOP AT extract.
APPEND <vim_extract_struc> TO <table_entries>.
ENDLOOP.
MOVE <table_entries>[] TO i_zgtinaudit[].
SORT i_zgtinaudit BY zzisgtin DESCENDING.
Store the key field (GTIN) values
LOOP AT i_zgtinaudit INTO wa_zgtinaudit.
wa_gtin-zzisgtin = wa_zgtinaudit-zzisgtin.
APPEND wa_gtin TO i_gtin.
ENDLOOP.
SORT i_gtin BY zzisgtin.
DELETE ADJACENT DUPLICATES FROM i_gtin.
Select existing data from the table for the GTINs
SELECT zzisgtin
zzcount
FROM zgtinaudit
INTO TABLE i_count
FOR ALL ENTRIES IN i_gtin
WHERE zzisgtin EQ i_gtin-zzisgtin.
IF sy-subrc EQ 0.
SORT i_count BY zzisgtin zzcount DESCENDING.
ENDIF.
Generate the counter
LOOP AT i_zgtinaudit INTO wa_zgtinaudit.
v_idx = sy-tabix.
IF NOT wa_zgtinaudit-zzisgtin IS INITIAL.
AT NEW zzisgtin.
CLEAR:
wa_count,
v_zzcount.
READ TABLE i_count INTO wa_count
WITH KEY zzisgtin = wa_zgtinaudit-zzisgtin.
IF sy-subrc EQ 0.
v_zzcount = wa_count-zzcount.
ENDIF.
ENDAT.
v_zzcount = v_zzcount + 1.
IF wa_zgtinaudit-zzcount IS INITIAL.
wa_zgtinaudit-zzcount = v_zzcount.
ENDIF.
IF wa_zgtinaudit-zzisauditusrid IS INITIAL.
wa_zgtinaudit-zzisauditusrid = sy-uname.
ENDIF.
MODIFY i_zgtinaudit FROM wa_zgtinaudit INDEX v_idx.
ENDIF.
ENDLOOP.
REFRESH <table_entries>[].
MOVE i_zgtinaudit[] TO <table_entries>[].
ENDMODULE. " modify_count INPUT
06-29-2007 1:51 PM
Hi,
I think there is no need of dumping data into an internal table you can just read the maximum count value from the extract table as below.
READ max(zzcount) INTO wa_zzcount FROM extract.
and then assign it to table field value.
wa_zzcount = wa_zzcount + 1.
<table>-zzcount = wa_zzcount.
I haven't checked but i think it will work.
Reward points if usefull.
thanks,
Muthu.
06-30-2007 6:49 AM
Hi,
Use select max( field name (i.e,counter value) ) from database table into counter.
case 'ok_code'.
when 'funct. code.'
then increment the counter assing the incremented counter value to ITAB-fieldname.
if sy-subrc = 0.
modify itab index sy-tabix.
else
append itab
insert DBtable name from table itab.
refresh itab
endif.
endcase.
use this method it will work.
Reward if helpful
Regards
Raghavendra.D.S