Alvedit programs

652 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
652
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
68
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Alvedit programs

  1. 1. TABLES: ekko.TYPE-POOLS: slis. "ALV Declarations *Data Declaration*---------------- TYPES: BEGIN OF t_ekko,ebeln TYPE ekpo-ebeln,ebelp TYPE ekpo-ebelp,statu TYPE ekpo-statu,aedat TYPE ekpo-aedat,matnr TYPE ekpo-matnr,menge TYPE ekpo-menge,meins TYPE ekpo-meins,netpr TYPE ekpo-netpr,peinh TYPE ekpo-peinh,field_style TYPE lvc_t_styl, "FOR DISABLEEND OF t_ekko.DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,wa_ekko TYPE t_ekko. *ALV data declarations DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE.DATA: it_fieldcat TYPE lvc_t_fcat, "slis_t_fieldcat_alv WITH HEADER LINE,wa_fieldcat TYPE lvc_s_fcat,gd_tab_group TYPE slis_t_sp_group_alv,gd_layout TYPE lvc_s_layo, "slis_layout_alv,gd_repid LIKE sy-repid. *************************************************************************Start-of-selection. START-OF-SELECTION.PERFORM data_retrieval.PERFORM set_specific_field_attributes.PERFORM build_fieldcatalog.PERFORM build_layout.PERFORM display_alv_report.*&---------------------------------------------------------------------**& Form BUILD_FIELDCATALOG
  2. 2. *&---------------------------------------------------------------------** Build Fieldcatalog for ALV Report*----------------------------------------------------------------------*FORM build_fieldcatalog.wa_fieldcat-fieldname = EBELN.wa_fieldcat-scrtext_m = Purchase Order.wa_fieldcat-col_pos = 0.wa_fieldcat-outputlen = 10.wa_fieldcat-emphasize = X.wa_fieldcat-key = X.APPEND wa_fieldcat TO it_fieldcat.CLEAR wa_fieldcat.wa_fieldcat-fieldname = EBELP.wa_fieldcat-scrtext_m = PO Item.wa_fieldcat-col_pos = 1.APPEND wa_fieldcat TO it_fieldcat.CLEAR wa_fieldcat.wa_fieldcat-fieldname = STATU.wa_fieldcat-scrtext_m = Status.wa_fieldcat-col_pos = 2.APPEND wa_fieldcat TO it_fieldcat.CLEAR wa_fieldcat.wa_fieldcat-fieldname = AEDAT.wa_fieldcat-scrtext_m = Item change date.wa_fieldcat-col_pos = 3.APPEND wa_fieldcat TO it_fieldcat.CLEAR wa_fieldcat.wa_fieldcat-fieldname = MATNR.wa_fieldcat-scrtext_m = Material Number.wa_fieldcat-col_pos = 4.APPEND wa_fieldcat TO it_fieldcat.CLEAR wa_fieldcat.
  3. 3. wa_fieldcat-fieldname = MENGE.wa_fieldcat-scrtext_m = PO quantity.wa_fieldcat-col_pos = 5.APPEND wa_fieldcat TO it_fieldcat.CLEAR wa_fieldcat.wa_fieldcat-fieldname = MEINS.wa_fieldcat-scrtext_m = Order Unit.wa_fieldcat-col_pos = 6.APPEND wa_fieldcat TO it_fieldcat.CLEAR wa_fieldcat.wa_fieldcat-fieldname = NETPR.wa_fieldcat-scrtext_m = Net Price.wa_fieldcat-edit = X. "sets whole column to be editablewa_fieldcat-col_pos = 7.wa_fieldcat-outputlen = 15.wa_fieldcat-datatype = CURR.APPEND wa_fieldcat TO it_fieldcat.CLEAR wa_fieldcat.wa_fieldcat-fieldname = PEINH.wa_fieldcat-scrtext_m = Price Unit.wa_fieldcat-col_pos = 8.APPEND wa_fieldcat TO it_fieldcat.CLEAR wa_fieldcat.ENDFORM. " BUILD_FIELDCATALOG*&---------------------------------------------------------------------**& Form BUILD_LAYOUT*&---------------------------------------------------------------------** Build layout for ALV grid report*----------------------------------------------------------------------*FORM build_layout.* Set layout field for field attributes(i.e. input/output)gd_layout-stylefname = FIELD_STYLE.
  4. 4. gd_layout-zebra = X.ENDFORM. " BUILD_LAYOUT*&---------------------------------------------------------------------**& Form DISPLAY_ALV_REPORT*&---------------------------------------------------------------------** Display report using ALV grid*----------------------------------------------------------------------*FORM display_alv_report.gd_repid = sy-repid.* call function REUSE_ALV_GRID_DISPLAYCALL FUNCTION REUSE_ALV_GRID_DISPLAY_LVCEXPORTINGi_callback_program = gd_repid* i_callback_user_command = USER_COMMANDis_layout_lvc = gd_layoutit_fieldcat_lvc = it_fieldcati_save = XTABLESt_outtab = it_ekkoEXCEPTIONSprogram_error = 1OTHERS = 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_ALV_REPORT*&---------------------------------------------------------------------**& Form DATA_RETRIEVAL*&---------------------------------------------------------------------** Retrieve data form EKPO table and populate itab it_ekko*----------------------------------------------------------------------*
  5. 5. FORM data_retrieval.SELECT ebeln ebelp statu aedat matnr menge meins netpr peinhUP TO 10 ROWSFROM ekpoINTO CORRESPONDING FIELDS OF TABLE it_ekko.ENDFORM. " DATA_RETRIEVAL*&---------------------------------------------------------------------**& Form set_specific_field_attributes*&---------------------------------------------------------------------** populate FIELD_STYLE table with specific field attributes*----------------------------------------------------------------------*form set_specific_field_attributes .DATA ls_stylerow TYPE lvc_s_styl .DATA lt_styletab TYPE lvc_t_styl .* Populate style variable (FIELD_STYLE) with style properties** The NETPR field/column has been set to editable in the fieldcatalog...* The following code sets it to be disabled(display only) if NETPR* is gt than 10.LOOP AT it_ekko INTO wa_ekko.IF wa_ekko-netpr GT 10.ls_stylerow-fieldname = NETPR .ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled."set field to disabledAPPEND ls_stylerow TO wa_ekko-field_style.MODIFY it_ekko FROM wa_ekko.ENDIF.ENDLOOP.endform. " set_specific_field_attributes&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&DATA:ok_code LIKE sy-ucomm,
  6. 6. save_ok 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,gs_layout TYPE lvc_s_layo,g_max TYPE i VALUE 100.*§1.Extend your output table for a field, e.g., CELLTAB, that holds* information about the edit status of each cell for the* corresponding row (the table type is SORTED!).DATA: BEGIN OF gt_outtab OCCURS 0. "with header line INCLUDE STRUCTURE sflight.DATA: celltab TYPE lvc_t_styl.DATA: END OF gt_outtab.*---------------------------------------------------------------------** MAIN **---------------------------------------------------------------------*CALL SCREEN 100.*---------------------------------------------------------------------** MODULE PBO OUTPUT **---------------------------------------------------------------------*MODULE pbo OUTPUT. SET PF-STATUS MAIN100. SET TITLEBAR MAIN100. IF g_custom_container IS INITIAL. CREATE OBJECT g_custom_container EXPORTING container_name = g_container. CREATE OBJECT grid1 EXPORTING i_parent = g_custom_container. PERFORM select_data_and_init_style.*§3.Provide the fieldname of the celltab field by using field* STYLEFNAME of the layout structure. gs_layout-stylefname = CELLTAB. CALL METHOD grid1->set_table_for_first_display EXPORTING i_structure_name = SFLIGHT
  7. 7. is_layout = gs_layout CHANGING it_outtab = gt_outtab[]. ENDIF.ENDMODULE. "pbo OUTPUT*---------------------------------------------------------------------** MODULE PAI INPUT **---------------------------------------------------------------------*MODULE pai INPUT. save_ok = ok_code. CLEAR ok_code. CASE save_ok. WHEN EXIT. PERFORM exit_program. WHEN SWITCH. PERFORM switch_edit_mode. WHEN OTHERS.* do nothing ENDCASE.ENDMODULE. "pai INPUT*---------------------------------------------------------------------** FORM EXIT_PROGRAM **---------------------------------------------------------------------*FORM exit_program. LEAVE PROGRAM.ENDFORM. "exit_program*&---------------------------------------------------------------------**& Form SELECT_DATA_AND_INIT_STYLE*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*FORM select_data_and_init_style. DATA: lt_sflight TYPE TABLE OF sflight WITH HEADER LINE, lt_celltab TYPE lvc_t_styl, l_index TYPE i. SELECT * FROM sflight INTO TABLE lt_sflight UP TO g_max ROWS.
  8. 8. * move corresponding fields from lt_sflight to gt_outtab LOOP AT lt_sflight. MOVE-CORRESPONDING lt_sflight TO gt_outtab. APPEND gt_outtab. ENDLOOP.*§2.After selecting data, set edit status for each row in a loop* according to field SEATSMAX. LOOP AT gt_outtab. l_index = sy-tabix. REFRESH lt_celltab. IF gt_outtab-seatsmax GE 300. PERFORM fill_celltab USING RW CHANGING lt_celltab. ELSE. PERFORM fill_celltab USING RO CHANGING lt_celltab. ENDIF.*§2c.Copy your celltab to the celltab of the current row of gt_outtab. INSERT LINES OF lt_celltab INTO TABLE gt_outtab-celltab. MODIFY gt_outtab INDEX l_index. ENDLOOP.ENDFORM. " SELECT_DATA_AND_INIT_STYLE*&---------------------------------------------------------------------**& Form FILL_CELLTAB*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** <--P_PT_CELLTAB text*----------------------------------------------------------------------*FORM fill_celltab USING value(p_mode)CHANGING pt_celltab TYPE lvc_t_styl. DATA: ls_celltab TYPE lvc_s_styl, l_mode TYPE raw4.* This forms sets the style of column PRICE editable* according to p_mode and the rest to read only either way.
  9. 9. IF p_mode EQ RW.*§2a.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_ENABLED to set a cell* to status "editable". l_mode = cl_gui_alv_grid=>mc_style_enabled. ELSE. "p_mode eq RO*§2b.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_DISABLED to set a cell* to status "non-editable". l_mode = cl_gui_alv_grid=>mc_style_disabled. ENDIF. ls_celltab-fieldname = CARRID. ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled. INSERT ls_celltab INTO TABLE pt_celltab. ls_celltab-fieldname = CONNID. ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled. INSERT ls_celltab INTO TABLE pt_celltab. ls_celltab-fieldname = FLDATE. ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled. INSERT ls_celltab INTO TABLE pt_celltab. ls_celltab-fieldname = PRICE. ls_celltab-style = l_mode. INSERT ls_celltab INTO TABLE pt_celltab. ls_celltab-fieldname = CURRENCY. ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled. INSERT ls_celltab INTO TABLE pt_celltab. ls_celltab-fieldname = PLANETYPE. ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled. INSERT ls_celltab INTO TABLE pt_celltab. ls_celltab-fieldname = SEATSMAX. ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled. INSERT ls_celltab INTO TABLE pt_celltab. ls_celltab-fieldname = SEATSOCC. ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
  10. 10. INSERT ls_celltab INTO TABLE pt_celltab. ls_celltab-fieldname = PAYMENTSUM. ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled. INSERT ls_celltab INTO TABLE pt_celltab.ENDFORM. " FILL_CELLTAB*&---------------------------------------------------------------------**& Form SWITCH_EDIT_MODE*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*FORM switch_edit_mode. IF grid1->is_ready_for_input( ) EQ 0.* set edit enabled cells ready for input CALL METHOD grid1->set_ready_for_input EXPORTING i_ready_for_input = 1. ELSE.* lock edit enabled cells against input CALL METHOD grid1->set_ready_for_input EXPORTING i_ready_for_input = 0. ENDIF.ENDFORM. " SWITCH_EDIT_MODE

×