2008 Jul 23 7:25 PM
Hi All,
I had a requirement to edit blockked ALV and Im successfull in making it so...But, I need to capture those edited values back to program...please help in this regards..
Thanking in advance
It is possible. But if you have many List then it will loop many times..My suggestion is look for another alternative.
Just check it.i did it with the help of END_OF_LIST.
in END OF LIST you need to loop the list and modify the contents. it is some what performance issue.
REPORT ZTEST_ENABLE_DISABLE.
TYPE-POOLS: SLIS.
INCLUDE <ICON>.
*- Fieldcatalog
DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
IT_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV..
DATA: X_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
X_FIELDCAT1 TYPE SLIS_FIELDCAT_ALV.
DATA: IT_EVENTS TYPE SLIS_T_EVENT,
X_EVENTS TYPE SLIS_ALV_EVENT.
X_EVENTS-NAME = 'END_OF_LIST'.
X_EVENTS-FORM = 'LIST_MODIFY_OUPUT'.
APPEND X_EVENTS TO IT_EVENTS.
DATA: BEGIN OF IT_VBAP OCCURS 0,
VBELN LIKE VBAP-VBELN,
POSNR LIKE VBAP-POSNR,
FLAG(1),
END OF IT_VBAP.
SELECT VBELN
POSNR
UP TO 10 ROWS
INTO TABLE IT_VBAP
FROM VBAP.
LOOP AT IT_VBAP.
IF SY-TABIX = 1 OR SY-TABIX = 5.
IT_VBAP-FLAG = 'X'.
MODIFY IT_VBAP INDEX SY-TABIX.
ENDIF.
ENDLOOP.
DATA:L_POS TYPE I VALUE 1.
CLEAR: L_POS.
L_POS = L_POS + 1.
X_FIELDCAT-SELTEXT_M = 'VBELN'.
X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-TABNAME = 'IT_VBAP'.
X_FIELDCAT-INPUT = 'X'.
X_FIELDCAT-EDIT = 'X'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-OUTPUTLEN = '10'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-SELTEXT_M = 'POSNR'.
X_FIELDCAT-FIELDNAME = 'POSNR'.
X_FIELDCAT-INPUT = 'X'.
X_FIELDCAT-EDIT = 'X'.
X_FIELDCAT-TABNAME = 'IT_VBAP'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-OUTPUTLEN = '5'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT = IT_FIELDCAT
IT_EVENTS = IT_EVENTS
TABLES
T_OUTTAB = IT_VBAP
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*&--------------------------------------------------------------------*
*& Form LIST_MODIFY_OUPUT
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
<b>FORM LIST_MODIFY_OUPUT.
DATA: L_VBELN LIKE VBAK-VBELN,
L_POSNR LIKE VBAP-POSNR,
L_INDEX TYPE SY-INDEX.
CLEAR IT_VBAP.
DO 20 TIMES.
CLEAR: L_VBELN, L_POSNR.
READ LINE SY-INDEX INDEX SY-LSIND
FIELD VALUE IT_VBAP-VBELN INTO L_VBELN
IT_VBAP-POSNR INTO L_POSNR .
"3lines are reserved for alv headings , so i am reading it form 4th line
"so 4th line is equal to 1st line of itab
IF SY-SUBRC = 0 AND SY-INDEX GE 4.
L_INDEX = SY-INDEX - 3.
READ TABLE IT_VBAP INDEX L_INDEX.
IF SY-SUBRC = 0 AND IT_VBAP-FLAG = 'X'.
*-Modifying current list
MODIFY LINE SY-INDEX INDEX SY-LSIND
FIELD FORMAT IT_VBAP-POSNR INPUT OFF.
MODIFY LINE SY-INDEX INDEX SY-LSIND
FIELD FORMAT IT_VBAP-VBELN INPUT OFF.
ENDIF.
ENDIF.
ENDDO.
ENDFORM. "LIST_MODIFY_OUPUT
2008 Jul 23 7:28 PM
2008 Jul 23 7:36 PM
Hi,
Within your program declare an event handler method for event data_changed of class cl_gui_alv_grid (importing er_data_changed). In the event handler method include logic similar to this:
* Process the changed rows
LOOP AT er_data_changed->mt_mod_cells ASSIGNING <fs_mod_cells>.
* Read the ALV row that was changed
READ TABLE me->it_alv ASSIGNING <fs_alv> INDEX <fs_mod_cells>-row_id.
CHECK sy-subrc = 0.
* Get the changed value
er_data_changed->get_cell_value( EXPORTING i_row_id = <fs_mod_cells>-row_id
i_fieldname = <fs_mod_cells>-fieldname
IMPORTING e_value = wa_value ).
* NOTE: wa_value contains the changed value (the value entered by the user in the ALV)
...
* Update the ALV itab with the new values
CASE <fs_mod_cells>-fieldname.
WHEN 'YOUR_FIELD'. "enter your field name(s)
<fs_alv>-your_field = wa_value.
...
ENDCASE.
...
ENDLOOP.
The me->it_alv is the internal table containing the ALV output. Field-symbol <fs_alv> should be defined with the same type as it_alv.
Regards,
Jamie
2008 Jul 23 7:37 PM
Check Form user_command in the below code
*&---------------------------------------------------------------------*
*& Report ZJAY_EDIT_ALV
*&
*&---------------------------------------------------------------------*
REPORT zjay_edit_alv.
*******************************************************************
* 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 DEFAULT 'MARA',
lines(5) TYPE n DEFAULT 7.
*******************************************************************
* 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 'ZSTANDARD'. "copy it from SALV func group 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 = sy-repid
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
2008 Jul 23 8:04 PM
It is possible. But if you have many List then it will loop many times..My suggestion is look for another alternative.
Just check it.i did it with the help of END_OF_LIST.
in END OF LIST you need to loop the list and modify the contents. it is some what performance issue.
REPORT ZTEST_ENABLE_DISABLE.
TYPE-POOLS: SLIS.
INCLUDE <ICON>.
*- Fieldcatalog
DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
IT_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV..
DATA: X_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
X_FIELDCAT1 TYPE SLIS_FIELDCAT_ALV.
DATA: IT_EVENTS TYPE SLIS_T_EVENT,
X_EVENTS TYPE SLIS_ALV_EVENT.
X_EVENTS-NAME = 'END_OF_LIST'.
X_EVENTS-FORM = 'LIST_MODIFY_OUPUT'.
APPEND X_EVENTS TO IT_EVENTS.
DATA: BEGIN OF IT_VBAP OCCURS 0,
VBELN LIKE VBAP-VBELN,
POSNR LIKE VBAP-POSNR,
FLAG(1),
END OF IT_VBAP.
SELECT VBELN
POSNR
UP TO 10 ROWS
INTO TABLE IT_VBAP
FROM VBAP.
LOOP AT IT_VBAP.
IF SY-TABIX = 1 OR SY-TABIX = 5.
IT_VBAP-FLAG = 'X'.
MODIFY IT_VBAP INDEX SY-TABIX.
ENDIF.
ENDLOOP.
DATA:L_POS TYPE I VALUE 1.
CLEAR: L_POS.
L_POS = L_POS + 1.
X_FIELDCAT-SELTEXT_M = 'VBELN'.
X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-TABNAME = 'IT_VBAP'.
X_FIELDCAT-INPUT = 'X'.
X_FIELDCAT-EDIT = 'X'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-OUTPUTLEN = '10'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-SELTEXT_M = 'POSNR'.
X_FIELDCAT-FIELDNAME = 'POSNR'.
X_FIELDCAT-INPUT = 'X'.
X_FIELDCAT-EDIT = 'X'.
X_FIELDCAT-TABNAME = 'IT_VBAP'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-OUTPUTLEN = '5'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT = IT_FIELDCAT
IT_EVENTS = IT_EVENTS
TABLES
T_OUTTAB = IT_VBAP
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*&--------------------------------------------------------------------*
*& Form LIST_MODIFY_OUPUT
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
<b>FORM LIST_MODIFY_OUPUT.
DATA: L_VBELN LIKE VBAK-VBELN,
L_POSNR LIKE VBAP-POSNR,
L_INDEX TYPE SY-INDEX.
CLEAR IT_VBAP.
DO 20 TIMES.
CLEAR: L_VBELN, L_POSNR.
READ LINE SY-INDEX INDEX SY-LSIND
FIELD VALUE IT_VBAP-VBELN INTO L_VBELN
IT_VBAP-POSNR INTO L_POSNR .
"3lines are reserved for alv headings , so i am reading it form 4th line
"so 4th line is equal to 1st line of itab
IF SY-SUBRC = 0 AND SY-INDEX GE 4.
L_INDEX = SY-INDEX - 3.
READ TABLE IT_VBAP INDEX L_INDEX.
IF SY-SUBRC = 0 AND IT_VBAP-FLAG = 'X'.
*-Modifying current list
MODIFY LINE SY-INDEX INDEX SY-LSIND
FIELD FORMAT IT_VBAP-POSNR INPUT OFF.
MODIFY LINE SY-INDEX INDEX SY-LSIND
FIELD FORMAT IT_VBAP-VBELN INPUT OFF.
ENDIF.
ENDIF.
ENDDO.
ENDFORM. "LIST_MODIFY_OUPUT
2008 Jul 24 4:15 AM
2008 Jul 24 1:26 PM
Hi,
I have to admit I hadn't really heard of "blocked ALV" before, so I searched online to find out what you meant. I got several Google (and SDN forum) hits, and based on those I assume you mean that you are using function module 'REUSE_ALV_BLOCK_LIST_DISPLAY' and its related f.m.'s.
Not having used these function modules before, I checked them out in SE37. Be aware that the documentation for all of these "blocked ALV" f.m.'s (in ECC 5.0 with language English) states the following:
"This function module has not been released. Do not use it."
Of course, we all know that just because a certain function module has not been "officially" released by SAP this doesn't mean we can never use it in our own programs. I completely understand that there are many "non-released" SAP function modules that are commonly used by customers. However, not many of these f.m.'s actually state explicitly in the documentation "Do not use it."
I would advise anyone out there to proceed with caution if you are using the "blocked ALV" f.m.'s. Or even better, just follow SAP's advice and don't use them at all. If you need multiple lists on a single screen this can be achieved by adding multiple ALV control containers to the screen and using those to hold your list blocks. The result will be a nicer looking (IMHO) and more friendly output for the users as well.
I'd be curious to know how many developers are using "blocked ALV's." I prefer the ALV Object model myself (or at least CL_GUI_ALV_GRID), but that is for another discussion...
Regards,
Jamie
2008 Jul 26 8:48 AM
Hi James,
Thanks for the reply. Does it mean that its not possible to capture the values from a blokked ALV....
Thanks,
Sundeep.
2008 Jul 28 3:01 PM
Hi,
I like to think that anything is possible with ABAP.
You should strongly consider using a different ALV technique unless your requirement specifically states that you must use only a blocked ALV (against SAP's "Do not use!" advice). You can get a better result with ALV controls (multiple ALV's within a single screen) or ALV Object Model. These will provide you with easier, more modern techniques for handling the data transfer.
However, since you seem to be stuck with using blocked ALV, I decided to do a where-used on some of the function modules. I could not find any specific examples where SAP is using editable blocked ALV's, but in program BALVBT01 the blocked ALV's contain check boxes which are handled during user input (after the refresh function for example). Maybe you can spend some time debugging that program to see how the interaction is occurring between the blocked ALV's and the ABAP.
Sorry that there does not seem to be an easy answer for this one, but that is just one more reason we should all use the most up-to-date ALV technology in our new developments.
Good luck!
Best Regards,
Jamie
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |