Пример заполнения веса брутто в функции BAPI_MATERIAL_SAVEDATA

Нам необходимо передать запись в таблице UNITOFMEASURE для базовой единицы измерения вместе со значением веса брутто и единицей веса брутто.

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
*&---------------------------------------------------------------------*
*& Report  ZHM_CHANGE_MATERIAL_WEIGHT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zhm_change_material_weight.

TYPES:BEGIN OF ty_mara,
        matnr TYPE mara-matnr,
        brgew TYPE mara-brgew,
        ntgew TYPE mara-ntgew,
        gewei TYPE mara-gewei,
        meins TYPE mara-meins,
        matnr_ext TYPE materialid-matnr_ext,
      END OF ty_mara.

DATA:
      lt_mara_not_semi TYPE TABLE OF ty_mara,
      lt_mara_semi TYPE TABLE OF ty_mara,
      like_string TYPE string.

DATA:
      ls_headdata LIKE bapimathead,
      ls_client_data TYPE bapi_mara,
      ls_client_datax TYPE bapi_marax,
      ls_return2 TYPE bapiret2,
      lt_unitsofmeasure TYPE TABLE OF bapi_marm,
      lt_unitsofmeasurex TYPE TABLE OF bapi_marmx,
      ls_unitsofmeasure TYPE bapi_marm,
      ls_unitsofmeasurex TYPE bapi_marmx.

FIELD-SYMBOLS:
               <fs_mara_not_semi> LIKE LINE OF lt_mara_not_semi,
               <fs_mara_semi> LIKE LINE OF lt_mara_semi.


SELECT *
  UP TO 1000 ROWS
  FROM mara
    INNER JOIN materialid
      ON materialid~matnr_int = mara~matnr
  INTO CORRESPONDING FIELDS OF TABLE lt_mara_not_semi
  WHERE ( brgew > 0 OR ntgew > 0 ) AND matnr_ext NOT LIKE '%\%' AND ( zbesk = 'P' OR zbesk = 'T' ).

LOOP AT lt_mara_not_semi ASSIGNING <fs_mara_not_semi>.
  CONCATENATE <fs_mara_not_semi>-matnr_ext '%\%' INTO like_string.
  SELECT *
    FROM mara
    INNER JOIN materialid
    ON materialid~matnr_int = mara~matnr
    INTO CORRESPONDING FIELDS OF TABLE lt_mara_semi
    WHERE matnr_ext LIKE like_string.

  LOOP AT lt_mara_semi ASSIGNING <fs_mara_semi>.
    ls_headdata-material = <fs_mara_semi>-matnr.
    ls_client_data-net_weight = <fs_mara_not_semi>-ntgew.
    ls_client_data-unit_of_wt = <fs_mara_not_semi>-gewei.
    ls_client_datax-net_weight = 'X'.
    ls_client_datax-unit_of_wt = 'X'.

    ls_unitsofmeasure-alt_unit   = <fs_mara_semi>-meins.
    ls_unitsofmeasure-gross_wt = ls_client_data-net_weight.
    CLEAR lt_unitsofmeasure.
    APPEND ls_unitsofmeasure TO lt_unitsofmeasure.

    ls_unitsofmeasurex-alt_unit = ls_unitsofmeasure-alt_unit.
    ls_unitsofmeasurex-gross_wt = 'X'.
    CLEAR lt_unitsofmeasurex.
    APPEND ls_unitsofmeasurex TO lt_unitsofmeasurex.

    CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
      EXPORTING
        headdata                    = ls_headdata
        clientdata                  = ls_client_data
        clientdatax                 = ls_client_datax
     IMPORTING
        return                      = ls_return2
     TABLES
       unitsofmeasure              = lt_unitsofmeasure
       unitsofmeasurex             = lt_unitsofmeasurex
              .
  ENDLOOP.
ENDLOOP.

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

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