Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Read internal table columns.

david_escofettrenado
Participant
0 Likes
1,978

Please,

Do you know how to read a internal table columns and assign it a fixed value (for exemple '/')?

I have a structure like LFA1 where i need to fill every field with value '/'. But i don't want to do: LFA1-LIFNR = '/', LFA1-LAND1 = '/', LFA1-NAME1 = '/'....

Best Regards,

David Escofet.

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
878

Hi,

You need to use field symbols like below:


FIELD-SYMBOLS <fs_comp> type any.

"in the loop assign each component of your LFA1 strucutre
DO.
     ASSIGN COMPONENT sy-index OF STRUCTURE lfa1 TO <fs_comp>. 
       IF sy-subrc ne 0.   "exit the loop the no more components left
          EXIT.
       ELSE.
         <fs_comp> = '/'.   "assign your desired value to each component
       ENDIF.
ENDDO.

That's all you need.

M.

3 REPLIES 3
Read only

MarcinPciak
Active Contributor
0 Likes
879

Hi,

You need to use field symbols like below:


FIELD-SYMBOLS <fs_comp> type any.

"in the loop assign each component of your LFA1 strucutre
DO.
     ASSIGN COMPONENT sy-index OF STRUCTURE lfa1 TO <fs_comp>. 
       IF sy-subrc ne 0.   "exit the loop the no more components left
          EXIT.
       ELSE.
         <fs_comp> = '/'.   "assign your desired value to each component
       ENDIF.
ENDDO.

That's all you need.

M.

Read only

Former Member
0 Likes
878

Hi

tables: lfa1.

DATA: l_descr_tab_std TYPE REF  TO cl_abap_structdescr.
 
field-symbols: <wa>    TYPE  abap_compdescr,
               <field> type any.

l_descr_tab_std ?= cl_abap_typedescr=>DESCRIBE_BY_DATA( LFA1  ).

loop at l_descr_tab_std->components ASSIGNING  <wa>.
  if <wa>-name <> ' .....'.
    assign component <wa>-name of structure lfa1 to <field>.
    <field> = '/'.
  endif.
endloop.

U make sure the field of LFA1 is type char

Max

Read only

raviprakash
Product and Topic Expert
Product and Topic Expert
0 Likes
878

>

> Please,

>

> Do you know how to read a internal table columns and assign it a fixed value (for exemple '/')?

>

> I have a structure like LFA1 where i need to fill every field with value '/'. But i don't want to do: LFA1-LIFNR = '/', LFA1-LAND1 = '/', LFA1-NAME1 = '/'....

>

>

> Best Regards,

> David Escofet.

Hi David,

Marcin Pciak solution is the most optimal solution. But i have an alternate solution for you problem. We can first find all the FIELDS of the given structure into an internal table and later loop and fill values in it. The fields of a table can be obtained from the Database Table DD03L.

FIELD-SYMBOLS: <fld> TYPE ANY.

DATA: gt_field TYPE TABLE OF dd03l-fieldname,
      gs_field LIKE LINE OF gt_field,
      l_fa1    TYPE {STRUCTURE}.

SELECT fieldname FROM dd03l INTO TABLE gt_field
                                 WHERE tabname = {STRUCTURE}.

LOOP AT gt_field INTO gs_field.

  ASSIGN COMPONENT gs_field OF STRUCTURE l_fa1 TO <fld>.
  <fld> = '/'.

ENDLOOP.

*Replace {STRUCTURE} with your own structure's name.

Regards,

Ravi.