SAP中对于获取订单的状态
在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.
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.
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.