其他分享
首页 > 其他分享> > ABAP-SM30维护视图

ABAP-SM30维护视图

作者:互联网

关于SM30维护视图的一些操作

EVENT视图事件(如:在保存,删除数据前做一些自定义操作)

 

 

 

*&---------------------------------------------------------------------*
*& 包含               ZBC_I_SM30_LOG
*&---------------------------------------------------------------------*

DEFINE assign_field.

  ASSIGN COMPONENT &1 OF STRUCTURE <ls_maintview> TO <lv_field>.
  IF sy-subrc = 0.
    IF <lv_field> IS ASSIGNED.
      <lv_field> = &2.
    ENDIF.
  ENDIF.

END-OF-DEFINITION.

FORM create_entry.

  FIELD-SYMBOLS:
    <ls_maintview> TYPE any,
    <lv_field>     TYPE any.

  CHECK x_header-maintview IS NOT INITIAL.

  ASSIGN (x_header-maintview) TO <ls_maintview>.
  CHECK sy-subrc = 0.
  CHECK <ls_maintview> IS ASSIGNED.

  assign_field 'CREATED_DATE' sy-datum.
  assign_field 'CREATED_TIME' sy-uzeit.
  assign_field 'CREATED_USER' sy-uname.

ENDFORM.

FORM change_entry.

  DATA:
    lo_data  TYPE REF TO data,
    lv_tabix TYPE sy-tabix.

  FIELD-SYMBOLS:
    <ls_maintview> TYPE any,
    <lv_field>     TYPE any.

  IF x_header-maintview IS NOT INITIAL.
    CREATE DATA lo_data TYPE (x_header-maintview).
    IF lo_data IS BOUND.
      ASSIGN lo_data->* TO <ls_maintview>.
    ENDIF.
    IF <ls_maintview> IS ASSIGNED.
      IF <action> = 'U'.
        LOOP AT total.
          READ TABLE extract WITH KEY <vim_xtotal_key>.
          IF sy-subrc = 0.
            lv_tabix = sy-tabix.
          ELSE.
            CONTINUE.
          ENDIF.
          IF <action> = 'U'.
            CLEAR <ls_maintview>.
            MOVE-CORRESPONDING <vim_total_struc> TO <ls_maintview>.
            assign_field 'CHANGED_DATE' sy-datum.
            assign_field 'CHANGED_TIME' sy-uzeit.
            assign_field 'CHANGED_USER' sy-uname.
            MOVE-CORRESPONDING <ls_maintview> TO <vim_total_struc>.
            MODIFY total.
            extract = total.
            MODIFY extract INDEX lv_tabix.
          ENDIF.
        ENDLOOP.
      ENDIF.
    ENDIF.
  ENDIF.

  sy-subrc = 0.

ENDFORM.

PBO中,一个字段的值决定另一个字段是否可编辑

PROCESS BEFORE OUTPUT. "PBO中
  MODULE liste_initialisieren.
  LOOP AT extract WITH CONTROL
   tctrl_ytzj001 CURSOR nextline.
    MODULE liste_show_liste.
    MODULE set_screen. "自己的Module程序写在loop的最后面
  ENDLOOP.

MODULE set_screen OUTPUT.
  PERFORM set_screen.
ENDMODULE.                 " SET_SCREEN  OUTPUT

FORM set_screen .
  FIELD-SYMBOLS:<fs> LIKE LINE OF tctrl_ytzj001-cols.
  IF extract+3(30) = 123.
    LOOP AT SCREEN.
      IF screen-name = 'YTZJ001-ERDAT'.
        screen-input = 0.
        MODIFY SCREEN.
      ENDIF.
    ENDLOOP.
  ENDIF.
ENDFORM.                    " SET_SCREEN

