Application Development and Automation 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: 
Read only

Internal table Item lines

Former Member
0 Likes
1,189

I have an internal table with header and line items for a posting. The header and line items are differntiated with a field called record type and it has values as H or L...now i have to run BDC for the line items.

So ihave to send lines for both H and L as one document...

Record type

H

L

L

L

H

L

L

This will from two documents: H L L L and H L L....

How should i loop through the internal table to split....i am not sure of the logic to do that.....

KIndly help...

Thanks.

9 REPLIES 9
Read only

Former Member
0 Likes
1,157

Check the syntax

ON CHANGE OF

AT NEW

Check the below code for the DIfference

DATA : BEGIN OF itab OCCURS 0,
bukrs LIKE t001-bukrs,
f1(10) TYPE c,
END OF itab.

itab-bukrs = '1000'.
itab-f1 = '1111111'.
APPEND itab.

itab-bukrs = '1100'.
itab-f1 = '3333333'.
APPEND itab.


itab-bukrs = '1200'.
itab-f1 = '555555'.
APPEND itab.

*at new

LOOP AT itab.
  AT NEW bukrs.
    WRITE :/ itab-bukrs , itab-f1.
  ENDAT.

ENDLOOP.

*onchange

LOOP AT itab.
  ON CHANGE OF itab-bukrs.
    WRITE :/ itab-bukrs , itab-f1.

  ENDON.

ENDLOOP.

Please find the output

1000 **********
1100 **********
1200 **********


1000 1111111
1100 3333333
1200 555555

Edited by: Raj on Jul 30, 2010 4:37 PM

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,157

You can use loop control statements to achieve this requirement:

LOOP AT itab INTO wa.
  
  wa1 = wa. "Trick to remove the * inside the AT ... ENDAT block

  AT NEW record_type.
    IF wa-record_type = 'H'.
      "Code for header data
    ELSEIF wa-record_type = 'L'.
      "Code for line items
    ENDIF.
  ENDAT.

ENDLOOP.

BR,

Suhas

Read only

Former Member
0 Likes
1,157

Hi Suhas,

This is not working in this case,if it is header is following with item record it will works,but for the last item records

its not working.

Read only

Former Member
0 Likes
1,157

you could separate the IT in TWO IT.. one for the header and one for the details.! and do two loops...

Read only

Former Member
0 Likes
1,157

Hi,

Please try this if it helps...

Before looping the internal table, add a tail record at the end (i.e. a dummy record which you won't process, let's say a record with record_type = 'D') then the syntax ON-CHANGE-OF will work till the last required record.

Let me know if useful...

Regards,

Kiran

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,157

It can be done two ways.

You will be having the key fields common for header and item tables.

you can either seperate the item details and header details into seperate internal tables.

The loop at header and then a nested loop at item, like this you can process your bdc.

or you can use control berak statements if you are planning to use a singe internal table.

Read only

0 Likes
1,157

Hi kesav,

This is not working.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,157

Please paste the internal data and your code part.

Read only

Former Member
0 Likes
1,157

hi,

Just use this simple code .

DATA : BEGIN OF itab OCCURS 0,

bukrs LIKE t001-bukrs,

f1(1) TYPE c,

END OF itab.

itab-f1 = '1'.

itab-bukrs = 'H'.

APPEND itab.

itab-f1 = '2'.

itab-bukrs = 'L'.

APPEND itab.

itab-f1 = '3'.

itab-bukrs = 'L'.

APPEND itab.

itab-f1 = '4'.

itab-bukrs = 'H'.

APPEND itab.

itab-f1 = '5'.

itab-bukrs = 'L'.

APPEND itab.

itab-f1 = '6'.

itab-bukrs = 'L'.

APPEND itab.

itab-f1 = '6'.

itab-bukrs = 'L'.

APPEND itab.

LOOP AT itab.

IF itab-bukrs = 'H'.

"Code for header data

WRITE 😕 itab-bukrs , itab-f1.

ELSEIF itab-bukrs = 'L'.

"Code for line items

WRITE 😕 itab-bukrs , itab-f1.

ENDIF.

ENDLOOP.

Hope this code will help you .

With Regards