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

dynamic internal table fields

Former Member
0 Likes
1,090

Hi,

I need to move fields from a dynamic internal table to another table. I have to check whether those fields which i'm interested in exists in that dynamic table or not before i assign the values in these fields to other fields.

Let me know how to do this.

Thanks,

KK.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
533

Hi,

thanks for the prompt response. The code you posted allows me to copy all the fields.

I'm interested to see only few fields in particular..and in case those fields doesn't exist in the dynamic table, it should not give a short dump.

Let me know your comments.

Thanks,

KK>

3 REPLIES 3
Read only

Former Member
0 Likes
533

Hello,

See the code bellow:


  DATA dref TYPE REF TO data.

  FIELD-SYMBOLS:
    <tab>   TYPE ANY TABLE,
    <wa>    TYPE ANY,
    <field> TYPE ANY.


  TRY.
      CREATE DATA dref
        TYPE STANDARD TABLE OF (dbtab) WITH NON-UNIQUE DEFAULT KEY.
      ASSIGN dref->* TO <tab>.

      SELECT *
             FROM (dbtab) UP TO rows ROWS
             INTO TABLE <tab>.

      LOOP AT <tab> ASSIGNING <wa>.

        DO.
          ASSIGN COMPONENT sy-index OF STRUCTURE <wa> TO <field>.
          IF sy-subrc = 0.
            WRITE / <field>.
          ELSE.
            EXIT.
          ENDIF.
        ENDDO.

        ULINE.
      ENDLOOP.
    CATCH cx_sy_create_data_error.
      WRITE 'Wrong Database!'.
  ENDTRY.

You can do the check that you need using the code between DO and ENDDO.

ASSIGN COMPONENT

... COMPONENT comp OF STRUCTURE struc

Effect

With this expression for mem_area, the memory area of a component comp of a structure struc is assigned to the field symbol. While the structure struc is specified directly, a data object must be specified for comp. The evaluation depends on the data type of comp:

If the field comp has a text-type type (c or string), or a flat structure, its content is interpreted as the name of the component.

If the field comp has a non-text, elementary type, the content is converted to the type i and interpreted as a position of the component in the structure. if the value for comp is 0, the storage area of the entire structure is assigned to the field symbol.

If struc is not a structure, the assignment is not executed and sy-subrc is set to 4.

Regards.

Read only

Former Member
0 Likes
534

Hi,

thanks for the prompt response. The code you posted allows me to copy all the fields.

I'm interested to see only few fields in particular..and in case those fields doesn't exist in the dynamic table, it should not give a short dump.

Let me know your comments.

Thanks,

KK>

Read only

0 Likes
533

Hello,

You need to use the assign component command to get the fields from the structure like described before.

If the field doesn't exist the sy-subrc field will be set to 4.


  CONSTANTS:
    lc1 TYPE c LENGTH 10 VALUE 'FIELD1',
    lc2 TYPE c LENGTH 10 VALUE 'FIELD2'.
  DATA:
    dref      TYPE REF TO data,
    fieldname TYPE c LENGTH 10,
    lv_i      TYPE n LENGTH 1.

  FIELD-SYMBOLS:
    <tab>   TYPE ANY TABLE,
    <wa>    TYPE ANY,
    <field> TYPE ANY,
    <fieldname> TYPE ANY.


  TRY.
      CREATE DATA dref
        TYPE STANDARD TABLE OF (dbtab) WITH NON-UNIQUE DEFAULT KEY.
      ASSIGN dref->* TO <tab>.

      SELECT *
             FROM (dbtab) UP TO rows ROWS
             INTO TABLE <tab>.

      LOOP AT <tab> ASSIGNING <wa>.


        DO 2 TIMES.
          lv_i = sy-index.
          CONCATENATE 'LC' lv_i INTO fieldname.
          ASSIGN (fieldname) TO <fieldname>.

          ASSIGN COMPONENT <fieldname> OF STRUCTURE <wa> TO <field>.
          IF sy-subrc = 0.
            WRITE / <field>.
          ELSE.
            EXIT.
          ENDIF.
        ENDDO.


        ULINE.
      ENDLOOP.
    CATCH cx_sy_create_data_error.
      WRITE 'Wrong Database!'.
  ENDTRY.

Regards,