程序中调用SM30

  DATA GT_DBA_SELLIST TYPE TABLE OF VIMSELLIST.
  DATA GT_TABNAME TYPE DD02V-TABNAME.
 
  CALL FUNCTION 'VIEW_RANGETAB_TO_SELLIST' “添加选择屏幕条件
    EXPORTING
      FIELDNAME                = 'MATKL'
      APPEND_CONJUNCTION       = 'AND'
    TABLES
      SELLIST                  = GT_DBA_SELLIST
      RANGETAB                 = S_MATKL
          .
 
 
  CALL FUNCTION 'VIEW_MAINTENANCE_CALL' ” 调用SM30函数
    EXPORTING
      ACTION                               = 'U'
      GENERATE_MAINT_TOOL_IF_MISSING       = 'X'
      VIEW_NAME                            = 'ZTCS118'
      NO_WARNING_FOR_CLIENTINDEP           = 'X' “跳过警告弹窗

    TABLES
      DBA_SELLIST                          = GT_DBA_SELLIST
    EXCEPTIONS
      CLIENT_REFERENCE                     = 1
      FOREIGN_LOCK                         = 2
      INVALID_ACTION                       = 3
      NO_CLIENTINDEPENDENT_AUTH            = 4
      NO_DATABASE_FUNCTION                 = 5
      NO_EDITOR_FUNCTION                   = 6
      NO_SHOW_AUTH                         = 7
      NO_TVDIR_ENTRY                       = 8
      NO_UPD_AUTH                          = 9
      ONLY_SHOW_ALLOWED                    = 10
      SYSTEM_FAILURE                       = 11
      UNKNOWN_FIELD_IN_DBA_SELLIST         = 12
      VIEW_NOT_FOUND                       = 13
      MAINTENANCE_PROHIBITED               = 14
      OTHERS                               = 15
            .
  IF SY-SUBRC <> 0.

  ENDIF.

程序中调用SM30,并跳过权限检查

*&---------------------------------------------------------------------*
* Program ID   : 7959
* Program Name : ZSD_RE010
* T-CODE :
* Program Type: <功能>
* Description : 品牌物料限制解除功能(调用SM30且跳过权限检查)
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zsd_re010.

*&---------------------------------------------------------------------*
*&全局变量
*&---------------------------------------------------------------------*
DATA:dba_sellist    LIKE  vimsellist OCCURS 0,
     excl_cua_funct LIKE  vimexclfun OCCURS 0,
     x_header       LIKE  vimdesc OCCURS 0 WITH HEADER LINE,
     x_namtab       LIKE  vimnamtab OCCURS 0,
     dpl_sellist    LIKE  vimsellist.

*&---------------------------------------------------------------------*
*&START-OF-SELECTION.
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  CALL FUNCTION 'VIEW_GET_DDIC_INFO'
    EXPORTING
      viewname        = 'ZTSD271_PPWL'
    TABLES
      sellist         = dba_sellist
      x_header        = x_header
      x_namtab        = x_namtab
    EXCEPTIONS
      no_tvdir_entry  = 1
      table_not_found = 2
      OTHERS          = 3.


  DATA:lockuser  TYPE sy-uname,
       answer(1) TYPE c.
  CALL FUNCTION 'VIEW_ENQUEUE'
    EXPORTING
      view_name        = 'ZTSD271_PPWL'
      action           = 'E'
      enqueue_mode     = 'E'
    EXCEPTIONS
      foreign_lock     = 1
      system_failure   = 2
      table_not_found  = 5
      client_reference = 7.

  IF sy-subrc NE 0.
    MESSAGE 'Data locked' TYPE 'S' DISPLAY LIKE 'E'.
    RETURN.
  ENDIF.


  CALL FUNCTION 'VIEW_MAINTENANCE'
    EXPORTING
      view_action               = 'U'
      view_name                 = 'ZTSD271_PPWL'
    TABLES
      dba_sellist               = dba_sellist
      excl_cua_funct            = excl_cua_funct
      x_header                  = x_header
      x_namtab                  = x_namtab
    EXCEPTIONS
      missing_corr_number       = 1
      no_database_function      = 2
      no_editor_function        = 3
      no_value_for_subset_ident = 4
      OTHERS                    = 5.

  CALL FUNCTION 'VIEW_ENQUEUE'
    EXPORTING
      view_name        = 'ZTSD271_PPWL'
      action           = 'D'
      enqueue_mode     = 'E'
    EXCEPTIONS
      foreign_lock     = 1
      system_failure   = 2
      table_not_found  = 5
      client_reference = 7.

 

标签:FUNCTION,sy,&---------------------------------------------------------------
来源: https://www.cnblogs.com/ap-ad-java-abap/p/16688184.html