Monday, November 5, 2007

BDC Using Session and Call Transactiom Methods with Longtext

BDC Using Session and Call Transactiom Methods with Longtext


REPORT Z_MM_BDC_MATERIAL_MASTER
NO STANDARD PAGE HEADING
LINE-SIZE 132
LINE-COUNT 65
MESSAGE-ID Z_MSGCLASS.
************************************************************************
* Description : BDC Using Session and Call Transactiom Methods *
* with Longtext *
* *
* 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 MM01 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 19/04/2006 Karthik
*----------------------------------------------------------------------*
* TABLES *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* 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(1300) 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 table to hold standard text
I_TDLINES LIKE TLINE OCCURS 0 WITH HEADER LINE.
*--- Internal to hold the records in the text file
DATA : BEGIN OF IT_DATA OCCURS 10,
MATNR(18), " Material Code
MBRSH(1), " Industry sector
MTART(4), " Material Type
WERKS(4), " Plant
LGORT(4), " Storage Location
MAKTX(40), " Material Description
MEINS(3), " Base unit of Measure
MATKL(9), " Material Group
BISMT(18), " Old Material Number
EKGRP(3), " Purchase grp
MFRPN(40), " Manufacturer part number
LGPBE(10), " Storage bin
DISMM(2), " MRP Type
DISPO(3), " MRP controller
MINBE(13), " Reorder Point
DISLS(2), " Lot size (materials planning)
MABST(17), " Maximum stock level
BESKZ(1), " Procurement type
PLIFZ(3), " Planned delivery time in days
FHORI(3), " Scheduling Margin Key for Floats
MTVFP(2), " Availability check
BKLAS(4), " Valuation Class
VPRSV(1), " Price Control
EKALR(1), " Material Is Costed with Quantity Structure
HKMAT(1), " Material-related origin
LTEXT(1000), " Variable to hold Long Text
END OF IT_DATA.
*--- Internal table to hold the long text
data: begin of it_ltext occurs 0,
matnr(18),
ltext(982),
end of it_ltext.

*--- Internal table to hold the error records.
DATA : BEGIN OF IT_ERROR OCCURS 0.
INCLUDE STRUCTURE IT_DATA.
DATA : MESSAGE(80) 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(1300),
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 'MM01', " Transaction
C_MODE(1) VALUE 'A', " Mode
C_UPDATE(1) VALUE 'S', " Update
C_SESS(12) TYPE C VALUE 'MAT_SESS'.

*----------------------------------------------------------------------*
* 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_BDC_SESS TYPE APQI-GROUPID VALUE 'UPLOAD',
V_MAX TYPE I VALUE '900', " Max records
V_LINES TYPE I, " No.of records
V_INSERT TYPE I,
V_COUNTER(2) TYPE N, " Sessions
F_OPENSESSION TYPE C,
V_RECORDS TYPE I.

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(02) TYPE C VALUE '09'. " To seperate fields in case of Dat

DATA: IT_INTERN TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
DATA: V_SFILE(255), " File path
V_EXT(3). " File Extension
*----------------------------------------------------------------------*
* Structures
*----------------------------------------------------------------------*
*---Parameter string for runtime of CALL TRANSACTION USING..
DATA: X_OPTIONS TYPE CTU_PARAMS.

*----------------------------------------------------------------------*
* SELECTION SCREEN. *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK SCR1 WITH FRAME TITLE TEXT-111.
PARAMETER : P_FILE TYPE RLGRAP-FILENAME OBLIGATORY DEFAULT " Input File
'C:\Material_master.TXT',
P_ERR TYPE RLGRAP-FILENAME OBLIGATORY DEFAULT " Error File
'C:\Material_master_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-222.
PARAMETER : P_CT RADIOBUTTON GROUP BDC, " Call Trans
P_BDC RADIOBUTTON GROUP BDC DEFAULT 'X'. " Create BDC sess
PARAMETER : P_SESS1 TYPE APQI-GROUPID OBLIGATORY
DEFAULT C_SESS. " Session name
PARAMETER : P_MAX(4) OBLIGATORY DEFAULT '100'. " Max. recs in a session
PARAMETERS: P_HEADER TYPE I DEFAULT 0. " Header Lines
PARAMETERS: P_BEGCOL TYPE I DEFAULT 1 NO-DISPLAY,
P_BEGROW TYPE I DEFAULT 1 NO-DISPLAY,
P_ENDCOL TYPE I DEFAULT 100 NO-DISPLAY,
P_ENDROW TYPE I DEFAULT 32000 NO-DISPLAY.
PARAMETERS: P_TEST AS CHECKBOX DEFAULT 'X'. " Test mode

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_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 report
PERFORM DISPLAY_SEL_SCR_REPORT.
*---- Perform to display the no.of records,success and error records
PERFORM DISPLAY_SUMMARY_REPORT.
*--- Perform to display the session report
PERFORM SESSION_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.

