SAP MIGO屏幕增强详解编程语言

1.获取屏幕当前状态

     FIELD-SYMBOLS:<godynpro> TYPE godynpro, 
                   <gohead>   TYPE gohead. 
    DATA:lv_godynpro TYPE string VALUE '(SAPLMIGO)GODYNPRO', 
         lv_gohead   TYPE string VALUE  '(SAPLMIGO)GOHEAD'. 
 
    ASSIGN (lv_godynpro) TO <godynpro>  . 
 
    <godynpro>-action    <godynpro>-refdoc

2.自定义表、结构

效果

SAP MIGO屏幕增强详解编程语言

存储表

SAP MIGO屏幕增强详解编程语言

结构

SAP MIGO屏幕增强详解编程语言

表结构

SAP MIGO屏幕增强详解编程语言

3.函数组

SAP MIGO屏幕增强详解编程语言

SAP MIGO屏幕增强详解编程语言

屏幕上数据放的是ymmt_migo

注意:需要参考数据字段

SAP MIGO屏幕增强详解编程语言

获取屏幕上的数据

SAP MIGO屏幕增强详解编程语言

SAP MIGO屏幕增强详解编程语言

将数据放入屏幕上

SAP MIGO屏幕增强详解编程语言

SAP MIGO屏幕增强详解编程语言

注意这里gv_flag来控制屏幕是否可编辑,放在屏幕PBO上

SAP MIGO屏幕增强详解编程语言

更新到数据库

SAP MIGO屏幕增强详解编程语言

SAP MIGO屏幕增强详解编程语言

SAP MIGO屏幕增强详解编程语言

4.BADI实现

SAP MIGO屏幕增强详解编程语言

创建实施

SAP MIGO屏幕增强详解编程语言

SAP MIGO屏幕增强详解编程语言

5.实现方法

IF_EX_MB_MIGO_BADI~INIT

  METHOD if_ex_mb_migo_badi~init. 
* regristration of badi-implementation: 
* Append class attribute GF_CLASS_ID (='MIGO_BADI_IMPLEMENTATION1') to 
* regristration table. 
  append gf_class_id to ct_init. 
  ENDMETHOD.

IF_EX_MB_MIGO_BADI~PBO_DETAIL

  METHOD if_ex_mb_migo_badi~pbo_detail. 
    DATA: ls_extdata TYPE ymms_migo. 
* this check is obligatory, otherwise the program flow is incorrect 
* (If there would be more than one implementation of BAdI MB_MIGO_BADI, 
*  only one subscreen would be displayed). 
 
    CHECK SY-UNAME = 'WANGXING'. 
 
    CHECK i_class_id = gf_class_id. 
* Show screen only if there is an item 
    CHECK i_line_id <> 0. 
* External subscreen: 
* The content of global field G_NO_INPUT (set in method MODE_SET) will 
* influence the number of external subsreen: 
*    IF g_no_input IS INITIAL. 
    e_cprog   = 'SAPLYWXMIGO_BADI'(006).  "程序名为定义的函数组的名称前加“SAPL“。 
    e_dynnr   = '1001'.                     "External fields: Input 
    e_heading = 'MIGO BADI TEST'(004). "显示标签的名称 
*    ENDIF. 
* Set G_LINE_ID (= line_id of item displayed on detail-tabstrip) 
    g_line_id = i_line_id. 
* Read data 
    READ TABLE gt_data INTO ls_extdata 
       WITH TABLE KEY line_id = i_line_id. 
* Export data to function group (for display on subscreen) 
    CALL FUNCTION 'YWXMIGO_PUT_DATA' 
      EXPORTING 
        is_migo_data = ls_extdata 
        iv_flag      = g_no_input. 
  ENDMETHOD.

IF_EX_MB_MIGO_BADI~PAI_DETAIL

  METHOD if_ex_mb_migo_badi~pai_detail. 
