Skip to Content

Assinging values to the Internal table base don the field name Dyanamically

Hi Experts,

I have a situation where I have 2 internal tables Source and Target of same structure. Source has data for all the fields and I have the 3rd Internal table which will have some of the field names of the fields on source(it could have just few field names or it might have all the fields also or even could be just one field name )

My Requirement is I would want the data in the Target table to be populated for only fields that are available in the 3rd table

Here is the example

Source has feild1,feild2,feild3,feild4 and has data for these fields

and the 3rd tables has just entries which are field names for example field 2 and field 3

now my requirement is I want the target table to be populated in such a way that in the target table data for feild1 should be blank,filed2 should have value field3 should have value an again for the field4 it should be blank

I want these to achieve dynamical since I have about 80 fields which Would not want to code it in the ABAP program

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Dec 15, 2011 at 03:40 PM

    There you go

    * Source Table
    LOOP AT itab1 INTO wa1.
    * Field Names
      LOOP AT itab3 INTO wa3.
    *   See if Target Field exists
        ASSIGN COMPONENT wa3-fieldname OF STRUCTURE wa2 TO <fs_target>.
        IF sy-subrc <> 0.
    *   Get Source Field
        ASSIGN COMPONENT wa3-fieldname OF STRUCTURE wa1 TO <fs_source>.
        IF sy-subrc = 0.
    *     Target -> Source
          <fs_target> = <fs_source>.
    * Target Table
      APPEND wa2 TO itab2.
      CLEAR wa2.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.