Batch Add item to VA02 Sales Order

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
class-methods ADD_ITEM_IN_VA02_ORDER_BDC
  importing
    !IV_VBELN type VBELN
    !IT_MATNR_QNT type ZHM_T_MATNR_QNT .
METHOD add_item_in_va02_order_bdc.
  DATA:
        bdcdata TYPE TABLE OF bdcdata,
        lt_messtab TYPE TABLE OF bdcmsgcoll,
        lv_vbeln TYPE bdc_fval,
        lv_qnt TYPE bdc_fval,
        lv_matnr TYPE bdc_fval,
        ls_opt TYPE ctu_params.

  FIELD-SYMBOLS:
                 <fs_matnr_qnt> LIKE LINE OF it_matnr_qnt.

  lv_vbeln = iv_vbeln.

  bdc_dynpro( EXPORTING program = 'SAPMV45A' dynpro = '0102'
  CHANGING bdcdata = bdcdata ).
  bdc_fields( EXPORTING fnam = 'BDC_CURSOR' fval = 'VBAK-VBELN'
    CHANGING bdcdata = bdcdata ).
  bdc_fields( EXPORTING fnam = 'BDC_OKCODE' fval = '/00'
    CHANGING bdcdata = bdcdata ).
  bdc_fields( EXPORTING fnam = 'VBAK-VBELN' fval = lv_vbeln
    CHANGING bdcdata = bdcdata ).

  bdc_dynpro( EXPORTING program = 'SAPMV45A' dynpro = '4001'
    CHANGING bdcdata = bdcdata ).
  bdc_fields( EXPORTING fnam = 'BDC_OKCODE' fval = '=POAN'
    CHANGING bdcdata = bdcdata ).
  bdc_fields( EXPORTING fnam = 'BDC_CURSOR' fval = 'RV45A-MABNR(01)'
    CHANGING bdcdata = bdcdata ).

  LOOP AT it_matnr_qnt ASSIGNING <fs_matnr_qnt>.
    lv_matnr = <fs_matnr_qnt>-matnr.
    move <fs_matnr_qnt>-qnt to lv_qnt.

    bdc_dynpro( EXPORTING program = 'SAPMV45A' dynpro = '4001'
      CHANGING bdcdata = bdcdata ).
    bdc_fields( EXPORTING fnam = 'BDC_OKCODE' fval = 'POAN'
      CHANGING bdcdata = bdcdata ).
    bdc_fields( EXPORTING fnam = 'BDC_CURSOR' fval = 'RV45A-MABNR(02)'
      CHANGING bdcdata = bdcdata ).
    bdc_fields( EXPORTING fnam = 'RV45A-MABNR(02)' fval = lv_matnr
      CHANGING bdcdata = bdcdata ).
    bdc_fields( EXPORTING fnam = 'RV45A-KWMENG(02)' fval = lv_qnt
      CHANGING bdcdata = bdcdata ).
  ENDLOOP.

  bdc_dynpro( EXPORTING program = 'SAPMV45A' dynpro = '4001'
    CHANGING bdcdata = bdcdata ).
  bdc_fields( EXPORTING fnam = 'BDC_OKCODE' fval = '=SICH'
    CHANGING bdcdata = bdcdata ).
  bdc_fields( EXPORTING fnam = 'BDC_CURSOR' fval = 'RV45A-MABNR(03)'
    CHANGING bdcdata = bdcdata ).

  ls_opt-updmode = 'S'.
  ls_opt-dismode = 'E'.

  REFRESH lt_messtab.

  CALL TRANSACTION 'VA02' USING bdcdata
        OPTIONS FROM ls_opt
        MESSAGES INTO lt_messtab.
ENDMETHOD.


PROGRAM Importing Type  BDC_PROG
DYNPRO  Importing Type  BDC_DYNR
BDCDATA Changing  Type  STANDARD TABLE
method BDC_DYNPRO.
  DATA: bdcdata_line TYPE bdcdata.
  CLEAR bdcdata_line.
  bdcdata_line-PROGRAM  = PROGRAM.
  bdcdata_line-DYNPRO   = DYNPRO.
  bdcdata_line-dynbegin = 'X'.
  APPEND bdcdata_line TO bdcdata.
endmethod.

FNAM  Importing Type  FNAM_____4
FVAL  Importing Type  BDC_FVAL
BDCDATA Changing  Type  STANDARD TABLE
method BDC_FIELDS.
  DATA: bdcdata_line TYPE bdcdata.
  CLEAR bdcdata_line.
  bdcdata_line-fnam = fnam.
  bdcdata_line-fval = fval.
  APPEND bdcdata_line TO bdcdata.
endmethod.

Добавить комментарий

Ваш адрес email не будет опубликован.