Properties SourceCde
txt
1
*----------------------------------------------------------------------*
2
*   INCLUDE LSVIMFX3                                                   *
3
*----------------------------------------------------------------------*
4
*&--------------------------------------------------------------------*
5
*&      Form LIST_ALV                                               *
6
*&--------------------------------------------------------------------*
7
* D_VIA_SELECTION_SCREEN --> X - mit Selektion, ' ' - Standardliste   *
8
*&--------------------------------------------------------------------*
9
FORM list_alv.
10
 
11
*  STATICS: vim_alv_fcat TYPE slis_t_fieldcat_alv,  --> global
12
*           alv_events TYPE slis_t_event,
13
*           alv_layout TYPE slis_layout_alv.
14
  STATICS: texttab_begin LIKE sy-tabix,
15
           textlen TYPE intlen, unittab TYPE tabname,
16
           unitname TYPE fieldname, cukytab TYPE tabname,
17
           cukyname TYPE fieldname,
18
           glob_unitvalue(3) TYPE c,    "vim_unit,UF296573/2000
19
           glob_cukyvalue TYPE vim_cuky.
20
  DATA: textfld_no, textoffset TYPE intlen, rc LIKE sy-subrc,
21
        progname LIKE sy-repid, value_len TYPE intlen,
22
        w_alv_value_tab TYPE tabl8000.
23
  FIELD-SYMBOLS: <alv_fcat> LIKE LINE OF vim_alv_fcat,
24
                 <textfields>.
25
 
26
  IF x_header-frm_bf_prn <> space.
27
* old user exit for printing still used
28
    PERFORM drucken_ztp_alt.
29
    EXIT.
30
  ENDIF.
31
  IF NOT vim_alv_fcat[] IS INITIAL.
32
    READ TABLE vim_alv_fcat ASSIGNING <alv_fcat> INDEX 1.
33
    IF <alv_fcat>-ref_tabname <> view_name.
34
      UNASSIGN <alv_fcat>. FREE vim_alv_fcat.
35
    ENDIF.
36
  ENDIF.
37
  IF vim_alv_fcat[] IS INITIAL.
38
* build up field catalogue from X_NAMTAB
39
    PERFORM fill_alv_fieldcat CHANGING vim_alv_fcat
40
                                       texttab_begin
41
                                       vim_alv_value_length
42
                                       unittab
43
                                       unitname
44
                                       glob_unitvalue
45
                                       cukytab
46
                                       cukyname
47
                                       glob_cukyvalue.
48
    PERFORM define_alv_callbacks CHANGING vim_alv_events.
49
    PERFORM make_list_commentary USING unittab
50
                                       unitname
51
                                       glob_unitvalue
52
                                       cukytab
53
                                       cukyname
54
                                       glob_cukyvalue
55
                                 CHANGING vim_list_header.
56
    PERFORM make_alv_layout CHANGING vim_alv_layout
57
                                     vim_alv_print.
58
    PERFORM init_alv_variant CHANGING vim_var_save
59
                                      vim_var_default
60
                                      vim_alv_variant.
61
    vim_alv_called_by = 'VIM_CALL_ALV'.
62
*    REFRESH: vim_alv_excluding, vim_alv_special_groups,
63
*             vim_alv_sort, vim_alv_event_exit.
64
*    CLEAR:   vim_alv_print, vim_alv_sel_hide.
65
  ENDIF.                               "new structure table
66
  REFRESH alv_value_tab.
67
  IF status-mode = list_bild.
68
* Build ALV_VALUE_TAB
69
    LOOP AT extract.
70
      w_alv_value_tab = <vim_xextract>.
71
*    LOOP AT extract ASSIGNING <extract_line>.
72
*      alv_value_tab = <extract_line>.
73
      APPEND w_alv_value_tab TO alv_value_tab.
74
    ENDLOOP.
75
  ELSE.
76
* Build VALUE_TAB with single line
77
    w_alv_value_tab = <vim_xextract>.
78
*    alv_value_tab = extract.
79
    APPEND w_alv_value_tab TO alv_value_tab.
80
  ENDIF.
81
  IF x_header-bastab <> space AND x_header-texttbexst <> space.
82
* table and texttable
83
    textlen = x_header-aft_txttbc - x_header-aft_txtkc.
84
*  IF x_header-bastab = space OR x_header-texttbexst = space
85
*   OR x_header-maintview NE x_header-viewname.
86
* no table & texttable
87
*    CLEAR textlen.
88
*  ENDIF.
89
*  IF textlen <> 0.
90
* Shift fields
91
    PERFORM maintain_alv_value_tab_text USING    textlen.
92
  ELSE.
93
    vim_alv_value_length = x_header-tablen.
94
  ENDIF.
95
  IF x_header-frm_bf_alv <> space.
96
    PERFORM (x_header-frm_bf_alv) IN PROGRAM (sy-repid).
97
* Release 6.10(Unicode): alv_value_tab has got type RAW!
98
* useful parameters:
99
*   vim_alv_value_length     int. length of dataset in alv_value_tab
100
*   vim_alv_called_by        form routine calling FM ALV_LIST_DISPLAY
101
*                            preset value: 'VIM_CALL_ALV'
102
*   alv_value_tab[]          internal table containing values
103
*   vim_alv_fcat[]     \
104
*   vim_alv_events[]    |
105
*   vim_list_header[]   >    preset by view-maintenance
106
*   vim_alv_variant     |
107
*   vim_alv_layout     /
108
    CHECK NOT alv_value_tab[] IS INITIAL. "suppress list
109
  ENDIF.
110
  PERFORM check_list_before_alv CHANGING rc.
111
  CHECK rc = 0.
112
  progname = sy-repid.
113
  CALL FUNCTION 'REUSE_ALV_TABLE_CREATE'
114
    EXPORTING
115
      it_fieldcat        = vim_alv_fcat
116
      i_callback_program = progname
117
      i_formname         = vim_alv_called_by.
118
  FREE alv_value_tab.
119
ENDFORM.                               " LIST_ALV
120
 
121
*&--------------------------------------------------------------------*
122
*&      Form DRUCKEN_ZTP_ALT                                          *
123
*&--------------------------------------------------------------------*
124
* Keeps compatibility of view maintenance dialogs using old user exit
125
* "before printing"
126
* D_VIA_SELECTION_SCREEN --> X - mit Selektion, ' ' - Standardliste   *
127
*&--------------------------------------------------------------------*
128
FORM drucken_ztp_alt.
129
  DATA: rc_safe LIKE sy-subrc, texttab_begin LIKE sy-tabix, x TYPE i,
