1. 程式人生 > 其它 >sap ALV預設匯出EXCEL 方法

sap ALV預設匯出EXCEL 方法

日常SAP 表格匯出到EXCEL中,有不同的情況發生,通用的方法如下,不用在程式碼中過多的去寫程式碼。

1、在表格上點右鍵,點電子 表格

2、在“從所有可用格式中選擇”下拉框中,選擇33 Excel-現有XXX格式

3、在“輸出到XXL的列表”中,選定"表“。

然後一路對勾就可以了;

示例程式碼:

*&---------------------------------------------------------------------*
*& Report ZFIRP0037
*&---------------------------------------------------------------------*
*& *&---------------------------------------------------------------------* REPORT zfirp0037. TABLES :bseg,kna1. **定義結構 TYPES: BEGIN OF gty_out, bukrs LIKE bseg-bukrs, "公司程式碼 belnr LIKE bseg-belnr, "憑證編號 gjahr LIKE bseg-gjahr, "年度 h_bldat LIKE
bseg-h_bldat, "票據日期 hkont LIKE bseg-hkont, "借方科目 shkzg LIKE bseg-shkzg, "借貸 hkont1 LIKE bseg-hkont, "貸方科目 kunnr LIKE bseg-kunnr, "客戶號 name1 LIKE kna1-name1, "客戶名稱 xref1 LIKE bseg-xref1, "業務員 wrbtr LIKE bseg-wrbtr, "
金額 sgtxt LIKE bseg-sgtxt, "摘要 h_blart LIKE bseg-h_blart, "憑證型別 prctr LIKE bseg-prctr, "利潤中心 h_budat LIKE bseg-h_budat, "過帳日期 END OF gty_out. *標準的ALV輸出 * slis 型別池 全域性變數 定義,多數沒用, DATA: g_repid TYPE sy-repid, g_line TYPE slis_fieldcat_alv, gt_fieldcat TYPE slis_t_fieldcat_alv, gt_layout TYPE slis_layout_alv, gt_sortinfo TYPE slis_sortinfo_alv, gt_lvc_title TYPE lvc_title, gt_list_top_of_page TYPE slis_t_listheader, gt_events TYPE slis_t_event, gt_fcat TYPE lvc_t_fcat, gt_table TYPE REF TO data, gs_settings TYPE lvc_s_glay, f2code LIKE sy-ucomm VALUE '&TEA'. * 定義用於輸出的內表 DATA: gt_tab TYPE STANDARD TABLE OF gty_out. DATA: gt_tab2 TYPE STANDARD TABLE OF gty_out. **定義雙擊執行事務程式碼 用, 猜的 DATA ok_code LIKE sy-ucomm. DATA: g_ucomm LIKE sy-ucomm. DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE."用來儲存螢幕欄位引數值,傳遞錄屏引數 * messages of call transaction DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE."記錄執行BDC過程中產生的訊息 DATA: ls_mss LIKE bdcmsgcoll. *選擇螢幕 SELECT-OPTIONS: s_kunnr FOR bseg-kunnr,"客戶號 s_BUKRS FOR bseg-bukrs,"公司程式碼 s_xref1 FOR bseg-xref1,"業務員 s_ktokd FOR kna1-ktokd,"客戶組 s_pzlx FOR kna1-ktokd,"憑證型別 s_rq FOR bseg-h_bldat OBLIGATORY. **功能 程式 ** 1 正常回款 START-OF-SELECTION. SELECT DISTINCT b~bukrs, b~belnr, b~gjahr, b~h_bldat, a~hkont, b~shkzg, b~hkont, b~kunnr, c~name1, b~xref1, b~wrbtr, b~sgtxt, b~h_blart, b~prctr, b~h_budat INTO TABLE @gt_tab FROM bseg AS a INNER JOIN bseg AS b ON a~bukrs = b~bukrs AND a~belnr = b~belnr AND a~gjahr = b~gjahr INNER JOIN kna1 AS c ON b~kunnr = c~kunnr WHERE ( a~hkont LIKE '1002%' OR a~hkont LIKE '1121%' OR a~hkont LIKE '1012%' ) "1002*銀行存款 1121 應收票據 1012 其它貨幣資金 1122* 應收帳款 AND a~shkzg = 'S' AND ( b~hkont LIKE '1122%' ) AND b~shkzg = 'H' AND b~h_monat <> '000' AND b~kunnr <> '' AND c~ktokd IN @s_ktokd "客戶類別 AND b~bukrs IN @s_bukrs AND b~kunnr IN @s_kunnr AND b~xref1 IN @s_xref1 AND b~h_blart IN @s_pzlx AND b~h_bldat IN @s_rq. **2 處理退款調款 ,需要變為負數 SELECT DISTINCT b~bukrs, b~belnr, b~gjahr, b~h_bldat, a~hkont, b~shkzg, b~hkont, b~kunnr, c~name1, b~xref1, b~wrbtr, b~sgtxt, b~h_blart, b~prctr, b~h_budat INTO TABLE @gt_tab2 FROM bseg AS a INNER JOIN bseg AS b ON a~bukrs = b~bukrs AND a~belnr = b~belnr AND a~gjahr = b~gjahr INNER JOIN kna1 AS c ON b~kunnr = c~kunnr WHERE ( a~hkont LIKE '1002%' OR a~hkont LIKE '1121%' OR a~hkont LIKE '1012%' ) AND a~shkzg = 'H' AND ( b~hkont LIKE '1122%' ) AND b~shkzg = 'S' AND b~h_monat <> '000' AND b~kunnr <> '' AND c~ktokd IN @s_ktokd "客戶類別 AND b~bukrs IN @s_bukrs AND b~kunnr IN @s_kunnr AND b~xref1 IN @s_xref1 AND b~h_blart IN @s_pzlx AND b~h_bldat IN @s_rq. **FIELD-SYMBOL 指標 可直接更改內表字段的值 . LOOP AT gt_tab2 ASSIGNING FIELD-SYMBOL(<fs_out>). <fs_out>-wrbtr = <fs_out>-wrbtr * -1. ENDLOOP. APPEND LINES OF gt_tab2 TO gt_taB. **去掉前導000 LOOP AT gt_tab ASSIGNING FIELD-SYMBOL(<fs_out2>). SHIFT <fs_out2>-kunnr LEFT DELETING LEADING '0'. SHIFT <fs_out2>-belnr LEFT DELETING LEADING '0'. SHIFT <fs_out2>-prctr LEFT DELETING LEADING '0'. ENDLOOP. END-OF-SELECTION. **執行函式 PERFORM frm_show_alv. * 輸出 alv 報表 FORM frm_show_alv . DEFINE append_alv_field. CLEAR g_line. g_line-fieldname = &1. g_line-tabname = 'GT_ALV'. g_line-reptext_ddic = &2. g_line-seltext_l = &2. g_line-seltext_m = &2. g_line-seltext_s = &2. g_line-cfieldname = &3. g_line-ctabname = &4. g_line-no_out = &5. g_line-no_zero = &6. g_line-outputlen = &7. g_line-qfieldname = &8. g_line-just = &9. g_line-ddictxt = 'L'. g_line-do_sum = 'X'. APPEND g_line TO gt_fieldcat. END-OF-DEFINITION. **ALV 顯示欄位 REFRESH:gt_fieldcat. append_alv_field 'bukrs' '公司' '' '' '' '' '' '' ''. append_alv_field 'h_bldat' '票據日期' '' '' '' '' '' '' ''. append_alv_field 'belnr' '憑證號' '' '' '' '' '' '' ''. append_alv_field 'kunnr' '客戶號' '' '' '' '' '' '' ''. append_alv_field 'name1' '客戶名稱' '' '' '' '' '' '' ''. append_alv_field 'xref1' '業務員' '' '' '' '' '' '' ''. append_alv_field 'HKONT' '借方科目' '' '' '' '' '' '' ''. append_alv_field 'SHKZG' '借貸' '' '' '' '' '' '' ''. append_alv_field 'HKONT1' '貸方科目' '' '' '' '' '' '' ''. append_alv_field 'wrbtr' '金額' '' '' '' '' '' '' ''. append_alv_field 'SGTXT' '摘要' '' '' '' '' '' '' ''. append_alv_field 'H_BLART' '型別' '' '' '' '' '' '' ''. append_alv_field 'PRCTR' '利潤中心' '' '' '' '' '' '' ''. append_alv_field 'h_budat' '過帳日期' '' '' '' '' '' '' ''. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = sy-repid * i_callback_pf_status_set = 'FRM_STATUS' "GUI指定子程式 * i_callback_user_command = 'FRM_USER_COMM' "客戶命令指定子程式 is_layout = gt_layout it_fieldcat = gt_fieldcat[] * it_events = events[] TABLES t_outtab = gt_tab[] "指定要顯示的內表名稱 EXCEPTIONS program_error = 1 OTHERS = 2. ENDFORM. ***雙擊聯查原始憑證,引數:憑證號,公司程式碼,年度 *FORM user_command USING i_ucomm LIKE sy-ucomm * is_selfield TYPE slis_selfield. * CASE i_ucomm . * WHEN '&IC1'. * READ TABLE gt_tab INDEX is_selfield-tabindex. * IF sy-subrc = 0. * IF is_selfield-value IS NOT INITIAL. * IF is_selfield-fieldname = 'BELNR'. * SET PARAMETER ID 'BLN' FIELD gt_tab-belnr. * SET PARAMETER ID 'GJR' FIELD gt_tab-gjahr. * ENDIF. * * SET PARAMETER ID 'BUK' FIELD gt_tab-bukrs. * * CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN. * ENDIF. * ENDIF. *ENDFORM. * *MODULE user_command_0100 INPUT. * CASE ok_code. * WHEN 'OK'. * * LEAVE TO SCREEN 0. * WHEN 'CAN'. * LEAVE TO SCREEN 0. * WHEN OTHERS. * ENDCASE. *ENDMODULE. **在ACDOCA表中,公司程式碼RBUKRS,會計年度GJAHR,借貸標識DRCRK,期間POPER(排除期間為00),科目號RACCT,利潤中心PRCTR,客戶KUNNR,公司程式碼貨幣RHCUR,以公司程式碼貨幣計金額 HSL, *1)以公司程式碼,年度,期間 為選擇條件,篩選出憑證編碼BELNR為集合一 *2)在集合一的基礎上,篩選出滿足: *(借貸標識DRCRK=S,科目號RACCT=1002*或者1121*,借貸標識DRCRK=H,科目號RACCT=1122* )或者 *(借貸標識DRCRK=S,科目號RACCT=1122*,借貸標識DRCRK=H,科目號RACCT=1002*或者1121*)的憑證編碼為集合二 *3)取集合二兩種情況的應收賬款RACCT=1122* 所在行的公司程式碼金額HSL,以及客戶KUNNR(客戶為空的排除掉),利潤中心PRCTR,金額求和之後乘以負一 *舉例:借方1002*貸方1122*滿足,借方1121*貸方1122*滿足,借1002*借1121*貸1122*貸1122*多借多貸也滿足
活到老,學到老。