Application Development 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: 

Fetching data from one internal table and populating their corresponding fieldname into other table.

calvinkarlo
Explorer
0 Kudos

Hi

I have my data in an internal table having 20 fields (user input). this input might change (position of fieldnames) depending on the contents of invoice.

now i want to get specific fieldname and populate this data into other internal internal table that has 10 fields.

so could anyone let me know how can i work on this.

I'm trying to check every field(field 01 - field 20) from input and input logic if it matches but it might affect runtime.

Thanks in advance!

8 REPLIES 8

Sandra_Rossi
Active Contributor
0 Kudos

Probably it's simple but I don't understand the question very well, so difficult to answer precisely.

Could you describe your exact case?

calvinkarlo
Explorer
0 Kudos

It's like the user will input dynamic field names from excel file.. For example for week 1 the field names are A ,B, C ,D and E for week 2 field names are A, C, E and F for week 3 A, B, E and D. But in my program I declare an internal table that can accept A, B, C, D, E, and F

Sandra_Rossi
Active Contributor

Still need clarification. Please provide a minimal reproducible example.

Based on the next code (I guess it's what you explained), what result do you want to obtain?

TYPES: BEGIN OF ty_itab_line,
         week_number TYPE i,
         a           TYPE flag,
         b           TYPE flag,
         c           TYPE flag,
         d           TYPE flag,
         e           TYPE flag,
         f           TYPE flag,
       END OF ty_itab_line.
TYPES ty_itab TYPE STANDARD TABLE OF ty_itab_line WITH EMPTY KEY.
DATA(itab) = VALUE ty_itab(
    ( week_number = 1 a = 'X' b = 'X' c = 'X' d = 'X' e = 'X' f = ' ' )    " 1: A B C D E
    ( week_number = 2 a = 'X' b = ' ' c = 'X' d = ' ' e = 'X' f = 'X' )    " 2: A   C   E F
    ( week_number = 3 a = 'X' b = 'X' c = ' ' d = 'X' e = 'X' f = ' ' ) ). " 3: A B   D E

calvinkarlo
Explorer
0 Kudos

Hi according to your comment I need to specify possible scenarios? Is there a way to automate this one? like the system will automatically create ty_itab from the user input? for example, for incoming weeks there is another combination of fieldnames.

calvinkarlo
Explorer
0 Kudos

For example here's the full list of the invoice

sometimes not all fields are filled in, so they delete that column.

now i want to get specific fieldnames(Charge) and populate this data into other internal internal table

thilakan_t
Participant
0 Kudos

Did you try move corresponding itab_source[] to itab_target[] ?

worker1
Explorer

You can simplify this by creating a mapping between the fields in your input table and the fields in your output table. That way, you don't need to check each field individually, which can save runtime. Just map them and transfer the data accordingly.

Sandra_Rossi
Active Contributor
0 Kudos

Could you make your question a little bit more ABAP-oriented please?

Below, I call "normalized" the internal table which contains all possible columns. I use the obsolete concept of subroutines and MOVE-CORRESPONDING, to simplify the code, and because I don't know your ABAP version.

TYPES: BEGIN OF ty_any_itab_line_1,
         batch_no      TYPE decfloat16,
         pallet_weight TYPE decfloat16,
       END OF ty_any_itab_line_1.
TYPES ty_any_itab_1 TYPE STANDARD TABLE OF ty_any_itab_line_1 WITH EMPTY KEY.

TYPES: BEGIN OF ty_normalized_itab_line,
         batch_no      TYPE decfloat16,
         fuel_charge   TYPE decfloat16,
         pallet_weight TYPE decfloat16,
       END OF ty_normalized_itab_line.
TYPES ty_normalized_itab TYPE STANDARD TABLE OF ty_normalized_itab_line WITH EMPTY KEY.

DATA(any_itab_1) = VALUE ty_any_itab_1(
       ( batch_no      = 1
         pallet_weight = 10 ) ).

DATA(normalized_itab) = VALUE ty_normalized_itab( ).
PERFORM normalize_input_table USING any_itab_1 CHANGING normalized_itab.

ASSERT normalized_itab = VALUE ty_normalized_itab(
       ( batch_no      = 1
         fuel_charge   = 0
         pallet_weight = 10 ) ).

FORM normalize_input_table
    USING
      input_table      TYPE ANY TABLE 
    CHANGING
      normalized_table TYPE ty_itab.
  MOVE-CORRESPONDING input_table TO normalized_table.
ENDFORM.