前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SAP ABAP 关于BAPI的扩展字段EXTENSIONIN处理

SAP ABAP 关于BAPI的扩展字段EXTENSIONIN处理

作者头像
matinal
发布2023-10-12 18:08:10
1.1K0
发布2023-10-12 18:08:10
举报
文章被收录于专栏:SAP Technical

1.找到对应的结构

2.查看SAP内部解释说明

 3. 找到结构

 4. 下面拿采购申请创建为例

代码语言:javascript
复制
DATA: ls_req_item TYPE BAPI_TE_MEREQITEM,

ls_req_itemx TYPE BAPI_TE_MEREQITEMX,

ls_extensionin TYPE bapiparex,

lt_extensionin TYPE STANDARD TABLE OF bapiparex.

clear ls_extensionin.

clear ls_req_item.

ls_req_item-preq_item = wa_gt_data-posic.

ls_req_item-ZZKOSTL = wa_praccount-costcenter.

ls_extensionin-structure = 'BAPI_TE_MEREQITEM'.

PERFORM transfer_to_extensionin USING ls_req_item CHANGING ls_extensionin.

APPEND ls_extensionin to lt_extensionin.

clear ls_extensionin.

clear ls_req_itemx.

ls_req_itemx-preq_item = wa_gt_data-posic.

ls_req_itemx-ZZKOSTL = 'X'.

ls_extensionin-structure = 'BAPI_TE_MEREQITEMX'.

PERFORM transfer_to_extensionin USING ls_req_itemx CHANGING ls_extensionin.

APPEND ls_extensionin to lt_extensionin.

FORM transfer_to_extensionin

USING

is_bapi_extensionin TYPE any

CHANGING

cs_bapiparex TYPE bapiparex.

DATA l_distance_characters TYPE I.

FIELD-SYMBOLS <any> TYPE any.

DESCRIBE DISTANCE BETWEEN cs_bapiparex-structure

AND cs_bapiparex-valuepart1

INTO l_distance_characters

IN CHARACTER MODE.

ASSIGN cs_bapiparex+l_distance_characters(*) TO <any>

CASTING LIKE is_bapi_extensionin.

<any> = is_bapi_extensionin.

ENDFORM.

* Create the PR with the above data's.

CALL FUNCTION 'BAPI_PR_CREATE'

EXPORTING

prheader = wa_header

prheaderx = wa_headerx

TABLES

return = t_return

pritem = t_item

pritemx = t_itemx

praccount = t_praccount

praccountx = t_praccountx

"pritemsource = t_itemsource

"pritemtext = t_itext

EXTENSIONIN = lt_extensionin

EXCEPTIONS

OTHERS = 1.

5. 说说重点

系统BAPI允许的最大extension长度为960(=240*4)。所以,如果超过这个长度就会有问题,或者DUMP,或者值不更新。

 将结构里增强字段总长度降低至960以下,就可以解决任何问题。

跟matinal学知识,提一个小知识点: 各种BAPI的扩张结构字段中,最好不要包含金额类型字段(CURR),改为CHAR类型。如果必须是金额类型的字段,我们可以用 CL_ABAP_CONTAINER_UTILITIES=>FILL_CONTAINER_C来转换为字符串,再截取,塞入到extension的多个字段传输。(matinal告诉你,这个是很多人不知道的知识点)

6. 再举个栗子

代码语言:javascript
复制
  DATA:ls_prheader    TYPE bapimereqheader,
       ls_prheaderx   TYPE bapimereqheaderx,
       lv_number      TYPE bapimereqheader-preq_no,
       l_comp         TYPE TABLE OF bapimereqcomponent WITH HEADER LINE,
       l_compx        TYPE TABLE OF bapimereqcomponentx WITH HEADER LINE,
       l_pritem       TYPE TABLE OF bapimereqitemimp  WITH HEADER LINE,
       l_pritemx      TYPE TABLE OF bapimereqitemx    WITH HEADER LINE,
       l_pritemtext   TYPE TABLE OF bapimereqitemtext WITH HEADER LINE,
       l_praccount    TYPE TABLE OF bapimereqaccount WITH HEADER LINE,
       l_praccountx   TYPE TABLE OF bapimereqaccountx WITH HEADER LINE,