130
        entifct_begin LIKE sy-tabix, len TYPE i,
131
        after_text_assigned TYPE c, hname LIKE d021s-fnam.
132
  DATA: fcat_entry TYPE slis_fieldcat_alv, i TYPE i,
133
        cukytab TYPE tabname, unittab TYPE tabname, rc LIKE sy-subrc,
134
        cukyname TYPE fieldname, unitname TYPE fieldname,
135
        cukyvalue TYPE vim_cuky, unitvalue TYPE vim_unit,
136
        length TYPE doffset, cukylength TYPE doffset,
137
        fcat_entry2 TYPE slis_fieldcat_alv, progname LIKE sy-repid,
138
        alv_called_by TYPE char30 VALUE 'VIM_CALL_ALV'.
139
  FIELD-SYMBOLS: <before_text>, <text>, <after_text>, <cuky>, <unit>,
140
                 <value> TYPE tabl8000, <w_value_tab_x> TYPE x.
141
 
142
  CLEAR structure_table.
143
  DESCRIBE TABLE structure_table.
144
  IF sy-tfill NE 0. READ TABLE structure_table INDEX 1. ENDIF.
145
  IF structure_table-tabname NE view_name.
146
    CALL FUNCTION 'VIEW_GET_FIELDTAB'
147
      EXPORTING
148
        view_name = view_name
149
      TABLES
150
        fieldtab  = structure_table.
151
    IF x_header-bastab NE space AND x_header-texttbexst NE space
152
       AND x_header-maintview = x_header-viewname.           "Subviews
153
* einfügen text-felder in structure_table hinter entity-key
154
      LOOP AT x_namtab WHERE texttabfld NE space
155
                         AND keyflag NE space.
156
        texttab_begin = sy-tabix.
157
        EXIT.
158
      ENDLOOP.
159
      LOOP AT x_namtab WHERE texttabfld EQ space
160
                         AND keyflag EQ space.
161
        entifct_begin = sy-tabix.
162
        EXIT.
163
      ENDLOOP.
164
      IF sy-subrc NE 0.  "no entifct fields -> delete text key fields
165
        LOOP AT structure_table FROM texttab_begin
166
                                WHERE keyflag NE space.
167
          DELETE structure_table.
168
        ENDLOOP.
169
      ELSE.
170
        WHILE sy-subrc EQ 0.
171
          LOOP AT structure_table FROM texttab_begin.
172
            DELETE structure_table.
173
            IF structure_table-keyflag EQ space.
174
              EXIT.
175
            ENDIF.
176
          ENDLOOP.
177
          IF sy-subrc EQ 0.
178
            INSERT structure_table INDEX entifct_begin.
179
            ADD: 1 TO entifct_begin, 1 TO texttab_begin.
180
          ENDIF.
181
        ENDWHILE.
182
      ENDIF.
183
* aktualisieren von offset und position in structure_table
184
      len = 0.
185
      LOOP AT structure_table.
186
        structure_table-offset = len.
187
        structure_table-position = sy-tabix.
188
* Alignment
189
        IF 'CNDT' CS structure_table-inttype.
190
* Character-like datatypes
191
          x = ( structure_table-offset
192
                + cl_abap_char_utilities=>charsize )
193
                MOD cl_abap_char_utilities=>charsize.
194
          IF x NE 0.
195
            structure_table-offset = structure_table-offset
196
                               + cl_abap_char_utilities=>charsize - x.
197
          ENDIF.
198
        ELSE.
199
          CASE structure_table-datatype.
200
            WHEN 'INT2' OR 'PREC'.
201
              x = ( structure_table-offset + 2 ) MOD 2.
202
              IF x NE 0.
203
                structure_table-offset = structure_table-offset + 2 - x.
204
              ENDIF.
205
            WHEN 'INT4'.
206
              x = ( structure_table-offset + 4 ) MOD 4.
207
              IF x NE 0.
208
                structure_table-offset = structure_table-offset + 4 - x.
209
              ENDIF.
210
            WHEN 'FLTP'.
211
              x = ( structure_table-offset + 8 ) MOD 8.
212
              IF x NE 0.
213
                structure_table-offset = structure_table-offset + 8 - x.
214
              ENDIF.
215
          ENDCASE.
216
        ENDIF.
217
        MODIFY structure_table.
218
        len = structure_table-offset + structure_table-intlen.
219
      ENDLOOP.
220
    ENDIF.                             "table with texttable
221
    IF x_header-hiddenflag NE space.   "hidden fields exist
222
* ignore hidden fields
223
      LOOP AT x_namtab WHERE readonly EQ vim_hidden OR
224
       domname IN vim_guid_domain.
225
        LOOP AT structure_table WHERE fieldname EQ x_namtab-viewfield.
226
          DELETE structure_table.
227
          EXIT.
228
        ENDLOOP.
229
      ENDLOOP.
230
* aktualisieren von offset und position in structure_table
231
      len = 0.
232
      LOOP AT structure_table.
233
        structure_table-offset = len.
234
        structure_table-position = sy-tabix.
235
        IF 'CNDT' CS structure_table-inttype.
236
* Character-like datatypes
237
          x = ( structure_table-offset
238
                + cl_abap_char_utilities=>charsize )
239
                MOD cl_abap_char_utilities=>charsize.
240
          IF x NE 0.
241
            structure_table-offset = structure_table-offset
242
                               + cl_abap_char_utilities=>charsize - x.
243
          ENDIF.
244
        ELSE.
245
          CASE structure_table-datatype.
246
            WHEN 'INT2' OR 'PREC'.
247
              x = ( structure_table-offset + 2 ) MOD 2.
248
              IF x NE 0.
249
                structure_table-offset = structure_table-offset + 2 - x.
250
              ENDIF.
251
            WHEN 'INT4'.
252
              x = ( structure_table-offset + 4 ) MOD 4.
253
              IF x NE 0.
254
                structure_table-offset = structure_table-offset + 4 - x.
255
              ENDIF.
256
            WHEN 'FLTP'.
257
              x = ( structure_table-offset + 8 ) MOD 8.
258
              IF x NE 0.
259
                structure_table-offset = structure_table-offset + 8 - x.
260
              ENDIF.
261
          ENDCASE.
262
        ENDIF.
263
        MODIFY structure_table.
264
        len = structure_table-offset + structure_table-intlen.
265
      ENDLOOP.
266
    ENDIF.                             "hidden fields exist
267
  ENDIF.                               "new structure table
268
* Aufbau der Value_tab
269
  ASSIGN value_tab TO <w_value_tab_x> CASTING.
270
  IF x_header-bastab NE space AND x_header-texttbexst NE space
271
                                       "base table with text table
272
     AND x_header-maintview = x_header-viewname.
273
    CLEAR value_tab.
274
    IF status-mode EQ list_bild.
275
      LOOP AT extract.
276
        PERFORM build_valtab_hfields.
277
      ENDLOOP.
278
    ELSE.
279
      PERFORM build_valtab_hfields.
280
    ENDIF.
281
*    ENDIF.
282
  ELSE.
283
* view or base table without text table and user exits exists or hidden
284
* fields exist
285
    CLEAR value_tab.
286
    IF x_header-hiddenflag EQ space AND"no hidden fields
287
       x_header-fieldorder EQ space.   "Subviews /untersch. Feldreihenf.
288
      IF status-mode EQ list_bild.
289
        LOOP AT extract.
290
          MOVE <vim_xextract> TO <w_value_tab_x>(x_header-tablen).
291
*          MOVE extract TO value_tab(tablen).
292
          APPEND value_tab.
293
        ENDLOOP.
294
      ELSE.
295
        MOVE <vim_xextract> TO <w_value_tab_x>(x_header-tablen).
296
*        MOVE extract TO value_tab(tablen).
297
        APPEND value_tab.
298
      ENDIF.
299
    ELSE. "hidden fields exist -> move field by field
300
      IF status-mode EQ list_bild.
301
        LOOP AT extract.
302
          PERFORM build_valtab_hfields.
303
        ENDLOOP.
304
      ELSE.
305
        PERFORM build_valtab_hfields.
306
      ENDIF.
307
    ENDIF.
308
  ENDIF.                               "base table with text_table.
309
  IF x_header-frm_bf_prn NE space.     "user exit exists
310
* perform user exit
311
    PERFORM (x_header-frm_bf_prn) IN PROGRAM (sy-repid).
312
  ENDIF.
313
  CHECK NOT value_tab[] IS INITIAL.    "suppress list
314
************************************************************************
315
* Build up ALV fieldcatalogue from STRUCTURE
316
  REFRESH vim_alv_fcat.
317
  LOOP AT structure_table.
318
    CLEAR fcat_entry.
319
    PERFORM conv_dfies_fcat USING structure_table
320
                                  sy-tabix
321
                            CHANGING fcat_entry.
322
    APPEND fcat_entry TO vim_alv_fcat.
323
  ENDLOOP.
324
  length = structure_table-offset + structure_table-intlen.
325
* consider CUKY or UNIT fields.......
326
  DESCRIBE TABLE vim_alv_fcat LINES i.
327
  LOOP AT vim_alv_fcat INTO fcat_entry WHERE datatype = 'CURR'
328
   OR datatype = 'QUAN'.
329
    CASE fcat_entry-datatype.
330
      WHEN 'CURR'.
331
        READ TABLE x_namtab WITH KEY viewfield = fcat_entry-cfieldname
332
            TRANSPORTING NO FIELDS.
333
        IF sy-subrc <> 0.
334
* try to get global currency field
335
          READ TABLE x_namtab WITH KEY viewfield = fcat_entry-fieldname.
336
          cukytab = x_namtab-reftable.
337
          cukyname = x_namtab-reffield.
338
          CONCATENATE x_namtab-reftable '-' x_namtab-reffield
339
                  INTO hname.
340
          ASSIGN (hname) TO <cuky>.
341
          IF sy-subrc = 0.
342
* global currency key exists to be inserted in value table
343
            fcat_entry-currency = cukyvalue = <cuky>.
344
          ENDIF.
345
        ENDIF.
346
      WHEN 'QUAN'.
347
        READ TABLE x_namtab WITH KEY viewfield = fcat_entry-qfieldname
348
            TRANSPORTING NO FIELDS.
349
        IF sy-subrc <> 0.
350
* try to get global quantity field
351
          READ TABLE x_namtab WITH KEY viewfield = fcat_entry-fieldname.
352
          unittab = x_namtab-reftable.
353
          unitname = x_namtab-reffield.
354
          CONCATENATE x_namtab-reftable '-' x_namtab-reffield
355
                  INTO hname.
356
          ASSIGN (hname) TO <unit>.
357
          IF sy-subrc = 0.
358
* global unit key exists to be inserted in value table
359
            fcat_entry-quantity = unitvalue = <unit>.
360
          ENDIF.
361
        ENDIF.
362
    ENDCASE.
363
    MODIFY vim_alv_fcat FROM fcat_entry.
364
  ENDLOOP.
365
  REFRESH alv_value_tab.
366
  LOOP AT value_tab.
367
    APPEND <w_value_tab_x> TO alv_value_tab.
368
  ENDLOOP.
369
*  APPEND LINES OF value_tab TO alv_value_tab.
370
  FREE value_tab.
371
  IF NOT cukyname IS INITIAL.
372
* Append global currency to value_tab
373
    LOOP AT alv_value_tab ASSIGNING <value>.
374
      <value>+length = cukyvalue.
375
    ENDLOOP.
376
    length = length + cukylength.
377
  ENDIF.
378
  IF NOT unitname IS INITIAL.
379
* Append global unit to value_tab
380
    LOOP AT alv_value_tab ASSIGNING <value>.
381
      <value>+length = unitvalue.
382
    ENDLOOP.
383
  ENDIF.
384
  PERFORM define_alv_callbacks CHANGING vim_alv_events.
385
  PERFORM make_list_commentary USING unittab
386
                                     unitname
387
                                     unitvalue
388
                                     cukytab
389
                                     cukyname
390
                                     cukyvalue
391
                               CHANGING vim_list_header.
392
  PERFORM make_alv_layout CHANGING vim_alv_layout
393
                                   vim_alv_print.
394
  PERFORM init_alv_variant CHANGING vim_var_save
395
                                    vim_var_default
396
                                    vim_alv_variant.
397
  progname = sy-repid.
398
  PERFORM check_list_before_alv CHANGING rc.
399
  CHECK rc = 0.
400
  CALL FUNCTION 'REUSE_ALV_TABLE_CREATE'
401
    EXPORTING
402
      it_fieldcat        = vim_alv_fcat
403
      i_callback_program = progname
404
      i_formname         = alv_called_by.
405
  FREE alv_value_tab.
406
*  if sy-subrc ne 0. raise print_error. endif.
407
ENDFORM.                               " DRUCKEN_ZTP_ALT
408
 
409
*&---------------------------------------------------------------------*
410
*&      Form  MAKE_LIST_COMMENTARY
411
*&---------------------------------------------------------------------*
412
*       Build up list header
413
*----------------------------------------------------------------------*
414
*      <--P_LIST_COMMENTARY  text
415
*----------------------------------------------------------------------*
416
FORM make_list_commentary USING p_unittab TYPE tabname
417
                                p_unitname TYPE fieldname
418
                                p_unitvalue TYPE any
419
                                                "vim_unitUF296573/2000
420
                                p_cukytab TYPE tabname
421
                                p_cukyname TYPE fieldname
422
                                p_cukyvalue TYPE vim_cuky
423
                       CHANGING p_list_header TYPE slis_t_listheader.
424
  DATA: h_header TYPE slis_listheader,
425
        text(40), w_dfies TYPE dfies.
426
 
427
  REFRESH p_list_header.
428
  h_header-typ = 'H'.
429
  h_header-info = x_header-ddtext.
430
  APPEND h_header TO p_list_header.
431
  h_header-typ = 'S'.
432
  IF x_header-bastab NE space AND x_header-texttbexst NE space
433
   AND x_header-maintview = x_header-viewname.
434
    h_header-key = svim_text_p01.
435
  ELSE.
436
    h_header-key = svim_text_p02.
437
  ENDIF.
438
  h_header-info = x_header-viewname.
439
  APPEND h_header TO p_list_header.
440
  IF x_header-clidep <> space.
441
    h_header-key = svim_text_p03.
442
    h_header-info = sy-mandt.
443
    APPEND h_header TO p_list_header.
444
  ENDIF.
445
  IF p_unitname <> space.
446
    CLEAR h_header.
447
    h_header-typ = 'S'.
448
    PERFORM vim_get_reffield_alv USING p_unitname
449
                                       p_unittab
450
                                  CHANGING w_dfies.
451
    IF w_dfies <> space.
452
      IF w_dfies-scrtext_m <> space.
453
        h_header-key = w_dfies-scrtext_m(20).
454
      ELSE.
455
        IF w_dfies-scrtext_l <> space.
456
          h_header-key = w_dfies-scrtext_l(20).
457
        ELSE.
458
          IF w_dfies-scrtext_s <> space.
459
            h_header-key = w_dfies-scrtext_s(10).
460
          ELSE.
461
            IF w_dfies-reptext <> space.
462
              h_header-key = w_dfies-reptext(20).
463
            ELSE.
464
              h_header-key = w_dfies-fieldname.
465
            ENDIF.
466
          ENDIF.
467
        ENDIF.
468
      ENDIF.
469
    ENDIF.
470
    h_header-info = p_unitvalue.
471
    APPEND h_header TO p_list_header.
472
  ENDIF.
473
  IF p_cukyname <> space.
474
    CLEAR h_header.
475
    h_header-typ = 'S'.
476
    PERFORM vim_get_reffield_alv USING p_cukyname
477
                                       p_cukytab
478
                                  CHANGING w_dfies.
479
    IF w_dfies <> space.
480
      IF w_dfies-scrtext_m <> space.
481
        h_header-key = w_dfies-scrtext_m(20).
482
      ELSE.
483
        IF w_dfies-scrtext_l <> space.
484
          h_header-key = w_dfies-scrtext_l(20).
485
        ELSE.
486
          IF w_dfies-scrtext_s <> space.
487
            h_header-key = w_dfies-scrtext_s(10).
488
          ELSE.
489
            IF w_dfies-reptext <> space.
490
              h_header-key = w_dfies-reptext(20).
491
            ELSE.
492
              h_header-key = w_dfies-fieldname.
493
            ENDIF.
494
          ENDIF.
495
        ENDIF.
496
      ENDIF.
497
    ENDIF.
498
    h_header-info = p_cukyvalue.
499
    APPEND h_header TO p_list_header.
500
  ENDIF.
501
ENDFORM.                               " MAKE_LIST_COMMENTARY
502
*&---------------------------------------------------------------------*
503
*&      Form  DEFINE_ALV_CALLBACKS
504
*&---------------------------------------------------------------------*
505
*       text
506
*----------------------------------------------------------------------*
507
*      <--P_ALV_EVENTS  text
508
*----------------------------------------------------------------------*
509
FORM define_alv_callbacks CHANGING p_alv_events TYPE slis_t_event.
510
  DATA: h_event TYPE slis_alv_event.
511
  CONSTANTS: formname_top_of_list TYPE slis_formname
512
             VALUE 'ALV_TOP_OF_LIST',
513
             formname_top_of_page TYPE slis_formname
514
             VALUE 'ALV_TOP_OF_PAGE',
515
             formname_end_of_page TYPE slis_formname
516
             VALUE 'ALV_END_OF_PAGE',
517
             formname_end_of_list TYPE slis_formname
518
             VALUE 'ALV_END_OF_LIST'.
519
  REFRESH p_alv_events.
520
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
521
    EXPORTING
522
      i_list_type = 0
523
    IMPORTING
524
      et_events   = p_alv_events.
525
* define TOP_OF_LIST event
526
  READ TABLE p_alv_events WITH KEY name = slis_ev_top_of_list
527
                           INTO h_event.
528
  IF sy-subrc = 0.
529
    h_event-form = formname_top_of_list.
530
    APPEND h_event TO p_alv_events.
531
  ENDIF.
532
* define TOP_OF_PAGE event
533
  READ TABLE p_alv_events WITH KEY name = slis_ev_top_of_page
534
                           INTO h_event.
535
  IF sy-subrc = 0.
536
    h_event-form = formname_top_of_page.
537
    APPEND h_event TO p_alv_events.
538
  ENDIF.
539
* define END_OF_PAGE event
540
  READ TABLE p_alv_events WITH KEY name = slis_ev_end_of_page
541
                           INTO h_event.
542
  IF sy-subrc = 0.
543
    h_event-form = formname_end_of_page.
544
    APPEND h_event TO p_alv_events.
545
  ENDIF.
546
* define END_OF_LIST event
547
  READ TABLE p_alv_events WITH KEY name = slis_ev_end_of_list
548
                           INTO h_event.
549
  IF sy-subrc = 0.
550
    h_event-form = formname_end_of_list.
551
    APPEND h_event TO p_alv_events.
552
  ENDIF.
553
ENDFORM.                    "define_alv_callbacks
554
 
555
*&---------------------------------------------------------------------*
556
*&      Form  ALV_TOP_OF_LIST
557
*&---------------------------------------------------------------------*
558
*       text
559
*----------------------------------------------------------------------*
560
*
561
*----------------------------------------------------------------------*
562
FORM alv_top_of_list.
563
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
564
    EXPORTING
565
      it_list_commentary = vim_list_header.
566
 
567
ENDFORM.                               " ALV_TOP_OF_LIST
568
*&---------------------------------------------------------------------*
569
*&      Form  ALV_TOP_OF_PAGE
570
*&---------------------------------------------------------------------*
571
*       text
572
*----------------------------------------------------------------------*
573
*
574
*----------------------------------------------------------------------*
575
FORM alv_top_of_page.
576
  WRITE AT (sy-linsz) sy-datum RIGHT-JUSTIFIED.
577
ENDFORM.                               " ALV_TOP_OF_PAGE
578
*&---------------------------------------------------------------------*
579
*&      Form  ALV_END_OF_PAGE
580
*&---------------------------------------------------------------------*
581
*       text
582
*----------------------------------------------------------------------*
583
*
584
*----------------------------------------------------------------------*
585
FORM alv_end_of_page.
586
  WRITE AT (sy-linsz) sy-pagno CENTERED.
587
ENDFORM.                               " ALV_END_OF_PAGE
588
 
589
*&---------------------------------------------------------------------*
590
*&      Form  MAKE_ALV_LAYOUT
591
*&---------------------------------------------------------------------*
592
*       text
593
*----------------------------------------------------------------------*
594
*      <--P_ALV_LAYOUT  text
595
*----------------------------------------------------------------------*
596
FORM make_alv_layout CHANGING p_alv_layout TYPE slis_layout_alv
597
                              p_alv_print  TYPE slis_print_alv.
598
* screen layout
599
  CLEAR p_alv_layout.
600
  p_alv_layout-colwidth_optimize = 'X'.
601
  p_alv_layout-f2code = '&ETA'.
602
  p_alv_layout-detail_popup = 'X'.
603
* print layout
604
*  p_alv_print-reserve_lines = 2.
605
  p_alv_print-no_print_listinfos = 'X'.
606
ENDFORM.                               " MAKE_ALV_LAYOUT
607
*&---------------------------------------------------------------------*
608
*&      Form  FILL_ALV_FIELDCAT
609
*&---------------------------------------------------------------------*
610
*       Builds up ALV-fieldcatalogue from X_NAMTAB
611
*----------------------------------------------------------------------*
612
*      <--P_VIM_ALV_FCAT  ALV-fieldctalogue
613
*----------------------------------------------------------------------*
614
FORM fill_alv_fieldcat CHANGING p_vim_alv_fcat TYPE slis_t_fieldcat_alv
615
                                texttab_begin LIKE sy-tabix
616
                                p_value_length TYPE intlen
617
*                                p_textlen TYPE intlen
618
                                p_unittab TYPE tabname
619
                                p_unitname TYPE fieldname
620
                                p_unitvalue TYPE any "vim_unit
621
                                       "UF296573/2000
622
                                p_cukytab TYPE tabname
623
                                p_cukyname TYPE fieldname
624
                                p_cukyvalue TYPE vim_cuky.
625
 
626
  DATA: fcat_header TYPE slis_fieldcat_alv, textfld_no TYPE i,
627
        fcat_reffield TYPE slis_fieldcat_alv, rc LIKE sy-subrc,
628
        first TYPE xfeld VALUE 'X', list_width TYPE outputlen,
629
        i TYPE i, first_func_field TYPE i, text_outp_len TYPE outputlen,
630
        fldno(2) TYPE n, strln TYPE i,
631
        hname TYPE fnam_____4, maintview, global_unit_set,
632
        global_cuky_set.
633
 
634
  CONSTANTS: max_list_width TYPE i VALUE 250.
635
 
636
  FIELD-SYMBOLS: <alv_fcat> LIKE LINE OF p_vim_alv_fcat,
637
                 <alv_fcat2> LIKE LINE OF p_vim_alv_fcat, "UF412290/2001
638
                 <x_namt> LIKE LINE OF x_namtab, <cuky> TYPE vim_cuky,
639
                 <unit> TYPE ANY.      "vim_unit. UF296573/2000
640
 
641
  REFRESH p_vim_alv_fcat.
642
  CLEAR:  p_unitname, p_cukyname, p_unitvalue, p_cukyvalue,
643
          p_value_length.
644
  IF x_header-bastab EQ space OR x_header-texttbexst EQ space
645
   OR x_header-maintview NE x_header-viewname.
646
    maintview = 'X'.                   "It's a maintenance view!
647
  ENDIF.
648
* Build up field catalogue
649
  LOOP AT x_namtab ASSIGNING <x_namt> WHERE texttabfld = space
650
   OR keyflag = space.
651
    i = i + 1.
652
    fcat_header-col_pos = i.
653
    fcat_header-fieldname = <x_namt>-viewfield.
654
    IF maintview = space.
655
      fcat_header-ref_tabname = <x_namt>-bastabname.
656
    ELSE.
657
      fcat_header-ref_tabname = x_header-maintview.
658
    ENDIF.
659
    fcat_header-key = <x_namt>-keyflag.
660
    fcat_header-seltext_l = <x_namt>-scrtext_l.
661
    fcat_header-seltext_m = <x_namt>-scrtext_m.
662
    fcat_header-seltext_s = <x_namt>-scrtext_s.
663
    fcat_header-reptext_ddic = <x_namt>-reptext.
