PROCESS BEFORE OUTPUT.
MODULE sort_extract.
MODULE sort_extract OUTPUT.
" Required Structure
TYPES: BEGIN OF ts_atank_it.
INCLUDE STRUCTURE zv_atank_it.
TYPES : index TYPE i.
TYPES: END OF ts_atank_it.
" Extract structure
TYPES : BEGIN OF ts_extract,
extract TYPE char512,
index TYPE i,
END OF ts_extract.
" Data Declaration
DATA : gv_newline TYPE char1.
FIELD-SYMBOLS: <fs_rec_from> TYPE x, "Hexadecimal value of from record
<fs_rec_to> TYPE x. "Hexadecimal value of to record
DATA :
lt_atank_it_tmp_view_maint TYPE STANDARD TABLE OF ts_atank_it,
lt_extract TYPE STANDARD TABLE OF ts_extract,
lt_atank_it_tmp TYPE STANDARD TABLE OF ts_atank_it.
DATA : ls_atank_it_tmp_sm30 TYPE ts_atank_it,
ls_extract TYPE ts_extract.
FIELD-SYMBOLS <fs_tank_it_view_maint> TYPE ts_atank_it.
" Logic branched based on the invoking call
IF sy-tcode = 'SM30'. " Create constant here
" Check if the button pressed by user in not the 'New Entries' button
IF NOT sy-ucomm = 'NEWL'.
IF sy-ucomm = 'BACK'
OR sy-ucomm = 'SAVE'.
" Refresh the new line addition flag
CLEAR gv_newline.
ENDIF.
" Prepare the table with values and the indexes
CLEAR lt_atank_it_tmp_view_maint.
LOOP AT extract.
ls_atank_it_tmp_sm30 = CORRESPONDING #( extract ).
ls_atank_it_tmp_sm30-index = sy-tabix.
APPEND ls_atank_it_tmp_sm30 TO lt_atank_it_tmp_view_maint.
CLEAR : ls_atank_it_tmp_sm30.
ENDLOOP.
" Initialize the extract table after copying it's data
CLEAR extract[].
" Sort the content by desired non-key field
SORT lt_atank_it_tmp_view_maint BY <desired non-key field> ASCENDING.
" Remove all the blank lines which are shown on screen
IF gv_newline IS NOT INITIAL.
" For a valid line, all the key fields can never be blank
DELETE lt_atank_it_tmp_view_maint WHERE <key field(s)> IS INITIAL.
ENDIF.
" Move back the sorted contents to Extract table
LOOP AT lt_atank_it_tmp_view_maint
ASSIGNING <fs_tank_it_view_maint>.
APPEND INITIAL LINE TO extract ASSIGNING FIELD-SYMBOL(<fs_extract_view_maint_sort>).
<fs_extract_view_maint_sort> = CORRESPONDING #( <fs_tank_it_view_maint> ).
ENDLOOP.
ELSE.
" User pressed the 'New Entries' button, record the same action
gv_newline = abap_true.
ENDIF.
ELSE.
IF NOT sy-ucomm = 'NEWL'.
IF sy-ucomm = 'BACK'
OR sy-ucomm = 'SAVE'.
CLEAR gv_newline.
ENDIF.
" Make table with Extract data and Index
CLEAR lt_extract.
LOOP AT extract.
ls_extract-extract = extract.
ls_extract-index = sy-tabix.
APPEND ls_extract TO lt_extract.
ENDLOOP.
" Store Extract data into Tank Item structure
CLEAR lt_atank_it_tmp.
LOOP AT extract.
APPEND INITIAL LINE TO lt_atank_it_tmp ASSIGNING <fs_rec_to> CASTING.
ASSIGN extract TO <fs_rec_from> CASTING.
<fs_rec_to> = <fs_rec_from>.
ENDLOOP.
" Store Index in Tank item structure
LOOP AT lt_atank_it_tmp
ASSIGNING FIELD-SYMBOL(<fs_atank>).
<fs_atank>-index = sy-tabix.
ENDLOOP.
CLEAR extract[].
" Sort the content by desired non-key field
SORT lt_atank_it_tmp BY <desired non-key field> ASCENDING.
IF gv_newline IS NOT INITIAL.
" For a valid line, all the key fields can never be blank
DELETE lt_atank_it_tmp_view_maint WHERE <key field(s)> IS INITIAL.
ENDIF.
" Move back the sorted contents to Extract table
LOOP AT lt_atank_it_tmp
ASSIGNING FIELD-SYMBOL(<fs_tank_it>).
" Read Table with same index
READ TABLE lt_extract WITH KEY index = <fs_tank_it>-index
INTO ls_extract.
IF sy-subrc = 0.
APPEND ls_extract-extract TO extract.
ENDIF.
ENDLOOP.
ELSE.
gv_newline = abap_true.
ENDIF.
ENDIF.
ENDMODULE.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 |