2023 Nov 10 11:22 AM
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!
2023 Nov 10 3:30 PM
Probably it's simple but I don't understand the question very well, so difficult to answer precisely.
Could you describe your exact case?
2023 Nov 11 6:09 AM
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
2023 Nov 11 9:14 AM
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
2023 Nov 11 9:58 AM
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.
2023 Nov 11 10:15 AM
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
2023 Nov 11 12:11 PM
Did you try move corresponding itab_source[] to itab_target[] ?
2023 Nov 11 1:02 PM
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.
2023 Nov 11 1:19 PM
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.