664
    fcat_header-datatype = <x_namt>-datatype.
665
    fcat_header-inttype = <x_namt>-inttype.
666
    fcat_header-ddic_outputlen = <x_namt>-outputlen.
667
    fcat_header-intlen = <x_namt>-flength.
668
    fcat_header-lowercase = <x_namt>-lowercase.
669
    CASE <x_namt>-datatype.
670
      WHEN 'CLNT'.
671
        IF x_header-clidep <> space.
672
          fcat_header-tech = 'X'.
673
        ENDIF.
674
      WHEN 'CURR'.
675
        READ TABLE x_namtab WITH KEY viewfield = <x_namt>-reffield
676
            TRANSPORTING NO FIELDS.
677
        IF sy-subrc = 0 AND <x_namt>-reftable = x_header-maintview.
678
          "UF163276/2001
679
* currency field in structure
680
          fcat_header-cfieldname = <x_namt>-reffield.
681
        ELSE.
682
          IF p_cukyvalue IS INITIAL.
683
* try to get global currency field
684
            p_cukytab = <x_namt>-reftable.
685
            p_cukyname = <x_namt>-reffield.
686
            CONCATENATE <x_namt>-reftable '-' <x_namt>-reffield
687
                    INTO hname.
688
            ASSIGN (hname) TO <cuky>.
689
            IF sy-subrc = 0.
690
* global currency key exists to be inserted in value table
691
              fcat_header-currency = p_cukyvalue = <cuky>.
692
            ENDIF.
693
          ELSE.
694
            fcat_header-currency = p_cukyvalue.
695
          ENDIF.
696
        ENDIF.
697
      WHEN 'QUAN'.
698
        READ TABLE x_namtab WITH KEY viewfield = <x_namt>-reffield
699
            TRANSPORTING NO FIELDS.
700
        IF sy-subrc = 0 AND <x_namt>-reftable = x_header-maintview.
701
          "UF163276/2001.
702
* quantity field in structure
703
          fcat_header-qfieldname = <x_namt>-reffield.
704
        ELSE.
705
* try to get global quantity field
706
          IF p_unitvalue IS INITIAL.
707
            p_unittab = <x_namt>-reftable.
708
            p_unitname = <x_namt>-reffield.
709
            CONCATENATE <x_namt>-reftable '-' <x_namt>-reffield
710
                    INTO hname.
711
            ASSIGN (hname) TO <unit>.
712
            IF sy-subrc = 0.
713
* global unit key exists to be inserted in value table
714
              fcat_header-quantity = p_unitvalue = <unit>.
715
            ENDIF.
716
          ELSE.
717
            fcat_header-quantity = p_unitvalue.
718
          ENDIF.
719
        ENDIF.
720
    ENDCASE.
721
    IF <x_namt>-readonly = vim_hidden
722
* hide hidden fields
723
     OR <x_namt>-domname IN vim_guid_domain.
724
* no GUID-values
725
      fcat_header-tech = 'X'.
726
    ELSE.
727
      list_width = list_width + <x_namt>-outputlen + 1.
728
    ENDIF.
729
    p_value_length = p_value_length + fcat_header-intlen.
730
    APPEND fcat_header TO p_vim_alv_fcat.
731
    CLEAR fcat_header.
732
    CHECK <x_namt>-texttabfld <> space.
733
    textfld_no = textfld_no + 1.       "get no. of text fields
734
*    p_textlen = p_textlen + <x_namt>-flength. "int. length of text flds
735
    CHECK <x_namt>-readonly <> vim_hidden.
736
    IF first <> space.
737
      texttab_begin = i.               "position of 1st text fld
738
      CLEAR first.
739
    ENDIF.
740
    text_outp_len = text_outp_len + <x_namt>-outputlen.
741
  ENDLOOP.
742
  first = 'X'.
743
  CLEAR i.
744
  IF x_header-bastab NE space AND x_header-texttbexst NE space
745
   AND x_header-maintview = x_header-viewname.
746
* Place text fields behind key fields.
747
    LOOP AT p_vim_alv_fcat ASSIGNING <alv_fcat> WHERE key = space.
748
      IF first <> space.
749
        first_func_field = <alv_fcat>-col_pos.
750
        CLEAR first.
751
      ENDIF.
752
      IF sy-tabix < texttab_begin.
753
        <alv_fcat>-col_pos = <alv_fcat>-col_pos + textfld_no.
754
      ELSE.
755
        i = i + 1.
756
        <alv_fcat>-col_pos = first_func_field + i - 1.
757
      ENDIF.
758
    ENDLOOP.
759
    first = 'X'.
760
    SORT p_vim_alv_fcat BY col_pos.
761
  ENDIF.
762
  IF list_width > max_list_width.
763
* line size to large for one line
764
    list_width = i = 1.
765
    LOOP AT p_vim_alv_fcat ASSIGNING <alv_fcat>.
766
      list_width = list_width + <alv_fcat>-ddic_outputlen + 1.
767
      IF list_width > max_list_width.
768
        i = i + 1.
769
        list_width = <alv_fcat>-ddic_outputlen + 1.
770
      ENDIF.
771
      <alv_fcat>-row_pos = i.
772
    ENDLOOP.
773
  ENDIF.
774
  IF maintview = space.                  "UF412290/2001b
775
*check field catalogue for doublettes and change their fieldname
776
    LOOP AT p_vim_alv_fcat ASSIGNING <alv_fcat>.
777
      i = sy-tabix.
778
      CLEAR fldno.
779
      LOOP AT p_vim_alv_fcat ASSIGNING <alv_fcat2>
780
       WHERE fieldname = <alv_fcat>-fieldname.
781
        CHECK sy-tabix <> i.
782
        <alv_fcat2>-ref_fieldname = <alv_fcat2>-fieldname.
783
        ADD 1 TO fldno.
784
        CONCATENATE <alv_fcat2>-fieldname fldno
785
         INTO <alv_fcat2>-fieldname.
786
        IF sy-subrc <> 0.
787
          strln = strlen( <alv_fcat2>-fieldname ) - 2.
788
          CONCATENATE <alv_fcat2>-fieldname(strln) fldno
789
          INTO <alv_fcat2>-fieldname.
790
        ENDIF.
791
      ENDLOOP.
792
    ENDLOOP.
793
  ENDIF.                                 "UF412290/2001e
794
ENDFORM.                               " FILL_ALV_FIELDCAT
795
 
796
*&---------------------------------------------------------------------*
797
*&      Form  VIM_CALL_ALV
798
*&---------------------------------------------------------------------*
799
*       Calls ABAP List Viewer. Has to be called from Function Module
800
*       REUSE_ALV_TABLE_CREATE.
801
*----------------------------------------------------------------------*
802
*      -->VALUE_TAB
803
*----------------------------------------------------------------------*
804
FORM vim_call_alv TABLES value_tab.
805
 
806
  DATA: progname LIKE sy-repid.
807
  FIELD-SYMBOLS: <alv_value_tab_x> TYPE tabl8000,
808
                 <value_tab_x> TYPE x.
809
 
810
  REFRESH value_tab.
811
  ASSIGN value_tab TO <value_tab_x> CASTING.
812
  LOOP AT alv_value_tab ASSIGNING <alv_value_tab_x>.
813
    <value_tab_x> = <alv_value_tab_x>.
814
    APPEND value_tab.
815
  ENDLOOP.
816
*  APPEND LINES OF alv_value_tab TO value_tab.
817
  progname = sy-repid.
818
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
819
      EXPORTING
820
           i_callback_program       = progname
821
           is_layout                = vim_alv_layout
822
           it_fieldcat              = vim_alv_fcat
823
*           it_excluding             = vim_alv_excluding
824
*           it_special_groups        = vim_alv_special_groups
825
*           it_sort                  = vim_alv_sort
826
*            IT_FILTER                =
827
*           is_sel_hide              = vim_alv_sel_hide
828
           i_default                = vim_var_default
829
           i_save                   = vim_var_save
830
           is_variant               = vim_alv_variant
831
           it_events                = vim_alv_events
832
*           it_event_exit            = vim_alv_event_exit
833
           is_print                 = vim_alv_print
834
*            IS_REPREP_ID             =
835
*            I_SCREEN_START_COLUMN    = 0
836
*            I_SCREEN_START_LINE      = 0
837
*            I_SCREEN_END_COLUMN      = 0
838
*            I_SCREEN_END_LINE        = 0
839
*       IMPORTING
840
*            E_EXIT_CAUSED_BY_CALLER  =
841
*            ES_EXIT_CAUSED_BY_USER   =
842
       TABLES
843
            t_outtab                 = value_tab[]
844
       EXCEPTIONS
845
            program_error            = 1
846
            OTHERS                   = 2.
847
  IF sy-subrc NE 0. RAISE print_error. ENDIF.
848
ENDFORM.                               "vim_call_alv
849
*&---------------------------------------------------------------------*
850
*&      Form  MAINTAIN_ALV_VALUE_TAB_TEXT
851
*&---------------------------------------------------------------------*
852
*       shift textfield directly behind key
853
*----------------------------------------------------------------------*
854
*      -->P_TEXTLEN  text
855
*----------------------------------------------------------------------*
856
FORM maintain_alv_value_tab_text USING    p_textlen TYPE intlen.
857
 
858
  DATA: x TYPE i, record TYPE tabl8000, textoffset TYPE intlen,
859
        BEGIN OF new_offs,
860
          ref_tabname TYPE tabname,
861
          fieldname TYPE viewfield,
862
          ref_fieldname TYPE fieldname,
863
          offset TYPE tabfdpos,
864
        END OF new_offs.
865
 
866
  STATICS: t_fld_offs LIKE SORTED TABLE OF new_offs WITH UNIQUE KEY
867
                           ref_tabname fieldname ref_fieldname
868
                           INITIAL SIZE 1,
869
           viewname TYPE viewname.
870
  FIELD-SYMBOLS: <x_namt> LIKE LINE OF x_namtab,
871
                 <alv_fcat> TYPE slis_fieldcat_alv,
872
                 <alv_val>.
873
 
874
  IF viewname <> x_header-viewname.
875
    viewname = x_header-viewname.
876
    REFRESH t_fld_offs.
877
    new_offs-offset = x_header-after_keyc.
878
*    new_offs-offset = x_header-keylen.
879
* Offset aktualisieren
880
    LOOP AT vim_alv_fcat ASSIGNING <alv_fcat> WHERE key = space.
881
      new_offs-ref_tabname = <alv_fcat>-ref_tabname.
882
      new_offs-fieldname = <alv_fcat>-fieldname.
883
      new_offs-ref_fieldname = <alv_fcat>-ref_fieldname. "UF412290/2001
884
* Alignment
885
      IF 'CNDT' CS <alv_fcat>-inttype.
886
* Character-like datatypes
887
        x = ( new_offs-offset + cl_abap_char_utilities=>charsize )
888
              MOD cl_abap_char_utilities=>charsize.
889
        IF x NE 0.
890
          new_offs-offset = new_offs-offset
891
                             + cl_abap_char_utilities=>charsize - x.
892
        ENDIF.
893
      ELSE.
894
        CASE <alv_fcat>-datatype.
895
          WHEN 'INT2' OR 'PREC'.
896
            x = ( new_offs-offset + 2 ) MOD 2.
897
            IF x NE 0.
898
              new_offs-offset = new_offs-offset + 2 - x.
899
            ENDIF.
900
          WHEN 'INT4'.
901
            x = ( new_offs-offset + 4 ) MOD 4.
902
            IF x NE 0.
903
              new_offs-offset = new_offs-offset + 4 - x.
904
            ENDIF.
905
          WHEN 'FLTP'.
906
            x = ( new_offs-offset + 8 ) MOD 8.
907
            IF x NE 0.
908
              new_offs-offset = new_offs-offset + 8 - x.
909
            ENDIF.
910
        ENDCASE.
911
      ENDIF.
912
      INSERT new_offs INTO TABLE t_fld_offs.
913
      new_offs-offset = new_offs-offset + <alv_fcat>-intlen.
914
    ENDLOOP.
915
  ENDIF.
916
  textoffset = x_header-after_tabc + x_header-aft_txtkc.
917
*  textoffset = x_header-tablen + x_header-textkeylen.
918
  LOOP AT alv_value_tab ASSIGNING <alv_val>.
919
    record(x_header-after_keyc) = <alv_val>(x_header-after_keyc).
920
*    record = <alv_val>(x_header-keylen).
921
    IF p_textlen > 0.
922
      record+x_header-after_keyc(p_textlen) =
923
       <alv_val>+textoffset(p_textlen).
924
*      record+x_header-keylen(p_textlen) =
925
*       <alv_val>+textoffset(p_textlen).
926
    ENDIF.
927
    LOOP AT x_namtab ASSIGNING <x_namt> WHERE keyflag = space AND
928
                                              texttabfld = space.
929
      READ TABLE t_fld_offs INTO new_offs WITH TABLE KEY
930
                                    ref_tabname = <x_namt>-bastabname
931
                                    fieldname = <x_namt>-viewfield
932
                                    ref_fieldname = space.
933
      IF sy-subrc = 0.
934
        record+new_offs-offset(<x_namt>-flength) =
935
         <alv_val>+<x_namt>-position(<x_namt>-flength).
936
      ELSE.                                "UF412290/2001b
937
* field had to be renamed because of doublettes
938
        READ TABLE t_fld_offs INTO new_offs WITH KEY
939
                                    ref_tabname = <x_namt>-bastabname
940
                                    ref_fieldname = <x_namt>-viewfield.
941
        IF sy-subrc = 0.
942
          record+new_offs-offset(<x_namt>-flength) =
943
           <alv_val>+<x_namt>-position(<x_namt>-flength).
944
        ENDIF.                             "UF412290/2001e
945
      ENDIF.
946
    ENDLOOP.
947
    CLEAR <alv_val>.
948
    <alv_val> = record.
949
  ENDLOOP.
950
ENDFORM.                               " MAINTAIN_ALV_VALUE_TAB_TEXT
951
*&---------------------------------------------------------------------*
952
*&      Form  VIM_GET_REFFIELD_ALV
953
*&---------------------------------------------------------------------*
954
*       text
955
*----------------------------------------------------------------------*
956
*      -->P_REFFIELD  text
957
*      -->P_REFTABLE  text
958
*      <--P_DFIES Entry for ALV-Fieldcatalogue
959
*----------------------------------------------------------------------*
960
FORM vim_get_reffield_alv USING value(p_reffield) TYPE fieldname
961
                                value(p_reftable) TYPE tabname
962
                      CHANGING p_dfies TYPE dfies.
963
 
964
  DATA: dfies_tab TYPE TABLE OF dfies.
965
 
966
  CALL FUNCTION 'DDIF_FIELDINFO_GET'
967
    EXPORTING
968
      tabname        = p_reftable
969
      fieldname      = p_reffield
970
      langu          = sy-langu
971
    TABLES
972
      dfies_tab      = dfies_tab
973
    EXCEPTIONS
974
      not_found      = 1
975
      internal_error = 2
976
      OTHERS         = 3.
977
  IF sy-subrc <> 0.
978
    EXIT.
979
  ELSE.
980
    READ TABLE dfies_tab INTO p_dfies INDEX 1.
981
  ENDIF.
982
ENDFORM.                               " VIM_GET_REFFIELD_ALV
983
 
984
*&---------------------------------------------------------------------*
985
*&      Form  CONV_DFIES_FCAT
986
*&---------------------------------------------------------------------*
987
*       text
988
*----------------------------------------------------------------------*
989
*      -->P_P_DFIES  text
990
*      <--P_P_FCAT_REFFIELD  text
991
*----------------------------------------------------------------------*
992
FORM conv_dfies_fcat USING    p_dfies LIKE dfies
993
                              i TYPE i
994
                    CHANGING p_fcat_reffield TYPE slis_fieldcat_alv.
995
 
996
  p_fcat_reffield-col_pos = i.
997
  p_fcat_reffield-fieldname = p_dfies-fieldname.
998
  p_fcat_reffield-ref_tabname = p_dfies-tabname.
999
  p_fcat_reffield-key = p_dfies-keyflag.
1000
  p_fcat_reffield-seltext_l = p_dfies-scrtext_l.
1001
  p_fcat_reffield-seltext_m = p_dfies-scrtext_m.
1002
  p_fcat_reffield-seltext_s = p_dfies-scrtext_s.
1003
  p_fcat_reffield-reptext_ddic = p_dfies-reptext.
1004
  p_fcat_reffield-datatype = p_dfies-datatype.
1005
  p_fcat_reffield-inttype = p_dfies-inttype.
1006
  p_fcat_reffield-ddic_outputlen = p_dfies-outputlen.
1007
  p_fcat_reffield-intlen = p_dfies-intlen.
1008
  p_fcat_reffield-lowercase = p_dfies-lowercase.
1009
  CASE p_dfies-datatype.
1010
    WHEN 'CLNT'.
1011
      CHECK x_header-clidep <> space AND p_fcat_reffield-key <> space.
1012
      p_fcat_reffield-tech = 'X'.
1013
    WHEN 'CURR'.
1014
* currency field in structure
1015
      p_fcat_reffield-cfieldname = p_dfies-reffield.
1016
    WHEN 'QUAN'.
1017
* currency field in structure
1018
      p_fcat_reffield-qfieldname = p_dfies-reffield.
1019
  ENDCASE.
1020
ENDFORM.                               " CONV_DFIES_FCAT
1021
*&---------------------------------------------------------------------*
1022
*&      Form  INIT_ALV_VARIANT
1023
*&---------------------------------------------------------------------*
1024
*       define path for list variant names
1025
*----------------------------------------------------------------------*
1026
*      <--P_VARIANT  text
1027
*      <--P_SAVE     text
1028
*----------------------------------------------------------------------*
1029
FORM init_alv_variant CHANGING p_save
1030
                               p_default
1031
                               p_variant STRUCTURE disvariant.
1032
 
1033
  CONCATENATE x_header-viewname sy-repid INTO p_variant-report.
1034
  p_save = 'A'.
1035
  p_default = 'X'.
1036
ENDFORM.                               " INIT_ALV_VARIANT
1037
*&---------------------------------------------------------------------*
1038
*&      Form  ALV_END_OF_LIST
1039
*&---------------------------------------------------------------------*
1040
*       text
1041
*----------------------------------------------------------------------*
1042
*
1043
*----------------------------------------------------------------------*
1044
FORM alv_end_of_list.
1045
  WRITE AT /(sy-linsz) sy-pagno CENTERED.
1046
ENDFORM.                               " ALV_END_OF_LIST