Sunday, April 20, 2014

EXAMPLE ALV

  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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
*&---------------------------------------------------------------------*
*& Report  ZTEST_ALV
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ztest_alv.
DATA : t_ekko TYPE TABLE OF ekko,
       x_ekko TYPE ekko.
*ALV Data declaration
*--------------------------------------------------------------------*
DATA: t_fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
      d_tab_group TYPE slis_t_sp_group_alv,
      x_layout TYPE slis_layout_alv,
      d_repid LIKE sy-repid,
      t_events TYPE slis_t_event,
      x_prntparams TYPE slis_print_alv,
      t_sort TYPE slis_t_sortinfo_alv,
      t_alv_isort TYPE slis_t_sortinfo_alv WITH HEADER LINE,
      t_alv_extab TYPE slis_t_extab WITH HEADER LINE.
*--------------------------------------------------------------------*


START-OF-SELECTION.
  SELECT * FROM ekko INTO TABLE t_ekko
    UP TO 50 ROWS.

  PERFORM f_alv.
*&---------------------------------------------------------------------*
*&      Form  F_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_alv .
  REFRESH t_fieldcatalog.

  PERFORM f_build_fieldcatalog.
  PERFORM f_build_layout.
  PERFORM f_build_events.
  PERFORM f_display_alv_report.

  REFRESH : t_ekko.
ENDFORM.                    " F_ALV
*&---------------------------------------------------------------------*
*&      Form  F_BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_build_fieldcatalog .
  PERFORM f_sub_fill_alv_field_catalog  USING:
     '01' '01' 'BUKRS'           'T_EKKO' 'R' 'Company Code'                       '' '' '' '' 'X',
     '01' '02' 'BSART'           'T_EKKO' 'L' 'PO Type'                            '' '' '' '' 'X',
     '01' '03' 'LOEKZ'           'T_EKKO' 'R' 'Delete'                             '' '' '' '' '',
     '01' '04' 'LIFNR'           'T_EKKO' 'R' 'Vendor'                             '' '' '' '' '',
     '01' '05' 'BSTYP'           'T_EKKO' 'R' 'Account'                            '' '' '' '' ''.
ENDFORM.                    " F_BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*&      Form  F_BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_build_layout .
  x_layout-colwidth_optimize = 'X'.
  x_layout-zebra = 'X'.
*  x_layout-info_fieldname = 'LINE_COLOR'.
  x_layout-box_tabname    = 'T_EKKO'.
ENDFORM.                    " F_BUILD_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  F_BUILD_EVENTS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_build_events .
  DATA: lx_events TYPE slis_alv_event.
  REFRESH t_events.

  CONSTANTS: c_formname_subtotal_text TYPE slis_formname
  VALUE 'F_SUBTOTAL_TEXT'.

  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type     = 0
    IMPORTING
      et_events       = t_events[]
    EXCEPTIONS
      list_type_wrong = 1
      OTHERS          = 2.

  LOOP AT t_events INTO lx_events.
    CASE lx_events-name.
      WHEN slis_ev_top_of_page.
        MOVE 'F_TOP_OF_PAGE' TO lx_events-form.
      WHEN slis_ev_pf_status_set.
        MOVE 'F_PF_STATUS_SET' TO lx_events-form.
    ENDCASE.
    MODIFY t_events FROM lx_events.
  ENDLOOP.

*Subtotal
  CLEAR lx_events.
  READ TABLE t_events INTO lx_events
  WITH KEY name = slis_ev_subtotal_text.
  IF sy-subrc EQ 0.
    MOVE c_formname_subtotal_text TO lx_events-form.
    MODIFY t_events FROM lx_events INDEX sy-tabix.
  ENDIF.
ENDFORM.                    " F_BUILD_EVENTS
*&---------------------------------------------------------------------*
*&      Form  F_DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_display_alv_report .
  d_repid = sy-repid.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = d_repid
      is_layout          = x_layout
      it_fieldcat        = t_fieldcatalog[]
      it_sort            = t_sort
      i_default          = 'X'
      i_save             = 'A'
      it_events          = t_events
      is_print           = x_prntparams
    TABLES
      t_outtab           = t_ekko
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.
  IF sy-subrc <> 0.
  ENDIF.
