ABAP MD11 / MD12 / MD13计划订单屏幕增强

Posted 狗尾巴草_lan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ABAP MD11 / MD12 / MD13计划订单屏幕增强相关的知识,希望对你有一定的参考价值。

ABAP计划订单屏幕增强,适用Tcode:MD11 MD12 MD13。

需求概述:

新增自定义字段如下:

字段名是否可编辑搜索帮助
订单类型
一模多出绑定关系号
一模多出当量
备注
ECN编号

 解题思路:

查看SAP屏幕源码,发现SAP在抬头页签预留了子屏幕SAPLCFD_SAP_GUI 1000,并且提供了不同数据类型的子屏幕,故每个字段皆是一个子屏幕,只需往全局变量里增加数据即可。

具体实现步骤:

1. 在结构CI_PLAFDB中新增字段,注意只需要添加可输入字段,即需要保存值的字段。

 2. 在类CL_CFD_SAP_GUI_CONTROLLER 方法SET_SUBSCREEN_ASSIGNMENT开始处加入隐式增强,主要是向全局表MT_CONTEXT_FIELDS中写入数据,以便下面代码输出子屏幕。

ENHANCEMENT 1  ZEHM_PP028_001.    "active version
  DATA: ls_position type i.
  IF SY-TCODE = 'MD11' OR SY-TCODE = 'MD12' OR SY-TCODE = 'MD13'.
    IF MT_CONTEXT_FIELDS IS INITIAL.
*     订单类型
      SELECT SINGLE DDTEXT
        INTO @DATA(LV_LABEL)
        FROM DD04T
       WHERE ROLLNAME   = 'AUFART'
         AND DDLANGUAGE = @SY-LANGU
         AND AS4LOCAL   = 'A'.

      DATA(LS_FIELD_METADATA) = VALUE TY_GS_FIELD_METADATA(
        POSITION                    = 1
        FIELD_NAME                  = 'ZZDAUAT'
        FIELD_TYPE                  = 'ASC_TO_STD'
        REFERENCE_FIELD_NAME        = 'ZZDAUAT'
        PERSISTENCE_FIELD_NAME      = 'ZZDAUAT'
        LENGTH                      = 4
        DDIC_TYPE                   = 'CHAR'
        LABEL                       = LV_LABEL
        SCREEN_LENGTH               = 4
        DATA_ELEMENT_NAME           = 'AUFART'
        CODE_TEXT_TABLE_NAME        = ''
        VALUE_HELP_CODE_VIEW_NAME   = 'ATPC_CDS_PLAF'
        VALUE_HELP_DATA_ELEMENT     = 'AUFART'
        ).

      LS_FIELD_METADATA-ASSIGNED_SUBSCREEN_NUMBER = GET_SUBSCREEN( IV_FIELD_TYPE    = 'ASC_TO_STD'   "ASC_TO_STD
                                                                   IV_DDIC_TYPE     = 'CHAR'
                                                                   IV_SCREEN_LENGTH = 4 ).
      APPEND LS_FIELD_METADATA TO MT_CONTEXT_FIELDS.
      CLEAR: LS_FIELD_METADATA, LV_LABEL.

*     一模多出绑定关系号
      SELECT SINGLE DDTEXT
        INTO @LV_LABEL
        FROM DD04T
       WHERE ROLLNAME   = 'ZE_YMDC'
         AND DDLANGUAGE = @SY-LANGU
         AND AS4LOCAL   = 'A'.

      LS_FIELD_METADATA = VALUE TY_GS_FIELD_METADATA(
        POSITION                    = 2
        FIELD_NAME                  = 'YMDC'
        FIELD_TYPE                  = 'TEXT'
        REFERENCE_FIELD_NAME        = 'YMDC'
        PERSISTENCE_FIELD_NAME      = 'YMDC'
        DDIC_TYPE                   = 'CHAR'
        LABEL                       = LV_LABEL
        SCREEN_LENGTH               = 10
        DATA_ELEMENT_NAME           = 'ZE_YMDC'
        IS_READ_ONLY                = ABAP_TRUE ).

        LS_FIELD_METADATA-ASSIGNED_SUBSCREEN_NUMBER = GET_SUBSCREEN( IV_FIELD_TYPE    = 'TEXT'
                                                                     IV_DDIC_TYPE     = 'CHAR'
                                                                     IV_SCREEN_LENGTH = 10 ).
        APPEND LS_FIELD_METADATA TO MT_CONTEXT_FIELDS.
        CLEAR: LS_FIELD_METADATA, LV_LABEL.

