码迷,mamicode.com
首页 > 其他好文 > 详细

SAP 金税接口代码 供参考

时间:2015-11-26 10:55:59      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:

程序可以通过抓取 客户 开票信息等 下载文本 导出

 

需要事先创建好几个structure 

zc0000sdt0016,
zc0000sdt0017

 

REPORT  zc0000sdr0016 NO STANDARD PAGE HEADING
                     LINE-COUNT 58
                     LINE-SIZE 170.
TABLES:vbrk,vbrp,t001.
*----------------------------------------------------------------------*
* type define
*----------------------------------------------------------------------*
TYPES: BEGIN OF ty_vbrk,
         vbeln  TYPE vbrk-vbeln,"invoice number
         fkart  TYPE vbrk-fkart, "ERPInvoiceType
         waerk  TYPE vbrk-waerk, "Currency
         vkorg  TYPE vbrk-vkorg, "Sales Organization
         vtweg  TYPE vbrk-vtweg, "Distribution Channel
         knumv  TYPE vbrk-knumv,
         fkdat  TYPE vbrk-fkdat, "Invoice data
         gjahr  TYPE vbrk-gjahr, "Year
         bukrs  TYPE vbrk-bukrs,
         taxk1  TYPE vbrk-taxk1, "Invoice type(eg:0 - Expore Invoice, 1 - VAT Inovice , 2 - Credit Inovice)BillingType
         kunag  TYPE vbrk-kunag, "Customer code
         sfakn  TYPE vbrk-sfakn, "Credit Notes
         fksto  TYPE vbrk-fksto, "Cancel flag
          del   TYPE c,
       END OF ty_vbrk,
       BEGIN OF ty_vbrp,
         vbeln  TYPE vbrp-vbeln, "Invoice number
         posnr  TYPE vbrp-posnr, "Item number
         fkimg  TYPE vbrp-fkimg, "Quantity
         vrkme  TYPE vbrp-vrkme, "Unit
         netwr  TYPE vbrp-netwr, "Sum
         vbelv  TYPE vbrp-vbelv, "First Document
         aubel  TYPE vbrp-aubel, "Sales Document
         matnr  TYPE vbrp-matnr, "Material Number
         arktx  TYPE vbrp-arktx, "Product chinese name
         ernam  TYPE vbrp-ernam, "Person code
         mwsbp  TYPE vbrp-mwsbp, "Tax
       END OF ty_vbrp,
       BEGIN OF ty_out,
          txt TYPE string,
       END OF ty_out,
        BEGIN OF ty_errlog,  "Linda 20141120 add
         str(100) TYPE c,    "Linda 20141120 add
        END OF ty_errlog.   "Linda 20141120 add
*----------------------------------------------------------------------*
*  Internal Tables define
*----------------------------------------------------------------------*
DATA: it_blitems       TYPE STANDARD TABLE OF zc0000sdt0016,"is struction
      it_tbillno       TYPE STANDARD TABLE OF zc0000sdt0017,"is table,
      it_kunnr         TYPE jito_kunnr_range_tt,
      it_vbeln         TYPE jit_vbeln_vl_range_tt,
      it_out           TYPE STANDARD TABLE OF ty_out,"use for output
      it_errlog        TYPE STANDARD TABLE OF ty_errlog,  "Linda 20141120 add
*----------------------------------------------------------------------*
*  Workarea define
*----------------------------------------------------------------------*
      iw_vbrk          TYPE ty_vbrk,
      iw_tbillno       TYPE zc0000sdt0017,"is table
      iw_blitems       TYPE zc0000sdt0016,"is struction
      iw_kunnr         TYPE jito_kunnr_range,
      iw_vbeln         TYPE jit_vbeln_vl_range,
      iw_out           TYPE ty_out,
      iw_errlog        TYPE ty_errlog,  "Linda 20141120 add
*----------------------------------------------------------------------*
*  Variables define
*----------------------------------------------------------------------*
      w_time           TYPE char6,           "run time
      w_path           TYPE rlgrap-filename, "path
      w_filename       TYPE rlgrap-filename, "file name
      w_data1          TYPE i,
      w_data2          TYPE i,
      w_filter         TYPE string." VALUE ‘Text Files(*.txt)|*.txt‘.Linda 20141024
*----------------------------------------------------------------------*
* Constants define
*----------------------------------------------------------------------*
CONSTANTS: cos_vl        TYPE char1  VALUE \‘,
           cos_open      TYPE char4  VALUE OPEN,
           cos_close     TYPE char5  VALUE CLOSE,
           cos_transfer  TYPE char8  VALUE TRANSFER,
           cos_comma     TYPE char1  VALUE ,.          "Linda 20141120 add

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-003.
PARAMETERS:"p_batch   TYPE  char20,                      "batch   1
           p_bukrs   TYPE  vbrk-bukrs OBLIGATORY.        "company
SELECT-OPTIONS:s_fkdat    FOR  vbrk-fkdat NO-EXTENSION.  "Billing date for billing index and printout  2
SELECTION-SCREEN BEGIN OF LINE .
SELECTION-SCREEN COMMENT 1(31) text-009 .                "enter data range
PARAMETER p_data1  TYPE char3.
SELECTION-SCREEN COMMENT 40(4) text-010.
PARAMETER p_data2  TYPE char3.
SELECTION-SCREEN COMMENT 70(79) text-008.
SELECTION-SCREEN END OF LINE.
SELECT-OPTIONS:
           s_vbeln     FOR  vbrk-vbeln,               "Billing Document 3
           s_kunag     FOR  vbrk-kunag,               "Payer  4
           s_matnr     FOR  vbrp-matnr NO-EXTENSION,  "Material Number 5
           s_aubel     FOR  vbrp-aubel NO-EXTENSION,  "Sales Document 6
           s_vkorg     FOR  vbrk-vkorg NO-EXTENSION OBLIGATORY.
PARAMETERS:p_gjahr     TYPE  vbrk-gjahr.              "Fiscal Year

PARAMETERS:p_nonrep    TYPE c AS CHECKBOX. "compare or not
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETER p_check3 RADIOBUTTON GROUP rad DEFAULT X USER-COMMAND rad.
SELECTION-SCREEN COMMENT 4(20) text-c03 FOR FIELD p_check3."TXT format
PARAMETER p_check4 RADIOBUTTON GROUP rad.
SELECTION-SCREEN COMMENT 28(30) text-c04 FOR FIELD p_check4."CSV format
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-002.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETER p_check2 TYPE c RADIOBUTTON GROUP rads DEFAULT X USER-COMMAND rad2.
SELECTION-SCREEN COMMENT 4(20) text-c02 FOR FIELD p_check2."output to server
SELECTION-SCREEN END OF LINE.
PARAMETERS: p_path2(1024) TYPE c LOWER CASE
                      VISIBLE LENGTH 200.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETER p_check1 RADIOBUTTON GROUP rads.
SELECTION-SCREEN COMMENT 4(20) text-c01 FOR FIELD p_check1."
SELECTION-SCREEN END OF LINE.
PARAMETERS: p_path(1024) TYPE c LOWER CASE
                      VISIBLE LENGTH 200.
SELECTION-SCREEN END OF BLOCK b3.

*----------------------------------------------------------------------*
* INITIALIZATION
*----------------------------------------------------------------------*
INITIALIZATION.
* init

*----------------------------------------------------------------------*
* AT SELECTION-SCREEN ON VALUE-REQUEST
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
  PERFORM frm_save_file CHANGING p_path.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN OUTPUT
*----------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
  IF p_data1 <> space AND p_data2 <> space. "Linda 20141120 add
    REFRESH:s_fkdat.  "Linda 20141024 add
  ENDIF.                  "Linda 20141120 add
  IF p_data1 <> space AND p_data2 <> space.
    PERFORM frm_chang_data USING p_data1
                           CHANGING s_fkdat-low.

    PERFORM frm_chang_data USING p_data2
                          CHANGING s_fkdat-high.
    APPEND s_fkdat.

  ENDIF.

*----------------------------------------------------------------------*
* AT SELECTION-SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
*  WHEN ONLI.
    PERFORM frm_init.
    IF p_path = space AND p_check1 = X.
      SET CURSOR FIELD P_PATH.
      MESSAGE e001(00) WITH Local path can not be space(018).
    ENDIF.
    IF p_path2 = space AND p_check2 = X.
      SET CURSOR FIELD P_PATH2.
      MESSAGE e001(00) WITH Server path can not be space(017).
    ENDIF.
  CASE sy-ucomm.
  WHEN RAD OR RAD2.
*   lw_filter = Text Files(*.txt)|*.txt|Csv Files(*.csv)|*.csv|Excel Files(*.xls)|*.xls|All Files(*.*)|*.*|."Text Files(*.txt)|*.txt|. "All Files(*.*)|*.*|
    IF p_check3 = X.
      w_filter = Text Files(*.txt)|*.txt(020).
    ELSEIF p_check4 = X.
      w_filter = Csv Files(*.csv)|*.csv(021).
    ENDIF.
    CLEAR: p_path,
           p_path2.
 WHEN OTHERS.
   ENDCASE.
  TRY.
      w_data1 = p_data1.
      w_data2 = p_data2.
    CATCH cx_root.
      SET CURSOR FIELD P_DATA1.
      MESSAGE e001(00) WITH Data range must be number(014).
  ENDTRY.
  IF w_data1 > w_data2.
    SET CURSOR FIELD P_DATA1.
    MESSAGE e001(00) WITH Data range must from small to big(015).
  ENDIF.
