ALV 可编辑保存,SMARTFORM打印
*&---------------------------------------------------------------------*
*& Report ZCFIR_005
*&
*&---------------------------------------------------------------------*
*&Debit/Credit Memo
*&
*&---------------------------------------------------------------------*
REPORT ZCFIR_005.
TABLES: VBRK,VBRP,KNA1,KNB1,T001,ZCTFI001.
TABLES: vbak, ztsd001 , vbap , marc,makt,konv.
TYPE-POOLS:slis.
*CLASS lcl_event_receiver DEFINITION DEFERRED.
DATA:gt_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
DATA:gs_layout TYPE slis_layout_alv.
DATA:g_repid LIKE sy-repid VALUE sy-repid.
DATA:gd_prntparams TYPE slis_print_alv.
DATA:w_layout TYPE slis_layout_alv.
DATA:g_proname TYPE tdsfname.
DATA:g_name TYPE rs38l_fnam.
DATA:w_ssfctrlop TYPE ssfctrlop.
DATA: control_parameters TYPE ssfctrlop,
output_options TYPE ssfcompop,
w_title TYPE zbtmm003,
g_company TYPE t001-butxt,
t_body TYPE TABLE OF zbtmm004 WITH HEADER LINE.
"DATA:alv_events TYPE slis_t_event. " alv events
DATA: user_command TYPE slis_formname VALUE 'USER_COMMAND'.
DEFINE field_frame.
gt_fieldcat-fieldname = &1.
gt_fieldcat-seltext_l = &2.
append gt_fieldcat.
clear gt_fieldcat.
END-OF-DEFINITION.
TYPES:BEGIN OF TY_MAIN,
BUKRS TYPE VBRK-BUKRS,"公司代码
VKORG TYPE VBRK-VKORG,"销售组织
FKART TYPE VBRK-FKART,"开票类型
FKARTDES TYPE VBRP-ARKTX,"文本描述
VBELN TYPE VBRK-VBELN,"开票凭证
FKDAT TYPE VBRK-FKDAT,"出具发票日期
KUNAG TYPE VBRK-KUNAG,"售达方
WAERK TYPE VBRK-WAERK,"SD 凭证货币
NETWR TYPE VBRK-NETWR,"净价值
T_STRING TYPE STRING,"金额大小描述
NAME TYPE KNA1-NAME1,"客户名称
ADRNR TYPE KNA1-ADRNR,"客户地址
ZTERM TYPE KNB1-ZTERM,"付款条件代码
CHARGE TYPE VBRP-ARKTX,"Overcharge/Undercharge
MEMO TYPE VBRP-ARKTX,"MEMO
END OF TY_MAIN.
DATA:GT_ITAB TYPE TABLE OF ZCTFI001 WITH HEADER LINE.
DATA:GT_ITAB2 TYPE TABLE OF ZCTFI001 WITH HEADER LINE.
DATA:W_ITAB TYPE TABLE OF ZCTFI001 WITH HEADER LINE.
DATA:W_ITAB2 TYPE ZCTFI001 .
DATA: T_ITAB TYPE ZCTFI001 .
DATA: ok_code TYPE sy-ucomm.
DATA: save_ok TYPE sy-ucomm.
TYPES: BEGIN OF TY_TAB1 ,
BUKRS TYPE VBRK-BUKRS,"公司代码
VKORG TYPE VBRK-VKORG,"销售组织
FKART TYPE VBRK-FKART,"开票类型
VBELN TYPE VBRK-VBELN,"开票凭证
FKDAT TYPE VBRK-FKDAT,"出具发票日期
KUNAG TYPE VBRK-KUNAG,"售达方
WAERK TYPE VBRK-WAERK,"SD 凭证货币
NETWR TYPE VBRK-NETWR,"净价值
POSNR TYPE VBRP-POSNR,"出具发票项目
MATNR TYPE VBRP-MATNR,"物料号
ARKTX TYPE VBRP-ARKTX,"销售订单项目短文本
ARKTX1 TYPE VBRP-ARKTX,"物料号&短文本
VRKME TYPE VBRP-VRKME,"销售单位
FKIMG TYPE VBRP-FKIMG,"实际已开票数量
NETWR1 TYPE VBRP-NETWR,"出具发票项目的凭证货币净值
NETPR TYPE VBRP-NETWR,"单价
CHARGE TYPE VBRP-ARKTX,
"NAME TYPE KNA1-NAME1,"客户名称
"ADRNR TYPE KNA1-ADRNR,"客户地址
"ZTERM TYPE KNB1-ZTERM,"付款条件代码
"T_STRING TYPE STRING,"金额大小描述
TEXT1 TYPE STRING,"数量
TEXT2 TYPE STRING,"单价
TEXT3 TYPE STRING,"项目金额
END OF TY_TAB1.
DATA: GT_ITAB1 TYPE TABLE OF ZCTFI002 WITH HEADER LINE.
DATA: W_ITAB1 TYPE ZCTFI002 .
DATA: NETWR TYPE BSID-DMBTR,"preis,
T_STRING TYPE CHAR200.
TYPES : BEGIN OF ty_header,
BUKRS TYPE VBRK-BUKRS,"公司代码
VKORG TYPE VBRK-VKORG,"销售组织
FKART TYPE VBRK-FKART,"开票类型
FKARTDES TYPE VBRP-ARKTX,"文本描述
VBELN TYPE VBRK-VBELN,"开票凭证
FKDAT TYPE VBRK-FKDAT,"出具发票日期
KUNAG TYPE VBRK-KUNAG,"售达方
WAERK TYPE VBRK-WAERK,"SD 凭证货币
NETWR TYPE VBRK-NETWR,"净价值
T_STRING TYPE STRING,"金额大小描述
NAME TYPE KNA1-NAME1,"客户名称
ADRNR TYPE KNA1-ADRNR,"客户地址
ZTERM TYPE KNB1-ZTERM,"付款条件代码
CHARGE TYPE VBRP-ARKTX,"Overcharge/Undercharge
MEMO TYPE VBRP-ARKTX,"MEMO
END OF ty_header.
DATA: lr_grid TYPE REF TO cl_gui_alv_grid.
DATA: T_RESULT1 TYPE TABLE OF ZCTFI003 .
DATA: W_RESULT1 TYPE ZCTFI003 .
DATA: BOX TYPE CHAR1.
SELECTION-SCREEN BEGIN OF BLOCK BK1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: P_KUNAG FOR VBRK-KUNAG,"客户编号
P_BUKRS FOR VBRK-BUKRS OBLIGATORY DEFAULT '1320'."公司代码
SELECT-OPTIONS: P_VBELN FOR VBRK-VBELN,"发票号
P_FKART FOR VBRK-FKART,"发票类型
P_VKORG FOR VBRK-VKORG OBLIGATORY DEFAULT '1320',"销售组织
P_FKDAT FOR VBRK-FKDAT."发票日期
PARAMETERS:P_BLART like BSIS-BLART,
P_BLDAT like BSID-BLDAT,
P_BLART1 like BSAD-BLART.
PARAMETERS: P_GROUP1 TYPE C RADIOBUTTON GROUP R1 DEFAULT 'X',
P_GROUP2 TYPE C RADIOBUTTON GROUP R1.
SELECTION-SCREEN END OF BLOCK BK1.
START-OF-SELECTION.
IF P_GROUP1 = 'X'.
PERFORM GETDATA.
PERFORM SHOWDATA.
ENDIF.
IF P_GROUP2 = 'X'.
CALL SCREEN 1001 .
ENDIF.
*&---------------------------------------------------------------------*
*& Form GETDATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GETDATA .
SELECT VBRK~BUKRS VBRK~VKORG VBRK~FKART VBRK~VBELN VBRK~FKDAT VBRK~KUNAG VBRK~WAERK VBRK~NETWR "KNA1~NAME1 KNA1~ADRNR KNB1~ZTERM
"VBRP~POSNR VBRP~VRKME VBRP~FKIMG VBRP~NETWR VBRP-MATNR
INTO CORRESPONDING FIELDS OF TABLE W_ITAB"GT_ITAB
FROM VBRK "INNER JOIN KNA1 ON KNA1~KUNNR = VBRK~KUNAG
"INNER JOIN KNB1 ON KNB1~KUNNR = VBRK~KUNAG
WHERE VBRK~VBELN IN P_VBELN"发票号码
AND VBRK~KUNAG IN P_KUNAG"客户编号
AND VBRK~FKART IN P_FKART"发票类型
AND VBRK~VKORG IN P_VKORG"销售组织
AND VBRK~FKDAT IN P_FKDAT"发票日期
AND VBRK~BUKRS IN P_BUKRS."公司代码
LOOP AT W_ITAB."GT_ITAB.
IF W_ITAB-FKART <> 'ZL2'.
W_ITAB-FKARTDES = 'Credit Notes'.
ELSE.
W_ITAB-FKARTDES = 'Debit Notes'.
ENDIF.
SELECT SINGLE * FROM ZCTFI001 WHERE VBELN = W_ITAB-VBELN AND BUKRS = W_ITAB-BUKRS AND VKORG = W_ITAB-VKORG.
IF SY-SUBRC = 0.
W_ITAB-CHARGEDES = ZCTFI001-CHARGEDES ."Overcharge/Undercharge
W_ITAB-MEMO = ZCTFI001-MEMO ."MEMO
ENDIF.
SELECT SINGLE * FROM KNA1 WHERE KUNNR = W_ITAB-KUNAG.
IF SY-SUBRC = 0.
"GT_ITAB-NAME = KNA1-NAME1."名称
"GT_ITAB-ADRNR = KNA1-ADRNR."地址
W_ITAB-NAME = KNA1-NAME1."名称
W_ITAB-STRAS = KNA1-STRAS."住宅号及街道
W_ITAB-LAND1 = KNA1-LAND1."国家代码
W_ITAB-ORT01 = KNA1-ORT01."城市
W_ITAB-REGIO = KNA1-REGIO."地区 (州、省、县)
W_ITAB-PSTLZ = KNA1-PSTLZ."邮政编码
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = W_ITAB-KUNAG
IMPORTING
OUTPUT = W_ITAB-KUNAG1.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = W_ITAB-VBELN
IMPORTING
OUTPUT = W_ITAB-VBELN1.
SELECT SINGLE * FROM KNB1 WHERE KUNNR = W_ITAB-KUNAG AND BUKRS = W_ITAB-BUKRS.
IF SY-SUBRC = 0.
"GT_ITAB-ZTERM = KNB1-ZTERM."付款条件代码
W_ITAB-ZTERM = KNB1-ZTERM."付款条件代码
ENDIF.
* CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
* EXPORTING
* date = sy-datum
* foreign_amount = W_ITAB-NETWR
* foreign_currency = W_ITAB-WAERK
* local_currency = 'USD'
* TYPE_OF_RATE = 'K'
* IMPORTING
* local_amount = NETWR.
NETWR = W_ITAB-NETWR.
CALL FUNCTION 'Z_MONEY_TRANSFORM'
EXPORTING
i_amt = NETWR
IMPORTING
saywords = T_STRING. "i_waers = W_ITAB-WAERK
W_ITAB-T_STRING = T_STRING.
MODIFY W_ITAB."GT_ITAB.
CLEAR NETWR.
CLEAR T_STRING.
ENDLOOP.
LOOP AT W_ITAB INTO T_ITAB." GT_ITAB INTO T_ITAB.
APPEND T_ITAB TO GT_ITAB."W_ITAB.
"MODIFY ZCTFI001 FROM TABLE GT_ITAB.
ENDLOOP.
LOOP AT GT_ITAB."W_ITAB.
SELECT * FROM VBRP WHERE VBELN = GT_ITAB-VBELN.
W_ITAB1-POSNR = VBRP-POSNR .
* W_ITAB1-MATNR = VBRP-MATNR.
* W_ITAB1-ARKTX = VBRP-ARKTX.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = VBRP-MATNR
IMPORTING
OUTPUT = W_ITAB1-MATNR.
W_ITAB1-ARKTX = VBRP-ARKTX.
CONCATENATE W_ITAB1-MATNR ':' W_ITAB1-ARKTX INTO W_ITAB1-MARKTX.
W_ITAB1-VRKME = VBRP-VRKME .
W_ITAB1-FKIMG = VBRP-FKIMG .
W_ITAB1-NETWR = VBRP-NETWR.
IF W_ITAB-FKART <> 'ZL2'.
W_ITAB1-CHARGE = 'overcharge'.
ELSE.
W_ITAB1-CHARGE = 'undercharge'.
ENDIF.
IF W_ITAB1-FKIMG <> '0'.
W_ITAB1-NETPR = W_ITAB1-NETWR / W_ITAB1-FKIMG."单价
ENDIF.
* W_ITAB1-BUKRS = GT_ITAB-BUKRS."公司代码
* W_ITAB1-VKORG = GT_ITAB-VKORG."销售组织
* W_ITAB1-FKART = GT_ITAB-FKART."开票类型
W_ITAB1-VBELN = GT_ITAB-VBELN."开票凭证
* W_ITAB1-FKDAT = GT_ITAB-FKDAT."出具发票日期
* W_ITAB1-KUNAG = GT_ITAB-KUNAG."售达方
* W_ITAB1-WAERK = GT_ITAB-WAERK."SD 凭证货币
* W_ITAB1-NETWR = GT_ITAB-NETWR."净价值
*
* W_ITAB1-TEXT1 = W_ITAB1-FKIMG.
* W_ITAB1-TEXT2 = W_ITAB1-NETPR.
* W_ITAB1-TEXT3 = W_ITAB1-NETWR1.
APPEND W_ITAB1 TO GT_ITAB1.
CLEAR W_ITAB1.
ENDSELECT.
ENDLOOP.
MODIFY ZCTFI002 FROM TABLE GT_ITAB1.
LOOP AT GT_ITAB.
READ TABLE GT_ITAB1 WITH KEY VBELN = GT_ITAB-VBELN.
GT_ITAB-CHARGE = GT_ITAB1-CHARGE.
MODIFY GT_ITAB.
ENDLOOP.
MODIFY ZCTFI001 FROM TABLE GT_ITAB.
"BREAK-POINT.NETWR
ENDFORM. " GETDATA
*&---------------------------------------------------------------------*
*& Form SHOWDATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SHOWDATA .
PERFORM f_init_layout.
PERFORM f_fieldcat.
PERFORM f_output_alv.
ENDFORM. " SHOWDATA
*&---------------------------------------------------------------------*
*& Form F_INIT_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F_INIT_LAYOUT .
gs_layout-colwidth_optimize = 'X'.
w_layout-zebra = 'X'.
w_layout-box_fieldname = 'BUKRS'.
ENDFORM. " F_INIT_LAYOUT
*&---------------------------------------------------------------------*
*& Form F_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F_FIELDCAT .
PERFORM f_init_fieldcat USING 'BUKRS' 'Company Code'.
PERFORM f_init_fieldcat USING 'VKORG' 'Sales organization'.
PERFORM f_init_fieldcat USING 'FKART' 'Billing Doc type'.
PERFORM f_init_fieldcat USING 'VBELN1' 'Billing Doc'.
PERFORM f_init_fieldcat USING 'FKDAT' 'Billing Date'.
PERFORM f_init_fieldcat USING 'KUNAG1' 'Customer number'.
* PERFORM f_init_fieldcat USING 'FKARTDES' '描述'.
"PERFORM f_init_fieldcat USING 'CHARGE' 'Overcharge/Undercharge'.
gt_fieldcat-fieldname = 'CHARGEDES'.
gt_fieldcat-seltext_s = 'O/U charge'.
gt_fieldcat-edit = 'X'.
gt_fieldcat-outputlen = 20.
APPEND gt_fieldcat.
"PERFORM f_init_fieldcat USING 'MEMO' 'MEMO'.
gt_fieldcat-fieldname = 'MEMO'.
gt_fieldcat-seltext_s = 'MEMO'.
gt_fieldcat-edit = 'X'.
gt_fieldcat-outputlen = 30.
APPEND gt_fieldcat.
ENDFORM. " F_FIELDCAT
*&---------------------------------------------------------------------*
*& Form F_OUTPUT_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F_OUTPUT_ALV .
G_REPID = SY-REPID.
GT_ITAB2[] = GT_ITAB[].
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_repid
i_callback_pf_status_set = 'F_STATUS'
i_callback_user_command = 'F_PRINT'
is_layout = w_layout
it_fieldcat = gt_fieldcat[]
i_save = 'X'
"it_events = alv_events " events
TABLES
t_outtab = GT_ITAB2[]" it_events = t_events[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. " F_OUTPUT_ALV
*&---------------------------------------------------------------------*
*& Form F_INIT_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0171 text
* -->P_0172 text
*----------------------------------------------------------------------*
FORM f_init_fieldcat USING p_fieldname p_seltext_l.
field_frame p_fieldname p_seltext_l.
ENDFORM. " F_INIT_FIELDCAT
*&---------------------------------------------------------------------*
*& Form f_status
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM f_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'STANDARD' EXCLUDING rt_extab.
ENDFORM. "f_status
*&---------------------------------------------------------------------*
*& Form f_print
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM f_print USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield..
CASE r_ucomm.
WHEN 'PNT'.
PERFORM f_strartprint.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'SAVE'.
GT_ITAB2[] = GT_ITAB[].
READ TABLE GT_ITAB2 INDEX rs_selfield-tabindex. " 将变动内容更新到内表
DATA: l_grid TYPE REF TO cl_gui_alv_grid.
*------------将ALV上修改的内容保存到内表---------------------------------*
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = l_grid.
CALL METHOD l_grid->check_changed_data.
rs_selfield-refresh = 'X'. "自动刷新
MODIFY ZCTFI001 FROM TABLE GT_ITAB2.
ENDCASE.
ENDFORM. "f_print
*&---------------------------------------------------------------------*
*& Form F_STRARTPRINT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F_STRARTPRINT .
data:count like sy-tabix.
* w_ssfctrlop-preview = 'X'.
* output_options-tddest = 'LP01'.
CLEAR w_ssfctrlop.
clear count.
g_proname = 'ZCFI_003_2'.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = g_proname
* VARIANT = ' '
* DIRECT_CALL = ' '
IMPORTING
fm_name = g_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
clear GT_ITAB[].
LOOP AT GT_ITAB2[] INTO w_itab2 where BUKRS = 'X'.
append w_itab2 to GT_ITAB[].
count = count + 1.
ENDLOOP.
LOOP AT GT_ITAB.
w_ssfctrlop-no_close = 'X'.
IF sy-tabix = count.
w_ssfctrlop-no_close = space.
ENDIF.
CALL FUNCTION g_name
EXPORTING
control_parameters = w_ssfctrlop
output_options = output_options
W_ZCTFI001 = GT_ITAB
TABLES
T_TAB1 = GT_ITAB1[]
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
w_ssfctrlop-no_open = 'X'.
ENDIF.
ENDLOOP.
ENDFORM. " F_STRARTPRINT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_1001 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_1001 INPUT.
save_ok = ok_code.
CASE SAVE_OK.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
WHEN 'CLOSE'.
LEAVE TO SCREEN 0.
WHEN 'INSERT'.
LEAVE TO SCREEN 1002.
WHEN 'PRINT'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_1001 INPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_1001 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_1002 INPUT.
save_ok = ok_code.
CASE SAVE_OK.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
WHEN 'CLOSE'.
LEAVE TO SCREEN 0.
WHEN 'SAVE'.
ENDCASE.
ENDMODULE. " USER_COMMAND_1002 INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_1001 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_1001 OUTPUT.
SET PF-STATUS 'STA1001'.
"SET TITLEBAR 'TIT1001'.
ENDMODULE. " STATUS_1001 OUTPUT