ENDFORM.                    " F_DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*&      Form  F_SUB_FILL_ALV_FIELD_CATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0092   text
*      -->P_0093   text
*      -->P_0094   text
*      -->P_0095   text
*      -->P_0096   text
*      -->P_0097   text
*      -->P_0098   text
*      -->P_0099   text
*      -->P_0100   text
*      -->P_0101   text
*      -->P_0102   text
*----------------------------------------------------------------------*
FORM f_sub_fill_alv_field_catalog  USING    p_rowpos TYPE sycurow
                                            p_colpos TYPE sycucol
                                            p_fldnam TYPE fieldname
                                            p_tabnam TYPE tabname
                                            p_justif TYPE char1
                                            p_seltext TYPE dd03p-scrtext_l
                                            p_out TYPE char1
                                            p_tech TYPE char1
                                            p_qfield TYPE slis_fieldname
                                            p_qtab TYPE slis_tabname
                                            p_key  TYPE char1.

  DATA: lx_fcat TYPE slis_fieldcat_alv.
  lx_fcat-row_pos = p_rowpos.
  lx_fcat-col_pos = p_colpos.
  lx_fcat-fieldname = p_fldnam.
  lx_fcat-tabname = p_tabnam.
  lx_fcat-just = p_justif.
  lx_fcat-seltext_l = p_seltext.
  lx_fcat-no_out = p_out.
  lx_fcat-tech = p_tech.
  lx_fcat-qfieldname = p_qfield.
  lx_fcat-qtabname = p_qtab.
  lx_fcat-key  = p_key.
  APPEND lx_fcat TO t_fieldcatalog.
  CLEAR lx_fcat.
ENDFORM.                    " F_SUB_FILL_ALV_FIELD_CATALOG

*&---------------------------------------------------------------------*
*&      Form  f_top_of_page
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM f_top_of_page.
*ALV Header Declarations
  DATA: lt_header TYPE slis_t_listheader,
        lx_header TYPE slis_listheader,
        lt_line LIKE lx_header-info,
        ld_lines TYPE i,
        ld_linesc(10) TYPE c.

  DATA : ld_year_txt(8).
*Title
  lx_header-typ = 'H'.
  lx_header-info = 'PETRONAS CARIGALI INDONESIA'.
  APPEND lx_header TO lt_header.
  CLEAR lx_header.

  lx_header-typ = 'S'.
  lx_header-info = 'PRODUCTION SHARING CONTRACTS'.
  APPEND lx_header TO lt_header.
  CLEAR lx_header.

  lx_header-typ = 'A'.
  lx_header-info = 'PRODUCTION SHARING CONTRACTS'.
  APPEND lx_header TO lt_header.
  CLEAR lx_header.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = lt_header.
ENDFORM.                    "f_top_of_page

*&---------------------------------------------------------------------*
*&      Form  f_pf_status_set
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->FU_EXTAB   text
*----------------------------------------------------------------------*
FORM f_pf_status_set USING fu_extab TYPE slis_t_extab.
  REFRESH fu_extab.
  SET PF-STATUS 'STANDARD' EXCLUDING fu_extab.
  SET TITLEBAR 'TITLE' WITH 'Financial Quarterly Report - 4ATT'.
ENDFORM.                    "F_ALV_STATUS

ADJUST TEMPLATE, GIU STATUS, MANAGE TR, MANAGE LOCK ENTRIES.

Hey folks,

today i'm gonna show you how to do some job in sap abap module.

first,
adjust template.
in screen painter, there are times when you need most of the button in gui status. well here's the simple way.

just click extras->adjust template
select list viewer and ok,
all of the buttons should have filled by now.

2. make GUI STATUS and GUI TITLE
to make GUI STATUS, you need to make GUI STATUS and GUI TITLE, here's the simple way.




3.Manage TR

in sap abap module, there are times when you have to edit the TR, to make it easier to understand. you can use the SE01 TCODE to do this.


in this step you can edit or change the TR as you wish.

4. manage LOCK ENTRIES.
there are times when you logged out instantiniously or because of the network problem while editing your code, if this happends when you tried to loggin again and edit your code, you will be unable to edit it since your last loggin had lock the entries. all  you have to do is delete the lock entries. use SM12 TCODE.


5. there are times when you wanted to export your report into excel, well sap has already the sistem for that, but you need to activate the GUI STATUS first.

well, that's it for now,
i will post again if i managed to solve something.
adios....