*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
  w_time = sy-uzeit.
  IF s_fkdat[] IS INITIAL AND p_data1 <> space AND p_data2 <> space.
    PERFORM frm_chang_data USING p_data1
                           CHANGING s_fkdat-low.

    PERFORM frm_chang_data USING p_data2
                          CHANGING s_fkdat-high.
    s_fkdat-sign = I.
    s_fkdat-option = BT.
    APPEND s_fkdat.
  ELSEIF s_fkdat[] IS INITIAL AND p_data1 = space AND p_data2 = space.
      MESSAGE s001(00) WITH text-022 text-025 DISPLAY LIKE E.
      RETURN.
      LEAVE TO LIST-PROCESSING.
  ENDIF.
  LOOP AT s_kunag.
    iw_kunnr-sign = s_kunag-sign.
    iw_kunnr-option = s_kunag-option.
    iw_kunnr-low = s_kunag-low.
    iw_kunnr-high = s_kunag-high.

    APPEND iw_kunnr TO it_kunnr.
  ENDLOOP.
  LOOP AT s_vbeln.
    iw_vbeln-sign = s_vbeln-sign.
    iw_vbeln-option = s_vbeln-option.
    iw_vbeln-low = s_vbeln-low.
    iw_vbeln-high = s_vbeln-high.

    APPEND iw_vbeln TO it_vbeln.
  ENDLOOP.

  CHECK it_errlog IS INITIAL.
  CALL FUNCTION ZBPI_FW_INVOICE_MAHLE_NEW
    EXPORTING
     fkdat_fr                = s_fkdat-low
     vbeln_fr                = s_vbeln-low
     kunnr_fr                = s_kunag-low
     matnr_fr                = s_matnr-low
     fkdat_to                = s_fkdat-high
     vbeln_to                = s_vbeln-high
     kunnr_to                = s_kunag-high
     matnr_to                = s_matnr-high
     aubel_fr                = s_aubel-low
     aubel_to                = s_aubel-high
     vkorg_fr                = s_vkorg-low
     vkorg_to                = s_vkorg-high
*     disc_cond_type    = p_disc
*     unit_cond_type    = p_unit
*     tax_cond_type     = p_tax
     bukrs                   = p_bukrs
     nonrepeat               = p_nonrep
     gjahr                   = p_gjahr
    TABLES
     zfw_billing_items       = it_blitems
     zfw_billingno           = it_tbillno
     zfw_kunnr               = it_kunnr
     zfw_vbeln               = it_vbeln
   EXCEPTIONS
     no_data                 = 1
     lock_errord             = 2
     insert_error            = 3.
  CASE sy-subrc.
   WHEN 1.
     iw_errlog-str = No matching data is found.(012).
       APPEND iw_errlog TO it_errlog.
   WHEN 2.
     iw_errlog-str = Lock table error.(023).
       APPEND iw_errlog TO it_errlog.
   WHEN 3.
     iw_errlog-str = Insert table error.(026).
       APPEND iw_errlog TO it_errlog.
  ENDCASE.

  CHECK it_errlog IS INITIAL.
**{ Insert started by Linda on 06-Jan-2015 - CRXX
    PERFORM frm_modify_blitems.
*
**} Insert ended   by Linda on 06-Jan-2015 - CRXX
* background process
  IF p_check2 = X.
    PERFORM frm_transfer_sever.
  ELSE.
*   front process
    PERFORM frm_transfer_loc.
  ENDIF.
*----------------------------------------------------------------------*
* END-OF-SELECTION
*----------------------------------------------------------------------*
END-OF-SELECTION.
* error log print
  LOOP AT it_errlog INTO iw_errlog."
    WRITE: /1  iw_errlog-str.
  ENDLOOP.

  FREE:it_tbillno,
       it_out,
       iw_vbrk,
       iw_tbillno,
       iw_blitems,
       it_vbeln,
       it_kunnr,
       it_blitems,
       w_time,
       w_path,
       w_filename,
       iw_out.
*&---------------------------------------------------------------------*
*&      Form  frm_transfer_sever
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_transfer_sever .
* 拼接文件名
  IF p_check3 = X.
    CONCATENATE p_bukrs s_vkorg-low sy-datum "LINDA 20140916
                w_time .txt
                INTO w_filename.
  ELSEIF p_check4 = X.
    CONCATENATE p_bukrs s_vkorg-low sy-datum "LINDA 20140916
                w_time .csv
                INTO w_filename.
  ENDIF.
* 拼接服务器路径
  CONCATENATE p_path2 w_filename
         INTO w_path SEPARATED BY cos_vl.

* 打开服务器文件  编码是非unicode
*  OPEN DATASET w_path FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE.
* 打开服务器文件  编码是unicode
  OPEN DATASET w_path FOR OUTPUT IN TEXT MODE ENCODING UTF-8.
* 打开成功
  IF sy-subrc = 0.
* 读取
    PERFORM frm_write_txt.
* 关闭 DATASET
    TRY.
        CLOSE DATASET w_path.
        IF sy-subrc <> 0.
* 文件名 &1 &2 &3 操作出错
          MESSAGE s001(00) WITH File name w_filename cos_close operate Error  INTO iw_errlog-str. "Linda 20141119
        ELSE.
* 导出成功
          MESSAGE s001(00) WITH Output successful INTO iw_errlog-str.
        ENDIF.
      CATCH cx_root.                                     "#EC CATCH_ALL
        MESSAGE s001(00) WITH File name w_filename cos_close operate Error  INTO iw_errlog-str. "Linda 20141119
      CLEANUP.
    ENDTRY.
  ELSE.
*   文件名 &1 &2 &3 操作出错
    MESSAGE s001(00) WITH File name w_filename cos_open operate Error INTO iw_errlog-str. "Linda 20141119
  ENDIF.
  APPEND iw_errlog TO it_errlog.
  CLEAR:w_filename,
        w_path.
ENDFORM.                    " frm_transfer_sever
*&---------------------------------------------------------------------*
*&      Form  frm_transfer_loc
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->p1      text
*      <--p2      text
*----------------------------------------------------------------------*
FORM frm_transfer_loc.
  DATA:lw_file TYPE string.
* 拼接download数据
  LOOP AT it_blitems INTO iw_blitems.
    PERFORM frm_con_string   USING     iw_blitems
                             CHANGING  iw_out-txt.
    APPEND iw_out TO it_out.
    CLEAR: iw_blitems,iw_out.
  ENDLOOP.
  lw_file = p_path.

  CALL FUNCTION GUI_DOWNLOAD
    EXPORTING
      filename                = lw_file "string
      filetype                = ASC
      codepage                = 8400  "4110 是utf-8
      write_bom               = X
    TABLES
      data_tab                = it_out
    EXCEPTIONS
      file_write_error        = 1
      no_batch                = 2
      gui_refuse_filetransfer = 3
      invalid_type            = 4
      no_authority            = 5
      unknown_error           = 6
      header_not_allowed      = 7
      separator_not_allowed   = 8
      filesize_not_allowed    = 9
      header_too_long         = 10
      dp_error_create         = 11
      dp_error_send           = 12
      dp_error_write          = 13
      unknown_dp_error        = 14
      access_denied           = 15
      dp_out_of_memory        = 16
      disk_full               = 17
      dp_timeout              = 18
      file_not_found          = 19
      dataprovider_exception  = 20
      control_flush_error     = 21
      OTHERS                  = 22.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE S NUMBER sy-msgno
            DISPLAY LIKE E
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    iw_errlog-str = Output success.(024).
    APPEND iw_errlog TO it_errlog.
  ENDIF.
ENDFORM.                    " frm_transfer_loc
*&---------------------------------------------------------------------*
*&      Form  frm_save_file
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--f_path      text
*----------------------------------------------------------------------*
FORM frm_save_file  CHANGING f_path TYPE file_table-filename.
  DATA: lw_fname   TYPE string,
         lw_path   TYPE string,
         lw_fpath  TYPE string.

  CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
      file_filter          = w_filter
    CHANGING
      filename             = lw_fname
      path                 = lw_path
      fullpath             = lw_fpath
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE E NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  f_path = lw_fpath.

ENDFORM.                    " frm_save_file
*&---------------------------------------------------------------------*
*&      Form  frm_con_string
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->piw_blitem  text
*      <--pw_txt      text
*----------------------------------------------------------------------*
FORM frm_con_string  USING  piw_blitem  TYPE zc0000sdt0016
                    CHANGING pw_txt TYPE string.
  DATA: lw_temp TYPE char1024.
  FIELD-SYMBOLS: <fs_temp> TYPE ANY.
  DO.
    ASSIGN COMPONENT sy-index OF STRUCTURE piw_blitem TO <fs_temp>.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
    CLEAR lw_temp.
    lw_temp = <fs_temp>.
*     去空格
    SHIFT lw_temp LEFT DELETING LEADING space.

    IF sy-index = 1.
      pw_txt = lw_temp.
    ELSE.
      IF p_check3 = X.  "Linda 20141120 add
      CONCATENATE pw_txt cl_abap_char_utilities=>horizontal_tab lw_temp
             INTO pw_txt.

       ELSEIF p_check4 = X.
      CONCATENATE pw_txt cos_comma lw_temp    "Linda 20141120 add
             INTO pw_txt.
*      ELSE.
*        CONCATENATE pw_txt cos_comma lw_temp
*               INTO pw_txt.
      ENDIF.
    ENDIF.
  ENDDO.
  UNASSIGN <fs_temp>.
ENDFORM.                    " frm_con_string
*&---------------------------------------------------------------------*
*&      Form  frm_write_txt
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_write_txt .
  DATA:lw_out      TYPE string.
**  上传数据头
** 捕获异常
*  TRY.
** 上传服务器
*      lw_out  = LINES( it_blitems ).
*      CONCATENATE w_filename ‘#Record‘ lw_out
*             INTO lw_out.
*      CONDENSE lw_out.
*      TRANSFER lw_out TO w_path.
** 判断传输是否成功
*      IF sy-subrc <> 0.
** 文件名 &1 &2 &3 操作出错
*        MESSAGE s001(00) WITH ‘File name‘ w_path cos_transfer ‘operate error‘.
*      ENDIF.
*    CATCH cx_root.
*      MESSAGE s001(00) WITH ‘File name‘ w_path cos_transfer ‘operate error‘.
*    CLEANUP.
*  ENDTRY.
*  上传数据
  LOOP AT it_blitems INTO iw_blitems.

    PERFORM frm_con_string   USING     iw_blitems
                             CHANGING  lw_out.
    TRY.
        TRANSFER lw_out TO w_path.
