BAPI_ACC_DOCUMENT_POST扩展字段

1、需求

BAPI_ACC_DOCUMENT_POST函数中没有“凭证行项目付款原因代码”字段的参数,
现需要将此字段传入BAPI中
BAPI_ACC_DOCUMENT_POST扩展字段_第1张图片
2、实现方法

2.1、程序实现

创建结构,包含需要传入的字段
BAPI_ACC_DOCUMENT_POST扩展字段_第2张图片

DATA: ls_extension2 TYPE bapiparex.
DATA: lt_extension2 LIKE TABLE OF ls_extension2.
DATA: ls_extension_field TYPE zds_acc_document_extension2.

CLEAR lt_extension2[].

CLEAR ls_extension_field.
ls_extension_field-posnr = ‘0000000001’. " 凭证行项目
ls_extension_field-rstgr = ‘1ZZ’. " 原因代码

CLEAR ls_extension2.
ls_extension2-structure = ‘ZDS_ACC_DOCUMENT_EXTENSION2’.
ls_extension2-valuepart1 = ls_extension_field.

2.2、增强实现

BADI增强:ACC_DOCUMENT
BAPI_ACC_DOCUMENT_POST扩展字段_第3张图片
BAPI_ACC_DOCUMENT_POST扩展字段_第4张图片
METHOD if_ex_acc_document~change .
DATA: wa_extension TYPE bapiparex,
ext_value(960) TYPE c,
wa_accit TYPE accit,
l_ref TYPE REF TO data.

FIELD-SYMBOLS: TYPE ANY,
TYPE ANY.

SORT c_extension2 BY structure.

LOOP AT c_extension2 INTO wa_extension.
AT NEW structure.
CREATE DATA l_ref TYPE (wa_extension-structure).
ASSIGN l_ref->* TO .
ENDAT.
CONCATENATE wa_extension-valuepart1 wa_extension-valuepart2
wa_extension-valuepart3 wa_extension-valuepart4
INTO ext_value.
MOVE ext_value TO .
ASSIGN COMPONENT ‘POSNR’ OF STRUCTURE TO .
READ TABLE c_accit WITH KEY posnr =
INTO wa_accit.
IF sy-subrc IS INITIAL.
MOVE-CORRESPONDING TO wa_accit.
MODIFY c_accit FROM wa_accit INDEX sy-tabix.
ENDIF.
ENDLOOP.

ENDMETHOD.
BAPI_ACC_DOCUMENT_POST扩展字段_第5张图片

BAPI_ACC_DOCUMENT_POST扩展字段_第6张图片
METHOD if_ex_acc_document~change.


  • Example to move fields from BAPI parameter EXTENSION2 to structure *
  • ACCIT (accounting document line items). *
  • The dictionary structure (content for EXTENSION2-STRUCTURE) must *
  • contain field POSNR, (TYPE POSNR_ACC) to indentify the correct line *
  • item of the internal table ACCIT. *

  • 本地变量
    DATA: wa_extension TYPE bapiparex,
    ext_value(960) TYPE c,
    wa_accit TYPE accit,
    wa_accit_temp TYPE accit,
    l_ref TYPE REF TO data.

    DATA: lt_ddic_field TYPE STANDARD TABLE OF dfies,
    ls_ddic_field TYPE dfies.

  • 指针变量
    FIELD-SYMBOLS: TYPE any,
    TYPE any.

    FIELD-SYMBOLS: TYPE any,
    TYPE any.

  • 逻辑控制
    DATA l_type TYPE c.

    PERFORM frm_get_type IN PROGRAM zzljyfien_0001 IF FOUND
    USING ‘ZZLJYFIEN_0001’
    CHANGING l_type.
    CHECK l_type = ‘S’.

  • 取增强结构字段
    CALL FUNCTION ‘DDIF_FIELDINFO_GET’
    EXPORTING
    tabname = ‘ZSJYFI_0003’
    TABLES
    dfies_tab = lt_ddic_field.

    SORT c_extension2 BY structure.

    LOOP AT c_extension2 INTO wa_extension.
    AT NEW structure.
    CREATE DATA l_ref TYPE (wa_extension-structure).
    ASSIGN l_ref->* TO .
    ENDAT.

    CHECK wa_extension-structure EQ 'ZSJYFI_0003'.
    
  •  CONCATENATE WA_EXTENSION-VALUEPART1 WA_EXTENSION-VALUEPART2
    
  •  WA_EXTENSION-VALUEPART3 WA_EXTENSION-VALUEPART4
    
  •  INTO EXT_VALUE.
    

*beign add by yangq on 2018-10-23
ext_value+0(240) = wa_extension-valuepart1.
ext_value+240(240) = wa_extension-valuepart2.
ext_value+480(240) = wa_extension-valuepart3.
ext_value+720(240) = wa_extension-valuepart4.
*end add by yangq on 2018-10-23

  MOVE ext_value TO .
  ASSIGN COMPONENT 'POSNR' OF STRUCTURE  TO .
  READ TABLE c_accit WITH KEY posnr = 
  INTO wa_accit.
  IF sy-subrc IS INITIAL.
    LOOP AT lt_ddic_field INTO ls_ddic_field.
  •    assign component ls_comp-name of structure  to .
        ASSIGN COMPONENT ls_ddic_field-fieldname OF STRUCTURE  TO .
        IF sy-subrc = 0.
          ASSIGN COMPONENT ls_ddic_field-fieldname OF STRUCTURE wa_accit TO .
          IF sy-subrc = 0.
            IF  IS INITIAL.          " ExtensionIn中的值为初始值时, 不去赋值
              " do nothing...
            ELSE.
               = . " 只有当 extensionin结构中有值时, 才去赋值
            ENDIF.
          ENDIF.
        ENDIF.
      ENDLOOP.
    
  • 检查并赋值
    CLEAR:wa_accit_temp.
    READ TABLE c_accit INTO wa_accit_temp INDEX sy-tabix.
    IF sy-subrc EQ 0.
    IF wa_accit-bschl IS INITIAL.
    wa_accit-bschl = wa_accit_temp-bschl.
    ENDIF.
    IF wa_accit-umskz IS INITIAL.
    wa_accit-umskz = wa_accit_temp-umskz.
    ENDIF.
    ** being add by yanqq on 2018-10-23

  •      IF wa_accit-zz_item10 IS INITIAL.
    
  •        wa_accit-zz_item10 = wa_accit_temp-zz_item10.
    
  •      ENDIF.
    
  •      IF wa_accit-zz_item13 IS INITIAL.
    
  •        wa_accit-zz_item13 = wa_accit_temp-zz_item13.
    
  •      ENDIF.
    
  •      IF wa_accit-zz_item14 IS INITIAL.
    
  •        wa_accit-zz_item14 = wa_accit_temp-zz_item14.
    
  •      ENDIF.
    
  •      IF wa_accit-zz_item15 IS INITIAL.
    
  •        wa_accit-zz_item15 = wa_accit_temp-zz_item15.
    
  •      ENDIF.
    

** end add by yanqq on 2018-10-23
*
ENDIF.
MODIFY c_accit FROM wa_accit INDEX sy-tabix.
ENDIF.
ENDLOOP.
ENDMETHOD.

有时候在扩展里边增加是不可以的,所以要在增强里写代码。

你可能感兴趣的:(SAP)