SAP 销售订单审批状态(查询/修改)

销售订单审批状态启用后,前端显示界面如下图

SAP 销售订单审批状态(查询/修改)_第1张图片

SAP 销售订单审批状态(查询/修改)_第2张图片

销售订单审批状态读取:STATUS_READ

销售订单审批状态修改:I_CHANGE_STATUS

销售订单审批状态读取

代码样例如下:

DATA: lv_objnr   TYPE vbak-objnr,
      lv_objnr_t TYPE jsto-objnr,
      lv_obtyp   TYPE jsto-obtyp,
      lv_stsma   TYPE jsto-stsma,
      lv_stonr   TYPE tj30-stonr,
      lt_status  TYPE TABLE OF jstat,
      ls_status  TYPE jstat.
SELECT SINGLE objnr INTO lv_objnr
    FROM vbak
    WHERE vbeln = i_vbeln.

  IF lv_objnr IS NOT INITIAL.
    lv_objnr_t = lv_objnr.
    CALL FUNCTION 'STATUS_READ'
      EXPORTING
*       CLIENT           = SY-MANDT
        objnr            = lv_objnr_t
*       ONLY_ACTIVE      = ' '
      IMPORTING
        obtyp            = lv_obtyp
        stsma            = lv_stsma
        stonr            = lv_stonr
      TABLES
        status           = lt_status
      EXCEPTIONS
        object_not_found = 1
        OTHERS           = 2.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.
    
    READ TABLE lt_status INTO ls_status WITH KEY stat = lv_estat2
                                                     inact = ''.
    IF sy-subrc = 0.
    ENDIF.
ENDIF.

销售订单审批状态修改

具体代码样例如下:

FUNCTION zjkdms003.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(I_VBELN) TYPE  VBELN_VA OPTIONAL
*"     VALUE(I_ESTAT) TYPE  J_ESTAT OPTIONAL
*"     VALUE(I_APPROVER) TYPE  TEXT30 OPTIONAL
*"     VALUE(I_NAME) TYPE  TEXT30 OPTIONAL
*"  EXPORTING
*"     VALUE(E_MSG) TYPE  BAPIRET2
*"----------------------------------------------------------------------
  DATA: lv_objnr   TYPE vbak-objnr,
        lv_objnr_t TYPE jsto-objnr,
        lv_obtyp   TYPE jsto-obtyp,
        lv_stsma   TYPE jsto-stsma,
        lv_stonr   TYPE tj30-stonr,
        lt_status  TYPE TABLE OF jstat,
        ls_status  TYPE jstat,
        lt_tj30    TYPE TABLE OF tj30,
        ls_tj30    TYPE tj30,
        lv_estat1  TYPE tj30-estat,
        lv_estat2  TYPE tj30-estat,
        lv_estat3  TYPE tj30-estat,
        ieinfo     TYPE einfo,
        lt_003     TYPE TABLE OF ztjkdms003,
        ls_003     TYPE ztjkdms003.

  CLEAR: lv_objnr,
         lv_objnr_t,
         lv_obtyp,
         lv_stsma,
         lv_stonr,
         lt_status,
         ls_status,
         lt_tj30,
         ls_tj30,
         lv_estat1,
         lv_estat2,
         lv_estat3,
         ieinfo,
         lt_003,
         ls_003.

  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = i_vbeln
    IMPORTING
      output = i_vbeln.

  SELECT SINGLE objnr INTO lv_objnr
    FROM vbak
    WHERE vbeln = i_vbeln.

  IF lv_objnr IS NOT INITIAL.
    lv_objnr_t = lv_objnr.
    CALL FUNCTION 'STATUS_READ'
      EXPORTING
*       CLIENT           = SY-MANDT
        objnr            = lv_objnr_t
