此博客为原创博客,都是个人工作经历所得,转载请注明出处

未清SO关闭处理

 

使用:  SD_SALESDOCUMENT_CHANGE   关闭订单

  DATA: ls_header_in  LIKE bapisdhd1 .
  DATA: ls_header_inx LIKE bapisdhd1x,
        lt_item_in    LIKE TABLE OF bapisditm,
        ls_item_in    LIKE bapisditm,
        lt_item_inx   LIKE TABLE OF bapisditmx,
        ls_item_inx   LIKE bapisditmx,
        lt_bapiret2   LIKE bapiret2   OCCURS 0 WITH HEADER LINE.
  DATA: lv_message    TYPE string.

*BREAK xiangcai.
  LOOP AT pt_data INTO DATA(ls_data).
    SELECT SINGLE lfstk
      INTO @DATA(ls_lfstk)
      FROM vbak
     WHERE vbeln = @ls_data-zbillno.
    IF ls_lfstk = 'C'.
      DATA(lv_msg) = '已完成交货'.
      ls_data-zmess  = '订单已完成交货'.
      ls_data-zpststu = '1'.
      ls_data-updat = sy-datum.
      ls_data-uptim = sy-uzeit.
      ls_data-upnam = sy-uname.
      MODIFY pt_data FROM ls_data.
      CONTINUE.
    ENDIF.
**检查回传的数量 ztotal = 创建的批发销售DN 的项目数量
    CLEAR:ls_zift0008sum.
    READ TABLE lt_zift0008sum INTO ls_zift0008sum WITH KEY zbillno = ls_data-zbillno
                                                           zlineno = ls_data-zlineno
                                                           BINARY SEARCH.

    IF ls_data-ztotal = ls_zift0008sum-ztotal.
      ls_header_inx-updateflag = 'U'.
*      ls_header_in-serv_date = sy-datum .
*      ls_header_inx-serv_date = 'X'.

      ls_item_in-itm_number = ls_data-zlineno.
      ls_item_in-material = ls_data-zmatnr.
      ls_item_in-reason_rej = '01'."拒绝原因
      APPEND ls_item_in TO lt_item_in.
      CLEAR: ls_item_in.

      ls_item_inx-updateflag = 'X'.
      ls_item_inx-itm_number = ls_data-zlineno.
      ls_item_inx-material = 'X'.
      ls_item_inx-reason_rej = 'X'.
      APPEND ls_item_inx TO lt_item_inx.
      CLEAR: ls_item_inx.

    ELSE.
      lv_msg = '前序数据没有接收完全'.
      ls_data-zmess  = '前序数据没有接收完全'.
      ls_data-zpststu = '2'.
      MODIFY pt_data FROM ls_data.
      RETURN.
    ENDIF.
  ENDLOOP.

  IF lt_item_in[] IS NOT INITIAL.
***未清SO关闭处理
    CALL FUNCTION 'SD_SALESDOCUMENT_CHANGE'
      EXPORTING
        salesdocument     = ls_data-zbillno
*       order_header_in   = ls_header_in
        order_header_inx  = ls_header_inx
        behave_when_error = 'P'
      TABLES
        item_in           = lt_item_in
        item_inx          = lt_item_inx
        return            = lt_bapiret2.

    LOOP AT lt_bapiret2 INTO DATA(ls_bapiret2) WHERE type = 'E' OR type = 'A' OR type = 'X'.
      DATA(lv_tyep) = 'E'.
      CLEAR: lv_message.
      MESSAGE ID ls_bapiret2-id
            TYPE ls_bapiret2-type
          NUMBER ls_bapiret2-number
            WITH ls_bapiret2-message_v1 ls_bapiret2-message_v2 ls_bapiret2-message_v3 ls_bapiret2-message_v4
            INTO lv_message.
      ls_data-zmess = ls_data-zmess && lv_message.
    ENDLOOP.



    IF lv_tyep NE 'E'.
      lv_message = 'SO关闭成功'.
      ls_data-zmess   = lv_message.
      ls_data-updat   = sy-datum.
      ls_data-uptim   = sy-uzeit.
      ls_data-upnam   = sy-uname.
      MODIFY pt_data FROM ls_data TRANSPORTING zmess zpststu updat uptim upnam WHERE zpststu NE 1.
    ELSE.
      ls_data-updat   = sy-datum.
      ls_data-uptim   = sy-uzeit.
      ls_data-upnam   = sy-uname.
      MODIFY pt_data FROM ls_data TRANSPORTING zmess zpststu updat uptim upnam WHERE zpststu NE 1.
    ENDIF.

ENDIF.

 

 

出现报错:输入凭证编号 (而且错误是第一次调用函数出现,第二次  第三次 针对这个问题测试 就成功了)

 

 

 

 

 

 走了标准的这段代码

 

 

 

 

 

 

 

 感觉在FORM的上一层,应该走进 ELSE 分支,却走进了 PERFORM  BELEG_LESEN.  的逻辑
进去之后 VBAK-VBELN 为空,所以报错

 

 

为了解决问题,先换用了BDC的方式

  IF lt_item_in[] IS NOT INITIAL.
