ABAP创建OA流程,日期格式问题

Posted yddwinter

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ABAP创建OA流程,日期格式问题相关的知识,希望对你有一定的参考价值。

1. 代码:

DATA:lv_date TYPE d.
DATA:lv_datestring TYPE string."传到OA的日期,如2023-01-09

lv_date = sy-datum.
CONCATENATE lv_date+0(4) lv_date+4(2) lv_date+6(2)
INTO lv_datestring
SEPARATED BY \'-\'.

ls_main1-field_name  = \'CJSJ\'.
ls_main1-field_value = lv_datestring.
ls_main1-view = \'X\'.
ls_main1-edit = \'X\'.
APPEND ls_main1 TO lt_main1.

2. 效果

ABAP 创建客户

  CALL METHOD CMD_EI_API=>MAINTAIN_BAPI

 

FUNCTION Z_CS_RFC_OA002 .
*"----------------------------------------------------------------------
*"*"本地接口:
*"  EXPORTING
*"     VALUE(EX_TYPE) TYPE  CHAR1
*"     VALUE(EX_MSG) TYPE  STRING
*"     VALUE(EX_VALUE) TYPE  KUNNR
*"  TABLES
*"      IN_DATA STRUCTURE  ZSCS_002
*"----------------------------------------------------------------------
  DATA:G_LIN TYPE STRING.
  DATA:LV_FLG.
  DATA:G_PARNR TYPE PARNR..

  DATA:LS_MAIN       TYPE CMDS_EI_MAIN,
       LS_MAIN1      TYPE CMDS_EI_MAIN,
       LS_MAIN2      TYPE CMDS_EI_MAIN,
       LS_MESG       TYPE CVIS_MESSAGE,
       LS_MESG1      TYPE CVIS_MESSAGE,
       LT_MSG        TYPE BAPIRET2_T,
       LWA_MSG       TYPE BAPIRET2,
       LT_CUST       TYPE CMDS_EI_EXTERN_T,
       LWA_CUST      TYPE CMDS_EI_EXTERN,
       LWA_SALE      TYPE CMDS_EI_SALES,
       LT_SALE       TYPE CMDS_EI_SALES_T,
       LT_FUNCTIONS  TYPE CMDS_EI_FUNCTIONS_T,
       LWA_FUNCTIONS TYPE CMDS_EI_FUNCTIONS,
       LT_COMPANY    TYPE CMDS_EI_COMPANY_T,
       LT_TEXT       TYPE CVIS_EI_TEXT_T,
       LWA_TEXT      TYPE CVIS_EI_TEXT,
       LT_CONTENT    TYPE TLINE_TAB,
       LWA_CONTENT   TYPE TLINE,
       LWA_TAX       TYPE CMDS_EI_TAX_IND,
       LT_TAX        TYPE CMDS_EI_TAX_IND_T,
       LT_REMARK     TYPE CVIS_EI_REM_T,
       LWA_REMARK    TYPE CVIS_EI_REM,
       LT_TEL        TYPE CVIS_EI_TLX_T,
       LWA_TEL       TYPE CVIS_EI_TLX_STR,
       LT_FAX        TYPE CVIS_EI_FAX_T,
       LWA_FAX       TYPE CVIS_EI_FAX_STR,
       LT_MAIL       TYPE CVIS_EI_SMTP_T,
       LWA_MAIL      TYPE CVIS_EI_SMTP_STR,
       LT_TEL01      TYPE CVIS_EI_TTX_T,
       LWA_TEL01     TYPE CVIS_EI_TTX_STR,
       LT_CONTACT    TYPE CMDS_EI_CONTACTS_T,
       LWA_CONTACT   TYPE CMDS_EI_CONTACTS,
       LT_VERSION    TYPE CVI_EI_VERSION_TYPE1_T,
       LWA_VERSION   TYPE CVI_EI_VERSION_TYPE1,
       LT_PHONE      TYPE CVIS_EI_PHONE_T,
       LWA_PHONE     TYPE CVIS_EI_PHONE_STR,
       LT_PHONE1     TYPE CVIS_EI_PHONE_T,
       LWA_PHONE1    TYPE CVIS_EI_PHONE_STR,
       LWA_COMPANY   TYPE CMDS_EI_COMPANY,
       LT_GET        TYPE CMDS_EI_EXTERN_T,
       LWA_GET       TYPE CMDS_EI_EXTERN.

  CONSTANTS:CON_INSERT TYPE C VALUE I,
            CON_UPDATE TYPE C VALUE M.
