TYPES : BEGIN OF TY_CSKS,
KOKRS LIKE CSKS-KOKRS, " Controlling Area
KOSTL LIKE CSKS-KOSTL, " Cost Center
DATBI LIKE CSKS-DATBI, " To-Date
DATAB LIKE CSKS-DATAB, " From-date
BUKRS LIKE CSKS-BUKRS, " Company code
KOSAR LIKE CSKS-KOSAR, " Headcount Indicator
VERAK LIKE CSKS-VERAK, " Person Responsible
BKZKP LIKE CSKS-BKZKP, " Lock Indocator for Actual
" Primiary Postings
ERSDA LIKE CSKS-ERSDA, " Date Created
BUTXT LIKE T001-BUTXT, " Company name
SKUID LIKE ZXMW_XREF_GNRIC-SKUID," Old cost center
KTEXT LIKE CSKT-KTEXT, " Short Name
LTEXT LIKE CSKT-LTEXT, " Long Name
TGVAL LIKE ZXMW_XREF_GNRIC-TGVAL,
END OF TY_CSKS.
************************************************************************
* CONSTANTS
************************************************************************
DATA : C_SELECTED TYPE C VALUE 'X', "Field for constant value 'X'
W_MESSAGE TYPE c, "ERROR MESSAGE
C_SRCID LIKE ZXMW_XREF_GNRIC-SRCID VALUE '3329',
C_ENTID LIKE ZXMW_XREF_GNRIC-ENTID VALUE '0062',
"MW Master Data Entity ID
C_DVERS LIKE ZXMW_XREF_GNRIC-DVERS VALUE '01',
" Definition Version for MW
" Mapping App
*Internal table for getting the Cost centers
DATA : IT_CSKS TYPE TY_CSKS OCCURS 0 WITH HEADER LINE.
DATA: IT_COSTCENTERS LIKE BAPI0012_CCLIST OCCURS 100 WITH HEADER LINE,
IT_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE,
IT_COSTCENTERDETAIL LIKE BAPI0012_CCOUTPUTLIST OCCURS 0 WITH
HEADER LINE.
*Internal table for final data
DATA : BEGIN OF IT_FINAL_DATA OCCURS 0,
TEXT(170) TYPE C,
END OF IT_FINAL_DATA.
*Internal table for old cost centers .
DATA :IT_ZXMW_XREF_GNRIC LIKE ZXMW_XREF_GNRIC OCCURS 0 WITH HEADER LINE.
*Internal table for costcenter Text.
DATA :BEGIN OF IT_CSKT OCCURS 0,
KOSTL LIKE CSKT-KOSTL,
DATBI LIKE CSKT-DATBI,
KTEXT LIKE CSKT-KTEXT,
LTEXT LIKE CSKT-LTEXT,
END OF IT_CSKT.
*----------------------------------------------------------------------*
* SELECTION-SCREEN
*----------------------------------------------------------------------*
*--Block for File path.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_KOKRS LIKE CSKS-KOKRS DEFAULT '1000'.
PARAMETERS: P_KOSAR LIKE CSKS-KOSAR DEFAULT 'Y'.
PARAMETERS :R1 RADIOBUTTON GROUP GRP1 DEFAULT 'X'.
PARAMETERS: P_UNIX LIKE RLGRAP-FILENAME DEFAULT
'/tmp/ZFO_SAPTOHR_COSTCENTERS.TXT'.
PARAMETERS :R2 RADIOBUTTON GROUP GRP1.
PARAMETERS: P_FILE LIKE RLGRAP-FILENAME DEFAULT 'C:\'.
SELECTION-SCREEN END OF BLOCK B1.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN ON
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON BLOCK B1.
* Form to Validate data specified on Selection Screen
CHECK SSCRFIELDS-UCOMM EQ 'ONLI'.
PERFORM SELECTIONSCREEN_VALIDATIONS.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
* Form to get file path to download the data
PERFORM GET_FILE_PATH USING P_FILE.
IF SY-SUBRC <> 0.
MESSAGE E002 WITH 'NO COST CENTERS FOUND'(002).
ENDIF.
ENDFORM. " GETCOSTCENTERS
*&---------------------------------------------------------------------*
*& Form GETCOSTDETAILS
*&---------------------------------------------------------------------*
* Get the Costcenter Details
*----------------------------------------------------------------------*
FORM GETCOSTDETAILS .
IF NOT IT_COSTCENTERS[] IS INITIAL.
SELECT KOKRS
KOSTL
DATBI
DATAB
BUKRS
KOSAR
VERAK
BKZKP
ERSDA
FROM CSKS
INTO TABLE IT_CSKS
FOR ALL ENTRIES IN IT_COSTCENTERS
WHERE KOKRS = IT_COSTCENTERS-CO_AREA AND
KOSAR = P_KOSAR AND
BKZKP = SPACE.
ENDIF.
IF NOT IT_CSKS[] IS INITIAL.
SELECT KOSTL
DATBI
KTEXT
LTEXT
FROM CSKT
INTO TABLE IT_CSKT
FOR ALL ENTRIES IN IT_CSKS
WHERE SPRAS = SY-LANGU AND
KOKRS = IT_CSKS-KOKRS AND
KOSTL = IT_CSKS-KOSTL AND
DATBI = IT_CSKS-DATBI.
CONCATENATE IT_CSKS-KOKRS W_KOSTL IT_CSKS-DATBI INTO W_SKEY.
SELECT SINGLE TGVAL
FROM ZXMW_XREF_GNRIC
INTO IT_CSKS-TGVAL
WHERE SRCID = C_SRCID AND
ENTID = C_ENTID AND
DVERS = C_DVERS AND
EFFDT <= SY-DATUM AND
EXPDT GT SY-DATUM AND
SKVAL = W_SKEY AND
STATUS <> 'U' .
*
**&---------------------------------------------------------------------
*
**& Form DOWNLOAD_UNIXFILE
**&---------------------------------------------------------------------
*
** Placing file in Application server
**----------------------------------------------------------------------
FORM DOWNLOAD_UNIXFILE .
OPEN DATASET P_UNIX FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC NE 0.
MESSAGE E001(0) WITH 'Unable to open file'.
ENDIF.
DO.
READ TABLE IT_FINAL_DATA INDEX SY-INDEX.
IF SY-SUBRC EQ 0.
TRANSFER IT_FINAL_DATA TO P_UNIX.
ELSE.
MESSAGE S001 WITH 'File' P_UNIX 'Successfully Downloaded'.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET P_UNIX.
ENDFORM. "DOWNLOAD_UNIXFILE
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_LOCALFILE
*&---------------------------------------------------------------------*
* Placing file in Presentation server
*----------------------------------------------------------------------*
FORM DOWNLOAD_LOCALFILE .
ENDFORM. " DOWNLOAD_LOCALFILE
*&---------------------------------------------------------------------*
*& Form GET_FILE_PATH
*&---------------------------------------------------------------------*
* F4 HELP to get the File Path
*----------------------------------------------------------------------*
FORM GET_FILE_PATH USING P_P_FILE.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
FILE_NAME = P_P_FILE.
ENDFORM. " GET_FILE_PATH
*&---------------------------------------------------------------------*
*& Form GET_LEGACY_COSTCENTERS
*&---------------------------------------------------------------------*
* Legacy system Cost centers
*----------------------------------------------------------------------*
*FORM GET_LEGACY_COSTCENTERS .
*
* LOOP AT IT_CSKS.
*
* CONCATENATE IT_CSKS-KOKRS IT_CSKS-KOSTL IT_CSKS-DATBI INTO W_SKEY.
*
* SELECT SINGLE TGVAL
* FROM ZXMW_XREF_GNRIC
* INTO IT_CSKS-TGVAL
* WHERE SRCID = C_SRCID AND
* ENTID = C_ENTID AND
* DVERS = C_DVERS AND
* EFFDT <= SY-DATUM AND
* EXPDT GT SY-DATUM AND
* TGVAL = IT_CSKS-KOSTL AND
* STATUS <> 'U' .
*
* IF SY-SUBRC = 0.
* MODIFY IT_CSKS.
* ENDIF.
*
* CONCATENATE IT_CSKS-BUKRS IT_CSKS-BUTXT IT_CSKS-KOSTL IT_CSKS-SKUID
* IT_CSKS-KTEXT IT_CSKS-LTEXT IT_CSKS-BKZKP IT_CSKS-KOSAR
* IT_CSKS-VERAK IT_CSKS-ERSDA IT_CSKS-DATBI IT_CSKS-DATAB
* INTO IT_FINAL_DATA SEPARATED BY '~'.
*
* CONCATENATE IT_FINAL_DATA '~' INTO IT_FINAL_DATA .
* APPEND IT_FINAL_DATA.
* CLEAR : IT_FINAL_DATA,
* IT_CSKS.
* ENDLOOP.
*
*ENDFORM. " GET_LEGACY_COSTCENTERS
*&---------------------------------------------------------------------*
*& Form SELECTIONSCREEN_VALIDATIONS
*&---------------------------------------------------------------------*
* Form used for selection screen validations
*----------------------------------------------------------------------*
FORM SELECTIONSCREEN_VALIDATIONS .
DATA : L_LEN TYPE I,
L_LEN1 TYPE I.
*If Presentation Server file path is not entered throw a Error message
IF P_FILE IS INITIAL AND R2 = C_SELECTED.
CLEAR SSCRFIELDS-UCOMM.
MESSAGE E001(ZZ) WITH TEXT-012.
ENDIF.
*If Application Server file path is not entered throw a Error message
IF P_UNIX IS INITIAL AND R1 = C_SELECTED.
CLEAR SSCRFIELDS-UCOMM.
MESSAGE E001(ZZ) WITH TEXT-021.
ENDIF.
* In Presentation server path,If second character is not ':' throw a
* Error message
IF R2 = C_SELECTED.
IF P_FILE+1(1) NE ':'.
MESSAGE E001(ZZ) WITH TEXT-003.
ENDIF.
ENDIF.
* In Presentation server path,If the file path starts with '/' or '\'
* throw a Error message
IF R2 = C_SELECTED.
IF P_FILE+0(1) EQ '\' OR P_FILE+0(1) EQ '/'.
MESSAGE E001(ZZ) WITH TEXT-003.
ENDIF.
ENDIF.
* Checking whether the Application Server Path is valid or not
IF R1 = 'X'.
CLEAR W_Message.
OPEN DATASET P_UNIX FOR INPUT IN TEXT MODE
MESSAGE W_Message ENCODING DEFAULT.
IF SY-SUBRC <> 0.
MESSAGE E001(ZZ) WITH P_UNIX W_Message.
STOP.
ELSE.
CLOSE DATASET P_UNIX.
ENDIF.
ENDIF.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.