*     一模多出当量
      SELECT SINGLE DDTEXT
        INTO @LV_LABEL
        FROM DD04T
       WHERE ROLLNAME   = 'ZE_IFFR'
         AND DDLANGUAGE = @SY-LANGU
         AND AS4LOCAL   = 'A'.

      LS_FIELD_METADATA = VALUE TY_GS_FIELD_METADATA(
        POSITION                    = 3
        FIELD_NAME                  = 'ZIFFR'
        FIELD_TYPE                  = 'TEXT'
        REFERENCE_FIELD_NAME        = 'ZIFFR'
        PERSISTENCE_FIELD_NAME      = 'ZIFFR'
        DDIC_TYPE                   = 'CHAR'
        LABEL                       = LV_LABEL
        SCREEN_LENGTH               = 0003
        DATA_ELEMENT_NAME           = 'ZE_IFFR'
        IS_READ_ONLY                = ABAP_TRUE ).

      LS_FIELD_METADATA-ASSIGNED_SUBSCREEN_NUMBER = GET_SUBSCREEN( IV_FIELD_TYPE    = 'TEXT'
                                                                   IV_DDIC_TYPE     = 'CHAR'
                                                                   IV_SCREEN_LENGTH = 3 ).
      APPEND LS_FIELD_METADATA TO MT_CONTEXT_FIELDS.
      CLEAR: LS_FIELD_METADATA, LV_LABEL.

*     备注
      SELECT SINGLE DDTEXT
        INTO @LV_LABEL
        FROM DD04T
       WHERE ROLLNAME   = 'ZE_REMARK'
         AND DDLANGUAGE = @SY-LANGU
         AND AS4LOCAL   = 'A'.

      LS_FIELD_METADATA = VALUE TY_GS_FIELD_METADATA(
        POSITION                    = 4
        FIELD_NAME                  = 'ZZREMARK'
        FIELD_TYPE                  = 'TEXT'
        REFERENCE_FIELD_NAME        = 'ZZREMARK'
        PERSISTENCE_FIELD_NAME      = 'ZZREMARK'
        DDIC_TYPE                   = 'CHAR'
        LENGTH                      = 50
        LABEL                       = LV_LABEL
        SCREEN_LENGTH               = 40
        DATA_ELEMENT_NAME           = 'ZE_REMARK'
        IS_READ_ONLY                = ABAP_TRUE ).

      LS_FIELD_METADATA-ASSIGNED_SUBSCREEN_NUMBER = GET_SUBSCREEN( IV_FIELD_TYPE    = 'TEXT'
                                                                   IV_DDIC_TYPE     = 'CHAR'
                                                                   IV_SCREEN_LENGTH = 40 ).
      APPEND LS_FIELD_METADATA TO MT_CONTEXT_FIELDS.
      CLEAR: LS_FIELD_METADATA, LV_LABEL.

*     ECN编号
      SELECT SINGLE DDTEXT
        INTO @LV_LABEL
        FROM DD04T
       WHERE ROLLNAME   = 'ZE_PS_ECN_ZECN'
         AND DDLANGUAGE = @SY-LANGU
         AND AS4LOCAL   = 'A'.

      LS_FIELD_METADATA = VALUE TY_GS_FIELD_METADATA(
        POSITION                    = 5
        FIELD_NAME                  = 'ZZAENNR'
        FIELD_TYPE                  = 'TEXT'
        REFERENCE_FIELD_NAME        = 'ZZAENNR'
        PERSISTENCE_FIELD_NAME      = 'ZZAENNR'
        DDIC_TYPE                   = 'CHAR'
        LENGTH                      = 30
        LABEL                       = LV_LABEL
        SCREEN_LENGTH               = 30
        DATA_ELEMENT_NAME           = 'ZZAENNR'
        IS_READ_ONLY                = ABAP_TRUE ).

      LS_FIELD_METADATA-ASSIGNED_SUBSCREEN_NUMBER = GET_SUBSCREEN( IV_FIELD_TYPE    = 'TEXT'
                                                                   IV_DDIC_TYPE     = 'CHAR'
                                                                   IV_SCREEN_LENGTH = 30 ).
      APPEND LS_FIELD_METADATA TO MT_CONTEXT_FIELDS.
      CLEAR: LS_FIELD_METADATA, LV_LABEL.
    ENDIF.