*--- Function module to upload the input 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-MATNR = I_INFILE_ASC-STRING+0(18).
* IT_DATA-MBRSH = I_INFILE_ASC-STRING+18(1).
* IT_DATA-MTART = I_INFILE_ASC-STRING+19(4).
* IT_DATA-WERKS = I_INFILE_ASC-STRING+23(4).
* IT_DATA-LGORT = I_INFILE_ASC-STRING+27(4).
* IT_DATA-MAKTX = I_INFILE_ASC-STRING+31(40).
* IT_DATA-MEINS = I_INFILE_ASC-STRING+71(3).
* IT_DATA-MATKL = I_INFILE_ASC-STRING+74(9).
* IT_DATA-BISMT = I_INFILE_ASC-STRING+83(18).
* IT_DATA-EKGRP = I_INFILE_ASC-STRING+101(3).
* IT_DATA-MFRPN = I_INFILE_ASC-STRING+104(40).
* IT_DATA-LTEX1 = I_INFILE_ASC-STRING+144(40).
* IT_DATA-LGPBE = I_INFILE_ASC-STRING+184(10).
* IT_DATA-DISMM = I_INFILE_ASC-STRING+194(2).
* IT_DATA-DISPO = I_INFILE_ASC-STRING+196(3).
* IT_DATA-MINBE = I_INFILE_ASC-STRING+199(13).
* IT_DATA-DISLS = I_INFILE_ASC-STRING+212(2).
* IT_DATA-MABST = I_INFILE_ASC-STRING+214(17).
* IT_DATA-BESKZ = I_INFILE_ASC-STRING+231(1).
* IT_DATA-PLIFZ = I_INFILE_ASC-STRING+232(3).
* IT_DATA-FHORI = I_INFILE_ASC-STRING+235(3).
* IT_DATA-MTVFP = I_INFILE_ASC-STRING+238(2).
* IT_DATA-BKLAS = I_INFILE_ASC-STRING+240(4).
* IT_DATA-VPRSV = I_INFILE_ASC-STRING+244(1).
* IT_DATA-EKALR = I_INFILE_ASC-STRING+245(1).
* IT_DATA-HKMAT = I_INFILE_ASC-STRING+246(1).

IT_DATA-MATNR = I_INFILE_ASC-STRING+0(18).
IT_DATA-MBRSH = I_INFILE_ASC-STRING+18(1).
IT_DATA-MTART = I_INFILE_ASC-STRING+19(4).
IT_DATA-WERKS = I_INFILE_ASC-STRING+23(4).
IT_DATA-LGORT = I_INFILE_ASC-STRING+27(4).
IT_DATA-MAKTX = I_INFILE_ASC-STRING+31(40).
IT_DATA-MEINS = I_INFILE_ASC-STRING+71(3).
IT_DATA-MATKL = I_INFILE_ASC-STRING+74(9).
IT_DATA-BISMT = I_INFILE_ASC-STRING+83(18).
IT_DATA-EKGRP = I_INFILE_ASC-STRING+101(3).
IT_DATA-MFRPN = I_INFILE_ASC-STRING+104(40).
IT_DATA-LGPBE = I_INFILE_ASC-STRING+144(10).
IT_DATA-DISMM = I_INFILE_ASC-STRING+154(2).
IT_DATA-DISPO = I_INFILE_ASC-STRING+156(3).
IT_DATA-MINBE = I_INFILE_ASC-STRING+159(13).
IT_DATA-DISLS = I_INFILE_ASC-STRING+172(2).
IT_DATA-MABST = I_INFILE_ASC-STRING+174(17).
IT_DATA-BESKZ = I_INFILE_ASC-STRING+191(1).
IT_DATA-PLIFZ = I_INFILE_ASC-STRING+192(3).
IT_DATA-FHORI = I_INFILE_ASC-STRING+195(3).
IT_DATA-MTVFP = I_INFILE_ASC-STRING+198(2).
IT_DATA-BKLAS = I_INFILE_ASC-STRING+200(4).
IT_DATA-VPRSV = I_INFILE_ASC-STRING+204(1).
IT_DATA-EKALR = I_INFILE_ASC-STRING+205(1).
IT_DATA-HKMAT = I_INFILE_ASC-STRING+206(1).
IT_DATA-LTEXT = I_INFILE_ASC-STRING+207(1000).

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-MAKTX IS INITIAL
OR IT_DATA-MEINS IS INITIAL
OR IT_DATA-MATKL IS INITIAL
OR IT_DATA-EKGRP IS INITIAL
OR IT_DATA-DISMM IS INITIAL
OR IT_DATA-VPRSV IS INITIAL .


