Modifying database table through ALV-Grid
Hi all.
I need to modify a database table (ZNG_SO_HEAD) by entering data in ALV-Grid, which displays its internal table (exact copy of ZNG_SO_HEAD), and clicking the button ('CHANGE') on the ALV-toolbar. The ALV is already editable, the button already exists. Here is the code. After changing data in ALV and clicking 'CHANGE' on the toolbar the database table ZNG_SO_HEAD remains unchangeable, but i need to change data in it somehow.
Thanks all.
REPORT zng_alv_tc_edit_simp.
*-- GLOBAL DATA DECLARATIONS FOR ALV
DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.
DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV'.
DATA gr_ccontainer TYPE REF TO cl_gui_custom_container.
DATA gt_fieldcat TYPE lvc_t_fcat.
DATA gs_layout TYPE lvc_s_layo.
TABLES: zng_so_head, zng_cust, zng_vendors.
*-- STRUCTURE OF INTERNAL TABLE
TYPES: BEGIN OF in_tab,
mandt TYPE zng_so_head-mandt,
so_num TYPE zng_so_head-so_num, "type numc
vend_num TYPE zng_so_head-vend_num, "type numc
cust_num TYPE zng_so_head-cust_num, "type numc
so_date TYPE zng_so_head-so_date, "type dats
END OF in_tab.
*-- INTERNAL TABLE HOLDING LIST DATA
DATA res_tab TYPE TABLE OF in_tab WITH HEADER LINE.
*DATA wa_res_tab LIKE LINE OF res_tab.
*-- FILLING IN INTERNAL TABLE
SELECT h~mandt h~so_num h~vend_num h~cust_num h~so_date
INTO TABLE res_tab FROM zng_so_head AS h.
* CLASS lcl_event_handler DEFINITION
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
* to add new functional buttons to the alv toolbar
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object
e_interactive,
* to implement user commands
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS. "lcl_event_handler DEFINITION
* CLASS lcl_event_handler IMPLEMENTATION
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_toolbar.
DATA: ls_toolbar TYPE stb_button.
MOVE 3 TO ls_toolbar-butn_type.
CLEAR ls_toolbar.
MOVE 'CHANGE' TO ls_toolbar-function.
MOVE icon_change TO ls_toolbar-icon.
MOVE 'change' TO ls_toolbar-quickinfo.
MOVE 'change' TO ls_toolbar-text.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar>
METHOD handle_user_command.
DATA:l_valid TYPE c.
CASE e_ucomm.
WHEN 'CHANGE'.
CALL METHOD gr_alvgrid->check_changed_data
IMPORTING
e_valid = l_valid.
IF l_valid = 'X'.
MODIFY zng_so_head FROM res_tab.
ENDIF.
ENDCASE.
ENDMETHOD. "handle_user_command
ENDCLASS. "lcl_event_handler IMPLEMENTATION
DATA object_ref TYPE REF TO lcl_event_handler.
FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat.
>>>>>>done correctly>>>>>>>>>
FORM display_alv.
>>>>>>done correctly>>>>>>>>>
START-OF-SELECTION.
CALL SCREEN 100.
* MODULE STATUS_0100 OUTPUT
MODULE display_alv OUTPUT.
SET PF-STATUS 'SCREEN_100'.
PERFORM display_alv.
CREATE OBJECT object_ref.
SET HANDLER object_ref->handle_toolbar FOR gr_alvgrid.
SET HANDLER object_ref->handle_user_command FOR gr_alvgrid.
ENDMODULE. "display_alv OUTPUT
* MODULE USER_COMMAND_0100 INPUT
MODULE user_command_0100 INPUT.
IF sy-ucomm = 'BACK' OR
sy-ucomm = 'EXIT' OR
sy-ucomm = 'CANCEL'.
LEAVE PROGRAM.
ELSE.
CALL METHOD object_ref->handle_toolbar.
CALL METHOD object_ref->handle_user_command.
ENDIF.
ENDMODULE.
Hello Nikolai,
I have written a sample code taking care of all the requirements(button in the toolbar and changes saved in database).I have used SPFLI table and the internal table i_spfli.This code works and the change is also made in the database table.
REPORT SAMPLE.
*-- GLOBAL DATA DECLARATIONS FOR ALV
DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.
DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV'.
DATA gr_ccontainer TYPE REF TO cl_gui_custom_container.
DATA gt_fieldcat TYPE lvc_t_fcat.
DATA gs_layout TYPE lvc_s_layo.
Data:i_spfli type table of spfli.
CLASS lcl_event_handler DEFINITION
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
DATA:l_valid TYPE c.
DATA: ls_toolbar TYPE stb_button.
METHODS:
to add new functional buttons to the alv toolbar
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object
e_interactive,
to implement user commands
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS. "lcl_event_handler DEFINITION
CLASS lcl_event_handler IMPLEMENTATION
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_toolbar.
CLEAR ls_toolbar.
MOVE 0 TO ls_toolbar-butn_type.
MOVE 'CHANGE' TO ls_toolbar-function.
MOVE 'ICON_CHANGE' TO ls_toolbar-icon.
MOVE 'change' TO ls_toolbar-quickinfo.
MOVE 'change' TO ls_toolbar-text.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar>
METHOD handle_user_command.
CASE e_ucomm.
WHEN 'CHANGE'.
CALL METHOD gr_alvgrid->check_changed_data
IMPORTING
e_valid = l_valid.
IF l_valid = 'X'.
MODIFY spfli FROM table i_spfli.
ENDIF.
ENDCASE.
ENDMETHOD. "handle_user_command
ENDCLASS. "lcl_event_handler IMPLEMENTATION
START-OF-SELECTION.
DATA object_ref TYPE REF TO lcl_event_handler.
select * from spfli into table i_spfli.
Call screen 100.
MODULE STATUS_0100 OUTPUT
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'SCREEN_100'.
PERFORM display_alv.
ENDMODULE. "display_alv OUTPUT
MODULE USER_COMMAND_0100 INPUT
MODULE user_command_0100 INPUT.
IF sy-ucomm = 'BACK' OR
sy-ucomm = 'EXIT' OR
sy-ucomm = 'CANCEL'.
LEAVE PROGRAM.
ENDIF.
ENDMODULE.
*& Form display_alv
FORM display_alv.
*IF gr_alvgrid IS INITIAL.
CREATE OBJECT gr_ccontainer
EXPORTING container_name = gc_custom_control_name.
CREATE OBJECT gr_alvgrid
EXPORTING i_parent = gr_ccontainer.
PERFORM prepare_field_catalog CHANGING gt_fieldcat.
CREATE OBJECT object_ref.
SET HANDLER object_ref->handle_toolbar FOR gr_alvgrid.
SET HANDLER object_ref->handle_user_command FOR gr_alvgrid.
CALL METHOD gr_alvgrid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_outtab = i_spfli[]
it_fieldcatalog = gt_fieldcat.
ENDFORM. "display_alv
*& Form prepare_field_catalog
FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat.
DATA ls_fcat TYPE lvc_s_fcat.
ls_fcat-fieldname = 'CARRID'.
ls_fcat-ref_table = 'SPFLI'.
ls_fcat-edit = 'X'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'CONNID'.
ls_fcat-ref_table = 'SPFLI'.
ls_fcat-edit = 'X'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'DEPTIME'.
ls_fcat-ref_table = 'SPFLI'.
ls_fcat-edit = 'X'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'ARRTIME'.
ls_fcat-ref_table = 'SPFLI'.
ls_fcat-edit = 'X'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
endform.
Hope this helps.
Regards,
Beejal
Similar Messages
-
Modifying database table in ALV Grid
Hi all.
I need to be able to modify the database table in ALV Grid. Here's the code. The database table, that is displayed is 'zng_so_head', it's internal table is 'res_tab'. In the program i tried to create a button 'CHANGE' on the ALV-toolbar, but when executing the program there's no such button (why?). What code, screens, screen elements, etc. should be added to this program to provide a possibility of changing data of the database table 'zng_so_head' (i mean changing existing data, adding new lines and saving changes)?
CODE:
& Report ZNG_ALV_TC_EDIT_SIMP&
REPORT ZNG_ALV_TC_EDIT_SIMP.
*-- GLOBAL DATA DECLARATIONS FOR ALV
DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.
DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV'.
DATA gr_ccontainer TYPE REF TO cl_gui_custom_container.
DATA gt_fieldcat TYPE lvc_t_fcat.
DATA gs_layout TYPE lvc_s_layo.
TABLES: zng_so_head, zng_cust, zng_vendors.
*-- STRUCTURE OF INTERNAL TABLE
TYPES: BEGIN OF in_tab,
so_num TYPE zng_so_head-so_num, "type numc
vend_num TYPE zng_so_head-vend_num, "type numc
cust_num TYPE zng_so_head-cust_num, "type numc
so_date TYPE zng_so_head-so_date, "type dats
END OF in_tab.
*-- INTERNAL TABLE HOLDING LIST DATA
DATA res_tab TYPE TABLE OF in_tab WITH HEADER LINE.
*-- FILLING IN INTERNAL TABLE
SELECT hso_num hvend_num hcust_num hso_date
INTO TABLE res_tab FROM zng_so_head AS h.
*& Form prepare_field_catalog
FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat.
DATA ls_fcat TYPE lvc_s_fcat.
ls_fcat-fieldname = 'SO_NUM'.
ls_fcat-inttype = 'N'.
ls_fcat-ref_table = 'zng_so_head'.
ls_fcat-outputlen = '12'.
ls_fcat-coltext = 'SO_NUM'.
ls_fcat-seltext = 'SO_NUM'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'VEND_NUM'.
ls_fcat-inttype = 'N'.
ls_fcat-ref_table = 'zng_so_head'.
ls_fcat-outputlen = '12'.
ls_fcat-coltext = 'VEND_NUM'.
ls_fcat-seltext = 'VEND_NUM'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'CUST_NUM'.
ls_fcat-inttype = 'N'.
ls_fcat-ref_table = 'zng_so_head'.
ls_fcat-outputlen = '12'.
ls_fcat-coltext = 'CUST_NUM'.
ls_fcat-seltext = 'CUST_NUM'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'SO_DATE'.
ls_fcat-inttype = 'D'.
ls_fcat-ref_table = 'zng_so_head'.
ls_fcat-outputlen = '12'.
ls_fcat-coltext = 'SO_DATE'.
ls_fcat-seltext = 'SO_DATE'.
APPEND ls_fcat TO pt_fieldcat.
ENDFORM. "prepare_field_catalog
*& Form display_alv
FORM display_alv.
IF gr_alvgrid IS INITIAL.
CREATE OBJECT gr_ccontainer
EXPORTING container_name = gc_custom_control_name.
CREATE OBJECT gr_alvgrid
EXPORTING i_parent = gr_ccontainer.
PERFORM prepare_field_catalog CHANGING gt_fieldcat.
CALL METHOD gr_alvgrid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_outtab = res_tab[]
it_fieldcatalog = gt_fieldcat.
ELSE.
CALL METHOD gr_alvgrid->refresh_table_display.
ENDIF.
ENDFORM. "display_alv
CLASS lcl_event_handler DEFINITION
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object
e_interactive.
ENDCLASS. "lcl_event_handler DEFINITION
CLASS lcl_event_handler IMPLEMENTATION
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_toolbar.
DATA: ls_toolbar TYPE stb_button.
MOVE 3 TO ls_toolbar-butn_type.
APPEND ls_toolbar TO e_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE 'CHANGE' TO ls_toolbar-function.
MOVE icon_change TO ls_toolbar-icon.
MOVE 'change' TO ls_toolbar-quickinfo.
MOVE 'change' TO ls_toolbar-text.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar
ENDCLASS. "lcl_event_handler IMPLEMENTATION
DATA object_ref TYPE REF TO lcl_event_handler.
START-OF-SELECTION.
CALL SCREEN 100.
MODULE STATUS_0100 OUTPUT
MODULE display_alv OUTPUT.
SET PF-STATUS 'SCREEN_100'.
PERFORM display_alv.
CREATE OBJECT object_ref.
SET HANDLER object_ref->handle_toolbar FOR gr_alvgrid.
ENDMODULE. "display_alv OUTPUT
MODULE USER_COMMAND_0100 INPUT
MODULE user_command_0100 INPUT.
IF sy-ucomm = 'BACK' OR
sy-ucomm = 'EXIT' OR
sy-ucomm = 'CANCEL'.
LEAVE PROGRAM.
ELSE.
CALL METHOD object_ref->handle_toolbar.
ENDIF.
ENDMODULE. "status_0100 INPUT
END OF CODE
Thanks all.Hi,
For the button on the toolbar,here is the code:
CLASS lcl_eh IMPLEMENTATION.
*METHOD: HANDLE_TOOLBAR
*DESCRIPTION: This method provides the necessary detail required to
create an extra button in the toolbar.
METHOD handle_toolbar.
CLEAR ls_toolbar.
MOVE 'CHANGE' TO ls_toolbar-function.
MOVE 0 TO ls_toolbar-butn_type.
MOVE CHANGETO ls_toolbar-text.
MOVE 'ICON_DETAIL' TO ls_toolbar-icon.
MOVE 'CHANGE' TO ls_toolbar-quickinfo.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar
Also,if you are using the CHANGE button to record changes in the DB,then in the local class that you have defined,you should use the following method and then write the logic:
*METHOD: HANDLE_USER_COMMAND
METHOD handle_user_command.
CASE e_ucomm.
WHEN 'CHANGE'.
CHECK_CHANGED_DATA
REFRESH_TABLE_DISPLAY
Now call the methods that i have given in my previous post.This function code will be checked at the event you click the button 'CHANGE'.I think you have done this in an ELSE condition in the PAI of the screen.Not too sure if it works in the PAI.
Regards,
Beejal
**Reward if this helps -
Hi,
I am trying to use class CL_ALV_CHANGED_DATA_PROTOCOL to update a database table from an ALV grid.
I have used program BCALV_EDIT_04 as an example.
I am able to successfully processed inserted or deleted lines using the attributes
MT_DELETED_ROWS
MT_INSERTED_ROWS
but I also want to process modified lines.
I was just wondering whether anyone out there has some example code for this.
I can see that there are the following attributes available
MT_MOD_CELLS
MP_MOD_ROWS.
I would ideally like to use MP_MOD_ROWS rather than MT_MOD_CELLS but it is not clear to me what type MP_MOD_ROWS is.
If anyone has any example code for this sort of thing, please let me know.
Thanks,
Rubyhi Ruby,
Yes we can use that *data reference variable *.
It is a variable( something comparable to a pointer ) that points to a int table( table with changed contents )
which ll be created at run-time based on the data type ot the internal table that we pass to the parameter it_outtab of method set_table_for_first_display ...
assign er_data_changed->mp_mod_rows->* to a field-symbol and use it...
Check the below code for example -> method refresh_changed_data
screen flow logic.
PROCESS BEFORE OUTPUT.
MODULE pbo.
PROCESS AFTER INPUT.
MODULE pai.
main program.
* CLASS lcl_event_responder DEFINITION *
CLASS lcl_event_responder DEFINITION.
PUBLIC SECTION.
DATA : ls_changed_cell TYPE lvc_s_modi,
lv_language TYPE spras..
METHODS refresh_changed_data FOR EVENT data_changed
OF cl_gui_alv_grid
IMPORTING er_data_changed
e_ucomm.
ENDCLASS. "event_responder DEFINITION
TYPES tt_makt TYPE STANDARD TABLE OF makt.
DATA: go_handler TYPE REF TO lcl_event_responder,
go_grid TYPE REF TO cl_gui_alv_grid,
gt_fieldcat TYPE lvc_t_fcat,
gv_language TYPE spras VALUE 'E',
gt_outtab TYPE tt_makt,
gs_tableline TYPE LINE OF tt_makt.
FIELD-SYMBOLS : <changed_rows> TYPE tt_makt.
CALL SCREEN 100.
* MODULE PBO OUTPUT *
MODULE pbo OUTPUT.
SET PF-STATUS 'BASIC'.
PERFORM create_and_init_alv CHANGING gt_outtab[]
gt_fieldcat.
ENDMODULE. "pbo OUTPUT
* MODULE PAI INPUT *
MODULE pai INPUT.
LEAVE PROGRAM.
ENDMODULE. "pai INPUT
FORM create_and_init_alv CHANGING pt_outtab LIKE gt_outtab[]
pt_fieldcat TYPE lvc_t_fcat.
CHECK go_grid IS NOT BOUND.
CREATE OBJECT go_grid
EXPORTING
i_parent = cl_gui_container=>default_screen.
PERFORM build_display_table.
PERFORM build_fieldcat CHANGING pt_fieldcat.
go_grid->set_table_for_first_display( CHANGING it_fieldcatalog = pt_fieldcat
it_outtab = pt_outtab ).
go_grid->set_ready_for_input( 1 ).
* raises the 'data_changed' event when we select another cell/any action after changing the data
go_grid->register_edit_event( EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_enter ).
CREATE OBJECT go_handler.
SET HANDLER go_handler->refresh_changed_data FOR go_grid.
ENDFORM. "CREATE_AND_INIT_ALV
FORM build_display_table.
FREE gt_outtab.
SELECT * FROM makt UP TO 20 ROWS INTO TABLE gt_outtab WHERE spras EQ gv_language.
ENDFORM. "build_display_table
FORM build_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.
DATA ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'MAKT'
CHANGING
ct_fieldcat = pt_fieldcat.
LOOP AT pt_fieldcat INTO ls_fcat.
ls_fcat-edit = abap_true.
MODIFY pt_fieldcat FROM ls_fcat.
ENDLOOP.
ENDFORM. "build_fieldcat
* CLASS event_responder IMPLEMENTATION *
CLASS lcl_event_responder IMPLEMENTATION.
METHOD refresh_changed_data.
ASSIGN er_data_changed->mp_mod_rows->* TO <changed_rows>.
LOOP AT <changed_rows> INTO gs_tableline.
BREAK-POINT.
ENDLOOP.
ENDMETHOD. "click
ENDCLASS. "event_responder IMPLEMENTATION
Cheers,
Jose. -
Show dynamic table in ALV grid
Hi !
how do I show a dynamic table in ALV GRID ?
I used the following commands:
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fieldcat[]
importing
ep_table = gt_new_table.
assign gt_new_table->* to <l_table>.
create data gs_new_line like line of <l_table>.
assign gs_new_line->* to <l_line>.
I added records into the table
Now I got a dynamic table.
How do I show it in ALV GRID ?
thanks
AdiHi,
Check these links
Re: Dynamic table
http://sap.ittoolbox.com/code/d.asp?a=s&d=3038
http://www.sap4.com/codigo-138.html
http://www.sapassist.com/code/d.asp?a=s&d=3365
There is an example in the report BCALV_TABLE_CREATE
report BCALV_TABLE_CREATE.
data: ok_code like sy-ucomm,
g_container type scrfname value 'BCALV_GRID_DEMO_0100_CONT1',
grid1 type ref to cl_gui_alv_grid,
g_custom_container type ref to cl_gui_custom_container.
data: gt_fieldcat type lvc_t_fcat.
data: gp_table type ref to data.
field-symbols: <gt_table> type table.
parameters: n type i.
if n > 100.
message a000(0k) with 'N <= 100'.
endif.
perform fieldcat_build.
call method cl_alv_table_create=>create_dynamic_table
exporting it_fieldcatalog = gt_fieldcat
importing ep_table = gp_table.
assign gp_table->* to <gt_table>.
perform fill_table.
call screen 100. -
How to update data in the database through ALV grid
Hi All,
I diplayed an ALV grid with five fields in a classical report. I have already set the fieldcat for one field as wa_fcat_edit = 'X'. I am able to edit(modify) the data in that field. But I want to update the data into the database which is modified by me in that field. Can I update the data using BDC or any other procedure?
This is an urgent require ment for me. Please help me ASAP.
Thanks & Regards,
Ramesh.Hi
Please go through the link.
Link: [http://www.****************/Tutorials/ALV/Edit/demo.htm]
regards
ravisankar -
Hi all,
I have one requirement.
I need to display output using alv grid display.Next when somebody select the rows in the grid display and press a push button then the selected fields are updated in the ztable created.
How can i achieve this.
How to get a push button on the alv.
how to update the the table with the selected rows.
Please give some suggestions for this.
Thanks to all in advance.CHk this program...
U have to mention button names in PF-status creation
REPORT ZVA0T_PRCTR_FAL NO STANDARD PAGE HEADING MESSAGE-ID RA.
Modification Log *
Program Name : ZVA0T_PRCTR_FAL *
Author : Suman K *
Date Written : 04/27/2004 *
Request # : SAGK901471 *
Requested by : Torrence Roundtree *
Description : This program is for maintainance of table *
ZVA0T_PRCTR_FAL. The program has been copied from *
custom program named ZSSVT_USR_TBL_MAINTENANCE and *
done with essential changes to include table *
ZVA0T_PRCTR_FAL and selection screen options. The *
existing program documentation is as below *
Program Specifications: *
Mod date Programmer Reference Description *
*04/27/2005 Suman K SAGK901471 Initial Development *
Type pools *
TYPE-POOLS : slis. " Used for ALV display
Tables
TABLES: ZVA0T_PRCTR_FAL . " LO43 Profit Center Listings
Constants
CONSTANTS:
For authorization check for modifying Table Entries
c_act_auth_01 LIKE tactz-actvt VALUE '01',
c_act_auth_02 LIKE tactz-actvt VALUE '02',
c_act_auth_06 LIKE tactz-actvt VALUE '06',
c_table LIKE dd02l-tabname VALUE 'ZVA0T_PRCTR_FAL',
" Table name
c_save TYPE c VALUE 'A', " Save
c_chg(3) TYPE c VALUE 'CHG', " Change Group
c_a TYPE c VALUE 'A', " Cancel Indicator
c_ct(2) TYPE c VALUE 'CT'. " Style Name
Work Variables declaration
DATA:
w_transaction_code LIKE tstc-tcode, " Transaction Code
w_variant TYPE disvariant, " Variant
ok_code LIKE sy-ucomm. " OK Code
Reference variables for the ALV grid control........................
DATA:
w_grid TYPE REF TO cl_gui_alv_grid, " ALV Grid
w_custom_container TYPE REF TO cl_gui_custom_container.
" Reference to Container
Variables used in User_command_0100
DATA:
w_confirm_ind TYPE c, " Deletion Indicator
W_SUBRC LIKE SY-SUBRC. " Subrc
Flag declaration
DATA:
fl_chng TYPE c, " Flag
fl_cancel TYPE c. " Flag
Internal tables declaration
To store the function codes.........................................
DATA:
BEGIN OF wa_fcode,
fcode LIKE sy-ucomm, " User Command
END OF wa_fcode.
Table for User Command
DATA: t_fcode LIKE STANDARD TABLE OF wa_fcode.
To store the data of ZVA0T_PRCTR_FAL table
DATA:
T_ZVA0T_PRCTR_FAL LIKE STANDARD TABLE
OF ZVA0T_PRCTR_FAL.
Table used in User_command_0100
DATA:
t_selected_rows TYPE lvc_t_row. " Selected row information
DATA:
FS_SELECTED_ROWS LIKE LINE OF T_SELECTED_ROWS.
" Work area for Selected Rows
Selection screen elements
SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME TITLE text-008.
SELECT-OPTIONS:
s_prctr FOR ZVA0T_PRCTR_FAL-leg_prctr.
" Profit Center
SELECTION-SCREEN: END OF BLOCK blk1.
SELECTION-SCREEN: BEGIN OF BLOCK blk2 WITH FRAME TITLE text-009.
PARAMETERS:
p_varant LIKE ltdx-variant. " ALV variant
SELECTION-SCREEN: END OF BLOCK blk2.
Initialization
INITIALIZATION.
Authorization check for transaction code
SELECT tcode
FROM tstc
INTO w_transaction_code
UP TO 1 ROWS
WHERE pgmna EQ sy-repid.
ENDSELECT.
IF sy-subrc EQ 0.
AUTHORITY-CHECK OBJECT 'S_TCODE'
ID 'TCD' FIELD w_transaction_code.
IF sy-subrc NE 0.
MESSAGE e100 WITH text-e01 w_transaction_code.
ENDIF. " IF SY-SUBRC NE 0
ENDIF. " IF SY-SUBRC EQ 0
At selection screen *
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_varant.
to get the existing values for the display variant
PERFORM f4_on_display_variant CHANGING p_varant.
AT SELECTION-SCREEN ON p_varant.
validates the diplay variant
IF p_varant IS NOT INITIAL.
PERFORM validate_variant.
ENDIF. " IF P_VARANT IS NOT INITIAL
Start Of Selection
START-OF-SELECTION.
CALL SCREEN 0100.
*& Form f4_on_display_variant
This subroutine is used to get the existing values for display variant
The parameter passed to the subroutine is Variant parameter
FORM f4_on_display_variant CHANGING p_varant TYPE any.
DATA: lw_variant LIKE disvariant. " Variant
lw_variant-report = sy-repid.
lw_variant-username = sy-uname.
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant = lw_variant
i_save = c_save
IMPORTING
es_variant = lw_variant
EXCEPTIONS
OTHERS = 1.
IF sy-subrc EQ 0.
p_varant = lw_variant-variant.
ELSE.
MESSAGE s100 WITH text-012.
ENDIF. " IF SY-SUBRC EQ 0
ENDFORM. " F4_ON_DISPLAY_VARIANT
*& Form validate_variant
This subroutine validates the variant entered onthe selection screen
There are no interface parameters to be passed to the subroutine
FORM validate_variant .
CLEAR w_variant.
w_variant-report = sy-repid.
MOVE p_varant TO w_variant-variant.
CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
EXPORTING
i_save = c_save
CHANGING
cs_variant = w_variant
EXCEPTIONS
wrong_input = 1
not_found = 2
program_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF. " IF SY-SUBRC <> 0
ENDFORM. " VALIDATE_VARIANT
*& Module STATUS_0100 OUTPUT
This is the PBO module for the ALV GRid dispaly
MODULE status_0100 OUTPUT.
Check the User authorizations and display the PF status accordingly
PERFORM check_authorizations.
Set the user status as per Authorizations
SET PF-STATUS 'ZVA0T_PRCTR_FAL' EXCLUDING t_fcode.
SET TITLEBAR 'ZVA0T_PRCTR_FAL'.
Instantiate the container control and Grid control.
IF w_custom_container IS INITIAL.
CREATE OBJECT w_custom_container
EXPORTING
container_name = 'CUSTOM_CONTAINER'.
CREATE OBJECT w_grid
EXPORTING
i_parent = w_custom_container.
ENDIF. " IF W_CUSTOM_CONTAINER IS ...
Clearing the work variables
PERFORM intialize.
Retrieve the table contents
PERFORM get_data.
Display the data in the ALV Grid control
PERFORM display_data.
ENDMODULE. " STATUS_0100 OUTPUT
*& Form check_authorizations
This subroutine is used to check the user authorizations
There are no interface parameters to be passed
FORM check_authorizations .
REFRESH t_fcode.
Authorization check for Create entry
AUTHORITY-CHECK OBJECT 'ZZ:TABLMNP'
ID 'ACTVT' FIELD c_act_auth_01
ID 'TABLE' FIELD c_table.
IF sy-subrc NE 0.
PERFORM fillcode USING 'CREA'.
PERFORM fillcode USING 'COPY'.
ENDIF. " IF SY-SUBRC NE 0
Authorization check for Change the entry
AUTHORITY-CHECK OBJECT 'ZZ:TABLMNP'
ID 'ACTVT' FIELD c_act_auth_02
ID 'TABLE' FIELD c_table.
IF sy-subrc NE 0.
PERFORM fillcode USING 'CHNG'.
ENDIF. " IF SY-SUBRC NE 0
Authorization check for Delete the entry
AUTHORITY-CHECK OBJECT 'ZZ:TABLMNP'
ID 'ACTVT' FIELD c_act_auth_06
ID 'TABLE' FIELD c_table.
IF sy-subrc NE 0.
PERFORM fillcode USING 'DELE'.
ENDIF. " IF SY-SUBRC NE 0
ENDFORM. " CHECK_AUTHORIZATIONS
*& Form fillcode
This subroutine is used to fill the function code in the table t_fcode
The parameter that passed to this subroutine is function code
FORM fillcode USING value(p_fcode) TYPE any.
CLEAR wa_fcode.
MOVE p_fcode TO wa_fcode-fcode.
APPEND wa_fcode TO t_fcode.
ENDFORM. " FILLCODE
*& Form intialize
This subroutine is used to initialize the work variables
There are no interface parameters that need to be passed
FORM intialize .
CLEAR t_ZVA0T_PRCTR_FAL.
REFRESH t_ZVA0T_PRCTR_FAL.
ENDFORM. " INITIALIZE
*& Form get_data
This subroutine is used to get data from the table
There are no interfaces parameters that need to be passed
FORM get_data .
retrieve the status and codegroup from the table
REFRESH t_ZVA0T_PRCTR_FAL.
SELECT *
FROM ZVA0T_PRCTR_FAL
INTO TABLE t_ZVA0T_PRCTR_FAL
WHERE leg_prctr IN s_prctr.
IF sy-subrc NE 0.
ENDIF. " IF SY-SUBRC NE 0
ENDFORM. " GET_DATA
*& Form display_data
This subroutine is used to display the data in the ALV Grid control
*There are no interface parameters that need to be passed to subroutine
FORM display_data .
DATA:
w_grid_layout TYPE lvc_s_layo, " Grid Layout
LT_fieldcat TYPE lvc_t_fcat. " Field Catalog
DATA:
FS_FIELDCAT LIKE LINE OF LT_FIELDCAT.
Filling the Layout
w_grid_layout-grid_title = text-001.
w_grid_layout-sel_mode = c_save.
w_grid_layout-stylefname = c_ct.
w_grid_layout-cwidth_opt = 'X'.
Filling the Variant structure
w_variant-report = sy-repid.
w_variant-username = sy-uname.
w_variant-variant = p_varant.
Filling the fieldcatalog.............................................
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = c_table
CHANGING
ct_fieldcat = lt_fieldcat.
To make the ALV list use the medium text label from DDIC
LOOP AT lt_fieldcat INTO FS_FIELDCAT.
MOVE 'M' TO fs_fieldcat-colddictxt.
MODIFY lt_fieldcat FROM FS_FIELDCAT.
ENDLOOP. " LOOP AT T_FIELDCAT
CALL METHOD w_grid->set_table_for_first_display
EXPORTING
i_structure_name = c_table
is_variant = w_variant
i_save = c_save
is_layout = w_grid_layout
CHANGING
it_outtab = t_ZVA0T_PRCTR_FAL
it_fieldcatalog = lt_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF. " IF SY-SUBRC NE 0
ENDFORM. " DISPLAY_DATA
*& Module USER_COMMAND_0100 INPUT
This is the PAI module for the screen 100.
MODULE user_command_0100 INPUT.
REFRESH t_selected_rows.
CLEAR FS_SELECTED_ROWS.
CLEAR fl_chng.
Getting the selected rows
CALL METHOD w_grid->get_selected_rows
IMPORTING
et_index_rows = t_selected_rows.
If more than one record is selected, error message
DESCRIBE TABLE t_selected_rows.
IF sy-tfill GT 1
AND SY-UCOMM NE 'REFR'
AND SY-UCOMM NE 'CREA'
AND SY-UCOMM NE 'DELE'.
MESSAGE e048(zcsv_sfdr).
ENDIF. " IF SY-TFILL GT 1
Read the first record
READ TABLE t_selected_rows INTO FS_SELECTED_ROWS INDEX 1.
READ TABLE t_ZVA0T_PRCTR_FAL
INTO ZVA0T_PRCTR_FAL INDEX fs_selected_rows-index.
CLEAR W_SUBRC.
W_SUBRC = SY-SUBRC.
CASE ok_code.
WHEN 'CREA'.
CLEAR ZVA0T_PRCTR_FAL.
CALL SCREEN 0200.
WHEN 'COPY'.
IF W_SUBRC EQ 0.
IF t_selected_rows IS NOT INITIAL.
CALL SCREEN 0200.
ELSE.
MESSAGE e100 WITH text-013.
ENDIF. " IF T_SELECTED_ROWS IS NOT ...
ELSE.
MESSAGE e100 WITH text-014.
ENDIF. " IF W_SUBRC EQ 0
WHEN 'CHNG'.
IF W_SUBRC EQ 0.
MOVE 'X' TO fl_chng.
IF t_selected_rows IS NOT INITIAL.
CALL SCREEN 0200.
ELSE.
MESSAGE e100 WITH text-e04.
ENDIF. " IF T_SELECTED_ROWS IS NOT ...
ELSE.
MESSAGE e100 WITH text-014.
ENDIF. " IF W_SUBRC EQ 0
WHEN 'DELE'.
IF t_selected_rows IS NOT INITIAL.
IF W_SUBRC EQ 0.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = text-002
text_question = text-003
text_button_1 = text-004
text_button_2 = text-005
default_button = '1'
display_cancel_button = 'X'
IMPORTING
answer = w_confirm_ind.
IF w_confirm_ind EQ '1'.
LOOP AT T_SELECTED_ROWS INTO FS_SELECTED_ROWS.
CLEAR ZVA0T_PRCTR_FAL.
READ TABLE T_ZVA0T_PRCTR_FAL
INTO ZVA0T_PRCTR_FAL INDEX fs_selected_rows-index.
IF SY-SUBRC EQ 0.
DELETE ZVA0T_PRCTR_FAL.
IF sy-subrc NE 0.
W_SUBRC = 4.
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDLOOP. " LOOP AT T_SELECTED_ROWS ...
IF W_SUBRC EQ 0.
MESSAGE s100 WITH text-010.
ELSE.
MESSAGE e100 WITH text-e03.
ENDIF. " IF W_SUBRC EQ 0
ELSEIF w_confirm_ind EQ '2'.
ENDIF. " IF W_CONFIRM_IND EQ '1'
ELSE.
MESSAGE e100 WITH text-014.
ENDIF. " IF W_SUBRC EQ 0
ELSE.
MESSAGE e100 WITH text-e05.
ENDIF. " IF T_SELECTED_ROWS IS NOT ...
WHEN 'BACK'.
SET SCREEN 0.
LEAVE SCREEN.
WHEN 'CANCEL'.
SET SCREEN 0.
LEAVE SCREEN.
ENDCASE. " CASE OK_CODE
CLEAR ok_code.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Module exit INPUT
This subroutine is used to leave the current screen
MODULE exit INPUT.
CALL METHOD w_custom_container->free.
CALL METHOD cl_gui_cfw=>flush.
SET SCREEN 0.
LEAVE SCREEN.
ENDMODULE. " EXIT INPUT
*& Module STATUS_0200 OUTPUT
This module is used to set the PF Status of the modify screen
MODULE status_0200 OUTPUT.
SET PF-STATUS 'STATUS_200'.
ENDMODULE. " STATUS_0200 OUTPUT
*& Module modify_0200 OUTPUT
This module is used to print the values on the screen
MODULE modify_0200 OUTPUT.
IF NOT fl_chng IS INITIAL.
LOOP AT SCREEN.
IF screen-group1 EQ c_chg.
screen-required = '0'.
screen-output = '1'.
screen-input = '0'.
MODIFY SCREEN.
ENDIF.
ENDLOOP. " LOOP AT SCREEN
ELSE.
LOOP AT SCREEN.
IF screen-group1 EQ c_chg.
screen-required = '1'.
screen-output = '1'.
screen-input = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP. " LOOP AT SCREEN
ENDIF. " IF NOT FL_CHNG IS INITIAL
ENDMODULE. " MODIFY_0200 OUTPUT
*& Module exit_0200 INPUT
This module is used to exit from the screen on pressing exit button
MODULE exit_0200 INPUT.
IF sy-datar IS INITIAL
AND fl_cancel IS INITIAL.
CLEAR fl_chng.
LEAVE PROGRAM.
ELSE.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = text-011
text_question = text-006
text_button_1 = text-004
text_button_2 = text-005
default_button = '1'
display_cancel_button = 'X'
IMPORTING
answer = w_confirm_ind.
CASE w_confirm_ind.
WHEN '1'.
sy-ucomm = 'SAVE'.
CLEAR fl_cancel.
WHEN '2'.
CLEAR fl_chng.
CLEAR fl_cancel.
LEAVE PROGRAM.
WHEN c_a.
fl_cancel = 'X'.
ENDCASE. " CASE W_CONFIRM_IND
ENDIF. " IF SY-DATAR IS INITIAL
ENDMODULE. " EXIT_0200 INPUT
*& Module USER_COMMAND_0200 INPUT
This module is used to update the database table with the user values
MODULE user_command_0200 INPUT.
IF sy-ucomm EQ 'SAVE'.
PERFORM SAVE.
ELSEIF SY-UCOMM EQ 'BACK'.
PERFORM BACK_CANCEL.
IF SY-UCOMM EQ 'SAVE'.
PERFORM SAVE. " IF SY-UCOMM EQ 'SAVE'
ENDIF.
ELSEIF SY-UCOMM EQ 'CANC'.
PERFORM BACK_CANCEL.
IF SY-UCOMM EQ 'SAVE'.
PERFORM SAVE. " IF SY-UCOMM EQ 'SAVE'
ENDIF.
ELSEIF SY-UCOMM EQ 'ENTE'.
fl_cancel = 'X'.
ENDIF. " IF SY-UCOMM EQ 'SAVE'
ENDMODULE. " USER_COMMAND_0200 INPUT
*& Form BACK_CANCEL
This subroutine provides functionality for BACK & CANCEL
form BACK_CANCEL .
IF sy-datar IS INITIAL
AND fl_cancel IS INITIAL.
CLEAR fl_chng.
SET SCREEN 0.
LEAVE SCREEN.
ELSE.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = text-011
text_question = text-006
text_button_1 = text-004
text_button_2 = text-005
default_button = '1'
display_cancel_button = 'X'
IMPORTING
answer = w_confirm_ind.
CASE w_confirm_ind.
WHEN '1'.
sy-ucomm = 'SAVE'.
CLEAR fl_cancel.
WHEN '2'.
CLEAR fl_chng.
CLEAR fl_cancel.
SET SCREEN 0.
LEAVE SCREEN.
WHEN 'A'.
fl_cancel = 'X'.
ENDCASE. " CASE W_CONFIRM_IND
ENDIF. " IF SY-DATAR IS INITIAL
endform. " BACK_CANCEL
*& Form SAVE
This subroutine provides functionality for SAVE
form SAVE .
MOVE:
SY-DATUM TO ZVA0T_PRCTR_FAL-erdat,
SY-UZEIT TO ZVA0T_PRCTR_FAL-erzet,
SY-UNAME TO ZVA0T_PRCTR_FAL-ernam.
IF fl_chng IS INITIAL.
INSERT ZVA0T_PRCTR_FAL.
IF sy-subrc EQ 0.
MESSAGE s100 WITH text-010.
ELSE.
MESSAGE e100 WITH text-e03.
ENDIF. " IF SY-SUBRC EQ 0
ELSE.
MODIFY ZVA0T_PRCTR_FAL.
IF sy-subrc EQ 0.
MESSAGE s100 WITH text-010.
ELSE.
MESSAGE e100 WITH text-e03.
ENDIF. " IF SY-SUBRC EQ 0
CLEAR t_ZVA0T_PRCTR_FAL.
ENDIF. " IF FL_CHNG IS INITIAL
SET SCREEN 0.
LEAVE SCREEN.
endform. " SAVE
Reward if helpful... -
Change the data in fieldcat and update the database table in alv oops
Hi,
my requirement is i have displayed a fieldcat in change mode and when i change the data and click on save it has to be updated the database table..
this has to be done using alv oops...Hi,
This code will reflect all the changes into the internal table that is being displayed.
* to reflect the data changed into internal table
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.
Now after this code is executed the internal table is modified as per the changes done in alv output.
Now you can use this internal table to update the database table.
Hope this helps you.
Regards,
Tarun -
How to print to tables in ALV grid
hi all
I have 2 internal tables with some values
i want to display the 2 internal tables in the grid one after another with some title
can anyone tell me how to do it
Thank you.i think in grid you can not do like this (By using function module). But you can do it in OO approach for that just check the se38 with alvgrid* and search. you can findout lot of example there. And one more option is there by using alv block but it is a list display.
Just check this sample program of alv block
TYPE-POOLS : SLIS.
TABLES : EKKO,EKPO.
DATA : BEGIN OF IEKKO OCCURS 0,
EBELN LIKE EKKO-EBELN,
AEDAT LIKE EKKO-AEDAT,
END OF IEKKO.
DATA : BEGIN OF IEKPO OCCURS 0,
EBELN LIKE EKPO-EBELN,
EBELP LIKE EKPO-EBELP,
MATNR LIKE EKPO-MATNR,
MENGE LIKE EKPO-MENGE,
MEINS LIKE EKPO-MEINS,
END OF IEKPO.
DATA : IFIELDCATEKKO TYPE SLIS_T_FIELDCAT_ALV,
IFIELDCATEKPO TYPE SLIS_T_FIELDCAT_ALV,
WFIELDCAT TYPE SLIS_FIELDCAT_ALV,
ILAYOUT TYPE SLIS_LAYOUT_ALV,
IEVENTHEAD TYPE SLIS_T_EVENT,
IEVENTITEM TYPE SLIS_T_EVENT,
WEVENT TYPE SLIS_ALV_EVENT,
ISORT TYPE SLIS_T_SORTINFO_ALV,
WSORT TYPE SLIS_SORTINFO_ALV.
PARAMETERS : P_NUM(3) TYPE N DEFAULT 10.
PERFORM GET_DATA_EKKO.
PERFORM GET_DATA_EKPO.
PERFORM BUILD_FCAT_HEAD.
PERFORM BUILD_FCAT_ITEM.
PERFORM BUILD_LAYOUT.
PERFORM BUILD_EVENT_TAB.
PERFORM DISPLAY_BLOCK.
*& Form GET_DATA_EKKO
* text
* --> p1 text
* <-- p2 text
FORM GET_DATA_EKKO .
SELECT EBELN AEDAT INTO TABLE IEKKO FROM EKKO UP TO P_NUM ROWS WHERE EBELN LIKE '45000057%'.
ENDFORM. " GET_DATA_EKKO
*& Form GET_DATA_EKPO
* text
* --> p1 text
* <-- p2 text
FORM GET_DATA_EKPO .
IF NOT IEKKO[] IS INITIAL.
SELECT EBELN EBELP MATNR MENGE MEINS INTO TABLE IEKPO FROM EKPO FOR ALL ENTRIES IN IEKKO
WHERE EBELN = IEKKO-EBELN.
ENDIF.
ENDFORM. " GET_DATA_EKPO
*& Form DISPLAY_BLOCK
* text
* --> p1 text
* <-- p2 text
FORM DISPLAY_BLOCK .
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* IT_EXCLUDING =
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = ILAYOUT
IT_FIELDCAT = IFIELDCATEKKO
I_TABNAME = 'IEKKO'
IT_EVENTS = IEVENTHEAD[]
* IT_SORT =
* I_TEXT = ' '
TABLES
T_OUTTAB = IEKKO
EXCEPTIONS
PROGRAM_ERROR = 1
MAXIMUM_OF_APPENDS_REACHED = 2
OTHERS = 3
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = ILAYOUT
IT_FIELDCAT = IFIELDCATEKPO
I_TABNAME = 'IEKPO'
IT_EVENTS = IEVENTITEM
* IT_SORT =
* I_TEXT = ' '
TABLES
T_OUTTAB = IEKPO
* EXCEPTIONS
* PROGRAM_ERROR = 1
* MAXIMUM_OF_APPENDS_REACHED = 2
* OTHERS = 3
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
* EXPORTING
* I_INTERFACE_CHECK = ' '
* IS_PRINT =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
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.
ENDFORM. " DISPLAY_BLOCK
*& Form BUILD_FCAT_HEAD
* text
* --> p1 text
* <-- p2 text
FORM BUILD_FCAT_HEAD .
WFIELDCAT-FIELDNAME = 'EBELN'.
WFIELDCAT-TABNAME = 'IEKKO'.
WFIELDCAT-SELTEXT_L = 'Pur. Doc no'.
WFIELDCAT-OUTPUTLEN = 15.
APPEND WFIELDCAT TO IFIELDCATEKKO.
CLEAR WFIELDCAT.
WFIELDCAT-FIELDNAME = 'AEDAT'.
WFIELDCAT-TABNAME = 'IEKKO'.
WFIELDCAT-SELTEXT_L = 'Pur. doc date'.
WFIELDCAT-OUTPUTLEN = 15.
APPEND WFIELDCAT TO IFIELDCATEKKO.
CLEAR WFIELDCAT.
ENDFORM. " BUILD_FCAT_HEAD
*& Form BUILD_FCAT_ITEM
* text
* --> p1 text
* <-- p2 text
FORM BUILD_FCAT_ITEM .
WFIELDCAT-FIELDNAME = 'EBELN'.
WFIELDCAT-TABNAME = 'IEKPO'.
WFIELDCAT-SELTEXT_L = 'Pur. Doc no'.
WFIELDCAT-OUTPUTLEN = 15.
APPEND WFIELDCAT TO IFIELDCATEKPO.
CLEAR WFIELDCAT.
WFIELDCAT-FIELDNAME = 'EBELP'.
WFIELDCAT-TABNAME = 'IEKPO'.
WFIELDCAT-SELTEXT_L = 'Pur. Doc item'.
*wfieldcat-do_sum = 'X'.
WFIELDCAT-OUTPUTLEN = 15.
APPEND WFIELDCAT TO IFIELDCATEKPO.
CLEAR WFIELDCAT.
WFIELDCAT-FIELDNAME = 'MATNR'.
WFIELDCAT-TABNAME = 'IEKPO'.
WFIELDCAT-SELTEXT_L = 'Material no'.
WFIELDCAT-OUTPUTLEN = 18.
APPEND WFIELDCAT TO IFIELDCATEKPO.
CLEAR WFIELDCAT.
WFIELDCAT-FIELDNAME = 'MENGE'.
WFIELDCAT-TABNAME = 'IEKPO'.
WFIELDCAT-SELTEXT_L = 'P.O. Qty'.
wfieldcat-do_sum = 'X'.
*WFIELDCAT-DATATYPE = 'QUAN'.
WFIELDCAT-OUTPUTLEN = 15.
APPEND WFIELDCAT TO IFIELDCATEKPO.
CLEAR WFIELDCAT.
WFIELDCAT-FIELDNAME = 'MEINS'.
WFIELDCAT-TABNAME = 'IEKPO'.
WFIELDCAT-SELTEXT_L = 'UOM'.
WFIELDCAT-OUTPUTLEN = 3.
APPEND WFIELDCAT TO IFIELDCATEKPO.
CLEAR WFIELDCAT.
ENDFORM. " BUILD_FCAT_ITEM
*& Form BUILD_LAYOUT
* text
* --> p1 text
* <-- p2 text
FORM BUILD_LAYOUT .
ILAYOUT-COLWIDTH_OPTIMIZE = 'X'.
ENDFORM. " BUILD_LAYOUT
*& Form BUILD_EVENT_TAB
* text
* --> p1 text
* <-- p2 text
FORM BUILD_EVENT_TAB .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = IEVENTHEAD
* EXCEPTIONS
* LIST_TYPE_WRONG = 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.
IEVENTITEM = IEVENTHEAD.
READ TABLE IEVENTHEAD INTO WEVENT WITH KEY NAME = 'TOP_OF_PAGE'.
IF SY-SUBRC = 0.
WEVENT-FORM = 'TOPOFPAGEHEAD'.
MODIFY IEVENTHEAD FROM WEVENT INDEX SY-TABIX.
ENDIF.
READ TABLE IEVENTHEAD INTO WEVENT WITH KEY NAME = 'USER_COMMAND'.
IF SY-SUBRC = 0.
WEVENT-FORM = 'USERCOMMAND'.
MODIFY IEVENTHEAD FROM WEVENT INDEX SY-TABIX.
ENDIF.
READ TABLE IEVENTITEM INTO WEVENT WITH KEY NAME = 'TOP_OF_PAGE'.
IF SY-SUBRC = 0.
WEVENT-FORM = 'TOPOFPAGEITEM'.
MODIFY IEVENTITEM FROM WEVENT INDEX SY-TABIX.
ENDIF.
ENDFORM. " BUILD_EVENT_TAB
FORM USERCOMMAND USING PUCOMM LIKE SY-UCOMM SELFIELD TYPE SLIS_SELFIELD.
CASE PUCOMM.
WHEN '&IC1'.
WHEN 'OTHERS'.
ENDCASE.
ENDFORM.
FORM TOPOFPAGEHEAD.
DATA : ILIST TYPE SLIS_T_LISTHEADER,
WLIST TYPE SLIS_LISTHEADER.
WLIST-INFO = 'Header data with P.O. no and creating date'.
WLIST-TYP = 'H'.
APPEND WLIST TO ILIST.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = ILIST
* I_LOGO =
* I_END_OF_LIST_GRID =
ENDFORM.
FORM TOPOFPAGEITEM.
DATA : ILIST TYPE SLIS_T_LISTHEADER,
WLIST TYPE SLIS_LISTHEADER.
WLIST-INFO = 'Item data with P.O.item material no and qty'.
WLIST-TYP = 'H'.
APPEND WLIST TO ILIST.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = ILIST
* I_LOGO =
* I_END_OF_LIST_GRID =
ENDFORM.
regards
shiba dutta -
Modifying single cell in ALV Grid via OO
Hi All,
Got a problem I hope someone can assist me with. I have a custom program generating an editable ALV grid. The users want to update a single cell in a row with value from a custom drop down. I've got the dropdown working, but I can't work out how to get the value back into the field. My attempts result in a 'GETWA_NOT_ASSIGNED' short dump.
I'm using the CL_GUI_ALV_GRID->get_selected_cells_id method to get the reference for the field to be modified, but I don't know where to go from here.
Any thoughts would be greatly appreciated. Btw, my knowledge of OO is passable, but not great, so any explanations of what the code is doing in a proposed solution would be greatly appreciated.
points will be rewarded.
Cheers,
StephenHello Stephen
Since your dropdown list restrict the already allowed values there should be no special need to validate the selected values.
Simply "grab" the data from the editable ALV into your internal itab in the ABAP report.
I have copied sample report BCALV_EDIT_07 into ZUS_SDN_BCALV_EDIT_07 and modified the report to show how to retrieve the dropdown values (which is simple). Please note that I added the GUI-function 'SAVE' to the GUI-status MAIN100.
* MODULE PAI INPUT *
MODULE pai INPUT.
save_ok = ok_code.
CLEAR ok_code.
"$TMP
g_grid->check_changed_data( ). " retrieve changes from editable grid
CASE save_ok.
WHEN 'EXIT'.
PERFORM exit_program.
"$TMP
WHEN 'SAVE'.
PERFORM save_data.
WHEN OTHERS.
* do nothing
ENDCASE.
ENDMODULE. "pai INPUT
*& Form SAVE_DATA
* text
FORM save_data. "$TMP
* define local data
data: ls_fcat type lvc_s_fcat,
lt_fcat type lvc_t_fcat.
lt_fcat = gt_fieldcat.
ls_fcat-edit = ' '.
modify lt_fcat from ls_fcat
TRANSPORTING edit
where ( edit = 'X' ). " display ALV should be not editable
" Simulate saving of data
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
* I_CALLBACK_PROGRAM = ' '
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
I_GRID_TITLE = 'Display modified list data'
* I_GRID_SETTINGS =
* IS_LAYOUT_LVC =
IT_FIELDCAT_LVC = lt_fcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS_LVC =
* IT_SORT_LVC =
* IT_FILTER_LVC =
* IT_HYPERLINK =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT_LVC =
* IS_REPREP_ID_LVC =
I_SCREEN_START_COLUMN = 5
I_SCREEN_START_LINE = 5
I_SCREEN_END_COLUMN = 120
I_SCREEN_END_LINE = 20
* I_HTML_HEIGHT_TOP =
* I_HTML_HEIGHT_END =
* IT_EXCEPT_QINFO_LVC =
* IR_SALV_FULLSCREEN_ADAPTER =
TABLES
t_outtab = gt_outtab
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.
ENDFORM. "SAVE_DATA
And here is the entire coding: In order to find the modified parts of the coding simply search for $TMP.
PROGRAM zus_sdn_bcalv_edit_07.
* Purpose:
* ~~~~~~~~
* This example shows how to define dropdown listboxes for
* particular cells of your output table.
* To check program behavior
* ~~~~~~~~~~~~~~~~~~~~~~~~~
* Conceive that customers are only allowed to smoke in the
* first class. For this reason, if the customer is a smoker
* only the first class (F) can be chosen in column 'CLASS',
* otherwise all classes.
* Essential steps (search for '§')
* ~~~~~~~~~~~~~~~
* 1.Define an extra field in your output table
* 2.Define a dropdown table and pass it to ALV.
* 3.Set your dropdown field editable and assign the fieldname of the
* corresponding additional field to DRDN_FIELD of the fieldcatalog.
* 4.Set the handle of your additional field of your output
* table according to the listbox that shall be displayed.
DATA: ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm,
g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',
g_grid TYPE REF TO cl_gui_alv_grid,
g_custom_container TYPE REF TO cl_gui_custom_container,
gt_fieldcat TYPE lvc_t_fcat,
gs_layout TYPE lvc_s_layo,
g_max TYPE i VALUE 100.
*§1.Define an extra field in your output table
* for each column where you want to use drop down listboxes.
* (One additional field refers to cells of one column).
DATA: BEGIN OF gt_outtab OCCURS 0.
INCLUDE STRUCTURE sbook.
DATA: drop_down_handle TYPE int4.
DATA: END OF gt_outtab.
* MAIN *
END-OF-SELECTION.
CALL SCREEN 100.
* MODULE PBO OUTPUT *
MODULE pbo OUTPUT.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'MAIN100'.
IF g_custom_container IS INITIAL.
PERFORM create_and_init_alv CHANGING gt_outtab[]
gt_fieldcat.
ENDIF.
ENDMODULE. "pbo OUTPUT
* MODULE PAI INPUT *
MODULE pai INPUT.
save_ok = ok_code.
CLEAR ok_code.
"$TMP
g_grid->check_changed_data( ). " retrieve changes from editable grid
CASE save_ok.
WHEN 'EXIT'.
PERFORM exit_program.
"$TMP
WHEN 'SAVE'.
PERFORM save_data.
WHEN OTHERS.
* do nothing
ENDCASE.
ENDMODULE. "pai INPUT
* FORM EXIT_PROGRAM *
FORM exit_program.
LEAVE PROGRAM.
ENDFORM. "exit_program
*& Form SAVE_DATA
* text
FORM save_data. "$TMP
* define local data
data: ls_fcat type lvc_s_fcat,
lt_fcat type lvc_t_fcat.
lt_fcat = gt_fieldcat.
ls_fcat-edit = ' '.
modify lt_fcat from ls_fcat
TRANSPORTING edit
where ( edit = 'X' ). " display ALV should be not editable
" Simulate saving of data
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
* I_CALLBACK_PROGRAM = ' '
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
I_GRID_TITLE = 'Display modified list data'
* I_GRID_SETTINGS =
* IS_LAYOUT_LVC =
IT_FIELDCAT_LVC = lt_fcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS_LVC =
* IT_SORT_LVC =
* IT_FILTER_LVC =
* IT_HYPERLINK =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT_LVC =
* IS_REPREP_ID_LVC =
I_SCREEN_START_COLUMN = 5
I_SCREEN_START_LINE = 5
I_SCREEN_END_COLUMN = 120
I_SCREEN_END_LINE = 20
* I_HTML_HEIGHT_TOP =
* I_HTML_HEIGHT_END =
* IT_EXCEPT_QINFO_LVC =
* IR_SALV_FULLSCREEN_ADAPTER =
TABLES
t_outtab = gt_outtab
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.
ENDFORM. "SAVE_DATA
*& Form BUILD_FIELDCAT
* text
* <--P_GT_FIELDCAT text
FORM build_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.
DATA ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SBOOK'
CHANGING
ct_fieldcat = pt_fieldcat.
LOOP AT pt_fieldcat INTO ls_fcat.
* Exchange smoker field with invoice field - just to
* make the dependance between SMOKER and CLASS more transparent
* (Smoking is only allowed in the first class).
IF ls_fcat-fieldname EQ 'SMOKER'.
ls_fcat-col_pos = 11.
ls_fcat-outputlen = 10.
MODIFY pt_fieldcat FROM ls_fcat.
ELSEIF ls_fcat-fieldname EQ 'INVOICE'.
ls_fcat-col_pos = 7.
MODIFY pt_fieldcat FROM ls_fcat.
ELSEIF ls_fcat-fieldname EQ 'CLASS'.
*§3.Set your dropdown field editable and assign the fieldname of the
* corresponding additional field to DRDN_FIELD of the fieldcatalog.
ls_fcat-edit = 'X'.
ls_fcat-drdn_field = 'DROP_DOWN_HANDLE'.
ls_fcat-outputlen = 5.
* Field 'checktable' is set to avoid shortdumps that are caused
* by inconsistend data in check tables. You may comment this out
* when the test data of the flight model is consistent in your system.
ls_fcat-checktable = '!'. "do not check foreign keys
MODIFY pt_fieldcat FROM ls_fcat.
ENDIF.
ENDLOOP.
ENDFORM. "build_fieldcat
*& Form CREATE_AND_INIT_ALV
* text
* <--P_GT_OUTTAB text
* <--P_GT_FIELDCAT text
* <--P_GS_LAYOUT text
FORM create_and_init_alv CHANGING pt_outtab TYPE STANDARD TABLE
pt_fieldcat TYPE lvc_t_fcat.
DATA: lt_exclude TYPE ui_functions.
CREATE OBJECT g_custom_container
EXPORTING
container_name = g_container.
CREATE OBJECT g_grid
EXPORTING
i_parent = g_custom_container.
PERFORM build_fieldcat CHANGING pt_fieldcat.
* Optionally restrict generic functions to 'change only'.
* (The user shall not be able to add new lines).
PERFORM exclude_tb_functions CHANGING lt_exclude.
PERFORM set_drdn_table.
PERFORM build_data CHANGING pt_outtab.
CALL METHOD g_grid->set_table_for_first_display
EXPORTING
it_toolbar_excluding = lt_exclude
CHANGING
it_fieldcatalog = pt_fieldcat
it_outtab = pt_outtab[].
* Set editable cells to ready for input initially
CALL METHOD g_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
ENDFORM. "CREATE_AND_INIT_ALV
*& Form EXCLUDE_TB_FUNCTIONS
* text
* <--P_LT_EXCLUDE text
FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions.
* Only allow to change data not to create new entries (exclude
* generic functions).
DATA ls_exclude TYPE ui_func.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
APPEND ls_exclude TO pt_exclude.
ENDFORM. " EXCLUDE_TB_FUNCTIONS
*& Form set_drdn_table
* text
* --> p1 text
* <-- p2 text
FORM set_drdn_table.
*§2.Define a dropdown table and pass it to ALV.
* One listbox is referenced by a handle, e.g., '1'.
* For each entry that shall appear in this listbox
* you have to append a line to the dropdown table
* with handle '1'.
* This handle can be assigned to several columns
* of the output table using the field catalog.
DATA: lt_dropdown TYPE lvc_t_drop,
ls_dropdown TYPE lvc_s_drop.
ls_dropdown-handle = '1'.
ls_dropdown-value = 'F'.
APPEND ls_dropdown TO lt_dropdown.
ls_dropdown-handle = '2'.
ls_dropdown-value = 'F'.
APPEND ls_dropdown TO lt_dropdown.
ls_dropdown-handle = '2'.
ls_dropdown-value = 'C'.
APPEND ls_dropdown TO lt_dropdown.
ls_dropdown-handle = '2'.
ls_dropdown-value = 'Y'.
APPEND ls_dropdown TO lt_dropdown.
CALL METHOD g_grid->set_drop_down_table
EXPORTING
it_drop_down = lt_dropdown.
ENDFORM. " set_drdn_table
*& Form build_data
* text
* --> p1 text
* <-- p2 text
FORM build_data CHANGING pt_outtab TYPE STANDARD TABLE.
DATA: lt_sbook TYPE TABLE OF sbook,
ls_sbook TYPE sbook,
l_index TYPE i,
ls_outtab LIKE LINE OF gt_outtab.
SELECT * FROM sbook INTO TABLE lt_sbook UP TO g_max ROWS."#EC CI_NOWHERE
IF sy-subrc NE 0.
PERFORM generate_entries CHANGING lt_sbook.
ENDIF.
*§4.Set the handle of your additional field of your output
* table according to the listbox that shall be displayed.
LOOP AT lt_sbook INTO ls_sbook.
l_index = sy-tabix.
MOVE-CORRESPONDING ls_sbook TO ls_outtab.
CLEAR ls_outtab-class.
* Alternate between smoker and non smoker to make
* it more obvious what this example is about
l_index = l_index MOD 2.
IF l_index EQ 1.
ls_outtab-smoker = 'X'.
ELSE.
ls_outtab-smoker = ' '.
ENDIF.
IF ls_outtab-smoker EQ 'X'.
ls_outtab-drop_down_handle = '1'.
ELSE.
ls_outtab-drop_down_handle = '2'.
ENDIF.
APPEND ls_outtab TO pt_outtab.
ENDLOOP.
ENDFORM. " build_data
*& Form generate_entries
* text
* <--P_LT_SLFIGHT text
FORM generate_entries CHANGING pt_sbook TYPE STANDARD TABLE.
DATA: ls_sbook TYPE sbook,
l_month(2) TYPE c,
l_day(2) TYPE c,
l_date(8) TYPE c,
l_prebookid TYPE i.
ls_sbook-carrid = 'LH'.
ls_sbook-connid = '0400'.
ls_sbook-forcurkey = 'DEM'.
ls_sbook-loccurkey = 'USD'.
ls_sbook-custtype = 'B'.
DO 110 TIMES.
l_prebookid = sy-index.
ls_sbook-forcuram = sy-index * 10.
ls_sbook-loccuram = ls_sbook-loccuram * 2.
ls_sbook-customid = sy-index.
ls_sbook-counter = 18.
ls_sbook-agencynum = 11.
l_month = sy-index / 10 + 1.
DO 2 TIMES.
l_day = 3 + l_month + sy-index * 2.
l_date+0(4) = '2000'.
l_date+4(2) = l_month.
l_date+6(2) = l_day.
ls_sbook-fldate = l_date.
SUBTRACT 3 FROM l_day.
ls_sbook-order_date+0(6) = l_date+0(6).
ls_sbook-order_date+6(2) = l_day.
ls_sbook-bookid = l_prebookid * 2 + sy-index.
IF sy-index EQ 1.
ls_sbook-smoker = 'X'.
ELSE.
ls_sbook-smoker = space.
ENDIF.
ls_sbook-luggweight = l_prebookid * 10.
IF ls_sbook-luggweight GE 1000.
ls_sbook-wunit = 'G'.
ls_sbook-class = 'C'.
ELSE.
ls_sbook-wunit = 'KG'.
ls_sbook-class = 'Y'.
ENDIF.
IF ls_sbook-bookid > 40 AND ls_sbook-wunit EQ 'KG'.
ls_sbook-invoice = 'X'.
ENDIF.
IF ls_sbook-bookid EQ 2.
ls_sbook-cancelled = 'X'.
ls_sbook-class = 'F'.
ENDIF.
APPEND ls_sbook TO pt_sbook.
ENDDO.
ENDDO.
ENDFORM. " generate_entries
Regards
Uwe -
Modify database table from internal table
Hi All,
I need to update database table from internal table which is having around 30000 records.
I am using MODIFY tabname FROM TABLE int_tabname...
Using this statement, I can modify the databse records very well. But user has some additional requirement.
He wants that the table should be modified from the internal table and after modification we should have the erroneous records to be displayed if any.
e.g. if 1500 records out of 30000 are erroneous then only 28500 records should be updated and 1500 records should be displayed as erroneous records so that the user can correct them and use them again for executing the program.
Is there any FM which imports the database table name and internal table, modifies the database and exports an internal tanle with erroneous records?
Any help will be appriciated,
Regards,
NehaHi
modifying datbase table useing internal table
<b>advises</b> before updating this datbase table plz lock that table to avoid incosistency
write the logic for modifying
Modify the database table as per new dunning procedure
MODIFY fkkvkp FROM TABLE lt_fkkvkp .
and finally unlock the table
<b>example</b>
*To lock table for further operations
constants: lc_tabname TYPE rstable-tabname VALUE 'FKKVKP' . "FKKVKP
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
tabname = lc_tabname
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc EQ 0.
To fetch all the contract accounts for customers of the segment
Households/SME.
PERFORM fetch_contract_accounts using lc_tabname .
ENDIF. " IF sy-subrc EQ 0.
*wrote the logic
Modify the database table as per new dunning procedure from internal table
MODIFY fkkvkp FROM TABLE lt_fkkvkp .
*unlock the tbale
CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
TABNAME = uc_tabname .
<b>Reward if usefull</b> -
Adobe Forms - Table control data Saved in Database table through Web Dynpro
Hello Friends,
I Am facing a Problem in Adobe Forms through Web Dynpro.
i Want to Make Interactive online Adobe Forms - In Table Control user enter the multiple entry in the table control and after that Click on SAVE button , entry will saved in Database table.
Please guide me.
Thanks in advance.
Gaurav.Hi Gaurabh,
For interactive form you have to check the property DisplayType = native and PdfSource should be a Context Attribute of type 'Xstring'.
For data retrieval, create a NODE and have all the required attributes within that node of AOBE form.
Fetch the data in WDDOINIT.
Also check, that the offline senario for this form is working.
Hope it helps you. -
Two Internal Tables for ALV Grid
Hi Gurus,
I have a little problem here. I have a report to display cost of production. The rows is about 50 displaying amount in dollars (currency fields). I have this in ALV Grid. But my problem is that the last 4 lines of the report are not currency fields like the others, they are quantity fields.
How can i go about to display this last 4 lines in this ALV Grid. They are from different internal tables off course because of the data type.
In short. I just want to display these 2 internal tables in an ALV Grid.
Thanks in Advance.Hi,
u can use ALV Block list to display 2 ALV.
Reffer to the below code.
DATA: v_layout TYPE slis_layout_alv.
DATA: ls_print TYPE slis_print_alv.
PERFORM build_fieldcatalog.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* IT_EXCLUDING =
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = v_layout
it_fieldcat = it_fcat_nlei
i_tabname = 'IT_NLEI_ALV'
it_events = it_event_nlei
* IT_SORT =
* I_TEXT = ' '
TABLES
t_outtab = it_nlei_alv
EXCEPTIONS
program_error = 1
maximum_of_appends_reached = 2
OTHERS = 3.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = v_layout
it_fieldcat = it_fcat_vbrp
i_tabname = 'IT_VBRP_ALV'
it_events = it_event_vbrp
* IT_SORT =
* I_TEXT = ' '
TABLES
t_outtab = it_vbrp_alv
EXCEPTIONS
program_error = 1
maximum_of_appends_reached = 2
OTHERS = 3.
ls_print-no_print_selinfos = 'X'. " Display no selection infos
ls_print-no_print_listinfos = 'X'. " Display no listinfos
ls_print-reserve_lines = 2. " Lines reserved for end of page
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
is_print = ls_print
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
EXCEPTIONS
program_error = 1
OTHERS = 2 -
Hi all
i have the following types:
<begin of type1,
fieldA type i ,
fieldB type i,
<end of type1,
<begin of type2,
fieldC type i
fieldA type i,
<end of type2,
<begin of type3,
fieldA type i,
fieldB type i,
fieldC type i,
<end of type3,
<begin of type4,
fieldA type i
fields1 type type1 occurs 4,
fields2 type type2 occurs 5,
fields3 type type3 occurs 7,
fieldD type i,
<end of type4.
I would like to set a internal table of type4 in an ALV grid. How do you do this? because i thought it could
like to hear from you! And off course << Moderator message - Please do not offer points >>
kind regards
Anton
Edited by: Rob Burbank on Nov 9, 2010 2:03 PMI have found another solution. I make one internal table with all the fields in it. It is not what i like, but it works...
thanks all for your replies!
kind regards
Anton Pierhagen -
How to modify DataBase Table with an internal Table
Hi, Friends.
I am coping Data from a Database table to an internal table after modifying data in the internal table I want to modify the db table according to the modification in the internal table. can some one help me out in this way, i am doing this modification in Table Control in Screen programing.
My Code is as follow.
MODULE zfsl_stinf_tc_init OUTPUT.
IF tc_copy IS INITIAL.
SELECT * INTO CORRESPONDING FIELDS OF TABLE it_zfsl_stinf FROM zfsl_stinf.
tc_copy = 'X'.
REFRESH CONTROL 'TC_FOR_ZFSL_STINF' FROM SCREEN '0001'.
ENDIF.
ENDMODULE. " zfsl_stinf_init OUTPUT
*& Module zfsl_stinf_tc_move OUTPUT
text
MODULE zfsl_stinf_tc_move OUTPUT.
MOVE-CORRESPONDING wa_it_zfsl_stinf TO zfsl_stinf.
ENDMODULE. " zfsl_stinf_tc_move OUTPUT
*& Module STATUS_0001 OUTPUT
text
MODULE status_0001 OUTPUT.
SET PF-STATUS 'ZFSL_SCREEN_1ONLY'.
SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0001 OUTPUT
*& Module zfsl_stinf_tc_modify INPUT
text
MODULE zfsl_stinf_tc_modify INPUT.
MOVE-CORRESPONDING zfsl_stinf TO wa_it_zfsl_stinf.
MODIFY it_zfsl_stinf FROM wa_it_zfsl_stinf INDEX tc_for_zfsl_stinf-current_line.
_*"" here i have the modified internal table " it_zfsl_stinf "*_
ENDMODULE. " zfsl_stinf_tc_modify INPUT
Kind regards,
FaisalHi
Here you are modifying your dbtable in module pool programming
so better to use work area to modify the database table
example:
data: itab type table of zfsl_stinf .
data: wa_itab type itab.
select single * from zfsl_stinf INTO itab WHERE <condition>
(pass your values to wa_itab.)
modify zfsl_stinf from values of wa_itab.
Regards
Srinivasu -
Hi,
I need to modify a single field in a custom database table for more than 1 record.
I need to update from the values in the internal table which has only that single field.
how to acheive this ..Pls help
Thankshi delcare work area wa and use
MODIFY dbtab FROM wa statement.
Maybe you are looking for
-
I had over 200 dollar takin out of my account! But this just happen! Tonight an in purchase history they are not showing up?!? What do I do!
-
Error while using External Webservice in CAF
Hi All, I am trying to use an external webservice in my CAF project. The webservice is working fine when tested using WebService Navigator but when I m testing in CAF Administrator UI it is giving the following error. ERROR. Problem in server respons
-
Broken motherboard iPhone 5?
My iPhone 5 went completely black for no reason which could be related to a mechanical, water damage or mishandling. I tried to reset the phone (holding the sleep/wake and home buttons) - it didn't work, then connect it to the iTunes (again, the phon
-
Gamma issue... beating a dead horse
so so confused, about this gamma shift from After Effects to Final Cut. I rendered the same clip out 4 different times and each time it has different gamma. Here are my render settings: 1. v210 Codec 2. Quicktime Animation 3. Apple FCP Uncompressed 8
-
CATS_DA and CADO different column fields
Hy friends, i have problem with CATS_DA when i log on in different language in system. I create z field in CATSDB - zccode. When i create report in English version everything is fine - field zccode show results. When i logon in Bulgarian language in