ABAP 获取屏幕字段值,field-symbols,assign..TO.. 相关知识实例

ABAP  获取屏幕字段值,field-symbols,assign..TO.. 相关知识实例

以QA32质量放行程序为例子:

ABAP 获取屏幕字段值,field-symbols,assign..TO.. 相关知识实例_第1张图片

由于这个两个值都在结构RQEVA中,为了方便这里获取整个结构值,最后利用指针指向这个程序的这个结构即可获取当前值,具体写法如下:

program zqme_check_at_qa11.
form check_ud using new_insplot type qals ud_data type qave.
  data: lv_aufnr type qals-aufnr.
  data: lt_status type table of jstat.
  data: ls_status type jstat.
  data: lv_objnr type jsto-objnr.
  data: lt_mseg type table of mseg.

  data: lt_mch1   type table of mch1,
        ls_mch1   type mch1,
        lv_value  type c,
        lv_valuef type c.
"获取屏幕字段值     
  data lc_string(25) value '(SAPMQEVA)RQEVA-ZUS_NEU_N'.
  data lc_string_f(25) value '(SAPMQEVA)RQEVA-US_NEU_F'.
  data lc_string_d(25) value '(SAPMQEVA)RQEVA-MHD_01'.
  data lc_string_e(25) value '(SAPMQEVA)RQEVA-VCODE'.
  data lc_string_g(25) value '(SAPMQEVA)QALS-MATNR'. "程序+表+字段

  data: lv_auth type rqeva-zus_neu_n.
  data: lt_qmel type table of qmel.
  data: ls_qmel type qmel.
  data: lv_charg type qals-charg.
  data: lt_tj02t type table of tj02t,
        ls_tj02t type tj02t.

"获取屏幕字段值,类1. FIELD-SYMBOLS:FIELD-SYMBOLS 是一个关键字,用于声明一个指针变量,允许在运行时指向内存中的"某个数据对象。通过 FIELD-SYMBOLS,可以在不提前指定具体变量名的情况下,将一个"变量看作指针,并在运行时动态绑定到数据对象。
  field-symbols:  type any.
  field-symbols:  type any.
  field-symbols:  type any.
  field-symbols:  type any.
  field-symbols:  type any.  
"通过变量名动态访问变量2. ASSIGN:
ASSIGN 是一个指令语句,用于将一个数据对象的引用分配给 FIELD-SYMBOLS 变量。在运行时,使用 ASSIGN 将数据对象分配给 FIELD-SYMBOLS 变量后,就可以通过 FIELD-SYMBOLS 变量直接访问和操作数据对象。示例:
  assign (lc_string) to  .
  assign (lc_string_f) to  .
  assign (lc_string_d) to .
  assign (lc_string_e) to .
  assign (lc_string_g) to .   

  clear:lv_auth,
        lv_value,
        lv_valuef.

  if  is assigned."restricted
    lv_value = .
  endif.

  if  is assigned."unrestricted
    lv_valuef = .
  endif.

data ls_mara type mara.
data ls_zmmt002 type zmmt002.
  clear ls_mara.
 clear  ls_zmmt002.

  check new_insplot-charg is not initial.

  if  is assigned and  = 'X'. "非限制状态
    if ud_data-vcode = 'X'."vcode = 'X' 表示限制放行
      message e009(zqm01).
    endif.
  endif.

  if  is assigned and  = 'X'."限制状态

    if ud_data-vcode = 'A'."表示非限制放行
      message e001(zqm01).
    endif.
  endif.


  clear ls_mara.
  select single * from mara into ls_mara where matnr = new_insplot-matnr.
  if ls_mara-mtart = 'ZXXX'and ud_data-vcode is initial ."
    message e002(zqm01).
  endif.

  check ud_data-vcode = 'A'.

  cl_salv_bs_runtime_info=>set( exporting display  = abap_false
                                            metadata = abap_false
                                            data     = abap_true ).
  field-symbols: type any table,
                   type any. "LIKE LINE OF  IT_TAB
  data:gr_data type ref to data.
  clear gr_data.
  unassign .

  submit zqmr_003                                         "LX02
    with pa_charg eq new_insplot-charg
    and return.

  try.
      cl_salv_bs_runtime_info=>get_data_ref( importing r_data = gr_data ).

      assign gr_data->* to .
    catch cx_salv_bs_sc_runtime_info.
  endtry.

  cl_salv_bs_runtime_info=>clear_all( ).

  data: lt_data type table of zqms_batchtrace,
        ls_data type zqms_batchtrace.

  refresh: lt_data.

  if  is assigned.
    unassign .
    loop at  assigning .
      clear ls_data.
      ls_data = .
      if ( ls_data-zustd = '批量限制' 
or ls_data-zustd = 'Batch limit' )

          and ls_data-charg ne new_insplot-charg.
        message e010(zqm01) with ls_data-charg .
        exit.
      endif.
      if ls_data-qmnum ne '' and ls_data-zflag = 'X'
          and ls_data-charg ne ''.

        message e005(zqm01) with ls_data-qmnum .
        exit.
      endif.
    endloop.
    unassign .
  endif.

  check ud_data-vcode = 'A'.
  call function 'ZQM_ECC_UPDATE_BATCH' " IN UPDATE TASK
    exporting
      is_insplot = new_insplot.

endform.

 form update_batch using new_insplot type qals .
  check new_insplot-charg is not initial.
  set update task local .
  call function 'ZQM_ECC_UPDATE_BATCH' in update task
    exporting
      is_insplot = new_insplot.

endform.

你可能感兴趣的:(ABAP,QA32,ABAP)