问题描述
在做销售开票的功能时用的BDC,业务在测试的时候总是报日期格式不一致的错误,而我自己测的时候却没啥问题,调试的时候发现是我和业务的时间格式不一致(我是YYYYMMDD,他是MMDDYYYY)。
解决方案
用函数CONVERT_DATE_TO_EXTERNAL将ABAP8位的日期改为登录用户的日期格式,在进行参数赋值即可
FORM frm_vf01_create USING p_ls_alv TYPE ty_alv .
DATA: bdcdata TYPE TABLE OF bdcdata,
ctumode LIKE ctu_params-dismode,
gt_messtab TYPE TABLE OF bdcmsgcoll WITH HEADER LINE,
lv_msg TYPE char200,
lv_msg2 TYPE char200.
DATA : lv_date TYPE char10 .
REFRESH:bdcdata[].
PERFORM bdc_dynpro USING 'SAPMV60A' '0102' CHANGING bdcdata .
PERFORM bdc_field USING 'BDC_CURSOR' 'KOMFK-VBELN(01)' CHANGING bdcdata.
PERFORM bdc_field USING 'BDC_OKCODE' '/00' CHANGING bdcdata.
PERFORM bdc_field USING 'KOMFK-VBELN(01)' p_ls_alv-vbeln CHANGING bdcdata.
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
date_internal = p_ls_alv-wadat_ist2
IMPORTING
date_external = lv_date
EXCEPTIONS
date_internal_is_invalid = 1
OTHERS = 2.
PERFORM bdc_field USING 'RV60A-FKDAT' lv_date CHANGING bdcdata.
PERFORM bdc_dynpro USING 'SAPMV60A' '0104' CHANGING bdcdata.
PERFORM bdc_field USING 'BDC_CURSOR' 'VBRK-FKART' CHANGING bdcdata.
PERFORM bdc_field USING 'BDC_OKCODE' '=SICH' CHANGING bdcdata.
ctumode = 'N'. "N就是一步完成,A前台运行模式 是分步enter完成 E 显示错误模式
REFRESH gt_messtab[].
CALL TRANSACTION 'VF01' USING bdcdata
MODE ctumode
UPDATE 'S'"S同步 A异步
MESSAGES INTO gt_messtab.
CLEAR:gt_messtab.
LOOP AT gt_messtab.
CLEAR:lv_msg2.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = gt_messtab-msgid
msgnr = gt_messtab-msgnr
msgv1 = gt_messtab-msgv1
msgv2 = gt_messtab-msgv2
msgv3 = gt_messtab-msgv3
msgv4 = gt_messtab-msgv4
IMPORTING
message_text_output = lv_msg.
CONCATENATE lv_msg2 lv_msg INTO lv_msg2.
ENDLOOP.
READ TABLE gt_messtab INTO DATA(ls_messtab) WITH KEY msgid = 'VF' msgnr = '311' .
IF sy-subrc = 0 .
LOOP AT gt_alv ASSIGNING FIELD-SYMBOL(<fs_alv>) WHERE vbeln = p_ls_alv-vbeln .
<fs_alv>-log = '销售发票创建成功' .
<fs_alv>-icon = icon_led_green .
<fs_alv>-vbeln_vf = ls_messtab-msgv1 .
<fs_alv>-posnr_vf = <fs_alv>-posnr .
ENDLOOP .
"更新ZSDT013销售发票
UPDATE zsdt013 SET vbeln_vf = ls_messtab-msgv1 WHERE vbeln_vl = p_ls_alv-vbeln .
COMMIT WORK .
ELSE .
LOOP AT gt_alv ASSIGNING <fs_alv> WHERE vbeln = p_ls_alv-vbeln .
<fs_alv>-log = '销售发票创建失败:' && lv_msg2 .
<fs_alv>-icon = icon_led_red .
ENDLOOP.
ENDIF .
CLEAR : bdcdata ,ctumode ,gt_messtab ,lv_msg .
ENDFORM.