*       ONLY_ACTIVE      = ' '
      IMPORTING
        obtyp            = lv_obtyp
        stsma            = lv_stsma
        stonr            = lv_stonr
      TABLES
        status           = lt_status
      EXCEPTIONS
        object_not_found = 1
        OTHERS           = 2.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

    IF lt_status IS NOT INITIAL.
      SELECT * INTO TABLE lt_tj30
        FROM tj30
        WHERE stsma = lv_stsma.
      SORT lt_tj30 BY estat.

      CLEAR: ls_tj30.
      READ TABLE lt_tj30 INTO ls_tj30 INDEX 1.
      IF sy-subrc = 0.
        lv_estat1 = ls_tj30-estat.
      ENDIF.

      CLEAR: ls_tj30.
      READ TABLE lt_tj30 INTO ls_tj30 INDEX 2.
      IF sy-subrc = 0.
        lv_estat2 = ls_tj30-estat.
      ENDIF.

      CLEAR: ls_tj30.
      READ TABLE lt_tj30 INTO ls_tj30 INDEX 3.
      IF sy-subrc = 0.
        lv_estat3 = ls_tj30-estat.
      ENDIF.

      IF i_estat = lv_estat1.
        READ TABLE lt_status INTO ls_status WITH KEY stat = lv_estat2
                                                     inact = ''.
        IF sy-subrc = 0.
          CALL FUNCTION 'I_CHANGE_STATUS'
            EXPORTING
              objnr          = lv_objnr_t
              estat_inactive = lv_estat2
              estat_active   = lv_estat1
              stsma          = lv_stsma
            EXCEPTIONS
              cannot_update  = 1
              OTHERS         = 2.
        ENDIF.

        READ TABLE lt_status INTO ls_status WITH KEY stat = lv_estat3
                                                     inact = ''.
        IF sy-subrc = 0.
          CALL FUNCTION 'I_CHANGE_STATUS'
            EXPORTING
              objnr          = lv_objnr_t
              estat_inactive = lv_estat3
              estat_active   = lv_estat1
              stsma          = lv_stsma
            EXCEPTIONS
              cannot_update  = 1
              OTHERS         = 2.
        ENDIF.

        IF sy-subrc <> 0.
* Implement suitable error handling here
        ENDIF.

        IF sy-msgty = 'E' OR sy-msgty = 'A'.
          e_msg-type = sy-msgty.
          e_msg-id = sy-msgid.
          e_msg-number = sy-msgno.
          ieinfo-msgid = sy-msgid.
          ieinfo-msgty = sy-msgty.
          ieinfo-msgno = sy-msgno.
          CALL FUNCTION 'MESSAGE_GET_TEXT'
            EXPORTING
              ieinfo        = ieinfo
              ilangu        = '1'
            IMPORTING
              etext         = e_msg-message
            EXCEPTIONS
              no_t100_found = 1
              OTHERS        = 2.
          IF sy-subrc <> 0.
* Implement suitable error handling here
          ENDIF.
        ELSE.
          e_msg-type = 'S'.
          e_msg-message = '审批成功'.
        ENDIF.
      ENDIF.

      IF i_estat = lv_estat2.
        READ TABLE lt_status INTO ls_status WITH KEY stat = lv_estat1
                                                     inact = ''.
        IF sy-subrc = 0.
          CALL FUNCTION 'I_CHANGE_STATUS'
            EXPORTING
              objnr          = lv_objnr_t
              estat_inactive = lv_estat1
              estat_active   = lv_estat2
              stsma          = lv_stsma
            EXCEPTIONS
              cannot_update  = 1
              OTHERS         = 2.
        ENDIF.

        READ TABLE lt_status INTO ls_status WITH KEY stat = lv_estat3
                                                     inact = ''.
        IF sy-subrc = 0.
          CALL FUNCTION 'I_CHANGE_STATUS'
            EXPORTING
              objnr          = lv_objnr_t
              estat_inactive = lv_estat3
              estat_active   = lv_estat2
              stsma          = lv_stsma
            EXCEPTIONS
              cannot_update  = 1
              OTHERS         = 2.
        ENDIF.

        IF sy-subrc <> 0.
* Implement suitable error handling here
        ENDIF.

        IF sy-msgty = 'E' OR sy-msgty = 'A'.
          e_msg-type = sy-msgty.
          e_msg-id = sy-msgid.
          e_msg-number = sy-msgno.
          ieinfo-msgid = sy-msgid.
          ieinfo-msgty = sy-msgty.
          ieinfo-msgno = sy-msgno.
          CALL FUNCTION 'MESSAGE_GET_TEXT'
            EXPORTING
              ieinfo        = ieinfo
              ilangu        = '1'
            IMPORTING
              etext         = e_msg-message
            EXCEPTIONS
              no_t100_found = 1
              OTHERS        = 2.
          IF sy-subrc <> 0.
* Implement suitable error handling here
          ENDIF.
        ELSE.
          e_msg-type = 'S'.
          e_msg-message = '审批成功'.
        ENDIF.
      ENDIF.

      IF i_estat = lv_estat3.
        IF lv_estat3 IS NOT INITIAL.
          READ TABLE lt_status INTO ls_status WITH KEY stat = lv_estat2
                                                       inact = ''.
          IF sy-subrc = 0.
            CALL FUNCTION 'I_CHANGE_STATUS'
              EXPORTING
                objnr          = lv_objnr_t
                estat_inactive = lv_estat2
                estat_active   = lv_estat3
                stsma          = lv_stsma
              EXCEPTIONS
                cannot_update  = 1
                OTHERS         = 2.
          ENDIF.

          READ TABLE lt_status INTO ls_status WITH KEY stat = lv_estat1
                                                       inact = ''.
          IF sy-subrc = 0.
            CALL FUNCTION 'I_CHANGE_STATUS'
              EXPORTING
                objnr          = lv_objnr_t
                estat_inactive = lv_estat1
                estat_active   = lv_estat3
                stsma          = lv_stsma
              EXCEPTIONS
                cannot_update  = 1
                OTHERS         = 2.
          ENDIF.

          IF sy-subrc <> 0.
* Implement suitable error handling here
          ENDIF.

          IF sy-msgty = 'E' OR sy-msgty = 'A'.
            e_msg-type = sy-msgty.
            e_msg-id = sy-msgid.
            e_msg-number = sy-msgno.
            ieinfo-msgid = sy-msgid.
            ieinfo-msgty = sy-msgty.
            ieinfo-msgno = sy-msgno.
            CALL FUNCTION 'MESSAGE_GET_TEXT'
              EXPORTING
                ieinfo        = ieinfo
                ilangu        = '1'
              IMPORTING
                etext         = e_msg-message
              EXCEPTIONS
                no_t100_found = 1
                OTHERS        = 2.
            IF sy-subrc <> 0.
* Implement suitable error handling here
            ENDIF.
          ELSE.
            e_msg-type = 'S'.
            e_msg-message = '审批成功'.
          ENDIF.
        ENDIF.
      ENDIF.

      IF i_estat IS INITIAL.
        e_msg-type = 'E'.
        e_msg-message = '请指定审批节点'.
      ENDIF.

    ENDIF.

  ENDIF.

  IF e_msg-type = 'S'. "当状态更新成功后,记录当前审批人信息
    ls_003-vbeln = i_vbeln.
    ls_003-estat = i_estat.
    ls_003-approver = i_approver.
    ls_003-name = i_name.
    ls_003-erdat = sy-datum.
    ls_003-erzet = sy-uzeit.
    COLLECT ls_003 INTO lt_003.
    CLEAR: ls_003.

    IF lt_003 IS NOT INITIAL.
      MODIFY ztjkdms003 FROM TABLE lt_003.
      IF sy-subrc = 0.
        COMMIT WORK AND WAIT.
      ELSE.
        ROLLBACK WORK.
      ENDIF.
    ENDIF.
  ENDIF.

ENDFUNCTION.

销售订单审批状态更新日志表

表:JCDS

SAP 销售订单审批状态(查询/修改)_第3张图片

你可能感兴趣的:(sap)