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: 

How to change the value of an internal table without loop?

Former Member

Hello Everyone,

Thank you for giving your time. I have an internal table having thousands of records. How can I replace the value of a variable in one go without using loops.

Ex. -

      LOOP AT gt_bseg_02 INTO gs_bseg_02.

        IF gs_bseg_02-koart = ''.

          gs_bseg_02-koart = 'XYZ'.

        ENDIF. " IF gs_bseg_02-koart = ''

modify gt_bseg_02 from gs_bseg_02.

      ENDLOOP. " LOOP AT gt_bseg_02 INTO gs_bseg_02

Is there any single statement to do this? like we can simple delete the records without using loops with the delete statement.

Regards

Mani

5 REPLIES 5

former_member1716
Active Contributor

Hi Mani,

You can use the below code,

Assign the value to the field like below, and then modify from the work area as written below.

WA_BSEG-KOART = 'XYZ'.

MODIFY gt_bseg_02 FROM wa_bseg TRANSPORTING koart WHERE koart EQ ''.

Please let us know on the progress :).

regards,

Satish

0 Kudos

Also Please check the below documentation for further clarifications.

http://help.sap.com/erp2005_ehp_04/helpdata/EN/fc/eb35eb358411d1829f0000e829fbfe/frameset.htm

Regards,

Satish

Although some people don't like it:

LOOP AT itab ASSIGNING <field-symbol> is NEVER slower but suaually much faster than LOOP AT itab INTO headerline.

FIELD-SYMBOLS:

  <bseg> TYPE bseg.

LOOP AT it_bseg ASSIGNING <bseg>

  WHERE koart IS INITIAL.

  <bseg>-koart = 'your value'.

ENDLOOP.

No modify needed because you are working directly with the table.

It won't be much slower than MODIFY itab TRANSPORTING ... WHERE


Regards


Clemens

Former Member
0 Kudos

Use modify transporting...

From the ABAP Keyword Documentation:

"The addition TRANSPORTING has the same effect as changing individual rows. The addition WHERE can only be specified together with the addition TRANSPORTING".

gs_bseg_02-koart = 'XYZ'.

modify gt_bseg_02 from gs_bseg_02 transporting koart where koart = ''.

Former Member
0 Kudos

Instead of loop you can use modify statement.

MODIFY itab FROM wa TRANSPORTING field WHERE <your condition>.

wa = work area containing your required value.

condition = optional