LV_TABIX = SY-TABIX.
V_MESG = 'Mandatory fields missing'(002).
* ----- Perform to store the error record
PERFORM ERROR_PROCESSING. " USING IT_DATA V_MESG.
* ----- Deleting the record which is initial
DELETE IT_DATA INDEX LV_TABIX.
ENDIF.
ENDLOOP.
CLEAR V_MESG.

ENDFORM. " DATA_VALIDATION
*&---------------------------------------------------------------------*
*& Form error_processing
*&---------------------------------------------------------------------*
* To process the error records
*----------------------------------------------------------------------*
FORM ERROR_PROCESSING. " USING F_IT_DATA
"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 0060
PERFORM POPULATE_DATA_SCREEN_0060.
*--- Perform to populate the data in screen 0070
PERFORM POPULATE_DATA_SCREEN_0070.
*--- Perform to populate the data in screen 0080
PERFORM POPULATE_DATA_SCREEN_0080.
*--- Perform to populate the data in screen 4004
PERFORM POPULATE_DATA_SCREEN_4004.
*--- Perform to populate the BASIC data 2 in screen 4004
PERFORM POPULATE_BDATA2_SCREEN_4004.
*--- Perform to populate the Purchasing data in screen 4000
PERFORM POPULATE_PURCHASE_SCREEN_4000.
IF NOT IT_DATA-LTEXT IS INITIAL.
*--- Perform to populate Long text
PERFORM POPULATE_LONG_TEXT.
ENDIF.
*--- Perform to populate the Purchase order text data in screen 4040
PERFORM POPULATE_PURORDTXT_SCREEN_4040.
*--- Perform to populate the MRP1 in screen 4000
PERFORM POPULATE_MRP1_SCREEN_4000.
*--- Perform to populate the MRP2 in screen 4000
PERFORM POPULATE_MRP2_SCREEN_4000.
*--- Perform to populate the MRP3 in screen 4000
PERFORM POPULATE_MRP3_SCREEN_4000.
*--- Perform to populate the MRP4 in screen 4000
PERFORM POPULATE_MRP4_SCREEN_4000.
*--- Perform to populate the Plant Data & Storage loc in screen 4000
PERFORM POPULATE_P_SL1_SCREEN_4000.
*--- Perform to populate the Plant Data & Storage loc in screen 4000
PERFORM POPULATE_P_SL2_SCREEN_4000.
*--- Perform to populate the Accounting 1 in screen 4000
PERFORM POPULATE_ACC1_SCREEN_4000.
*--- Perform to populate the Accounting 2 in screen 4000
PERFORM POPULATE_ACC2_SCREEN_4000.
*--- Perform to populate the costing data 1 in screen 4000
PERFORM POPULATE_COSTING1_SCREEN_4000.
*--- Perform to populate the costing data 1 in screen 4000
PERFORM POPULATE_COSTING2_SCREEN_4000.


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.
CLEAR X_OPTIONS.
X_OPTIONS-DISMODE = C_MODE.
X_OPTIONS-UPDMODE = C_UPDATE.
X_OPTIONS-DEFSIZE = 'X'.

