首页 > 其他分享 >ABAP:销售订单审批及反审函数

ABAP:销售订单审批及反审函数

时间:2022-12-19 10:48:43浏览次数:56  
标签:反审 BDC bdc field PERFORM 订单 ABAP ls USING

销售订单审批及反审函数:

  DATA:ls_zsdt028 TYPE zsdt028,
       lt_zsdt028 TYPE TABLE OF zsdt028,
       ls_zsdt008 TYPE zsdt008,
       lt_zsdt008 TYPE TABLE OF zsdt008,
       ls_zsdt027 TYPE zsdt027,
       lt_zsdt027 TYPE TABLE OF zsdt027,
       ls_vbak TYPE vbak,
       ls_zrfct002 TYPE zrfct002,
       ls_zrfct005 TYPE zrfct005.

  DATA:lv_canum TYPE canum,
       lv_zrfc_logid TYPE zsdt008-zrfc_logid,
       lv_vbeln TYPE vbak-vbeln.

  CLEAR:lt_zsdt008,ls_zsdt008,lv_canum,lv_zrfc_logid,lv_vbeln.

  "获取源表数据
  CLEAR:lt_zsdt028.
  SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_zsdt028 FROM zsdt028 WHERE zrfc_logid = i_id.
  IF lt_zsdt028 IS INITIAL.
    e_code = 'E'.
    e_msg  = '无可执行数据'.
    RETURN.
  ENDIF.

  lv_canum = i_canum - 10.
  SELECT * INTO TABLE lt_zsdt008 FROM zsdt008 WHERE zrfc_logid = i_id AND canum = lv_canum. "获取上一步审批订单数据

  SORT lt_zsdt008 BY zrfc_logid canum.

  READ TABLE lt_zsdt008 INTO ls_zsdt008 INDEX 1.

  SELECT SINGLE * INTO ls_zsdt027 FROM zsdt027 WHERE zrfcid = ls_zsdt008-zrfcid AND canum = i_canum.    ""获取创建时对应的业务流程

  SELECT SINGLE zrfc_logid INTO lv_zrfc_logid FROM zsdt008 WHERE zrfcid = ls_zsdt027-zzrfcid AND objkey = ls_zsdt008-objkey."获取源头订单ID

  SELECT SINGLE objkey INTO lv_vbeln FROM zsdt008 WHERE zrfc_logid = lv_zrfc_logid AND canum = ls_zsdt027-zcanum.

  CLEAR:lt_zsdt028,ls_zsdt028.
  SELECT SINGLE * INTO ls_zsdt028 FROM zsdt028 WHERE zrfc_logid = i_id.
  IF sy-subrc <> 0.
    e_code = 'E'.
    e_msg  = '无可执行数据'.
    RETURN.
  ENDIF.

  CLEAR:ls_vbak.
  SELECT SINGLE *
    INTO ls_vbak
    FROM vbak
   WHERE vbeln = lv_vbeln.
  IF sy-subrc <> 0.
    e_code = 'E'.
    e_msg  = '无可执行数据'.
    RETURN.
  ENDIF.

  PERFORM frm_release_so USING ls_vbak-vbeln
                               '' "10
                               'X'"20
                         CHANGING e_code e_msg e_flow_end.

  IF e_code = 'E'.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  ELSE.
    CALL METHOD zcl_rfc=>get_source
      EXPORTING
        i_id       = i_id
        i_canum    = i_canum
      IMPORTING
        e_zrfct002 = ls_zrfct002.
*      RECEIVING
*        R_SOURCE   = LS_SOURCE.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.

    CLEAR:ls_zsdt008.
    ls_zsdt008-canum      = ls_zrfct002-canum.
    ls_zsdt008-objtype    = ls_zrfct002-objtype_save.
    ls_zsdt008-objkey     = ls_vbak-vbeln.
    ls_zsdt008-zrfcid     = ls_zrfct002-zrfcid.
    ls_zsdt008-zrfc_logid = i_id.
    APPEND ls_zsdt008 TO lt_zsdt008.

    MODIFY zsdt008 FROM TABLE lt_zsdt008.

    e_code = 'S'.
    CONCATENATE 'SO:' ls_vbak-vbeln '审批成功' INTO e_msg.
