Optimize Ranges

ranges: rng_vbelv for vbfa-vbelv.

*&---------------------------------------------------------------------*
*&      Form  OPTIMIZE_RANGE
*&---------------------------------------------------------------------*
form optimize_range.
data:    lv_lvbelv like vbfa-vbelv,   "önceki
lv_nvbelv like vbfa-vbelv,   "yenisi
lv_vbelv  like vbfa-vbelv,   "yenisi
lv_aralik(1),                "aralık
lv_ltabix like sy-tabix,
lv_ntabix like sy-tabix.

sort rng_vbelv.
clear: lv_lvbelv, lv_nvbelv, lv_aralik.
loop at rng_vbelv.
lv_ntabix = sy-tabix.
lv_nvbelv = rng_vbelv-low.
lv_vbelv = lv_nvbelv - 1.
*    condense lv_vbelv.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input  = lv_vbelv
importing
output = lv_vbelv.

if lv_lvbelv is not initial and lv_lvbelv eq lv_vbelv.
lv_ltabix = lv_ntabix - 1.
read table rng_vbelv index lv_ltabix.
rng_vbelv-option = 'BT'.
rng_vbelv-high   = lv_nvbelv.
modify rng_vbelv index lv_ltabix.
delete rng_vbelv index lv_ntabix.
lv_lvbelv = lv_nvbelv.
continue.
endif.
lv_lvbelv = lv_nvbelv.
endloop.
describe table rng_vbelv lines sy-index.
endform.                    " OPTIMIZE_RANGE

Sıralı tablo kullanımı

types: begin of typ_lfa1,
lifnr type lfa1-lifnr,
name1 type lfa1-name1,
end of typ_lfa1.
data: gt_lfa1 type sorted table of typ_lfa1 with unique key lifnr
with header line.


*&---------------------------------------------------------------------*
*&      Form  READ_LFA1
*&---------------------------------------------------------------------*
form read_lfa1  using    piv_parnr type ihpa-parnr
changing pcs_lfa1  type typ_lfa1.
clear pcs_lfa1.
read table gt_lfa1 into pcs_lfa1 with table key lifnr = piv_parnr.
if sy-subrc ne 0.
select single *
into corresponding fields of pcs_lfa1
from lfa1
where lifnr eq piv_parnr.
check sy-subrc eq 0.
insert pcs_lfa1 into table gt_lfa1.
endif.
endform.                                                    " READ_LFA1

itab to file with separated by coma, semicolon, etc

data: struct type ref to cl_abap_structdescr,
ls_component type abap_compdescr.
lt_tab  type truxs_t_text_data with header line,
ls_tab(4096),
lv_tab       type string.
lv_text      type c length 255.
field-symbols: <lfs_file>  type any.
loop at lt_itab.
clear: lt_tab,
lv_tab.
loop at struct->components into ls_component.
read table gt_fieldcat into gs_fcat with key fieldname = ls_component-name.
check sy-subrc eq 0.
ASSIGN COMPONENT ls_component-name OF STRUCTURE lt_itab TO <lfs_file>.
check sy-subrc eq 0.
case gs_fcat-datatype.
when 'DATS'.
write <lfs_file> to lv_text MM/DD/YYYY.
when 'QUAN' or 'CURR'.
write <lfs_file> to lv_text.
call function 'CLOI_PUT_SIGN_IN_FRONT'
changing
value = lv_text.
when 'INT4'.
write <lfs_file> to lv_text DECIMALS 0.
call function 'CLOI_PUT_SIGN_IN_FRONT'
changing
value = lv_text.
when others.
write <lfs_file> to lv_text.
endcase.
condense lv_text.
concatenate lt_tab lv_text into lt_tab
separated by lv_tab.
lv_tab = ';'.    "separator
endloop.
append lt_tab.
endloop.