2012 Jun 25 3:46 PM
HI All,
IS it possible to have across and down reports in abap list (not alv) for exmaple
my itab has values
BAN MYS 890
BAN HUB 780
BAN MAN 588
BAN BEL 734
BAN TUM 723
MUM MYS 233
MUM HUB 434
MUM MAN 422
MUM BEL 231
MUM TUM 723
what I need is the like this
BAN MUM
MYS 890 233
HUB 780 434
MAN 588 422
BEL 734 231
TUM 723 723
Any help is highly appreciated.
REgards,
Harsha
2012 Jun 26 9:20 AM
REPORT zztransp.
TYPE-POOLS: vrm.
TYPES: BEGIN OF ts_input,
fld1 TYPE string,
fld2 TYPE string,
fld3 TYPE string,
END OF ts_input,
tt_input TYPE STANDARD TABLE OF ts_input,
tt_comp TYPE SORTED TABLE OF string WITH UNIQUE DEFAULT KEY.
FIELD-SYMBOLS: <outtab> TYPE ANY TABLE,
<outlin> TYPE any,
<input> TYPE ts_input,
<comp> TYPE string,
<key> TYPE any,
<col> TYPE any,
<val> TYPE any,
<fld> TYPE any.
DATA:
lt_input TYPE tt_input,
lt_comp TYPE tt_comp,
l_sdescr TYPE REF TO cl_abap_structdescr,
l_sdescr_new TYPE REF TO cl_abap_structdescr,
l_tdescr TYPE REF TO cl_abap_tabledescr,
l_handle TYPE REF TO data,
l_skey TYPE string,
l_component TYPE abap_compdescr,
ls_comp TYPE abap_componentdescr,
lt_components TYPE abap_component_tab.
PARAMETERS:
p_head(5) AS LISTBOX OBLIGATORY VISIBLE LENGTH 15 DEFAULT 'FLD1',
p_keyc(5) AS LISTBOX OBLIGATORY VISIBLE LENGTH 15 DEFAULT 'FLD2',
p_valc(5) AS LISTBOX OBLIGATORY VISIBLE LENGTH 15 DEFAULT 'FLD3'.
INITIALIZATION.
%_p_head_%_app_%-text = 'Head column'.
%_p_keyc_%_app_%-text = 'Key column'.
%_p_valc_%_app_%-text = 'Value column'.
PERFORM set_list USING: 'P_HEAD', 'P_KEYC', 'P_VALC'.
START-OF-SELECTION.
* Fill sample data
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'BAN'. <input>-fld2 = 'MYS'. <input>-fld3 = '890'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'BAN'. <input>-fld2 = 'HUB'. <input>-fld3 = '780'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'BAN'. <input>-fld2 = 'MAN'. <input>-fld3 = '588'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'BAN'. <input>-fld2 = 'BEL'. <input>-fld3 = '734'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'BAN'. <input>-fld2 = 'TUM'. <input>-fld3 = '723'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'MUM'. <input>-fld2 = 'MYS'. <input>-fld3 = '233'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'MUM'. <input>-fld2 = 'HUB'. <input>-fld3 = '434'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'MUM'. <input>-fld2 = 'MAN'. <input>-fld3 = '422'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'MUM'. <input>-fld2 = 'BEL'. <input>-fld3 = '231'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'MUM'. <input>-fld2 = 'TUM'. <input>-fld3 = '723'.
* Get components list
LOOP AT lt_input ASSIGNING <input>.
ASSIGN COMPONENT p_head OF STRUCTURE <input> TO <comp>.
IF sy-subrc = 0.
INSERT <comp> INTO TABLE lt_comp.
ENDIF.
ENDLOOP.
* Build new key field
l_sdescr ?= cl_abap_typedescr=>describe_by_name( 'TS_INPUT' ).
ls_comp-type = l_sdescr->get_component_type( p_keyc ).
ls_comp-name = 'KEY'.
APPEND ls_comp TO lt_components.
* Build new columns
LOOP AT lt_comp ASSIGNING <comp>.
ls_comp-type = l_sdescr->get_component_type( p_valc ).
IF <comp> CO '0123456789'. "Only num. is not allowed for column name
CONCATENATE 'V_' <comp> INTO ls_comp-name.
ELSE.
ls_comp-name = <comp>.
ENDIF.
APPEND ls_comp TO lt_components.
ENDLOOP.
l_sdescr_new = cl_abap_structdescr=>create( lt_components ).
l_tdescr = cl_abap_tabledescr=>create( l_sdescr_new ).
* Create table and structure
CREATE DATA l_handle TYPE HANDLE l_tdescr.
ASSIGN l_handle->* TO <outtab>.
CREATE DATA l_handle TYPE HANDLE l_sdescr_new.
ASSIGN l_handle->* TO <outlin>.
* Sort input table by output key
SORT lt_input BY (p_keyc) ASCENDING.
* Fill output table
READ TABLE lt_input ASSIGNING <input> INDEX 1.
IF sy-subrc = 0.
ASSIGN COMPONENT 'KEY' OF STRUCTURE <outlin> TO <fld>.
ASSIGN COMPONENT p_keyc OF STRUCTURE <input> TO <key>.
IF sy-subrc = 0.
<fld> = <key>.
l_skey = <key>.
ENDIF.
ENDIF.
LOOP AT lt_input ASSIGNING <input>.
ASSIGN COMPONENT p_keyc OF STRUCTURE <input> TO <key>.
IF l_skey <> <key>.
INSERT <outlin> INTO TABLE <outtab>.
CLEAR <outlin>.
ASSIGN COMPONENT 'KEY' OF STRUCTURE <outlin> TO <fld>.
IF sy-subrc = 0.
<fld> = <key>.
ENDIF.
l_skey = <key>.
ENDIF.
ASSIGN COMPONENT p_head OF STRUCTURE <input> TO <col>.
IF <col> CO '0123456789'.
CONCATENATE 'V_' <col> INTO <col>.
ENDIF.
ASSIGN COMPONENT <col> OF STRUCTURE <outlin> TO <fld>.
IF sy-subrc = 0.
ASSIGN COMPONENT p_valc OF STRUCTURE <input> TO <val>.
<fld> = <val>.
ENDIF.
ENDLOOP.
INSERT <outlin> INTO TABLE <outtab>.
* Simple output
SORT lt_input BY fld1 ASCENDING fld2 ASCENDING.
LOOP AT lt_input ASSIGNING <input>.
WRITE: / <input>-fld1, <input>-fld2, <input>-fld3.
ENDLOOP.
ULINE.
WRITE (3) ''.
LOOP AT lt_comp ASSIGNING <comp>.
WRITE (3) <comp>.
ENDLOOP.
LOOP AT <outtab> ASSIGNING <outlin>.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <outlin> TO <fld>.
IF sy-subrc <> 0. EXIT. ENDIF.
IF sy-index = 1.
WRITE /(3) <fld>.
ELSE.
WRITE (3) <fld>.
ENDIF.
ENDDO.
ENDLOOP.
*&---------------------------------------------------------------------*
*& Form SET_LIST
*&---------------------------------------------------------------------*
FORM set_list USING p_id TYPE vrm_id.
DATA: lt_val TYPE vrm_values.
FIELD-SYMBOLS: <v> TYPE vrm_value.
APPEND INITIAL LINE TO lt_val ASSIGNING <v>.
<v>-key = 'FLD1'.
<v>-text = 'FLD1'.
APPEND INITIAL LINE TO lt_val ASSIGNING <v>.
<v>-key = 'FLD2'.
<v>-text = 'FLD2'.
APPEND INITIAL LINE TO lt_val ASSIGNING <v>.
<v>-key = 'FLD3'.
<v>-text = 'FLD3'.
* Setup listbox
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = p_id
values = lt_val
EXCEPTIONS
id_illegal_name = 1
OTHERS = 2.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ENDFORM
2012 Jun 25 3:51 PM
Hi,
U can create a new table with the cross values, sth like this
MYS | 890 | 233 |
HUB | 780 | 434 |
MAN | 588 | 231 |
BEL | 734 | 723 |
TUM | 723 | 723 |
Then display that result in a ALV view.
Regards
2012 Jun 25 4:01 PM
hai
Write both MUM and BAN in fieldcatlog with respective position and try mr. Miguel Alvear said itab in ALV view
2012 Jun 26 5:35 AM
2012 Jun 25 8:47 PM
Radio Yerevan answers: In principle, yes
Looks you are looking for the logic.
For each distinct column 1 value, create a new column.
For each distinct column 2 value, create a new line.
Put each numeric value under column 1 value next to column2 values line.
How'd you do that without ALV, without ABAP, without computer?
Program works accordingly.
Regards
Clemens
2012 Jun 26 9:20 AM
REPORT zztransp.
TYPE-POOLS: vrm.
TYPES: BEGIN OF ts_input,
fld1 TYPE string,
fld2 TYPE string,
fld3 TYPE string,
END OF ts_input,
tt_input TYPE STANDARD TABLE OF ts_input,
tt_comp TYPE SORTED TABLE OF string WITH UNIQUE DEFAULT KEY.
FIELD-SYMBOLS: <outtab> TYPE ANY TABLE,
<outlin> TYPE any,
<input> TYPE ts_input,
<comp> TYPE string,
<key> TYPE any,
<col> TYPE any,
<val> TYPE any,
<fld> TYPE any.
DATA:
lt_input TYPE tt_input,
lt_comp TYPE tt_comp,
l_sdescr TYPE REF TO cl_abap_structdescr,
l_sdescr_new TYPE REF TO cl_abap_structdescr,
l_tdescr TYPE REF TO cl_abap_tabledescr,
l_handle TYPE REF TO data,
l_skey TYPE string,
l_component TYPE abap_compdescr,
ls_comp TYPE abap_componentdescr,
lt_components TYPE abap_component_tab.
PARAMETERS:
p_head(5) AS LISTBOX OBLIGATORY VISIBLE LENGTH 15 DEFAULT 'FLD1',
p_keyc(5) AS LISTBOX OBLIGATORY VISIBLE LENGTH 15 DEFAULT 'FLD2',
p_valc(5) AS LISTBOX OBLIGATORY VISIBLE LENGTH 15 DEFAULT 'FLD3'.
INITIALIZATION.
%_p_head_%_app_%-text = 'Head column'.
%_p_keyc_%_app_%-text = 'Key column'.
%_p_valc_%_app_%-text = 'Value column'.
PERFORM set_list USING: 'P_HEAD', 'P_KEYC', 'P_VALC'.
START-OF-SELECTION.
* Fill sample data
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'BAN'. <input>-fld2 = 'MYS'. <input>-fld3 = '890'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'BAN'. <input>-fld2 = 'HUB'. <input>-fld3 = '780'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'BAN'. <input>-fld2 = 'MAN'. <input>-fld3 = '588'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'BAN'. <input>-fld2 = 'BEL'. <input>-fld3 = '734'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'BAN'. <input>-fld2 = 'TUM'. <input>-fld3 = '723'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'MUM'. <input>-fld2 = 'MYS'. <input>-fld3 = '233'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'MUM'. <input>-fld2 = 'HUB'. <input>-fld3 = '434'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'MUM'. <input>-fld2 = 'MAN'. <input>-fld3 = '422'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'MUM'. <input>-fld2 = 'BEL'. <input>-fld3 = '231'.
APPEND INITIAL LINE TO lt_input ASSIGNING <input>.
<input>-fld1 = 'MUM'. <input>-fld2 = 'TUM'. <input>-fld3 = '723'.
* Get components list
LOOP AT lt_input ASSIGNING <input>.
ASSIGN COMPONENT p_head OF STRUCTURE <input> TO <comp>.
IF sy-subrc = 0.
INSERT <comp> INTO TABLE lt_comp.
ENDIF.
ENDLOOP.
* Build new key field
l_sdescr ?= cl_abap_typedescr=>describe_by_name( 'TS_INPUT' ).
ls_comp-type = l_sdescr->get_component_type( p_keyc ).
ls_comp-name = 'KEY'.
APPEND ls_comp TO lt_components.
* Build new columns
LOOP AT lt_comp ASSIGNING <comp>.
ls_comp-type = l_sdescr->get_component_type( p_valc ).
IF <comp> CO '0123456789'. "Only num. is not allowed for column name
CONCATENATE 'V_' <comp> INTO ls_comp-name.
ELSE.
ls_comp-name = <comp>.
ENDIF.
APPEND ls_comp TO lt_components.
ENDLOOP.
l_sdescr_new = cl_abap_structdescr=>create( lt_components ).
l_tdescr = cl_abap_tabledescr=>create( l_sdescr_new ).
* Create table and structure
CREATE DATA l_handle TYPE HANDLE l_tdescr.
ASSIGN l_handle->* TO <outtab>.
CREATE DATA l_handle TYPE HANDLE l_sdescr_new.
ASSIGN l_handle->* TO <outlin>.
* Sort input table by output key
SORT lt_input BY (p_keyc) ASCENDING.
* Fill output table
READ TABLE lt_input ASSIGNING <input> INDEX 1.
IF sy-subrc = 0.
ASSIGN COMPONENT 'KEY' OF STRUCTURE <outlin> TO <fld>.
ASSIGN COMPONENT p_keyc OF STRUCTURE <input> TO <key>.
IF sy-subrc = 0.
<fld> = <key>.
l_skey = <key>.
ENDIF.
ENDIF.
LOOP AT lt_input ASSIGNING <input>.
ASSIGN COMPONENT p_keyc OF STRUCTURE <input> TO <key>.
IF l_skey <> <key>.
INSERT <outlin> INTO TABLE <outtab>.
CLEAR <outlin>.
ASSIGN COMPONENT 'KEY' OF STRUCTURE <outlin> TO <fld>.
IF sy-subrc = 0.
<fld> = <key>.
ENDIF.
l_skey = <key>.
ENDIF.
ASSIGN COMPONENT p_head OF STRUCTURE <input> TO <col>.
IF <col> CO '0123456789'.
CONCATENATE 'V_' <col> INTO <col>.
ENDIF.
ASSIGN COMPONENT <col> OF STRUCTURE <outlin> TO <fld>.
IF sy-subrc = 0.
ASSIGN COMPONENT p_valc OF STRUCTURE <input> TO <val>.
<fld> = <val>.
ENDIF.
ENDLOOP.
INSERT <outlin> INTO TABLE <outtab>.
* Simple output
SORT lt_input BY fld1 ASCENDING fld2 ASCENDING.
LOOP AT lt_input ASSIGNING <input>.
WRITE: / <input>-fld1, <input>-fld2, <input>-fld3.
ENDLOOP.
ULINE.
WRITE (3) ''.
LOOP AT lt_comp ASSIGNING <comp>.
WRITE (3) <comp>.
ENDLOOP.
LOOP AT <outtab> ASSIGNING <outlin>.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <outlin> TO <fld>.
IF sy-subrc <> 0. EXIT. ENDIF.
IF sy-index = 1.
WRITE /(3) <fld>.
ELSE.
WRITE (3) <fld>.
ENDIF.
ENDDO.
ENDLOOP.
*&---------------------------------------------------------------------*
*& Form SET_LIST
*&---------------------------------------------------------------------*
FORM set_list USING p_id TYPE vrm_id.
DATA: lt_val TYPE vrm_values.
FIELD-SYMBOLS: <v> TYPE vrm_value.
APPEND INITIAL LINE TO lt_val ASSIGNING <v>.
<v>-key = 'FLD1'.
<v>-text = 'FLD1'.
APPEND INITIAL LINE TO lt_val ASSIGNING <v>.
<v>-key = 'FLD2'.
<v>-text = 'FLD2'.
APPEND INITIAL LINE TO lt_val ASSIGNING <v>.
<v>-key = 'FLD3'.
<v>-text = 'FLD3'.
* Setup listbox
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = p_id
values = lt_val
EXCEPTIONS
id_illegal_name = 1
OTHERS = 2.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ENDFORM
2012 Jun 26 12:06 PM
HI Manu,
Thanks a ton for your time and I really appreciate it. Will debug and let you know.
Regards,
Harsha
2012 Jun 27 5:33 AM
HI Manu,
Your program worked very well and would like to award points to you.
Really grateful for your time and brain.
REgards,
Harsha
2012 Jun 27 10:18 AM
You're welcome mate There could be a day I'll need your help in return!
If you don't have other issues, you should close the thread...
Manu.