根据剪贴板获取剪贴板的信息
REPORT YTEST_BARRY. TYPES:BEGIN OF TY_OUT, MATNR TYPE MAKT-MATNR, MAKTX TYPE MAKT-MAKTX, MENGE TYPE VBAP-KWMENG , END OF TY_OUT. DATA IT_TAB TYPE TABLE OF TY_OUT . DATA WA_TAB TYPE TY_OUT . START-OF-SELECTION . PERFORM CLIPTOITAB TABLES IT_TAB. *----------------------------------------------------------------------* * 剪贴板数据到内表,根据制表符分割 * 如果有数据类型错误,比如内表是数值型但是剪贴板里面是字母, * 则弹出W消息,并忽略这条数据 *----------------------------------------------------------------------* FORM CLIPTOITAB TABLES ITAB. DATA: HTAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB . DATA: LT_CLIP TYPE TABLE OF CHAR2048 WITH HEADER LINE , LT_FLD TYPE TABLE OF CHAR2048 WITH HEADER LINE. DATA: CXROOT TYPE REF TO CX_ROOT, EXCMSG TYPE STRING. FIELD-SYMBOLS:<FS_FLD> , <FS_TAB> . ASSIGN ITAB TO <FS_TAB> . CALL METHOD CL_GUI_FRONTEND_SERVICES=>CLIPBOARD_IMPORT IMPORTING DATA = LT_CLIP[] EXCEPTIONS CNTL_ERROR = 1 ERROR_NO_GUI = 2 NOT_SUPPORTED_BY_GUI = 3 OTHERS = 4. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 . ELSE. CALL METHOD CL_GUI_CFW=>FLUSH . LOOP AT LT_CLIP. CLEAR LT_FLD[]. SPLIT LT_CLIP AT HTAB INTO TABLE LT_FLD. LOOP AT LT_FLD. ASSIGN COMPONENT SY-TABIX OF STRUCTURE <FS_TAB> TO <FS_FLD>. CHECK SY-SUBRC = 0.
TRY . LT_FLD = TRANSLATE( VAL = LT_FLD FROM = |\r| TO = '' ). LT_FLD = TRANSLATE( VAL = LT_FLD FROM = |\n| TO = '' ). LT_FLD = TRANSLATE( VAL = LT_FLD FROM = |"| TO = '' ). LT_FLD = TRANSLATE( VAL = LT_FLD FROM = |D| TO = '' ). "测试
****以上处理字符中多余数据 空格 换行等 <FS_FLD> = LT_FLD.
****以下获取异常数据 CATCH CX_ROOT INTO CXROOT. EXCMSG = CXROOT->GET_TEXT( ). ENDTRY. ENDLOOP. APPEND ITAB . CLEAR ITAB. ENDLOOP. IF EXCMSG IS NOT INITIAL. MESSAGE W000(OO) WITH '数据转换有错误发生,已经忽略'. ENDIF. ENDIF. ENDFORM.