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

Internal Table to Structure

Former Member
0 Likes
858

Dear developers, I need your help

I have an internal table (TYPE TIHTTPNVP) with some records in it. See below for details...

I need to get the values into a structure from the sflight model:

How do I get the values from the table into the strucutre? Like the value from the row with the name mndt to the component MANDT in the structure...

4 REPLIES 4
Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
819

Hi Fabian,

You can use ASSIGN COMPONENT OF STRUCTURE for this requirement. You can check the syntax in keyword help.

Something like this:

LOOP AT itab INTO struc.

  lv_fieldname = struc-name.

  ASSIGN COMPONENT lv_fieldname OF STRUCTURE wa_sflight INTO <fs_field>.

  <fs_field> = struc-value.

ENDLOOP.

Read only

Former Member
0 Likes
819

Kumar Akshat wrote:

Hi Fabian,

You can use ASSIGN COMPONENT OF STRUCTURE for this requirement. You can check the syntax in keyword help.

Dear Kumar,

This ain't work... because I need the components from a table and not from the structure... Or am I wrong?

Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
819

That was a hint. It was supposed to be built upon. Please check the pseudocode I added in my last response.

Read only

Former Member
0 Likes
819

Hi,

I think we have two ways to do this

1. as explained above by another user using

DATA : it_data TYPE tihttpnvp,
        it TYPE STANDARD TABLE OF sflight,
        wa_data TYPE ihttpnvp,
        wa TYPE sflight.
DATA: lv_field TYPE text30,
        lv_structure_name TYPE text30.

FIELD-SYMBOLS: <fs_value> TYPE any.
FIELD-SYMBOLS: <fs_struc> TYPE any.

lv_structure_name = 'wa_data'.
wa_data-name = 'mandt'.
wa_data-value = '600'.
APPEND wa_data TO it_data.
CLEAR wa_data.

wa_data-name = 'carrid'.
wa_data-value = 'LH'.
APPEND wa_data TO it_data.
CLEAR wa_data.

LOOP AT it_data INTO wa_data.
   lv_field = 'VALUE'.
   ASSIGN (lv_structure_name) TO <fs_struc>.
   ASSIGN COMPONENT lv_field OF STRUCTURE <fs_struc> TO <fs_value>.
   IF sy-subrc EQ 0 .
     CASE sy-tabix.
       WHEN '1'.
         MOVE <fs_value> TO wa-mandt.
       WHEN '2'.
         MOVE <fs_value> TO wa-carrid.
     ENDCASE.
   ENDIF.
ENDLOOP.

as above its just an example for your understanding.

or

2. as per your method by comparing filed names and pass the values into the corresponding fields.

Thanks

Mani