*----- call transaction method to upload data
CALL TRANSACTION C_TCODE USING IT_BDCTAB
OPTIONS FROM X_OPTIONS
MESSAGES INTO I_BDCMSGCOLL.

* 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 either for FSP0 or FSP2
*----------------------------------------------------------------------*
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 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'(003),
132(1) SY-VLINE.
FORMAT INTENSIFIED OFF.
PERFORM COLOR_FILL.
WRITE :/1(132) SY-ULINE.
WRITE :/1(1) SY-VLINE,
2(24) 'Processed Records'(004),
27(2) ' : ',
30 V_TOTAL,
132(1) SY-VLINE.
PERFORM COLOR_FILL.
WRITE :/1(1) SY-VLINE,
2(24) 'Successfully Uploaded'(005),
27(2) ' : ',
30 V_SUCCESS,
132(1) SY-VLINE.
PERFORM COLOR_FILL.
WRITE :/1(1) SY-VLINE,
2(24) 'Error Records'(006),
27(2) ' : ',
30 V_ERROR,
132(1) SY-VLINE.
PERFORM COLOR_FILL.
WRITE :/1(1) SY-VLINE,
2(24) 'Empty Records'(007),
27(2) ' : ',
30 V_EMPTY,
132(1) SY-VLINE.
WRITE :/1(132) SY-ULINE.

ENDFORM. " DISPLAY_SUCCESS_ERROR_DATA

*&---------------------------------------------------------------------*
*& 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.

* WRITE :/1(89) SY-ULINE.
SKIP.
WRITE :/1(132) SY-ULINE.
WRITE :/1(1) SY-VLINE,
40 'ERROR RECORDS'(008),
132(1) SY-VLINE.
WRITE :/1(132) SY-ULINE.
WRITE : /1(1) SY-VLINE,
2(18) 'Material Number'(009),
20(1) SY-VLINE,
21(4) 'Type'(010),
25(1) SY-VLINE,
26(5) 'Plant'(011),
31(1) SY-VLINE,
32(16) 'storage location'(012),
48(1) SY-VLINE,
49(80) 'Message'(013),
132(1) SY-VLINE.


WRITE :/1(132) SY-ULINE.

ENDFORM. " DISPLAY_ERROR_HEADER

*&---------------------------------------------------------------------*
*& Form DISPLAY_ERROR_DETAIL
*&---------------------------------------------------------------------*
* To display the error records
*----------------------------------------------------------------------*
FORM DISPLAY_ERROR_DETAIL.

LOOP AT IT_ERROR.
WRITE : /1(1) SY-VLINE,
2(18) IT_ERROR-MATNR,
20(1) SY-VLINE,
21(4) IT_ERROR-MTART,
25(1) SY-VLINE,
26(5) IT_ERROR-WERKS,
31(1) SY-VLINE,
32(16) IT_ERROR-LGORT,
48(1) SY-VLINE,
49(80) IT_ERROR-MESSAGE,
132(1) SY-VLINE.

ENDLOOP.
WRITE :/1(132) SY-ULINE.