data ls_ASSOCIATION_KEY_FIELDS TYPE ty_gs_std_assoc_metadata.
ls_ASSOCIATION_KEY_FIELDS-field_name = 'ZZDAUAT'.
ls_ASSOCIATION_KEY_FIELDS-POSITION = '1'.
ls_ASSOCIATION_KEY_FIELDS-ddic_type = 'CHAR'.
ls_ASSOCIATION_KEY_FIELDS-data_element_name = 'AUFART'.
ls_ASSOCIATION_KEY_FIELDS-gui_search_help_name = '/CUM/CU_AUART'.
ls_ASSOCIATION_KEY_FIELDS-search_help_input_parameter = 'AUART'.
ls_ASSOCIATION_KEY_FIELDS-search_help_export_parameter = 'AUART'.
ls_ASSOCIATION_KEY_FIELDS-ASSIGNED_SUBSCREEN_NUMBER = GET_SUBSCREEN( IV_FIELD_TYPE    = 'ASC_TO_STD'   "ASC_TO_STD
                                                                   IV_DDIC_TYPE     = 'CHAR'
                                                                   IV_SCREEN_LENGTH = 4 ).
APPEND ls_ASSOCIATION_KEY_FIELDS TO MT_ASSOCIATION_KEY_FIELDS.
  ENDIF.

ENDENHANCEMENT.

3. 在类CL_CFD_SAP_GUI_CONTROLLER 方法IF_CFD_SAP_GUI_CONTROLLER~PBO_SUBSCREEN 结束处加入隐式增强,主要是控制增强字段的显示属性,例如只读字段以及MD13时皆不可编辑。

ENHANCEMENT 1  ZEHM_PP028_002.    "active version
  READ TABLE MT_CONTEXT_FIELDS WITH TABLE KEY POSITION = MV_CURRENT_SUBSCREEN_POSITION REFERENCE INTO LR_CONTEXT_FIELD.
  IF LR_CONTEXT_FIELD IS BOUND.
    IF LR_CONTEXT_FIELD->FIELD_NAME = 'ZZDAUAT'.
      LOOP AT SCREEN INTO DATA(LS_SCREEN).
        IF LS_SCREEN-NAME CS GC_UI_NAME_POSTFIX-DESCRIPTION.
          LS_SCREEN-INVISIBLE = 1.
          LS_SCREEN-INPUT     = 0.
          MODIFY SCREEN FROM LS_SCREEN.
        ENDIF.
      ENDLOOP.
    ELSEIF LR_CONTEXT_FIELD->FIELD_NAME = 'YMDC' OR LR_CONTEXT_FIELD->FIELD_NAME = 'ZIFFR'.
      IF LR_CONTEXT_FIELD->IS_INVISIBLE EQ ABAP_FALSE.
        MODIFY_SUBSCREEN_FIELDS( IV_POSITION      = LR_CONTEXT_FIELD->POSITION
                                 IV_FIELD_TYPE    = LR_CONTEXT_FIELD->FIELD_TYPE
                                 IV_SCREEN_LENGTH = LR_CONTEXT_FIELD->SCREEN_LENGTH
                                 IV_IS_READ_ONLY  = LR_CONTEXT_FIELD->IS_READ_ONLY
                                 IV_IS_MANDATORY  = LR_CONTEXT_FIELD->IS_MANDATORY ).

        UPDATE_UI_VALUE( IV_POSITION   = LR_CONTEXT_FIELD->POSITION
                         IR_UI_VALUES  = IR_UI_VALUES ).

        LOOP AT SCREEN INTO LS_SCREEN.
          LS_SCREEN-INVISIBLE = 0.
          LS_SCREEN-INPUT     = 0.
          MODIFY SCREEN FROM LS_SCREEN.
        ENDLOOP.
      ENDIF.
    ENDIF.
  ENDIF.

ENDENHANCEMENT.

4. 在类CL_CFD_SAP_GUI_CONTROLLER 方法SET_UI_VALUE_FIELD结束处加入隐式增强,主要是根据业务逻辑获取只读字段的值并赋值给全局变量。

