-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathadd-fied-to-table.abap
130 lines (118 loc) · 4.76 KB
/
add-fied-to-table.abap
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
FORM add_dynamic_data.
TYPES: BEGIN OF lst_ausp,
matnr TYPE mara-matnr,
atinn TYPE ausp-atinn,
atwrt TYPE ausp-atwrt,
END OF lst_ausp.
DATA: lv_objek TYPE c LENGTH 18,
lv_max TYPE i,
lt_ausp TYPE TABLE OF lst_ausp,
lr_itab TYPE REF TO data,
lv_count TYPE n LENGTH 2,
lt_ausp_sorted TYPE SORTED TABLE OF lst_ausp WITH NON-UNIQUE KEY matnr.
LOOP AT gt_itab.
SELECT SINGLE cuobj FROM inob
WHERE klart = '026'
AND objek = @gt_itab-matnr
INTO @DATA(lv_cuobj).
IF sy-subrc = 0.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lv_cuobj
IMPORTING
output = lv_objek.
SELECT @gt_itab-matnr, atinn, atwrt FROM ausp
WHERE objek = @lv_objek
AND klart = '026'
APPENDING TABLE @lt_ausp.
IF sy-subrc = 0.
IF sy-dbcnt > lv_max.
lv_max = sy-dbcnt.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
DATA(lt_comp) = CAST cl_abap_structdescr( cl_abap_structdescr=>describe_by_data( gt_itab ) )->get_components( ).
DATA(lt_fcat) = gt_fieldcat[].
SORT lt_fcat BY col_pos DESCENDING.
READ TABLE lt_fcat INTO DATA(ls_fcat) INDEX 1.
FREE lt_fcat.
DO lv_max TIMES.
lv_count = sy-index.
APPEND INITIAL LINE TO lt_comp ASSIGNING FIELD-SYMBOL(<ls_comp>).
<ls_comp>-name = 'ATINN' && lv_count.
<ls_comp>-type ?= cl_abap_elemdescr=>describe_by_name( 'ATINN' ).
APPEND INITIAL LINE TO gt_fieldcat ASSIGNING FIELD-SYMBOL(<ls_fcat>).
<ls_fcat>-fieldname = <ls_comp>-name.
<ls_fcat>-tabname = ls_fcat-tabname.
ADD 1 TO ls_fcat-col_pos.
<ls_fcat>-col_pos = ls_fcat-col_pos.
<ls_fcat>-no_out = abap_true.
<ls_fcat>-seltext_m = <ls_fcat>-seltext_l = <ls_fcat>-reptext_ddic = |{ TEXT-c01 } { lv_count }|.
<ls_fcat>-seltext_s = |{ TEXT-c02 } { lv_count }|.
<ls_fcat>-rollname = 'ATINN'.
<ls_fcat>-ref_tabname = 'AUSP'.
<ls_fcat>-ref_fieldname = 'ATINN'.
<ls_fcat>-no_out = abap_true.
APPEND INITIAL LINE TO lt_comp ASSIGNING <ls_comp>.
<ls_comp>-name = 'ATBEZ' && lv_count.
<ls_comp>-type ?= cl_abap_elemdescr=>describe_by_name( 'ATBEZ' ).
APPEND INITIAL LINE TO gt_fieldcat ASSIGNING <ls_fcat>.
<ls_fcat>-fieldname = <ls_comp>-name.
<ls_fcat>-tabname = ls_fcat-tabname.
ADD 1 TO ls_fcat-col_pos.
<ls_fcat>-col_pos = ls_fcat-col_pos.
<ls_fcat>-seltext_m = <ls_fcat>-seltext_l = <ls_fcat>-reptext_ddic = |{ TEXT-c03 } { lv_count }|.
<ls_fcat>-seltext_s = |{ TEXT-c04 } { lv_count }|.
<ls_fcat>-rollname = 'ATBEZ'.
<ls_fcat>-ref_tabname = 'CABNT'.
<ls_fcat>-ref_fieldname = 'ATBEZ'.
APPEND INITIAL LINE TO lt_comp ASSIGNING <ls_comp>.
<ls_comp>-name = 'ATWRT' && lv_count.
<ls_comp>-type ?= cl_abap_elemdescr=>describe_by_name( 'ATWRT' ).
APPEND INITIAL LINE TO gt_fieldcat ASSIGNING <ls_fcat>.
<ls_fcat>-tabname = ls_fcat-tabname.
<ls_fcat>-fieldname = <ls_comp>-name.
ADD 1 TO ls_fcat-col_pos.
<ls_fcat>-col_pos = ls_fcat-col_pos.
<ls_fcat>-seltext_m = <ls_fcat>-seltext_l = <ls_fcat>-reptext_ddic = |{ TEXT-c05 } { lv_count }|.
<ls_fcat>-seltext_s = |{ TEXT-c06 } { lv_count }|.
<ls_fcat>-rollname = 'ATWRT'.
<ls_fcat>-ref_tabname = 'AUSP'.
<ls_fcat>-ref_fieldname = 'ATWRT'.
ENDDO.
DATA(lo_tabledescr) = cl_abap_tabledescr=>create( cl_abap_structdescr=>create( lt_comp ) ).
CREATE DATA lr_itab TYPE HANDLE lo_tabledescr.
ASSIGN lr_itab->* TO <gt_itab>.
SORT lt_ausp BY matnr atinn.
lt_ausp_sorted = lt_ausp.
SORT lt_ausp BY atinn.
DELETE ADJACENT DUPLICATES FROM lt_ausp COMPARING atinn.
IF lt_ausp IS NOT INITIAL.
SELECT atinn, atbez FROM cabnt
FOR ALL ENTRIES IN @lt_ausp
WHERE atinn = @lt_ausp-atinn
AND spras = @p_spras
AND adzhl = @space
INTO TABLE @DATA(lt_cabnt).
SORT lt_cabnt BY atinn.
ENDIF.
FREE lt_ausp.
LOOP AT gt_itab.
APPEND INITIAL LINE TO <gt_itab> ASSIGNING FIELD-SYMBOL(<ls_itab>).
MOVE-CORRESPONDING gt_itab TO <ls_itab>.
lv_count = '00'.
LOOP AT lt_ausp_sorted ASSIGNING FIELD-SYMBOL(<ls_ausp>) WHERE matnr = gt_itab-matnr.
ADD 1 TO lv_count.
ASSIGN COMPONENT |ATINN{ lv_count }| OF STRUCTURE <ls_itab> TO FIELD-SYMBOL(<lv_field>).
<lv_field> = <ls_ausp>-atinn.
ASSIGN COMPONENT |ATWRT{ lv_count }| OF STRUCTURE <ls_itab> TO <lv_field>.
<lv_field> = <ls_ausp>-atwrt.
READ TABLE lt_cabnt ASSIGNING FIELD-SYMBOL(<ls_cabnt>) WITH KEY atinn = <ls_ausp>-atinn BINARY SEARCH.
IF sy-subrc = 0.
ASSIGN COMPONENT |ATBEZ{ lv_count }| OF STRUCTURE <ls_itab> TO <lv_field>.
<lv_field> = <ls_cabnt>-atbez.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDFORM.