• 欢迎光临~

ABAP-VLPOD保存自动开票增强

开发技术 开发技术 2022-12-27 次浏览

1.增强点

 1 *一代增强
 2 *包含文件MV50AFZ1
 3 *子例程USEREXIT_SAVE_DOCUMENT
 4   IF sy-tcode = 'VLPOD' AND sy-ucomm = 'SICH_T' .
 5 
 6     READ TABLE xlikp INDEX 1 .
 7     IF xlikp-lfart = 'LF' AND xlikp-pdstk = 'C' .
 8 
 9       DATA: lv_jobnum  TYPE btcjobcnt,
10             gv_jobname TYPE btcjob VALUE 'ZSDE04'. "后台作业名称
11 
12       CALL FUNCTION 'JOB_OPEN'
13         EXPORTING
14           jobname          = gv_jobname
15         IMPORTING
16           jobcount         = lv_jobnum
17         EXCEPTIONS
18           cant_create_job  = 1
19           invalid_job_data = 2
20           jobname_missing  = 3
21           OTHERS           = 4.
22       IF sy-subrc = 0.
23 
24         SUBMIT zsdf_zdkp WITH p_vbeln = likp-vbeln
25                          WITH p_vkorg = likp-vkorg
26                          WITH p_aedat = likp-podat
27                          VIA JOB gv_jobname NUMBER lv_jobnum AND RETURN .
28         IF sy-subrc = 0 .
29 
30           CALL FUNCTION 'JOB_CLOSE'
31             EXPORTING
32               jobcount             = lv_jobnum
33               jobname              = gv_jobname
34               strtimmed            = 'X'
35             EXCEPTIONS
36               cant_start_immediate = 1
37               invalid_startdate    = 2
38               jobname_missing      = 3
39               job_close_failed     = 4
40               job_nosteps          = 5
41               job_notex            = 6
42               lock_failed          = 7
43               invalid_target       = 8
44               invalid_time_zone    = 9
45               OTHERS               = 10.
46 
47         ENDIF .
48 
49       ENDIF.
50     ENDIF .
51 
52   ENDIF .    

2.自开发程序

  1 REPORT zsdf_zdkp.
  2 RANGES: rt_vbeln FOR vbco7-vbeln.
  3 
  4 PARAMETERS: p_vbeln TYPE likp-vbeln.
  5 PARAMETERS: p_vkorg TYPE vbco7-vkorg.
  6 PARAMETERS: p_aedat TYPE likp-aedat.
  7 
  8 DATA:lv_vbeln TYPE likp-vbeln .
  9 DATA: lv_garg TYPE seqg3-garg.
 10 DATA: lt_enq TYPE TABLE OF seqg3.
 11 
 12 CLEAR lv_garg .
 13 CLEAR lv_vbeln .
 14 REFRESH lt_enq .
 15 
 16 CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
 17   EXPORTING
 18     input  = p_vbeln
 19   IMPORTING
 20     output = lv_vbeln.
 21 
 22 CONCATENATE sy-mandt lv_vbeln INTO lv_garg.
 23 
 24 DO 10 TIMES .
 25 
 26   CALL FUNCTION 'ENQUEUE_READ'
 27     EXPORTING
 28       gclient               = sy-mandt
 29       gname                 = 'LIKP'
 30       garg                  = lv_garg
 31       guname                = ''
 32     TABLES
 33       enq                   = lt_enq
 34     EXCEPTIONS
 35       communication_failure = 1
 36       system_failure        = 2
 37       OTHERS                = 3.
 38   IF lt_enq[] IS INITIAL .
 39 
 40     EXIT .
 41 
 42   ELSE .
 43 
 44     WAIT UP TO '0.5' SECONDS.
 45 
 46   ENDIF .
 47 
 48 ENDDO .
 49 
 50 CHECK p_vbeln IS NOT INITIAL.
 51 **  触发自动开票的job
 52 rt_vbeln-sign = 'I'.
 53 rt_vbeln-option = 'EQ'.
 54 rt_vbeln-low = p_vbeln.
 55 APPEND rt_vbeln.
 56 
 57 cl_salv_bs_runtime_info=>set( display = ''
 58                         metadata = ''
 59                         data = 'X' ).
 60 *调用VF06标准程序开票
 61 SUBMIT rv60sbat WITH vkor1 = p_vkorg
 62                 WITH x_vbeln IN rt_vbeln
 63                 WITH allel = 'X'
 64                 WITH exdate = sy-datum
 65                 WITH extime = sy-uzeit
 66                 WITH immedi = 'X'
 67                 WITH vfkda = p_aedat AND RETURN.
 68 CALL METHOD cl_salv_bs_runtime_info=>clear_all.
 69 
 70 *"写入抬头文本
 71 WAIT UP TO 20 SECONDS.
 72 SELECT vbeln FROM vbfa  INTO TABLE @DATA(lt_vbeln) WHERE vbtyp_n = 'M' AND vbelv = @p_vbeln.
 73 DATA :t_read    TYPE TABLE OF tline WITH HEADER LINE,
 74       vl_tdname LIKE thead-tdname.
 75 vl_tdname = p_vbeln.
 76 "读交货单抬头文本
 77 CALL FUNCTION 'READ_TEXT'
 78   EXPORTING
 79     client                  = sy-mandt
 80     id                      = '0001'
 81     language                = sy-langu
 82     name                    = vl_tdname
 83     object                  = 'VBBK'
 84 *   ARCHIVE_HANDLE          = 0
 85 *   LOCAL_CAT               = ' '
 86 * IMPORTING
 87 *   HEADER                  =
 88 *   OLD_LINE_COUNTER        =
 89   TABLES
 90     lines                   = t_read
 91   EXCEPTIONS
 92     id                      = 1
 93     language                = 2
 94     name                    = 3
 95     not_found               = 4
 96     object                  = 5
 97     reference_check         = 6
 98     wrong_access_to_archive = 7
 99     OTHERS                  = 8.
100 IF sy-subrc <> 0.
101 * Implement suitable error handling here
102 ENDIF.
103 "写入开票凭证长文本
104 DATA:ls_theader TYPE thead. "长文本的head
105 
106 ls_theader-tdobject = 'VBBK'."固定值
107 ls_theader-tdid = '0002'."固定值
108 ls_theader-tdspras = sy-langu.
109 LOOP AT lt_vbeln INTO   DATA(ls_vbeln).
110   ls_theader-tdname = ls_vbeln-vbeln."物料编码(如果有前导零的话,一定要补上)
111 
112   CALL FUNCTION 'SAVE_TEXT'
113     EXPORTING
114       client          = sy-mandt
115       header          = ls_theader
116 *     INSERT          = ' '
117       savemode_direct = 'X'
118 *     OWNER_SPECIFIED = ' '
119 *     LOCAL_CAT       = ' '
120 *     KEEP_LAST_CHANGED       = ' '
121 *           IMPORTING
122 *     FUNCTION        =
123 *     NEWHEADER       =
124     TABLES
125       lines           = t_read
126     EXCEPTIONS
127       id              = 1
128       language        = 2
129       name            = 3
130       object          = 4
131       OTHERS          = 5.
132   IF sy-subrc <> 0.
133 * Implement suitable error handling here
134   ENDIF.
135 ENDLOOP.
136 
137 CLEAR: t_read.
程序员灯塔
转载请注明原文链接:ABAP-VLPOD保存自动开票增强
喜欢 (0)