11-05-2008 5:39 PM
Hello experts:
I have a little problem, I want to create an ALV field with 4 decimales, it's a dinamic table, but when the alv report shows the fields it shows only 2 decimals, here the main code for explaining me better:
Here the code for create the field with decimals:
* Netpr
lv_cols = lv_cols + 1.
MOVE lv_cols TO wa_it_fldcat-col_pos.
MOVE 'NETPR' TO wa_it_fldcat-fieldname.
MOVE 'Net Price' TO wa_it_fldcat-scrtext_l.
MOVE 'Net Price' TO wa_it_fldcat-scrtext_m.
MOVE 'Net Pr' TO wa_it_fldcat-scrtext_s.
MOVE 'CURR' TO wa_it_fldcat-datatype.
MOVE 'P' TO wa_it_fldcat-inttype.
MOVE 11 TO wa_it_fldcat-intlen.
MOVE 4 TO wa_it_fldcat-decimals.
MOVE '' TO wa_it_fldcat-ref_field.
MOVE '' TO wa_it_fldcat-ref_table.
APPEND wa_it_fldcat TO t_fldcat.
After create more fields, here the code for create the dinamic ALV table:
* Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = t_fldcat
IMPORTING
ep_table = t_newtable.
ASSIGN t_newtable->* TO <t_dyntable>.
* Create dynamic work area and assign to FS
CREATE DATA t_newline LIKE LINE OF <t_dyntable>.
ASSIGN t_newline->* TO <fs_dyntable>.
After this method, the structure of the work area having the data type of the fields and all the atributes, the decimals of the NETPR fields just have 2 decimals =(
I hope my explanation it's clear.
Any help with this issue it's very welcome, thank you very much for your time.
Miriam
11-05-2008 6:20 PM
I think you may remove this statement
MOVE 'CURR' TO wa_it_fldcat-datatype.
11-05-2008 5:53 PM
i think it is directly taking NETPR data element properties, change the name to some thing else and see.
11-05-2008 6:11 PM
No, the ekpo-netpr has only 2 decimals, that's why I'm creating the field manually.
11-05-2008 6:20 PM
I think you may remove this statement
MOVE 'CURR' TO wa_it_fldcat-datatype.
11-05-2008 6:30 PM
Hi
Xiaonan Hu is right: u need to delete the row where u transfer CURR as type:
* Netpr
lv_cols = lv_cols + 1.
MOVE lv_cols TO wa_it_fldcat-col_pos.
MOVE 'NETPR' TO wa_it_fldcat-fieldname.
MOVE 'Net Price' TO wa_it_fldcat-scrtext_l.
MOVE 'Net Price' TO wa_it_fldcat-scrtext_m.
MOVE 'Net Pr' TO wa_it_fldcat-scrtext_s.
*MOVE 'CURR' TO wa_it_fldcat-datatype.
MOVE 'P' TO wa_it_fldcat-inttype.
MOVE 11 TO wa_it_fldcat-intlen.
MOVE 4 TO wa_it_fldcat-decimals.
MOVE '' TO wa_it_fldcat-ref_field.
MOVE '' TO wa_it_fldcat-ref_table.
APPEND wa_it_fldcat TO t_fldcat.
If you transfer CURR, the method will defined a type p with 2 decimals by default, so it's useless to indicate the decimals in this case.
Infact the method calls the fm ALV_TABLE_CREATE, and here the abap code is:
- for CURR type:
elseif ls_fieldcat-datatype = 'CURR'.
concatenate 'DATA:'
ls_fieldcat-fieldname
'TYPE'
ls_fieldcat-inttype
'DECIMALS 2.'
into lt_source-line separated by space.
- for P type
if ls_fieldcat-inttype = 'P' and not ls_fieldcat-decimals is
initial.
replace '.' with 'DECIMALS' into lt_source-line.
concatenate lt_source-line ls_fieldcat-decimals '.' into
lt_source-line separated by space.
endif.
Max
11-05-2008 11:14 PM
Well, I've commented the datatype CURR, but now when I assign the value to the field of the dynamic table, there's no value, even the field have it, here the code for better explanation:
* Netpr
lv_cols = lv_cols + 1.
MOVE lv_cols TO wa_it_fldcat-col_pos.
MOVE 'NETPR' TO wa_it_fldcat-fieldname.
MOVE 'Net Price' TO wa_it_fldcat-scrtext_l.
MOVE 'Net Price' TO wa_it_fldcat-scrtext_m.
MOVE 'Net Pr' TO wa_it_fldcat-scrtext_s.
* MOVE 'CURR' TO wa_it_fldcat-datatype.
MOVE 'P' TO wa_it_fldcat-inttype.
MOVE 8 TO wa_it_fldcat-intlen.
MOVE 4 TO wa_it_fldcat-decimals.
MOVE '' TO wa_it_fldcat-ref_field.
MOVE '' TO wa_it_fldcat-ref_table.
APPEND wa_it_fldcat TO t_fldcat.
Here the code to move the value to the dynamic table field:
MOVE 'NETPR' TO wa_flname.
lv_netpr = wa_ekko_ekpo-netpr * lv_total_menge.
MOVE lv_netpr TO fieldvalue.
ASSIGN COMPONENT wa_flname
OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
<fs_fldval> = fieldvalue.
lv_netpr definition is:
lv_netpr TYPE p DECIMALS 4
And fieldvalue definition is:
DATA: fieldvalue(40) TYPE c,
And now the <fs_fldval> doesn't have any value, there are some other fields whom definition is like some sap table type, for example ekpo-menge, and this fields are filled normally.
11-06-2008 10:07 AM
Hi
Your code works fine:
DATA: T_FLDCAT TYPE LVC_T_FCAT,
WA_IT_FLDCAT TYPE LVC_S_FCAT,
LV_COLS TYPE LVC_S_FCAT-COL_POS.
DATA: T_NEWTABLE TYPE REF TO DATA,
T_NEWLINE TYPE REF TO DATA.
FIELD-SYMBOLS: <T_DYNTABLE> TYPE TABLE,
<FS_DYNTABLE> TYPE ANY,
<FS_FLDVAL> TYPE ANY.
DATA: WA_FLNAME(40) TYPE C,
FIELDVALUE(40) TYPE C,
LV_NETPR TYPE P DECIMALS 4.
START-OF-SELECTION.
* Netpr
LV_COLS = LV_COLS + 1.
MOVE LV_COLS TO WA_IT_FLDCAT-COL_POS.
MOVE 'NETPR' TO WA_IT_FLDCAT-FIELDNAME.
MOVE 'Net Price' TO WA_IT_FLDCAT-SCRTEXT_L.
MOVE 'Net Price' TO WA_IT_FLDCAT-SCRTEXT_M.
MOVE 'Net Pr' TO WA_IT_FLDCAT-SCRTEXT_S.
* MOVE 'CURR' TO WA_IT_FLDCAT-DATATYPE.
MOVE 'P' TO WA_IT_FLDCAT-INTTYPE.
MOVE 11 TO WA_IT_FLDCAT-INTLEN.
MOVE 4 TO WA_IT_FLDCAT-DECIMALS.
MOVE '' TO WA_IT_FLDCAT-REF_FIELD.
MOVE '' TO WA_IT_FLDCAT-REF_TABLE.
APPEND WA_IT_FLDCAT TO T_FLDCAT.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = T_FLDCAT
IMPORTING
EP_TABLE = T_NEWTABLE.
ASSIGN T_NEWTABLE->* TO <T_DYNTABLE>.
* Create dynamic work area and assign to FS
CREATE DATA T_NEWLINE LIKE LINE OF <T_DYNTABLE>.
ASSIGN T_NEWLINE->* TO <FS_DYNTABLE>.
MOVE 'NETPR' TO WA_FLNAME.
LV_NETPR = '10.4444' * 2.
* MOVE LV_NETPR TO FIELDVALUE.
ASSIGN COMPONENT WA_FLNAME
OF STRUCTURE <FS_DYNTABLE> TO <FS_FLDVAL>.
<FS_FLDVAL> = LV_NETPR.
WRITE: <FS_FLDVAL>.
Max
11-05-2008 6:28 PM
Hi,
Try this ...Give a Reference to the currency unit
Link to currency unit
u2022 Cfieldname (currency unit field name): This is used for currency fields that have a reference to any unit field. This is only relevant for amount columns with associated unit. This parameter contains the Name of the internal output table field containing the currency unit associated with the amount field FIELDCAT-FIELDNAME. The field in FIELDCAT-CFIELDNAME must have its own field catalog entry.
Value set: SPACE, output table field name.
u2022 Ctabname (internal currency unit field output table): Name of the internal output table containing the FIELDCAT-CFIELDNAME field.
Value set: SPACE, output table field name.
In this Cfieldname....give a Table field which is used to store a value with four decimal places and of type P.
If required you can create a DDIC element for this also.
11-07-2008 6:22 PM
Hi Max:
I don't know why on the output and debug mode, is empty this field, =(
11-11-2008 3:54 PM
Thank you very much for your help, my problem was solved, I tried with the following code and now works fine:
* Netpr
lv_cols = lv_cols + 1.
MOVE lv_cols TO wa_it_fldcat-col_pos.
MOVE 'NETPR' TO wa_it_fldcat-fieldname.
MOVE 'Net Price' TO wa_it_fldcat-scrtext_l.
MOVE 'Net Price' TO wa_it_fldcat-scrtext_m.
MOVE 'Net Pr' TO wa_it_fldcat-scrtext_s.
MOVE 'DEC' TO wa_it_fldcat-datatype.
MOVE 'P' TO wa_it_fldcat-inttype.
MOVE 17 TO wa_it_fldcat-intlen.
MOVE 4 TO wa_it_fldcat-decimals.
MOVE '' TO wa_it_fldcat-ref_field.
MOVE '' TO wa_it_fldcat-ref_table.
APPEND wa_it_fldcat TO t_fldcat.
I don't know why didn't work without fillying the datatype field, but with this it's done. 😃
Best regards,