2023年2月

原文地址:http://blog.sina.com.cn/s/blog_ad5dbd0201010qtt.html

公司间需要买卖操作,由于发货和收货都是同一批人在操作,为了减少业务人员的工作量,提高工作效率,特实现以上功能

  1、增强实现:增强点为交货单过账成功时触发,在提交前触发,如果遇到不可预知问题,可能造成数据不一致,所以在过账成功后触发,效果更好。

  2、BADI增强:DELIVERY_PUBLISH:数据库更新期间交货数据的公告,采用方法:PUBLISH_AFTER_SAVE

  3、功能实现:由于该增强没有参数,所以问题的关键是业务数据的获取,采用以下方法获取,其他功能就大家自己具体去实现了,这里只是把关键的地方粘贴出来:

  FIELD-SYMBOLS : <V_VBELN> TYPE LIKP-VBELN.
  FIELD-SYMBOLS : <V_LFART> TYPE LIKP-LFART.
  FIELD-SYMBOLS : <V_LFDAT> TYPE LIKP-LFDAT.
  FIELD-SYMBOLS : <V_VKBUR> TYPE LIKP-VKBUR.
  FIELD-SYMBOLS : <V_MBLNR> TYPE EMKPF-MBLNR.
  DATA : V_VAL TYPE STRING VALUE '(SAPMV50A)LIKP-VBELN'.
  DATA : V_VAL1 TYPE STRING VALUE '(SAPMV50A)LIKP-LFART'.

  DATA : V_VAL2 TYPE STRING VALUE '(SAPMV50A)LIKP-WADAT_IST'.
  DATA : V_VAL3 TYPE STRING VALUE '(SAPMV50A)emkpf-MBLNR'.
  DATA : V_VAL4 TYPE STRING VALUE '(SAPMV50A)LIKP-VKBUR'.
  CLEAR:C_VBELN,C_LFART,C_BUDAT,C_MBLNR,C_YEAR,C_JZRQ,
        C_CPZH,C_WERKS,C_LGORT.
  DATA:I_LOG TYPE TABLE OF ZMDLOG,
       W_LOG TYPE ZMDLOG.
*********获取交货类型
  ASSIGN (V_VAL1) TO <V_LFART>.
  MOVE <V_LFART> TO C_LFART.
*********获取物料凭证
  ASSIGN (V_VAL3) TO <V_MBLNR>.
  MOVE <V_MBLNR> TO C_MBLNR.
*********获取交货单号
  ASSIGN (V_VAL) TO <V_VBELN>.
  MOVE <V_VBELN> TO C_VBELN.
*********销售办公室
  ASSIGN (V_VAL4) TO <V_VKBUR>.
  MOVE <V_VKBUR> TO C_VKBUR.

  4、采购订单自动生产使用BAPI:BAPI_PO_CREATE1

  5、采购收货使用BAPI:BAPI_GOODSMVT_CREATE

  6、当需要交货单冲销时,增强点为交货过账冲销前,要先保证采购收货冲销成功并删除采购订单,才能执行过账冲销,这样才能保证数据的连续性,采购入库冲销的BAPI:BAPI_GOODSMVT_CANCEL

  注意:当交货过账成功,采购订单没有生产时,我们要扑捉异常,同时冲销交货单这样才能保证数据的一致性。

1、include

databegin of gth_qamr.
        include structure qamr.
data: kurztext like qamv-kurztext,
      ztext like qamv-kurztext,
      verwmerkm like qamv-verwmerkm,
      steuerkz  like qamv-steuerkz.
dataend of gth_qamr.
data: gtd_qamr like table of gth_qamr.

 

2、append

 

结构复用:引用自江正军老师-博客园 博客链接:www.cnblogs.com/jiangzhengjun


TYPES BEGIN OF struc_type
   TYPES comp ..
   TYPES comp TYPE struc_type BOXED"参照另一结构类型
   INCLUDE { {TYPE struc_type} | {STRUCTURE struc} } "将另一结构包括进来
        [AS name [RENAMING WITH SUFFIX suffix]]
TYPES END OF struc_type.

 

语句:碰到一个写一个

COLLECT语句用法

用于报表数据的合并计算,如果非数据字段值相等,那么数值字段值相加

内表可以不用排序

LOOP AT gtd_test into gth_test.

  COLLECT gth_test into gtd_sum.
  clear:gth_test.
ENDLOOP.

可以在LOOP循环中先筛选数据后再使用COLLECT语句。

注意事项:collect语句合并所有(类型为I、P、F)的字段,其他类型的字段默认为关键字。

 

SAP内表去重

DELETE ADJACENT DUPLICATES FROM <内表:gtd_out> COMPARING <字段:ALL FIELDS>.

 

DELETE 内表语法

1. DELETE itab[ ].

    用于loop当中,删除当前loop行,read table  会改变sy-tabix的值,但是不影响该语法执行结果

2.DELETE  itab INDEX  i.

     删除内表中的指定行

3.DELETE TABLE itab FROM wa.

       删除内表KEY值与工作区KEY值相同的行,  关键字TABLE不能丢,否则执行会报错

 

ABAP 如何判断调用smartforms时是进行打印还是预览

  DATA: option TYPE ssfcresop."控制参数

smartforms导出PDF:

常用函数有;

convert_otf
convert_otfspooljob_2_pdf
convert_abapspooljob_2_pdf
CONVERT_OTF_2_PDF;
SX_OBJECT_CONVER_OTF_PDF;
HRHAP_DOC_CONVERT_SMF_TO_PDF

实例:

FORMexport_pdf.DATA:zsmart_name TYPErs38l_fnam.CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTINGformname= 'ZLE_SHIP_BMEPR'
    IMPORTINGfm_name=zsmart_nameEXCEPTIONSno_form= 1no_function_module= 2OTHERS= 3.DATA: w_ctrlop TYPE ssfctrlop, "Smart Forms: 控制结构 "W_CONTROL
        w_compop TYPE ssfcompop, "SAP Smart Forms: 智能写作器 (传输) 选项"W_OUTPUT.
        w_return TYPE ssfcrescl. "Smart Forms: 表格打印结束时返回值
  DATA: len TYPEi,
w_filesize
TYPEi,
g_pdf_xstring
TYPExstring,
l_lines
TYPE TABLE OF tline WITH HEADER LINE.DATA doctab TYPE TABLE OF docs WITH HEADER LINE.DATA itab LIKE tline OCCURS 0 WITH HEADER LINE DATA: file_name TYPE string,

fullpath
TYPE string,
path
TYPE string,
p_sefile
LIKE rlgrap-filename VALUE 'D:\'. "'/usr/sap/tmp/'.

w_ctrlop-getotf =
'X'."OTF 表的返回
w_ctrlop-no_dialog =
'X'."关闭打印对话框
* W_CTRLOP-NO_OPEN =
'X'."no dialog box
* W_CTRLOP-NO_CLOSE =
'X'."no

*&W_COMPOP-TDNOPRINT =
'X'.
w_compop-tdnoprev =
'X'."没有打印预览

"W_COMPOP用来设置打印参数弹出对话框中的值,下面这几个参数不必要
* W_COMPOP-TDNEWID =
'X'. "New Spool
w_compop-tdimmed =
'X'.
w_compop-tddelete =
''. "Delete Spool After Print
w_compop-tdfinal =
'X'.
w_compop-tdiexit =
'X'. "Exit after printing in print preview
w_compop-tddest =
'LP02'. "设备名称
w_compop-xdf2outdev =
'LP02'.
w_compop-tdarmod =
'1'.

*&smartforms打印 ,将打印的值输入到W_RETURN-OTFDATA[]中
CALL FUNCTION zsmart_name
EXPORTING
control_parameters = w_ctrlop
output_options = w_compop
* totalpages = totalpages
* zbukrs = p_bukrs
* zcb = cb
gth_header = gth_alv_sel
IMPORTING
job_output_info = w_return
TABLES
gtd_item = gtd_item
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.

*"CONVERT_OTF函数取不到lines的返回值,所以注释掉,用CONVERT_OTF_2_PDF
* CALL FUNCTION
'CONVERT_OTF'* EXPORTING
* format =
'PDF'* IMPORTING
* bin_filesize = len
* bin_file = g_pdf_xstring
* TABLES
* otf = w_return-otfdata[]
* lines = itab
* EXCEPTIONS
* err_max_linewidth = 1
* err_format = 2
* err_conv_not_possible = 3
* err_bad_otf = 4
* OTHERS = 5.

CALL FUNCTION
'CONVERT_OTF_2_PDF'"转换otf数据为二进制PDF文件
* EXPORTING
* use_otf_mc_cmd =
'X'* archive_index = archive_index
IMPORTING
bin_filesize = len
TABLES
otf = w_return-otfdata[]
doctab_archive = doctab
lines = l_lines[]
EXCEPTIONS
err_conv_not_possible = 1
err_otf_mc_noendmarker = 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.

* CONCATENATE p_sefile sy-uname
'-'sy-uzeit'.pdf'INTO file_name. "addrss
* OPEN DATASET file_name FOR OUTPUT IN BINARY MODE." MESSAGE L_MESSAGE_DB.
* IF sy-subrc EQ 0.
* TRANSFER g_pdf_xstring TO file_name.
* CLOSE DATASET file_name.
* ELSE.
* MESSAGE
'OPEN ERROR!!'TYPE'E'.
* STOP.
* ENDIF.

CONCATENATE
'D:\'sy-uname'-'sy-uzeit' FFF.pdf'INTO file_name.

"定义文件名
"这一段不屏蔽, 在打印的时候会有显示选择路径的对话框,屏蔽则直接保存在上面的文件名
"file_name 指定的路径
CALL METHOD cl_gui_frontend_services=>file_save_dialog "保存文件窗口(选择路径)
EXPORTING
default_extension =
'PDF'file_filter ='*.PDF'default_file_name = file_name
CHANGING
filename = file_name
path = path
fullpath = fullpath
* user_action = ua
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.

CALL FUNCTION
'GUI_DOWNLOAD'"保存文件在本地
EXPORTING
bin_filesize = len
filename = file_name
filetype =
'BIN'IMPORTING
filelength = w_filesize
TABLES
data_tab = l_lines[]
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
'File not downloaded'TYPE'I'.
ENDIF.
ENDIF.

ENDFORM. "export_pdf