2012 Jan 26 2:33 PM
Hello,
I have table with list of names and operations ,the table can store more than one name per operation and
there is option that in the table can be 1...n operation ,In the output of the method I need to return all
the operation in different table ,I.e. table for the list of names operation1 , names and operation2 etc.
I Have 10 potential operations and I don't want to export 10 tables in the method.
There is elegant way to do it ?
The tables that I need to return is like
name
operation_type
Regards
Joy
2012 Jan 26 3:00 PM
You can try creating Deep Internal table and export it back from the method. In the Deep table, create a Field for Operation and and a table to contain the names.
Something like this:
TYPES: BEGIN OF lty_name,
field TYPE char30,
END OF lty_name.
TYPES: lty_t_name TYPE STANDARD TABLE OF lty_name WITH DEFAULT KEY.
TYPES: BEGIN OF lty_export,
operation TYPE char10,
name TYPE lty_t_name,
END OF lty_export.
DATA: li_export TYPE STANDARD TABLE OF lty_export.
FIELD-SYMBOLS: <lfs_exp> LIKE LINE OF li_export,
<lfs_name> LIKE LINE OF <lfs_exp>-name.
APPEND INITIAL LINE TO li_export ASSIGNING <lfs_exp>.
<lfs_exp>-operation = 'Operation1'.
APPEND INITIAL LINE TO <lfs_exp>-name ASSIGNING <lfs_name>.
<lfs_name>-field = 'name1'.
APPEND INITIAL LINE TO <lfs_exp>-name ASSIGNING <lfs_name>.
<lfs_name>-field = 'name2'.
APPEND INITIAL LINE TO <lfs_exp>-name ASSIGNING <lfs_name>.
<lfs_name>-field = 'name3'.
APPEND INITIAL LINE TO li_export ASSIGNING <lfs_exp>.
<lfs_exp>-operation = 'Operation2'.
APPEND INITIAL LINE TO <lfs_exp>-name ASSIGNING <lfs_name>.
<lfs_name>-field = 'name4'.
APPEND INITIAL LINE TO <lfs_exp>-name ASSIGNING <lfs_name>.
<lfs_name>-field = 'name5'.
Regards,
Naimesh Patel
Hello,
I have table with list of names and operations ,the table can store more than one name per operation and
there is option that in the table can be 1...n operation ,In the output of the method I need to return all
the operation in different table ,I.e. table for the list of names operation1 , names and operation2 etc.
I Have 10 potential operations and I don't want to export 10 tables in the method.
There is elegant way to do it ?
The tables that I need to return is like
name
operation_type
Regards
Joy
2012 Jan 26 2:47 PM
2012 Jan 26 2:53 PM
Hi ,
You can return a table ( GT_MAIN_TABLE ) that has of a deep structure.
TT_STANDART
name type char50
operation_type optype " That is your data type
GT_MAIN_TABLE
name type char50
all_operations type TT_STANDART " Which consists of two fields.
For eveyline
Name -> "Myoperation"
all_operations -> TABLE Which has n entries ->>> "Myoperation" 01
"Myoperation2" 02
"Myoperation3" 03
Regards.
2012 Jan 26 3:00 PM
You can try creating Deep Internal table and export it back from the method. In the Deep table, create a Field for Operation and and a table to contain the names.
Something like this:
TYPES: BEGIN OF lty_name,
field TYPE char30,
END OF lty_name.
TYPES: lty_t_name TYPE STANDARD TABLE OF lty_name WITH DEFAULT KEY.
TYPES: BEGIN OF lty_export,
operation TYPE char10,
name TYPE lty_t_name,
END OF lty_export.
DATA: li_export TYPE STANDARD TABLE OF lty_export.
FIELD-SYMBOLS: <lfs_exp> LIKE LINE OF li_export,
<lfs_name> LIKE LINE OF <lfs_exp>-name.
APPEND INITIAL LINE TO li_export ASSIGNING <lfs_exp>.
<lfs_exp>-operation = 'Operation1'.
APPEND INITIAL LINE TO <lfs_exp>-name ASSIGNING <lfs_name>.
<lfs_name>-field = 'name1'.
APPEND INITIAL LINE TO <lfs_exp>-name ASSIGNING <lfs_name>.
<lfs_name>-field = 'name2'.
APPEND INITIAL LINE TO <lfs_exp>-name ASSIGNING <lfs_name>.
<lfs_name>-field = 'name3'.
APPEND INITIAL LINE TO li_export ASSIGNING <lfs_exp>.
<lfs_exp>-operation = 'Operation2'.
APPEND INITIAL LINE TO <lfs_exp>-name ASSIGNING <lfs_name>.
<lfs_name>-field = 'name4'.
APPEND INITIAL LINE TO <lfs_exp>-name ASSIGNING <lfs_name>.
<lfs_name>-field = 'name5'.
Regards,
Naimesh Patel
2012 Jan 26 4:49 PM
HI Naimesh Patel ,
I have created deep structure but my question is assume that the table is like follows:
it_input
Name operation
aaaa t
bbbb t
sssss q
yyyyy q
.....What I need in this case (assume that I have just 2 operation) table with two entries
it_out
operation names
t -> table that include aaa and bbbb
q ->table that include ssss and yyyyy
How I can do that , I try loop with case to operation but I dont succeeded?
Thanks,
Joy
2012 Jan 26 5:02 PM
Try something like this:
TYPES: BEGIN OF lty_input,
operation TYPE char10,
name TYPE char30,
END OF lty_input.
DATA: li_input TYPE STANDARD TABLE OF lty_input.
DATA: lwa_input LIKE LINE OF li_input.
lwa_input-operation = 'Operation1'.
lwa_input-name = 'name1'.
APPEND lwa_input TO li_input.
lwa_input-operation = 'Operation1'.
lwa_input-name = 'name2'.
APPEND lwa_input TO li_input.
lwa_input-operation = 'Operation1'.
lwa_input-name = 'name3'.
APPEND lwa_input TO li_input.
lwa_input-operation = 'Operation2'.
lwa_input-name = 'name4'.
APPEND lwa_input TO li_input.
lwa_input-operation = 'Operation2'.
lwa_input-name = 'name5'.
APPEND lwa_input TO li_input.
SORT li_input BY operation.
DATA: lwa_exp LIKE LINE OF li_export,
lwa_name LIKE LINE OF lwa_exp-name.
LOOP AT li_input INTO lwa_input.
lwa_exp-operation = lwa_input-operation.
lwa_name-field = lwa_input-name.
APPEND lwa_name TO lwa_exp-name.
AT END OF operation.
APPEND lwa_exp TO li_export.
ENDAT.
ENDLOOP.
Regards,
Naimesh Patel
2012 Jan 26 5:03 PM
have 2 input tables it1 and it2 with same data.
sort it1 by operation
delete adjacent duplicates from it1 comparing operation
loop at it1.
loop at it2 where operation = it1-operation.
populate your deep table here.
endloop
endloop
Edited by: Kartik Tarla on Jan 26, 2012 10:33 PM
2012 Jan 26 5:15 PM
Hi ,
I think this could give an idea. First get distinct operations and collect all data into it_main_output.
Then use it anywhere as your needed operation.
REPORT zz_test.
TYPES : BEGIN OF ts_input ,
name TYPE char50 ,
operation TYPE char50,
END OF ts_input.
TYPES : t_input TYPE TABLE OF ts_input .
DATA : it_input TYPE TABLE OF ts_input WITH HEADER LINE.
DATA : ls_input LIKE LINE OF it_input.
DATA : BEGIN OF it_input_ops OCCURS 0,
operation TYPE char50,
END OF it_input_ops.
*DATA : it_
*** Here it_input is filled with values
***aaaa t
***bbbb t
***sssss q
***yyyyy q
it_input-name = 'aaaa'.
it_input-operation = 't'.
APPEND it_input.
it_input-name = 'bbbb'.
it_input-operation = 't'.
APPEND it_input.
it_input-name = 'sssss'.
it_input-operation = 'q'.
APPEND it_input.
it_input-name = 'yyyyy'.
it_input-operation = 'q'.
APPEND it_input.
DATA : BEGIN OF it_main_output OCCURS 10,
operation TYPE char50,
content TYPE t_input, " Here is the table for one name of operation
END OF it_main_output.
SORT it_input.
LOOP AT it_input.
CLEAR : it_input_ops.
it_input_ops-operation = it_input-operation.
COLLECT it_input_ops.
ENDLOOP.
LOOP AT it_input_ops. " Distinct Operations
CLEAR : it_main_output.
it_main_output-operation = it_input_ops-operation.
LOOP AT it_input INTO ls_input
WHERE operation = it_input_ops-operation.
" If we have same entry Collect will prevent to double
" Otherwise we can use append here
COLLECT ls_input INTO it_main_output-content.
ENDLOOP.
APPEND it_main_output.
ENDLOOP.
"RESULT ROWS OF it_main_output.
"1 t Standard Table[2x2(200)]
"2 q Standard Table[2x2(200)]
***To get an operations TABLE
READ TABLE it_main_output WITH KEY operation = 't'.
IF sy-subrc EQ 0.
LOOP AT it_main_output-content INTO ls_input.
WRITE : / ls_input-name , ls_input-operation.
ENDLOOP.
ENDIF.And the output of the program is ;
aaa t
bbb t
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |