本文主要是介绍ABAP 工单状态筛选(参考COOIS),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
如果想在自开发的报表中使用类似COOIS的状态来筛选工单可以参考其源码,
主要包含以下几个代码段:
1.定义屏幕元素,由于表TJ02T不含搜索帮助,所以要手工添加:
屏幕元素:
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN:
COMMENT 1(20) TEXT-SYS FOR FIELD P_SYST1 MODIF ID C1,
POSITION 33.
PARAMETERS:
P_SYST1 LIKE TJ02T-TXT04 MODIF ID C1,
P_SYSH1 LIKE JEST-STAT NO-DISPLAY.
SELECTION-SCREEN
POSITION 46.
PARAMETERS:
P_EXCL1 LIKE RCOSA-EXCL1 MODIF ID C1.
SELECTION-SCREEN:
COMMENT 40(5) TEXT-EXC FOR FIELD P_EXCL1 MODIF ID C1,
COMMENT 52(3) TEXT-AND FOR FIELD P_SYST2 MODIF ID C1,
POSITION 58.
PARAMETERS:
P_SYST2 LIKE TJ02T-TXT04 MODIF ID C1,
P_SYSH2 LIKE JEST-STAT NO-DISPLAY.
SELECTION-SCREEN
POSITION 71.
PARAMETERS:
P_EXCL2 LIKE RCOSA-EXCL1 MODIF ID C1.
SELECTION-SCREEN:
COMMENT 65(5) TEXT-EXC FOR FIELD P_EXCL2 MODIF ID C1.
SELECTION-SCREEN END OF LINE.
PARAMETERS:
P_SELID LIKE TJ48T-SELID NO-DISPLAY.
搜索帮助:
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_SYST1.
PERFORM VAL_REQ_STATUS USING 'P_SYST1' CHANGING P_SYST1 P_SYSH1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_SYST2.
PERFORM VAL_REQ_STATUS USING 'P_SYST2' CHANGING P_SYST2 P_SYSH2.
*&---------------------------------------------------------------------*
*& Form val_req_status
*&---------------------------------------------------------------------*
* F4-Help to select system status by text, providing also code
*----------------------------------------------------------------------*
* -->I_DYNPF Name of dynpro field
* -->C_TXT04 Status short text
* -->C_STAT Status code
*----------------------------------------------------------------------*
FORM VAL_REQ_STATUS USING I_DYNPF
CHANGING C_TXT04 LIKE TJ02T-TXT04
C_STAT LIKE JEST-STAT.
TYPES: BEGIN OF TY_VALUE,
ISTAT TYPE J_ISTAT,
TXT04 TYPE J_TXT04,
TXT30 TYPE J_TXT30,
END OF TY_VALUE.
DATA: L_VALUE TYPE DYNFIELDVALUE,
L_REPID TYPE SY-REPID,
LS_DYNP TYPE DYNPREAD,
LS_TJ02 TYPE TJ02,
LS_VALUE TYPE TJ02T,
LS_RETURN TYPE DDSHRETVAL,
LT_DYNP TYPE STANDARD TABLE OF DYNPREAD,
LT_TJ02 TYPE STANDARD TABLE OF TJ02,
LT_VALUE TYPE STANDARD TABLE OF TJ02T,
LT_RETURN TYPE STANDARD TABLE OF DDSHRETVAL.
* personal value key
DATA: L_PVALKEY TYPE DDSHPVKEY.
* Get current value from screen
LS_DYNP-FIELDNAME = I_DYNPF.
APPEND LS_DYNP TO LT_DYNP.
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
DYNAME = SY-REPID
DYNUMB = SY-DYNNR
TABLES
DYNPFIELDS = LT_DYNP
EXCEPTIONS
OTHERS = 0.
READ TABLE LT_DYNP INTO LS_DYNP INDEX 1.
* Get all possible values
SELECT * FROM TJ02 INTO TABLE LT_TJ02
WHERE NODIS = SPACE.
IF LT_TJ02 IS NOT INITIAL.
SELECT * FROM TJ02T INTO TABLE LT_VALUE
FOR ALL ENTRIES IN LT_TJ02
WHERE ISTAT = LT_TJ02-ISTAT
AND SPRAS = SY-LANGU.
ENDIF.
IF LINES( LT_TJ02 ) <> LINES( LT_VALUE ).
* Not all status available in current language, try in german
* as in FORM value_state(saplcoss)
LOOP AT LT_TJ02 INTO LS_TJ02.
READ TABLE LT_VALUE INTO LS_VALUE WITH KEY ISTAT = LS_TJ02-ISTAT.
CHECK SY-SUBRC <> 0.
SELECT SINGLE * FROM TJ02T INTO LS_VALUE
WHERE ISTAT = LS_TJ02-ISTAT
AND SPRAS = 'D'.
IF SY-SUBRC = 0.
APPEND LS_VALUE TO LT_VALUE.
ENDIF.
ENDLOOP.
ENDIF.
SORT LT_VALUE BY ISTAT.
* Call own F4-help, not showing internal status number
L_VALUE = LS_DYNP-FIELDVALUE.
L_REPID = 'PPIO_ENTRY'.
* fill key for personal value list
L_PVALKEY = SY-UNAME.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
DDIC_STRUCTURE = 'TJ02T'
RETFIELD = 'TXT04'
PVALKEY = L_PVALKEY
VALUE = L_VALUE
VALUE_ORG = 'S'
CALLBACK_PROGRAM = L_REPID
CALLBACK_FORM = 'VAL_REQ_STATUS_CALLBACK'
TABLES
VALUE_TAB = LT_VALUE
RETURN_TAB = LT_RETURN.
* Get selectect value and internal status number
READ TABLE LT_RETURN INTO LS_RETURN WITH KEY FIELDNAME = 'ISTAT'.
IF SY-SUBRC = 0.
READ TABLE LT_VALUE WITH KEY ISTAT = LS_RETURN-FIELDVAL
INTO LS_VALUE.
CHECK SY-SUBRC = 0.
C_TXT04 = LS_VALUE-TXT04.
C_STAT = LS_VALUE-ISTAT.
ELSE.
CLEAR: C_TXT04, C_STAT.
ENDIF.
ENDFORM. "val_req_status
2.工单校验:
DATA: BEGIN OF STATUS_TMP OCCURS 0,
STAT LIKE JEST-STAT,
EXCL LIKE RC27X-FLG_SEL,
END OF STATUS_TMP.
DATA: STATUS_HDR_TAB LIKE STATUS_TMP OCCURS 0 WITH HEADER LINE,
STATUS_OPR_TAB LIKE STATUS_TMP OCCURS 0 WITH HEADER LINE,
STATUS_CMP_TAB LIKE STATUS_TMP OCCURS 0 WITH HEADER LINE.
TYPES:
BEGIN OF TYP_S_AUFNR,
AUFNR TYPE AUFNR,
END OF TYP_S_AUFNR,
TYP_TS_AUFNR TYPE SORTED TABLE OF TYP_S_AUFNR
WITH NON-UNIQUE KEY AUFNR,
BEGIN OF TYP_S_OBJNR,
AUFNR TYPE AUFNR,
AUFPL TYPE CO_AUFPL,
APLFL TYPE PLNFOLGE,
PLNFL TYPE PLNFOLGE,
OBJNR TYPE J_OBJNR,
END OF TYP_S_OBJNR,
TYP_TS_AUFNR_OBJNR TYPE SORTED TABLE OF TYP_S_OBJNR
WITH NON-UNIQUE KEY AUFNR OBJNR,
TYP_TS_AUFPL_OBJNR TYPE SORTED TABLE OF TYP_S_OBJNR
WITH NON-UNIQUE KEY AUFPL OBJNR,
TYP_TS_OBJNR TYPE SORTED TABLE OF TYP_S_OBJNR,
BEGIN OF TYP_S_VBELN,
VBELN TYPE VBELN,
END OF TYP_S_VBELN,
TYP_TS_VBELN TYPE SORTED TABLE OF TYP_S_VBELN
WITH NON-UNIQUE KEY VBELN.
DATA: YX VALUE 'X'.
DATA:LTS_OBJNR TYPE TYP_TS_AUFNR_OBJNR.
* APPEND STATUS TO IMPORTED TABLE FOR HEADER SELECTION
PERFORM FILL_STATUS_TABLE
TABLES STATUS_HDR_TAB
USING P_SYST1
P_SYSH1
P_EXCL1
P_SYST2
P_SYSH2
P_EXCL2.
IF STATUS_HDR_TAB[] IS NOT INITIAL.
CLEAR LTS_OBJNR[] .
SELECT AUFNR OBJNR FROM AUFK
INTO CORRESPONDING FIELDS OF TABLE LTS_OBJNR[]
WHERE WERKS = P_PWERK
AND AUFNR IN S_AUFNR
.
PERFORM REDUCE_AUFNR_OBJNR_BY_STATUS
TABLES STATUS_HDR_TAB
USING P_SELID
CHANGING LTS_OBJNR[].
ENDIF.
*&---------------------------------------------------------------------*
*& Form FILL_STATUS_TABLE
*&---------------------------------------------------------------------*
FORM FILL_STATUS_TABLE TABLES STATUS_TAB STRUCTURE STATUS_HDR_TAB
USING SYST1 LIKE TJ02T-TXT04
SYSH1 LIKE JEST-STAT
EXCL1 LIKE RCOSA-EXCL1
SYST2 LIKE TJ02T-TXT04
SYSH2 LIKE JEST-STAT
EXCL2 LIKE RCOSA-EXCL1.
DATA STATUS_TMP LIKE STATUS_HDR_TAB.
* Append status from selection screen to imported status table
IF NOT SYSH1 IS INITIAL.
STATUS_TMP-STAT = SYSH1.
STATUS_TMP-EXCL = EXCL1.
COLLECT STATUS_TMP INTO STATUS_TAB.
ELSEIF NOT SYST1 IS INITIAL.
CALL FUNCTION 'STATUS_TEXT_CONVERSION'
EXPORTING
LANGUAGE = SY-LANGU
TXT04 = SYST1
IMPORTING
STATUS_NUMBER = STATUS_TMP-STAT
EXCEPTIONS
INSUFFICIENT_INPUT = 1
NOT_FOUND = 2
OBJECT_NOT_FOUND = 3
WRONG_MODE = 4
OTHERS = 5.
IF SY-SUBRC EQ 0.
STATUS_TMP-EXCL = EXCL1.
COLLECT STATUS_TMP INTO STATUS_TAB.
ENDIF.
ENDIF.
IF NOT SYSH2 IS INITIAL.
STATUS_TMP-STAT = SYSH2.
STATUS_TMP-EXCL = EXCL2.
COLLECT STATUS_TMP INTO STATUS_TAB.
ELSEIF NOT SYST2 IS INITIAL.
CALL FUNCTION 'STATUS_TEXT_CONVERSION'
EXPORTING
LANGUAGE = SY-LANGU
TXT04 = SYST2
IMPORTING
STATUS_NUMBER = STATUS_TMP-STAT
EXCEPTIONS
INSUFFICIENT_INPUT = 1
NOT_FOUND = 2
OBJECT_NOT_FOUND = 3
WRONG_MODE = 4
OTHERS = 5.
IF SY-SUBRC EQ 0.
STATUS_TMP-EXCL = EXCL2.
COLLECT STATUS_TMP INTO STATUS_TAB.
ENDIF.
ENDIF.
ENDFORM. " FILL_STATUS_TABLE
*&---------------------------------------------------------------------*
*& Form REDUCE_AUFNR_OBJNR_BY_STATUS
*&---------------------------------------------------------------------*
FORM REDUCE_AUFNR_OBJNR_BY_STATUS
TABLES STATUS_TAB STRUCTURE STATUS_HDR_TAB
USING SELID LIKE P_SELID
CHANGING CTS_OBJNR TYPE TYP_TS_OBJNR.
* Statusobjekte
DATA:
OBJNR_TAB LIKE JSTO_PRE OCCURS 0 WITH HEADER LINE.
FIELD-SYMBOLS:
<LS_OBJNR> TYPE TYP_S_OBJNR.
CHECK NOT SELID IS INITIAL
OR NOT STATUS_TAB[] IS INITIAL.
* preread
LOOP AT CTS_OBJNR[] ASSIGNING <LS_OBJNR>.
OBJNR_TAB-OBJNR = <LS_OBJNR>-OBJNR.
APPEND OBJNR_TAB.
ENDLOOP.
CALL FUNCTION 'STATUS_PRE_READ'
TABLES
JSTO_PRE_TAB = OBJNR_TAB.
DATA OBJECTS_DELETED.
PERFORM REDUCE_OBJNR_BY_STATUS
TABLES OBJNR_TAB
STATUS_TAB
USING SELID
CHANGING OBJECTS_DELETED.
IF OBJECTS_DELETED = YX.
* Alle Aufträge entfernen, deren OBJNR nicht mehr in der Tabelle
* OBJNR_TAB enthalten ist.
IF OBJNR_TAB[] IS INITIAL.
REFRESH CTS_OBJNR[].
ELSE.
SORT OBJNR_TAB BY OBJNR.
LOOP AT CTS_OBJNR[] ASSIGNING <LS_OBJNR>.
READ TABLE OBJNR_TAB
WITH KEY OBJNR = <LS_OBJNR>-OBJNR
BINARY SEARCH.
IF SY-SUBRC <> 0.
DELETE CTS_OBJNR[].
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
ENDFORM. " REDUCE_AUFNR_OBJNR_BY_STATUS
*&---------------------------------------------------------------------*
*& Form REDUCE_OBJNR_BY_STATUS
*&---------------------------------------------------------------------*
FORM REDUCE_OBJNR_BY_STATUS
TABLES OBJNR_TAB STRUCTURE OBJNR_TAB
STATUS_TAB STRUCTURE STATUS_HDR_TAB
USING SELID LIKE P_SELID
CHANGING OBJECTS_DELETED.
DATA OBJNR_CNT LIKE SY-DBCNT.
CLEAR OBJECTS_DELETED.
CHECK NOT OBJNR_TAB[] IS INITIAL.
DESCRIBE TABLE OBJNR_TAB LINES OBJNR_CNT.
* Statusprüfung gegen Status in Statustabelle
LOOP AT STATUS_TAB.
IF OBJNR_TAB[] IS INITIAL.
EXIT.
ELSE.
* Alle Objektnummern, bei denen der geforderte Status (nicht) sitzt,
* werden aus der Tabelle OBJNR_TAB gelöscht.
CALL FUNCTION 'STATUS_CHECK_MULTI'
EXPORTING
STATUS = STATUS_TAB-STAT
FLG_EXCLUDE = STATUS_TAB-EXCL
TABLES
OBJECTS = OBJNR_TAB.
ENDIF.
ENDLOOP.
* Statusprüfung gegen das Selektionsschema
IF NOT SELID IS INITIAL.
LOOP AT OBJNR_TAB.
DATA FLG_STATUS_OK TYPE C. "Statusprüfung OK
CALL FUNCTION 'STATUS_CHECK_BY_SELSCHEM'
EXPORTING
OBJNR = OBJNR_TAB-OBJNR
SELID = SELID
IMPORTING
FULLFILL = FLG_STATUS_OK
EXCEPTIONS
NO_STAT_SCHEME = 01
NO_STAT_TAB = 02.
IF SY-SUBRC IS INITIAL
AND FLG_STATUS_OK IS INITIAL.
DELETE OBJNR_TAB.
ENDIF.
ENDLOOP.
ENDIF.
DESCRIBE TABLE OBJNR_TAB LINES SY-DBCNT.
IF SY-DBCNT <> OBJNR_CNT.
OBJECTS_DELETED = YX.
ENDIF.
ENDFORM. " REDUCE_OBJNR_BY_STATUS
执行FORM REDUCE_AUFNR_OBJNR_BY_STATUS 后 表LTS_OBJNR[]中剩余的工单即为通过状态筛选的工单,可以通过 FOR ALL ENTRIES IN 将 LTS_OBJNR[]作为条件
这篇关于ABAP 工单状态筛选(参考COOIS)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!