ABAP 交货单屏幕增强 增加自建表

Posted 狗尾巴草_lan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ABAP 交货单屏幕增强 增加自建表相关的知识,希望对你有一定的参考价值。

需求描述:

实际业务中,交货单行项目存在多个传票号,所以需要在交货单行项目自定义屏幕上增加一个长文本框(或者表),如下图所示

实现过程:

1. 屏幕添加控件

①在自定义屏幕添加自定义控件

②在PBO中定义事件

 这是定义函数组全部变量

 这是创建文本框代码

 ③设置文本框可编辑/只读

2. 将数据库表数据显示在屏幕上,需要考虑修改交货时不能覆盖用户输入数据,因为屏幕数据会传入ABAP内存所以仅当该内存不存在时才查询数据库表

 3. 将屏幕输入数据保存至数据库表,通过MEMORY ID实现数据传输

①在屏幕数据回传函数中将屏幕数据传入ABAP内存

 ②对交货单处理增强点LE_SHP_DELIVERY_PROC创建实施,修改方法IF_EX_LE_SHP_DELIVERY_PROC~SAVE_DOCUMENT_PREPARE将ABAP内存数据更新数据库表

总是提示此文章质量较低,猜测是字数不够,所以附上源码

PROCESS BEFORE OUTPUT.
  MODULE TEXTEDIT_9200.
  MODULE STATUS_9200.

PROCESS AFTER INPUT.
* MODULE USER_COMMAND_9001.
*&---------------------------------------------------------------------*
*& Module STATUS_9200 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_9200 OUTPUT.
  LOOP AT SCREEN.
    IF GS_LIPS-WBSTA = 'C'.
      SCREEN-INPUT = '0'.

      IF GC_EDITOR IS NOT INITIAL.
        GC_EDITOR->SET_READONLY_MODE( 1 ).
      ENDIF.
    ELSE.
      ASSIGN ('(SAPMV50A)T180-TRTYP') TO <FS_ANY>.
      IF <FS_ANY> IS ASSIGNED.
        IF <FS_ANY> = 'A'.
          SCREEN-INPUT = '0'.

          IF GC_EDITOR IS NOT INITIAL.
            GC_EDITOR->SET_READONLY_MODE( 1 ).
          ENDIF.
        ELSE.
          SCREEN-INPUT = '1'.

          IF GC_EDITOR IS NOT INITIAL.
            GC_EDITOR->SET_READONLY_MODE( 0 ).
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.

    MODIFY SCREEN.
  ENDLOOP.

ENDMODULE.

*&---------------------------------------------------------------------*
*& Module TEXTEDIT_9200 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE TEXTEDIT_9200 OUTPUT.
  DATA: LT_ZTSD053   TYPE STANDARD TABLE OF ZTSD053,
        LS_ZTSD053   TYPE ZTSD053,
        LV_ZZSUMMONS TYPE STRING,
        LV_LFIMG     TYPE STRING,
        LV_STRING    TYPE STRING.

  CLEAR: LT_ZTSD053, LV_ZZSUMMONS, LV_LFIMG, LV_STRING.

* 创建文本框
  IF GC_CONTAINER IS INITIAL.
    CREATE OBJECT GC_CONTAINER
      EXPORTING
        CONTAINER_NAME              = 'GC_ZZSUMMONS'
      EXCEPTIONS
        CNTL_ERROR                  = 1
        CNTL_SYSTEM_ERROR           = 2
        CREATE_ERROR                = 3
        LIFETIME_ERROR              = 4
        LIFETIME_DYNPRO_DYNPRO_LINK = 5.
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF .

    CREATE OBJECT GC_EDITOR
      EXPORTING
        "   MAX_NUMBER_CHARS       = 2000    "字数限制
        PARENT                     = GC_CONTAINER
        WORDWRAP_MODE              = CL_GUI_TEXTEDIT=>WORDWRAP_AT_WINDOWBORDER
        WORDWRAP_POSITION          = -1
        WORDWRAP_TO_LINEBREAK_MODE = CL_GUI_TEXTEDIT=>FALSE
      EXCEPTIONS
        ERROR_CNTL_CREATE          = 1
        ERROR_CNTL_INIT            = 2
        ERROR_CNTL_LINK            = 3
        ERROR_DP_CREATE            = 4
        GUI_TYPE_NOT_SUPPORTED     = 5
        OTHERS                     = 6.
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    GC_EDITOR->SET_TOOLBAR_MODE( 0 ).
    GC_EDITOR->SET_STATUSBAR_MODE( 0 ).
  ENDIF.

* 获取内存数据
  IMPORT LT_ZTSD053 = LT_ZTSD053 FROM MEMORY ID 'ZTSD053'.
  IF SY-SUBRC <> 0.
*   查询传票号
    SELECT VBELN,
           POSNR,
           ZZSUMMONS,
           LFIMG
      INTO CORRESPONDING FIELDS OF TABLE @LT_ZTSD053
      FROM ZTSD053
     WHERE VBELN = @GS_LIPS-VBELN.
    IF SY-SUBRC <> 0.
      SELECT VBELN,
             POSNR,
             ZZSUMMONS
        INTO TABLE @DATA(LT_LIPS)
        FROM LIPS
       WHERE VBELN     =  @GS_LIPS-VBELN
         AND ZZSUMMONS <> ''.
      LOOP AT LT_LIPS INTO DATA(LS_LIPS).
        SPLIT LS_LIPS-ZZSUMMONS AT '|' INTO TABLE DATA(LT_ZZSUMMONS).
        LOOP AT LT_ZZSUMMONS INTO DATA(LS_ZZSUMMONS).
          LS_ZTSD053-VBELN = LS_LIPS-VBELN.
          LS_ZTSD053-POSNR = LS_LIPS-POSNR.
          SPLIT LS_ZZSUMMONS AT ':' INTO LS_ZTSD053-ZZSUMMONS LV_LFIMG.
          LS_ZTSD053-LFIMG = LV_LFIMG.
          APPEND LS_ZTSD053 TO LT_ZTSD053.
          CLEAR: LS_ZTSD053, LV_LFIMG.
        ENDLOOP.
      ENDLOOP.
    ENDIF.