*    DATA:ls_zrfct005 TYPE zrfct005.
    CLEAR:ls_zrfct005.
    ls_zrfct005-status = '53'.
    ls_zrfct005-msgty = e_code.
    ls_zrfct005-msgid = '00'.
    ls_zrfct005-msgno = '001'.
    ls_zrfct005-msgv1 = e_msg.
    ls_zrfct005-msgv4 = ls_vbak-vbeln.
    APPEND ls_zrfct005 TO et_return.
  ENDIF.

FORM frm_release_so  USING    uv_vbeln TYPE vbak-vbeln
                              uv_status10
                              uv_status20
                     CHANGING cv_code TYPE msgty
                              cv_msg  TYPE msgtxt
                              cv_flow_end TYPE char01.

*  DATA: lv_mode TYPE c VALUE 'E',
*        ls_msg TYPE bdcmsgcoll.
*  DATA: BEGIN OF msgtab OCCURS 0.
*          INCLUDE STRUCTURE bdcmsgcoll.
*  DATA: END OF msgtab.
*
*  CLEAR bdcdata[].
*
*  PERFORM bdc_dynpro USING 'SAPMV45A' '0102'.
*  PERFORM bdc_field  USING 'BDC_CURSOR'  'VBAK-VBELN'.
*  PERFORM bdc_field  USING 'BDC_OKCODE' '/00'.
*  PERFORM bdc_field  USING 'VBAK-VBELN' uv_vbeln.
*
*
*
*
*  PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.
*  PERFORM bdc_field  USING 'BDC_OKCODE' '=HEAD'.
*  PERFORM bdc_field  USING 'BDC_SUBSCR'  'SAPMV45A                                4021SUBSCREEN_HEADER'.
*  PERFORM bdc_field  USING 'BDC_SUBSCR'  'SAPMV45A                                4701PART-SUB'.
*  PERFORM bdc_field  USING 'BDC_SUBSCR'  'SAPMV45A                                4400SUBSCREEN_BODY'.
*  PERFORM bdc_field  USING 'BDC_SUBSCR'  'SAPMV45A                                4440HEADER_FRAME'.
*  PERFORM bdc_field  USING 'BDC_SUBSCR'  'SAPMV45A                                8310HEAD_USER'.
*  PERFORM bdc_field  USING 'BDC_SUBSCR'  'SAPLV45W                                0400SUBSCREEN_VERTRAG'.
*  PERFORM bdc_field  USING 'BDC_SUBSCR'  'SAPMV45A                                4900SUBSCREEN_TC'.
*  PERFORM bdc_field  USING 'BDC_CURSOR'  'RV45A-MABNR(01)'.
*  PERFORM bdc_field  USING 'BDC_SUBSCR'  'SAPMV45A                                4050SUBSCREEN_BUTTONS'.
*
*  PERFORM bdc_dynpro USING 'SAPMV45A' '4002'.
*  PERFORM bdc_field  USING 'BDC_OKCODE' '=T\10'.
*  PERFORM bdc_field  USING 'BDC_SUBSCR'  'SAPMV45A                                4012SUBSCREEN_HEADER'.
*  PERFORM bdc_field  USING 'BDC_CURSOR'  'RV45A-TXT_VBELN'.
*  PERFORM bdc_field  USING 'BDC_SUBSCR'  'SAPMV45A                                4301SUBSCREEN_BODY'.
*
*  PERFORM bdc_dynpro USING 'SAPMV45A' '4002'.
*  PERFORM bdc_field  USING 'BDC_OKCODE' '=KSTC'.
*  PERFORM bdc_field  USING 'BDC_SUBSCR'  'SAPMV45A                                4012SUBSCREEN_HEADER'.
*  PERFORM bdc_field  USING 'BDC_CURSOR'  'RV45A-TXT_VBELN'.
*  PERFORM bdc_field  USING 'BDC_SUBSCR'  'SAPMV45A                                4301SUBSCREEN_BODY'.
*
*
*  PERFORM bdc_dynpro USING 'SAPLBSVA' '0300'.
*  PERFORM bdc_field  USING 'BDC_OKCODE' '=BACK'.
*  PERFORM bdc_field  USING 'BDC_SUBSCR'  'SAPLBSVA                                0800HEADER'.
*  PERFORM bdc_field  USING 'BDC_SUBSCR'  'SAPLBSVA                                0302SUBSCREEN'.
*  PERFORM bdc_field  USING 'BDC_CURSOR'  'J_STMAINT-ANWS(01)'.
*
*  PERFORM bdc_field  USING 'J_STMAINT-ANWS(01)' uv_status10.
*  PERFORM bdc_field  USING 'J_STMAINT-ANWS(02)' uv_status20.
*
*
*  PERFORM bdc_dynpro USING 'SAPMV45A' '4002'.
*  PERFORM bdc_field  USING 'BDC_OKCODE' '=SICH'.
*  PERFORM bdc_field  USING 'BDC_SUBSCR'  'SAPMV45A                                4012SUBSCREEN_HEADER'.
*  PERFORM bdc_field  USING 'BDC_CURSOR'  'RV45A-TXT_VBELN'.
*  PERFORM bdc_field  USING 'BDC_SUBSCR'  'SAPMV45A                                4301SUBSCREEN_BODY'.
*
*
*
*
*
*
*
*  CALL TRANSACTION 'VA02' USING bdcdata[] MODE lv_mode UPDATE 'E'
*        MESSAGES INTO msgtab.
*
**  WAIT UP TO 1 SECONDS.
*
*  CLEAR bdcdata[].
*
*  READ TABLE msgtab INTO ls_msg WITH KEY msgtyp = 'E'.
*  IF sy-subrc = 0.
*    cv_code = 'E'.
*    MESSAGE ID ls_msg-msgid TYPE ls_msg-msgtyp NUMBER ls_msg-msgnr
*      WITH ls_msg-msgv1 ls_msg-msgv2 ls_msg-msgv3 ls_msg-msgv4
*      INTO cv_msg.
*  ENDIF.


  DATA:ls_vbak TYPE vbak.
  IF uv_status20 IS NOT INITIAL.  "审批
    SELECT SINGLE * INTO ls_vbak FROM vbak WHERE vbeln = uv_vbeln.
    CALL FUNCTION 'STATUS_CHANGE_EXTERN'
      EXPORTING
*         CHECK_ONLY                = ' '
*         CLIENT                    = SY-MANDT
        objnr                     = ls_vbak-objnr
        user_status               = 'E0002'
*         SET_INACT                 = ' '
*         SET_CHGKZ                 =
*         NO_CHECK                  = ' '
*       IMPORTING
*         STONR                     =
*       EXCEPTIONS
*         OBJECT_NOT_FOUND          = 1
*         STATUS_INCONSISTENT       = 2
*         STATUS_NOT_ALLOWED        = 3
*         OTHERS                    = 4
              .
    IF sy-subrc <> 0.
      cv_code = 'E'.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
              INTO cv_msg.
      RETURN.
    ENDIF.
  ELSEIF uv_status10 IS NOT INITIAL. "反审
    SELECT SINGLE * INTO ls_vbak FROM vbak WHERE vbeln = uv_vbeln.
    CALL FUNCTION 'STATUS_CHANGE_EXTERN'
      EXPORTING
*         CHECK_ONLY                = ' '
*         CLIENT                    = SY-MANDT
        objnr                     = ls_vbak-objnr
        user_status               = 'E0001'
*         SET_INACT                 = ' '
*         SET_CHGKZ                 =
*         NO_CHECK                  = ' '
*       IMPORTING
*         STONR                     =
*       EXCEPTIONS
*         OBJECT_NOT_FOUND          = 1
*         STATUS_INCONSISTENT       = 2
*         STATUS_NOT_ALLOWED        = 3
*         OTHERS                    = 4
              .
    IF sy-subrc <> 0.
      cv_code = 'E'.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
              INTO cv_msg.
      RETURN.
    ENDIF.
  ENDIF.
ENDFORM.                    " FRM_RELEASE_SO

 

标签:反审,BDC,bdc,field,PERFORM,订单,ABAP,ls,USING
From: https://www.cnblogs.com/ap-ad-java-abap/p/16991592.html

相关文章