*千分位 DATA : LV_STR TYPE STRING, LV_CURRC TYPE STRING, LV_TMP1 TYPE STRING, LV_TMP2 TYPE STRING, LV_LEN TYPE I, LV_LEN1 TYPE I, LV_LEN2 TYPE I, LV_LEN3 TYPE I, LV_LEN4 TYPE I. DATA: LV_CURR TYPE BAPICURR-BAPICURR, LV_ANBTR TYPE STRING. CLEAR:LV_STR,LV_CURRC,LV_TMP1,LV_TMP2,LV_LEN,LV_LEN1,LV_LEN2,LV_LEN3,LV_LEN4. CLEAR LV_ANBTR. LV_ANBTR = GS_OLE-ANBTR. CONDENSE GS_OLE-ANBTR NO-GAPS. LV_STR = GS_OLE-ANBTR. *统一转换给外部数据,保留精度 CALL FUNCTION 'BAPI_CURRENCY_CONV_TO_EXTERNAL' EXPORTING CURRENCY = '' AMOUNT_INTERNAL = LV_STR IMPORTING AMOUNT_EXTERNAL = LV_CURR. CLEAR LV_CURRC. LV_CURRC = LV_CURR. SPLIT LV_CURRC AT '.' INTO LV_TMP1 LV_TMP2. CONDENSE:LV_TMP1,LV_TMP2. LV_LEN = STRLEN( LV_TMP1 ). LV_LEN1 = LV_LEN MOD 3. LV_LEN2 = LV_LEN DIV 3. *根据整除保留的整数进行循环,无偏移时最后一次不用循环默认为0 DO LV_LEN2 TIMES. *小于1和无偏移时,最后一次的逗号不用加 IF LV_LEN = 3 OR ( LV_LEN1 = 0 AND SY-INDEX = LV_LEN2 ). EXIT. ENDIF. *偏移按照第一次进行偏移 IF LV_LEN1 <> 0. LV_LEN3 = LV_LEN1 + SY-INDEX - 4 + 3 * SY-INDEX . ENDIF. *无偏移3的倍数+当前次数-1,1为第一次偏移 IF LV_LEN1 = 0. LV_LEN3 = 3 * SY-INDEX + SY-INDEX - 1. ENDIF. *从中间插入 LV_LEN4 = STRLEN( LV_TMP1 ) - LV_LEN3. CONCATENATE LV_TMP1+0(LV_LEN3) ',' LV_TMP1+LV_LEN3(LV_LEN4) INTO LV_TMP1. ENDDO. *保留2位小数 LV_CURRC = LV_TMP1 && '.' && LV_TMP2+0(2). CONDENSE LV_CURRC. CLEAR GS_OLE-ANBTR. GS_OLE-ANBTR = LV_CURRC. *负号提前 CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT' CHANGING VALUE = LV_ANBTR. IF LV_ANBTR+0(1) = '-'. GS_OLE-ANBTR = '-' && GS_OLE-ANBTR. ENDIF.
标签:CURRC,ANBTR,负号,TMP1,千分,LV,字符串,TYPE,OLE From: https://www.cnblogs.com/Anyohh233/p/18082624