ENHANCEMENT 1  ZEHM_PP028_003.    "active version
  DATA: LV_YMDC  TYPE ZSPP038-YMDC,
        LV_ZIFFR TYPE ZSPP038-ZIFFR,
        LS_ZTPP052 TYPE ZTPP052.

  READ TABLE MT_CONTEXT_FIELDS WITH TABLE KEY POSITION = MV_CURRENT_SUBSCREEN_POSITION REFERENCE INTO DATA(LR_CONTEXT_FIELD).
  IF LR_CONTEXT_FIELD IS BOUND.

    ASSIGN ('(SAPLM61O)PLAF-PLNUM') TO FIELD-SYMBOL(<LV_PLNUM>).
    IF <LV_PLNUM> IS ASSIGNED.
      call function 'ZPP_GET_YMDC_INFO'
        exporting
          iv_plnum         = <LV_PLNUM>
       IMPORTING
         ES_ZTPP052       = LS_ZTPP052.
    ENDIF.


    IF LR_CONTEXT_FIELD->FIELD_NAME = 'YMDC'.
      LV_YMDC =  LS_ZTPP052-ZYMDC.
      SET_UI_FIELD( IR_UI_VALUES       = IR_UI_VALUES
                    IV_COMPONENT       = IR_UI_FIELD_NAMES->VALUE_FIELD
                    IV_VALUE           = LV_YMDC
                    IV_IS_NUMERIC_TYPE = ABAP_TRUE ).
    ENDIF.

    IF LR_CONTEXT_FIELD->FIELD_NAME = 'ZIFFR'.
      LV_ZIFFR = LS_ZTPP052-AEQUI.
      SET_UI_FIELD( IR_UI_VALUES       = IR_UI_VALUES
                    IV_COMPONENT       = IR_UI_FIELD_NAMES->VALUE_FIELD
                    IV_VALUE           = LV_ZIFFR
                    IV_IS_NUMERIC_TYPE = ABAP_TRUE ).
    ENDIF.
  ENDIF.

ENDENHANCEMENT.

5. 在类CL_CFD_SAP_GUI_CONTROLLER 方法IF_CFD_SAP_GUI_CONTROLLER~POV_SUBSCREEN开始处加入隐式增强,主要是添加自定义搜索帮助。

ENHANCEMENT 1  ZEHM_PP028_004.    "active version
  DATA lt_selection_values TYPE if_cfd_sap_gui_ddic_value_help=>ty_gts_return_value.
  DATA ls_selection_values TYPE LINE OF if_cfd_sap_gui_ddic_value_help=>ty_gts_return_value.
  DATA AUART_TMP TYPE T003O-AUART.

  IF ( SY-TCODE = 'MD11' OR SY-TCODE = 'MD12' OR SY-TCODE = 'MD13' ).
    READ TABLE MT_CONTEXT_FIELDS WITH TABLE KEY POSITION = GET_POSITION_FROM_SCREEN( ) REFERENCE INTO DATA(LR_CONTEXT_FIELDS).
    IF LR_CONTEXT_FIELDS IS BOUND.
      IF LR_CONTEXT_FIELDS->FIELD_NAME = 'ZZDAUAT'.
        ASSIGN ('(SAPLM61O)PLAF-PWWRK') TO FIELD-SYMBOL(<Lv_WERKS>).
        IF SY-SUBRC = 0.
          CALL FUNCTION 'CO_F4_AUART'
            EXPORTING
*                      AKTYP     = RC27S-AKTYP
*                      AUTYP_IMP = T490-AUTYP
              WERKS     = <Lv_WERKS>
            IMPORTING
              AUART_EXP = AUART_TMP.
          if AUART_TMP IS NOT INITIAL.
          if mt_value_help_executed IS INITIAL.
            APPEND 1 TO mt_value_help_executed.
          endif.
*            DATA(lt_key_component_contexts)  = get_key_component_contexts( lr_context_fields ).
*APPEND INITIAL LINE TO mt_association_key_fields ASSIGNING FIELD-SYMBOL(<fs_key_fields>).
*<fs_key_fields>-field_name = 'ZZDAUAT'.
*<fs_key_fields>-position = LR_CONTEXT_FIELDS->position.


*              ls_selection_values-parameter_name = 'ZZDAUAT'.
*              ls_selection_values-parameter_value = AUART_TMP.
*              APPEND ls_selection_values to lt_selection_values.
*
*              mo_subscreen_handler->write_value_to_subscreen(
*                iv_subscreen_position      = LR_CONTEXT_FIELDS->position
*                iv_subscreen_dynpro_number = LR_CONTEXT_FIELDS->assigned_subscreen_number
*                it_dynpro_values           = VALUE #(
*                  ( fieldname  = 'ASSOCIATION_FIELD_VALUE'
*                    fieldvalue = AUART_TMP
*                  )
*                 )
*                ).