*   将传票号传入内存
    EXPORT LT_ZTSD053 = LT_ZTSD053 TO MEMORY ID 'ZTSD053'.
  ENDIF.

* 编辑传票号转成长文本
  LOOP AT LT_ZTSD053 INTO LS_ZTSD053 WHERE VBELN = GS_LIPS-VBELN
                                       AND POSNR = GS_LIPS-POSNR.
    IF LS_ZTSD053-LFIMG IS NOT INITIAL.
      LV_LFIMG = LS_ZTSD053-LFIMG.
      CONDENSE LV_LFIMG.
      CONCATENATE LS_ZTSD053-ZZSUMMONS LV_LFIMG
             INTO LV_STRING SEPARATED BY ':'.
    ELSE.
      LV_STRING = LS_ZTSD053-ZZSUMMONS.
    ENDIF.

    IF LV_ZZSUMMONS IS INITIAL.
      LV_ZZSUMMONS = LV_STRING.
    ELSE.
      CONCATENATE LV_ZZSUMMONS LV_STRING
             INTO LV_ZZSUMMONS SEPARATED BY '|'.
    ENDIF.
  ENDLOOP.

  GC_EDITOR->SET_TEXTSTREAM( LV_ZZSUMMONS ).

ENDMODULE.
FUNCTION ZSD_SHP_ITEM_FROM_SUBSCREEN .
*"----------------------------------------------------------------------
*"*"本地接口:
*"  EXPORTING
*"     REFERENCE(ES_LIPS) TYPE  LIPS
*"----------------------------------------------------------------------
  DATA: LT_LINE      TYPE TABLE OF LINE,
        LT_TLINE     TYPE TABLE OF TLINE,
        LT_ZTSD053   TYPE STANDARD TABLE OF ZTSD053,
        LS_ZTSD053   TYPE ZTSD053,
        LV_ZZSUMMONS TYPE STRING,
        LV_LFIMG     TYPE STRING.

* 获取传票号文本框内容
  LV_ZZSUMMONS = ZCL_UTIL_LONGTEXT=>GET_TXT_FROM_TE( IO_TE = GC_EDITOR ).

* 清除内存中该行项目数据
  IMPORT LT_ZTSD053 = LT_ZTSD053 FROM MEMORY ID 'ZTSD053'.
  IF SY-SUBRC = 0.
    DELETE LT_ZTSD053 WHERE VBELN = GS_LIPS-VBELN
                        AND POSNR = GS_LIPS-POSNR.
  ENDIF.

* 编辑传票号以便写入自建表
  IF LV_ZZSUMMONS IS NOT INITIAL.
    SPLIT LV_ZZSUMMONS AT '|' INTO TABLE DATA(LT_ZZSUMMONS).
    LOOP AT LT_ZZSUMMONS INTO DATA(LS_ZZSUMMONS).
      LS_ZTSD053-VBELN = GS_LIPS-VBELN.
      LS_ZTSD053-POSNR = GS_LIPS-POSNR.
      SPLIT LS_ZZSUMMONS AT ':' INTO LS_ZTSD053-ZZSUMMONS LV_LFIMG.
      LS_ZTSD053-LFIMG = LV_LFIMG.
      APPEND LS_ZTSD053 TO LT_ZTSD053.
      CLEAR: LS_ZTSD053, LV_LFIMG.
    ENDLOOP.
  ENDIF.

* 将传票号传入内存(增强ZEHM_QTC010_001 方法IF_EX_LE_SHP_DELIVERY_PROC~SAVE_DOCUMENT_PREPARE)
  EXPORT LT_ZTSD053 = LT_ZTSD053 TO MEMORY ID 'ZTSD053'.

  ES_LIPS = GS_LIPS.
  ES_LIPS-ZZSUMMONS = LV_ZZSUMMONS.

ENDFUNCTION.
  METHOD IF_EX_LE_SHP_DELIVERY_PROC~SAVE_DOCUMENT_PREPARE.
    DATA: LT_ZTSD053   TYPE STANDARD TABLE OF ZTSD053,
          LS_ZTSD053   TYPE ZTSD053,
          LV_ZZSUMMONS TYPE STRING.

*   传票号写入自建表(数据来自函数 ZSD_SHP_ITEM_FROM_SUBSCREEN )
    IMPORT LT_ZTSD053 = LT_ZTSD053 FROM MEMORY ID 'ZTSD053'.
    IF SY-SUBRC = 0.
*     先清空历史数据
      READ TABLE CT_XLIKP INTO DATA(LS_LIKP) INDEX 1.
      IF SY-SUBRC = 0.
        DELETE FROM ZTSD053 WHERE VBELN = LS_LIKP-VBELN.
      ENDIF.

      MODIFY ZTSD053 FROM TABLE LT_ZTSD053.
      FREE MEMORY ID 'ZTSD053'.
    ENDIF.


  ENDMETHOD.

以上是关于ABAP 交货单屏幕增强 增加自建表的主要内容,如果未能解决你的问题,请参考以下文章

ABAP 交货单屏幕增强 增加自建表

ABAP 交货单屏幕增强

ABAP 交货单屏幕增强

ABAP 交货单屏幕增强

ABAP EWM PRDI交货单过账

ABAP EWM PRDO交货单过账