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

Regarding fetching values from internal table

Former Member
0 Likes
624

Hi Experts,

Very badly i need your help.

The requirement is to get the values from the excel sheet and generate text files as accordingly..

So how my approach was

i  created an internal table with 5 fields as required and the last field of this itab is for storing "roles" and these roles have different "sub-roles" stored in another one custom table.

Fetched the data from excel sheet into that internal table say itab1.

and based on the roles selected i fetched the subroles from the custom tables into another one internal table say itab 2..

Here comes my problem.. i.e

The requirement is , they want the final internal table to have the subroles appended under the roles column itself.. I don't understand how to do..

NB : the roles may have multiple sub-roles.

below is how the data should be displayed.

filed1      field2     field3    field4     field5_role

--------     --------     -------    --------     ----------------

f1.1           f1.2     f1.3     f1.4        role1

f1.1          f1.2      f1.3     f1.4        subrole1

f1.1          f1.2      f1.3     f1.4        subrole2

NB : subrole1 and subrole2 are coming from a custom table based the role1 fetched from the excel sheet.

Please advise how to do.. I

Thanks in advance and best regards,

Swarnadeepta.

5 REPLIES 5
Read only

Former Member
0 Likes
595

I could not fully understand your requirement, but i think it can be addressed by introducing a table type in the final internal table.

let me check if it is possible, i will post code.

Read only

Former Member
0 Likes
595

Well, I tried a lot in the system. Seems like the easiest way is to created a table type in data dictionary, and include the table type in another structure in data dictionary.

But it is too much effort and unnecessary object creation in the system.

It can be done, but why do you want that? What is exact problem you are facing? can it not be done if you have separate tables?

Read only

Former Member
0 Likes
595

Hi,

You can declare another temporary internal table of type itab1 say itab3. loop on itab1, append that record to itab3 and read records from itab2 within itab1 loop based on role of itab1 record to get sub role records using another loop and append those records to itab3.

Finally you will get the required data in itab3.

Thanks & Regards

Shravan

Read only

Former Member
0 Likes
595

Hi,

Please see below codes:

Data: itab3 like table of itab1 with header line.

loop at itab1.

     append itab1 to itab3.

     loop at itab2 where fld5 = itab1-fld5.    

          move-corresponding itab1 to itab3.

          itab3-fld5 = itab2-fld5.

          append itab3.

     endloop.

endloop.

Itab3 is what you want.

Thanks&Regards,

Felix Yang

Read only

Former Member
0 Likes
595

Hi,

Loop at itab_upload into wa_upload.

  wa_final_role-field1 = wa_upload-field1.

  wa_final_role-field2 = wa_upload-field2.

  wa_final_role-field3 = wa_upload-field3.

  wa_final_role-field4 = wa_upload-field4.

  wa_final_role-field5_role = wa_upload-field5_role.

  APPEND wa_final TO it_final.

  CLEAR wa_final.

  SORT gt_erd_pdprof BY zerd_no.

  SORT gt_erd_tmp BY zz_template.

  LOOP AT it_subrole into wa_subrole WHERE field5_role = wa_upload-field5_role.

    wa_final_role-field1 = wa_upload-field1.

    wa_final_role-field2 = wa_upload-field2.

    wa_final_role-field3 = wa_upload-field3.

    wa_final_role-field4 = wa_upload-field4.

    wa_final_role-field5_subrole = wa_subrole-field5_subrole.

    APPEND wa_final to it_final.

   ENDLOOP.

ENDLOOP.

Now the output would be

filed1      field2     field3    field4     field5_role

--------     --------     -------    --------     ----------------

f1.1           f1.2     f1.3     f1.4        role1

f1.1          f1.2      f1.3     f1.4        subrole1

f1.1          f1.2      f1.3     f1.4        subrole2

This is what i was expecting. Many Many Thank you all for your response

With best Regards,
Swarnadeepta .