* 判断传输是否成功
        IF sy-subrc <> 0.
* 文件名 &1 &2 &3 操作出错
          MESSAGE s001(00) WITH File name w_path cos_transfer operate error.
        ENDIF.
      CATCH cx_root.
        MESSAGE s001(00) WITH File name w_path cos_transfer operate error.
      CLEANUP.
    ENDTRY.
    CLEAR: iw_blitems,lw_out.
  ENDLOOP.
ENDFORM.                    " frm_write_txt
*&---------------------------------------------------------------------*
*&      Form  frm_chang_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->fw_data  text
*      <--fw_budat text
*----------------------------------------------------------------------*
FORM frm_chang_data  USING    fw_data
                     CHANGING fw_budat.
  DATA:l_today TYPE p0001-begda,
       lw_data TYPE t5a4a-dlydy,
       lw_calc TYPE p0001-begda.
*       lw_data2 LIKE sy-datum.

  l_today = sy-datum.
  lw_data = fw_data.
  IF fw_data = 0.
    fw_budat = sy-datum.
  ELSEIF fw_data > 0.
    CALL FUNCTION RP_CALC_DATE_IN_INTERVAL
      EXPORTING
        date      = l_today
        days      = lw_data
        months    = 0
        signum    = +
        years     = 0
      IMPORTING
        calc_date = lw_calc.
    fw_budat = lw_calc .
  ELSE.
    CALL FUNCTION RP_CALC_DATE_IN_INTERVAL
      EXPORTING
        date      = l_today
        days      = lw_data
        months    = 0
        signum    = -
        years     = 0
      IMPORTING
        calc_date = lw_calc.

    fw_budat = lw_calc .
  ENDIF.
ENDFORM.                    " frm_chang_data
*&---------------------------------------------------------------------*
*&      Form  frm_init
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_init .
*  SELECT * FROM t001 INTO t001. "Linda 20141204 del
* authority-check
    AUTHORITY-CHECK OBJECT F_BKPF_BUK
                   ID BUKRS FIELD p_bukrs
                   ID ACTVT FIELD 03.
    IF sy-subrc <> 0.
*      You have no authorization for Company code
    MESSAGE e004(zp001) WITH p_bukrs.
    ENDIF.
*  ENDSELECT.                 "Linda 20141204 del

ENDFORM.                    " frm_init
**{ Insert started by Linda on 06-Jan-2015 - CR0001
*&---------------------------------------------------------------------*
*&      Form  FRM_MODIFY_BLITEMS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_modify_blitems .
  DATA:lw_blitems TYPE zc0000sdt0016.
  LOOP AT it_blitems INTO lw_blitems.
CALL FUNCTION CONVERSION_EXIT_CUNIT_OUTPUT
  EXPORTING
    input                = lw_blitems-vrkme
    language             = sy-langu
IMPORTING
*   LONG_TEXT            =
   output               = lw_blitems-vrkme
*   SHORT_TEXT           =
* EXCEPTIONS
*   UNIT_NOT_FOUND       = 1
*   OTHERS               = 2
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

MODIFY it_blitems FROM lw_blitems TRANSPORTING vrkme.
    ENDLOOP.

ENDFORM.                    " FRM_MODIFY_BLITEMS

 

发票号码回传程序

 

   1 REPORT  zc0000sdr0017 NO STANDARD PAGE HEADING
   2                      LINE-COUNT 58
   3                      LINE-SIZE 170.
   4 TYPE-POOLS: icon,slis,kcdu,tpit.
   5 TABLES: sscrfields,
   6         zc0000sdt0020.
   7 *----------------------------------------------------------------------*
   8 * type define
   9 *----------------------------------------------------------------------*
  10 TYPES: ty_dir_list TYPE STANDARD TABLE OF salfldir,
  11        BEGIN OF ty_dir,
  12          name    TYPE pfeflname,
  13          size TYPE pfeflsize,
  14          name2 TYPE pfeflname,
  15          END OF ty_dir,
  16        BEGIN OF ty_tabl,
  17          line(200),
  18        END OF ty_tabl,
  19        BEGIN OF ty_vbeln,
  20          vbeln TYPE vbrk-vbeln,
  21          fkart TYPE vbrk-fkart,
  22          kunrg TYPE vbrk-kunrg,
  23          bukrs TYPE vbrk-bukrs,
  24          fkdat TYPE vbrk-fkdat,
  25          xblnr TYPE xblnr,
  26          gjahr TYPE gjahr,
  27          bktxt TYPE bktxt, "linda 20140918
  28          zline TYPE i,  "bseg table lines  "Linda 20141023
  29         END OF ty_vbeln,
  30         BEGIN OF ty_vbrk,
  31          vbeln TYPE vbrk-vbeln,
  32          bukrs TYPE vbrk-bukrs,
  33          gjahr TYPE vbrk-gjahr,
  34          xblnr TYPE vbrk-xblnr,
  35          fkdat TYPE vbrk-fkdat,
  36         END OF ty_vbrk,
  37 * add local file read  begin
  38         BEGIN OF ty_row,
  39           field TYPE char40,
  40         END OF ty_row,
  41 * add local file read  end
  42         BEGIN OF ty_errlog,  "Linda 20141120 add
  43          str(100) TYPE c,    "Linda 20141120 add
  44         END OF ty_errlog.   "Linda 20141120 add
  45 *----------------------------------------------------------------------*
  46 *  Internal Tables define
  47 *----------------------------------------------------------------------*
  48 DATA: it_file        TYPE ty_dir_list,
  49       it_file2       TYPE STANDARD TABLE OF ty_dir,
  50       it_errtab      TYPE tpit_t_errdoc,
  51       it_buztab      TYPE TABLE OF tpit_buztab,
  52       it_fldtab         TYPE tpit_t_fname,
  53       it_tabl        TYPE STANDARD TABLE OF ty_tabl WITH HEADER LINE,
  54       it_errlog      TYPE STANDARD TABLE OF zc0000sdt0020,
  55       it_errlog2     TYPE STANDARD TABLE OF ty_errlog,  "Linda 20141120 add
  56       it_fieldcat    TYPE slis_t_fieldcat_alv,
  57       it_bseg        TYPE STANDARD TABLE OF bseg." Linda 20141024 add
  58 *&---------------------------------------------------------------------*
  59 *  Workarea define
  60 *&---------------------------------------------------------------------*
  61 DATA: iw_file      TYPE salfldir,
  62       iw_file2     TYPE ty_dir,
  63       iw_ins       TYPE ty_vbeln,
  64       iw_vbrk      TYPE ty_vbrk,
  65       iw_err       TYPE zc0000sdt0020,
  66       iw_errlog    TYPE ty_errlog,  "Linda 20141120 add
  67       iw_bseg      TYPE bseg.
  68 *----------------------------------------------------------------------*
  69 *   Global Variables
  70 *----------------------------------------------------------------------*
  71 DATA :w_ret           TYPE char1,
  72       w_cmd(100)      TYPE c,
  73       w_date          TYPE sy-datum,
  74       w_time          TYPE char6,
  75       w_read_file     TYPE salfile-longname,
  76       functxt         TYPE smp_dyntxt,
  77       ok_code         TYPE sy-ucomm,
  78       w_repid         TYPE sy-repid,
  79       w_str(1000)     TYPE c,
  80       putdahigh       TYPE zc0000sdt0020-putda,
  81       puttihigh       TYPE zc0000sdt0020-putti,
  82       vbelnhigh       TYPE zc0000sdt0020-vbeln,
  83       xblnrhigh       TYPE zc0000sdt0020-xblnr,
  84       w_file_path     TYPE string,
  85       w_lfile         TYPE string, "file name
  86       w_row_num       TYPE char4,
  87       w_msg_txt       TYPE string.
  88 *----------------------------------------------------------------------*
  89 *  Constants define
  90 *----------------------------------------------------------------------*
  91 CONSTANTS: cos_star2(3)       TYPE c VALUE *.*,
  92            cos_2(2)           TYPE c VALUE 2,
  93            cos_1(1)           TYPE c VALUE 1,
  94            cos_numc(4)        TYPE c VALUE NUMC.
  95 
  96 SELECTION-SCREEN: FUNCTION KEY 1 .
  97 SELECTION-SCREEN BEGIN OF LINE.
  98 PARAMETER p_check2 TYPE c RADIOBUTTON GROUP rads DEFAULT X.
  99 SELECTION-SCREEN COMMENT 4(20) text-c02 FOR FIELD p_check2."导出到服务器
 100 SELECTION-SCREEN END OF LINE.
 101 SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
 102 PARAMETERS: p_fpath(1024) TYPE c DEFAULT g:\r3ftp\formware\writeback\nonprocess\‘,"need edit  D:\usr\sap\put\Inbound\Nonprocess 103             p_bpath(1024) TYPE c DEFAULT g:\r3ftp\formware\writeback\bak\." D:\usr\sap\put\Inbound\Backup 104 SELECTION-SCREEN END OF BLOCK b1.
 105 SELECTION-SCREEN BEGIN OF LINE.
 106 PARAMETER p_check1 RADIOBUTTON GROUP rads.
 107 SELECTION-SCREEN COMMENT 4(20) text-c01 FOR FIELD p_check1."导出到本地
 108 SELECTION-SCREEN END OF LINE.
 109 SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t01.
 110 PARAMETERS: p_flpath(1024) TYPE c DEFAULT ‘‘."need edit  D:\usr\sap\put\Inbound\Nonprocess 111 *            p_blpath(1024) TYPE c DEFAULT D:\Backup\." D:\usr\sap\put\Inbound\Backup 112 SELECTION-SCREEN END OF BLOCK b2.
 113 *----------------------------------------------------------------------*
 114 * INITIALIZATION.
 115 *----------------------------------------------------------------------*
 116 INITIALIZATION.
 117   functxt-icon_id   = icon_biw_info_catalog.
 118   functxt-icon_text = ERROR LOG.
 119   sscrfields-functxt_01 = functxt.
 120 *----------------------------------------------------------------------*
 121 * AT SELECTION-SCREEN ON VALUE-REQUEST
 122 *----------------------------------------------------------------------*
 123 AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_flpath.
 124   PERFORM form_get_file_path_upload.
 125 *----------------------------------------------------------------------*
 126 * START-OF-SELECTION
 127 *----------------------------------------------------------------------*
 128 START-OF-SELECTION.
 129   w_date = sy-datum.
 130   w_time = sy-uzeit.
 131 *   file process
 132   IF p_check2 IS NOT INITIAL.
 133     PERFORM frm_file_process.
 134   ELSE.
 135 * local
 136     PERFORM frm_file_process_local.
 137   ENDIF.
 138 *----------------------------------------------------------------------*
 139 * AT SELECTION-SCREEN
 140 *----------------------------------------------------------------------*
 141 AT SELECTION-SCREEN.
 142   IF sy-ucomm = ONLI.
 143     IF p_flpath IS INITIAL AND p_check1 = X.
 144       MESSAGE e001(00) WITH local path can not be init(001).
 145       SET CURSOR FIELD P_FLPATH.
 146     ENDIF.
 147   ENDIF.
 148   CASE sscrfields-ucomm.
 149     WHEN FC01.
 150       CALL SCREEN 9000.
 151     WHEN OTHERS.
 152       ...
 153   ENDCASE.
 154 *----------------------------------------------------------------------*
 155 * END-OF-SELECTION
 156 *----------------------------------------------------------------------*
 157 END-OF-SELECTION.
 158   IF w_ret = X.
 159     IF it_errlog IS INITIAL.
 160       WRITE: /1  Write back fail,please see error log.(014).
 161     ELSE.
 162       LOOP AT it_errlog INTO iw_errlog."
 163         WRITE: /1  iw_errlog-str.
 164       ENDLOOP.
 165     ENDIF.
 166   ELSE.
 167     WRITE: /1  Write back success(012).
 168   ENDIF.
 169   CLEAR:it_errlog,iw_errlog.
 170 *----------------------------------------------------------------------*
 171 *  子程序名称 :文件处理
 172 *  子程序名   :frm_file_process
 173 *  概要       :文件处理
 174 * 参数       :无
 175 *  返回值     :无
 176 *----------------------------------------------------------------------*
 177 FORM frm_file_process.
 178   DATA: lw_path TYPE salfile-longname,
 179         w_cmd1   TYPE string.
 180 *   Nonprocess路径名组成
 181   CLEAR lw_path.
 182   lw_path = p_fpath.
 183 *   取得目录中的内容
 184   PERFORM frm_read_directory TABLES it_file
 185                              USING  lw_path
 186                              CHANGING w_ret.
 187   IF w_ret = space.
 188 *   把文件夹Nonprocess下的文件复制到文件夹Backup下
 189 
 190 **{ Insert started by ZhouTing on 25-Jan-2015 - CR0010
 191 
 192 ** begin of comment by zhou ting
 193 ** to use open dataset instead
 194 *
 195 **    这是在Linux系统下用的
 196 **    CONCATENATE p_fpath cos_nonprocess cos_star2            "#EC NOTEXT
 197 **                INTO w_cmd1.
 198 **    这是在windows系统下用的
 199 *    CONCATENATE p_fpath cos_star2                           "#EC NOTEXT
 200 *              INTO w_cmd1.
 201 *
 202 **    这是在Linux系统下用的  "need be edited
 203 **    CONCATENATE cp w_cmd1 p_bpath INTO w_cmd SEPARATED BY space.
 204 **    这是在windows系统下用的
 205 *    CONCATENATE copy w_cmd1 p_bpath INTO w_cmd SEPARATED BY space.
 206 ***{ Insert started by Linda on 06-Jan-2015 - CR0010
 207 *    TRY.
 208 ***{ Insert ended by Linda on 06-Jan-2015 - CR0010
 209 *    CALL SYSTEM ID COMMAND FIELD w_cmd
 210 *                  ID TAB FIELD it_tabl-*sys*.
 211 *
 212 *    IF sy-subrc <> 0.
 213 *      CONCATENATE Move file fail(013) p_bpath INTO iw_errlog-str.
 214 *      APPEND iw_errlog TO it_errlog2.
 215 *      w_ret = X.
 216 *    ENDIF.
 217 ***{ Insert started by Linda on 06-Jan-2015 - CR0010
 218 *         CATCH cx_root.
 219 *             CONCATENATE Move file fail(013) p_bpath INTO iw_errlog-str.
 220 *      APPEND iw_errlog TO it_errlog2.
 221 *      w_ret = X.
 222 *     ENDTRY.
 223 ***{ Insert ended by Linda on 06-Jan-2015 - CR0010
 224 ** end of comment.
 225 
 226     PERFORM frm_copy_file USING p_fpath p_bpath it_file
 227                           CHANGING w_ret.
 228     IF w_ret <> 0.
 229       CONCATENATE Move file fail(013) p_bpath INTO iw_errlog-str.
 230       APPEND iw_errlog TO it_errlog2.
 231       w_ret = X.
 232     ENDIF.
 233 
 234 **{ Insert ended by ZhouTing on 25-Jan-2015 - CR0010
 235 
 236 *   文件数据传送接口表
 237 
 238     PERFORM frm_transfer_data USING lw_path
 239                               CHANGING w_ret.
 240   ENDIF.
 241 
 242 ENDFORM.                    " FRM_file_process
 243 *----------------------------------------------------------------------*
 244 *  子程序名称 :取得目录中的内容
 245 *  子程序名   :frm_read_directory
 246 *  概要       :取得目录中的内容
 247 * 参数       :fit_dir_bukrs type ty_dir_list        取得的目录列表
 248 *             :f_dir_path type salfile-longname      目录路径
 249 *  返回值     :f_ret type c  正常取得:space  未取得:1 异常:2
 250 *----------------------------------------------------------------------*
 251 FORM frm_read_directory TABLES fit_dir TYPE ty_dir_list
 252                          USING f_dir_path TYPE salfile-longname
 253                          CHANGING f_ret TYPE c.
 254   DATA: lw_lines TYPE i.
 255 
 256   CLEAR f_ret.
 257   REFRESH fit_dir.
 258   CALL FUNCTION RZL_READ_DIR_LOCAL
 259     EXPORTING
 260       name           = f_dir_path
 261     TABLES
 262       file_tbl       = fit_dir
 263     EXCEPTIONS
 264       argument_error = 1
 265       not_found      = 2
 266       OTHERS         = 3.
 267 
 268   IF sy-subrc <> 0.
 269     f_ret = cos_2.
 270     RETURN.
 271   ENDIF.
 272 
 273   lw_lines = LINES( fit_dir ).
 274   IF lw_lines < 3.
 275     f_ret = cos_1.
 276   ENDIF.
 277 ENDFORM.                    " frm_read_directory
 278 *----------------------------------------------------------------------*
 279 *  子程序名称 :数据传输处理
 280 *  子程序名   :frm_copy_file
 281 *  概要       :把需处理的文件拷贝到bak目录下
 282 * 参数       :i_frompath    目录路径
 283 *               i_topath      目录路径
 284 *  返回值     :o_ret 正常:space  异常:4
 285 *----------------------------------------------------------------------*
 286 FORM frm_copy_file USING i_frompath
 287                          i_topath
 288                          i_filelist TYPE ty_dir_list
 289                    CHANGING o_ret.
 290 
 291   DATA: from_file TYPE string,
 292         to_file   TYPE string,
 293         lt_file_content TYPE TABLE OF string,
 294         lv_text     TYPE string,
 295         ls_filelist TYPE salfldir.
 296 
 297   LOOP AT i_filelist FROM 3 INTO ls_filelist.
 298 
 299     REFRESH lt_file_content.
 300 
 301     "源文件路径+文件名
 302     CONCATENATE i_frompath ls_filelist-name INTO from_file.
 303     "目标文件路径+文件名
 304     CONCATENATE i_topath   ls_filelist-name INTO to_file.
 305 
 306     "把源文件内容保存进内表
 307     OPEN DATASET from_file FOR INPUT IN TEXT MODE
 308                          ENCODING NON-UNICODE
 309                          IGNORING CONVERSION ERRORS.
 310     IF sy-subrc NE 0.
 311       o_ret = 4.
 312       EXIT.
 313     ENDIF.
 314     DO.
 315       READ DATASET from_file INTO lv_text.
 316       IF sy-subrc NE 0.
 317         EXIT.
 318       ENDIF.
 319       APPEND lv_text TO lt_file_content.
 320     ENDDO.
 321 
 322     CLOSE DATASET from_file.
 323 
 324 
 325     "把源文件内容从系统内表中写入目标文件中
 326     OPEN DATASET to_file FOR OUTPUT IN TEXT MODE
 327                          ENCODING NON-UNICODE
 328                          IGNORING CONVERSION ERRORS.
 329 
 330     IF sy-subrc NE 0.
 331       o_ret = 4.
 332       EXIT.
 333     ENDIF.
 334     LOOP AT lt_file_content INTO lv_text.
 335       TRANSFER lv_text TO to_file.
 336     ENDLOOP.
 337     CLOSE DATASET to_file.
 338 
 339   ENDLOOP.
 340 
 341 ENDFORM.                    "frm_copy_file
 342 *----------------------------------------------------------------------*
 343 *  子程序名称 :数据传输处理
 344 *  子程序名   :frm_transfer_data
 345 *  概要       :文件数据传送接口表
 346 * 参数       :f_path type salfile-longname    目录路径
 347 *  返回值     :无
 348 *----------------------------------------------------------------------*
 349 FORM frm_transfer_data USING f_path TYPE salfile-longname
 350                        CHANGING lw_ret.
 351   DATA: lw_loopc       TYPE sy-index,
 352         lw_text(2048)  TYPE c,
 353 *        lw_ret(1)      TYPE c,
 354         lw_zwrit       TYPE i,
 355         lw_lines       TYPE i,
 356         lw_len         TYPE i.
 357 
 358 *  处理文件名排序的问题
 359   SORT it_file BY name DESCENDING.
 360   lw_lines = LINES( it_file ).
 361   lw_lines = lw_lines - 1.
 362 *  删除无用的2行
 363   DELETE it_file FROM lw_lines.
 364 *  从it_file 取数添加到it_file2
 365 
 366   LOOP AT it_file INTO iw_file.
 367     MOVE-CORRESPONDING iw_file TO iw_file2.
 368 
 369     lw_len = STRLEN( iw_file-name ) - 18.
 370 
 371     SHIFT iw_file-name BY lw_len PLACES LEFT.
 372     iw_file2-name2 = iw_file-name+0(14).
 373     APPEND iw_file2 TO it_file2.
 374     CLEAR:lw_len,iw_file2.
 375   ENDLOOP.
 376 
 377   CLEAR iw_file.
 378 *  按文件生成时间排序
 379   SORT it_file2 BY name2.
 380   LOOP AT it_file2 INTO iw_file2.
 381 *   文件路径组
 382     CLEAR w_read_file.
 383     CONCATENATE f_path iw_file2-name INTO w_read_file.
 384 *   打开文件
 385     OPEN DATASET w_read_file FOR INPUT
 386                              IN TEXT MODE ENCODING NON-UNICODE.
 387     IF sy-subrc <> 0.
 388       EXIT.
 389     ENDIF.
 390     DO.
 391       lw_loopc = sy-index.
 392       TRY.
 393           CLEAR lw_text.
 394           READ DATASET w_read_file INTO lw_text.
 395         CATCH cx_sy_conversion_codepage.
 396           CLOSE DATASET: w_read_file.
 397           EXIT.
 398       ENDTRY.
 399 *      空文件的情况下
 400       IF sy-subrc <> 0 AND lw_loopc = 1."lw_loopc = 2 带标题的文件
 401         PERFORM frm_get_errno CHANGING lw_zwrit.
 402         iw_err-zwrit = lw_zwrit.
 403         IF p_check1 = X.
 404           iw_err-filen = w_lfile.
 405         ELSE.
 406           iw_err-filen = iw_file2-name.
 407         ENDIF.
 408         iw_err-errin = FILE NO DATA(002).
 409         iw_err-putda = w_date.
 410         iw_err-putti = w_time.
 411         INSERT zc0000sdt0020 FROM iw_err.
 412         CLEAR:iw_err.
 413         lw_ret = X.
 414         " EXIT.
 415       ELSEIF sy-subrc <> 0.
 416 **{ Insert started by ZhouTing on 30-Jan-2015 - CR0010
 417         "lw_ret = X.
 418 **{ Insert ended by ZhouTing on 30-Jan-2015 - CR0010
 419         EXIT.
 420       ENDIF.
 421 *     第一行不是标题
 422 *      IF lw_loopc = 1.
 423 *        CONTINUE.
 424 *      ENDIF.
 425 *     拆分数据并加入接口表
 426 *      0090036259 LR  0000300713  20140525  123456  3000
 427 *  vbeln fkart 客户代码   金税号
 428       CHECK lw_ret IS INITIAL.
 429       PERFORM frm_separate_text USING lw_text
 430                                 CHANGING lw_ret.
 431       CHECK lw_ret IS INITIAL.
 432       PERFORM frm_writeback CHANGING lw_ret.
 433     ENDDO.
 434 
 435 **{ Insert started by ZhouTing on 27-Jan-2015 - CR0010
 436     CLOSE DATASET w_read_file.
 437 **{ Insert ended by ZhouTing on 27-Jan-2015 - CR0010
 438 
 439     DELETE DATASET w_read_file.
 440 
 441   ENDLOOP.
 442 ENDFORM.                    " frm_transfer_data
 443 *----------------------------------------------------------------------*
 444 *  子程序名称 :拆分数据并加入接口表
 445 *  子程序名   :frm_separate_text
 446 *  概要       :拆分数据并加入接口表
 447 * 参数       :f_text type c           要拆分的数据
 448 *  返回值     :无
 449 *----------------------------------------------------------------------*
 450 FORM frm_separate_text USING f_text TYPE c
 451                        CHANGING f_ret TYPE c.
 452   DATA: lw_value(100) TYPE c,
 453         lw_val(1024)  TYPE c,
 454         lw_ret        TYPE char1,
 455         lw_zwrit      TYPE i.
 456   CLEAR f_ret.
 457   lw_val = f_text.
 458 
 459 *  Sys_Inv_No
 460   SPLIT lw_val AT cl_abap_char_utilities=>horizontal_tab
 461   INTO lw_value lw_val.
 462   IF lw_value = space.
 463 *    检查 发票号是否为空
 464     PERFORM frm_get_errno CHANGING lw_zwrit.
 465     iw_err-zwrit = lw_zwrit.
 466     IF p_check1 = X.
 467       iw_err-filen = w_lfile.
 468     ELSE.
 469       iw_err-filen = iw_file2-name.
 470     ENDIF.
 471     iw_err-errin = INVOICENO IS EMPTY(003).
 472     iw_err-vbeln = lw_value.
 473     iw_err-putda = w_date.
 474     iw_err-putti = w_time.
 475     INSERT zc0000sdt0020 FROM iw_err.
 476     CLEAR:iw_err.
 477     f_ret = X.
 478   ELSE.
 479 * Sys_Inv_No检查
 480     PERFORM frm_numeric_check USING lw_value
 481                               CHANGING lw_ret.
 482     IF lw_ret = X.
 483 *    检查 发票是否为数字
 484       PERFORM frm_get_errno CHANGING lw_zwrit.
 485       iw_err-zwrit = lw_zwrit.
 486       IF p_check1 = X.
 487         iw_err-filen = w_lfile.
 488       ELSE.
 489         iw_err-filen = iw_file2-name.
 490       ENDIF.
 491       iw_err-errin = INVOICENO IS NOT NUMBER(004).
 492       iw_err-vbeln = lw_value.
 493       iw_err-putda = w_date.
 494       iw_err-putti = w_time.
 495       INSERT zc0000sdt0020 FROM iw_err.
 496       CLEAR:iw_err.
 497       f_ret = X.
 498     ELSE.
 499 *    检查 发票存在性
 500       PERFORM frm_check_inv USING lw_value
 501                             CHANGING lw_ret.
 502       IF lw_ret  = X.
 503         PERFORM frm_get_errno CHANGING lw_zwrit.
 504         iw_err-zwrit = lw_zwrit.
 505         IF p_check1 = X.
 506           iw_err-filen = w_lfile.
 507         ELSE.
 508           iw_err-filen = iw_file2-name.
 509         ENDIF.
 510         iw_err-errin = INVOICENO IS NOT EXIST(005).
 511         iw_err-vbeln = lw_value.
 512         iw_err-putda = w_date.
 513         iw_err-putti = w_time.
 514         INSERT zc0000sdt0020 FROM iw_err.
 515         CLEAR:iw_err.
 516         f_ret = X.
 517       ELSEIF lw_val = space."  金税号 为空检查
 518         PERFORM frm_get_errno CHANGING lw_zwrit.
 519         iw_err-zwrit = lw_zwrit.
 520         IF p_check1 = X.
 521           iw_err-filen = w_lfile.
 522         ELSE.
 523           iw_err-filen = iw_file2-name.
 524         ENDIF.
 525         iw_err-errin = JINSHUHAO IS EMPTY(006).
 526         iw_err-vbeln = lw_value.
 527         iw_err-putda = w_date.
 528         iw_err-putti = w_time.
 529         INSERT zc0000sdt0020 FROM iw_err.
 530         CLEAR:iw_err.
 531         f_ret = X.
 532       ELSE.
 533         iw_ins-vbeln = lw_value. "保存 数据
 534 * fkart
 535         CLEAR lw_value.
 536         SPLIT lw_val AT  cl_abap_char_utilities=>horizontal_tab
 537         INTO lw_value lw_val.
 538         iw_ins-fkart = lw_value. "保存 数据
 539 
 540 *kunrg
 541         CLEAR lw_value.
 542         SPLIT lw_val AT  cl_abap_char_utilities=>horizontal_tab
 543         INTO lw_value lw_val.
 544         iw_ins-kunrg = lw_value. "保存 数据
 545 * Year
 546         IF lw_val = space."  年度 为空检查
 547           PERFORM frm_get_errno CHANGING lw_zwrit.
 548           iw_err-zwrit = lw_zwrit.
 549           IF p_check1 = X.
 550             iw_err-filen = w_lfile.
 551           ELSE.
 552             iw_err-filen = iw_file2-name.
 553           ENDIF.
 554           iw_err-errin = YEAR IS EMPTY(007).
 555           iw_err-vbeln = lw_value.
 556           iw_err-putda = w_date.
 557           iw_err-putti = w_time.
 558           INSERT zc0000sdt0020 FROM iw_err.
 559           CLEAR:iw_err.
 560           f_ret = X.
 561         ELSE.
 562           CLEAR lw_value.
 563           SPLIT lw_val AT  cl_abap_char_utilities=>horizontal_tab
 564           INTO lw_value lw_val.
 565           iw_ins-gjahr = lw_value+0(4). "保存 数据
 566 *linda   20140806
 567           iw_ins-fkdat = lw_value. "保存 数据
 568         ENDIF.
 569 * VAT_Inv_No
 570         CLEAR lw_value.
 571         SPLIT lw_val AT  cl_abap_char_utilities=>horizontal_tab
 572         INTO lw_value lw_val.
 573         iw_ins-xblnr = lw_value. "保存 数据
 574         iw_ins-bktxt = lw_value."Linda 20140918
 575 * bukrs
 576         CLEAR lw_value.
 577         SPLIT lw_val AT  cl_abap_char_utilities=>horizontal_tab
 578         INTO lw_value lw_val.
 579         iw_ins-bukrs = lw_value. "保存 数据
 580       ENDIF.
 581     ENDIF.
 582   ENDIF.
 583 ENDFORM.                    " frm_separate_text
 584 *Sys_Inv_No VAT_Inv_No  VAT Issue_date  Total_Amount
 585 *0090035243 12345654321 2005-08-10  8
 586 *----------------------------------------------------------------------*
 587 *  子程序名称 :数据类型检查
 588 *  子程序名   :frm_numeric_check
 589 *  概要       :数据类型检查
 590 * 参数       :f_val TYPE c            要检查的数据
 591 *  返回值     :f_ret TYPE c            正常:space    出错:X
 592 *----------------------------------------------------------------------*
 593 FORM frm_numeric_check USING f_val TYPE c
 594                        CHANGING f_ret TYPE c.
 595   DATA: lw_type TYPE dd01v-datatype.
 596 
 597   CHECK f_val <> space.
 598   CLEAR f_ret.
 599   CALL FUNCTION NUMERIC_CHECK
 600     EXPORTING
 601       string_in = f_val
 602     IMPORTING
 603       htype     = lw_type.
 604   IF lw_type <> cos_numc.
 605     f_ret = X.
 606   ENDIF.
 607 ENDFORM.                    " frm_numeric_check
 608 
 609 *&---------------------------------------------------------------------*
 610 *&      Form  frm_get_errno
 611 *&---------------------------------------------------------------------*
 612 *       text
 613 *----------------------------------------------------------------------*
 614 *      <--P_LW_ZWRIT  text
 615 *----------------------------------------------------------------------*
 616 FORM frm_get_errno  CHANGING f_zwrit TYPE i.
 617   CALL FUNCTION NUMBER_GET_NEXT
 618     EXPORTING
 619       nr_range_nr             = 01      "snro
 620       object                  = ZWRITEBACK   "snro object "be edit
 621     IMPORTING
 622       number                  = f_zwrit   "所得到的号码
 623     EXCEPTIONS
 624       interval_not_found      = 1
 625       number_range_not_intern = 2
 626       object_not_found        = 3
 627       quantity_is_0           = 4
 628       quantity_is_not_1       = 5
 629       interval_overflow       = 6
 630       buffer_overflow         = 7
 631       OTHERS                  = 8.
 632   IF sy-subrc <> 0.
 633     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
 634     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO iw_errlog-str.
 635     APPEND iw_errlog TO it_errlog2.
 636   ENDIF.
 637 
 638 ENDFORM.                    " frm_get_errno
 639 *&---------------------------------------------------------------------*
 640 *&      Form  FRM_CHECK_INV
 641 *&---------------------------------------------------------------------*
 642 *       text
 643 *----------------------------------------------------------------------*
 644 *      -->f_vbeln  text
 645 *      <--f_ret  text
 646 *----------------------------------------------------------------------*
 647 FORM frm_check_inv  USING   f_vbeln
 648                     CHANGING f_ret.
 649   DATA:lw_count TYPE i.
 650   SELECT COUNT(*)
 651        INTO lw_count
 652        FROM vbrk                      "(Reference Document Number)
 653        WHERE vbeln = f_vbeln .   "Billing Document
 654   IF sy-subrc = 4.
 655     f_ret = X.
 656   ENDIF.
 657 ENDFORM.                    " FRM_CHECK_INV
 658 *&---------------------------------------------------------------------*
 659 *&      Form  frm_writeback
 660 *&---------------------------------------------------------------------*
 661 *       text
 662 *----------------------------------------------------------------------*
 663 *      -->fw_ret  text
 664 *----------------------------------------------------------------------*
 665 FORM frm_writeback CHANGING fw_ret.
 666   DATA:lw_zwrit TYPE i,
 667        lw_count TYPE i,
 668        lw_bktxt TYPE bktxt, "linda 20140916
 669        lw_belnr TYPE bkpf-belnr,
 670        lw_gjahr TYPE char4.
 671 *Select IsExist Invoice
 672   SELECT SINGLE vbeln
 673          bukrs
 674          gjahr
 675          xblnr
 676          fkdat
 677     INTO iw_vbrk
 678     FROM vbrk                      "(Reference Document Number)
 679     WHERE vbeln = iw_ins-vbeln.    "Billing Document
 680   IF iw_vbrk-xblnr <> iw_ins-xblnr.
 681 * 将发票号更新到发票 BKPF-XBLNR(Reference Document Number)
 682     PERFORM frm_vbrk_xblnr USING iw_ins-xblnr
 683                                  iw_ins-vbeln.
 684     IF w_msg_txt IS NOT INITIAL.
 685       PERFORM frm_get_errno CHANGING lw_zwrit.
 686       iw_err-zwrit = lw_zwrit.
 687       IF p_check1 = X.
 688         iw_err-filen = w_lfile.
 689       ELSE.
 690         iw_err-filen = iw_file2-name.
 691       ENDIF.
 692       iw_err-errin = UPDATA VBRK FAIL(008).
 693       iw_err-vbeln = iw_ins-vbeln.
 694       iw_err-xblnr = iw_ins-xblnr.
 695       iw_err-putda = w_date.
 696       iw_err-putti = w_time.
 697       INSERT zc0000sdt0020 FROM iw_err.
 698       CLEAR:iw_err,w_msg_txt.
 699       fw_ret = X.
 700     ENDIF.
 701   ENDIF.
 702   CHECK fw_ret IS INITIAL.
 703   SELECT SINGLE belnr bktxt "Linda 20140916 xblnr
 704     INTO (lw_belnr,lw_bktxt) "Linda 20140916lw_xblnr
 705     FROM bkpf
 706     WHERE bukrs = iw_vbrk-bukrs
 707           AND awkey = iw_ins-vbeln    "BKPF-AWKEY(Reference Key)
 708           AND gjahr = iw_vbrk-fkdat+0(4).
 709 
 710   IF lw_bktxt <> iw_ins-bktxt.
 711     lw_gjahr = iw_vbrk-fkdat+0(4).
 712     IF lw_belnr IS INITIAL.
 713       PERFORM frm_get_errno CHANGING lw_zwrit.
 714       iw_err-zwrit = lw_zwrit.
 715       IF p_check1 = X.
 716         iw_err-filen = w_lfile.
 717       ELSE.
 718         iw_err-filen = iw_file2-name.
 719       ENDIF.
 720       iw_err-errin = Invoice Is Empty(009).
 721       iw_err-vbeln = iw_ins-vbeln.
 722       iw_err-xblnr = iw_ins-xblnr.
 723       iw_err-putda = w_date.
 724       iw_err-putti = w_time.
 725       INSERT zc0000sdt0020 FROM iw_err.
 726       CLEAR:iw_err,w_msg_txt.
 727       fw_ret = X.
 728     ELSE.
 729 *    将发票号更新到凭证BKPF中的BKPF-XBLNR(Reference Document Number)
 730 *    update the GTS No.# to BKPF-XBLNR(Reference Document Number)
 731 *    2 reason:1>.要调用的function 用到了bseg这个结构;
 732 *                 Call function "Z_FI_ITEMS_MASS_CHANGE" using BSEG as import structure
 733 *           2>使用的频率不高,1周1次,每次XX 条,所以即使写成 select * 也对性能影响不大
 734 *                The call frequence will be weekly, and the volume is limited, thus should the performance impact is restricted.
 735       SELECT *
 736       INTO TABLE it_bseg
 737       FROM bseg
 738       WHERE bukrs = iw_vbrk-bukrs
 739        AND belnr = lw_belnr
 740        AND gjahr = lw_gjahr.
 741 
 742       PERFORM frm_bseg_sgtxt USING  iw_ins.
 743       IF w_msg_txt IS NOT INITIAL.
 744         PERFORM frm_get_errno CHANGING lw_zwrit.
 745         iw_err-zwrit = lw_zwrit.
 746         IF p_check1 = X.
 747           iw_err-filen = w_lfile.
 748         ELSE.
 749           iw_err-filen = iw_file2-name.
 750         ENDIF.
 751         iw_err-errin = BDC update fail(010).
 752         iw_err-vbeln = iw_ins-vbeln.
 753         iw_err-xblnr = iw_ins-xblnr.
 754         iw_err-putda = w_date.
 755         iw_err-putti = w_time.
 756         INSERT zc0000sdt0020 FROM iw_err.
 757         CLEAR:iw_err,w_msg_txt.
 758         fw_ret = X.
 759       ENDIF.
 760 
 761     ENDIF.
 762   ENDIF.
 763   CHECK fw_ret IS INITIAL.
 764   SELECT COUNT(*)
 765     FROM zc0000sdt0020
 766     INTO lw_count
 767     WHERE vbeln = iw_ins-vbeln.
 768   IF lw_count > 1.
 769     DELETE FROM zc0000sdt0020 WHERE vbeln = iw_ins-vbeln.
 770     IF sy-subrc = 0.
 771       COMMIT WORK AND WAIT.
 772     ELSE.
 773       ROLLBACK WORK.
 774     ENDIF.
 775   ENDIF.
 776   CLEAR:it_bseg.
 777 ENDFORM.                    " frm_writeback
 778 *&---------------------------------------------------------------------*
 779 *&      Module  STATUS_9000  OUTPUT
 780 *&---------------------------------------------------------------------*
 781 *       text
 782 *----------------------------------------------------------------------*
 783 MODULE status_9000 OUTPUT.
 784   SET PF-STATUS 800.
 785   SET TITLEBAR ERROR LOG SEARCH.
 786 
 787 ENDMODULE.                 " STATUS_9000  OUTPUT
 788 *&---------------------------------------------------------------------*
 789 *&      Module  USER_COMMAND_9000  INPUT
 790 *&---------------------------------------------------------------------*
 791 *       text
 792 *----------------------------------------------------------------------*
 793 MODULE user_command_9000 INPUT.
 794   CASE ok_code.
 795     WHEN EXECUTE.
 796       PERFORM frm_data_select.
 797 
 798       IF it_errlog IS INITIAL.
 799         MESSAGE e001(00) WITH NO error log data(011).
 800         LEAVE TO SCREEN 9000.
 801       ENDIF.
 802 *  ALV最后结果输出
 803       PERFORM frm_display_data.
 804     WHEN CANCEL.
 805       LEAVE TO SCREEN 0.
 806     WHEN EXIT.
 807       LEAVE PROGRAM.
 808     WHEN BACK.
 809       LEAVE TO SCREEN 0.
 810   ENDCASE.
 811 ENDMODULE.                 " USER_COMMAND_9000  INPUT
 812 *----------------------------------------------------------------------*
 813 *  子程序名称 :ALV最后结果输出
 814 *  子程序名   :frm_display_data
 815 *  概要       :ALV最后结果输出
 816 * 参数       :无
 817 *  返回值     :无
 818 *----------------------------------------------------------------------*
 819 FORM frm_display_data .
 820   w_repid = sy-repid.
 821   CALL FUNCTION REUSE_ALV_GRID_DISPLAY
 822     EXPORTING
 823       i_callback_program = w_repid
 824       i_structure_name   = ZC0000SDT0020
 825       it_fieldcat        = it_fieldcat
 826     TABLES
 827       t_outtab           = it_errlog.
 828   IF sy-subrc <> 0.
 829 * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
 830 *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
 831   ENDIF.
 832 
 833 ENDFORM.                    " frm_display_data
 834 *&---------------------------------------------------------------------*
 835 *&      Form  frm_data_select
 836 *&---------------------------------------------------------------------*
 837 *       text
 838 *----------------------------------------------------------------------*
 839 *  -->  p1        text
 840 *  <--  p2        text
 841 *----------------------------------------------------------------------*
 842 FORM frm_data_select .
 843   IF zc0000sdt0020-filen IS NOT INITIAL.
 844     CONCATENATE FILEN LIKE ‘‘‘ zc0000sdt0020-filen %‘‘‘ INTO w_str.
 845   ENDIF.
 846 **************** putda**************************************
 847   IF zc0000sdt0020-putda IS NOT INITIAL AND putdahigh IS INITIAL.
 848     IF w_str IS NOT INITIAL.
 849       CONCATENATE w_str  and putda = ZC0000SDT0020-putda INTO w_str.
 850     ELSE.
 851       w_str = putda = ZC0000SDT0020-putda.
 852     ENDIF.
 853   ENDIF.
 854   IF zc0000sdt0020-putda IS INITIAL AND putdahigh IS NOT INITIAL.
 855     IF w_str IS NOT INITIAL.
 856       CONCATENATE w_str  and putda = putdahigh INTO w_str.
 857     ELSE.
 858       w_str = putda = putdahigh.
 859     ENDIF.
 860   ENDIF.
 861   IF zc0000sdt0020-putda IS NOT INITIAL AND putdahigh IS NOT INITIAL.
 862     IF w_str IS NOT INITIAL.
 863       CONCATENATE w_str  and putda <= putdahigh and putda >= ZC0000SDT0020-putda INTO w_str.
 864     ELSE.
 865       w_str = putda <= putdahigh and putda >= ZC0000SDT0020-putda.
 866     ENDIF.
 867 
 868   ENDIF.
 869 *  **************** putti**************************************
 870   IF zc0000sdt0020-putti IS NOT INITIAL AND puttihigh IS INITIAL.
 871     IF w_str IS NOT INITIAL.
 872       CONCATENATE w_str  and putti = ZC0000SDT0020-putti INTO w_str.
 873     ELSE.
 874       w_str = putti = ZC0000SDT0020-putti.
 875     ENDIF.
 876   ENDIF.
 877   IF zc0000sdt0020-putti IS INITIAL AND puttihigh IS NOT INITIAL.
 878     IF w_str IS NOT INITIAL.
 879       CONCATENATE w_str  and putti = puttihigh INTO w_str.
 880     ELSE.
 881       w_str = putti = puttihigh.
 882     ENDIF.
 883   ENDIF.
 884   IF zc0000sdt0020-putti IS NOT INITIAL AND puttihigh IS NOT INITIAL.
 885     IF w_str IS NOT INITIAL.
 886       CONCATENATE w_str  and putti <= puttihigh and putti >= ZC0000SDT0020-putti INTO w_str.
 887     ELSE.
 888       w_str = putti <= puttihigh and putti >= ZC0000SDT0020-putti.
 889     ENDIF.
 890 
 891   ENDIF.
 892 *  **************** VBELN**************************************
 893   IF zc0000sdt0020-vbeln IS NOT INITIAL AND vbelnhigh IS INITIAL.
 894     IF w_str IS NOT INITIAL.
 895       CONCATENATE w_str  and VBELN = ZC0000SDT0020-VBELN INTO w_str.
 896     ELSE.
 897       w_str = VBELN = ZC0000SDT0020-VBELN.
 898     ENDIF.
 899   ENDIF.
 900   IF zc0000sdt0020-vbeln IS INITIAL AND vbelnhigh IS NOT INITIAL.
 901     IF w_str IS NOT INITIAL.
 902       CONCATENATE w_str  and VBELN = VBELNHIGH INTO w_str.
 903     ELSE.
 904       w_str = VBELN = VBELNHIGH.
 905     ENDIF.
 906   ENDIF.
 907   IF zc0000sdt0020-vbeln IS NOT INITIAL AND vbelnhigh IS NOT INITIAL.
 908     IF w_str IS NOT INITIAL.
 909       CONCATENATE w_str  and VBELN <= VBELNHIGH and VBELN >= ZC0000SDT0020-VBELN INTO w_str.
 910     ELSE.
 911       w_str = VBELN <= VBELNHIGH and VBELN >= ZC0000SDT0020-VBELN.
 912     ENDIF.
 913 
 914   ENDIF.
 915 *  **************** XBLNR**************************************
 916   IF zc0000sdt0020-xblnr IS NOT INITIAL AND xblnrhigh IS INITIAL.
 917     IF w_str IS NOT INITIAL.
 918       CONCATENATE w_str  and XBLNR = ZC0000SDT0020-XBLNR INTO w_str.
 919     ELSE.
 920       w_str = XBLNR = ZC0000SDT0020-XBLNR.
 921     ENDIF.
 922   ENDIF.
 923   IF zc0000sdt0020-xblnr IS INITIAL AND xblnrhigh IS NOT INITIAL.
 924     IF w_str IS NOT INITIAL.
 925       CONCATENATE w_str  and XBLNR = XBLNRHIGH INTO w_str.
 926     ELSE.
 927       w_str = XBLNR = XBLNRHIGH.
 928     ENDIF.
 929   ENDIF.
 930   IF zc0000sdt0020-xblnr IS NOT INITIAL AND xblnrhigh IS NOT INITIAL.
 931     IF w_str IS NOT INITIAL.
 932       CONCATENATE w_str  and XBLNR <= XBLNRHIGH and XBLNR >= ZC0000SDT0020-XBLNR INTO w_str.
 933     ELSE.
 934       w_str = XBLNR <= XBLNRHIGH and XBLNR >= ZC0000SDT0020-XBLNR.
 935     ENDIF.
 936 
 937   ENDIF.
 938 *  **************** ERRIN**************************************
 939   IF zc0000sdt0020-errin IS NOT INITIAL.
 940     IF w_str IS NOT INITIAL.
 941       CONCATENATE w_str  and ERRIN LIKE ‘‘‘ zc0000sdt0020-errin %‘‘‘ INTO w_str.
 942     ELSE.
 943       CONCATENATE ERRIN LIKE ‘‘‘ zc0000sdt0020-errin %‘‘‘ INTO w_str.
 944     ENDIF.
 945   ENDIF.
 946   SELECT zwrit
 947          filen
 948          putda
 949          putti
 950          vbeln
 951          xblnr
 952          errin
 953   INTO CORRESPONDING FIELDS OF TABLE it_errlog
 954   FROM zc0000sdt0020
 955   WHERE (w_str).
 956   CLEAR:w_str.
 957 ENDFORM.                    " frm_data_select
 958 *&---------------------------------------------------------------------*
 959 *&      Form  frm_vbrk_xblnr
 960 *&---------------------------------------------------------------------*
 961 *       text
 962 *----------------------------------------------------------------------*
 963 *      -->pf_xblnr  text
 964 *      -->pf_vbeln  text
 965 *----------------------------------------------------------------------*
 966 FORM frm_vbrk_xblnr  USING  pf_xblnr
 967                             pf_vbeln.
 968 
 969   CALL FUNCTION UPDATE_XBLNR_IN_VBRK
 970     EXPORTING
 971       i_vbeln                 = pf_vbeln
 972       i_xblnr                 = pf_xblnr
 973 *   I_XBLNR_CHECK           =
 974 * IMPORTING
 975 *   E_XBLNR                 =
 976    EXCEPTIONS
 977      document_blocked        = 1
 978      update_no_success       = 2
 979      OTHERS                  = 3
 980             .
 981   IF sy-subrc <> 0.
 982     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
 983      INTO w_msg_txt
 984             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
 985   ENDIF.
 986 
 987 ENDFORM.                    " FRM_VBRK_BDC
 988 *&---------------------------------------------------------------------*
 989 *&      Form  FRM_FILE_PROCESS_LOCAL
 990 *&---------------------------------------------------------------------*
 991 *       text
 992 *----------------------------------------------------------------------*
 993 *  -->  p1        text
 994 *  <--  p2        text
 995 *----------------------------------------------------------------------*
 996 FORM frm_file_process_local.
 997   DATA: ls_row         TYPE kcdu_srec,
 998         lw_zwrit       TYPE i.
 999 
1000   PERFORM file_format_check.
1001   PERFORM upload_csv.
1002 
1003 *   文件数据传送接口表
1004   DO.
1005     w_row_num = sy-index.
1006     CLEAR ls_row.
1007     "    w_step_ok = X.
1008     CALL FUNCTION FILE_NEXT_RECORD
1009       IMPORTING
1010         next_record = ls_row
1011       EXCEPTIONS
1012         no_record   = 1.
1013     IF sy-subrc <> 0 OR ls_row IS INITIAL.
1014       IF w_row_num = 1.
1015         PERFORM frm_get_errno CHANGING lw_zwrit.
1016         iw_err-zwrit = lw_zwrit.
1017         iw_err-filen = w_lfile.
1018         iw_err-errin = FILE NO DATA(002).
1019         iw_err-putda = w_date.
1020         iw_err-putti = w_time.
1021         INSERT zc0000sdt0020 FROM iw_err.
1022         CLEAR:iw_err.
1023         w_ret = X.
1024       ENDIF.
1025       EXIT.
1026     ENDIF.
1027 
1028 *     第一行不是标题
1029 *      IF lw_loopc = 1.
1030 *        CONTINUE.
1031 *      ENDIF.
1032 *     拆分数据并加入接口表
1033 *      0090036259 LR  0000300713  20140525  123456  3000
1034 *  vbeln fkart 客户代码   金税号
1035     CHECK  w_ret IS INITIAL.
1036     PERFORM frm_separate_text USING ls_row
1037                               CHANGING w_ret.
1038     CHECK  w_ret IS INITIAL.
1039     PERFORM frm_writeback CHANGING w_ret.
1040 
1041   ENDDO.
1042 
1043 ENDFORM.                    " frm_file_process_local
1044 *&---------------------------------------------------------------------*
1045 *&      Form  form_get_file_path_upload
1046 *&---------------------------------------------------------------------*
1047 *       text
1048 *----------------------------------------------------------------------*
1049 *  -->  p1        text
1050 *  <--  p2        text
1051 *----------------------------------------------------------------------*
1052 FORM form_get_file_path_upload .
1053   DATA:
1054       ld_rc    TYPE i,
1055       lw_file  TYPE string,
1056       lt_file  TYPE filetable.
1057 
1058   CALL FUNCTION GET_DYNP_VALUE
1059     EXPORTING
1060       i_field = P_FLPATH
1061       i_repid = sy-repid
1062       i_dynnr = 1000
1063     CHANGING
1064       o_value = p_flpath.
1065 
1066   lw_file = p_flpath.
1067 
1068   CALL FUNCTION CH_SPLIT_FILENAME
1069     EXPORTING
1070       complete_filename = lw_file
1071     IMPORTING
1072       path              = w_file_path
1073     EXCEPTIONS
1074       invalid_drive     = 1
1075       invalid_path      = 2
1076       OTHERS            = 3.
1077 
1078   CALL METHOD cl_gui_frontend_services=>file_open_dialog
1079     EXPORTING
1080 *      window_title            =
1081       default_extension       = *.TXT
1082       default_filename        = lw_file
1083       file_filter             = *.TXT
1084 *      with_encoding           =
1085       initial_directory       = w_file_path
1086 *      multiselection          =
1087     CHANGING
1088       file_table              = lt_file
1089       rc                      = ld_rc
1090 *      user_action             =
1091 *      file_encoding           =
1092     EXCEPTIONS
1093       file_open_dialog_failed = 1
1094       cntl_error              = 2
1095       error_no_gui            = 3
1096       not_supported_by_gui    = 4
1097       OTHERS                  = 5.
1098   IF sy-subrc <> 0.
1099     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
1100                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
1101   ELSE.
1102     READ TABLE lt_file INTO lw_file INDEX 1.
1103     p_flpath = lw_file.
1104   ENDIF.
1105 
1106 ENDFORM.                    " form_get_file_path_upload
1107 
1108 *&---------------------------------------------------------------------*
1109 *&      Form  file_format_check
1110 *&---------------------------------------------------------------------*
1111 *       text
1112 *----------------------------------------------------------------------*
1113 *  -->  p1        text
1114 *  <--  p2        text
1115 *----------------------------------------------------------------------*
1116 FORM file_format_check .
1117   DATA:ld_ext   TYPE char10,
1118        lw_file  TYPE string,
1119        lw_name  TYPE string.
1120   lw_file = p_flpath.
1121   CALL FUNCTION CH_SPLIT_FILENAME
1122     EXPORTING
1123       complete_filename = lw_file
1124     IMPORTING
1125       extension         = ld_ext
1126       name              = lw_name
1127       name_with_ext     = w_lfile
1128     EXCEPTIONS
1129       invalid_drive     = 1
1130       invalid_path      = 2
1131       OTHERS            = 3.
1132   IF sy-subrc <> 0.
1133     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
1134             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO iw_errlog-str.
1135     APPEND iw_errlog TO it_errlog2.
1136     w_ret = X.
1137   ENDIF.
1138 
1139   IF sy-subrc <> 0.
1140     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
1141             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
1142   ELSE.
1143     CALL FUNCTION AIPC_CONVERT_TO_UPPERCASE
1144       EXPORTING
1145         i_input  = ld_ext
1146         i_langu  = sy-langu
1147       IMPORTING
1148         e_output = ld_ext.
1149   ENDIF.
1150 ENDFORM.                    " file_format_check
1151 *&---------------------------------------------------------------------*
1152 *&      Form  upload_csv
1153 *&---------------------------------------------------------------------*
1154 *       text
1155 *----------------------------------------------------------------------*
1156 *  -->  p1        text
1157 *  <--  p2        text
1158 *----------------------------------------------------------------------*
1159 FORM upload_csv .
1160   DATA:ld_file TYPE localfile.
1161 
1162   ld_file = p_flpath.
1163 
1164   CALL FUNCTION FILE_OPEN
1165     EXPORTING
1166       filnm             = ld_file
1167       upl               = X
1168       filfmt            = T
1169     EXCEPTIONS
1170       logname_not_found = 1
1171       file_not_opened   = 2
1172       OTHERS            = 3.
1173   IF sy-subrc <> 0.
1174     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
1175             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO iw_errlog-str.
1176     APPEND iw_errlog TO it_errlog2.
1177     w_ret = X.
1178   ENDIF.
1179 ENDFORM.                    " upload_csv
1180 *&---------------------------------------------------------------------*
1181 *&      Form  FRM_BSEG_UPDATE
1182 *&---------------------------------------------------------------------*
1183 *       text
1184 *----------------------------------------------------------------------*
1185 *      -->pf_bukrs  text
1186 *      -->pf_belnr  text
1187 *      -->pf_gjahr  text
1188 *      -->pf_buzei  text
1189 *      -->pf_bschl  text
1190 *      -->pf_bktxt  text
1191 *----------------------------------------------------------------------*
1192 FORM frm_bseg_update USING pf_bukrs
1193                            pf_belnr
1194                            pf_gjahr
1195                            pf_buzei
1196                            pf_bschl
1197                            pf_bktxt. "Linda 20141117
1198   DATA:iw_buztab TYPE tpit_buztab,
1199        iw_fldtab TYPE tpit_fname.
1200 
1201 *   所改字段之值
1202 *  iw_bseg-sgtxt   = pf_sgtxt. "Linda 20141117 edi
1203   iw_bseg-sgtxt    = pf_bktxt.
1204 
1205   iw_buztab-bukrs  = pf_bukrs.
1206   iw_buztab-belnr  = pf_belnr.
1207   iw_buztab-gjahr  = pf_gjahr.
1208   iw_buztab-buzei  = pf_buzei.
1209   iw_buztab-bschl  = pf_bschl. "posting key
1210 *    it_buztab-koart  = S.    "leixing
1211   APPEND iw_buztab TO it_buztab.
1212 
1213   iw_fldtab-fname = SGTXT.
1214   iw_fldtab-aenkz  = X.
1215   APPEND iw_fldtab TO it_fldtab.
1216 
1217 * copy from FI_ITEMS_MASS_CHANGE , change defult module from asynchronous to synchronous
1218   CALL FUNCTION Z_FI_ITEMS_MASS_CHANGE
1219     EXPORTING
1220       s_bseg     = iw_bseg
1221       i_bktxt    = pf_bktxt
1222     IMPORTING
1223       errtab     = it_errtab
1224     TABLES
1225       it_buztab  = it_buztab
1226       it_fldtab  = it_fldtab
1227     EXCEPTIONS
1228       bdc_errors = 1
1229       OTHERS     = 2.
1230   IF sy-subrc = 0.
1231     COMMIT WORK AND WAIT.
1232   ELSE.
1233     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
1234         WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO w_msg_txt.
1235   ENDIF.
1236   CLEAR:it_errtab,it_errtab[],it_buztab,it_buztab[],it_fldtab,it_fldtab[],iw_bseg.
1237 
1238 ENDFORM.                    " FRM_BSEG_UPDATE
1239 *&---------------------------------------------------------------------*
1240 *&      Form  FRM_BSEG_SGTXT
1241 *&---------------------------------------------------------------------*
1242 *       text
1243 *----------------------------------------------------------------------*
1244 *  -->  pf_ins        text
1245 *----------------------------------------------------------------------*
1246 FORM frm_bseg_sgtxt USING pf_ins LIKE iw_ins.
1247   DATA:lw_bseg  TYPE bseg.
1248   LOOP AT it_bseg INTO lw_bseg.
1249 
1250     PERFORM frm_bseg_update USING lw_bseg-bukrs
1251                                   lw_bseg-belnr
1252                                   lw_bseg-gjahr
1253                                   lw_bseg-buzei
1254                                   lw_bseg-bschl
1255                                   pf_ins-bktxt.
1256     IF w_msg_txt IS NOT INITIAL.
1257       EXIT.
1258     ENDIF.
1259   ENDLOOP.
1260 ENDFORM.                    " FRM_BSEG_SGTXT

 

SAP 金税接口代码 供参考

标签:

原文地址:http://www.cnblogs.com/SlashOut/p/4996882.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!