*----------------------------------------------------------------------- 
* Changing parameter E_FORCE_CHANGE can be set to 'X'. In this case 
* method LINE_MODIFY is called. 
* ATTENTION: 
* DO NOT SET parameter E_FORCE_CHANGE = ' '. In this case you might 
* overwrite parameter E_FORCE_CHANGE of another BAdI implementation. 
*----------------------------------------------------------------------- 
    DATA: ls_extdata_new TYPE ymms_migo, 
          ls_extdata_old TYPE ymms_migo. 
 
* Only if a line exists 
    CHECK i_line_id <> 0. 
* Get data from external screen 
    CALL FUNCTION 'YWXMIGO_GET_DATA' 
      IMPORTING 
        es_migo_data = ls_extdata_new. 
* Compare new data with old data 
    READ TABLE gt_data INTO ls_extdata_old 
       WITH TABLE KEY line_id = i_line_id. 
    ls_extdata_new-line_id = i_line_id. 
    IF ls_extdata_old <> ls_extdata_new. 
*   If there were any changes, it's obligatory to force MIGO to trigger 
*   method LINE_MODIFY. 
      e_force_change = 'X'. 
    ENDIF. 
  ENDMETHOD.

IF_EX_MB_MIGO_BADI~LINE_MODIFY

  METHOD if_ex_mb_migo_badi~line_modify. 
    DATA: ls_extdata_old      TYPE ymms_migo, 
          ls_extdata_new      TYPE ymms_migo, 
          ls_migo_badi_exampl TYPE ymmt_migo, 
          l_subrc             TYPE sy-subrc. 
 
* Get external data from internal table: 
    READ TABLE gt_data INTO ls_extdata_old 
      WITH TABLE KEY line_id = i_line_id. 
    l_subrc = sy-subrc. 
 
* Update data in internal table: 
    IF l_subrc <> 0. 
*   Line is new: If GOITEM has a reference to a material document, 
*                the already existing external data can be read. 
      IF NOT cs_goitem-mblnr IS INITIAL AND NOT cs_goitem-mjahr IS INITIAL 
         AND NOT cs_goitem-zeile IS INITIAL. 
        SELECT SINGLE * FROM ymmt_migo INTO ls_migo_badi_exampl 
               WHERE mblnr = cs_goitem-mblnr 
                 AND mjahr = cs_goitem-mjahr 
                 AND zeile = cs_goitem-zeile. 
        IF sy-subrc = 0. 
          MOVE-CORRESPONDING ls_migo_badi_exampl TO ls_extdata_new. 
        ENDIF. 
      ENDIF. 
*    ls_extdata_new-sgtxt  = cs_goitem-sgtxt. 
      ls_extdata_new-line_id = i_line_id. 
      INSERT ls_extdata_new INTO TABLE gt_data. 
    ELSE. 
*   Line exists: Get external data entered on BAdI-subscreeen, but only 
*                if line_modify was called for the item displayed in the 
*                'detail tabstrip'. 
      CHECK g_line_id = i_line_id. 
      CALL FUNCTION 'YWXMIGO_GET_DATA' 
        IMPORTING 
          es_migo_data = ls_extdata_new. 
      ls_extdata_new-line_id = i_line_id. 
*    if ls_extdata_new-sgtxt <> ls_extdata_old-sgtxt. 
**     Field was changed on external screen 
*      cs_goitem-sgtxt = ls_extdata_new-sgtxt. 
*    else. 
**     Take data from GOITEM 
*      ls_extdata_new-sgtxt = cs_goitem-sgtxt. 
*    endif. 
      MODIFY TABLE gt_data FROM ls_extdata_new. 
    ENDIF. 
  ENDMETHOD.

IF_EX_MB_MIGO_BADI~LINE_DELETE

  METHOD if_ex_mb_migo_badi~line_delete. 
    DELETE TABLE gt_data WITH TABLE KEY line_id = i_line_id. 
  ENDMETHOD.

IF_EX_MB_MIGO_BADI~RESET

  METHOD if_ex_mb_migo_badi~reset. 
* clear all internal data: 
    CLEAR: gt_data, 
           g_no_input, 
           gs_exdata_header, 
           g_cancel, 
           g_line_id. 
  ENDMETHOD.

IF_EX_MB_MIGO_BADI~POST_DOCUMENT

  METHOD if_ex_mb_migo_badi~post_document. 
    DATA: ls_migo_badi_example TYPE ymmt_migo, 
          lt_migo_badi_example TYPE TABLE OF ymmt_migo, 
          ls_extdata           TYPE ymms_migo, 
          ls_xmseg             TYPE mseg. 
    FIELD-SYMBOLS: <gt_extdata> TYPE migo_badi_example_screen_field. 
* Transaction MIGO will now post a material document. 
* Any errors here MUST be issued as A-message (better: X-message) 
 
* Copy data from material document into internal table 
    LOOP AT gt_data INTO ls_extdata. 
      IF g_cancel IS INITIAL. 
        READ TABLE it_mseg INTO ls_xmseg 
           WITH KEY line_id = ls_extdata-line_id. 
      ELSE. 
        READ TABLE it_mseg INTO ls_xmseg 
           WITH KEY smbln = ls_extdata-mblnr 
                    smblp = ls_extdata-zeile 
                    sjahr = ls_extdata-mjahr. 
      ENDIF. 
      IF sy-subrc IS INITIAL. 
        "MOVE-CORRESPONDING ls_extdata TO ls_migo_badi_example. 
        MOVE-CORRESPONDING ls_xmseg   TO ls_migo_badi_example. 
 
        ls_migo_badi_example-erfmg = ls_extdata-erfmg. 
        ls_migo_badi_example-erfme = ls_extdata-erfme. 
        APPEND ls_migo_badi_example TO lt_migo_badi_example. 
      ENDIF. 
    ENDLOOP. 
* The data from external detail screen can be saved now: 
    CHECK gt_data IS NOT INITIAL. 
    CALL FUNCTION 'YWXMIGO_UPDATE_DATA' IN UPDATE TASK 
      TABLES 
        it_migo_data = lt_migo_badi_example. 
* The data from external header screen can be saved now: 
*  MOVE-CORRESPONDING is_mkpf TO gs_exdata_header. 
*  CALL FUNCTION 'MIGO_BADI_EXAMPLE_UPDATE_HEAD' IN UPDATE TASK 
*    EXPORTING 
*      is_migo_badi_header_fields = gs_exdata_header. 
  ENDMETHOD.

IF_EX_MB_MIGO_BADI~MODE_SET

  METHOD if_ex_mb_migo_badi~mode_set. 
 
* ACTION and REFDOC will discribe the mode of transaction MIGO. 
* ---------------------------------------------------------------------- 
* i_action: 
* A01 = Goods receipt 
* A02 = Return delivery 
* A03 = Cancellation 
* A04 = Display 
* A05 = Release GR bl.st. 
* A06 = Subsequent deliv. 
* A07 = Goods issue 
* 
* i_refdoc: 
* R01 = Purchase order 
* R02 = Material document 
* R03 = Delivery note 
* R04 = Inbound delivery 
* R05 = Outbound delivery 
* R06 = Transport 
* R07 = Transport ID code 
* R08 = Order 
* R09 = Reservation 
* R10 = Other GR 
*----------------------------------------------------------------------- 
 
* In case of 'DISPLAY' the global field G_NO_INPUT will be set to 'X'. 
* The result is that a different external subscreen will be choosen in 
* method PBO_DETAIL. 
    IF i_action = 'A04' OR i_action = 'A03'. 
      g_no_input = 'X'. 
    ENDIF. 
* In case of 'CANCEL' the global field G_CANCEL will be set to 'X'. 
* The result is that in method POST_DOCUMENT a different handling is 
* used 
    IF i_action = 'A03'. 
      g_cancel = 'X'. 
    ENDIF. 
  ENDMETHOD.

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/18002.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论