2011 Dec 19 11:03 AM
Hi Apabers
1)I have a selection screen with Original Delivery and Consignment Delivery.
2)grid output with vbeln,refvbeln and quantity. where quantity is the editable field.
3)when the user change the quantity the changed data should save in such a way that i should not change the old records but have to insert new records with changed data in this manner selection-screen Consignment Delivery as vbeln, grid output vbeln as refvbeln and changed quantity.
i am stuck to save the changed data.
hope for the help.
Thanks & regards.
Hi Apabers
1)I have a selection screen with Original Delivery and Consignment Delivery.
2)grid output with vbeln,refvbeln and quantity. where quantity is the editable field.
3)when the user change the quantity the changed data should save in such a way that i should not change the old records but have to insert new records with changed data in this manner selection-screen Consignment Delivery as vbeln, grid output vbeln as refvbeln and changed quantity.
i am stuck to save the changed data.
hope for the help.
Thanks & regards.
2011 Dec 19 11:17 AM
Hi,
Refer this below link
http://wiki.sdn.sap.com/wiki/display/Snippets/ALV-Editingandsavingtheeditedvaluesin+Database(OOPS)
or take this sample program and make changes in your programe accordingly.
REPORT z_demo_alv_jg.*******************************************************************
TYPE-POOLS *
*******************************************************************
TYPE-POOLS: slis. *******************************************************************
INTERNAL TABLES/WORK AREAS/VARIABLES *
*******************************************************************
DATA: i_fieldcat TYPE slis_t_fieldcat_alv,
i_index TYPE STANDARD TABLE OF i WITH HEADER LINE,
w_field TYPE slis_fieldcat_alv,
p_table LIKE dd02l-tabname,
dy_table TYPE REF TO data,
dy_tab TYPE REF TO data,
dy_line TYPE REF TO data.*******************************************************************
FIELD-SYMBOLS *
*******************************************************************
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
<dyn_wa> TYPE ANY,
<dyn_field> TYPE ANY,
<dyn_tab_temp> TYPE STANDARD TABLE.*******************************************************************
SELECTION SCREEN *
*******************************************************************
PARAMETERS: tabname(30) TYPE c,
lines(5) TYPE n.*******************************************************************
START-OF-SELECTION *
*******************************************************************
START-OF-SELECTION.* Storing table name
p_table = tabname.* Create internal table dynamically with the stucture of table name
entered in the selection screen
CREATE DATA dy_table TYPE STANDARD TABLE OF (p_table).
ASSIGN dy_table->* TO <dyn_table>.
IF sy-subrc <> 0.
MESSAGE i000(z_zzz_ca_messages) WITH ' No table found'. LEAVE TO LIST-PROCESSING.
ENDIF.
Create workarea for the table
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.* Create another temp. table
CREATE DATA dy_tab TYPE STANDARD TABLE OF (p_table).
ASSIGN dy_tab->* TO <dyn_tab_temp>. SORT i_fieldcat BY col_pos.* Select data from table
SELECT * FROM (p_table)
INTO TABLE <dyn_table>
UP TO lines ROWS. REFRESH <dyn_tab_temp>.* Display report
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_structure_name = p_table
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'SET_PF_STATUS'
TABLES
t_outtab = <dyn_table>
EXCEPTIONS
program_error = 1
OTHERS = 2. IF sy-subrc <> 0. ENDIF.&----
*& Form SET_PF_STATUS
&----
Setting custom PF-Status
----
-->RT_EXTAB Excluding table
----
FORM set_pf_status USING rt_extab TYPE slis_t_extab. SET PF-STATUS 'Z_STANDARD'.ENDFORM. "SET_PF_STATUS&----
*& Form user_command
&----
Handling custom function codes
----
-->R_UCOMM Function code value
-->RS_SELFIELD Info. of cursor position in ALV
----
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.* Local data declaration
DATA: li_tab TYPE REF TO data,
l_line TYPE REF TO data.* Local field-symbols
FIELD-SYMBOLS:<l_tab> TYPE table,
<l_wa> TYPE ANY.* Create table
CREATE DATA li_tab TYPE STANDARD TABLE OF (p_table).
ASSIGN li_tab->* TO <l_tab>.* Create workarea
CREATE DATA l_line LIKE LINE OF <l_tab>.
ASSIGN l_line->* TO <l_wa>. CASE r_ucomm.* When a record is selected
WHEN '&IC1'.* Read the selected record
READ TABLE <dyn_table> ASSIGNING <dyn_wa> INDEX
rs_selfield-tabindex. IF sy-subrc = 0.* Store the record in an internal table
APPEND <dyn_wa> TO <l_tab>.* Fetch the field catalog info
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = 'Z_DEMO_PDF_JG'
i_structure_name = p_table
CHANGING
ct_fieldcat = i_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc = 0.* Make all the fields input enabled except key fields
w_field-input = 'X'. MODIFY i_fieldcat FROM w_field TRANSPORTING input
WHERE key IS INITIAL. ENDIF.* Display the record for editing purpose
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_structure_name = p_table
it_fieldcat = i_fieldcat
i_screen_start_column = 10
i_screen_start_line = 15
i_screen_end_column = 200
i_screen_end_line = 20
TABLES
t_outtab = <l_tab>
EXCEPTIONS
program_error = 1
OTHERS = 2. IF sy-subrc = 0.* Read the modified data
READ TABLE <l_tab> INDEX 1 INTO <l_wa>.* If the record is changed then track its index no.
and populate it in an internal table for future
action
IF sy-subrc = 0 AND <dyn_wa> <> <l_wa>.
<dyn_wa> = <l_wa>.
i_index = rs_selfield-tabindex.
APPEND i_index.
ENDIF.
ENDIF. ENDIF.* When save button is pressed
WHEN 'SAVE'.* Sort the index table
SORT i_index.* Delete all duplicate records
DELETE ADJACENT DUPLICATES FROM i_index. LOOP AT i_index.* Find out the changes in the internal table
and populate these changes in another internal table
READ TABLE <dyn_table> ASSIGNING <dyn_wa> INDEX i_index.
IF sy-subrc = 0.
APPEND <dyn_wa> TO <dyn_tab_temp>.
ENDIF. ENDLOOP.* Lock the table
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
mode_rstable = 'E'
tabname = p_table
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3. IF sy-subrc = 0.* Modify the database table with these changes
MODIFY (p_table) FROM TABLE <dyn_tab_temp>. REFRESH <dyn_tab_temp>.* Unlock the table
CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
mode_rstable = 'E'
tabname = p_table. ENDIF.
ENDCASE. rs_selfield-refresh = 'X'.ENDFORM. "user_command
Regards,
Sanjay Gogikar
2011 Dec 19 11:30 AM
Hi,
Thanku for quick reply.
Hope u have read my requirement..
i am using REUSE_ALV_GRID_DISPLAY.
Thanks & regards.
2011 Dec 19 12:55 PM
Copy data to another internal table before displaying the report.
i_copy[] = i_output[] .
Write the following code in User Command subroutine.
Step1: Create a reference variable to hold the instance of the ALV grid control.
This instance is defined with reference to class CL_GUI_ALV_GRID
DATA: ref1 TYPE REF TO cl_gui_alv_grid.
Step2: Instantiate the ALV grid control to the above created variable.
Call 'GET_GLOBALS_FROM_SLVC_FULLSCR' function module to do this.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref1.
Step3: Check the changed data from the selected entries
CALL METHOD ref1->check_changed_data.
Step4:
Now loop into display table and read copied data.
For those records where quantity is not matching store them as a new record in the table.
LOOP AT i_output INTO wa_output.
READ TABLE i_copy INTO wa_copy
WITH KEY vbeln = wa_output-vbeln
refvbeln = wa_output-refvbeln.
if sy-subrc = 0
AND wa_copy-quantity <> wa_output-quantity.
*--- Append wa_output to another table or i_output/i_copy
ENDIF.
ENDLOOP.
2011 Dec 20 5:43 AM
Hi,
am not able to fetch the data, here is my code..can u please help me...
----
Displaying Grid Output
----
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = LT_FIELDCAT
I_DEFAULT = 'X'
I_SAVE = 'A'
TABLES
T_OUTTAB = LT_FINAL.
CLEAR :WA_LAYOUT,WA_FIELDCAT.
FREE : LT_FIELDCAT,LT_FINAL.
&----
*& Form BUILD_FIELDCAT
&----
FORM BUILD_FIELDCAT .
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY-CPROG
I_STRUCTURE_NAME = 'ZPDMTISSUES'
CHANGING
CT_FIELDCAT = LT_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
LOOP AT LT_FIELDCAT ASSIGNING <FS_FIELDCAT>.
IF <FS_FIELDCAT>-FIELDNAME EQ 'MENGE'.
<FS_FIELDCAT>-EDIT = 'X'.
ENDIF.
ENDLOOP.
CLEAR : WA_LAYOUT, WA_COMMON_GRID_SETTINGS.
WA_LAYOUT-ZEBRA = 'X'.
WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
WA_COMMON_GRID_SETTINGS-EDT_CLL_CB = 'X'.
ENDFORM. " BUILD_FIELDCAT
----
*& Form SET_PF_STATUS
----
FORM SET_PF_STATUS USING EXCLUDETAB TYPE SLIS_T_EXTAB. "#EC CALLED
SET PF-STATUS 'ZPDMTCONSIGN'.
ENDFORM. "SET_PF_STATUS
&----
*& Form USER_COMMAND *
&----
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM L_SELFIELD TYPE SLIS_SELFIELD."#EC CALLED "#EC *
When user clicks on '&DATA_SAVE' button
IF SY-UCOMM = '&DATA_SAVE'.
CALL FUNCTION 'POPUP_TO_CONFIRM' "#EC *
EXPORTING
TITLEBAR = TEXT-003
TEXT_QUESTION = TEXT-004
TEXT_BUTTON_1 = 'Yes'
TEXT_BUTTON_2 = 'No'
DEFAULT_BUTTON = '1'
IMPORTING
ANSWER = L_ANSWER
EXCEPTIONS
TEXT_NOT_FOUND = 1
OTHERS = 2.
ENDIF.
*If User Want To Save Changes
IF L_ANSWER = '1'.
CLEAR : WA_FINAL.
*Deleting Empty Records From LT_FINAL
DELETE LT_FINAL WHERE MENGE IS INITIAL.
*IF User Clicks On Save Without Making Changes
IF LT_FINAL = ZPDMTISSUES.
MESSAGE S000(ZZ) WITH TEXT-006.
EXIT.
ELSE.
*To Create Or Change A Record
UPDATE ZPDMTISSUES FROM TABLE LT_FINAL.
COMMIT WORK AND WAIT.
CLEAR : LT_FINAL.
L_SELFIELD-REFRESH = 'X'.
REFRESH : LT_FINAL.
*IF User Clicks On Save After Making Changes
LOOP AT LT_FINAL.
READ TABLE LT_FINAL WITH KEY ID = LT_FINAL-ID.
IF SY-SUBRC = 0.
IF LT_FINAL <> ZPDMTISSUES.
*Records Changed
L_RECORDSCHANGED = L_RECORDSCHANGED + 1.
ENDIF.
ELSE.
*Records Deleted
L_RECORDSDELETED = L_RECORDSDELETED + 1.
ENDIF.
CLEAR : LT_FINAL.
ENDLOOP.
*To Display Number Of Records Created Or Changed Or Deleted
IF L_RECORDSCHANGED IS NOT INITIAL.
CONCATENATE L_RECORDSCHANGED TEXT-007 INTO L_TEXT2 SEPARATED BY SPACE.
ENDIF.
IF L_RECORDSDELETED IS NOT INITIAL.
CONCATENATE L_RECORDSDELETED TEXT-008 INTO L_TEXT3 SEPARATED BY SPACE.
ENDIF.
DATA : REF_GRID TYPE REF TO CL_GUI_ALV_GRID. "new
IF REF_GRID IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF_GRID.
ENDIF.
IF NOT REF_GRID IS INITIAL.
CALL METHOD REF_GRID->CHECK_CHANGED_DATA.
ENDIF.
APPEND LINES OF LT_FINAL TO LT_COPY.
LOOP AT LT_FINAL INTO WA_FINAL.
READ TABLE LT_COPY INTO WA_COPY
WITH KEY VBELN = P_RVBELN
REFVBELN = P_VBELN.
IF SY-SUBRC = 0
AND WA_COPY-MENGE <> WA_FINAL-MENGE.
APPEND WA_FINAL TO LT_FINAL.
ENDIF.
CLEAR : LT_FINAL.
ENDLOOP.
ENDIF.
ENDIF.
ENDFORM. "USER_COMMAND
Thanks & regards.
2011 Dec 20 10:00 AM
Hi anusha,
Please check it in debug mode , in debug mode check whether internal table is filled or not , if it is empty check your data fetching logic and check field cat also once,
Regards
Siva
2011 Dec 19 1:19 PM
Hi
1. Before displaying the data to output. Copy the data into temp internal table for referance.(ex: t_out_tmp)
2. In grid setting ALV set the option EDT_CLL_CB = 'X'.
3. In user command perform of ALV once save is performed do following operation.
IF sy-ucomm = 'SAVE'.
Loop at t_out into wa_out.
read table t_out_tmp into wa_tmp with key vbeln = wa_out-vbeln.
if sy-subrc = 0.
*---it is not new record,in this case check remaining editable fields changes.
if wa_out_tmp-qty <> wa_out-qty.
*--Update the data.
endif.
else.
*---it is now new record,for this case create the record
endif.
endloop.
endif.
Regards,
raghu.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |