2012 Feb 10 6:58 AM
Hi ,
I am using alv grid function module, in output i dont want to display the fields which dont have data
Hi ,
I am using alv grid function module, in output i dont want to display the fields which dont have data
2012 Feb 10 7:05 AM
Would the empty fields/column change dynamically ? or is it a fixed column which has no data ? if so you could just remove it from the field catalog after checking if it is initial.
2012 Feb 10 7:16 AM
Hi Venu,
This can be done by
Reading the internal table from which u are displaying the ALV if find one row with valu in field then display tat column or remove from the fieldcatlog. Before displaying the ALV
Regards,
Madhukar Shetty
2012 Feb 10 7:16 AM
we dont know which column has no data..... we have to do it dynamically
2012 Feb 10 7:19 AM
we dont know which column has no data..... we have to do it dynamically
This code does that dynamically, Here the field2 & Fiels4 are not displayed.
TYPE-POOLS:slis,abap.
TYPES:BEGIN OF ty_stru,
field1 TYPE c,field2 TYPE c,field3 TYPE c,field4 TYPE c,
END OF ty_stru.
DATA:itab TYPE TABLE OF ty_stru,
wa_stru TYPE ty_stru,
lv_repid TYPE sy-repid,
wa_fieldcat TYPE slis_fieldcat_alv,
it_fieldcat TYPE TABLE OF slis_fieldcat_alv,
it_details TYPE abap_compdescr_tab,
wa_components TYPE abap_compdescr,
lf_ref_descr TYPE REF TO cl_abap_structdescr,
lv_field TYPE abap_compname.
FIELD-SYMBOLS:<fs> TYPE ANY,
<fs1> TYPE ANY.
lf_ref_descr ?= cl_abap_typedescr=>describe_by_data( wa_stru ).
it_details[] = lf_ref_descr->components[].
wa_stru-field1 = 'A'.wa_stru-field3 = 'C'.APPEND wa_stru TO itab.
wa_stru-field1 = 'X'.wa_stru-field3 = 'Y'.APPEND wa_stru TO itab.
IF NOT itab[] IS INITIAL.
LOOP AT it_details INTO wa_components.
ASSIGN wa_components-name TO <fs>.
CHECK sy-subrc = 0.
SORT itab BY (<fs>) DESCENDING.
CONCATENATE 'WA_STRU' '-' <fs> INTO lv_field .
ASSIGN (lv_field) TO <fs1>.
CHECK sy-subrc = 0.
READ TABLE itab INTO wa_stru INDEX 1 TRANSPORTING (<fs>).
IF sy-subrc = 0 AND ( NOT <fs1> IS INITIAL ).
wa_fieldcat-fieldname = wa_components-name.
wa_fieldcat-seltext_m = wa_components-name.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
ENDIF.
ENDLOOP.
lv_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = lv_repid
it_fieldcat = it_fieldcat[]
TABLES
t_outtab = itab[].
ENDIF.
2012 Feb 10 9:14 AM
Hello Keshav,
Imho this code is not fool-proof
SORT itab BY (<fs>) DESCENDING.You're assuming none of the fields have negative values, i.e., 0.00 > 1.00- So your code will assume the field as INITIAL although it is not!
@OP: NO_OUT will not hide the field from being displayed on the screen via layout management. If you want to stop this behaviour, mark the field as TECHNICAL.
BR,
Suhas
Edited by: Suhas Saha on Feb 10, 2012 2:45 PM
2012 Feb 10 9:18 AM
Yes - Your analysis was really good
So how can we check if the field has any contents in the row. Now ideas as of now .. Any hints ? Without using a loop where not initial .
As I am working in lower version its not accepting anything which was coded in ECC6. Is read statement with not initial possible ?
Kesav
2012 Feb 10 9:51 AM
> So how can we check if the field has any contents in the row. Now ideas as of now .. Any hints ? Without using a loop where not initial .
Hint: You need to iterate on the table for every fieldcatalog field & check if the field is initial!
I am on ABAP Release 702, so it's easy for me I can use a dynamic delete to check for initial values.
BR,
Suhas
PS: I don't have access to SAP at this moment, so can't post the code snippet.
2012 Feb 10 10:27 AM
How you are hiding the Fields in the Layout...
If you are hiding with NO_OUT = 'X' and TECH = 'X' Then your requirement should work well.
Or else use SAP ALV standard Downloading process.
Also Please check the below code for Field Hiding.
Cost
Clear X_FCAT.
X_FCAT-COL_POS = '22'.
X_FCAT-OUTPUTLEN = '18'.
X_FCAT-FIELDNAME = 'COST'.
X_FCAT-TABNAME = 'TB_DISPLAY_WM'.
X_FCAT-SCRTEXT_S = 'Cost'(058).
If Not G_Y3P Is Initial.
X_FCAT-NO_OUT = 'X'.
X_FCAT-TECH = 'X'.
Endif.
Append X_FCAT To P_TB_FCAT.
Reward points if help full.
2012 Feb 10 7:21 AM
hi madhukar shetty,
I am using dynamic internal table with so many number of fields,
and can u send me the syntax which you posted.
regards,
venu.ch
2012 Feb 10 7:28 AM
If you are using a dynamic internal table then before the line of code
lf_ref_descr ?= cl_abap_typedescr=>describe_by_data( wa_stru ).
add
field-symbols:<fs_line> type any.
data:wf_ref type ref to data.
create data wf_ref like line of <dyn_tab>.
assign wf_ref->* to <fs_line>.
lf_ref_descr ?= cl_abap_typedescr=>describe_by_data( <fs_line> ).
Change
SORT itab BY (<fs>) DESCENDING. as SORT <dyntab> BY (<fs>) DESCENDING
CONCATENATE 'WA_STRU' '-' <fs> INTO lv_field . as CONCATENATE '<FS_LINE>' '-' <fs> INTO lv_field .
READ TABLE itab INTO wa_stru as READ TABLE <dyntab> assigning <fs_line>.
2012 Feb 10 7:32 AM
Hi
ok so you can do is during generation of data in the dynamic table based on the value create the fieldcatlog.
Kindly revert if you dont get it.
Regards,
Madhukar Shetty
2012 Feb 10 8:46 AM
first i created fieldcatalog for the output table,
next i created dynamci internal table based on fieldcatalog,
now in output table some fields dont have data, so we dont want to display in the output,
am using some like this, is it correct?
<fs_table> is output table, in where conditon wt we have to give?
here we have to check for the column which dont have data
LOOP AT IT_FCAT TRANSPORTING NO FIELDS WHERE COL_POS > 0.
READ TABLE <FS_TABLE> INTO <FS_WA> INDEX SY-TABIX.
IF SY-SUBRC EQ 0.
W_FCAT-NO_OUT = 'X'.
MODIFY IT_FCAT FROM W_FCAT.
ENDIF.
ENDLOOP.
regards,
venu.ch
2012 Feb 10 9:07 AM
Check if this works
LOOP AT It_Fcat into wa_fcat.
lv_tabix = sy-tabix.
ASSIGN wa_fcat-fieldname TO <fs>.
CHECK sy-subrc = 0.
SORT <fs_table> BY (<fs>) DESCENDING.
CONCATENATE '<FS_WA>' '-' <fs> INTO lv_field .
ASSIGN (lv_field) TO <fs1>.
CHECK sy-subrc = 0.
READ TABLE <fs_table> assigning <fs_wa> INDEX 1 TRANSPORTING (<fs>).
IF sy-subrc = 0 AND <fs1> IS INITIAL.
wa_fcat-no_out = 'X'.
modify It_Fcat from wa_fcat index lv_tabix.
endif.
endloop.
2012 Feb 10 7:23 AM
This seems to be a slightly complex requirement. You would need to then dynamically l read each field, set flags if even a single value is found for a particular field( flag unset for empty fields) and then dynamical populate your field catalog accordingly.
Field Symbols are your best bet when doing this.
2012 Feb 10 7:28 AM
Hello venu,
Find the column which is initial by checking the condition and then remove from field catalog table using no_out option of field catalog.
i_catlog_line-fieldname = p_fieldname. "p_fieldnae is column you want not to be displayed
* To hide extra fields in catalog
i_catlog_line-no_out = 'X'.
* Reading table catlog for removing the fields which are not needed in grid
read table i_catlog with key fieldname = p_fieldname
transporting no fields.
if sy-subrc = 0.
* Modifying table catlog
modify i_catlog from i_catlog_line
index sy-tabix
transporting no_out.
endif.
The above code is used if you want that field to be in field catlog but not to be displayed in ALV.
Regards,
Supriya.
2012 Feb 10 9:07 AM
hi,
how can we know which column dont have data.....can you send me the syntax.
regards,
venu.ch
2012 Feb 10 9:29 AM
hi,
LOOP AT IT_FCAT TRANSPORTING NO FIELDS WHERE COL_POS > 0.
READ TABLE <FS_TABLE> INTO <FS_WA> INDEX SY-TABIX.
IF SY-SUBRC EQ 0.
W_FCAT-NO_OUT = 'X'.
MODIFY IT_FCAT FROM W_FCAT.
ELSE.
STOP.
ENDIF.
ENDLOOP.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |