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: 

Reg. internal table logic

Former Member
0 Kudos
81

Hi,

I have an internal table with 5 fields (Vbeln, A, B, C, D ) and records like this:

Record1:

Field vbeln (value is 6000000001), Field A (value is 2006), Field B (value is 1130), Field C (value is initial), Field D (value is initial)

Record1:

Field vbeln (value is 6000000001), Field A (value is initial), Field B (value is initial), Field C (value is 2005), Field D (value is 1134)

Now whenever, Field A and Field B has values, field C and field D are initial and vice versa.

I Want to get all of the field values in just one record like below when the key vbeln is same.:

Field vbeln (value is 6000000001), Field A (value is 2006), Field B (value is 1130), Field C (value is 2005), Field D (value is 1134)

I know I can create another internal table, copy the contents, use the looping logic and achieve the same but wondering if there is any better way of doing the same?

Appreciate your input.

Thanks!

1 ACCEPTED SOLUTION

suresh_datti
Active Contributor
0 Kudos
62

I guess you can use COLLECT..

~Suresh

6 REPLIES 6

suresh_datti
Active Contributor
0 Kudos
63

I guess you can use COLLECT..

~Suresh

0 Kudos
62

Hi!

If the 2005 is a year, then collect will not the good solution.

Try out like this:


LOOP AT itab1 INTO wa1.
  READ TABLE itab2 INTO wa2
    WITH KEY key2 = wa1-key1.
  IF sy-subrc = 0.
* pass the values, check the fields to be INITIAL
    IF wa2-field1 IS INITIAL.
      MOVE ...
    ENDIF.
  ENDIF.
ENDLOOP.

Regards

Tamá

Former Member
0 Kudos
62

Hi,

INstead of APPEND use COLLECT ..

Thanks,

Naern

Former Member
0 Kudos
62

thanks for your input. I realize the field A is date, B is time, C is date, D is time. I don't think 'collect' will work here. Any input on this?

Thank you.

0 Kudos
62

I guess go through previous update by Tamás Nyisztor.

That will solve ur problem.

Regards,

Amey

ferry_lianto
Active Contributor
0 Kudos
62

Hi,

You need another internal tables. Please try this.


SORT ITAB1.

ITAB2[] = ITAB1[].

LOOP AT ITAB1.
  LOOP AT ITAB2 WHERE ITAB2-VBELN EQ ITAB1-VBELN
                  AND ITAB2-DATE1 NE ITAB1-DATE1
                  AND ITAB2-TIME1 NE ITAB1-TIME1.

    ITAB3-VBELN = ITAB1-VBELN.
    ITAB3-DATE1 = ITAB1-DATE1.
    ITAB3-TIME1 = ITAB1-TIME1.
    ITAB3-DATE2 = ITAB2-DATE2.
    ITAB3-TIME2 = ITAB2-TIME2.
    APPEND ITAB3.
  ENDLOOP.
ENDLOOP. 

Regards,

Ferry Lianto