‎2010 Jul 30 11:58 AM
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.
‎2010 Jul 30 12:05 PM
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 555555Edited by: Raj on Jul 30, 2010 4:37 PM
‎2010 Jul 30 12:14 PM
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
‎2010 Jul 30 4:13 PM
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.
‎2010 Jul 30 4:51 PM
you could separate the IT in TWO IT.. one for the header and one for the details.! and do two loops...
‎2010 Aug 02 1:04 PM
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
‎2010 Aug 01 4:57 PM
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.
‎2010 Aug 02 8:38 AM
‎2010 Aug 02 10:03 AM
‎2010 Aug 02 12:01 PM
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