*&---------------------------------------------------------------

*&S1.检查数据条目数
  G_LIN = LINES( IN_DATA[] ).
  IF G_LIN EQ 0.
    EX_TYPE = E.
    EX_MSG = 没有数据!.
  ELSEIF G_LIN GT 30.
    EX_TYPE = E.
    EX_MSG = 数据大于30条!.
  ENDIF.

  CHECK EX_TYPE NE E.

  LOOP AT IN_DATA.
*&S2.1.主数据
    LWA_CUST-HEADER-OBJECT_TASK = I.
    LWA_CUST-CENTRAL_DATA-CENTRAL-DATA-KTOKD = Z001.  "客户帐户组
*&sign
    LWA_CUST-CENTRAL_DATA-CENTRAL-DATAX-KTOKD = X.
*LWA_CUST-CENTRAL_DATA-CENTRAL-DATAX-CIVVE = X.
*&S2.2.地址数据
    LWA_CUST-CENTRAL_DATA-ADDRESS-TASK = I.
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-TITLE   = 0003.        "关键字 ‘3‘公司
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-NAME    = 重庆火锅客户."客户名称
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-LANGU   = SY-LANGU.
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-COUNTRY = CN.
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATA-STREET  = 重庆渝中区新华路123号.
*&sign
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-TITLE = X.
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-NAME  = X.
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-LANGU = X.
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-COUNTRY = X.
    LWA_CUST-CENTRAL_DATA-ADDRESS-POSTAL-DATAX-STREET  = X.
*&S2.3电话
    CLEAR:LWA_PHONE.
    REFRESH LT_PHONE.
    LWA_PHONE-CONTACT-TASK = CON_INSERT.
    LWA_PHONE-CONTACT-DATA-TELEPHONE = 18866666666."电话号码 W_BASIS-TEL.
    LWA_PHONE-CONTACT-DATAX-TELEPHONE = X.
    APPEND LWA_PHONE TO LT_PHONE.
    LWA_CUST-CENTRAL_DATA-ADDRESS-COMMUNICATION-PHONE-PHONE = LT_PHONE.
**S2.4联系人1
*CLEAR:G_PARNR.
*CALL FUNCTION NUMBER_GET_NEXT
*  EXPORTING
*    NR_RANGE_NR             = AP
*    OBJECT                  = PARTNER
*    QUANTITY                = 1
*  IMPORTING
*    NUMBER                  = G_PARNR
*  EXCEPTIONS
*    INTERVAL_NOT_FOUND      = 1
*    NUMBER_RANGE_NOT_INTERN = 2
*    OBJECT_NOT_FOUND        = 3
*    QUANTITY_IS_0           = 4
*    QUANTITY_IS_NOT_1       = 5
*    INTERVAL_OVERFLOW       = 6
*    BUFFER_OVERFLOW         = 7
*    OTHERS                  = 8.
*LWA_CONTACT-TASK = I.
*LWA_CONTACT-ADDRESS_TYPE_3-TASK = I.
*LWA_CONTACT-DATA_KEY-PARNR = G_PARNR.
*LWA_CONTACT-ADDRESS_TYPE_3-POSTAL-DATA-FIRSTNAME  = aa.
*LWA_CONTACT-ADDRESS_TYPE_3-POSTAL-DATA-LASTNAME   = bb.
*LWA_CONTACT-ADDRESS_TYPE_3-POSTAL-DATAX-FIRSTNAME = X.
*LWA_CONTACT-ADDRESS_TYPE_3-POSTAL-DATAX-LASTNAME  = X.
*LWA_CONTACT-ADDRESS_TYPE_3-COMMUNICATION-PHONE-PHONE = LT_PHONE1.
*APPEND LWA_CONTACT TO LT_CONTACT.
*LWA_CUST-CENTRAL_DATA-CONTACT-CONTACTS = LT_CONTACT.
*&S2.5联系人电话
*lwa_phone1-contact-task = I.
*lwa_phone1-contact-data-telephone = 89999888.
*lwa_phone1-contact-data-extension = 3434343.
*lwa_phone1-contact-datax-extension = X.
*lwa_phone1-contact-datax-telephone = X.
*APPEND lwa_phone1 TO lt_phone1.

*&get in_data.
    APPEND LWA_CUST TO LT_CUST.
    LS_MAIN-CUSTOMERS = LT_CUST."客户 (Tab.) 的复杂外部接口
*&S3.Create custmer
    CALL METHOD CMD_EI_API=>MAINTAIN_BAPI
      EXPORTING
*       IV_TEST_RUN              = P_TEST
        IV_COLLECT_MESSAGES      = X
        IS_MASTER_DATA           = LS_MAIN
      IMPORTING
        ES_MASTER_DATA_CORRECT   = LS_MAIN1
        ES_MESSAGE_CORRECT       = LS_MESG1
        ES_MASTER_DATA_DEFECTIVE = LS_MAIN2
        ES_MESSAGE_DEFECTIVE     = LS_MESG.

*&S3.1get message
    LT_MSG = LS_MESG-MESSAGES.
    LT_GET[] = LS_MAIN1-CUSTOMERS.
*&S3.2.get return:
    LOOP AT LT_MSG INTO LWA_MSG WHERE TYPE = E OR TYPE = A.
      EX_TYPE = E.
      EX_MSG  = LWA_MSG-MESSAGE.
    ENDLOOP.
*&S3.3.成功commit work
    IF EX_TYPE NE E.
      COMMIT WORK.
      READ TABLE LT_GET INTO LWA_GET INDEX 1.
*&S3.3Get custmer
      EX_VALUE = LWA_GET-HEADER-OBJECT_INSTANCE-KUNNR.
      IN_DATA-KUNNR = LWA_GET-HEADER-OBJECT_INSTANCE-KUNNR.
      EX_TYPE = S.
      EX_MSG  = 新增客户成功!.
*&bdc 写联系人
      PERFORM BDC_DYNPRO      USING SAPMF02D 0101.
      PERFORM BDC_FIELD       USING BDC_CURSOR
                                    RF02D-D0360.
      PERFORM BDC_FIELD       USING BDC_OKCODE
                                    /00.
      PERFORM BDC_FIELD       USING RF02D-KUNNR
                                    IN_DATA-KUNNR.
      PERFORM BDC_FIELD       USING RF02D-D0360
                                    X. "RECORD-D0360_002.
      PERFORM BDC_DYNPRO      USING SAPMF02D 0360.
      PERFORM BDC_FIELD       USING BDC_CURSOR
                                    KNVK-TELF1(01).
      PERFORM BDC_FIELD       USING BDC_OKCODE
                                    =ENTR.
*      PERFORM BDC_FIELD       USING KNVK-ANRED(01)
*                                    RECORD-ANRED_01_003.
*      PERFORM BDC_FIELD       USING KNVK-NAMEV(01)
*                                    RECORD-NAMEV_01_004.
      PERFORM BDC_FIELD       USING KNVK-NAME1(01)
                                    IN_DATA-NAME1."RECORD-NAME1_01_005.
      PERFORM BDC_FIELD       USING KNVK-TELF1(01)
                                    IN_DATA-TELF1."RECORD-TELF1_01_006.
      PERFORM BDC_DYNPRO      USING SAPMF02D 0360.
      PERFORM BDC_FIELD       USING BDC_CURSOR
                                    KNVK-ABTNR(01).
      PERFORM BDC_FIELD       USING BDC_OKCODE
                                    =ENTR.
      PERFORM BDC_FIELD       USING KNVK-ABTNR(01)
                                    =ENTR."RECORD-ABTNR_01_007.
      PERFORM BDC_DYNPRO      USING SAPMF02D 0360.
      PERFORM BDC_FIELD       USING BDC_CURSOR
                                    KNVK-NAMEV(01).
      PERFORM BDC_FIELD       USING BDC_OKCODE
                                    =UPDA.
* PERFORM BDC_TRANSACTION USING XD02.
      CALL TRANSACTION XD02 USING BDCDATA  MODE N MESSAGES INTO IT_MESSAGE.
      CLEAR BDCDATA.
      WAIT UP TO 1 SECONDS.

      READ TABLE IT_MESSAGE WITH KEY MSGTYP = E.
      IF SY-SUBRC EQ 0.
        EX_TYPE = W.
        EX_MSG  = 供应商联系人信息创建失败!.
       ENDIF.
*&S3.4.error 则rollback.
    ELSE.
      ROLLBACK WORK.
    ENDIF.

  ENDLOOP.

ENDFUNCTION.

 

以上是关于ABAP创建OA流程,日期格式问题的主要内容,如果未能解决你的问题,请参考以下文章

ABAP 创建客户

ABAP调用WebService时日期类型问题

ABAP函数篇1 日期函数

关于泛微OA创建新流程表单无法前台显示字段

泛微OA外部流程触发设置

ABAP必备基础语法