*       ls_req_item    TYPE bapi_te_mereqitem,
       ls_req_item    TYPE bapi_te_requisition_item,
       ls_req_itemx   TYPE bapi_te_mereqitemx,
       ls_extensionin TYPE bapiparex,
       lt_extensionin TYPE STANDARD TABLE OF bapiparex,
       l_return       TYPE TABLE OF bapiret2 WITH HEADER LINE.

	  IF <l_data>-zrwl IS NOT INITIAL.
        ls_req_item-zrwl    = <l_data>-zrwl.
        ls_req_itemx-zrwl    = 'X'.
      ENDIF.

      CLEAR ls_extensionin.
      ls_extensionin-STRUCTURE = 'BAPI_TE_MEREQITEM'.
      PERFORM transfer_to_extensionin USING ls_req_item CHANGING ls_extensionin.
      APPEND ls_extensionin TO lt_extensionin.

      CLEAR ls_extensionin.
      ls_extensionin-STRUCTURE = 'BAPI_TE_MEREQITEMX'.
      PERFORM transfer_to_extensionin USING ls_req_itemx CHANGING ls_extensionin.
      APPEND ls_extensionin TO lt_extensionin.

7. 完整的例子

代码语言:javascript
复制
REPORT  ZMM_PR_BATCH_INPUT .


TYPES:BEGIN OF TY_ITAB,
      WBS_ELEMENT(24),
      MATERIAL(18),
      QUANTITY(13),
      UNIT(3),
      DELIV_DATE(8),
      PURCH_ORG(4),
*      KNTTP TYPE EBAN-KNTTP,
      END OF TY_ITAB.
DATA:ITAB TYPE TABLE OF TY_ITAB WITH HEADER LINE.
DATA:WA TYPE TY_ITAB.


TYPES:BEGIN OF TY_RESULT,
      WBS_ELEMENT(24),
      MATERIAL(18),
      QUANTITY(13),
      UNIT(3),
      DELIV_DATE(8),
      PURCH_ORG(4),
*      KNTTP TYPE EBAN-KNTTP,
      FLAG(1),
      NUMBER TYPE BAPIMEREQHEADER-PREQ_NO,
      MESSAGE(1200),
      END OF TY_RESULT.
DATA:IT_RESULT TYPE TABLE OF TY_RESULT with header line.
data: g_info type string.


DATA:PRHEADER TYPE BAPIMEREQHEADER,
     PRHEADERX TYPE BAPIMEREQHEADERX,
     NUMBER TYPE BAPIMEREQHEADER-PREQ_NO,
     PRITEM TYPE TABLE OF BAPIMEREQITEMIMP WITH HEADER LINE,
     PRITEMX TYPE TABLE OF BAPIMEREQITEMX WITH HEADER LINE,
     PRITEMTEXT TYPE TABLE OF BAPIMEREQITEMTEXT WITH HEADER LINE,
     PRACCOUNT TYPE TABLE OF BAPIMEREQACCOUNT WITH HEADER LINE,
     PRACCOUNTX TYPE TABLE OF BAPIMEREQACCOUNTX WITH HEADER LINE,
     RETURN TYPE TABLE OF BAPIRET2 WITH HEADER LINE.
DATA:FLAG(1).


selection-screen begin of block shi with frame title text-001.
parameters:p_file like rlgrap-filename memory id zy1 obligatory.
PARAMETERS:P_WERKS LIKE MARC-WERKS OBLIGATORY.
parameters:P_CHECK  RADIOBUTTON GROUP SHI,
           P_CHECK1  RADIOBUTTON GROUP SHI.
selection-screen end of block shi.


at selection-screen on value-request for p_file.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
    IMPORTING
      file_name     = p_file.


*at selection-screen.
*****加权限对象-----
*  IF P_WERKS IS NOT INITIAL.
*    AUTHORITY-CHECK OBJECT 'M_BANF_WRK'
*                        ID 'ACTVT' FIELD '01'
*                        ID 'WERKS' FIELD P_WERKS.
*    IF SY-SUBRC <> 0.
*      MESSAGE E019(ZMM001) WITH P_WERKS.
*    ENDIF.
*  ENDIF.


START-OF-SELECTION.
  PERFORM FRM_GETDATA.
  PERFORM FRM_MVT_BAPI.
  PERFORM FRM_DOWNLOAD.
*&---------------------------------------------------------------------*
*&      Form  FRM_GETDATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_GETDATA .
  CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
*   CODEPAGE                      = ' '
      FILENAME                      = P_FILE
      FILETYPE                      = 'DAT'
*   HEADLEN                       = ' '
*   LINE_EXIT                     = ' '
*   TRUNCLEN                      = ' '
*   USER_FORM                     = ' '
*   USER_PROG                     = ' '
*   DAT_D_FORMAT                  = ' '
* IMPORTING
*   FILELENGTH                    =
     TABLES
       DATA_TAB                      = ITAB
* EXCEPTIONS
*   CONVERSION_ERROR              = 1
*   FILE_OPEN_ERROR               = 2
*   FILE_READ_ERROR               = 3
*   INVALID_TYPE                  = 4
*   NO_BATCH                      = 5
*   UNKNOWN_ERROR                 = 6
*   INVALID_TABLE_WIDTH           = 7
*   GUI_REFUSE_FILETRANSFER       = 8
*   CUSTOMER_ERROR                = 9
*   OTHERS                        = 10
             .
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.




ENDFORM.                    " FRM_GETDATA
*&---------------------------------------------------------------------*
*&      Form  FRM_MVT_BAPI
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_MVT_BAPI .
  DATA:m_SBDKZ TYPE MARC-SBDKZ.


  LOOP AT ITAB.
    MOVE-CORRESPONDING ITAB TO IT_RESULT.


    CLEAR m_SBDKZ.
    SELECT SINGLE
           SBDKZ
           INTO m_SBDKZ
           FROM
           MARC
           WHERE MATNR = ITAB-MATERIAL AND WERKS = P_WERKS.


*    IF ITAB-KNTTP = ''.
*        IT_RESULT-FLAG = 'E'.
*        IT_RESULT-MESSAGE = '科目分配为空'.
*        APPEND IT_RESULT.
*        CLEAR IT_RESULT.
*    ELSEIF ITAB-KNTTP = '1' AND m_SBDKZ = '2'.
*        IT_RESULT-FLAG = 'E'.
*        IT_RESULT-MESSAGE = '系统库存按非项目管理'.
*        APPEND IT_RESULT.
*        CLEAR IT_RESULT.
*    ELSEIF ITAB-KNTTP = '2' AND m_SBDKZ = '1'.
*        IT_RESULT-FLAG = 'E'.
*        IT_RESULT-MESSAGE = '系统库存按项目管理'.
*        APPEND IT_RESULT.
*        CLEAR IT_RESULT.
*    ELSE.
        IF P_CHECK = 'X'.
          PRHEADER-PR_TYPE = 'NB'.
        ELSE.
          PRHEADER-PR_TYPE = 'ZNB'.
        ENDIF.
        PRHEADERX-PR_TYPE = 'X'.


        PRITEM-PREQ_ITEM = '00010'.
        PRITEM-MATERIAL = ITAB-MATERIAL.
        PRITEM-PLANT = P_WERKS.
        PRITEM-QUANTITY = ITAB-QUANTITY.
        PRITEM-UNIT = ITAB-UNIT.
        PRITEM-DELIV_DATE = ITAB-DELIV_DATE.


*       Modified by liuxy2010-01-25
        IF m_SBDKZ = '1'.
           PRITEM-ACCTASSCAT = 'Q'.
        ELSE.
           PRITEM-ACCTASSCAT = ''.
        ENDIF.


        PRITEM-PURCH_ORG = ITAB-PURCH_ORG.
        APPEND PRITEM.
        CLEAR PRITEM.


        PRITEMX-PREQ_ITEM = '00010'.
        PRITEMX-MATERIAL = 'X'.
        PRITEMX-PLANT = 'X'.
        PRITEMX-QUANTITY = 'X'.
        PRITEMX-UNIT = 'X'.
        PRITEMX-DELIV_DATE = 'X'.
        PRITEMX-ACCTASSCAT = 'X'.
        PRITEMX-PURCH_ORG = 'X'.
        APPEND PRITEMX.
        CLEAR PRITEMX.


        PRITEMTEXT-PREQ_ITEM = '00010'.
        PRITEMTEXT-TEXT_ID = 'B01'.
        PRITEMTEXT-TEXT_LINE = ITAB-WBS_ELEMENT.
        APPEND PRITEMTEXT.
        CLEAR PRITEMTEXT.


        PRACCOUNT-PREQ_ITEM = '00010'.
        PRACCOUNT-SERIAL_NO = '01'.
        PRACCOUNT-WBS_ELEMENT = ITAB-WBS_ELEMENT.
        APPEND PRACCOUNT.
        CLEAR PRACCOUNT.


        PRACCOUNTX-PREQ_ITEM = '00010'.
        PRACCOUNTX-SERIAL_NO = '01'.
        PRACCOUNTX-WBS_ELEMENT = 'X'.
        PRACCOUNTX-PREQ_ITEMX = 'X'.
        APPEND PRACCOUNTX.
        CLEAR PRACCOUNTX.


        CALL FUNCTION 'BAPI_PR_CREATE'
         EXPORTING
           PRHEADER                    = PRHEADER
           PRHEADERX                   = PRHEADERX
*       TESTRUN                     =
         IMPORTING
           NUMBER                      = NUMBER
*       PRHEADEREXP                 =
          TABLES
            RETURN                      = RETURN
            PRITEM                      = PRITEM
            PRITEMX                     = PRITEMX
            PRITEMTEXT                  = PRITEMTEXT
*       PRITEMEXP                   =
*       PRITEMSOURCE                =
            PRACCOUNT                   = PRACCOUNT
*       PRACCOUNTPROITSEGMENT       =
            PRACCOUNTX                  = PRACCOUNTX
*       PRADDRDELIVERY              =
*       PRITEMTEXT                  =
*       PRHEADERTEXT                =
*       EXTENSIONIN                 =
*       EXTENSIONOUT                =
*       PRVERSION                   =
*       PRVERSIONX                  =
*       ALLVERSIONS                 =
                  .


        CLEAR RETURN.
        LOOP AT RETURN WHERE TYPE = 'E' OR TYPE = 'A'.
          FLAG = 'X'.
          IT_RESULT-FLAG = 'E'.
          CONCATENATE IT_RESULT-MESSAGE '&' RETURN-MESSAGE INTO IT_RESULT-MESSAGE.
        ENDLOOP.
        IF FLAG = 'X'.
          CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
        ELSE.
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
          wait up to 1 seconds.
          IT_RESULT-FLAG = 'S'.
          IT_RESULT-MESSAGE = '成功创建!'.
          IT_RESULT-NUMBER = NUMBER.
        ENDIF.
        APPEND IT_RESULT.
        CLEAR IT_RESULT.
        CLEAR PRHEADER.
        CLEAR PRHEADERX.
        CLEAR NUMBER.
        REFRESH PRITEM.
        CLEAR PRITEM.
        REFRESH PRITEMX.
        CLEAR PRITEMX.
        REFRESH PRITEMTEXT.
        CLEAR PRITEMTEXT.
        REFRESH PRACCOUNT.
        CLEAR PRACCOUNT.
        REFRESH PRACCOUNTX.
        CLEAR PRACCOUNTX.
        CLEAR FLAG.
        REFRESH RETURN.
        CLEAR RETURN.
*    ENDIF.
  ENDLOOP.
ENDFORM.                    " FRM_MVT_BAPI
*&---------------------------------------------------------------------*
*&      Form  FRM_DOWNLOAD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_DOWNLOAD .
  CALL FUNCTION 'GUI_DOWNLOAD'
     EXPORTING
*    BIN_FILESIZE                    =
       FILENAME                        = 'C:/PR批导结果表.TXT'
       FILETYPE                        = 'ASC'
       APPEND                          = ' '
*    WRITE_FIELD_SEPARATOR           = ' '
*    HEADER                          = '00'
*    TRUNC_TRAILING_BLANKS           = ' '
*    WRITE_LF                        = 'X'
*    COL_SELECT                      = ' '
*    COL_SELECT_MASK                 = ' '
*    DAT_MODE                        = ' '
*    CONFIRM_OVERWRITE               = ' '
*    NO_AUTH_CHECK                   = ' '
*    CODEPAGE                        = ' '
*    IGNORE_CERR                     = ABAP_TRUE
*    REPLACEMENT                     = '#'
*    WRITE_BOM                       = ' '
*    TRUNC_TRAILING_BLANKS_EOL       = 'X'
*    WK1_N_FORMAT                    = ' '
*    WK1_N_SIZE                      = ' '
*    WK1_T_FORMAT                    = ' '
*    WK1_T_SIZE                      = ' '
*  IMPORTING
*    FILELENGTH                      =
     TABLES
       DATA_TAB                        = IT_RESULT
*    FIELDNAMES                      =
*  EXCEPTIONS
*    FILE_WRITE_ERROR                = 1
*    NO_BATCH                        = 2
*    GUI_REFUSE_FILETRANSFER         = 3
*    INVALID_TYPE                    = 4
*    NO_AUTHORITY                    = 5
*    UNKNOWN_ERROR                   = 6
*    HEADER_NOT_ALLOWED              = 7
*    SEPARATOR_NOT_ALLOWED           = 8
*    FILESIZE_NOT_ALLOWED            = 9
*    HEADER_TOO_LONG                 = 10
*    DP_ERROR_CREATE                 = 11
*    DP_ERROR_SEND                   = 12
*    DP_ERROR_WRITE                  = 13
*    UNKNOWN_DP_ERROR                = 14
*    ACCESS_DENIED                   = 15
*    DP_OUT_OF_MEMORY                = 16
*    DISK_FULL                       = 17
*    DP_TIMEOUT                      = 18
*    FILE_NOT_FOUND                  = 19
*    DATAPROVIDER_EXCEPTION          = 20
*    CONTROL_FLUSH_ERROR             = 21
*    OTHERS                          = 22
             .
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  WRITE:'数据成功保存到C盘根目录下,请查看!'.

ENDFORM.                    " FRM_DOWNLOAD
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-10-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
项目管理
CODING 项目管理(CODING Project Management,CODING-PM)工具包含迭代管理、需求管理、任务管理、缺陷管理、文件/wiki 等功能,适用于研发团队进行项目管理或敏捷开发实践。结合敏捷研发理念,帮助您对产品进行迭代规划,让每个迭代中的需求、任务、缺陷无障碍沟通流转, 让项目开发过程风险可控,达到可持续性快速迭代。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档