https://www.bilibili.com/read/cv4326715
1 *&---------------------------------------------------------------------* 2 *& Report ZBPC_UJO_SQE 3 *&---------------------------------------------------------------------* 4 *& 5 *&---------------------------------------------------------------------* 6 REPORT zbpc_ujo_sqe. 7 8 DATA: g_need_refresh TYPE c. 9 DATA: lo_alv TYPE REF TO cl_gui_alv_grid. 10 TABLES:zbpc_s_entity,zbpc_s_product,zbpc_s_time. 11 *DEFINE g_amount. 12 * &1 = &1. 13 * &1-z_category = &2. 14 * &1-z_account = &3. 15 * &1-z_time = &4. 16 * &1-z_datasource = &5. 17 * &1-z_misc1 = &6. 18 ** &1-measure = |Periodic|. 19 * &1-measure = ||. 20 * &1-z_class = |CLASS_NONE|. 21 * &1-z_currency = |CURRENCY_NONE|. 22 * &1-z_entity = &7. 23 * &1-z_line = |LINE_NONE|. 24 * &1-z_misc2 = |MISC2_NONE|. 25 * &1-z_product = &8. 26 * &1-z_view = |VIEW_NONE|. 27 *END-OF-DEFINITION. 28 * g_amount os_ytts_uk_y_ssres 'BUDGET_V0' 'PL02' con_next_year_inp 'SS_RESULT' con_z_misc1 'BCSYBW050.INP' <fs_ts_uk_y>-zattributes. 29 30 DEFINE sel. 31 CLEAR ls_sel. 32 ls_sel-dimension = &1. 33 ls_sel-attribute = 'ID'. 34 ls_sel-sign = 'I'. 35 ls_sel-option = 'BT'. 36 ls_sel-low = &2. 37 ls_sel-high = &3. 38 APPEND ls_sel TO lt_sel. 39 END-OF-DEFINITION. 40 *--·与ALV相关的变量 41 DATA: wa_fieldcat TYPE lvc_s_fcat, "ALV显示字段內表 42 it_fieldcat TYPE lvc_t_fcat, "ALV显示字段结构 43 wa_layout TYPE lvc_s_layo, "ALV显示风格结构 44 ls_glay TYPE lvc_s_glay, 45 it_sub_fieldcat TYPE lvc_t_fcat, 46 wa_sub_layout TYPE lvc_s_layo, 47 con_diabox TYPE REF TO cl_gui_dialogbox_container, 48 wcl_alv1 TYPE REF TO cl_gui_alv_grid, 49 tem_grid TYPE REF TO cl_gui_alv_grid, 50 ref_grid TYPE REF TO cl_gui_alv_grid. 51 52 *--·与ALV函数相关的参数 53 DATA: wa_sort_lvc TYPE lvc_s_sort, "关于ALV中排序字段的结构 54 it_sort_lvc TYPE lvc_t_sort, "关于ALV中排序字段的内表 55 it_excluding TYPE slis_t_extab, "关于排除ALV工具栏标准按钮的内表 56 wa_excluding LIKE LINE OF it_excluding, "关于排除ALV工具栏标准按钮的结构 57 lt_ddval TYPE lvc_t_drop, "关于下拉列表的内表 58 lt_ddval_01 TYPE lvc_t_drop, "关于下拉列表的内表 59 ls_ddval TYPE lvc_s_drop, "关于下拉列表的工作区 60 * ls_ddval TYPE LVC_T_DRAL, "关于下拉列表的工作区 61 git_events TYPE slis_t_event. "注册ALV事件的内表 62 TYPE-POOLS: slis. 63 64 TYPES: BEGIN OF typ_data, 65 checkbox TYPE c, 66 * cbox TYPE aq_markbg, 67 68 z_account TYPE c LENGTH 32, 69 z_category TYPE c LENGTH 32, 70 z_class TYPE c LENGTH 32, 71 z_currency TYPE c LENGTH 32, 72 z_datasource TYPE c LENGTH 32, 73 z_entity TYPE c LENGTH 32, 74 z_line TYPE c LENGTH 32, 75 z_misc1 TYPE c LENGTH 32, 76 z_misc2 TYPE c LENGTH 32, 77 z_product TYPE c LENGTH 32, 78 z_time TYPE c LENGTH 32, 79 z_view TYPE c LENGTH 32, 80 signeddata TYPE /b28/oisdata, 81 measure TYPE c LENGTH 32, 82 cell_color TYPE slis_t_specialcol_alv, " 83 color TYPE c LENGTH 4, 84 cellstyles TYPE lvc_t_styl. " 85 * INCLUDE STRUCTURE zbpc_s_planning_sub. 86 TYPES: END OF typ_data. 87 88 DATA:gt_show TYPE TABLE OF zbpc_s_planning_sub, 89 gs_show TYPE zbpc_s_planning_sub. 90 DATA:gt_alv TYPE TABLE OF typ_data, 91 gs_alv TYPE typ_data. 92 93 DATA:lt_sel TYPE uj0_t_sel, 94 ls_sel TYPE uj0_s_sel. 95 DATA:ls_cg TYPE zbpc_s_planning_sub, 96 lt_cg TYPE TABLE OF zbpc_s_planning_sub. 97 98 CLASS lcl_event_handler DEFINITION. 99 PUBLIC SECTION. 100 101 METHODS handle_data_changed FOR EVENT data_changed 102 OF cl_gui_alv_grid 103 IMPORTING er_data_changed e_onf4 e_onf4_before e_onf4_after e_ucomm. 104 105 106 METHODS handle_data_change_finish FOR EVENT data_changed_finished OF cl_gui_alv_grid 107 IMPORTING 108 e_modified 109 et_good_cells. 110 ENDCLASS. "lcl_event_handler DEFINITION 111 112 *----------------------------------------------------------------------* 113 * CLASS lcl_event_handler IMPLEMENTATION 114 *----------------------------------------------------------------------* 115 * 116 *----------------------------------------------------------------------* 117 CLASS lcl_event_handler IMPLEMENTATION. 118 119 METHOD handle_data_changed. 120 PERFORM handle_data_changed USING er_data_changed e_onf4 e_onf4_before e_onf4_after e_ucomm. 121 ENDMETHOD. 122 123 METHOD handle_data_change_finish. 124 CHECK g_need_refresh = 'X'. 125 gs_alv-color = ''. 126 MODIFY gt_alv FROM gs_alv TRANSPORTING color WHERE checkbox = ''. 127 gs_alv-color = 'C600'. 128 MODIFY gt_alv FROM gs_alv TRANSPORTING color WHERE checkbox = 'X'. 129 130 131 CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' 132 IMPORTING 133 e_grid = lo_alv. 134 * CALL METHOD lo_alv->check_changed_data. 135 136 * lo_alv->refresh_table_display( ). 137 DATA: stbl TYPE lvc_s_stbl. 138 stbl-row = 'X'." 基于行的稳定刷新 139 stbl-col = 'X'." 基于列稳定刷新 140 CALL METHOD lo_alv->refresh_table_display 141 EXPORTING 142 is_stable = stbl. 143 * PERFORM refresh_table_alv. 144 ENDMETHOD. 145 ENDCLASS. "lcl_event_handler IMPLEMENTATION 146 147 148 149 PARAMETERS:i_appset TYPE uj_appset_id AS LISTBOX VISIBLE LENGTH 32 DEFAULT 'WMPLAN', "UJ_APPSET_ID 150 * I_APPL_I TYPE UJ_APPL_ID, "UJ_APPL_ID 151 i_appl_i TYPE uj_appl_id AS LISTBOX VISIBLE LENGTH 32 DEFAULT 'Planning', "UJ_APPL_ID 152 * I_APPL_I TYPE UJ_APPL_ID AS LISTBOX VISIBLE LENGTH 20 , "UJ_APPL_ID 153 iaccount TYPE char32 OBLIGATORY 154 . 155 TABLES:zbpc_s_category,zbpc_s_datasource,zbpc_s_misc1. 156 *I_APPSET = |WMPLAN|. 157 * I_APPL_I = |Planning|. 158 *IACCOUNT = |PL01|. 159 *TRANSLATE iaccount TO UPPER CASE. 160 SELECTION-SCREEN:BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001. 161 SELECT-OPTIONS: 162 s_entity FOR zbpc_s_entity-z_entity , 163 s_prod FOR zbpc_s_product-z_product , 164 s_time FOR zbpc_s_time-z_time, 165 166 s_categ FOR zbpc_s_category-z_category, 167 s_datas FOR zbpc_s_datasource-z_datasource, 168 s_misc1 FOR zbpc_s_misc1-z_misc1. 169 . 170 SELECTION-SCREEN:END OF BLOCK b1. 171 172 173 INITIALIZATION. 174 %_i_appset_%_app_%-text = '环境'. 175 %_i_appl_i_%_app_%-text = '模型ID'. 176 %_iaccount_%_app_%-text = '科目类型'. 177 %_s_entity_%_app_%-text = '组织'. 178 %_s_prod_%_app_%-text = '产品'. 179 %_s_time_%_app_%-text = '时间'. 180 181 %_s_categ_%_app_%-text = '版本'. 182 %_s_datas_%_app_%-text = '数据源'. 183 %_s_misc1_%_app_%-text = 'Z_MISC1'. 184 185 AT SELECTION-SCREEN ON VALUE-REQUEST FOR i_appset. 186 PERFORM frm_f4_i_appset. 187 188 AT SELECTION-SCREEN ON VALUE-REQUEST FOR i_appl_i. 189 PERFORM frm_f4_i_appl_i. 190 191 START-OF-SELECTION. 192 PERFORM get_data. 193 PERFORM frm_get_event. 194 PERFORM display_data. 195 196 *&---------------------------------------------------------------------* 197 *& FORM GET_DATA 198 *&---------------------------------------------------------------------* 199 * 获取数据 200 *----------------------------------------------------------------------* 201 FORM get_data. 202 *----------------------------------------------------------------------* 203 *GET_BPC_DATA 204 205 CLEAR lt_sel. 206 CLEAR:lt_cg[],lt_cg. 207 sel 'MEASURES' 'Periodic' 'Periodic' . "PCD科目 208 sel 'Z_ACCOUNT' iaccount iaccount. "PCD科目 209 210 * %_s_categ_%_app_%-text = '版本'. 211 * %_s_datas_%_app_%-text = '数据源'. 212 * %_s_misc1_%_app_%-text = 'Z_MISC1'. 213 LOOP AT s_categ INTO DATA(s_categ1). 214 sel 'Z_CATEGORY' s_categ1-low s_categ1-low . "预算数 215 ENDLOOP. 216 217 sel 'Z_CLASS' 'CLASS_NONE' 'CLASS_NONE'. 218 sel 'Z_CURRENCY' 'CURRENCY_NONE' 'CURRENCY_NONE'. 219 220 LOOP AT s_datas INTO DATA(s_datas1). 221 sel 'Z_DATASOURCE' s_datas1-low s_datas1-low . " 222 ENDLOOP. 223 224 SORT s_entity BY low. 225 DELETE ADJACENT DUPLICATES FROM s_entity COMPARING low. 226 LOOP AT s_entity INTO DATA(is_table_entity). 227 sel 'Z_ENTITY' is_table_entity-low is_table_entity-low . 228 ENDLOOP. 229 sel 'Z_LINE' 'LINE_NONE' 'LINE_NONE'. 230 231 LOOP AT s_misc1 INTO DATA(s_misc11). 232 sel 'Z_MISC1' s_misc11-low s_misc11-low . " 233 ENDLOOP. 234 235 sel 'Z_MISC2' 'MISC2_NONE' 'MISC2_NONE'. 236 SORT s_prod BY low. 237 DELETE ADJACENT DUPLICATES FROM s_prod COMPARING low. 238 LOOP AT s_prod INTO DATA(is_table_product). 239 sel 'Z_PRODUCT' is_table_product-low is_table_product-low . . 240 ENDLOOP. 241 242 LOOP AT s_time INTO DATA(is_table_time). 243 sel 'Z_TIME' is_table_time-low is_table_time-low . "时间 244 ENDLOOP. 245 sel 'Z_VIEW' 'VIEW_NONE' 'VIEW_NONE'. 246 247 248 DATA: lo_appl TYPE REF TO cl_uja_application, 249 lt_appl_dim TYPE uja_t_appl_dim, 250 ls_appl_dim LIKE LINE OF lt_appl_dim, 251 lt_dim_name TYPE ujq_t_dim, 252 ls_dim_name LIKE LINE OF lt_dim_name, 253 lo_model TYPE REF TO if_uj_model, 254 lo_dataref TYPE REF TO data, 255 lo_query TYPE REF TO if_ujo_query, 256 lt_data TYPE REF TO data, 257 lt_message TYPE uj0_t_message. 258 259 FIELD-SYMBOLS: <lt_tx_data> TYPE STANDARD TABLE, 260 <ls_data> TYPE any. 261 262 *i_appl_i = 'Sales'. 263 264 CREATE OBJECT lo_appl 265 EXPORTING 266 i_appset_id = i_appset 267 i_application_id = i_appl_i. 268 269 REFRESH lt_appl_dim. 270 lo_appl->get_appl_dim( 271 EXPORTING 272 i_appl_id = i_appl_i 273 IMPORTING 274 et_appl_dim = lt_appl_dim ). 275 276 REFRESH lt_dim_name. 277 278 LOOP AT lt_appl_dim INTO ls_appl_dim. 279 ls_dim_name = ls_appl_dim-dimension. 280 APPEND ls_dim_name TO lt_dim_name. 281 CLEAR ls_dim_name. 282 ENDLOOP. 283 284 ls_dim_name = 'MEASURES'. 285 286 APPEND ls_dim_name TO lt_dim_name. 287 288 SORT lt_dim_name. 289 290 TRY. 291 lo_model = cl_uj_model=>get_model( i_appset ). 292 lo_model->create_tx_data_ref( 293 EXPORTING 294 i_appl_name = i_appl_i 295 i_type = 'T' 296 it_dim_name = lt_dim_name 297 if_tech_name = space 298 IMPORTING 299 er_data = lo_dataref ). 300 CATCH cx_uj_static_check. 301 ENDTRY. 302 303 ASSIGN lo_dataref->* TO <lt_tx_data>. 304 CREATE DATA lt_data LIKE LINE OF <lt_tx_data>. 305 ASSIGN lt_data->* TO <ls_data>. 306 307 TRY. 308 lo_query = cl_ujo_query_factory=>get_query_adapter( 309 i_appset_id = i_appset 310 i_appl_id = i_appl_i 311 ). 312 313 lo_query->run_rsdri_query( 314 EXPORTING 315 it_dim_name = lt_dim_name 316 it_range = lt_sel 317 if_check_security = abap_false 318 IMPORTING 319 et_data = <lt_tx_data> 320 et_message = lt_message 321 ). 322 CATCH cx_ujo_read. 323 324 325 326 ENDTRY. 327 LOOP AT <lt_tx_data> INTO <ls_data>. 328 * APPEND <LS_DATA> TO ET_DATA. 329 * APPEND <LS_DATA> TO GT_SHOW. 330 gs_alv = CORRESPONDING #( <ls_data> ). 331 APPEND gs_alv TO gt_alv.CLEAR gs_alv. 332 ENDLOOP. 333 ENDFORM. "GET_DATA 334 *&---------------------------------------------------------------------* 335 *& Form DISPLAY_DATA 336 *&---------------------------------------------------------------------* 337 *& text 338 *&---------------------------------------------------------------------* 339 *& --> p1 text 340 *& <-- p2 text 341 *&---------------------------------------------------------------------* 342 FORM display_data . 343 344 PERFORM frm_set_fieldcat. 345 346 PERFORM frm_layout. 347 348 PERFORM frm_disp_data. 349 ENDFORM. 350 351 FORM frm_set_fieldcat . 352 CLEAR: it_fieldcat,wa_fieldcat. 353 wa_fieldcat-checkbox = 'X' ."设置第一列为复选框 354 wa_fieldcat-edit = 'X' . 355 wa_fieldcat-key = 'X'. 356 * wa_fieldcat-outputlen = '3'. 357 PERFORM set_fieldcat USING 'CHECKBOX' '选择框'. 358 359 * PERFORM set_fieldcat USING 'MEASURE' 'MEASURE'. 360 * wa_fieldcat-key = 'X'. "设置为关键列 361 * wa_fieldcat-icon = 'X'. 362 * wa_fieldcat-outputlen = '3'. 363 PERFORM set_fieldcat USING 'Z_ACCOUNT' 'Z_ACCOUNT'. 364 wa_fieldcat-emphasize = 'C710'. " 365 wa_fieldcat-outputlen = '32'. 366 PERFORM set_fieldcat USING 'Z_ENTITY' 'Z_ENTITY'. 367 wa_fieldcat-emphasize = 'C310'. "设置字段的颜色 368 wa_fieldcat-outputlen = '32'. 369 PERFORM set_fieldcat USING 'Z_PRODUCT' 'Z_PRODUCT'. 370 wa_fieldcat-emphasize = 'C410'. " 371 PERFORM set_fieldcat USING 'Z_TIME' 'Z_TIME'. 372 wa_fieldcat-emphasize = 'C510'. " 373 PERFORM set_fieldcat USING 'Z_MISC1' 'Z_MISC1'. 374 * wa_fieldcat-key = 'X'. "设置为关键列 375 * wa_fieldcat-icon = 'X'. 376 * wa_fieldcat-outputlen = '3'. 377 378 PERFORM set_fieldcat USING 'Z_CATEGORY' 'Z_CATEGORY'. 379 * wa_fieldcat-emphasize = 'C600'. " 380 PERFORM set_fieldcat USING 'Z_DATASOURCE' 'Z_DATASOURCE'. 381 PERFORM set_fieldcat USING 'Z_CLASS' 'Z_CLASS'. 382 PERFORM set_fieldcat USING 'Z_CURRENCY' 'Z_CURRENCY'. 383 384 PERFORM set_fieldcat USING 'Z_LINE' 'Z_LINE'. 385 386 PERFORM set_fieldcat USING 'Z_MISC2' 'Z_MISC2'. 387 388 . 389 PERFORM set_fieldcat USING 'Z_VIEW' 'Z_VIEW'. 390 PERFORM set_fieldcat USING 'SIGNEDDATA' 'SIGNEDDATA'. 391 ENDFORM. " FRM_SET_FIELDCAT 392 393 FORM frm_layout . 394 CLEAR wa_layout. 395 wa_layout-cwidth_opt = 'X'. 396 wa_layout-no_rowmark = 'X'. " 397 wa_layout-zebra = 'X'. 398 wa_layout-countfname = 'COUNT'. " 399 wa_layout-info_fname = 'COLOR'." 400 wa_layout-ctab_fname = 'CELL_COLOR'. 401 wa_layout-stylefname = 'CELLSTYLES'. 402 403 ENDFORM. " FRM_LAYOUT 404 405 FORM frm_disp_data . 406 SORT gt_alv BY z_entity z_product. 407 408 409 410 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' 411 EXPORTING 412 * I_INTERFACE_CHECK = ' ' 413 * I_BYPASSING_BUFFER = 414 * I_BUFFER_ACTIVE = 415 i_callback_program = sy-repid 416 i_callback_pf_status_set = 'FRM_SET_PF_STATUS' "USER_COMMAND 417 i_callback_user_command = 'FRM_USER_COMMAND' 418 * i_background_id = 'ALV_BACKGROUND' 419 is_layout_lvc = wa_layout 420 it_fieldcat_lvc = it_fieldcat 421 i_save = 'X' "是否保存布局 422 it_events = git_events 423 TABLES 424 t_outtab = gt_alv[] 425 * t_outtab = gt_show[] 426 EXCEPTIONS 427 program_error = 1 428 OTHERS = 2. 429 IF sy-subrc <> 0. 430 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 431 WITH sy-msgv1 sy-msgv2. 432 EXIT. 433 ENDIF. 434 435 436 ENDFORM. " FRM_DISP_DATA 437 *&---------------------------------------------------------------------* 438 *& Form FRM_SET_PF_STATUS 439 *&---------------------------------------------------------------------* 440 * 为ALV设置状态栏 441 *----------------------------------------------------------------------* 442 * --> p1 text 443 * <-- p2 text 444 *----------------------------------------------------------------------* 445 FORM frm_set_pf_status USING pt_extab TYPE slis_t_extab. 446 447 SET PF-STATUS 'STANDARD' EXCLUDING pt_extab. 448 DATA(gv_num) = lines( gt_alv ). 449 SET TITLEBAR 'TITLE' WITH gv_num. 450 * sy-uname sy-datum sy-uzeit. "【模型数据】共计: &1 条 &2 &3 &4 451 ENDFORM. "frm_set_pf_status 452 *&---------------------------------------------------------------------* 453 *& Form USER_COMMAND 454 *&---------------------------------------------------------------------* 455 * 为ALV定制事件 456 *----------------------------------------------------------------------* 457 * --> r_ucomm 当前使用事务代码 458 * <-- rs_selfield 表结构 459 *----------------------------------------------------------------------* 460 FORM frm_user_command USING r_ucomm LIKE sy-ucomm 461 rs_selfield TYPE slis_selfield. 462 DATA: l_guid TYPE REF TO cl_gui_alv_grid. 463 CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' 464 IMPORTING 465 e_grid = l_guid. 466 467 468 CALL METHOD l_guid->check_changed_data. 469 IF sy-subrc <> 0."调用完函数等之后,检查返回码sy-subrc的值,并做判断处理 470 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 471 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 472 ENDIF. 473 474 475 rs_selfield-refresh = 'X'. 476 rs_selfield-row_stable = 'X'. 477 rs_selfield-col_stable = 'X'. 478 * CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' 479 * IMPORTING 480 * e_grid = l_guid. 481 * 482 * "调用CHECK_CHANGED_DATA可以使被修改的数据自动更新到内表中去 483 * CALL METHOD l_guid->check_changed_data. 484 * IF sy-subrc <> 0."调用完函数等之后,检查返回码sy-subrc的值,并做判断处理 485 * MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 486 * WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 487 * ENDIF. 488 ** 按钮 489 * CASE r_ucomm. 490 * WHEN 'BACK'. 491 * LEAVE TO SCREEN 0. 492 * WHEN '&IC1'. 493 * CLEAR wa_output. 494 * READ TABLE gt_show INTO gs_show INDEX rs_selfield-tabindex. 495 * IF rs_selfield-fieldname = 'JHDH'. 496 * CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' 497 * EXPORTING 498 * input = gs_show-jhdh 499 * IMPORTING 500 * output = gs_show-jhdh. 501 * SET PARAMETER ID 'VL' FIELD gs_show-jhdh. 502 * IF gs_show-jhdh IS NOT INITIAL. 503 * CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN. 504 * ENDIF. 505 * ENDIF. 506 * ENDCASE. 507 ENDFORM. 508 *&---------------------------------------------------------------------* 509 *& Form SET_FIELDCAT 510 *&---------------------------------------------------------------------* 511 *& text 512 *&---------------------------------------------------------------------* 513 *& --> P_ 514 *& --> P_ 515 *&---------------------------------------------------------------------* 516 FORM set_fieldcat USING VALUE(p_0548) 517 VALUE(p_0549). 518 wa_fieldcat-just = 'L'."对其方式,L表示左对齐 519 wa_fieldcat-fieldname = p_0548 . 520 wa_fieldcat-coltext = p_0549 . 521 wa_fieldcat-seltext = p_0549 . 522 APPEND wa_fieldcat TO it_fieldcat. 523 CLEAR wa_fieldcat. 524 ENDFORM. " SET_FIELDCAT 525 FORM frm_get_event . 526 DATA l_events TYPE LINE OF slis_t_event. 527 l_events-name = 'CALLER_EXIT'. "'CALLER_EXIT'在此写固定即可 528 l_events-form = 'FRM_ENTER_EVENT'."回车事件调用的FORM 529 APPEND l_events TO git_events. 530 531 ENDFORM. " FRM_GET_EVENT 532 533 FORM frm_enter_event USING e_grid TYPE slis_data_caller_exit. 534 DATA: lv_event_receiver TYPE REF TO lcl_event_handler, 535 lt_f4 TYPE lvc_t_f4, 536 ls_f4 TYPE lvc_s_f4. 537 538 539 CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' 540 IMPORTING 541 e_grid = ref_grid. "类CL_GUI_ALV_GRID的实例 542 543 * 设置enter事件 544 CALL METHOD ref_grid->register_edit_event 545 EXPORTING 546 i_event_id = cl_gui_alv_grid=>mc_evt_enter 547 EXCEPTIONS 548 error = 1 549 OTHERS = 2. 550 IF sy-subrc <> 0." 551 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 552 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 553 ENDIF. 554 555 556 DATA gt_event_receiver TYPE REF TO lcl_event_handler. 557 DATA: l_ref_alv TYPE REF TO cl_gui_alv_grid. 558 CREATE OBJECT gt_event_receiver. 559 560 CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' 561 IMPORTING 562 e_grid = l_ref_alv. 563 * CALL METHOD l_ref_alv->set_drop_down_table 564 * EXPORTING 565 * it_drop_down = lt_ddval. 566 567 ref_grid->register_edit_event( cl_gui_alv_grid=>mc_evt_enter ). 568 ref_grid->register_edit_event( cl_gui_alv_grid=>mc_evt_modified ). 569 SET HANDLER gt_event_receiver->handle_data_changed FOR ref_grid. 570 571 DATA: go_event_handler TYPE REF TO lcl_event_handler. 572 DATA: lo_alv TYPE REF TO cl_gui_alv_grid. 573 CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' 574 IMPORTING 575 e_grid = lo_alv. 576 CALL METHOD lo_alv->check_changed_data. 577 578 lo_alv->register_edit_event( cl_gui_alv_grid=>mc_evt_enter ). 579 lo_alv->register_edit_event( cl_gui_alv_grid=>mc_evt_modified ). 580 581 582 CREATE OBJECT go_event_handler. 583 SET HANDLER go_event_handler->handle_data_change_finish FOR lo_alv. 584 *----------------------------------------------------------------------* 585 586 ENDFORM. " FRM_GET_EVENT 587 *&---------------------------------------------------------------------* 588 *& Form FRM_F4_I_APPSET 589 *&---------------------------------------------------------------------* 590 *& text 591 *&---------------------------------------------------------------------* 592 *& --> p1 text 593 *& <-- p2 text 594 *&---------------------------------------------------------------------* 595 FORM frm_f4_i_appset . 596 TYPES: BEGIN OF typ_tab, 597 * ELIKZ TYPE CHAR1, 598 elikz_txt TYPE char30, 599 END OF typ_tab. 600 DATA: lt_value_tab TYPE TABLE OF typ_tab. 601 602 lt_value_tab = VALUE #( ( elikz_txt = 'WMPLAN' ) 603 ( elikz_txt = 'WMCONSOL' ) 604 * ( ELIKZ_TXT = 'Rates' ) ). 605 ). 606 607 CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' 608 EXPORTING 609 retfield = 'ELIKZ' "指定要返回屏幕参数的在内表中的field 610 dynpprog = sy-repid "指定屏幕参数所在的程序名称 611 dynpnr = sy-dynnr "指定参数所在的屏幕编号 612 dynprofield = 'I_APPSET' "指定屏幕参数的名称 613 value_org = 'S' "C表示cell,S表示structure 614 callback_program = sy-repid 615 TABLES 616 value_tab = lt_value_tab 617 EXCEPTIONS 618 parameter_error = 1 619 no_values_found = 2 620 OTHERS = 3. 621 IF sy-subrc <> 0. 622 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 623 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 624 ENDIF. 625 ENDFORM. 626 *&---------------------------------------------------------------------* 627 *& Form FRM_F4_I_APPL_I 628 *&---------------------------------------------------------------------* 629 *& text 630 *&---------------------------------------------------------------------* 631 *& --> p1 text 632 *& <-- p2 text 633 *&---------------------------------------------------------------------* 634 FORM frm_f4_i_appl_i . 635 TYPES: BEGIN OF typ_tab, 636 * ELIKZ TYPE CHAR1, 637 elikz_txt TYPE char30, 638 END OF typ_tab. 639 DATA: lt_value_tab_id TYPE TABLE OF typ_tab. 640 641 lt_value_tab_id = VALUE #( ( elikz_txt = 'Planning' ) 642 ( elikz_txt = 'Consolidation' ) 643 ( elikz_txt = 'Rates' ) ). 644 645 CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' 646 EXPORTING 647 retfield = 'ELIKZ' "指定要返回屏幕参数的在内表中的field 648 dynpprog = sy-repid "指定屏幕参数所在的程序名称 649 dynpnr = sy-dynnr "指定参数所在的屏幕编号 650 dynprofield = 'I_APPL_I' "指定屏幕参数的名称 651 value_org = 'S' "C表示cell,S表示structure 652 callback_program = sy-repid 653 TABLES 654 value_tab = lt_value_tab_id 655 EXCEPTIONS 656 parameter_error = 1 657 no_values_found = 2 658 OTHERS = 3. 659 IF sy-subrc <> 0. 660 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 661 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 662 ENDIF. 663 ENDFORM. 664 *&---------------------------------------------------------------------* 665 *& Form HANDLE_DATA_CHANGED 666 *&---------------------------------------------------------------------* 667 *& text 668 *&---------------------------------------------------------------------* 669 *& --> ER_DATA_CHANGED 670 *& --> E_ONF4 671 *& --> E_ONF4_BEFORE 672 *& --> E_ONF4_AFTER 673 *& --> E_UCOMM 674 *&---------------------------------------------------------------------* 675 FORM handle_data_changed USING p_er_data_changed TYPE REF TO cl_alv_changed_data_protocol 676 p_e_onf4 677 p_e_onf4_before 678 p_e_onf4_after 679 p_e_ucomm. 680 DATA: lo_alv TYPE REF TO cl_gui_alv_grid. 681 CLEAR g_need_refresh. 682 683 READ TABLE p_er_data_changed->mt_mod_cells WITH KEY fieldname = 'CHECKBOX' 684 TRANSPORTING NO FIELDS. 685 IF sy-subrc = 0. 686 g_need_refresh = 'X'. 687 ENDIF. 688 ENDFORM. 689 690 * DATA: ls_data TYPE REF TO data. 691 * DATA:s_matnr TYPE RANGE OF matnr. 692 * DATA:seltab TYPE TABLE OF rsparams, 693 * seltab_res TYPE TABLE OF rsparams, 694 * seltab_wa LIKE LINE OF seltab. 695 * FIELD-SYMBOLS: <lt_data> TYPE ANY TABLE,<fs_data> TYPE any . 696 * 697 * DATA:s_entity TYPE RANGE OF matnr,s_prod TYPE RANGE OF matnr,s_time TYPE RANGE OF matnr. 698 * 699 * 700 * 701 * 702 * s_entity = VALUE #( BASE s_entity FOR line_ytmd IN ot_yt_md_rela 703 * ( sign = 'I' low = line_ytmd-nodename_yt high = '' option = 'EQ' ) ). 704 * 705 * 706 * s_prod = VALUE #( BASE s_time FOR line_bl IN gt_bl_id 707 * ( sign = 'I' low = line_bl-nodename high = '' option = 'EQ' ) ). 708 * 709 ** s_time = VALUE #( BASE s_time FOR line_next_year IN gt_next_year 710 ** ( sign = 'I' low = line_next_year-z_date high = '' option = 'EQ' ) ). 711 * 712 * s_time = VALUE #( sign = 'I' option = 'EQ' ( low = con_year_inp high = '' ) ). 713 * 714 * 715 * SORT s_entity BY low. 716 * DELETE ADJACENT DUPLICATES FROM s_entity COMPARING low. 717 * 718 * CALL METHOD cl_salv_bs_runtime_info=>set 719 * EXPORTING 720 * display = '' 721 * metadata = '' " 722 * data = 'X'. " 723 * 724 * SUBMIT zweight 725 * WITH i_appset = i_appset_id 726 * WITH i_appl_i = i_appl_id 727 * WITH iaccount = i_account 728 * WITH s_entity IN s_entity 729 * WITH s_prod IN s_prod 730 * WITH s_time IN s_time 731 * AND RETURN. 732 * 733 * TRY . 734 * CALL METHOD cl_salv_bs_runtime_info=>get_data_ref 735 * IMPORTING 736 * r_data = ls_data. 737 * ASSIGN ls_data->* TO <lt_data>. 738 * CATCH cx_salv_bs_sc_runtime_info. 739 * MESSAGE 'UNABLE TO RETRIEVE ALV DATA' TYPE 'E'. 740 * ENDTRY. 741 * cl_salv_bs_runtime_info=>clear_all( ). 742 * 743 * DATA gt_zppt_b001_yg TYPE TABLE OF zbpc_s_planning_sub. 744 * DATA gs_zppt_b001_yg TYPE zbpc_s_planning_sub. 745 * FIELD-SYMBOLS:<af1> TYPE any . 746 * 747 * DEFINE z_dynamic. 748 * 749 * DATA: lo_struct TYPE REF TO cl_abap_structdescr, 750 * lo_element TYPE REF TO cl_abap_elemdescr, 751 * lo_tab TYPE REF TO cl_abap_tabledescr, 752 * lt_comps TYPE cl_abap_structdescr=>component_table, 753 * ls_comp LIKE LINE OF lt_comps. 754 * DATA:p_strucname(32). 755 * DATA:po_data TYPE REF TO data. 756 * 757 * CLEAR:lo_tab,po_data. 758 * 759 * pt_fields = &1. 760 * p_strucname = &2 . 761 * 762 * IF p_strucname IS NOT INITIAL. 763 * lo_struct ?= cl_abap_typedescr=>describe_by_name( p_strucname ). 764 * lt_comps = lo_struct->get_components( ). 765 * ENDIF. 766 * 767 * LOOP AT pt_fields INTO ls_field. 768 * DATA(lv_tabix) = sy-tabix. 769 * ls_comp-name = ls_field-fieldname. 770 * lo_element ?= cl_abap_elemdescr=>describe_by_name( ls_field-rollname ). 771 * ls_comp-type ?= lo_element. 772 * INSERT ls_comp INTO lt_comps INDEX lv_tabix. 773 ** APPEND ls_comp TO lt_comps. 774 * ENDLOOP. 775 * 776 * lo_struct = cl_abap_structdescr=>create( lt_comps ). 777 * lo_tab = cl_abap_tabledescr=>create( p_line_type = lo_struct 778 * p_table_kind = cl_abap_tabledescr=>tablekind_std 779 * p_unique = abap_false ). 780 * 781 ** 创建动态内表 782 * CREATE DATA po_data TYPE HANDLE lo_tab. 783 * 784 * REFRESH: pt_fields[]. 785 * END-OF-DEFINITION. 786 * TYPES:BEGIN OF ty_dynamic_table_field, 787 * fieldname TYPE fieldname, 788 * rollname TYPE rollname, 789 * END OF ty_dynamic_table_field. 790 * DATA:ls_zabap_dynamic_table_field TYPE ty_dynamic_table_field. 791 * DATA: pt_fields TYPE TABLE OF ty_dynamic_table_field, 792 * ls_field TYPE ty_dynamic_table_field. 793 * DATA: lo_data TYPE REF TO data, 794 * lo_line TYPE REF TO data. 795 * FIELD-SYMBOLS:<gt_alv> TYPE table,<gs_alv> TYPE any,<fs> TYPE any . 796 * 797 * pt_fields = VALUE #( ( fieldname = 'Z_ENTITY' rollname = 'CHAR32' ) 798 * ( fieldname = 'Z_PRODUCT' rollname = 'CHAR32' ) ). 799 * 800 * z_dynamic pt_fields 'ZBPC_S_CALCULATE' . 801 * 802 **&---------------------------------------------------------------------* 803 * 804 **&---------------------------------------------------------------------* 805 * DATA : w_it_field TYPE abap_sortorder_tab, 806 * w_str_field TYPE abap_sortorder. 807 * FIELD-SYMBOLS:<fs_signeddata> TYPE any . 808 * FIELD-SYMBOLS:<fs_act> TYPE any . 809 * FIELD-SYMBOLS:<fs_z_entity> TYPE any . 810 * FIELD-SYMBOLS:<fs_z_product> TYPE any . 811 * FIELD-SYMBOLS:<fs_z_entity_o> TYPE any . 812 * FIELD-SYMBOLS:<fs_z_product_o> TYPE any . 813 * ASSIGN po_data->* TO <gt_alv>. 814 * 815 * CREATE DATA lo_line LIKE LINE OF <gt_alv>. 816 * ASSIGN lo_line->* TO <gs_alv>. 817 * 818 * 819 * IF <lt_data>[] IS NOT INITIAL. 820 ** DELETE <lt_data>[] WHERE z_category eq |ACT&FCS|. 821 * w_it_field = VALUE #( ( name = 'Z_ENTITY' descending = '' ) ( name = 'Z_PRODUCT' descending = '' ) ). 822 * 823 * SORT <lt_data> BY (w_it_field). 824 * 825 * LOOP AT <lt_data> ASSIGNING <fs_data>. 826 * 827 * ASSIGN COMPONENT 'Z_ENTITY' OF STRUCTURE <fs_data> TO <fs_z_entity>. 828 * IF <fs_z_entity> IS ASSIGNED AND <fs_z_entity> IS NOT INITIAL. 829 * ASSIGN COMPONENT 'Z_ENTITY' OF STRUCTURE <gs_alv> TO <fs_z_entity_o>. 830 * <fs_z_entity_o> = <fs_z_entity>. 831 * ENDIF. 832 * 833 * ASSIGN COMPONENT 'Z_PRODUCT' OF STRUCTURE <fs_data> TO <fs_z_product>. 834 * IF <fs_z_entity> IS ASSIGNED AND <fs_z_entity> IS NOT INITIAL. 835 * ASSIGN COMPONENT 'Z_PRODUCT' OF STRUCTURE <gs_alv> TO <fs_z_product_o>. 836 * <fs_z_product_o> = <fs_z_product>+0(8) && |.INP|. 837 * ENDIF. 838 * 839 * ASSIGN COMPONENT 'SIGNEDDATA' OF STRUCTURE <fs_data> TO <fs_signeddata>. 840 * IF <fs_signeddata> IS ASSIGNED AND <fs_signeddata> IS NOT INITIAL. 841 * ASSIGN COMPONENT 'Z_ACT' OF STRUCTURE <gs_alv> TO <fs_act>. 842 * <fs_act> = <fs_signeddata>. 843 * ENDIF. 844 * 845 ** COLLECT <gs_alv> inTO <gt_alv>. 846 * APPEND <gs_alv> TO <gt_alv>. 847 * UNASSIGN :<fs_act>,<fs_z_entity>,<fs_z_product>. 848 * CLEAR:<gs_alv>. 849 * ENDLOOP. 850 * 851 * ENDIF.