ABAP SM30 Table Maintenance Program field is automatically assigned

background

SM30 table maintenance program during use, and often need to modify some autocomplete value, the more conventional approach is to modify the logic flow screen, but if the SM30 reactivated, then the logic flow will overwrite, relatively trouble, prior to contacting table maintenance program over the 'incident', emerging from the study of the following methods

principle

Event number Event function
01 Modify the data before saving
05 When you create a data modification
21 When exit cell editing filling hidden fields

step

1, generated table maintenance procedures, and recommends a maintenance view, set the read only field

2, respectively, for the event to create a subroutine (01 events, pay attention to the variable component of ACTION total, change field attribute tag for entry)

3, to achieve the following code, can be adjusted according to actual needs

In this case the version number ZZVER modify each time, is incremented by one, so in event 01, the other fields are used to record real-time reception, which can also be written to the 01 events

*&---------------------------------------------------------------------*
*&  新增条目事件
*&----------------------------------------------------------------------
form sub_new_entry.

  assign component 'CREATED_BY' of structure <table1> to field-symbol(<fs_field>).
  if <fs_field> is assigned and <fs_field> is initial.
    <fs_field> = sy-uname.
    unassign <fs_field>.
  endif.

  assign component 'CREATED_ON' of structure <table1> to <fs_field>.
  if <fs_field> is assigned.
    <fs_field> = sy-datum.
    unassign <fs_field>.
  endif.

  assign component 'CREATED_AT' of structure <table1> to <fs_field>.
  if <fs_field> is assigned.
    <fs_field> = sy-uzeit.
    unassign <fs_field>.
  endif.

  "  assign component 'ZZVER' of structure <table1> to <fs_field>.
  "  if <fs_field> is assigned.
  "    <fs_field> = 1.
  "    unassign <fs_field>.
  "  endif.

endform.
*&---------------------------------------------------------------------*
*&  修改条目事件
*&----------------------------------------------------------------------
form sub_change_entry.

  "check sy-ucomm eq 'SAVE'.

  "  检查当前行是否为新增行
  read table total with key <f1_x>.
  check sy-subrc eq 0.
  assign component 'ACTION' of structure total to field-symbol(<fs_action>).
  if sy-subrc eq 0 and <fs_action> ne 'N'."不是新增行则继续 .

    assign component 'CHANGED_BY' of structure <table1> to field-symbol(<fs_field>).
    if <fs_field> is assigned.
      <fs_field> = sy-uname.
      unassign <fs_field>.
    endif.

    assign component 'CHANGED_ON' of structure <table1> to <fs_field>.
    if <fs_field> is assigned.
      <fs_field> = sy-datum.
      unassign <fs_field>.
    endif.

    assign component 'CHANGED_AT' of structure <table1> to <fs_field>.
    if <fs_field> is assigned.
      <fs_field> = sy-uzeit.
      unassign <fs_field>.
    endif.

    "    assign component 'ZZVER' of structure <table1> to <fs_field>.
    "    if <fs_field> is assigned.
    "      <fs_field> =  conv i( <fs_field> ) + 1.
    "      CONDENSE <fs_field>.
    "    endif.
  endif.

endform.
form sub_before_save.

  "自动版本号修改
  loop at zmdgv_dms_div_total.
    read table total index sy-tabix.
    assign component 'ACTION' of structure total to field-symbol(<fs_field>).
    if sy-subrc eq 0.
      check <fs_field> eq 'N' or <fs_field> eq 'U'.
    endif.

    if zmdgv_dms_div_total-zzver is initial.
      zmdgv_dms_div_total-zzver = 1.
    else.
      zmdgv_dms_div_total-zzver = zmdgv_dms_div_total-zzver + 1.
    endif.

    condense zmdgv_dms_div_total-zzver.
    modify zmdgv_dms_div_total.
  endloop.
endform.

Remark

View cluster maintenance need to convert the total variable, contact QQ: 2212332116

 

Guess you like

Origin blog.csdn.net/u012232542/article/details/90925845