2008 Jul 17 8:55 AM
Hi,
there is why to now how much Colman i have in internal table?
Regards
2008 Jul 17 9:02 AM
Hi,
please take a look into the well documentated classes of the runtime type service (RTTS). The root class for this is CL_ABAP_TYPEDESCR.
For internal table the classes CL_ABAP_TABLEDESCR and CL_ABAP_STRUCTDESCR might be interesting for you.
[Determining the Attributes of Data Objects|http://help.sap.com/saphelp_nw70/helpdata/EN/fc/eb3145358411d1829f0000e829fbfe/frameset.htm]
Regards Rudi
Hi,
there is why to now how much Colman i have in internal table?
Regards
2008 Jul 17 8:59 AM
2008 Jul 17 9:02 AM
hi,
i now that for table row number i use sy-TFILL
what i have to use to now table colman nubers
Regards
2008 Jul 17 8:59 AM
I think you're asking how to find the number of columns in an internal table.
Easy. Let's assume your table is call it_itab,
DATA: l_count TYPE i,
lp_data TYPE REF TO DATA.
FIELD-SYMBOLS: <l_field> TYPE any,
<ls_wa> TYPE any.
CREATE DATA lp_data LIKE LINE OF it_itab.
ASSIGN lp_data->* TO <ls_wa>.
l_count = 0.
DO.
ADD 1 TO l_count.
ASSIGN COMPONENT l_count OF STRUCTURE <ls_wa> TO <l_field>.
IF sy-subrc IS NOT INITIAL.
EXIT.
ENDIF.
ENDDO.
SUBTRACT 1 FROM l_count.
WRITE: / 'Number of columns', l_count.Edited by: Matthew Billingham on Jul 17, 2008 10:03 AM
Better solution
2008 Jul 17 9:02 AM
Hi,
please take a look into the well documentated classes of the runtime type service (RTTS). The root class for this is CL_ABAP_TYPEDESCR.
For internal table the classes CL_ABAP_TABLEDESCR and CL_ABAP_STRUCTDESCR might be interesting for you.
[Determining the Attributes of Data Objects|http://help.sap.com/saphelp_nw70/helpdata/EN/fc/eb3145358411d1829f0000e829fbfe/frameset.htm]
Regards Rudi
2008 Jul 17 9:03 AM
>
> Hi,
>
> please take a look into the well documentated classes of the runtime type service (RTTS). The root class for this is CL_ABAP_TYPEDESCR.
>
> For internal table the classes CL_ABAP_TABLEDESCR and CL_ABAP_STRUCTDESCR might be interesting for you.
>
> [Determining the Attributes of Data Objects|http://help.sap.com/saphelp_nw70/helpdata/EN/fc/eb3145358411d1829f0000e829fbfe/frameset.htm]
>
> Regards Rudi
Much better solution than mine!
2008 Jul 17 9:06 AM
hi Matthew Billingham ,
i not familiar with classes maybe u can give me e.g.
Regards
2008 Jul 17 9:13 AM
Hi,
see this example:
DATA gt_mara TYPE mara_tab.
DATA gx_struc TYPE REF TO cl_abap_structdescr.
DATA gx_table TYPE REF TO cl_abap_tabledescr.
DATA gv_lines TYPE i.
FIELD-SYMBOLS <gs_components> TYPE abap_compdescr.
FIELD-SYMBOLS <gv_field> TYPE ANY.
gx_table ?= cl_abap_typedescr=>describe_by_data( gt_mara ).
gx_struc ?= gx_table->get_table_line_type( ).
DESCRIBE TABLE gx_struc->components LINES gv_lines.
Regards Rudi
2008 Jul 17 9:19 AM
Try this code.
DATA : BEGIN OF it_mara OCCURS 0,
matnr LIKE mara-matnr,
ersda LIKE mara-ersda,
END OF it_mara.
DATA : p(5) TYPE c.
FIELD-SYMBOLS: <fs_record> TYPE ANY.
FIELD-SYMBOLS: <fs_comp> TYPE ANY.
IF it_mara IS NOT INITIAL.
ASSIGN it_mara TO <fs_record>.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs_record> TO <fs_comp>.
IF sy-subrc EQ 0.
p = p + 1.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
WRITE : / p.
2008 Jul 17 9:20 AM
>
> hi Matthew Billingham ,
>
> i not familiar with classes maybe u can give me e.g.
>
> Regards
Follow Rudi's approach
Or - no classes with this one - haven't tried it, but it should work:
DATA: lp_data TYPE REF TO data.
FIELD-SYMBOLS: <ls_wa>.
DATA: l_count TYPE i,
l_type TYPE c.
CREATE DATA lp_data LIKE LINE OF itab.
ASSIGN lp_data->* TO <ls_wa>.
DESCRIBE FIELD <ls_wa> l_type COMPONENTS l_count.Read the abap help on keywords DESCRIBE FIELD.
matt
2008 Jul 17 9:21 AM
>
> Try this code.
>
> DATA : BEGIN OF it_mara OCCURS 0,
> matnr LIKE mara-matnr,
> ersda LIKE mara-ersda,
> END OF it_mara.
>
> DATA : p(5) TYPE c.
> FIELD-SYMBOLS: <fs_record> TYPE ANY.
> FIELD-SYMBOLS: <fs_comp> TYPE ANY.
>
> IF it_mara IS NOT INITIAL.
> ASSIGN it_mara TO <fs_record>.
> DO.
> ASSIGN COMPONENT sy-index OF STRUCTURE <fs_record> TO <fs_comp>.
> IF sy-subrc EQ 0.
> p = p + 1.
> ELSE.
> EXIT.
> ENDIF.
> ENDDO.
> ENDIF.
> WRITE : / p.
Doesn't work if the table has no records in it.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |