REPORT zly_report. *********Report Demo**************************************** *本程序主要将普通的ALV报表做拆分讲解 *一个简单的ALV包括以下一个部分 *1.数据定义部分:这部分用来定义全局变量,包括表,结构,工作区,宏,变量等 *2.选择屏幕定义部分:这部分是用来定义选择屏幕,包括屏幕的布局等 *3.数据处理部分:这部分包括数据查询和数据处理两块,根据不同的需求和查询条件将查询结果处理,最红汇总到需要展示的内表种 *4.字段目录设置:这部分是设置ALV需要展示的字段,字段描述以及alv的属性等 *5.数据展示:调用alv函数,展示内表数据 *6.功能处理:对ALV特定功能处理 *********数据定义部分*************************************** TABLES:zhsb_order_index."用tables关键字定义一个全局的工作区/结构 TYPES:BEGIN OF ty_show, guid TYPE crmt_object_guid, object_id TYPE crmt_object_id_db, process_type TYPE crmt_process_type, description TYPE crmt_process_description, posting_date TYPE crmt_posting_date, sales_org TYPE crmt_sales_org, created_by TYPE crmt_created_by, provider TYPE bu_partner, stat_user TYPE crm_j_status, zzzserialno TYPE zserialno, zzzmodeno TYPE zmodeno, zzfld00000n TYPE zdtel00003y, name_org1 TYPE bu_nameor1, name_org2 TYPE bu_nameor2, country TYPE land1, region TYPE regio, city1 TYPE ad_city1, street TYPE ad_street, END OF ty_show, BEGIN OF ty_but000, partner TYPE bu_partner, name_org1 TYPE bu_nameor1, name_org2 TYPE bu_nameor2, addrnumber TYPE ad_addrnum, END OF ty_but000, BEGIN OF ty_adrc, addrnumber TYPE ad_addrnum, country TYPE land1, region TYPE regio, city1 TYPE ad_city1, street TYPE ad_street, END OF ty_adrc. DATA:gt_show TYPE TABLE OF ty_show, "展示的内表 gw_show LIKE LINE OF gt_show, "数据处理对应的工作区 vt_show TYPE TABLE OF ty_show, "临时表 gt_but000 TYPE TABLE OF ty_but000, "相关表 gw_but000 LIKE LINE OF gt_but000, "相关表的工作区 gt_adrc TYPE TABLE OF ty_adrc, "相关表 gw_adrc LIKE LINE OF gt_adrc. "相关表的工作区 DATA:gt_fieldcat TYPE lvc_t_fcat, "字段目录内表 gs_fieldcat LIKE LINE OF gt_fieldcat, "字段目录工作区 ls_layout TYPE lvc_s_layo. "布局 DATA:lr_grid TYPE REF TO cl_gui_alv_grid. DATA:gt_event TYPE slis_t_event, gw_event LIKE LINE OF gt_event. DATA:gw_grid_setting TYPE lvc_s_glay. DEFINE append_fieldcat . CLEAR gs_fieldcat. gs_fieldcat-fieldname = &1."字段 gs_fieldcat-scrtext_l = &2."显示的描述 gs_fieldcat-outputlen = &3."输出长度 gs_fieldcat-no_zero = &4."不显示前导0 * gs_fieldcat-just = 'C'."居中对齐,R,L IF &1 = 'ZZZSERIALNO'. gs_fieldcat-edit = 'X'. ENDIF. APPEND gs_fieldcat TO gt_fieldcat. END-OF-DEFINITION. *********选择屏幕************************************************ SELECTION-SCREEN:BEGIN OF BLOCK blk01 WITH FRAME TITLE text-001. SELECT-OPTIONS:s_id FOR zhsb_order_index-object_id, s_type FOR zhsb_order_index-process_type, s_date FOR zhsb_order_index-posting_date, s_sale FOR zhsb_order_index-sales_org. SELECTION-SCREEN END OF BLOCK blk01. SELECTION-SCREEN:BEGIN OF BLOCK blk02 WITH FRAME TITLE text-002. SELECT-OPTIONS:s_prv FOR zhsb_order_index-provider. SELECTION-SCREEN END OF BLOCK blk02. START-OF-SELECTION. **********数据处理************************************************* PERFORM frm_get_data."数据查询 PERFORM frm_pro_data."数据处理 PERFORM frm_set_field."设置字段目录,布局 PERFORM frm_show. *END-OF-SELECTION."非逻辑数据库不需要 *&---------------------------------------------------------------------* *& Form FRM_GET_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_get_data . "取主表数据 SELECT guid object_id process_type description posting_date sales_org created_by provider stat_user zzzserialno zzzmodeno zzfld00000n INTO CORRESPONDING FIELDS OF TABLE gt_show FROM zhsb_order_index WHERE object_id IN s_id AND process_type IN s_type AND posting_date IN s_date AND sales_org IN s_sale AND provider IN s_prv. "临时表数据准备 vt_show[] = gt_show[]. SORT vt_show BY provider. DELETE ADJACENT DUPLICATES FROM vt_show COMPARING provider. DELETE vt_show WHERE provider = ''. IF vt_show[] IS NOT INITIAL. "取副表数据 SELECT but000~partner but000~name_org1 but000~name_org2 but020~addrnumber INTO TABLE gt_but000 FROM but000 INNER JOIN but020 ON but000~partner = but020~partner FOR ALL ENTRIES IN vt_show WHERE but000~partner = vt_show-provider. IF gt_but000[] IS NOT INITIAL. "取副表数据 SELECT addrnumber country region city1 street INTO TABLE gt_adrc FROM adrc FOR ALL ENTRIES IN gt_but000 WHERE addrnumber = gt_but000-addrnumber. ENDIF. REFRESH:vt_show[]. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_PRO_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_pro_data . LOOP AT gt_show INTO gw_show. READ TABLE gt_but000 INTO gw_but000 WITH KEY partner = gw_show-provider. IF sy-subrc = 0. gw_show-name_org1 = gw_but000-name_org1. gw_show-name_org2 = gw_but000-name_org2. READ TABLE gt_adrc INTO gw_adrc WITH KEY addrnumber = gw_but000-addrnumber. IF sy-subrc = 0. gw_show-country = gw_adrc-country. gw_show-region = gw_adrc-region. gw_show-city1 = gw_adrc-city1. gw_show-street = gw_adrc-street. ENDIF. ENDIF. MODIFY gt_show FROM gw_show. ENDLOOP. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_SET_FIELD *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_set_field . append_fieldcat:'OBJECT_ID' '服务单号' 10 'X', 'PROCESS_TYPE' '单据类型' 4 '', 'DESCRIPTION' '单据描述' 40 '', 'POSTING_DATE' '创建日期' 10 '', 'SALES_ORG' '销售组织' 14 '', 'CREATED_BY' '创建用户' 12 '', 'PROVIDER' '服务商' 10 'X', 'STAT_USER' '单据状态' 5 '', 'ZZZSERIALNO' '序列号' 30 '', 'ZZZMODENO' '型号' 40 '', 'ZZFLD00000N' '服务类型' 2 '', 'NAME_ORG1' '服务商名称1' 40 '', * 'NAME_ORG2' '服务商名称2' 40 '', 'COUNTRY' '国家' 3 '', 'REGION' '省份' 3 '', 'CITY1' '城市' 40 '', 'STREET' '街道' 60 ''. ls_layout-cwidth_opt = 'X'. "优化列宽选项是否设置 ls_layout-zebra = 'X'. gw_event-form = 'DATA_CHANGED_METHOD'. gw_event-name = 'DATA_CHANGED'. APPEND gw_event TO gt_event. gw_grid_setting-edt_cll_cb = 'X'. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_SHOW *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_show . CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING i_callback_program = sy-repid i_callback_pf_status_set = 'PRM_SET_STATUS' i_callback_user_command = 'PRM_USER_COMMAND' is_layout_lvc = ls_layout it_fieldcat_lvc = gt_fieldcat[] i_grid_settings = gw_grid_setting * I_GRID_TITLE = LV_TITLE i_default = 'X' i_save = 'A' it_events = gt_event[] TABLES t_outtab = gt_show EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0. ENDIF. ENDFORM. FORM prm_set_status USING rt_extab TYPE slis_t_extab. SET PF-STATUS 'ZSTAT'. CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING e_grid = lr_grid. ENDFORM. FORM prm_user_command USING p_ucomm LIKE sy-ucomm p_selfield TYPE slis_selfield. CHECK p_ucomm = '&IC1'. READ TABLE gt_show INTO gw_show INDEX p_selfield-tabindex. IF sy-subrc = 0. ENDIF. ENDFORM. FORM data_changed_method USING pa_data_changed TYPE REF TO cl_alv_changed_data_protocol . DATA: l_it_data TYPE lvc_t_modi, l_wa_data LIKE LINE OF l_it_data. FIELD-SYMBOLS:<lv_field> TYPE any. l_it_data = pa_data_changed->mt_mod_cells. CHECK l_it_data IS NOT INITIAL. LOOP AT pa_data_changed->mt_mod_cells INTO l_wa_data. READ TABLE gt_show INTO gw_show INDEX l_wa_data-row_id. IF sy-subrc = 0. ASSIGN COMPONENT l_wa_data-fieldname OF STRUCTURE gw_show TO <lv_field>. IF sy-subrc = 0. <lv_field> = l_wa_data-value. MODIFY gt_show FROM gw_show INDEX l_wa_data-row_id. ENDIF. ENDIF. ENDLOOP. CALL METHOD lr_grid->refresh_table_display. ENDFORM. " DATA_CHANGED_METHOD
^_^很多人都把资料锁进了note里,以后还怎么百度呢^_^