*            MR_OLD_FIELD_VALUES = MR_FIELD_VALUES.
*            ASSIGN MR_FIELD_VALUES to FIELD-SYMBOL(<fs_FIELD_VALUES>).
*            if sy-subrc = 0.
*              ASSIGN COMPONENT 'ZZDAUAT' of STRUCTURE <fs_FIELD_VALUES> to FIELD-SYMBOL(<fs_ZZDAUAT>).
*              if sy-subrc = 0.
*                <fs_ZZDAUAT> = AUART_TMP.
*              endif.
*            endif.

            SET_UI_FIELD( IR_UI_VALUES       = IR_UI_VALUES
                          IV_COMPONENT       = gc_ui_fields-association-value
                          IV_VALUE           = AUART_TMP
                          IV_IS_NUMERIC_TYPE = ABAP_TRUE ).

data lv_ZZDAUAT TYPE AUFART.
lv_ZZDAUAT = AUART_TMP.
EXPORT lv_ZZDAUAT = lv_ZZDAUAT to MEMORY id 'ZEHM_PP028_006'.

*              set_key_components(
*                    it_key_component_contexts = lt_key_component_contexts
*                    it_selection_values       = lt_selection_values ).
            ENDIF.
           trigger_roundtrip( ).
        ENDIF.
        RETURN.
      ENDIF.
    ENDIF.
  ENDIF.
ENDENHANCEMENT.

6. 由于添加搜索帮助会导致后面DUMP,故在类CL_CFD_SAP_GUI_CONTROLLER 方法VALIDATE_CODE_VALUE开始处加入隐式增强,退出该方法防止DUMP。

ENHANCEMENT 1  ZEHM_PP028_006.    "active version
IF sy-tcode = 'MD11' OR SY-TCODE = 'MD12' OR SY-TCODE = 'MD13'.
RETURN.
ENDIF.
ENDENHANCEMENT.

7. 在类CL_CFD_SAP_GUI_CONTROLLER 方法SET_UI_FIELD结束处加入隐式增强,将自定义搜索帮助选择的值传入屏幕变量。

ENHANCEMENT 2  ZEHM_PP028_006.    "active version
IF sy-tcode = 'MD11' OR SY-TCODE = 'MD12' OR SY-TCODE = 'MD13'.
ASSIGN COMPONENT 'ASSOCIATION_FIELD_LABEL' OF STRUCTURE  ir_ui_values->* TO FIELD-SYMBOL(<lv_ASSOCIATION_FIELD_LABEL>).
IF <lv_ASSOCIATION_FIELD_LABEL> IS ASSIGNED.
IF <lv_ASSOCIATION_FIELD_LABEL> = '订单类型'.
IF <lv_ui_value> IS ASSIGNED.
data lv_ZZDAUAT TYPE AUFART.
  import lv_ZZDAUAT = lv_ZZDAUAT FROM MEMORY id 'ZEHM_PP028_006'.
  IF lv_ZZDAUAT IS NOT INITIAL.
    ASSIGN COMPONENT 'ASSOCIATION_FIELD_VALUE' OF STRUCTURE  ir_ui_values->* TO FIELD-SYMBOL(<lv_ASSOCIATION_FIELD_VALUE>).
  <lv_ASSOCIATION_FIELD_VALUE> = lv_ZZDAUAT .
  ENDIF.

  endif.
ENDIF.
ENDIF.
ENDIF.
ENDENHANCEMENT.

8. 在Include LM61OF8I结束处加入隐式增强,检查输入字段值是否正确。

ENHANCEMENT 1  ZEHM_PP028_007.    "active version
  DATA LS_T399X TYPE T399X.

  IF SY-TCODE EQ 'MD11' OR SY-TCODE EQ 'MD12'.
    IF PLAF-ZZDAUAT IS NOT INITIAL
      AND PLAF-PLWRK IS NOT INITIAL.
      SELECT SINGLE *
        INTO LS_T399X
        FROM T399X
        WHERE WERKS EQ PLAF-PWWRK
        AND AUART EQ PLAF-ZZDAUAT.
      IF SY-SUBRC NE 0.
        MESSAGE E053(ZPP01).  "订单类型不存在
      ENDIF.
    ENDIF.
  ENDIF.
ENDENHANCEMENT.

以上是关于ABAP MD11 / MD12 / MD13计划订单屏幕增强的主要内容,如果未能解决你的问题,请参考以下文章

MD5加密工具类

C# MD5 应用

Java MD5加密

MD5code

小程序MD5加密(支持中文)

刷里程碑 怎样绕过MD5验证