当前位置:网站首页>SAP ooalv-sd module actual development case (add, delete, modify and check)
SAP ooalv-sd module actual development case (add, delete, modify and check)
2022-07-29 08:37:00 【Boating in rainy days】
SAP OOALV-SD Module practical development case ( Additions and deletions )
The small white abap Development , The code is more like Grandma's foot binding, which is smelly and long . In short, basic code functions can be realized , The code will also be optimized later , Welcome to discuss .
function : According to the selection screen , Getting different dimensions is my data , In accordance with the button to achieve different functions
The main program
REPORT zsdt0001 MESSAGE-ID z_sd_01.
INCLUDE zsdt0001_top.
INCLUDE zsdt0001_form.
INCLUDE zsdt0001_pai.
INCLUDE zsdt0001_pbo.
INITIALIZATION.
" PERFORM frm_check_authority . " Permission check
START-OF-SELECTION.
PERFORM frm_get_data. " get data END-OF-SELECTION. SET PF-STATUS '0100'. " Set up gui state
IF gt_year IS NOT INITIAL OR gt_prod IS NOT INITIAL OR gt_prom IS NOT INITIAL.
CALL SCREEN 0100 . " Display the data
ELSE.
MESSAGE s000 DISPLAY LIKE 'E'.
ENDIF.
zsdt0001_top
DATA: gt_year TYPE TABLE OF ztsd004, " year gt_prom TYPE TABLE OF ztsd005, " Sales promotion
gt_prod TYPE TABLE OF ztsd006, " product gs_year TYPE ztsd004, gs_prom TYPE ztsd005, gs_prod TYPE ztsd006. *OOALV DATA: gs_layout TYPE lvc_s_layo, gt_fieldcat TYPE lvc_t_fcat, gs_fieldcat TYPE lvc_s_fcat. DATA gs_stable TYPE lvc_s_stbl. " Fix
DATA STYLELIN TYPE LVC_S_STYL.
DATA gs_alv TYPE REF TO cl_gui_alv_grid .
DATA gs_parent TYPE REF TO cl_gui_custom_container.
DATA ok_code TYPE sy-ucomm .
DATA g_toolbar TYPE ui_functions.
" Macro definition DEFINE m_fcat. CLEAR gs_fieldcat. gs_fieldcat-fieldname = &1. " Field id
gs_fieldcat-scrtext_l = &2. " Field description gs_fieldcat-checkbox = &3 . " Check box
" gs_fieldcat-edit = &4. " Editable or not
* Search for help
* The search help here needs to be in se11 Can only be used here after being defined in
IF onl1 = 'X'.
gs_fieldcat-ref_table = 'ZTSD004'. " Transparent table gs_fieldcat-txt_field = 'MVGR1'. " Field
ELSEIF onl2 = 'X'.
gs_fieldcat-ref_table = 'ZTSD005'.
gs_fieldcat-txt_field = 'KDGRP'.
gs_fieldcat-txt_field = 'MVGR1'.
gs_fieldcat-txt_field = 'KONDA'.
ELSEIF onl3 = 'X'.
gs_fieldcat-ref_table = 'ZTSD006'.
gs_fieldcat-txt_field = 'KONDA'.
gs_fieldcat-txt_field = 'KDGRP'.
ENDIF.
APPEND gs_fieldcat TO gt_fieldcat .
END-OF-DEFINITION.
* Select screen
SELECTION-SCREEN BEGIN OF BLOCK bo2 WITH FRAME TITLE TEXT-002.
PARAMETERS : onl1 RADIOBUTTON GROUP rept , " year onl2 RADIOBUTTON GROUP rept, " Sales promotion
onl3 RADIOBUTTON GROUP rept. " product
SELECTION-SCREEN END OF BLOCK bo2.

Screen creation
1. Logical flow
PROCESS BEFORE OUTPUT.
* call gui
MODULE STATUS_0100.
* call ooalv
MODULE INIT_ALV .
*
PROCESS AFTER INPUT.
* Exit button
MODULE exit at exit-command .
* Button function
MODULE USER_COMMAND_0100.
2. Element list 
3. Layout
This container is used to store alv The effect of the display 
ZSDT0001_PBO
*&---------------------------------------------------------------------*
*& contain ZSDT0001_PBO
*&---------------------------------------------------------------------*
MODULE init_alv OUTPUT.
IF gs_alv IS INITIAL.
PERFORM creat_alv.
PERFORM frm_init_fieldcat. " Set the output screen ALV Output fields PERFORM frm_init_layout. " Set the output screen ALV Display format
PERFORM frm_display_alv. " call ALV Display function displays data ELSE. PERFORM refresh_alv . " The refresh screen
ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS '0100'. "gui state
SET TITLEBAR '0100'.
ENDMODULE.
ZSDT0001_PAI
*&---------------------------------------------------------------------*
*& contain ZSDT0001_PAI
*&---------------------------------------------------------------------*
MODULE exit INPUT.
LEAVE PROGRAM .
ENDMODULE.
" Button function MODULE user_command_0100 INPUT. CASE OK_CODE. WHEN 'BACK'. LEAVE TO SCREEN 0 . WHEN 'EXIT' OR 'CANCEL'. LEAVE PROGRAM . WHEN '&SAVE'. PERFORM frm_save_data. " Save the data
WHEN '&DELE'.
PERFORM frm_delete_data. " Delete data * WHEN '&DAM'. * PERFORM frm_disp_edit. " Show <-> modify
ENDCASE.
ENDMODULE.
ZSDT0001_FORM
*&---------------------------------------------------------------------*
*& contain ZSDT0001_FORM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form frm_get_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text I'm really convinced
*&---------------------------------------------------------------------*
FORM frm_get_data .
" according to fs Field reference to get the corresponding data IF onl1 = 'X'. " year
SELECT * FROM ztsd004
* INNER JOIN tvm1t ON ztsd004~bezei = tvm1t~bezei
INTO CORRESPONDING FIELDS OF TABLE gt_year.
ELSEIF onl2 = 'X'.
" Sales promotion SELECT * FROM ztsd005 * INNER JOIN t188t ON ztsd005~vtext = t188t~vtext * INNER JOIN t151t ON ztsd005~ktext = t151t~ktext * INNER JOIN tvm1t ON ztsd005~bezei = tvm1t~bezei INTO CORRESPONDING FIELDS OF TABLE gt_prom. ELSEIF onl3 = 'X'. " product
SELECT * FROM ztsd006
* INNER JOIN t188t ON ztsd006~vtext = t188t~vtext
* INNER JOIN t151t ON ztsd006~ktext = t151t~ktext
* INNER JOIN makt ON ztsd006~maktx = makt~maktx
INTO CORRESPONDING FIELDS OF TABLE gt_prod.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_init_layout
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_init_layout .
gs_layout-cwidth_opt = 'X'.
gs_layout-zebra = 'X'." Color alternation . gs_layout-edit = 'X'. " modify
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_init_fieldcat
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_init_fieldcat ." Macro definition CLEAR gs_fieldcat. " Annual field display
IF onl1 = 'X'.
m_fcat:
'MJAHR' ' year ' '' ,
'MVGR1' ' Series code ' '' ,
'BEZEI' ' Series name ' '' ,
'PRICE' ' Rebate unit price ' '' ,
'ERNAM' ' founder ' '' ,
'AUDAT' ' Date of creation ' '' ,
'ZERNAM' ' Auditor ' '' ,
'ANGDT' ' Audit date ' '' ,
'STATE' ' state ' '' ,
'ZTIME' ' Update time ' '' .
APPEND gs_fieldcat TO gt_fieldcat .
ELSEIF onl2 = 'X'.
m_fcat:
'MJAHR' ' year ' '' ,
'KDGRP' ' Customer classification ' '' ,
'MVGR1' ' Series code ' '' ,
'KONDA' ' Promotion type ' '' ,
'VTEXT' ' Promotion type description ' '' ,
'KTEXT' ' Customer classification name ' '' ,
'BEZEI' ' Series name ' '' ,
'PRICE' ' Rebate unit price ' '' ,
'ERNAM' ' founder ' '' ,
'AUDAT' ' Date of creation ' '' ,
'ZERNAM' ' Auditor ' '' ,
'ANGDT' ' Audit date ' '' ,
'STATE' ' state ' '' ,
'ZTIME' ' Update time ' '' .
APPEND gs_fieldcat TO gt_fieldcat .
ELSEIF onl3 = 'X'.
m_fcat:
'MJAHR' ' year ' '' ,
'KONDA' ' Promotion type ' '' ,
'VTEXT' ' Promotion type description ' '' ,
'KDGRP' ' Customer classification ' '' ,
'KTEXT' ' Customer classification name ' '' ,
'MANTR' ' Product code ' '' ,
'MAKTX' ' The product name ' '' ,
'PRICE' ' Rebate unit price ' '' ,
'ERNAM' ' founder ' '' ,
'AUDAT' ' Date of creation ' '' ,
'ZERNAM' ' Auditor ' '' ,
'ANGDT' ' Audit date ' '' ,
'STATE' ' state ' '' ,
'ZTIME' ' Update time ' '' .
APPEND gs_fieldcat TO gt_fieldcat .
ENDIF.
PERFORM frm_toolbar .
ENDFORM.
* Close to alv Some buttons on
FORM frm_toolbar .
REFRESH g_toolbar.
PERFORM append_alv_exclude_functions TABLES g_toolbar USING:
cl_gui_alv_grid=>mc_fc_reprep ,
cl_gui_alv_grid=>mc_fc_check ,
cl_gui_alv_grid=>mc_mb_export ,
cl_gui_alv_grid=>mc_fc_detail ,
* cl_gui_alv_grid=>mc_fc_refresh ,
cl_gui_alv_grid=>mc_fc_graph ,
cl_gui_alv_grid=>mc_fc_loc_undo ,
cl_gui_alv_grid=>mc_fc_loc_delete_row ,
cl_gui_alv_grid=>mc_fc_loc_insert_row ,
cl_gui_alv_grid=>mc_fc_loc_copy_row ,
cl_gui_alv_grid=>mc_fc_loc_cut ,
cl_gui_alv_grid=>mc_fc_loc_append_row ,
cl_gui_alv_grid=>mc_fc_loc_paste_new_row ,
cl_gui_alv_grid=>mc_fc_info ,
cl_gui_alv_grid=>mc_fc_loc_copy ,
cl_gui_alv_grid=>mc_fc_loc_paste ,
cl_gui_alv_grid=>mc_fc_print ,
cl_gui_alv_grid=>mc_mb_sum ,
cl_gui_alv_grid=>mc_mb_view ,
cl_gui_alv_grid=>mc_fc_current_variant ,
cl_gui_alv_grid=>mc_fc_save_variant ,
cl_gui_alv_grid=>mc_fc_load_variant ,
cl_gui_alv_grid=>mc_fc_maintain_variant ,
cl_gui_alv_grid=>mc_fc_deselect_all ,
cl_gui_alv_grid=>mc_fc_select_all .
ENDFORM.
FORM append_alv_exclude_functions TABLES pt_exclude TYPE ui_functions
USING p_value TYPE ui_func.
APPEND p_value TO pt_exclude.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_display_alv
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_display_alv .
IF onl1 = 'X'.
CALL METHOD gs_alv->set_table_for_first_display
EXPORTING
it_toolbar_excluding = g_toolbar
is_layout = gs_layout
CHANGING
it_outtab = gt_year " Outgoing table it_fieldcatalog = gt_fieldcat " Form column format
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
ELSEIF onl2 = 'X'.
CALL METHOD gs_alv->set_table_for_first_display
EXPORTING
it_toolbar_excluding = g_toolbar
is_layout = gs_layout
CHANGING
it_outtab = gt_prom " Outgoing table it_fieldcatalog = gt_fieldcat " Form column format
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
ELSEIF onl3 = 'X'.
CALL METHOD gs_alv->set_table_for_first_display
EXPORTING
it_toolbar_excluding = g_toolbar
is_layout = gs_layout
CHANGING
it_outtab = gt_prod " Outgoing table it_fieldcatalog = gt_fieldcat " Form column format
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
ENDIF.
ENDFORM.
FORM creat_alv .
CREATE OBJECT gs_parent
EXPORTING
container_name = 'GC_CON'. " In the interface cunstomer control Control name * take lav Pour into the container CREATE OBJECT gs_alv EXPORTING i_parent = gs_parent. ENDFORM. *&---------------------------------------------------------------------* *& Form refresh_alv *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM refresh_alv . gs_stable-row = 'X'. gs_stable-col = 'X'. CALL METHOD gs_alv->refresh_table_display EXPORTING is_stable = gs_stable * i_soft_refresh = EXCEPTIONS finished = 1 OTHERS = 2. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form frm_save_data *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_save_data . DATA: gt_tmp_4 TYPE TABLE OF ztsd004. DATA: gt_tmp_5 TYPE TABLE OF ztsd005. DATA: gt_tmp_6 TYPE TABLE OF ztsd006. DATA flg TYPE c LENGTH 1. " Modifying data -> Data obtained from the internal table -> Add import database ->
"1. Add success -> Modify the status and reviewer -> modify to examine There is a database -> The return message is successful IF onl1 = 'X'. MODIFY ztsd004 FROM TABLE gt_year . SELECT * FROM ztsd004 INTO CORRESPONDING FIELDS OF TABLE gt_tmp_4. CALL FUNCTION 'CTVB_COMPARE_TABLES_3' EXPORTING it_table_old = gt_tmp_4 it_table_new = gt_year iv_key_count = 100 IMPORTING ev_no_changes = flg. IF flg = 'X'. MESSAGE s001 DISPLAY LIKE 'S'. EXIT. ELSE . MESSAGE e002 DISPLAY LIKE 'E'. EXIT . ENDIF. CLEAR : flg, gt_tmp_4. ELSEIF onl2 = 'X'. MODIFY ztsd005 FROM TABLE gt_prom . SELECT * FROM ztsd005 INTO CORRESPONDING FIELDS OF TABLE gt_tmp_5. CALL FUNCTION 'CTVB_COMPARE_TABLES_3' EXPORTING it_table_old = gt_tmp_5 it_table_new = gt_prom iv_key_count = 100 IMPORTING ev_no_changes = flg. IF flg = 'X'. MESSAGE s001 DISPLAY LIKE 'S'. EXIT. ELSE . MESSAGE e002 DISPLAY LIKE 'E'. EXIT . ENDIF. CLEAR : flg, gt_tmp_5. ELSEIF onl3 = 'X'. MODIFY ztsd006 FROM TABLE gt_prod . SELECT * FROM ztsd006 INTO CORRESPONDING FIELDS OF TABLE gt_tmp_6. CALL FUNCTION 'CTVB_COMPARE_TABLES_3' EXPORTING it_table_old = gt_tmp_6 it_table_new = gt_prod iv_key_count = 100 IMPORTING ev_no_changes = flg. IF flg = 'X'. MESSAGE s001 DISPLAY LIKE 'S'. EXIT. ELSE . MESSAGE e002 DISPLAY LIKE 'E'. EXIT . ENDIF. CLEAR : flg, gt_tmp_6. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form frm_delete_data *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_delete_data . *1. Get the selected line number *2. Send the selected data to another internal table *3. Delete the selected line number *4. Delete database " Delete
DATA lt_select TYPE lvc_t_row.
DATA gt_del4 TYPE TABLE OF ztsd004.
DATA gt_del5 TYPE TABLE OF ztsd005.
DATA gt_del6 TYPE TABLE OF ztsd006.
DATA gs_del4 LIKE LINE OF gt_del4.
DATA gs_del5 LIKE LINE OF gt_del5.
DATA gs_del6 LIKE LINE OF gt_del6.
* DATA ls_del LIKE LINE OF gt_del.
CALL METHOD gs_alv->get_selected_rows
IMPORTING
et_index_rows = lt_select.
IF onl1 = 'X'.
LOOP AT lt_select INTO DATA(ls_select4).
READ TABLE gt_year INTO gs_year INDEX ls_select4-index.
IF sy-subrc = 0.
MOVE-CORRESPONDING gs_year TO gs_del4.
gs_del4-ztime = 'X'.
APPEND gs_del4 TO gt_del4.
CLEAR gs_del4.
ENDIF.
DELETE gt_year INDEX ls_select4-index.
DELETE ztsd004 FROM TABLE gt_del4 .
IF sy-subrc = 0.
MESSAGE s003 DISPLAY LIKE 'S'.
ELSE.
MESSAGE e004 DISPLAY LIKE 'E'.
ENDIF.
ENDLOOP.
ELSEIF onl2 = 'X'.
LOOP AT lt_select INTO DATA(ls_select5).
READ TABLE gt_prom INTO gs_prom INDEX ls_select5-index.
IF sy-subrc = 0.
MOVE-CORRESPONDING gs_prom TO gs_del5.
gs_del5-ztime = 'X'.
APPEND gs_del5 TO gt_del5.
CLEAR gs_del5.
ENDIF.
DELETE gt_prom INDEX ls_select5-index.
DELETE ztsd005 FROM TABLE gt_del5 .
IF sy-subrc = 0.
MESSAGE s003 DISPLAY LIKE 'S'.
ELSE.
MESSAGE e004 DISPLAY LIKE 'E'.
ENDIF.
ENDLOOP.
ELSEIF onl3 = 'X'.
LOOP AT lt_select INTO DATA(ls_select6).
READ TABLE gt_prod INTO gs_prod INDEX ls_select6-index. " Get the selected line number IF sy-subrc = 0. MOVE-CORRESPONDING gs_prod TO gs_del6. gs_del6-ztime = 'X'. APPEND gs_del6 TO gt_del6. CLEAR gs_del6. ENDIF. DELETE gt_prod INDEX ls_select6-index." Delete ooalv Show
DELETE ztsd006 FROM TABLE gt_del6 . " Delete from database IF sy-subrc = 0. MESSAGE s003 DISPLAY LIKE 'S'. ELSE. MESSAGE e004 DISPLAY LIKE 'E'. ENDIF. ENDLOOP. ENDIF. PERFORM refresh_alv . " Refresh
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_check_authority
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_check_authority .
* AUTHORITY-CHECK OBJECT 'ZQM06_WERK'
* ID 'WERKS' FIELD p_werks.
* IF sy-subrc <> 0.
* MESSAGE e036(zsy_qm_dev) WITH p_werks.
* ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_disp_edit
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
*FORM frm_disp_edit .
* STYLELIN-FIELDNAME = 'ZBQFS'. " Column name to edit * STYLELIN-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED. " Set to non editable
* CLEAR STYLELIN.
*ENDFORM.
effect

