2009 May 28 8:08 AM
Hi,
I have a very simple requirement.
Let we have a work area <WA> with fields F1, F2 and F3 and corresponding value as V1, V2 and V3 respectively. WA-F1 = V1,WA-F2 = V2, WA-F3 = V3 .
F1 F2 F3
V1 V2 V3
Now my requirement is I want this field name and value as entry of new internal table with three entries, like shown below.
F V ( F and V are field name of new internal table)
-
F1 V1
F2 V2
F3 V3
-
So our new table have three entries now.
One way have done is, as I know the field name so i read its value and append them one by one in new table, but it doesn't seem good and time consuming if number of fields are quite large let say 50. Then we have to append 50 times.
Do some one have other way to do this, any function module,class or any new logic.
Thanks in advance.
Hemant.
Hi,
I have a very simple requirement.
Let we have a work area <WA> with fields F1, F2 and F3 and corresponding value as V1, V2 and V3 respectively. WA-F1 = V1,WA-F2 = V2, WA-F3 = V3 .
F1 F2 F3
V1 V2 V3
Now my requirement is I want this field name and value as entry of new internal table with three entries, like shown below.
F V ( F and V are field name of new internal table)
-
F1 V1
F2 V2
F3 V3
-
So our new table have three entries now.
One way have done is, as I know the field name so i read its value and append them one by one in new table, but it doesn't seem good and time consuming if number of fields are quite large let say 50. Then we have to append 50 times.
Do some one have other way to do this, any function module,class or any new logic.
Thanks in advance.
Hemant.
2009 May 28 8:14 AM
Hi Dude,
Go through this link :[http://www.saptechies.com/excel-upload-alternative-kcd_excel_ole_to_int_convert/]
2009 May 28 11:38 AM
Hi Hemant,
Try this.
Let us take a matnr and mtart fields are there in the itab , With some values 100 ROH
TYPES: Begin of ty_final,
Value(100) type c,
End of ty_final.
Types : begin of ty_itab
Matnr type matnr,
Mtart type mtart,
End of ty_itab,
Data: it_final type standard table of ty_final,
Wa_final type ty_final,
Itab type standard table of ty_itab,
Wa type ty_itab.
***Loop into the internal table. Now the work area will have Wa_matnr = 001 and wa_mtart = ROH
Loop at itab into wa.
IF NOT wa-matnr is initial.
Concatenate u2018MATNRu2019 WA_MATNR into wa_final-value separated by space.
Append wa_final into it_final.
ENDIF.
IF NOT WA-MTART IS INITIAL
Concatenate u2018MTARTu2019 WA_MTART into wa_final-mtart_value separated by space.
Append wa_final into it_final.
ENDIF.
The final internal table will have
MATNR 001
MTART ROH
2009 May 28 12:22 PM
Hi hemant,
Use method cl_alv_table_create=>create_dynamic_table to get dynamic internal table, using that we can get ouput in the above said format in ALV.
Example:
Say your internal table is declared like
matnr type mara-matnr,
code type wgh01-wwgha,
desc type wgh01-wwghb,
qty type mseg-menge,
sample output:
matnr--
desc3
12354--
10
1234 is material and 3;4;10 are respective quantity
Ur field catelog will be:
lcat-fieldname = 'HEAD'.
lcat-datatype = 'CHAR'.
lcat-seltext = 'Category'.
lcat-intlen = 128.
lcat-outputlen = 50.
append lcat to fieldcat.
clear lcat.
lcat-fieldname = 'MATNR'.
lcat-datatype = 'CHAR'.
lcat-seltext = 'matnr'.
lcat-intlen = 4.
lcat-outputlen = 50.
append lcat to fieldcat.
clear lcat.
Dynamic fields:
loop at it_final into wa_final.
read table fieldcat into lcat with key fieldname = wa_final-code.
if sy-subrc <> 0.
lcat-fieldname = wa_final-code.
lcat-datatype = 'CHAR'.
lcat-seltext = wa_final-desc.
lcat-intlen = 17.
append lcat to fieldcat.
clear lcat.
endif.
endloop.
call method cl_alv_table_create=>create_dynamic_table
exporting
i_style_table =
it_fieldcatalog = fieldcat
i_length_in_byte =
importing
ep_table = newfield
e_style_fname =
exceptions
generate_subpool_dir_full = 1
others = 2
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
assign newfield->* to <dynamic_cat>.
create data newdata like line of <dynamic_cat>.
assign newdata->* to <dynamic_value>.
endform. " buildcat
populate value to the dynamic internal table********
form loadata .
loop at it_final into wa_final.
assign component 'HEAD' of structure <dynamic_value> to <fs1>.
<fs1> = wa_final-head.
assign component 'MATNR' of structure <dynamic_value> to <fs1>.
<fs1> = ' '.
assign component wa_final-code of structure <dynamic_value> to <fs1>.
<fs1> = wa_final-qty.
at end of head.
append <dynamic_value> to <dynamic_cat>.
clear : <dynamic_value>.
endat.
clear : wa_final.
endloop.
You have to pass <dynamic_cat> table in the ALV Grid display function module.
Regards,
Aswin.
2009 May 28 12:55 PM
Hi,
Check this logic..[Convert Rows of internal table to Columns|http://docs.google.com/Doc?id=dfv2hmgs_5d6bcxqgp&hl=en]
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |