Sunday, December 19, 2010

Usage of ALV Function elements and making a column editable

Summary:

Web dynpro application to demonstrate the usage of ALV functions and also to make a column editable. Below example have the following features

  1. lists the Materials in the ALV
  2. Has the options search, which will search the given Material.
  3. Material master data DG Indicator profile field is editable.
  4. After entering the DG profile indicator field for material(s), Material can be saved by hitting on ‘SAVE’ Button provided.

This document is divided into two sections:

  1. Creating web dynpro component

  2. Creating the application

Part 1. CREATING WEB DYN PRO COMPONENT

  1. Create the web dynpro component interface

Transaction code: SE80

  • ¨ Mention the Name of Dynpro Component to be created

  • ¨ Let the Type Be Web Dynpro Component

  • ¨ Give The name of Window to Main Window as Shown

  1. Create nodes for material input called Input_material, for Material details called MARA in the Component controller.

Define the node input_material in the component controller.

3. Define node for material with dictionary structure MARA with cardinality 0..n.

4. Choose fields for the MARA node.

5. Include ALV_TABLE in the used components

6. Create a view to display the material details in ALV with options of

“SEARCH” – which will search the entered material and

“SAVE” – which saves the changed data on the ALV

7. Create a view container UI Element in the layout for the ALV display.

Copy the context nodes INPUT_MATERIAL and MARA from the component controller to view controller.



8. Create a transparent container in the layout and include button for “Search” and “Save” functionality.

9. Map the MARA node into DATA of the INTERFACECONTROLLER to pass the data into ALV.

10. Pull input_material into the FUNCTIONAL_ELEMENTS.

11. Include ALV TABLE VIEW into the View controller of the Material_master view.

12. Populate the data in the WDDOINIT method of the MATERIAL_MASTER view for the MARA node.

11. Include the Used controllers ALV_TABLE and INTERFACECONTROLLER in the view properties.

12. Code to fetch material data from MARA and bind it to node MARA.

METHOD wddoinit .
DATA:
node_mara TYPE REF TO if_wd_context_node,
elem_mara TYPE REF TO if_wd_context_element,
stru_mara TYPE if_material_master=>element_mara .
  DATA:BEGIN OF wa_mara,
matnr TYPE mara-matnr,
lvorm TYPE mara-lvorm,
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
bismt TYPE mara-bismt,
meins TYPE mara-meins,
bstme TYPE mara-bstme,
brgew TYPE mara-brgew,
ntgew TYPE mara-ntgew,
gewei TYPE mara-gewei,
volum TYPE mara-volum,
spart TYPE mara-spart,
profl TYPE mara-profl,
END OF wa_mara.
DATA:t_mara LIKE TABLE OF wa_mara.
* navigate from to via lead selection
node_mara = wd_context->get_child_node( name = if_material_master=>wdctx_mara ).
*-Bind Data into MARA node
SELECT matnr
lvorm
mtart
matkl
bismt
meins
bstme
brgew
ntgew
gewei
volum
spart
profl FROM mara INTO TABLE t_mara
WHERE ersda = '20080415'.
node_mara->bind_table( t_mara ).
*Code to set ALV Editable
DATA:
lr_comp_alv TYPE REF TO if_wd_component_usage,
lr_comp_if_alv TYPE REF TO iwci_salv_wd_table,
lr_config TYPE REF TO cl_salv_wd_config_table.
*... ALV Component Usage
lr_comp_alv = wd_this->wd_cpuse_alv_table( ).
IF lr_comp_alv->has_active_component( ) IS INITIAL.
lr_comp_alv->create_component( ).
ENDIF.
  lr_comp_if_alv = wd_this->wd_cpifc_alv_table( ).
*... Configure ALV
lr_config = lr_comp_if_alv->get_model( ).
  lr_config->if_salv_wd_table_settings~set_read_only(
value = abap_false
).
*Code to create material number as the input field in the ALV
*toolbar and also to make Dangerous goods field as editable.
  DATA lr_inputui1 TYPE REF TO cl_salv_wd_fe_input_field.
DATA input1 TYPE REF TO cl_salv_wd_function.
DATA: lr_column_settings TYPE REF TO if_salv_wd_column_settings,
lr_column TYPE REF TO cl_salv_wd_column,
lr_input_field TYPE REF TO cl_salv_wd_uie_input_field.
  CREATE OBJECT lr_inputui1 EXPORTING value_elementname = 'MATNR'.
  lr_inputui1->set_label_text( ' Material Number :' ).
input1 = lr_config->if_salv_wd_function_settings~create_function( id = 'LINPUT1' ).
input1->set_editor( lr_inputui1 ).
  lr_column_settings ?= lr_config.
lr_column = lr_column_settings->get_column( 'PROFL' ).
CREATE OBJECT lr_input_field EXPORTING value_fieldname = 'PROFL'.
lr_column->set_cell_editor( lr_input_field ).
ENDMETHOD.

13. Create an Action for the “SEARCH” . On action of search fetches the entered material in the ALV List.

method ONACTIONSEARCH .
DATA:
node_input_material TYPE REF TO if_wd_context_node,
elem_input_material TYPE REF TO if_wd_context_element,
stru_input_material TYPE if_material_master=>element_input_material ,
item_matnr LIKE stru_input_material-matnr.
* navigate from to via lead selection
node_input_material = wd_context->get_child_node( name = if_material_master=>wdctx_input_material ).
*   get element via lead selection
elem_input_material = node_input_material->get_element( ).
*   get single attribute
elem_input_material->get_attribute(
EXPORTING
name = `MATNR`
IMPORTING
value = item_matnr ).
DATA:
node_mara TYPE REF TO if_wd_context_node,
elem_mara TYPE REF TO if_wd_context_element,
stru_mara TYPE if_material_master=>element_mara .
  DATA:BEGIN OF wa_mara,
matnr TYPE mara-matnr,
lvorm TYPE mara-lvorm,
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
bismt TYPE mara-bismt,
meins TYPE mara-meins,
bstme TYPE mara-bstme,
brgew TYPE mara-brgew,
ntgew TYPE mara-ntgew,
gewei TYPE mara-gewei,
volum TYPE mara-volum,
spart TYPE mara-spart,
profl TYPE mara-profl,
END OF wa_mara.
DATA:t_mara LIKE TABLE OF wa_mara.
* navigate from to via lead selection
node_mara = wd_context->get_child_node( name = if_material_master=>wdctx_mara ).
SELECT matnr
lvorm
mtart
matkl
bismt
meins
bstme
brgew
ntgew
gewei
volum
spart
profl FROM mara INTO TABLE t_mara
WHERE matnr = item_matnr.


node_mara->bind_table( t_mara ).
endmethod.


14. Create an Action “SAVE” , to save the changed data for the DG indicator profile for the material.

15. Create a Service call for BAPI

16. Enter the BAPI function module.

17.choose the import and export parameters

18. On Action save , get the changed data and call the BAPI for saving the material data.

19. Activate the objects

Part 2 CREATING APPLICATION

20. Create Web dynpro application.

21. Run the web dynpro application, Material data is listed by default.

22. Enter the Material number and hit on search

23. Enter the DG profile number and hit on SAVE , BAPI is called to save the material data in the database.







No comments:

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

Blog Archive

goodsites