ENDFORM. " DISPLAY_ERROR_DETAIL
*---------------------------------------------------------------------*
* 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-MATNR
IT_ERROR-MBRSH
IT_ERROR-MTART
IT_ERROR-WERKS
IT_ERROR-LGORT
IT_ERROR-MAKTX
IT_ERROR-MEINS
IT_ERROR-MATKL
IT_ERROR-BISMT
IT_ERROR-EKGRP
IT_ERROR-MFRPN
* IT_ERROR-LTEX1
IT_ERROR-LGPBE
IT_ERROR-DISMM
IT_ERROR-DISPO
IT_ERROR-MINBE
IT_ERROR-DISLS
IT_ERROR-MABST
IT_ERROR-BESKZ
IT_ERROR-PLIFZ
IT_ERROR-FHORI
IT_ERROR-MTVFP
IT_ERROR-BKLAS
IT_ERROR-VPRSV
IT_ERROR-EKALR
IT_ERROR-HKMAT
IT_ERROR-LTEXT
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(18) = IT_ERROR-MATNR.
* I_FINAL-STRING+18(1) = IT_ERROR-MBRSH.
* I_FINAL-STRING+19(4) = IT_ERROR-MTART.
* I_FINAL-STRING+23(4) = IT_ERROR-WERKS.
* I_FINAL-STRING+27(4) = IT_ERROR-LGORT.
* I_FINAL-STRING+31(40) = IT_ERROR-MAKTX.
* I_FINAL-STRING+71(3) = IT_ERROR-MEINS.
* I_FINAL-STRING+74(9) = IT_ERROR-MATKL.
* I_FINAL-STRING+83(18) = IT_ERROR-BISMT.
* I_FINAL-STRING+101(3) = IT_ERROR-EKGRP.
* I_FINAL-STRING+104(40) = IT_ERROR-MFRPN.
* I_FINAL-STRING+144(40) = IT_ERROR-LTEX1.
* I_FINAL-STRING+184(10) = IT_ERROR-LGPBE.
* I_FINAL-STRING+194(2) = IT_ERROR-DISMM.
* I_FINAL-STRING+196(3) = IT_ERROR-DISPO.
* I_FINAL-STRING+199(13) = IT_ERROR-MINBE.
* I_FINAL-STRING+212(2) = IT_ERROR-DISLS.
* I_FINAL-STRING+214(17) = IT_ERROR-MABST.
* I_FINAL-STRING+231(1) = IT_ERROR-BESKZ.
* I_FINAL-STRING+232(3) = IT_ERROR-PLIFZ.
* I_FINAL-STRING+235(3) = IT_ERROR-FHORI.
* I_FINAL-STRING+238(2) = IT_ERROR-MTVFP.
* I_FINAL-STRING+240(4) = IT_ERROR-BKLAS.
* I_FINAL-STRING+244(1) = IT_ERROR-VPRSV.
* I_FINAL-STRING+245(1) = IT_ERROR-EKALR.
* I_FINAL-STRING+246(1) = IT_ERROR-HKMAT.

I_FINAL-STRING+0(18) = IT_ERROR-MATNR.
I_FINAL-STRING+18(1) = IT_ERROR-MBRSH.
I_FINAL-STRING+19(4) = IT_ERROR-MTART.
I_FINAL-STRING+23(4) = IT_ERROR-WERKS.
I_FINAL-STRING+27(4) = IT_ERROR-LGORT.
I_FINAL-STRING+31(40) = IT_ERROR-MAKTX.
I_FINAL-STRING+71(3) = IT_ERROR-MEINS.
I_FINAL-STRING+74(9) = IT_ERROR-MATKL.
I_FINAL-STRING+83(18) = IT_ERROR-BISMT.
I_FINAL-STRING+101(3) = IT_ERROR-EKGRP.
I_FINAL-STRING+104(40) = IT_ERROR-MFRPN.
I_FINAL-STRING+144(10) = IT_ERROR-LGPBE.
I_FINAL-STRING+154(2) = IT_ERROR-DISMM.
I_FINAL-STRING+156(3) = IT_ERROR-DISPO.
I_FINAL-STRING+159(13) = IT_ERROR-MINBE.
I_FINAL-STRING+172(2) = IT_ERROR-DISLS.
I_FINAL-STRING+174(17) = IT_ERROR-MABST.
I_FINAL-STRING+191(1) = IT_ERROR-BESKZ.
I_FINAL-STRING+192(3) = IT_ERROR-PLIFZ.
I_FINAL-STRING+195(3) = IT_ERROR-FHORI.
I_FINAL-STRING+198(2) = IT_ERROR-MTVFP.
I_FINAL-STRING+200(4) = IT_ERROR-BKLAS.
I_FINAL-STRING+204(1) = IT_ERROR-VPRSV.
I_FINAL-STRING+205(1) = IT_ERROR-EKALR.
I_FINAL-STRING+206(1) = IT_ERROR-HKMAT.
I_FINAL-STRING+207(1000) = IT_ERROR-LTEXT.

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_0060
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM POPULATE_DATA_SCREEN_0060.

PERFORM BDC_DYNPRO USING 'SAPLMGMM' '0060'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RMMG1-MATNR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=AUSW'.
PERFORM BDC_FIELD USING 'RMMG1-MATNR' IT_DATA-MATNR.
PERFORM BDC_FIELD USING 'RMMG1-MBRSH' IT_DATA-MBRSH.
PERFORM BDC_FIELD USING 'RMMG1-MTART' IT_DATA-MTART.

ENDFORM. " POPULATE_DATA_SCREEN_0060
*&---------------------------------------------------------------------*
*& Form POPULATE_DATA_SCREEN_0070
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM POPULATE_DATA_SCREEN_0070.

PERFORM BDC_DYNPRO USING 'SAPLMGMM' '0070'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'MSICHTAUSW-DYTXT(15)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(01)' 'X'.
PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(02)' 'X'.
PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(03)' 'X'.
PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(05)' 'X'.
PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(06)' 'X'.
PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(07)' 'X'.
PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(08)' 'X'.
PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(09)' 'X'.
PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(10)' 'X'.
PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(11)' 'X'.
PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(12)' 'X'.
PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(13)' 'X'.
PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(14)' 'X'.
PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(15)' 'X'.

ENDFORM. " POPULATE_DATA_SCREEN_0070
*&---------------------------------------------------------------------*
*& Form POPULATE_DATA_SCREEN_0080
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM POPULATE_DATA_SCREEN_0080.

PERFORM BDC_DYNPRO USING 'SAPLMGMM' '0080'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RMMG1-LGORT'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=ENTR'.
PERFORM BDC_FIELD USING 'RMMG1-WERKS' IT_DATA-WERKS.
PERFORM BDC_FIELD USING 'RMMG1-LGORT' IT_DATA-LGORT.

ENDFORM. " POPULATE_DATA_SCREEN_0080
*&---------------------------------------------------------------------*
*& Form POPULATE_DATA_SCREEN_4004
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM POPULATE_DATA_SCREEN_4004.

PERFORM BDC_DYNPRO USING 'SAPLMGMM' '4004'.
* PERFORM BDC_FIELD USING 'BDC_CURSOR' 'MARA-BISMT'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=SP02'.
PERFORM BDC_FIELD USING 'MAKT-MAKTX' IT_DATA-MAKTX.
PERFORM BDC_FIELD USING 'MARA-BISMT' IT_DATA-BISMT.
PERFORM BDC_FIELD USING 'MARA-MEINS' IT_DATA-MEINS.
PERFORM BDC_FIELD USING 'MARA-MATKL' IT_DATA-MATKL.

ENDFORM. " POPULATE_DATA_SCREEN_4004
*&---------------------------------------------------------------------*
*& Form POPULATE_BASICDATA2_SCREEN_400
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM POPULATE_BDATA2_SCREEN_4004.

PERFORM BDC_DYNPRO USING 'SAPLMGMM' '4004'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'MAKT-MAKTX'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=SP09'.

ENDFORM. " POPULATE_BASICDATA2_SCREEN_400
*&---------------------------------------------------------------------*
*& Form POPULATE_PURCHASING_SCREEN_400
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM POPULATE_PURCHASE_SCREEN_4000.

PERFORM BDC_DYNPRO USING 'SAPLMGMM' '4000'.
* PERFORM BDC_FIELD USING 'BDC_CURSOR' 'MARA-MFRPN'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=SP11'.
PERFORM BDC_FIELD USING 'MARC-EKGRP' IT_DATA-EKGRP.
PERFORM BDC_FIELD USING 'MARA-MFRPN' IT_DATA-MFRPN.

ENDFORM. " POPULATE_PURCHASING_SCREEN_400
*&---------------------------------------------------------------------*
*& Form POPULATE_LONG_TEXT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM POPULATE_LONG_TEXT .

DATA: LV_LNGTEXT(72).

DATA: LV_STRING(1000),
LEN TYPE I,
I_POS TYPE I,
LV_LNLEN TYPE I,
LV_LINE(2) TYPE N,
LV_FIRST,
LV_LNCNT TYPE I,
LV_FLAG.

LV_LNLEN = 72.
LV_STRING = IT_DATA-LTEXT.
LEN = STRLEN( LV_STRING ).
PERFORM BDC_DYNPRO USING 'SAPLMGMM' '4040'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=LTEX'.
LV_LINE = 2.
DO.
IF LV_FLAG = SPACE.
LEN = STRLEN( LV_STRING+I_POS ).
ENDIF.
IF LEN = 0.
PERFORM BDC_DYNPRO USING 'SAPLSTXX' '1100'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=TXBA'.