边栏推荐
- The first week of postgraduate freshman training: deep learning and pytorch Foundation
- 集群使用规范
- [opencv] - Operator (Sobel, canny, Laplacian) learning
- ROS common instructions
- Classic interview question: = = the difference between equals
- QT version of Snake game project
- What constitutes the smart charging pile system?
- Week 1 task deep learning and pytorch Foundation
- How to quickly experience oneos
- Four pin OLED display based on stm32
猜你喜欢

Day6: using PHP to write landing pages

Simulation of four way responder based on 51 single chip microcomputer

Temperature acquisition and control system based on WiFi

谷歌浏览器免跨域配置

C language function output I love you

pnpm install出现:ERR_PNPM_PEER_DEP_ISSUES Unmet peer dependencies

Chrony time synchronization

Chrony 时间同步

Hal learning notes - Advanced timer of 7 timer

DC motor control system based on DAC0832
随机推荐
Analysis of zorder sampling partition process in Hudi - "deepnova developer community"
[[first blog]p controller implementation instructions in UDA course]
Inclination sensor is used for long-term monitoring of communication tower and high-voltage tower
Intelligent shelf safety monitoring system
Several ways of debugging support under oneos
What is the working principle of the noise sensor?
110道 MySQL面试题及答案 (持续更新)
Intelligent temperature control system
The first week of postgraduate freshman training: deep learning and pytorch Foundation
Day4: the establishment of MySQL database and its simplicity and practicality
The computer video pauses and resumes, and the sound suddenly becomes louder
Component transfer participation lifecycle
【OpenCV】-算子(Sobel、Canny、Laplacian)学习
Noise monitoring and sensing system
LeetCode力扣题目总结(题目编号:53、3、141、面试题022、剑指offer链表中环的入口节点、20、19、牛客NC1、103、1143、牛客127)
commonjs导入导出与ES6 Modules导入导出简单介绍及使用
What constitutes the smart charging pile system?
access数据库可以被远程访问吗
深度学习(2):图片文字识别
为了速率创建线程池,启动核心线程