How to Upload Long Text into SAP Using Excel Sheet and SAVE_TEXT Function Module
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了How to Upload Long Text into SAP Using Excel Sheet and SAVE_TEXT Function Module相关的知识,希望对你有一定的参考价值。
Created by
Reference Link:
Note 933420 - ALSM_EXCEL_TO_INTERNAL_TABLE
http://scn.sap.com/docs/DOC-45423
Error rendering macro ‘code‘: Invalid value specified for parameter ‘lang‘TYPES: BEGIN OF TY_ITAB , MATNR(18) TYPE C, LMAKTX(2112) TYPE C, ROW TYPE I, TSIZE TYPE I, END OF TY_ITAB. * Data Declarations - Internal Tables DATA: I_TAB TYPE STANDARD TABLE OF TY_ITAB INITIAL SIZE 0, WA TYPE TY_ITAB , IT_EXLOAD LIKE ZALSMEX_TABLINE OCCURS 0 WITH HEADER LINE. DATA: IT_LINES LIKE STANDARD TABLE OF TLINE WITH HEADER LINE, IT_TEXT_HEADER LIKE STANDARD TABLE OF THEAD WITH HEADER LINE, P_ERROR TYPE SY-LISEL , LEN TYPE I . * Selection Screen SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-002. PARAMETERS:PFILE TYPE RLGRAP-FILENAME OBLIGATORY, W_BEGIN TYPE I OBLIGATORY, W_END TYPE I OBLIGATORY. SELECTION-SCREEN END OF BLOCK B1. AT SELECTION-SCREEN. IF PFILE IS INITIAL. MESSAGE S368(00) WITH ‘Please input filename‘. STOP. ENDIF. START-OF-SELECTION. REFRESH:I_TAB. PERFORM EXCEL_DATA_INT_TABLE. PERFORM EXCEL_TO_INT. PERFORM CONTOL_PARAMETER. AT SELECTION-SCREEN ON VALUE-REQUEST FOR PFILE. PERFORM F4_FILENAME. *&---------------------------------------------------------------------* *& Form F4_FILENAME *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM F4_FILENAME . CALL FUNCTION ‘F4_FILENAME‘ EXPORTING PROGRAM_NAME = SYST-CPROG DYNPRO_NUMBER = SYST-DYNNR * FIELD_NAME = ‘ ‘ IMPORTING FILE_NAME = PFILE . ENDFORM. " F4_FILENAME *&---------------------------------------------------------------------* *& Form EXCEL_DATA_INT_TABLE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM EXCEL_DATA_INT_TABLE . CALL FUNCTION ‘YALSM_EXCEL_TO_INTERNAL_TABLE‘ EXPORTING FILENAME = PFILE I_BEGIN_COL = ‘0001‘ I_BEGIN_ROW = W_BEGIN I_END_COL = ‘0100‘ I_END_ROW = W_END "65536 TABLES INTERN = IT_EXLOAD. ENDFORM. " EXCEL_DATA_INT_TABLE *&---------------------------------------------------------------------* *& Form EXCEL_TO_INT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM EXCEL_TO_INT . LOOP AT IT_EXLOAD . CASE IT_EXLOAD-COL1. WHEN ‘0001‘. WA-MATNR = IT_EXLOAD-VALUE. WHEN ‘0002‘. WA-LMAKTX = IT_EXLOAD-VALUE. ENDCASE. AT END OF ROW1. WA-TSIZE = STRLEN( WA-LMAKTX ) . WA-ROW = IT_EXLOAD-ROW1 . APPEND WA TO I_TAB. CLEAR WA . ENDAT. ENDLOOP. ENDFORM. " EXCEL_TO_INT *&---------------------------------------------------------------------* *& Form CONTOL_PARAMETER *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM CONTOL_PARAMETER . DATA OFF TYPE I VALUE ‘1‘. LOOP AT I_TAB INTO WA. * * Create Header IT_TEXT_HEADER-TDID = ‘BEST‘. IT_TEXT_HEADER-TDSPRAS = SY-LANGU . IT_TEXT_HEADER-TDNAME = WA-MATNR. IT_TEXT_HEADER-TDOBJECT = ‘MATERIAL‘. MOVE WA-TSIZE TO LEN . LEN = LEN / 53 + 1. DO LEN TIMES . MOVE ‘*‘ TO IT_LINES-TDFORMAT. MOVE WA-LMAKTX+OFF(53) TO IT_LINES-TDLINE. SHIFT IT_LINES-TDLINE LEFT DELETING LEADING ‘ ‘. OFF = OFF + 53 . APPEND IT_LINES. CLEAR IT_LINES . ENDDO. AT END OF ROW. CALL FUNCTION ‘SAVE_TEXT‘ EXPORTING CLIENT = SY-MANDT HEADER = IT_TEXT_HEADER INSERT = ‘ ‘ SAVEMODE_DIRECT = ‘X‘ TABLES LINES = IT_LINES EXCEPTIONS ID = 1 LANGUAGE = 2 NAME = 3 OBJECT = 4 OTHERS = 5. * Check the Return Code IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 INTO P_ERROR. EXIT. ENDIF. CLEAR: WA ,LEN , OFF. REFRESH IT_LINES . ENDAT. ENDLOOP. ENDFORM. " CONTOL_PARAMETER
Upload Excel File Format:
Output In SAP Using MM03 T-code