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: 

Append-corresponding records to internal table.

0 Kudos

Hello dears,

I need your help to correctly append/insert the records to my internal table. I have the code below(the last part of it has to be adjusted):

The problem is that I need to insert the values into the correspondent column (equnr).

By using appending-corresponding fields of table, it just adds the values after my initial lines (image attached)capture.jpg.

Thank you!

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

FORM logic .


 types:BEGIN OF ty_logic,
var1(15) TYPE c,
var2(15) TYPE c,
var3(15) TYPE c,
equnr TYPE equi-equnr,
END OF ty_logic.
DATA: t_logic TYPE STANDARD TABLE OF ty_logic,
wa_logic TYPE ty_logic.


 loop at it_afru2 into wa_afru.
if wa_afru-ltxa1 in lt_rng_check.
split wa_afru-ltxa1 at '|' into wa_logic-var1 wa_logic-var2 wa_logic-var3.
append wa_logic to t_logic.
else.
continue.

 clear wa_afru.
endif.
endloop.

 If t_logic is not INITIAL.
clear wa_logic.
loop at t_logic into wa_logic.
select equnr from equi
where matnr eq @wa_logic-var1 AND
serge eq @wa_logic-var2
APPENDING CORRESPONDING FIELDS OF TABLE @t_logic.

ENDLOOP.
endif.
1 ACCEPTED SOLUTION

venkateswaran_k
Active Contributor

Hi rapadungadunga2

You have to modify your code as below:

The code you wrote at place loop at t_logic into wa_logic.

Instead of append corresponding you should write modify.

data lv_tabix type sy-tabix.
If t_logic is not INITIAL.
 clear wa_logic.
 loop at t_logic into wa_logic.
     lv_tabix = sy-tabix.
     select equnr from equi INTO @WA_LOGIC-EQUNR where matnr eq @wa_logic-var1 AND
                                                      serge eq @wa_logic-var2
      
      MODIFY T_LOGIC FROM @WA_LOGIC INDEX LV_TABIX.
 ENDLOOP.
endif.

Regards,

Venkat

10 REPLIES 10

Sandra_Rossi
Active Contributor
0 Kudos

Please edit your question, select your code and press the button [CODE], which makes the code appear colored/indented, it will be easier for people to look at it. Thank you!

Sandra_Rossi
Active Contributor

Have a look at ABAP documentation how to work with internal tables.

0 Kudos

Dear Sandra,


Thank you for that CODE hint. I updated my question.

As for the "ABAP documentation" advice, this can be universal applied and you can reply almost to any question here on the forum with "Read the ABAP documentation". It doesn't always clarifying things for you, especially when you are a beginner.

Kind regards,

Lucian

venkateswaran_k
Active Contributor

Hi rapadungadunga2

You have to modify your code as below:

The code you wrote at place loop at t_logic into wa_logic.

Instead of append corresponding you should write modify.

data lv_tabix type sy-tabix.
If t_logic is not INITIAL.
 clear wa_logic.
 loop at t_logic into wa_logic.
     lv_tabix = sy-tabix.
     select equnr from equi INTO @WA_LOGIC-EQUNR where matnr eq @wa_logic-var1 AND
                                                      serge eq @wa_logic-var2
      
      MODIFY T_LOGIC FROM @WA_LOGIC INDEX LV_TABIX.
 ENDLOOP.
endif.

Regards,

Venkat

0 Kudos

Hi Venkateswaran,

Thank you for your input. I appreciate it.

Problem solved.

shraddha_mundwadkar
Participant

Select within loop is not recommended. you can try below

select equnr matnr serge from equi into table @DATA(lt_logic) for all entries in t_logic where matnr eq @t_logic-var1 AND serge eq @t_logic-var2

loop at t_logic assiging field-symbol(<fs_logic>). 
read table lt_logic into data(wa_logic) with key matnr = <fs_logic>-var1 serge = <fs_logic>-var2.  

if sy-subrc = 0.  

<fs_logic>-equnr = wa_logic-equnr.  

endif.

endloop.

Thanks,

Shraddha

0 Kudos

Thank you sandra.rossi

0 Kudos

Hello Shraddha,

Thanks a lot for your detailed explanation. I'll use the logic you provided when appending the records to the final alv list.

Have a great day!

Sandra_Rossi
Active Contributor
0 Kudos

In your code, you use APPEND, which appends lines, hence the result you obtain. So, I guess you are asking how to update lines of the internal table.

Usually, ABAP developers don't look at the documentation, so at least you are saying that you tried to find information, but I don't understand what kind of problem you had with the explanations from the chapter "Changing internal tables".

0 Kudos

Hello Sandra,

Indeed, I usually check first the documentation, then I'm looking on the forum for already answered questions in regards to my topic, in the end I'm asking for opinions. Sometimes it's easy to find an answer, sometimes you get easily confused (being a beginner as myself). From my experience so far, there is no such valuable input, than the one of an experienced abaper which comes also with some tricks, that you cannot find in the classical documentation.

Nevertheless, thank you for taking your time to review my request.

Have a very nice day!

Lucian