SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L1S31 { font-style. italic; color: #808080; } .L1S32 { color: #3399FF; } .L1S33 { color: #4DA619; } .L1S52 { color: #0000FF; } *&---------------------------------------------------------------------*
*& Report /TDK/CB00030
*&
*&---------------------------------------------------------------------*
*&
*PROGRAM : /TDK/CB00030
*CREATE BY : WANG JIANG TAO
*DATE: 2012.12.14
*DESCRIPTION : Selection List Update
************************************************************************
* CHANGE LOG
* DATE NO CHANGED BY CONTENTS
* 2012/12/14 r01-00 a6023629 Create New
REPORT /TDK/CB00030 NO STANDARD PAGE HEADING
LINE-COUNT 220
LINE-SIZE 110.
TYPE-POOLS : SSCR,SLIS.
TABLES : T001K,KALAMATCON1,/TDK/CT000501,/TDK/CT000201.
*DATA : Z_YEAR(4) TYPE C,
* Z_MONTH(2) TYPE C.
DATA: RESTRICT TYPE SSCR_RESTRICT,
OPTLIST TYPE SSCR_OPT_LIST,
ASS TYPE SSCR_ASS.
DATA : TH_T001K LIKE T001K,
TD_T001K LIKE TABLE OF TH_T001K.
DATA : LTH_KOKRS LIKE TKA02-KOKRS.
DATA : TD_KALAMATCON1 LIKE TABLE OF KALAMATCON1,
TH_KALAMATCON1 LIKE LINE OF TD_KALAMATCON1.
DATA : TD_KALAMATCON1_ALL LIKE TABLE OF KALAMATCON1,
TH_KALAMATCON1_ALL LIKE LINE OF TD_KALAMATCON1.
DATA : LTH_DATUM LIKE SY-DATUM,
LTH_UZEIT LIKE SY-UZEIT,
LTH_NAME LIKE SY-UNAME,
LTH_CPROG LIKE SY-CPROG.
DATA : BEGIN OF TH_MARC,
MATNR LIKE MARC-MATNR, " Material
WERKS LIKE MARC-WERKS, " Plant
PRCTR LIKE MARC-PRCTR, " Profit Center
MMSTA LIKE MARC-MMSTA, " Plant Specific Material Status
END OF TH_MARC.
DATA : TD_MARC LIKE TABLE OF TH_MARC.
DATA : LTH_FIRST_DAY LIKE BAPI0002_4-POSTING_DATE,
LTH_LAST_DAY LIKE BAPI0002_4-POSTING_DATE.
DATA : LTH_MONTH LIKE BAPI0002_4-FISCAL_PERIOD,
LTH_YEAR LIKE BAPI0002_4-FISCAL_YEAR.
DATA : TD_MAT_HIER TYPE STANDARD TABLE OF /TDK/SC0002,
TH_MAT_HIER LIKE LINE OF TD_MAT_HIER,
LTD_MATNR LIKE STANDARD TABLE OF /TDK/SC0001,
LST_MATNR LIKE LINE OF LTD_MATNR.
DATA : BEGIN OF TH_ARRANGE_DATA,
WERKS LIKE MARC-WERKS,
MATNR LIKE MARC-MATNR,
BU(34) TYPE C,
CBU(34) TYPE C,
SBU(34) TYPE C,
PRCTR LIKE MARC-PRCTR,
TDKGROUP(9) TYPE C,
DATUM LIKE SY-DATUM,
UZEIT LIKE SY-UZEIT,
NAME LIKE SY-UNAME,
CPROG LIKE SY-CPROG,
END OF TH_ARRANGE_DATA,
TD_ARRANGE_DATA LIKE TABLE OF TH_ARRANGE_DATA.
DATA : BEGIN OF TH_EXPORT_DATA,
MATCONID LIKE KALAMATCON1-MATCONID,
MATNR LIKE MARC-MATNR,
BWKEY LIKE MARC-WERKS,
BU(34) TYPE C,
CBU(34) TYPE C,
SBU(34) TYPE C,
PRCTR LIKE MARC-PRCTR,
TDKGROUP(9) TYPE C,
DATUM LIKE SY-DATUM,
UZEIT LIKE SY-UZEIT,
UNAME LIKE SY-UNAME,
CPROG LIKE SY-CPROG,
END OF TH_EXPORT_DATA,
TD_EXPORT_DATA LIKE TABLE OF TH_EXPORT_DATA.
DATA : TH_MATCON LIKE KALAMATCON2,
TD_MATCON LIKE TABLE OF TH_MATCON,
TH_MATCON_ALL LIKE TH_MATCON,
TD_MATCON_ALL LIKE TABLE OF TH_MATCON,
MATCONID TYPE CK_MATCONID,
MATCONTXT TYPE CK_MATCONTXT.
DATA : TH_/TDK/CT000501 LIKE /TDK/CT000501,
TD_/TDK/CT000501 LIKE TABLE OF TH_/TDK/CT000501.
DATA:
TH_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
TH_LAYOUT TYPE SLIS_LAYOUT_ALV,
TD_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
CONSTANTS:
C_X TYPE CHAR1 VALUE 'X',
FIELD TYPE CHAR1 VALUE '_'.
*CONSTANTS CNS_EXEC(4) TYPE C VALUE 'ONLI'.
*DATA TD_EXCLUDE TYPE TABLE OF SY-UCOMM.
PARAMETERS : P_BUKRS LIKE T001K-BUKRS.
SELECT-OPTIONS : S_BWKEY FOR T001K-BWKEY NO INTERVALS.
PARAMETERS : RB1 RADIOBUTTON GROUP GRP DEFAULT 'X' USER-COMMAND RB .
SELECTION-SCREEN BEGIN OF BLOCK A3 WITH FRAME TITLE TEXT-006.
SELECTION-SCREEN BEGIN OF BLOCK A1 WITH FRAME TITLE TEXT-001.
SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN COMMENT 1(1) TEXT-002.
PARAMETERS : RB1_1 RADIOBUTTON GROUP RGP2 DEFAULT 'X' USER-COMMAND R.
SELECTION-SCREEN COMMENT 3(10) TEXT-003 FOR FIELD RB1_1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(30) COMM1 MODIF ID MG1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 4(20) TEXT-002 FOR FIELD P_YEAR.
PARAMETERS : P_YEAR LIKE /TDK/CT000201-GJAHR.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 4(20) TEXT-011 for FIELD P_MONTH.
PARAMETERS : P_MONTH TYPE /TDK/CT000201-MONAT.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS : RB1_2 RADIOBUTTON GROUP RGP2.
SELECTION-SCREEN COMMENT 3(30) TEXT-005 FOR FIELD RB1_2.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 4(17) TEXT-012 FOR FIELD S_MATCO.
SELECT-OPTIONS : S_MATCO FOR KALAMATCON1-MATCONID NO INTERVALS.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK A1.
SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN COMMENT 2(1) TEXT-006.
PARAMETERS : CK1 AS CHECKBOX USER-COMMAND UM.
SELECTION-SCREEN COMMENT 3(30) TEXT-007.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN COMMENT 2(1) TEXT-008.
PARAMETERS : CK2 AS CHECKBOX USER-COMMAND UM.
SELECTION-SCREEN COMMENT 3(30) TEXT-009.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK A3.
PARAMETERS : RB2 RADIOBUTTON GROUP GRP.
SELECTION-SCREEN BEGIN OF BLOCK A2 WITH FRAME TITLE TEXT-010.
PARAMETERS : P_MATCO LIKE KALAMATCON1-MATCONID.
SELECTION-SCREEN END OF BLOCK A2.
AT SELECTION-SCREEN OUTPUT.
PERFORM SCREEN_CONTROLING.
INITIALIZATION.
PERFORM S_MATCO_DATA.
START-OF-SELECTION.
PERFORM SCREEN_CHECK.
* Background running
IF CK2 = C_X.
SY-BATCH = C_X.
ENDIF.
* Update mode
IF RB1 = C_X.
PERFORM GET_PROCESS_DATA.
PERFORM ARRANGE_DATA.
* Create data
IF RB1_1 = C_X.
PERFORM CREATE_DATA.
ENDIF.
* Delete data
IF RB1_2 = C_X.
PERFORM DELETE_DATA.
ENDIF.
* Test run
IF CK1 = C_X.
PERFORM GET_PROCESS_DATA.
PERFORM ARRANGE_DATA.
ENDIF.
ENDIF.
* ALV Output
IF RB2 = C_X.
PERFORM DISPLAY_DATA.
PERFORM OUTPUT_ALV_LIST.
ENDIF.
*&---------------------------------------------------------------------*
*& Form S_MATCO_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
*
*----------------------------------------------------------------------*
FORM S_MATCO_DATA .
OPTLIST-NAME = 'OBJECTKEY1'.
OPTLIST-OPTIONS-EQ = C_X.
OPTLIST-OPTIONS-BT = ''.
APPEND OPTLIST TO RESTRICT-OPT_LIST_TAB.
ASS-KIND = 'S'.
ASS-NAME = 'S_MATCO'.
ASS-SG_MAIN = 'I'.
ASS-SG_ADDY = SPACE.
ASS-OP_MAIN = 'OBJECTKEY1'.
APPEND ASS TO RESTRICT-ASS_TAB.
CLEAR OPTLIST.
CLEAR ASS.
CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
EXPORTING
RESTRICTION = RESTRICT
EXCEPTIONS
TOO_LATE = 1
REPEATED = 2
SELOPT_WITHOUT_OPTIONS = 3
SELOPT_WITHOUT_SIGNS = 4
INVALID_SIGN = 5
EMPTY_OPTION_LIST = 6
INVALID_KIND = 7
REPEATED_KIND_A = 8
OTHERS = 9.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " S_MATCO_DATA
*&---------------------------------------------------------------------*
*& Form SCREEN_CONTROLING
*&---------------------------------------------------------------------*
* CONTROL SCREEN
*----------------------------------------------------------------------*
* --> p1 text
*
*----------------------------------------------------------------------*
FORM SCREEN_CONTROLING .
COMM1 ='Organization Period'.
LOOP AT SCREEN.
IF SCREEN-GROUP1 = 'MG1'.
SCREEN-INTENSIFIED = '0'.
MODIFY SCREEN.
ENDIF.
IF RB1 = C_X.
CASE C_X.
WHEN RB1_1.
IF SCREEN-NAME = 'S_MATCO-LOW'.
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
WHEN RB1_2.
IF SCREEN-NAME = 'P_YEAR'.
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
IF SCREEN-NAME = 'P_MONTH'.
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
ENDCASE.
ELSE.
IF SCREEN-NAME = 'S_MATCO-LOW'.
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
IF SCREEN-NAME = 'P_YEAR'.
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
IF SCREEN-NAME = 'P_MONTH'.
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
IF SCREEN-NAME = 'CK1'.
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
IF SCREEN-NAME = 'CK2'.
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
ENDIF.
* CASE C_X.
* WHEN RB1.
* IF SCREEN-NAME = 'P_MATCO'.
* SCREEN-INPUT = '0'.
* MODIFY SCREEN.
* ENDIF.
* WHEN RB2.
* IF SCREEN-NAME = 'RB1_1'.
* SCREEN-INPUT = '0'.
* MODIFY SCREEN.
* ENDIF.
* IF SCREEN-NAME = 'P_YEAR'.
* SCREEN-INPUT = '0'.
* MODIFY SCREEN.
* ENDIF.
* IF SCREEN-NAME = 'P_MONTH'.
* SCREEN-INPUT = '0'.
* MODIFY SCREEN.
* ENDIF.
* IF SCREEN-NAME = 'RB1_2'.
* SCREEN-INPUT = '0'.
* MODIFY SCREEN.
* ENDIF.
* IF SCREEN-NAME = 'S_MATCO-LOW'.
* SCREEN-INPUT = '0'.
* MODIFY SCREEN.
* ENDIF.
* IF SCREEN-NAME = 'CK1'.
* SCREEN-INPUT = '0'.
* MODIFY SCREEN.
* ENDIF.
* IF SCREEN-NAME = 'CK2'.
* SCREEN-INPUT = '0'.
* MODIFY SCREEN.
* ENDIF.
* ENDCASE.
* CASE C_X.
* WHEN CK1.
* IF SCREEN-NAME = 'CK2'.
* SCREEN-INPUT = '0'.
* MODIFY SCREEN.
* ENDIF.
* WHEN CK2.
* IF SCREEN-NAME = 'CK1'.
* SCREEN-INPUT = '0'.
* MODIFY SCREEN.
* ENDIF.
* ENDCASE.
ENDLOOP.
*Hidde Execution Button
* IF CK2 = C_X.
* APPEND CNS_EXEC TO TD_EXCLUDE.
* CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
* EXPORTING
* P_STATUS = SY-PFKEY
* TABLES
* P_EXCLUDE = TD_EXCLUDE.
* ENDIF.
ENDFORM. " SCREEN_CONTROLING
*&---------------------------------------------------------------------*
*& Form SCREEN_CHECK
*&---------------------------------------------------------------------*
* SCREEN CHECK
*----------------------------------------------------------------------*
* --> p1 text
*
*----------------------------------------------------------------------*
FORM SCREEN_CHECK .
IF P_BUKRS IS INITIAL.
MESSAGE S021(/TDK/P001) WITH TEXT-013 DISPLAY LIKE 'E'.
SET CURSOR FIELD 'P_BUKRS'.
LEAVE LIST-PROCESSING.
ENDIF.
IF RB1_1 IS NOT INITIAL.
IF P_YEAR IS INITIAL.
MESSAGE S021(/TDK/P001) WITH TEXT-002 DISPLAY LIKE 'E'.
SET CURSOR FIELD 'P_YEAR'.
LEAVE LIST-PROCESSING.
ENDIF.
IF P_MONTH IS INITIAL.
MESSAGE S021(/TDK/P001) WITH TEXT-011 DISPLAY LIKE 'E'.
SET CURSOR FIELD 'P_MONTH'.
LEAVE LIST-PROCESSING.
ENDIF.
ELSE.
IF S_MATCO IS INITIAL.
MESSAGE S021(/TDK/P001) WITH TEXT-012 DISPLAY LIKE 'E'.
SET CURSOR FIELD 'S_MATCO'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
SELECT BUKRS BWKEY FROM T001K
INTO CORRESPONDING FIELDS OF TABLE TD_T001K
WHERE BUKRS = P_BUKRS
AND BWKEY IN S_BWKEY.
IF SY-SUBRC <> 0.
MESSAGE S001(/TDK/CB00030) DISPLAY LIKE 'E'.
SET CURSOR FIELD 'P_BUKRS'.
LEAVE LIST-PROCESSING.
ENDIF.
LOOP AT TD_T001K INTO TH_T001K.
SELECT SINGLE KOKRS FROM TKA02 " get contorlling area
INTO LTH_KOKRS
WHERE BUKRS = TH_T001K-BUKRS.
IF SY-SUBRC <> 0.
MESSAGE S002(/TDK/CB00030) DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDLOOP.
CASE C_X.
WHEN RB1.
SELECT MATCONID
ERFNM
CPUDT
INTO CORRESPONDING FIELDS OF TABLE TD_KALAMATCON1
FROM KALAMATCON1
WHERE KALAMATCON1~MATCONID IN S_MATCO.
WHEN RB2.
SELECT MATCONID
ERFNM
CPUDT
INTO CORRESPONDING FIELDS OF TABLE TD_KALAMATCON1
FROM KALAMATCON1
WHERE KALAMATCON1~MATCONID = P_MATCO.
ENDCASE.
IF TD_KALAMATCON1 IS INITIAL.
MESSAGE E003(/TDK/CB00030).
LEAVE LIST-PROCESSING.
ENDIF.
IF P_MONTH > 12.
MESSAGE S567(F5) WITH P_MONTH DISPLAY LIKE 'E'.
SET CURSOR FIELD 'P_MONTH'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " SCREEN_CHECK
*&---------------------------------------------------------------------*
*& Form GET_PROCESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
*
*----------------------------------------------------------------------*
FORM GET_PROCESS_DATA .
LTH_DATUM = SY-DATUM.
LTH_UZEIT = SY-UZEIT.
LTH_NAME = SY-UNAME.
LTH_CPROG = SY-CPROG.
IF RB1 = C_X.
IF RB1_1 = C_X.
LOOP AT TD_T001K INTO TH_T001K.
SELECT MATNR
WERKS
PRCTR
MMSTA
INTO CORRESPONDING FIELDS OF TABLE TD_MARC
FROM MARC
WHERE MARC~WERKS = TH_T001K-BWKEY
AND MARC~LVORM = ''
AND MARC~MMSTA <> '00'.
ENDLOOP.
IF TD_MARC IS INITIAL.
MESSAGE E004(/TDK/CB00030).
ENDIF.
LTH_MONTH = P_MONTH.
LTH_YEAR = P_YEAR.
CALL FUNCTION 'BAPI_COAREA_GETPERIODLIMITS'
EXPORTING
CONTROLLINGAREAID = LTH_KOKRS
FISCAL_PERIOD = LTH_MONTH
FISCAL_YEAR = LTH_YEAR
IMPORTING
FIRST_DAY_OF_PERIOD = LTH_FIRST_DAY
LAST_DAY_OF_PERIOD = LTH_LAST_DAY.
IF LTH_FIRST_DAY = '' AND LTH_LAST_DAY = ''.
MESSAGE E005(/TDK/CB00030).
ENDIF.
REFRESH: LTD_MATNR,
TD_MAT_HIER.
CLEAR: TH_MAT_HIER,
LST_MATNR.
LOOP AT TD_MARC INTO TH_MARC.
LST_MATNR-MATNR = TH_MARC-MATNR.
APPEND LST_MATNR TO LTD_MATNR.
ENDLOOP.
CLEAR LST_MATNR.
SORT LTD_MATNR BY MATNR ASCENDING.
DELETE ADJACENT DUPLICATES FROM LTD_MATNR COMPARING MATNR.
IF LTD_MATNR IS NOT INITIAL.
LOOP AT TD_T001K INTO TH_T001K.
CALL FUNCTION '/TDK/C_MAT_ORG'
EXPORTING
I_PATTERN = '1'
I_BUKRS = TH_T001K-BUKRS
IT_MATNR = LTD_MATNR
I_DATE = LTH_LAST_DAY
I_SETNAME = '0000T_T'
IMPORTING
ET_MAT_HIER = TD_MAT_HIER
EXCEPTIONS
INVALID_MATERIAL = 1
INVALID_ITEM_GROUP = 2
INVALID_SETNAME = 3
INVALID_BU = 4
INVALID_SEGMENT = 5
INVALID_PARAMETER = 6
INVALID_COMPANY = 7
OTHERS = 8.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDLOOP.
ENDIF.
IF TD_MAT_HIER IS INITIAL.
MESSAGE E006(/TDK/CB00030).
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " GET_PROCESS_DATA
*&---------------------------------------------------------------------*
*& Form ARRANGE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
*
*----------------------------------------------------------------------*
FORM ARRANGE_DATA .
LOOP AT TD_MAT_HIER INTO TH_MAT_HIER.
TH_ARRANGE_DATA-MATNR = TH_MAT_HIER-MATNR.
TH_ARRANGE_DATA-BU = TH_MAT_HIER-ORG_LV3.
TH_ARRANGE_DATA-CBU = TH_MAT_HIER-ORG_LV4.
TH_ARRANGE_DATA-SBU = TH_MAT_HIER-SEGMENT.
TH_ARRANGE_DATA-TDKGROUP = TH_MAT_HIER-/EPCOS/TDKKL.
TH_ARRANGE_DATA-DATUM = SY-DATUM.
TH_ARRANGE_DATA-UZEIT = SY-UZEIT.
TH_ARRANGE_DATA-NAME = SY-UNAME.
TH_ARRANGE_DATA-CPROG = SY-CPROG.
APPEND TH_ARRANGE_DATA TO TD_ARRANGE_DATA.
CLEAR : TH_MAT_HIER,TH_ARRANGE_DATA.
ENDLOOP.
LOOP AT TD_ARRANGE_DATA INTO TH_ARRANGE_DATA.
READ TABLE TD_MARC INTO TH_MARC WITH KEY MATNR = TH_ARRANGE_DATA-MATNR.
IF SY-SUBRC = 0.
TH_ARRANGE_DATA-MATNR = TH_MARC-MATNR.
TH_ARRANGE_DATA-WERKS = TH_MARC-WERKS.
TH_ARRANGE_DATA-PRCTR = TH_MARC-PRCTR.
MODIFY TD_ARRANGE_DATA FROM TH_ARRANGE_DATA TRANSPORTING WERKS PRCTR WHERE MATNR = TH_MARC-MATNR.
CLEAR TH_ARRANGE_DATA.
ENDIF.
ENDLOOP.
SORT TD_ARRANGE_DATA BY BU CBU SBU PRCTR TDKGROUP.
DATA :
LTH_BUKRS LIKE T001K-BUKRS,
LTH_MATCONID LIKE KALAMATCON1-MATCONID,
LTH_DATE(4) TYPE C,
LTH_CLASS(1) TYPE C,
LTH_DATUM(4) TYPE C.
CLEAR : LTH_BUKRS,LTH_MATCONID,LTH_DATE,LTH_CLASS.
LOOP AT TD_ARRANGE_DATA INTO TH_ARRANGE_DATA.
IF TH_ARRANGE_DATA-BU IS NOT INITIAL.
LTH_CLASS = 'B'.
LTH_BUKRS = P_BUKRS.
LTH_DATE = P_YEAR.
CONCATENATE LTH_CLASS LTH_BUKRS FIELD LTH_DATE TH_ARRANGE_DATA-BU INTO LTH_MATCONID.
TH_EXPORT_DATA-MATCONID = LTH_MATCONID.
TH_EXPORT_DATA-MATNR = TH_ARRANGE_DATA-MATNR.
TH_EXPORT_DATA-BWKEY = TH_ARRANGE_DATA-WERKS.
TH_EXPORT_DATA-BU = TH_ARRANGE_DATA-BU.
TH_EXPORT_DATA-CBU = TH_ARRANGE_DATA-CBU.
TH_EXPORT_DATA-SBU = TH_ARRANGE_DATA-SBU.
TH_EXPORT_DATA-PRCTR = TH_ARRANGE_DATA-PRCTR.
TH_EXPORT_DATA-TDKGROUP = TH_ARRANGE_DATA-TDKGROUP.
TH_EXPORT_DATA-DATUM = TH_ARRANGE_DATA-DATUM.
TH_EXPORT_DATA-UZEIT = TH_ARRANGE_DATA-UZEIT.
TH_EXPORT_DATA-UNAME = TH_ARRANGE_DATA-NAME.
TH_EXPORT_DATA-CPROG = TH_ARRANGE_DATA-CPROG.
APPEND TH_EXPORT_DATA TO TD_EXPORT_DATA.
ENDIF.
CLEAR : LTH_BUKRS,LTH_MATCONID,LTH_DATE,LTH_CLASS.
CLEAR : TH_EXPORT_DATA.
IF TH_ARRANGE_DATA-CBU IS NOT INITIAL.
LTH_CLASS = 'C'.
LTH_BUKRS = P_BUKRS.
LTH_DATE = P_YEAR.
CONCATENATE LTH_CLASS LTH_BUKRS FIELD LTH_DATE TH_ARRANGE_DATA-CBU INTO LTH_MATCONID.
TH_EXPORT_DATA-MATCONID = LTH_MATCONID.
TH_EXPORT_DATA-MATNR = TH_ARRANGE_DATA-MATNR.
TH_EXPORT_DATA-BWKEY = TH_ARRANGE_DATA-WERKS.
TH_EXPORT_DATA-BU = TH_ARRANGE_DATA-BU.
TH_EXPORT_DATA-CBU = TH_ARRANGE_DATA-CBU.
TH_EXPORT_DATA-SBU = TH_ARRANGE_DATA-SBU.
TH_EXPORT_DATA-PRCTR = TH_ARRANGE_DATA-PRCTR.
TH_EXPORT_DATA-TDKGROUP = TH_ARRANGE_DATA-TDKGROUP.
TH_EXPORT_DATA-DATUM = TH_ARRANGE_DATA-DATUM.
TH_EXPORT_DATA-UZEIT = TH_ARRANGE_DATA-UZEIT.
TH_EXPORT_DATA-UNAME = TH_ARRANGE_DATA-NAME.
TH_EXPORT_DATA-CPROG = TH_ARRANGE_DATA-CPROG.
APPEND TH_EXPORT_DATA TO TD_EXPORT_DATA.
ENDIF.
CLEAR : LTH_BUKRS,LTH_MATCONID,LTH_DATE,LTH_CLASS.
CLEAR : TH_EXPORT_DATA.
IF TH_ARRANGE_DATA-SBU IS NOT INITIAL.
LTH_CLASS = 'S'.
LTH_BUKRS = P_BUKRS.
LTH_DATE = P_YEAR.
CONCATENATE LTH_CLASS LTH_BUKRS FIELD LTH_DATE TH_ARRANGE_DATA-SBU INTO LTH_MATCONID.
TH_EXPORT_DATA-MATCONID = LTH_MATCONID.
TH_EXPORT_DATA-MATNR = TH_ARRANGE_DATA-MATNR.
TH_EXPORT_DATA-BWKEY = TH_ARRANGE_DATA-WERKS.
TH_EXPORT_DATA-BU = TH_ARRANGE_DATA-BU.
TH_EXPORT_DATA-CBU = TH_ARRANGE_DATA-CBU.
TH_EXPORT_DATA-SBU = TH_ARRANGE_DATA-SBU.
TH_EXPORT_DATA-PRCTR = TH_ARRANGE_DATA-PRCTR.
TH_EXPORT_DATA-TDKGROUP = TH_ARRANGE_DATA-TDKGROUP.
TH_EXPORT_DATA-DATUM = TH_ARRANGE_DATA-DATUM.
TH_EXPORT_DATA-UZEIT = TH_ARRANGE_DATA-UZEIT.
TH_EXPORT_DATA-UNAME = TH_ARRANGE_DATA-NAME.
TH_EXPORT_DATA-CPROG = TH_ARRANGE_DATA-CPROG.
APPEND TH_EXPORT_DATA TO TD_EXPORT_DATA.
ENDIF.
CLEAR : LTH_BUKRS,LTH_MATCONID,LTH_DATE,LTH_CLASS.
CLEAR : TH_EXPORT_DATA.
IF TH_ARRANGE_DATA-PRCTR IS NOT INITIAL.
LTH_CLASS = 'P'.
LTH_BUKRS = P_BUKRS.
LTH_DATE = P_YEAR.
CONCATENATE LTH_CLASS LTH_BUKRS FIELD LTH_DATE TH_ARRANGE_DATA-PRCTR INTO LTH_MATCONID.
TH_EXPORT_DATA-MATCONID = LTH_MATCONID.
TH_EXPORT_DATA-MATNR = TH_ARRANGE_DATA-MATNR.
TH_EXPORT_DATA-BWKEY = TH_ARRANGE_DATA-WERKS.
TH_EXPORT_DATA-BU = TH_ARRANGE_DATA-BU.
TH_EXPORT_DATA-CBU = TH_ARRANGE_DATA-CBU.
TH_EXPORT_DATA-SBU = TH_ARRANGE_DATA-SBU.
TH_EXPORT_DATA-PRCTR = TH_ARRANGE_DATA-PRCTR.
TH_EXPORT_DATA-TDKGROUP = TH_ARRANGE_DATA-TDKGROUP.
TH_EXPORT_DATA-DATUM = TH_ARRANGE_DATA-DATUM.
TH_EXPORT_DATA-UZEIT = TH_ARRANGE_DATA-UZEIT.
TH_EXPORT_DATA-UNAME = TH_ARRANGE_DATA-NAME.
TH_EXPORT_DATA-CPROG = TH_ARRANGE_DATA-CPROG.
APPEND TH_EXPORT_DATA TO TD_EXPORT_DATA.
ENDIF.
CLEAR : LTH_BUKRS,LTH_MATCONID,LTH_DATE,LTH_CLASS.
CLEAR : TH_EXPORT_DATA.
IF TH_ARRANGE_DATA-TDKGROUP IS NOT INITIAL.
LTH_CLASS = 'I'.
LTH_BUKRS = P_BUKRS.
LTH_DATE = P_YEAR.
CONCATENATE LTH_CLASS LTH_BUKRS FIELD LTH_DATE TH_ARRANGE_DATA-TDKGROUP INTO LTH_MATCONID.
TH_EXPORT_DATA-MATCONID = LTH_MATCONID.
TH_EXPORT_DATA-MATNR = TH_ARRANGE_DATA-MATNR.
TH_EXPORT_DATA-BWKEY = TH_ARRANGE_DATA-WERKS.
TH_EXPORT_DATA-BU = TH_ARRANGE_DATA-BU.
TH_EXPORT_DATA-CBU = TH_ARRANGE_DATA-CBU.
TH_EXPORT_DATA-SBU = TH_ARRANGE_DATA-SBU.
TH_EXPORT_DATA-PRCTR = TH_ARRANGE_DATA-PRCTR.
TH_EXPORT_DATA-TDKGROUP = TH_ARRANGE_DATA-TDKGROUP.
TH_EXPORT_DATA-DATUM = TH_ARRANGE_DATA-DATUM.
TH_EXPORT_DATA-UZEIT = TH_ARRANGE_DATA-UZEIT.
TH_EXPORT_DATA-UNAME = TH_ARRANGE_DATA-NAME.
TH_EXPORT_DATA-CPROG = TH_ARRANGE_DATA-CPROG.
APPEND TH_EXPORT_DATA TO TD_EXPORT_DATA.
ENDIF.
CLEAR : LTH_BUKRS,LTH_MATCONID,LTH_DATE,LTH_CLASS.
CLEAR : TH_EXPORT_DATA.
ENDLOOP.
ENDFORM. " ARRANGE_DATA
*&---------------------------------------------------------------------*
*& Form CREATE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
*
*----------------------------------------------------------------------*
FORM CREATE_DATA .
IF CK1 = ''.
IF RB1_1 = C_X.
LOOP AT TD_EXPORT_DATA INTO TH_EXPORT_DATA.
SELECT SINGLE * FROM /TDK/CT000501
WHERE MATCONID = TH_EXPORT_DATA-MATCONID
AND MATNR = TH_EXPORT_DATA-MATNR
AND BWKEY = TH_EXPORT_DATA-BWKEY.
IF SY-SUBRC = 0.
DELETE FROM /TDK/CT000501 WHERE MATCONID = TH_EXPORT_DATA-MATCONID
AND MATNR = TH_EXPORT_DATA-MATNR
AND BWKEY = TH_EXPORT_DATA-BWKEY.
IF SY-SUBRC = 0.
COMMIT WORK AND WAIT.
ELSE.
ROLLBACK WORK.
ENDIF.
ENDIF.
MOVE-CORRESPONDING TH_EXPORT_DATA TO /TDK/CT000501.
INSERT /TDK/CT000501.
IF SY-SUBRC = 0.
COMMIT WORK AND WAIT.
ELSE.
ROLLBACK WORK.
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
* IF RB1 = C_X.
* IF RB1_1 = C_X.
* LOOP AT TD_EXPORT_DATA INTO TH_EXPORT_DATA.
* SELECT MATCONID
* ERFNM
* CPUDT
* APPENDING CORRESPONDING FIELDS OF TABLE TD_KALAMATCON1_ALL
* FROM KALAMATCON1
* WHERE KALAMATCON1~MATCONID = TH_EXPORT_DATA-MATCONID.
*
* ENDLOOP.
* IF TD_KALAMATCON1_ALL IS INITIAL.
* MESSAGE E009(/TDK/CB00030).
* ENDIF.
* ENDIF.
* ENDIF.
LOOP AT TD_EXPORT_DATA INTO TH_EXPORT_DATA.
TH_MATCON-MATCONID = TH_EXPORT_DATA-MATCONID.
TH_MATCON-MATNR = TH_EXPORT_DATA-MATNR.
TH_MATCON-WERKS = TH_EXPORT_DATA-BWKEY.
APPEND TH_MATCON TO TD_MATCON.
ENDLOOP.
IF RB1 = C_X.
IF RB1_1 = C_X.
IF CK1 = ''.
LOOP AT TD_MATCON INTO TH_MATCON.
MATCONID = TH_MATCON-MATCONID.
MATCONTXT = TH_MATCON-MATCONID.
MOVE-CORRESPONDING TH_MATCON TO TH_MATCON_ALL.
APPEND TH_MATCON_ALL TO TD_MATCON_ALL.
CALL FUNCTION 'CKU5_KALAMATCON_UPDATE'
EXPORTING
MATCONID = MATCONID
MATCONTXT = MATCONTXT
TABLES
T_MATCON = TD_MATCON_ALL
EXCEPTIONS
INVALID_CALL = 1
MATCONTXT_NOT_SET = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CLEAR : MATCONID,MATCONTXT,TH_MATCON_ALL,TH_MATCON.
REFRESH TD_MATCON_ALL.
ENDLOOP.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " CREATE_DATA
*&---------------------------------------------------------------------*
*& Form DELETE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
*
*----------------------------------------------------------------------*
FORM DELETE_DATA .
IF RB1 = C_X.
IF RB1_2 = C_X.
LOOP AT S_MATCO.
CALL FUNCTION 'CKU5_KALAMATCON_DELETE'
EXPORTING
MATCONID = S_MATCO-LOW.
IF SY-SUBRC = 0.
COMMIT WORK AND WAIT.
ELSE.
MESSAGE E011(/TDK/CB00030).
ENDIF.
DELETE FROM /TDK/CT000501 WHERE MATCONID = S_MATCO-LOW.
IF SY-SUBRC <> 0.
MESSAGE E012(/TDK/CB00030).
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
ENDFORM. " DELETE_DATA
*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
*
*----------------------------------------------------------------------*
FORM DISPLAY_DATA .
IF RB2 = C_X.
LOOP AT TD_T001K INTO TH_T001K.
SELECT * FROM /TDK/CT000501
INTO CORRESPONDING FIELDS OF TABLE TD_/TDK/CT000501
WHERE MATCONID = P_MATCO
AND BWKEY = TH_T001K-BWKEY.
ENDLOOP.
IF TD_/TDK/CT000501 IS INITIAL.
MESSAGE E007(/TDK/CB00030).
ENDIF.
ENDIF.
TH_FIELDCAT-SELTEXT_L = 'Selection ID'.
TH_FIELDCAT-FIELDNAME = 'MATCONID'.
APPEND TH_FIELDCAT TO TD_FIELDCAT.
TH_FIELDCAT-SELTEXT_L = 'Material'.
TH_FIELDCAT-FIELDNAME = 'MATNR'.
APPEND TH_FIELDCAT TO TD_FIELDCAT.
TH_FIELDCAT-SELTEXT_L = 'Plant'.
TH_FIELDCAT-FIELDNAME = 'BWKEY'.
APPEND TH_FIELDCAT TO TD_FIELDCAT.
TH_FIELDCAT-SELTEXT_L = 'Business Unit'.
TH_FIELDCAT-FIELDNAME = 'BU'.
APPEND TH_FIELDCAT TO TD_FIELDCAT.
TH_FIELDCAT-SELTEXT_L = 'CBU'.
TH_FIELDCAT-FIELDNAME = 'CBU'.
APPEND TH_FIELDCAT TO TD_FIELDCAT.
TH_FIELDCAT-SELTEXT_L = 'SBU'.
TH_FIELDCAT-FIELDNAME = 'SBU'.
APPEND TH_FIELDCAT TO TD_FIELDCAT.
TH_FIELDCAT-SELTEXT_L = 'Profit Center'.
TH_FIELDCAT-FIELDNAME = 'PRCTR'.
APPEND TH_FIELDCAT TO TD_FIELDCAT.
TH_FIELDCAT-SELTEXT_L = 'TDK Item Group'.
TH_FIELDCAT-FIELDNAME = 'TDKGROUP'.
APPEND TH_FIELDCAT TO TD_FIELDCAT.
TH_FIELDCAT-SELTEXT_L = 'User ID'.
TH_FIELDCAT-FIELDNAME = 'UNAME'.
APPEND TH_FIELDCAT TO TD_FIELDCAT.
TH_LAYOUT-COLWIDTH_OPTIMIZE = C_X.
TH_LAYOUT-ZEBRA = C_X.
ENDFORM. " DISPLAY_DATA
*&---------------------------------------------------------------------*
*& Form OUTPUT_ALV_LIST
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
*
*----------------------------------------------------------------------*
FORM OUTPUT_ALV_LIST .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_HTML_TOP_OF_PAGE = 'HTML_TOP_OF_PAGE'
IS_LAYOUT = TH_LAYOUT
IT_FIELDCAT = TD_FIELDCAT[]
I_DEFAULT = C_X
I_SAVE = 'A'
TABLES
T_OUTTAB = TD_/TDK/CT000501
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM. " OUTPUT_ALV_LIST
*&---------------------------------------------------------------------*
*& Form HTML_TOP_OF_PAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->DOCUMENT text
*----------------------------------------------------------------------*
FORM HTML_TOP_OF_PAGE USING DOCUMENT TYPE REF TO CL_DD_DOCUMENT.
DATA: LW_TEXT TYPE SDYDO_TEXT_ELEMENT.
CLEAR LW_TEXT.
LW_TEXT = 'Company Code: '.
CALL METHOD DOCUMENT->ADD_TEXT
EXPORTING
TEXT = LW_TEXT.
CALL METHOD DOCUMENT->ADD_GAP
EXPORTING
WIDTH = 1.
CLEAR LW_TEXT.
LW_TEXT = P_BUKRS.
CALL METHOD DOCUMENT->ADD_TEXT
EXPORTING
TEXT = LW_TEXT.
CALL METHOD DOCUMENT->ADD_GAP
EXPORTING
WIDTH = 68.
CLEAR LW_TEXT.
LW_TEXT = TEXT-010.
CALL METHOD DOCUMENT->ADD_TEXT
EXPORTING
TEXT = LW_TEXT.
CALL METHOD DOCUMENT->ADD_GAP
EXPORTING
WIDTH = 68.
LW_TEXT = 'User: '.
CALL METHOD DOCUMENT->ADD_TEXT
EXPORTING
TEXT = LW_TEXT.
CALL METHOD DOCUMENT->ADD_GAP
EXPORTING
WIDTH = 1.
LW_TEXT = SY-UNAME.
CALL METHOD DOCUMENT->ADD_TEXT
EXPORTING
TEXT = LW_TEXT.
CALL METHOD DOCUMENT->ADD_GAP
EXPORTING
WIDTH = 1.
CALL METHOD DOCUMENT->NEW_LINE.
LW_TEXT = 'Selection List : '.
CALL METHOD DOCUMENT->ADD_TEXT
EXPORTING
TEXT = LW_TEXT.
CALL METHOD DOCUMENT->ADD_GAP
EXPORTING
WIDTH = 1.
CLEAR LW_TEXT.
LW_TEXT = P_MATCO.
CALL METHOD DOCUMENT->ADD_TEXT
EXPORTING
TEXT = LW_TEXT.
CALL METHOD DOCUMENT->ADD_GAP
EXPORTING
WIDTH = 162.
LW_TEXT = 'Date: '.
CALL METHOD DOCUMENT->ADD_TEXT
EXPORTING
TEXT = LW_TEXT.
CALL METHOD DOCUMENT->ADD_GAP
EXPORTING
WIDTH = 1.
LW_TEXT+0(4) = SY-DATUM+0(4).
LW_TEXT+4(1) = '/'.
LW_TEXT+5(2) = SY-DATUM+4(2).
LW_TEXT+7(1) = '/'.
LW_TEXT+8(2) = SY-DATUM+6(2).
CALL METHOD DOCUMENT->ADD_TEXT
EXPORTING
TEXT = LW_TEXT.
LW_TEXT = SY-UZEIT.
CALL METHOD DOCUMENT->ADD_TEXT
EXPORTING
TEXT = LW_TEXT.
CALL METHOD DOCUMENT->ADD_GAP
EXPORTING
WIDTH = 12.
ENDFORM. "HTML_TOP_OF_PAGE
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/13973563/viewspace-752271/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/13973563/viewspace-752271/