PERFORM BDC_DYNPRO USING 'SAPLSPO1' '0100'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=YES'.
EXIT.
ENDIF.
IF LEN < lv_lnlen =" LEN." lv_lngtext =" LV_STRING+I_POS(LV_LNLEN)." lv_first =" SPACE." lv_first =" 'X'." lv_lnlen =" 72." lv_flag =" 'X'." i_pos =" I_POS" lv_lncnt =" LV_LNCNT" lv_line =" LV_LINE" p_ftype =" 'ASC'." p_ftype =" 'DAT'." f_stop =" 'X'." pf_file =" V_SFILE" pfx_file =" PFX_EXTENSION" pfx_dotextension =" .">.
*--- 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 .
IF SY-SUBRC = 0.
*--- Asigning the field value to a field symbol
MOVE IT_INTERN-VALUE TO .
ENDIF.
AT END OF ROW.
APPEND IT_DATA.
CLEAR IT_DATA.
ENDAT.
ENDLOOP.

ENDFORM. " MOVE_DATA

*&---------------------------------------------------------------------*
*& Form CONVER_XLS_ITAB
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
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. "#EC *
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

*--- Perform to move the data into an internal data
PERFORM MOVE_DATA.

ENDFORM. " CONVERT_XLS_ITAB
*&---------------------------------------------------------------------*
*& Form DISPLAY_SEL_SCR_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
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'(016),
132(1) SY-VLINE.
WRITE :/1(132) SY-ULINE.
FORMAT INTENSIFIED OFF.

*--- Input file name
PERFORM COLOR_FILL.
WRITE :/1(1) SY-VLINE,
2(24) 'Input File name'(017),
27(2) ' : ',
30(100) P_FILE,
132(1) SY-VLINE.

IF NOT IT_ERROR[] IS INITIAL.
*--- Setting the Error file name with .CSV
PERFORM COLOR_FILL.
IF V_EXT = '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 COLOR_FILL.
WRITE :/1(1) SY-VLINE,
2(24) 'Error File name'(018),
27(2) ' : ',
30(100) P_ERR,
132(1) SY-VLINE.
ENDIF.

*--- File type
PERFORM COLOR_FILL.
WRITE :/1(1) SY-VLINE,
2(24) 'File Type'(019),
27(2) ' : '.
IF V_EXT = 'XLS'.
WRITE :30 'XLS'(020),
132(1) SY-VLINE.
ELSE.
WRITE :30 P_FTYPE,
132(1) SY-VLINE.
ENDIF.
*--- BDC methods
PERFORM COLOR_FILL.
IF P_CT = 'X'.
WRITE :/1(1) SY-VLINE,
2(24) 'Call Transaction'(021),
27(2) ' : ',
30 P_CT,
132(1) SY-VLINE.
ELSE.
WRITE :/1(1) SY-VLINE,
2(24) 'Create Session'(022),
27(2) ' : ',
30 P_BDC,
132(1) SY-VLINE.
ENDIF.
*--- Test Mode
PERFORM COLOR_FILL.
WRITE :/1(1) SY-VLINE,
2(24) 'Test Mode'(023),
27(2) ' : ',
30 P_TEST,
132(1) SY-VLINE.
*--- Header lines
PERFORM COLOR_FILL.
WRITE :/1(1) SY-VLINE,
2(24) 'Header Lines'(024),
27(2) ' : ',
30 P_HEADER LEFT-JUSTIFIED,
132(1) SY-VLINE.
WRITE :/1(132) SY-ULINE.

ENDFORM. " DISPLAY_SEL_SCR_REPORT
*&---------------------------------------------------------------------*
*& Form COLOR_FILL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM COLOR_FILL.

IF F_COLOR = SPACE.
FORMAT COLOR 2.
F_COLOR = 'X'.
ELSE.
FORMAT COLOR 4.
CLEAR F_COLOR.
ENDIF.

ENDFORM. " COLOR_FILL
*&---------------------------------------------------------------------*
*& Form DELETE_HEADER_EMPTY_RECS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM DELETE_HEADER_EMPTY_RECS.

DATA: LV_TABIX LIKE SY-TABIX.

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_RECS

No comments: