REPORT ZVVSC001 LINE-SIZE 80 LINE-COUNT 66 NO STANDARD PAGE HEADING. ************************************************************************ * Description : Upload data from tabs delimited text file * and perform =something= automatically * with 'CALL TRANSACTION USING...' technique. * All the lines with '=something=' or '=to be customized=' * words are empty template only and need to be filled with * real data. Transactions XX01, XX02, XX03 are templates * as well and should be changed with real ones. * For demo reasons the LIBS transaction is used for call * (LIBS is SAP guide for Lists Design). * Inputs : PC Input File Name * Outputs : '=something= statistics & errors' report * : (error input data lines are printed, * : for successfully processed - total count only) * Error/Return Codes : None * External References: WS_FILENAME_GET, WS_UPLOAD, * : MESSAGE_PREPARE, * : transactions LIBS, XX01, XX02, XX03, ... . ************************************************************************ ********* TABLES ******************************************************* ********* CONSTANS ***************************************************** CONSTANTS: C_MODE(1) TYPE C VALUE 'N', "Call Transaction display mode * A - display all; * E - display only error; * N - No display. C_UPDATE(1) TYPE C VALUE 'S', "Call Transaction update type * S - continue processing when update is completed (synchronous); * A - continue procwssing immediately; * L - local update. C_X(1) TYPE C VALUE 'X', C_Q(1) TYPE C VALUE '?'. ********* DATA: VARIABLES ********************************************** DATA: W_MSG(50) TYPE C, "Message string by Input File Proc. W_N LIKE SY-TABIX, "Counter W_N1 LIKE SY-TABIX, "Counter of selected W_NS LIKE SY-TABIX, "Counter of successfully processed W_MSGTXT(273) TYPE C. "Formatted message text ********* DATA: INTERNAL TABLES, RANGES ******************************** *-------- BDC table ---------------------------------------------------- DATA: IT_BDC LIKE BDCDATA OCCURS 0 WITH HEADER LINE. *-------- BDC messages tables ------------------------------------------ DATA: IT_BDCMSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE, BEGIN OF IT_BDCMSGLIN OCCURS 0, LINE LIKE SY-TABIX, "Input file # MSG LIKE BDCMSGCOLL, "All BDC messages for the line # END OF IT_BDCMSGLIN. *-------- Input file --------------------------------------------------- DATA: BEGIN OF IT_FILE OCCURS 0, * =something= data field(s), "Input file fields LINE LIKE SY-TABIX, "Input file line # "(not present in the Input File) END OF IT_FILE. ********* FIELD GROUPS ************************************************* ********* FIELD SYMBOLS ************************************************ ********* SELECT-OPTIONS AND PARAMETERS ******************************** PARAMETERS: P_FNAME LIKE RLGRAP-FILENAME OBLIGATORY. "filename prefix *************** * 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 PROCESS_ERRORS. 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. ENDFORM. ************************************************************************ FORM PRINT_FOOTER. * =to be customized= WRITE /'*** End Of Report ***'. ENDFORM. ************************************************************************ FORM PRINT_ERROR_HEADER. FORMAT INTENSIFIED ON COLOR COL_BACKGROUND. * =to be customized= WRITE: / " =something= 'columns headers'(nnn), 'Line #'(001). ULINE. FORMAT INTENSIFIED OFF. ENDFORM. ************************************************************************ FORM PRINT_INPUT_LINE. * =to be customized= WRITE: / "=something= field(s) under text-=something= " (under columns headers) color col_key, IT_FILE-LINE UNDER 'Line #'(001) COLOR COL_KEY. ENDFORM. ************************************************************************ FORM PRINT_STATISTIC. WRITE: / 'Read Lines'(002) INTENSIFIED ON, AT 40 W_N INTENSIFIED OFF. SKIP 1. WRITE: / 'Selected Lines'(004) INTENSIFIED ON, AT 40 W_N1 INTENSIFIED OFF. SKIP 1. WRITE: / 'Processed Lines'(003) INTENSIFIED ON, AT 40 W_NS INTENSIFIED OFF. SKIP 1. ENDFORM. ************************************************************************ FORM PRINT_ERROR_ITEM. WRITE : / IT_BDCMSGLIN-MSG-TCODE, AT 6 IT_BDCMSGLIN-MSG-DYNAME, AT 15 IT_BDCMSGLIN-MSG-DYNUMB, AT 20 IT_BDCMSGLIN-MSG-MSGTYP, AT 21 IT_BDCMSGLIN-MSG-MSGNR, AT 24 '(', AT 25 IT_BDCMSGLIN-MSG-MSGID, AT 27 ')', AT 29 IT_BDCMSGLIN-MSG-FLDNAME. CALL FUNCTION 'MESSAGE_PREPARE' EXPORTING LANGUAGE = IT_BDCMSGLIN-MSG-MSGSPRA MSG_ID = IT_BDCMSGLIN-MSG-MSGID MSG_NO = IT_BDCMSGLIN-MSG-MSGNR MSG_VAR1 = IT_BDCMSGLIN-MSG-MSGV1 MSG_VAR2 = IT_BDCMSGLIN-MSG-MSGV2 MSG_VAR3 = IT_BDCMSGLIN-MSG-MSGV3 MSG_VAR4 = IT_BDCMSGLIN-MSG-MSGV4 IMPORTING MSG_TEXT = W_MSGTXT EXCEPTIONS FUNCTION_NOT_COMPLETED = 1 MESSAGE_NOT_FOUND = 2 OTHERS = 3. CASE SY-SUBRC. WHEN 0. WRITE: / W_MSGTXT. WHEN 1. WRITE: / 'Error Processing Message'(015). WHEN 2. WRITE: / 'Unknown Error Message'(016). WHEN 3. WRITE: / 'Unknown Error'(017). ENDCASE. ENDFORM. ************************************************************************ FORM VALIDATE_FILE. * additional validation for =something=, if needed LOOP AT IT_FILE. * CHECK ..... DELETE IT_FILE. ENDLOOP. DESCRIBE TABLE IT_FILE LINES W_N1. W_NS = W_N1. ENDFORM. ************************************************************************ FORM PROCESS_FILE. LOOP AT IT_FILE. PERFORM PROCESS_LINE. ENDLOOP. ENDFORM. ************************************************************************ FORM NUMERATE_LINES. DESCRIBE TABLE IT_FILE LINES W_N. LOOP AT IT_FILE. IT_FILE-LINE = SY-TABIX. MODIFY IT_FILE INDEX SY-TABIX. ENDLOOP. ENDFORM. ************************************************************************ FORM PROCESS_ERRORS. IF NOT IT_BDCMSGLIN IS INITIAL. PERFORM PRINT_ERROR_HEADER. LOOP AT IT_BDCMSGLIN. AT NEW LINE. READ TABLE IT_FILE WITH KEY LINE = IT_BDCMSGLIN-LINE BINARY SEARCH. PERFORM PRINT_INPUT_LINE. ENDAT. PERFORM PRINT_ERROR_ITEM. ENDLOOP. ENDIF. 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'(005). ENDIF. ENDFORM. ************************************************************************ FORM PROCESS_LINE. CLEAR IT_BDC[]. PERFORM BDC_XX01_PREPARE. * perform call_transaction using 'XX01'. PERFORM CALL_TRANSACTION USING 'LIBS'. IF SY-SUBRC <> 0. PERFORM COLLECT_ERROR_MESSAGES. ELSE. CLEAR IT_BDC[]. PERFORM BDC_XX02_PREPARE. * perform call_transaction using 'XX02'. PERFORM CALL_TRANSACTION USING 'LIBS'. IF SY-SUBRC <> 0. PERFORM COLLECT_ERROR_MESSAGES. ELSE. CLEAR IT_BDC[]. PERFORM BDC_XX03_PREPARE. * perform call_transaction using 'XX03'. PERFORM CALL_TRANSACTION USING 'LIBS'. IF SY-SUBRC <> 0. PERFORM COLLECT_ERROR_MESSAGES. ELSE. * end so on ENDIF. ENDIF. ENDIF. ENDFORM. ************************************************************************ FORM BDC_XX01_PREPARE. * 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 ENDFORM. ************************************************************************ FORM BDC_XX02_PREPARE. * as for bdc_xx01_prepare ENDFORM. ************************************************************************ FORM BDC_XX03_PREPARE. * as for bdc_xx01_prepare ENDFORM. ************************************************************************ FORM COLLECT_ERROR_MESSAGES. LOOP AT IT_BDCMSG. CLEAR IT_BDCMSGLIN. IT_BDCMSGLIN-LINE = IT_FILE-LINE. IT_BDCMSGLIN-MSG = IT_BDCMSG. APPEND IT_BDCMSGLIN. ENDLOOP. SUBTRACT 1 FROM W_NS. ENDFORM. ************************************************************************ FORM CALL_TRANSACTION USING VALUE(P_TCODE) TYPE C. CLEAR: IT_BDCMSG[], IT_BDCMSG. CALL TRANSACTION P_TCODE USING IT_BDC MODE C_MODE UPDATE C_UPDATE MESSAGES INTO IT_BDCMSG. 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. ************************************************************************