REPORT Z_MM_BDC_GOODS_RECEIPTS NO STANDARD PAGE HEADING
MESSAGE-ID Z_MSGCLASS " Message class
LINE-COUNT 65(4) " Width of Report display
LINE-SIZE 255. " No.of lines in page
************************************************************************
* 1. Read input file *
* 2. Check the mandatory fields and if any one of them is missing *
* move the record to error file. *
* 3. Fill the bdcdata and call MB1C transaction *
* 4. If any errors format the message and send it for reporting *
* 5. If any errors, it downloads the error file *
* 6. Based on user input, this programs does the follwoing *
* a).Call transaction and in case of errors add to a session *
* B).Create session *
* 7. Display the Audit report *
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Request No. Created Date Developer name *
*----------------------------------------------------------------------*
* D00001 18/05/2006
*----------------------------------------------------------------------*
* TABLES *
*----------------------------------------------------------------------*
TABLES :MSEG. " Document Segment: Material
*----------------------------------------------------------------------*
* FLAGS *
*----------------------------------------------------------------------*
DATA: F_STOP, " Flag used to stop processing
F_COLOR. " For color
*----------------------------------------------------------------------*
* INTERNAL TABLE DECLARATIONS *
*----------------------------------------------------------------------*
*--- Internal table for input file for ascii data load
DATA: BEGIN OF I_INFILE_ASC OCCURS 0,
STRING(1600) TYPE C,
END OF I_INFILE_ASC.
*--- Internal table to store messages from Call Transaction.
DATA : I_BDCMSGCOLL TYPE STANDARD TABLE OF BDCMSGCOLL WITH HEADER LINE,
*--- Internal table for BDC data
IT_BDCTAB TYPE BDCDATA OCCURS 0 WITH HEADER LINE.
*--- Internal to hold the records in the text file
DATA : BEGIN OF IT_DATA OCCURS 0,
BLDAT(10), " Document Date in Document
BUDAT(10), " Posting Date in the Document
BWARTWA(3), " Movement type (inventory management)
WERKS(4), " Plant
LGORT(4), " Storage location
WVERS2(1), " Version 2 GR/GI Slip
MATNR(18), " Material Number
ERFMG(13), " Quantity in unit of entry
EXBWR(13), " Externally entered posting amt in local currency
END OF IT_DATA.
*--- Internal table to hold the error records.
DATA : BEGIN OF IT_ERROR OCCURS 0.
INCLUDE STRUCTURE IT_DATA.
DATA : MESSAGE(69) TYPE C,
END OF IT_ERROR.
*--- Internal table for session names
DATA : BEGIN OF IT_SESSION OCCURS 0,
NAME(12),
END OF IT_SESSION.
*--- Internal table to hold Collecting messages in the SAP System
DATA : IT_MSG LIKE BDCMSGCOLL OCCURS 10 WITH HEADER LINE.
*--- Internal table to hold error records to be downloaded
DATA : BEGIN OF I_FINAL OCCURS 0,
STRING(1600),
END OF I_FINAL.
*--- Internal table for session names
DATA : BEGIN OF I_SESSION OCCURS 0,
NAME(12),
END OF I_SESSION.
*----------------------------------------------------------------------*
* CONSTANTS *
*----------------------------------------------------------------------*
CONSTANTS : C_FILETYPE LIKE RLGRAP-FILETYPE VALUE 'DAT', " Filetype
C_TCODE LIKE TSTC-TCODE VALUE 'MB1C', " Transaction
C_MODE(1) VALUE 'A', " Mode
C_UPDATE(1) VALUE 'S', " Update
C_SESS(12) TYPE C VALUE 'GOODS_SESS'. " Session Name
*----------------------------------------------------------------------*
* DATA DECLARATIONS *
*----------------------------------------------------------------------*
DATA : V_TABIX LIKE SY-TABIX, " Table Index
V_MESG(80), " Message
V_ERROR TYPE I, " No.of Errors
V_SUCCESS TYPE I, " No.of Successes
V_LINES TYPE I, " No.of Records
V_INSERT TYPE I, "
V_COUNTER(2) TYPE N, " No. of Sessions
F_OPENSESSION TYPE C. " Flag for Open Sess
DATA: V_EMPTY TYPE I, " No. of Empty Records
V_TOTAL TYPE I, " Total no. of records with data
V_SESSION TYPE APQI-GROUPID, " Session Name
V_DEL TYPE X VALUE '09'. " To seperate fields in case of Dat
*-----Rows for Table with Excel Data
DATA: IT_INTERN TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
DATA: V_SFILE(255), " File path
V_FILEEXT(3). " File Extension
*----------------------------------------------------------------------*
* SELECTION SCREEN. *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK SCR1 WITH FRAME TITLE TEXT-025.
PARAMETER : P_FILE TYPE RLGRAP-FILENAME OBLIGATORY DEFAULT " Input File
'C:\GOODS_RECEIPTS.TXT',
P_ERR TYPE RLGRAP-FILENAME OBLIGATORY DEFAULT " Error File
'C:\GOODS_RECEIPTS_ERR.TXT'.
PARAMETER: P_FTYPE LIKE RLGRAP-FILETYPE DEFAULT 'DAT'. " File Type
SELECTION-SCREEN END OF BLOCK SCR1.
SELECTION-SCREEN BEGIN OF BLOCK MODE WITH FRAME TITLE TEXT-002.
PARAMETER : P_CT RADIOBUTTON GROUP BDC, " Call Transaction
P_BDC RADIOBUTTON GROUP BDC DEFAULT 'X'." Create BDC sess
PARAMETER : P_SESS1 TYPE APQI-GROUPID OBLIGATORY DEFAULT C_SESS."Sesname
PARAMETER : P_MAX(4) OBLIGATORY DEFAULT '100'. " No.of recs in a session
PARAMETER : P_TEST AS CHECKBOX DEFAULT 'X'. " Test mode
PARAMETERS: P_HEADER TYPE I DEFAULT 0. " Header Lines
PARAMETERS: P_BEGCOL TYPE I DEFAULT 1 NO-DISPLAY, " Start Column
P_BEGROW TYPE I DEFAULT 1 NO-DISPLAY, " Start Row
P_ENDCOL TYPE I DEFAULT 100 NO-DISPLAY, " End Column
P_ENDROW TYPE I DEFAULT 32000 NO-DISPLAY. " End Row
SELECTION-SCREEN END OF BLOCK MODE.
*---------------------------------------------------------------------*
* AT SELECTION-SCREEN *
*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
*--- Validating file
PERFORM VALIDATE_FILE USING P_FILE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_ERR.
*--- Validating file
PERFORM VALIDATE_FILE USING P_ERR.
*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
*--- Perform to store the data to an internal table
PERFORM READ_INPUT_FILE_DATA.
*--- Perform to get values from the text file
* PERFORM FILE_VALIDATION.
* Process data in non test mode only
IF P_TEST = SPACE.
IF NOT IT_DATA[] IS INITIAL.
PERFORM PROCESS_DATA.
ELSE.
MESSAGE S003(Z_MSGCLASS).
F_STOP = 'X'.
STOP.
ENDIF.
ENDIF.
*----------------------------------------------------------------------*
* END OF SELECTION. *
*----------------------------------------------------------------------*
END-OF-SELECTION.
IF F_STOP = SPACE.
*--- Perform to display the selection screen of the report
PERFORM DISPLAY_SEL_SCR_REPORT.
*--- Perform to display the session report
PERFORM SESSION_REPORT.
*---- Perform to display the no.of records,success and error records
PERFORM DISPLAY_SUMMARY_REPORT.
*--- Downloading error records.
PERFORM DOWNLOAD_ERROR_FILES.
*---- Perform to display the error records
PERFORM DISPLAY_ERROR_RECORDS.
ENDIF.
*----------------------------------------------------------------------*
* Form : Validate_Input_File
*----------------------------------------------------------------------*
* Description : To provide F4 help for file if read from PC
*----------------------------------------------------------------------*
FORM VALIDATE_FILE USING F_FILE TYPE RLGRAP-FILENAME.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
FILE_NAME = F_FILE
EXCEPTIONS
MASK_TOO_LONG = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE S010(Z_MSGCLASS). " 'Error in getting filename'.
ENDIF.
ENDFORM. " Validate_Input_File
*----------------------------------------------------------------------*
* Form : Read_InputFile
*----------------------------------------------------------------------*
* Description : To upload the data into internal table
*----------------------------------------------------------------------*
FORM READ_INPUTFILE TABLES F_INFILE
USING F_FILE TYPE RLGRAP-FILENAME
F_FILTYP TYPE RLGRAP-FILETYPE.
DATA : LV_DEL TYPE CHAR01,
LV_FILE TYPE STRING.
CLEAR F_INFILE.
REFRESH F_INFILE.
LV_FILE = F_FILE.
IF F_FILTYP = 'DAT'.
LV_DEL = ''.
ENDIF.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = LV_FILE
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = LV_DEL
TABLES
DATA_TAB = F_INFILE
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17 .
IF SY-SUBRC <> 0.
MESSAGE I011(Z_MSGCLASS). " 'Error in uploading the file'.
F_STOP = 'X'.
STOP.
ENDIF.
ENDFORM. "Read_InputFile
*&---------------------------------------------------------------------*
*& Form FORMAT_ASC_DATA
*&---------------------------------------------------------------------*
* To format the ASCII data
*----------------------------------------------------------------------*
FORM FORMAT_ASC_DATA.
LOOP AT I_INFILE_ASC.
IT_DATA-BLDAT = I_INFILE_ASC-STRING+0(10).
IT_DATA-BUDAT = I_INFILE_ASC-STRING+10(10).
IT_DATA-BWARTWA = I_INFILE_ASC-STRING+20(3).
IT_DATA-WERKS = I_INFILE_ASC-STRING+23(4).
IT_DATA-LGORT = I_INFILE_ASC-STRING+27(4).
IT_DATA-WVERS2 = I_INFILE_ASC-STRING+31(1).
IT_DATA-MATNR = I_INFILE_ASC-STRING+32(18).
IT_DATA-ERFMG = I_INFILE_ASC-STRING+50(13).
IT_DATA-EXBWR = I_INFILE_ASC-STRING+63(13).
ENDLOOP.
ENDFORM. " FORMAT_ASC_DATA
*---------------------------------------------------------------------*
* Form FILE_VALIDATION
*---------------------------------------------------------------------*
* To validate data
*---------------------------------------------------------------------*
FORM FILE_VALIDATION.
DATA: LV_TABIX LIKE SY-TABIX,
LV_FLAG(1).
LOOP AT IT_DATA.
CLEAR V_MESG.
* ----- check for the mandatory fields
IF IT_DATA-BLDAT IS INITIAL
OR IT_DATA-BUDAT IS INITIAL
OR IT_DATA-BWARTWA IS INITIAL
OR IT_DATA-WERKS IS INITIAL
OR IT_DATA-WVERS2 IS INITIAL
OR IT_DATA-MATNR IS INITIAL
OR IT_DATA-ERFMG IS INITIAL
OR IT_DATA-EXBWR IS INITIAL.
LV_TABIX = SY-TABIX.
V_MESG = 'Mandatory fields missing'(001).
*----- Perform to store the error record
PERFORM ERROR_PROCESSING.
*----- Deleting the record which is initial
DELETE IT_DATA INDEX LV_TABIX.
ENDIF.
ENDLOOP.
CLEAR V_MESG.
ENDFORM. " FILE_VALIDATION
*&---------------------------------------------------------------------*
*& Form Error_Processing
*&---------------------------------------------------------------------*
* To process the error records
*----------------------------------------------------------------------*
FORM ERROR_PROCESSING.
"F_MESG.
V_ERROR = V_ERROR + 1.
IT_ERROR = IT_DATA.
IT_ERROR-MESSAGE = V_MESG.
APPEND IT_ERROR.
CLEAR IT_ERROR.
ENDFORM. " Error_Processing
*---------------------------------------------------------------------*
* Form : Process_Data *
*---------------------------------------------------------------------*
* --- Populating the BDC Data *
*---------------------------------------------------------------------*
FORM PROCESS_DATA .
LOOP AT IT_DATA.
CLEAR :IT_BDCTAB,
I_BDCMSGCOLL.
REFRESH:IT_BDCTAB,
I_BDCMSGCOLL.
*--- To fill the data from the text file
PERFORM FILL_BDCDATA.
IF P_CT EQ 'X'.
*--- Posts data using call transaction method.
PERFORM CALL_TRANSACTION.
ELSE.
*--- Posts data using session method.
PERFORM CALL_SESSION USING C_TCODE P_MAX P_SESS1.
ENDIF.
ENDLOOP.
IF F_OPENSESSION = 'X'.
PERFORM CLOSE_SESSION.
ENDIF.
ENDFORM. " PROCESS_DATA
*&---------------------------------------------------------------------*
*& Form FILL_BDCDATA
*&---------------------------------------------------------------------*
* To populate the data
*----------------------------------------------------------------------*
FORM FILL_BDCDATA.
*--- Perform to populate the data in screen 0400
PERFORM POPULATE_DATA_SCR_0400.
*--- Perform to populate the data in screen 0421
PERFORM POPULATE_DATA_SCR_0421.
*--- Perform to populate the data in screen 0002
PERFORM POPULATE_DATA_SCR_0002.
*--- Perform to populate the data in screen 0002
PERFORM POPULATE_DATA_SCR_0002.
*--- Perform to populate the data in screen 0421
PERFORM POPULATE_DATA_SCR2_0421.
*--- Perform to populate the data in screen 0002
PERFORM POPULATE_DATA_SCR_0002.
*--- Perform to populate the data in screen 0410
PERFORM POPULATE_0410.
*--- Perform to populate the data in screen 0002
PERFORM POPULATE_DATA_SCR_0002.
ENDFORM. " FILL_BDCDATA
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING F_PROGRAM F_DYNPRO.
CLEAR IT_BDCTAB.
IT_BDCTAB-PROGRAM = F_PROGRAM.
IT_BDCTAB-DYNPRO = F_DYNPRO.
IT_BDCTAB-DYNBEGIN = 'X'.
APPEND IT_BDCTAB.
ENDFORM. "BDC_DYNPRO
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> SPACE.
CLEAR IT_BDCTAB.
IT_BDCTAB-FNAM = FNAM.
IT_BDCTAB-FVAL = FVAL.
APPEND IT_BDCTAB.
ENDIF.
ENDFORM. "BDC_FIELD
*---------------------------------------------------------------------*
* Form : Call_Transaction *
*---------------------------------------------------------------------*
*--- Posts data using call transaction method. *
*---------------------------------------------------------------------*
FORM CALL_TRANSACTION .
CLEAR: V_LINES,
V_MESG.
*----- call transaction method to upload data
CALL TRANSACTION C_TCODE USING IT_BDCTAB
MODE C_MODE
UPDATE C_UPDATE
MESSAGES INTO I_BDCMSGCOLL.
IF SY-SUBRC <> 0.
DESCRIBE TABLE I_BDCMSGCOLL LINES V_LINES.
READ TABLE I_BDCMSGCOLL INDEX V_LINES TRANSPORTING ALL FIELDS.
*--- Formats message returned by Call transaction.
PERFORM FORMAT_MESSAGE.
*--- Perform to process error processing
PERFORM ERROR_PROCESSING." USING IT_DATA V_MESG.
PERFORM CALL_SESSION USING C_TCODE P_MAX P_SESS1.
ELSE. "If call transaction is successful.
V_SUCCESS = V_SUCCESS + 1.
ENDIF.
ENDFORM. " Call_Transaction
*&---------------------------------------------------------------------*
*& Form format_message
*&---------------------------------------------------------------------*
*-------Reading messages
*----------------------------------------------------------------------*
FORM FORMAT_MESSAGE.
CLEAR V_MESG.
*--- Function module to get the message.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = I_BDCMSGCOLL-MSGID
LANG = SY-LANGU
NO = I_BDCMSGCOLL-MSGNR
V1 = I_BDCMSGCOLL-MSGV1
V2 = I_BDCMSGCOLL-MSGV2
V3 = I_BDCMSGCOLL-MSGV3
V4 = I_BDCMSGCOLL-MSGV4
IMPORTING
MSG = V_MESG.
ENDFORM. " Format_Message
*----------------------------------------------------------------------
* Form : Call_Session
*----------------------------------------------------------------------
* Description : To call the session
*----------------------------------------------------------------------
*
FORM CALL_SESSION USING FP_TCODE TYPE ANY
F_MAX TYPE ANY
F_SESS1 TYPE ANY.
* To open the session
PERFORM OPEN_SESSION USING F_MAX F_SESS1.
* Perform Insert BDC Session
PERFORM BDC_INSERT USING FP_TCODE.
* To close the session
IF V_INSERT = F_MAX .
PERFORM CLOSE_SESSION.
ENDIF.
ENDFORM. " Call_Session
*----------------------------------------------------------------------
* Form : Open_Session
*----------------------------------------------------------------------
* Description : Form to open BDC open group.
*----------------------------------------------------------------------
*
FORM OPEN_SESSION USING F_MAX TYPE ANY
F_SESS1 TYPE ANY.
IF V_INSERT = F_MAX OR F_OPENSESSION = SPACE.
V_COUNTER = V_COUNTER + 1.
CLEAR V_SESSION.
CONCATENATE F_SESS1 '_' V_COUNTER INTO V_SESSION.
* Opening the BDC Session
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = V_SESSION
KEEP = 'X'
USER = SY-UNAME
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11.
IF SY-SUBRC <> 0.
MESSAGE I007(Z_MSGCLASS). " 'Error in Opening the Session'.
EXIT.
ELSE.
CLEAR V_INSERT.
F_OPENSESSION = 'X'.
ENDIF.
ENDIF.
ENDFORM. " Open_Session
*----------------------------------------------------------------------
* Form : BDC_Insert
*----------------------------------------------------------------------
* Description : Form to Insert data.
*----------------------------------------------------------------------
FORM BDC_INSERT USING FP_TCODE TYPE ANY.
* Inserting BDC
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = FP_TCODE
TABLES
DYNPROTAB = IT_BDCTAB
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7.
IF SY-SUBRC <> 0.
MESSAGE I008(Z_MSGCLASS). " 'Error in inserting the record'.
ELSE.
V_INSERT = V_INSERT + 1.
ENDIF.
ENDFORM. " BDC_Insert
*----------------------------------------------------------------------
* Form : Close_Session
*----------------------------------------------------------------------
* Description : To close the session
*----------------------------------------------------------------------
FORM CLOSE_SESSION.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE I009(Z_MSGCLASS). " 'Session cannot be closed'.
ELSE.
I_SESSION-NAME = V_SESSION.
APPEND I_SESSION.
CLEAR I_SESSION.
CLEAR F_OPENSESSION.
ENDIF.
ENDFORM. " Close_Session
*---------------------------------------------------------------------*
* Form DOWNLOAD_ERROR_FILES
*---------------------------------------------------------------------*
*--- Downloading the error records to erro file
*----------------------------------------------------------------------*
FORM DOWNLOAD_ERROR_FILES.
DATA : LV_DEL TYPE CHAR01,
LV_FILE TYPE STRING.
IF NOT IT_ERROR[] IS INITIAL.
IF P_FTYPE = 'DAT'.
LOOP AT IT_ERROR.
CONCATENATE IT_ERROR-BLDAT
IT_ERROR-BUDAT
IT_ERROR-BWARTWA
IT_ERROR-WERKS
IT_ERROR-LGORT
IT_ERROR-WVERS2
IT_ERROR-MATNR
IT_ERROR-ERFMG
IT_ERROR-EXBWR
INTO I_FINAL-STRING SEPARATED BY V_DEL.
APPEND I_FINAL.
CLEAR I_FINAL.
ENDLOOP.
CLEAR I_FINAL.
ELSEIF P_FTYPE = 'ASC'.
LOOP AT IT_ERROR.
I_FINAL-STRING+0(10) = IT_ERROR-BLDAT.
I_FINAL-STRING+10(10) = IT_ERROR-BUDAT.
I_FINAL-STRING+20(3) = IT_ERROR-BWARTWA.
I_FINAL-STRING+23(4) = IT_ERROR-WERKS.
I_FINAL-STRING+27(4) = IT_ERROR-LGORT.
I_FINAL-STRING+31(1) = IT_ERROR-WVERS2.
I_FINAL-STRING+32(18) = IT_ERROR-MATNR.
I_FINAL-STRING+50(13) = IT_ERROR-ERFMG.
I_FINAL-STRING+63(13) = IT_ERROR-EXBWR.
APPEND I_FINAL.
CLEAR I_FINAL.
ENDLOOP.
ENDIF. "IF P_FTYPE = 'DAT'.
LV_FILE = P_ERR.
IF P_FTYPE = 'DAT'.
LV_DEL = ''.
ENDIF.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
FILENAME = LV_FILE
FILETYPE = 'ASC'
* APPEND = ' '
WRITE_FIELD_SEPARATOR = LV_DEL
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* IMPORTING
* FILELENGTH =
TABLES
DATA_TAB = I_FINAL
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.
IF SY-SUBRC <> 0.
MESSAGE I012(Z_MSGCLASS). " Error in downloading the file.
ENDIF.
ENDIF. "IF NOT I_FILE_ERROR[] IS INITIAL.
ENDFORM. " DOWNLOAD_ERROR_FILES
*&---------------------------------------------------------------------*
*& Form POPULATE_DATA_SCREEN_0400
*&---------------------------------------------------------------------*
* To populate the data for the screen 0400
*----------------------------------------------------------------------*
FORM POPULATE_DATA_SCR_0400.
PERFORM BDC_DYNPRO USING 'SAPMM07M' '0400'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RM07M-XNUVR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM BDC_FIELD USING 'MKPF-BLDAT' IT_DATA-BLDAT.
PERFORM BDC_FIELD USING 'MKPF-BUDAT' IT_DATA-BUDAT.
PERFORM BDC_FIELD USING 'RM07M-BWARTWA' IT_DATA-BWARTWA.
PERFORM BDC_FIELD USING 'RM07M-WERKS' IT_DATA-WERKS.
PERFORM BDC_FIELD USING 'RM07M-LGORT' IT_DATA-LGORT.
PERFORM BDC_FIELD USING 'RM07M-WVERS2' IT_DATA-WVERS2.
ENDFORM. " POPULATE_DATA_SCR_0400
*&---------------------------------------------------------------------*
*& Form POPULATE_DATA_SCREEN_0421
*&---------------------------------------------------------------------*
* To populate the data for the screen 0421
*----------------------------------------------------------------------*
FORM POPULATE_DATA_SCR_0421.
PERFORM BDC_DYNPRO USING 'SAPMM07M' '0421'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'MSEG-ERFMG(01)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM BDC_FIELD USING 'MSEG-MATNR(01)' IT_DATA-MATNR.
PERFORM BDC_FIELD USING 'MSEG-ERFMG(01)' IT_DATA-ERFMG.
ENDFORM. " POPULATE_DATA_SCR_0421
*&---------------------------------------------------------------------*
*& Form POPULATE_DATA_SCREEN_0002
*&---------------------------------------------------------------------*
* To populate the data for the screen 0002
*----------------------------------------------------------------------*
FORM POPULATE_DATA_SCR_0002.
PERFORM BDC_DYNPRO USING 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=ENTE'.
ENDFORM. " POPULATE_DATA_SCR_0002
*&---------------------------------------------------------------------*
*& Form POPULATE_DATA_SCREEN2_0421
*&---------------------------------------------------------------------*
* To populate the data for the screen 0421
*----------------------------------------------------------------------*
FORM POPULATE_DATA_SCR2_0421.
PERFORM BDC_DYNPRO USING 'SAPMM07M' '0421'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'MSEG-MATNR(01)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=PF02'.
ENDFORM. " POPULATE_DATA_SCR2_0421
*&---------------------------------------------------------------------*
*& Form POPPULATE_0410
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM POPULATE_0410 .
PERFORM BDC_DYNPRO USING 'SAPMM07M' '0410'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'MSEG-EXBWR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=BU'.
PERFORM BDC_FIELD USING 'MSEG-EXBWR' IT_DATA-EXBWR.
ENDFORM. " POPPULATE_0410
*&---------------------------------------------------------------------*
*& Form READ_INPUT_FILE_DATA
*&---------------------------------------------------------------------*
* To Read the input file data
*----------------------------------------------------------------------*
FORM READ_INPUT_FILE_DATA.
*--- Splitting the filename and its extension
PERFORM SPLIT_FILENAME_EXT.
CASE V_FILEEXT.
WHEN 'XLS'.
*--- Perform to convert the Excel data into an internal table
PERFORM CONVERT_XLS_ITAB.
WHEN 'TXT'.
IF P_FTYPE = 'ASC'.
*--- Uploading the data from server
PERFORM READ_INPUTFILE TABLES I_INFILE_ASC
USING P_FILE P_FTYPE.
*--- Perform Formating ASC type data
PERFORM FORMAT_ASC_DATA.
ELSEIF P_FTYPE = 'DAT'.
*--- Uploading the data from server
PERFORM READ_INPUTFILE TABLES IT_DATA
USING P_FILE P_FTYPE.
ENDIF.
WHEN OTHERS.
MESSAGE S000(Z_MSGCLASS).
F_STOP = 'X'.
STOP.
ENDCASE.
IF NOT IT_DATA[] IS INITIAL.
*--- Perform to delete header and empty lines.
PERFORM DELETE_HEADER_EMPTY_RECS.
ENDIF.
ENDFORM. " READ_INPUT_FILE_DATA
*&---------------------------------------------------------------------*
*& Form SPLIT_FILENAME_EXT
*&---------------------------------------------------------------------*
* To split the filename and the extension
*----------------------------------------------------------------------*
FORM SPLIT_FILENAME_EXT.
MOVE P_FILE TO V_SFILE.
*--- To get the extensions of the file
CALL FUNCTION 'CV120_SPLIT_FILE'
EXPORTING
PF_FILE = V_SFILE
IMPORTING
* PFX_FILE =
PFX_EXTENSION = V_FILEEXT.
* PFX_DOTEXTENSION = .
*--- Checking the case of file extension
IF V_FILEEXT NA SY-ABCDE.
TRANSLATE V_FILEEXT TO UPPER CASE.
ENDIF.
ENDFORM. " SPLIT_FILENAME_EXT
*&---------------------------------------------------------------------*
*& Form MOVE_DATA
*&---------------------------------------------------------------------*
* To move the input file data to an internal table
*----------------------------------------------------------------------*
FORM MOVE_DATA.
DATA : LV_INDEX TYPE I.
FIELD-SYMBOLS
*--- Sorting the internal table
SORT IT_INTERN BY ROW COL.
CLEAR IT_INTERN.
LOOP AT IT_INTERN.
MOVE IT_INTERN-COL TO LV_INDEX.
*--- Assigning the each record to an internal table row
ASSIGN COMPONENT LV_INDEX OF STRUCTURE IT_DATA TO
*--- Asigning the field value to a field symbol
MOVE IT_INTERN-VALUE TO
AT END OF ROW.
APPEND IT_DATA.
CLEAR IT_DATA.
ENDAT.
ENDLOOP.
ENDFORM. " MOVE_DATA
*&---------------------------------------------------------------------*
*& Form CONVER_XLS_ITAB
*&---------------------------------------------------------------------*
* To convert the excel data into an internal table
*----------------------------------------------------------------------*
FORM CONVERT_XLS_ITAB.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = P_BEGCOL
I_BEGIN_ROW = P_BEGROW
I_END_COL = P_ENDCOL
I_END_ROW = P_ENDROW
TABLES
INTERN = IT_INTERN
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 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.
IF NOT IT_INTERN[] IS INITIAL.
*--- Perform to move the data into an internal data
PERFORM MOVE_DATA.
ELSE.
MESSAGE I003(Z_MSGCLASS).
F_STOP = 'X'.
STOP.
ENDIF.
ENDFORM. " CONVERT_XLS_ITAB
*&---------------------------------------------------------------------*
*& Form DISPLAY_SELECTION_SCR
*&---------------------------------------------------------------------*
* To display the selection screen input
*----------------------------------------------------------------------*
FORM DISPLAY_SEL_SCR_REPORT.
WRITE :/1(132) SY-ULINE.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
WRITE :/1(1) SY-VLINE,
65(65) 'SELECTION SCREEN DATA'(003),
132(1) SY-VLINE.
WRITE : /1(132) SY-ULINE.
FORMAT INTENSIFIED OFF.
*--- Input file name
WRITE :/1(1) SY-VLINE,
2(24) 'Input File name'(004),
27(2) ' : ',
30(100) P_FILE,
132(1) SY-VLINE.
IF NOT IT_ERROR[] IS INITIAL.
*--- Setting the Error file name with .CSV
PERFORM FILL_COLOR.
IF V_FILEEXT = 'XLS'.
IF NOT P_ERR CS '.XLS'.
IF P_ERR CA '.'.
P_ERR = P_ERR(SY-FDPOS).
CONCATENATE P_ERR '.CSV' INTO P_ERR.
ENDIF.
ENDIF.
P_FTYPE = 'DAT'.
V_DEL = '2C'. " Hexadecimal value for ','
ENDIF.
*--- Error File name
PERFORM FILL_COLOR.
WRITE :/1(1) SY-VLINE,
2(24) 'Error File name'(005),
27(2) ' : ',
30(100) P_ERR,
132(1) SY-VLINE.
ENDIF.
*--- File type
PERFORM FILL_COLOR.
WRITE :/1(1) SY-VLINE,
2(24) 'File Type'(006),
27(2) ' : '.
IF V_FILEEXT = 'XLS'.
WRITE :30 'XLS'(007),
132(1) SY-VLINE.
ELSE.
WRITE :30 P_FTYPE,
132(1) SY-VLINE.
ENDIF.
*--- BDC methods
PERFORM FILL_COLOR.
IF P_CT = 'X'.
WRITE :/1(1) SY-VLINE,
2(24) 'Call Transaction'(008),
27(2) ' :',
30 P_CT,
132(1) SY-VLINE.
ELSE.
WRITE :/1(1) SY-VLINE,
2(24) 'Create Session'(009),
27(2) ' : ',
30 P_BDC,
132(1) SY-VLINE.
ENDIF.
*--- Test Mode
PERFORM FILL_COLOR.
WRITE :/1(1) SY-VLINE,
2(24) 'Test Mode'(010),
27(2) ' : ',
30 P_TEST,
132(1) SY-VLINE.
*--- Header lines
PERFORM FILL_COLOR.
WRITE :/1(1) SY-VLINE,
2(24) 'Header Lines'(011),
27(2) ' : ',
30 P_HEADER LEFT-JUSTIFIED,
132(1) SY-VLINE.
WRITE :/1(132) SY-ULINE.
ENDFORM. " DISPLAY_SELECTION_SCR
*&---------------------------------------------------------------------*
*& Form DELETE_HEADER_EMPTY_RECS
*&---------------------------------------------------------------------*
* To delete the Header and empty records
*----------------------------------------------------------------------*
FORM DELETE_HEADER_EMPTY_RECS.
DATA: LV_TABIX LIKE SY-TABIX. " Table Index
IF NOT P_HEADER IS INITIAL.
LOOP AT IT_DATA.
IF P_HEADER > 0 AND NOT IT_DATA IS INITIAL.
DELETE IT_DATA FROM 1 TO P_HEADER.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
CLEAR IT_DATA.
*--- To delete the empty lines from internal table
LOOP AT IT_DATA.
LV_TABIX = SY-TABIX.
IF IT_DATA IS INITIAL.
V_EMPTY = V_EMPTY + 1.
DELETE IT_DATA INDEX LV_TABIX.
ENDIF.
ENDLOOP.
CLEAR IT_DATA.
*--- Total no of recs in file
DESCRIBE TABLE IT_DATA LINES V_TOTAL.
IF V_TOTAL = 0.
MESSAGE I013(Z_MSGCLASS). " No records in the file
F_STOP = 'X'.
STOP.
ENDIF.
ENDFORM. " DELETE_HEADER_EMPTY_LINES
*&---------------------------------------------------------------------*
*& Form DISPLAY_SUCCESS_ERROR_DATA
*&---------------------------------------------------------------------*
* To display the no.of records,success and error records
*----------------------------------------------------------------------*
FORM DISPLAY_SUMMARY_REPORT.
SKIP 3.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
WRITE :/1(132) SY-ULINE.
WRITE :/1(1) SY-VLINE,
65 'SUMMARY REPORT'(012),
132(1) SY-VLINE.
FORMAT INTENSIFIED OFF.
PERFORM FILL_COLOR.
WRITE :/1(132) SY-ULINE.
WRITE :/1(1) SY-VLINE,
2(24) 'Processed Records'(013),
27(2) ' : ',
30 V_TOTAL,
132(1) SY-VLINE.
PERFORM FILL_COLOR.
WRITE :/1(1) SY-VLINE,
2(24) 'Successfully Uploaded'(014),
27(2) ' : ',
30 V_SUCCESS,
132(1) SY-VLINE.
PERFORM FILL_COLOR.
WRITE :/1(1) SY-VLINE,
2(24) 'Error Records'(015),
27(2) ' : ',
30 V_ERROR,
132(1) SY-VLINE.
PERFORM FILL_COLOR.
WRITE :/1(1) SY-VLINE,
2(24) 'Empty Records'(016),
27(2) ' : ',
30 V_EMPTY,
132(1) SY-VLINE.
IF P_CT IS INITIAL.
PERFORM FILL_COLOR.
WRITE :/1(1) SY-VLINE,
2(23) 'No.of Records Uploaded'(026),
25(2) ' : ',
30 V_INSERT,
132(1) SY-VLINE.
ENDIF.
WRITE :/1(132) SY-ULINE.
ENDFORM. " DISPLAY_SUCCESS_ERROR_DATA
*----------------------------------------------------------------------*
* Form : Session_Report
*----------------------------------------------------------------------*
* Description : To display the list of sessions created
*----------------------------------------------------------------------*
FORM SESSION_REPORT .
IF NOT I_SESSION[] IS INITIAL.
FORMAT COLOR COL_HEADING.
WRITE :/01(132) SY-ULINE.
WRITE :/01(01) SY-VLINE,
65 'SESSIONS CREATED'(017) CENTERED,
132(01) SY-VLINE.
WRITE :/01(132) SY-ULINE.
FORMAT INTENSIFIED OFF.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE :/01(132) SY-ULINE.
LOOP AT I_SESSION.
WRITE : /1 SY-VLINE.
AT FIRST.
WRITE : 5 'Session names'(018).
ENDAT.
WRITE : 27 ':', 30 I_SESSION-NAME,
132 SY-VLINE.
ENDLOOP.
WRITE : /01(132) SY-ULINE.
ENDIF.
ENDFORM. " Session_Report
*&---------------------------------------------------------------------*
*& Form DISPLAY_ERROR_RECORDS
*&---------------------------------------------------------------------*
* To display the error records
*----------------------------------------------------------------------*
FORM DISPLAY_ERROR_RECORDS.
IF V_ERROR > 0.
* ---- Perform to display the error header
PERFORM DISPLAY_ERROR_HEADER.
* ---- Perform to display the error records
PERFORM DISPLAY_ERROR_DETAIL.
ENDIF.
ENDFORM. " DISPLAY_ERROR_RECORDS
*&---------------------------------------------------------------------
**& Form DISPLAY_ERROR_HEADER
*&---------------------------------------------------------------------
** To display the error header
*----------------------------------------------------------------------
FORM DISPLAY_ERROR_HEADER.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
SKIP.
WRITE :/1(132) SY-ULINE.
WRITE :/1(1) SY-VLINE,
65 'ERROR RECORDS'(019),
132(1) SY-VLINE.
FORMAT INTENSIFIED OFF.
FORMAT COLOR COL_HEADING.
WRITE :/1(132) SY-ULINE.
WRITE : /1(1) SY-VLINE,
2(10) 'Document Date'(020),
12(1) SY-VLINE,
13(10) 'Posting Date'(021),
23(1) SY-VLINE,
24(3) 'Movement type'(022),
27(1) SY-VLINE,
28(4) 'Plant'(023),
32(1) SY-VLINE,
33(4) 'Storage location'(024),
132(1) SY-VLINE.
WRITE :/1(132) SY-ULINE.
FORMAT INTENSIFIED OFF.
ENDFORM. " DISPLAY_ERROR_HEADER
*&---------------------------------------------------------------------
* Form DISPLAY_ERROR_DETAIL
*&---------------------------------------------------------------------
* To display the error records
*----------------------------------------------------------------------
FORM DISPLAY_ERROR_DETAIL.
LOOP AT IT_ERROR.
PERFORM FILL_COLOR.
WRITE : /1(1) SY-VLINE,
2(10) IT_ERROR-BLDAT,
12(1) SY-VLINE,
13(10) IT_ERROR-BUDAT,
23(1) SY-VLINE,
24(3) IT_ERROR-BWARTWA,
27(1) SY-VLINE,
28(4) IT_ERROR-WERKS,
32(1) SY-VLINE,
33(4) IT_ERROR-LGORT,
132(1) SY-VLINE.
ENDLOOP.
WRITE :/1(132) SY-ULINE.
ENDFORM. " DISPLAY_ERROR_DETAIL
*&---------------------------------------------------------------------*
*& Form COLOR_FILL
*&---------------------------------------------------------------------*
*--- To display the background color
*----------------------------------------------------------------------*
FORM FILL_COLOR.
IF F_COLOR = SPACE.
FORMAT COLOR 2.
F_COLOR = 'X'.
ELSE.
FORMAT COLOR 4.
CLEAR F_COLOR.
ENDIF.
ENDFORM. " COLOR_FILL
No comments:
Post a Comment