***未清SO关闭处理
*    CALL FUNCTION 'SD_SALESDOCUMENT_CHANGE'
    READ TABLE pt_data INTO ls_data INDEX 1.
    IF sy-subrc NE 0.
      RETURN.
    ENDIF.
    PERFORM frm_dynpro  USING                                               'SAPMV45A' '0102' 'X'.
    PERFORM frm_dynpro  USING                                                ' ' 'BDC_CURSOR'
                                                                            'VBAK-VBELN'.
    PERFORM frm_dynpro  USING                                                ' ' 'BDC_OKCODE'
                                                                            '=ENT2'.
    PERFORM frm_dynpro  USING                                                ' ' 'VBAK-VBELN'
                                                                            ls_data-zbillno.
    PERFORM frm_dynpro  USING                                               'SAPMV45A' '4001' 'X'.
    PERFORM frm_dynpro  USING                                                ' ' 'BDC_OKCODE'
                                                                            '=BABS'.
    PERFORM frm_dynpro  USING                                                ' ' 'BDC_CURSOR'
                                                                            'RV45A-MABNR(01)'.
    PERFORM frm_dynpro  USING                                               'SAPMV45A' '0250' 'X'.
    PERFORM frm_dynpro  USING                                                ' ' 'BDC_CURSOR'
                                                                            'RV45A-S_ABGRU'.
    PERFORM frm_dynpro  USING                                                ' ' 'BDC_OKCODE'
                                                                            '=SUEB'.
    PERFORM frm_dynpro  USING                                                ' ' 'RV45A-S_ABGRU'
                                                                            '01'."gs_data-S_ABGRU_009.
    PERFORM frm_dynpro  USING                                               'SAPMV45A' '4001' 'X'.
    PERFORM frm_dynpro  USING                                                ' ' 'BDC_OKCODE'
                                                                            '=SICH'.
    PERFORM frm_dynpro  USING                                                ' ' 'VBKD-BSTKD'
                                                                            '01'."gs_data-BSTKD_010.
    PERFORM frm_dynpro  USING                                                ' ' 'BDC_CURSOR'
                                                                            'KUWEV-KUNNR'.
*perform frm_dynpro  using                                                ' ' 'KUWEV-KUNNR'
*                                                                        gs_data-KUNNR_011.
*PERFORM frm_dynpro  USING                                                ' ' 'VBAK-AUGRU'
*                                                                        '01'."gs_data-AUGRU_012.
    CLEAR:gt_messtab[],gt_messtab.
    CALL TRANSACTION 'VA02' USING gt_bdcd
                            MODE gv_mode
                            UPDATE 'S'
                            MESSAGES INTO gt_messtab.
    IF sy-subrc = 0.
      ls_data-zpststu = 1.
    ENDIF.
    LOOP AT gt_messtab WHERE msgtyp = 'E' OR msgtyp = 'A' OR msgtyp = 'X'.
      ls_data-zpststu = 2.
      SELECT SINGLE *
        INTO @DATA(ls_t100)
        FROM t100
       WHERE sprsl = @gt_messtab-msgspra
         AND arbgb = @gt_messtab-msgid
         AND msgnr = @gt_messtab-msgnr.
      IF sy-subrc = 0.
        DATA(l_mstring) = ls_t100-text.
        IF l_mstring CS '&1'.
          REPLACE '&1' WITH gt_messtab-msgv1 INTO l_mstring.
          REPLACE '&2' WITH gt_messtab-msgv2 INTO l_mstring.
          REPLACE '&3' WITH gt_messtab-msgv3 INTO l_mstring.
          REPLACE '&4' WITH gt_messtab-msgv4 INTO l_mstring.
        ELSE.
          REPLACE '&' WITH gt_messtab-msgv1 INTO l_mstring.
          REPLACE '&' WITH gt_messtab-msgv2 INTO l_mstring.
          REPLACE '&' WITH gt_messtab-msgv3 INTO l_mstring.
          REPLACE '&' WITH gt_messtab-msgv4 INTO l_mstring.
        ENDIF.
        CONDENSE l_mstring.
        CONCATENATE ls_data-zmess l_mstring INTO ls_data-zmess.
      ELSE.
        CONCATENATE ls_data-zmess gt_messtab INTO ls_data-zmess.
      ENDIF.
    ENDLOOP.


    IF ls_data-zpststu = 1.
*  lv_type = 'S'.
*  ls_data-zpststu = 1.
*  ZDOCNO
      lv_message = 'SO关闭成功'.
      ls_data-zmess   = lv_message.
      ls_data-updat   = sy-datum.
      ls_data-uptim   = sy-uzeit.
      ls_data-upnam   = sy-uname.
      MODIFY pt_data FROM ls_data TRANSPORTING zmess zpststu updat uptim upnam WHERE zpststu NE 1.
   ELSE.
      ls_data-updat   = sy-datum.
      ls_data-uptim   = sy-uzeit.
      ls_data-upnam   = sy-uname.
      MODIFY pt_data FROM ls_data TRANSPORTING zmess zpststu updat uptim upnam WHERE zpststu NE 1.
**回传回写log表 ZIFT0008
      CLEAR:gv_flag.
      PERFORM frm_update_zift0008 TABLES pt_data
                                  CHANGING gv_flag.
   ENDIF.
ENDIF.

 

 

posted @ 2019-09-29 16:41  Rainystuday  阅读(389)  评论(0编辑  收藏  举报