REPORT ZVVSC002 LINE-SIZE 80 LINE-COUNT 66 NO STANDARD PAGE HEADING. ************************************************************************ * Description : Upload data from tab delimited text file * and perform =something= automatically * (create BDC Session). * All the lines with '=something=' or '=to be customized=' * words are empty template only and need to be filled with * real data. Transaction XX01 is template * as well and should be changed with real one. * For demo reasons the LIBS transaction is used for * of BDC session (LIBS is SAP guide for Lists Design). * Inputs : PC Input File Name, Batch Session Name * Outputs : '=something= statistics & errors' report * Error/Return Codes : None * External References: WS_FILENAME_GET, WS_UPLOAD, * : transactions LIBS, XX01. ************************************************************************ ********* TABLES ******************************************************* ********* CONSTANS ***************************************************** CONSTANTS: C_X(1) TYPE C VALUE 'X'. ********* DATA: VARIABLES ********************************************** DATA: W_MSG(50) TYPE C, "Message string by Input File Proc. W_N0 LIKE SY-TABIX, "Counter: records read W_N1 LIKE SY-TABIX, "Counter: records selected W_N2 LIKE SY-TABIX. "Counter: records processed ********* DATA: INTERNAL TABLES, RANGES ******************************** *-------- BDC table ---------------------------------------------------- DATA: IT_BDC LIKE BDCDATA OCCURS 0 WITH HEADER LINE. *-------- Input file --------------------------------------------------- DATA: BEGIN OF IT_FILE OCCURS 0, * =something= data field(s), "Input file fields END OF IT_FILE. ********* FIELD GROUPS ************************************************* ********* FIELD SYMBOLS ************************************************ ********* SELECT-OPTIONS AND PARAMETERS ******************************** PARAMETERS: P_FNAME LIKE RLGRAP-FILENAME OBLIGATORY, "Filename Prefix P_GROUP LIKE APQI-GROUPID OBLIGATORY. "BDC Session Name ********* MACROS ******************************************************* *************** INITIALIZATION. *************** ************************* **** at selection-screen. ************************* *--------- F4 for PC Input file ---------------------------------------- AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME. PERFORM SELECT_FILE. *--------- PC Input file ----------------------------------------------- AT SELECTION-SCREEN ON P_FNAME. PERFORM TRY_UPLOAD_FILE. ******************** * at selection-screen. ******************** ******************* START-OF-SELECTION. ******************* PERFORM NUMERATE_LINES. PERFORM VALIDATE_FILE. ***************** END-OF-SELECTION. ***************** PERFORM PROCESS_FILE. PERFORM PRINT_STATISTIC. PERFORM PRINT_FOOTER. ************ TOP-OF-PAGE. ************ PERFORM PRINT_HEADER. ********************************** * top-of-page during line-selection. ********************************** ****************** * at line-selection. ****************** ******** * at pf01. ******** **************** * at user-command. **************** ************************************************************************ FORM PRINT_HEADER. * =to be customized= * can be used: * SY-TITLE, SY-TCODE, SY-REPID, SY-DATUM, SY-UZEIT, SY-PAGNO. WRITE: 'Page: ', SY-PAGNO. * =to be customized= * WRITE: / " =something= 'columns headers'(nnn), ENDFORM. ************************************************************************ FORM PRINT_FOOTER. * =to be customized= WRITE /'*** End Of Report ***'. ENDFORM. ************************************************************************ FORM PRINT_INPUT_LINE. * =to be customized= * WRITE: / "=something= field(s) under text-=something= * " (under columns headers) color col_key, ENDFORM. ************************************************************************ FORM PRINT_STATISTIC. SKIP 1. WRITE: / 'Read Lines'(014) INTENSIFIED ON, AT 40 W_N0 INTENSIFIED OFF. WRITE: / 'Selected Lines'(015) INTENSIFIED ON, AT 40 W_N1 INTENSIFIED OFF. WRITE: / 'Processed Lines'(016) INTENSIFIED ON, AT 40 W_N2 INTENSIFIED OFF. ENDFORM. ************************************************************************ FORM VALIDATE_FILE. LOOP AT IT_FILE. * validation for =something=, if needed * CHECK ..... DELETE IT_FILE. ENDLOOP. DESCRIBE TABLE IT_FILE LINES W_N1. ENDFORM. ************************************************************************ FORM PROCESS_FILE. PERFORM OPEN_BDC. LOOP AT IT_FILE. PERFORM PROCESS_LINE. ENDLOOP. PERFORM CLOSE_BDC. ENDFORM. ************************************************************************ FORM NUMERATE_LINES. DESCRIBE TABLE IT_FILE LINES W_N0. ENDFORM. ************************************************************************ FORM SELECT_FILE. CALL FUNCTION 'WS_FILENAME_GET' EXPORTING DEF_PATH = 'c:\' MASK = ',Text Files,*.txt;*.doc,All Files,*.*.'(101) TITLE = 'Select File'(100) IMPORTING FILENAME = P_FNAME EXCEPTIONS INV_WINSYS = 1 NO_BATCH = 2 SELECTION_CANCEL = 3 SELECTION_ERROR = 4 OTHERS = 5. IF SY-SUBRC <> 0 AND SY-SUBRC <> 3. MESSAGE E102(YB) WITH 'Error Selecting File'(007). ENDIF. ENDFORM. ************************************************************************ FORM TRY_UPLOAD_FILE. CALL FUNCTION 'WS_UPLOAD' EXPORTING FILENAME = P_FNAME FILETYPE = 'DAT' TABLES DATA_TAB = IT_FILE EXCEPTIONS CONVERSION_ERROR = 1 FILE_OPEN_ERROR = 2 FILE_READ_ERROR = 3 INVALID_TABLE_WIDTH = 4 INVALID_TYPE = 5 NO_BATCH = 6 UNKNOWN_ERROR = 7 OTHERS = 8. IF SY-SUBRC <> 0. CASE SY-SUBRC. * =to be customized=: text-006 = 'Uploading Error:' * text-06n = Concrete Error Description WHEN 1. CONCATENATE TEXT-006 TEXT-061 INTO W_MSG SEPARATED BY SPACE. WHEN 2. CONCATENATE TEXT-006 TEXT-062 INTO W_MSG SEPARATED BY SPACE. WHEN 3. CONCATENATE TEXT-006 TEXT-063 INTO W_MSG SEPARATED BY SPACE. WHEN 4. CONCATENATE TEXT-006 TEXT-064 INTO W_MSG SEPARATED BY SPACE. WHEN 5. CONCATENATE TEXT-006 TEXT-065 INTO W_MSG SEPARATED BY SPACE. WHEN 6. CONCATENATE TEXT-006 TEXT-066 INTO W_MSG SEPARATED BY SPACE. WHEN 7. CONCATENATE TEXT-006 TEXT-067 INTO W_MSG SEPARATED BY SPACE. WHEN 8. CONCATENATE TEXT-006 TEXT-068 INTO W_MSG SEPARATED BY SPACE. ENDCASE. MESSAGE E102(YB) WITH W_MSG. ENDIF. IF IT_FILE IS INITIAL. MESSAGE E102(YB) WITH 'Empty File!(013). ENDIF. ENDFORM. ************************************************************************ FORM PROCESS_LINE. PERFORM PRINT_INPUT_LINE. PERFORM BDC_XX01_PREPARE. ENDFORM. ************************************************************************ FORM BDC_XX01_PREPARE. REFRESH IT_BDC. * add lines to BDC data table using forms: ----------------------------- * bdc_dynpro * bdc_field * bdc_okcode * for example: * perform bdc_dynpro using 'SAPML03T' '0112'. "Confirm Single Item * perform bdc_field using 'LTAP-NISTA' it_file-umlme. "Quantity * perform bdc_okcode using '/00'. "Enter *----------------------------------------------------------------------- CALL FUNCTION 'BDC_INSERT' EXPORTING TCODE = 'LIBS' * POST_LOCAL = NOVBLOCAL * PRINTING = NOPRINT TABLES DYNPROTAB = IT_BDC 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. WRITE: 'Error inserting BDC data'(517) COLOR COL_NEGATIVE, SY-SUBRC. ELSE. ADD 1 TO W_N2. ENDIF. ENDFORM. ************************************************************************ FORM BDC_DYNPRO USING VALUE(P_PROGRAM) TYPE C VALUE(P_DYNPRO) TYPE C. CLEAR IT_BDC. MOVE: P_PROGRAM TO IT_BDC-PROGRAM, P_DYNPRO TO IT_BDC-DYNPRO, C_X TO IT_BDC-DYNBEGIN. APPEND IT_BDC. ENDFORM. ************************************************************************ FORM BDC_FIELD USING VALUE(P_FIELD) TYPE C VALUE(P_VALUE). CLEAR IT_BDC. MOVE P_FIELD TO IT_BDC-FNAM. WRITE P_VALUE TO IT_BDC-FVAL LEFT-JUSTIFIED. APPEND IT_BDC. ENDFORM. ************************************************************************ FORM BDC_OKCODE USING VALUE(P_CODE) TYPE C. CLEAR IT_BDC. MOVE: 'BDC_OKCODE' TO IT_BDC-FNAM, P_CODE TO IT_BDC-FVAL. APPEND IT_BDC. ENDFORM. ************************************************************************ FORM OPEN_BDC. CALL FUNCTION 'BDC_OPEN_GROUP' EXPORTING * CLIENT = SY-MANDT * DEST = FILLER8 GROUP = P_GROUP * HOLDDATE = FILLER8 * KEEP = FILLER1 USER = SY-UNAME * RECORD = FILLER1 * IMPORTING * QID = 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. CASE SY-SUBRC. * =to be customized=: text-600 = 'Error Creating BDC group:' * text-6nn = Concrete Error Description WHEN 1. CONCATENATE TEXT-600 TEXT-601 INTO W_MSG SEPARATED BY SPACE. WHEN 2. CONCATENATE TEXT-600 TEXT-602 INTO W_MSG SEPARATED BY SPACE. WHEN 3. CONCATENATE TEXT-600 TEXT-603 INTO W_MSG SEPARATED BY SPACE. WHEN 4. CONCATENATE TEXT-600 TEXT-604 INTO W_MSG SEPARATED BY SPACE. WHEN 5. CONCATENATE TEXT-600 TEXT-605 INTO W_MSG SEPARATED BY SPACE. WHEN 6. CONCATENATE TEXT-600 TEXT-606 INTO W_MSG SEPARATED BY SPACE. WHEN 7. CONCATENATE TEXT-600 TEXT-607 INTO W_MSG SEPARATED BY SPACE. WHEN 8. CONCATENATE TEXT-600 TEXT-608 INTO W_MSG SEPARATED BY SPACE. WHEN 9. CONCATENATE TEXT-600 TEXT-609 INTO W_MSG SEPARATED BY SPACE. WHEN 10.CONCATENATE TEXT-600 TEXT-610 INTO W_MSG SEPARATED BY SPACE. WHEN 11.CONCATENATE TEXT-600 TEXT-611 INTO W_MSG SEPARATED BY SPACE. ENDCASE. MESSAGE E102(YB) WITH W_MSG. ENDIF. ENDFORM. ************************************************************************ FORM CLOSE_BDC. CALL FUNCTION 'BDC_CLOSE_GROUP' EXCEPTIONS NOT_OPEN = 1 QUEUE_ERROR = 2 OTHERS = 3. IF SY-SUBRC <> 0. CASE SY-SUBRC. * =to be customized=: text-700 = 'Error Closing BDC group:' * text-70n = Concrete Error Description WHEN 1. CONCATENATE TEXT-700 TEXT-701 INTO W_MSG SEPARATED BY SPACE. WHEN 2. CONCATENATE TEXT-700 TEXT-702 INTO W_MSG SEPARATED BY SPACE. WHEN 3. CONCATENATE TEXT-700 TEXT-703 INTO W_MSG SEPARATED BY SPACE. ENDCASE. MESSAGE E102(YB) WITH W_MSG. ENDIF. ENDFORM. ************************************************************************