BAPI_PRODORDCONF_CREATE_TT 报工(CO11N)

        在LC项目中,根据客户需求,需要封装CO11N,做一个Dialog程序,只对最后一道工序报工,感觉很简单,用BDC方式做了一版,运行期间,问题百出,后来找到函数BAPI_PRODORDCONF_CREATE_TT,解决了问题,代码如下,分享一下,资源共享。

      DATA:IT_TT        TYPE TABLE OF BAPI_PP_TIMETICKET,
               WA_TT        TYPE BAPI_PP_TIMETICKET,
               IT_DR        TYPE TABLE OF BAPI_CORU_RETURN,
               WA_DR        TYPE BAPI_CORU_RETURN,
               WA_RETURN    TYPE BAPIRET1,
               I_ERRMSG     TYPE BAPIRET2-MESSAGE,"记录返回消息中的错误消息
               I_TIME(14)   TYPE C, "传送时间
               I_ERRFLG     TYPE C,
               I_COUNT      TYPE I."用于对导入数据的行数记录

              CLEAR:WA_TT,
                    I_COUNT,
                    I_ERRMSG,
                    I_ERRFLG,
                    WA_RETURN.

*          * 订单号转换
              CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                EXPORTING
                  INPUT = ITAB_SER05-PPAUFNR
                IMPORTING
                  OUTPUT = WA_TT-ORDERID.
              WA_TT-OPERATION = V_VORNR.
              WA_TT-YIELD      = '1'.
              WA_TT-POSTG_DATE = SY-DATUM.


          DATA:C_VORNR TYPE AFVC-VORNR,
               C_AUFNR TYPE AFKO-AUFNR,
               C_APLZL TYPE AFVC-APLZL,
               C_AUFPL TYPE AFVC-AUFPL,
               WA_AFVV TYPE AFVV.

              CLEAR IT_TT.
              REFRESH IT_TT.

              CLEAR IT_DR.
              REFRESH IT_DR.

              SELECT SINGLE AFVC~APLZL AFVC~AUFPL
                            INTO (C_APLZL, C_AUFPL)
                            FROM AFVC INNER JOIN AFKO
                            ON    AFVC~AUFPL = AFKO~AUFPL
                            WHERE AFKO~AUFNR = WA_TT-ORDERID
                            AND   AFVC~VORNR = V_VORNR.

              SELECT SINGLE * FROM AFVV INTO WA_AFVV
                              WHERE AUFPL = C_AUFPL
                              AND   APLZL = C_APLZL.

              WA_TT-FIN_CONF = '1'.

              WA_TT-CONF_ACTI_UNIT1 = WA_AFVV-VGE01.
              WA_TT-CONF_ACTI_UNIT2 = WA_AFVV-VGE02.
              WA_TT-CONF_ACTI_UNIT3 = WA_AFVV-VGE03.
              WA_TT-CONF_ACTI_UNIT4 = WA_AFVV-VGE04.
              WA_TT-CONF_ACTI_UNIT5 = WA_AFVV-VGE05.
              WA_TT-CONF_ACTI_UNIT6 = WA_AFVV-VGE06.
              WA_TT-CONF_ACTIVITY1 = WA_TT-YIELD * WA_AFVV-VGW01 / WA_AFVV-BMSCH.
              WA_TT-CONF_ACTIVITY2 = WA_TT-YIELD * WA_AFVV-VGW02 / WA_AFVV-BMSCH.
              WA_TT-CONF_ACTIVITY3 = WA_TT-YIELD * WA_AFVV-VGW03 / WA_AFVV-BMSCH.
              WA_TT-CONF_ACTIVITY4 = WA_TT-YIELD * WA_AFVV-VGW04 / WA_AFVV-BMSCH.
              WA_TT-CONF_ACTIVITY5 = WA_TT-YIELD * WA_AFVV-VGW05 / WA_AFVV-BMSCH.
              WA_TT-CONF_ACTIVITY6 = WA_TT-YIELD * WA_AFVV-VGW06 / WA_AFVV-BMSCH.
*          ************************

              APPEND WA_TT TO IT_TT.
              CALL FUNCTION 'BAPI_PRODORDCONF_CREATE_TT'   "主要是这个BAPI
                IMPORTING
                  RETURN        = WA_RETURN
                TABLES
                  TIMETICKETS   = IT_TT
                  DETAIL_RETURN = IT_DR.

*             处理BAPI错误
              CLEAR I_ERRFLG.
              CLEAR I_ERRMSG.
              LOOP AT IT_DR INTO WA_DR.
                IF WA_DR-TYPE = 'E'.
                  I_ERRFLG = 'X'.

                  I_ERRMSG = WA_DR-MESSAGE.
                ELSE.

                ENDIF.

                IF I_ERRFLG IS INITIAL.
                  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
                    EXPORTING
                      WAIT = 'X'.

                ELSE.
                  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

                      MESSAGE E232(ZLC) WITH I_ERRMSG.
                      DELETE FROM ZPPBG  WHERE SERNR = RESULT1-SERNR.

                ENDIF.
              ENDLOOP.

  

posted @ 2019-04-01 09:08  Park_SAP  阅读(4084)  评论(0编辑  收藏  举报