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: 

ABAP- internal table looping

Former Member
0 Kudos

Hi All,

I am having a scenario where for different values of PERSON i want the inner loop to run based on the condition present in inner loop.

If there are multiple values of PART_REF for a given PERSON, I want all of them to be displayed along with their respective job family.

Example:

PERSON     PART_REF

101              ABC

101              DEF

102              PQR

102              XYZ

PART_REF   JOB_FAMILY

ABC             201

DEF             202

PQR             301

XYZ              302

Current Output:                                Required Output:

PERSON   JOB_FAMILY                  PERSON   JOB_FAMILY

101            202                                  101             201

102            302                                   101            202

                                                         102             301

                                                          102            302

Below is code by which i am able to display only last value of part_ref along with its job_family.

LOOP AT i_A INTO wa_A where PERSON = SOURCE_FIELDS-PERSON.


LOOP AT i_B INTO wa_B WHERE PART_REF = wa_A-PART_REF.


  if sy-subrc = 0.
RESULT = wa_B-Job_Family.
else.
RESULT = 'blank'.
endif.


clear wa_B.


ENDLOOP.


clear wa_A.


endloop.

Thanks,

Tanvi

3 REPLIES 3

Former Member
0 Kudos

Hi,

Replace

LOOP AT i_B INTO wa_B WHERE PART_REF = wa_A-PART_REF.

with

READ TABLE i_B INTO wa_B WITH KEY PART_REF = wa_A-PART_REF.

and try

0 Kudos

It is not making any difference.Still only the first value of job family for the last part_ref is getting displayed. Moreover i want to loop through the
PART_REF too.

Former Member
0 Kudos

Try this.

LOOP AT I_A INTO WA_A WHERE PERSON = SOURCE_FIELDS-PERSON.

       READ TABLE I_B INTO WA_B WITH KEY PART_REF = WA_A-PART_REF.

       IF SY-SUBRC = 0.

         LOOP AT I_B INTO WA_B WHERE PART_REF = WA_A-PART_REF.

           RESULT = wa_B-Job_Family.

           CLEAR WA_B.

         ENDLOOP.

       ELSE.

         RESULT = 'BLANK'.

       ENDIF.

       CLEAR WA_A.

     ENDLOOP.