CONCATENATE 'OR' TWK1-AUFNR INTO Z_OBJNR. DATA:objnr TYPE aufk-objnr. objnr = 'OR000000100014'. DATA:t_status TYPE TABLE OF jstat WITH HEADER LINE. "结果存放在STATUS表中 CALL FUNCTION 'STATUS_READ' EXPORTING client = sy-mandt objnr = 'OR000001100154' TABLES status = t_status EXCEPTIONS object_not_found = 1 OTHERS = 2. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. LOOP AT t_status. IF t_status-STAT = 'I0002' AND t_status-INACT = 'X'. WRITE:'已删除'. EXIT. ENDIF. ENDLOOP. DATA:line TYPE bsvx-sttxt. CALL FUNCTION 'STATUS_TEXT_EDIT' EXPORTING FLG_USER_STAT = 'X' OBJNR = 'OR000001100154' ONLY_ACTIVE = 'X' SPRAS = SY-LANGU IMPORTING LINE = line EXCEPTIONS OBJECT_NOT_FOUND = 01 OTHERS = 02. WRITE:line. SEARCH line FOR 'CLSD'. IF sy-subrc = 0. WRITE:'订单已关闭'. ENDIF.
在SAP中对于如何获取订单的状态,提供了至少两个函数(我自己知道的),分别是 STATUS_READ 和 STATUS_TEXT_EDIT。下面简单介绍这两个函数 1.STATUS_READ 改函数的实现原理大概是通过订单的对象好(OR+订单号)到JEST中取出字段STAT INACT. JEST表中STAT是一串从字面看不出意思的字符,可以根据STAT到表TJ02T中找到具体的描述。 下面是具体用法 DATA:objnr TYPE aufk-objnr. objnr = 'OR000000100014'. DATA:t_status TYPE TABLE OF jstat WITH HEADER LINE. "结果存放在STATUS表中 CALL FUNCTION 'STATUS_READ' EXPORTING client = sy-mandt objnr = objnr TABLES status = t_status EXCEPTIONS object_not_found = 1 OTHERS = 2. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. LOOP AT t_status. IF t_status = 'I0046'. WRITE:'订单已关闭'. EXIT. ENDIF. ENDLOOP. 2.STATUS_TEXT_EDIT 改函数读取的结果是将订单状态拼接到一个字符串中,而且这个字符串是在前台订单上看到的状态,比较直接,这样做的结果就可能由于状态较多导致长度过长,在某些情况下取的数据可能不准。 下面是一段代码 DATA:line TYPE bsvx-sttxt. CALL FUNCTION 'STATUS_TEXT_EDIT' EXPORTING client = sy-mandt objnr = objnr spras = sy-langu IMPORTING line = line EXCEPTIONS object_not_found = 1 OTHERS . " IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. SEARCH line FOR 'CLSD'. IF sy-subrc = 0. WRITE:'订单已关闭'. ENDIF.
2012-10-17 16:35:43