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

Need help with ABAP logic for Internal table split....

Former Member
0 Likes
1,104

Gurus,

I have an internal table with header and line items for a Customer invoice document. 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 check each of these documents using BAPI_ACC_DOCUMENT_CHECK...

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.

4 REPLIES 4
Read only

Former Member
0 Likes
747

Hi laxman kumar,

well, maybe I don't understand your problem, but you may perform as following:


LOOP AT internal_table.
  IF internal_table-record_type = 'H'.
    IF NOT itab_items[] IS INITIAL.
      " call BAPI for previous document
    ENDIF.

    CLEAR: itab_items.
    REFRESH: itab_items.
    MOVE internal_table TO structure_header. "<-- or whatever the structure is
  ELSEIF internal_table-record_type = 'L'.
    MOVE internal_table TO itab_items. "<-- may need to adjust fields
    APPEND itab_items.
  ENDIF.
ENDLOOP.

...where structure_header is the header for the BAPI, and itab_items the line items. Please take into account that this is just a stub, and you may have to complete it with the proper structures and fields.

Nevertheless, I hope it helps. Kind regards,

Alvaro

Read only

0 Likes
747

Thanks for the reply alvaro...

Actually, i need to separate the different documents in an internal table in groups of HLLL and HLL...i mean i have an internal table with all these documents in the order HLLLLHLLLHLLL...no i have to separate the document individually into HLLLL, HLLLL, HLLL.....

Afte that i have to send each one of them individually to check BAPI...i have logic for that....

I am just trying to figure out how to separate these items into documents with HLLLL....

Thanks....

Read only

0 Likes
747

Hi again,

I dont think if I get it. Well, if you have an internal table with sequence HLLLLLHLLLLHLL, then the piece of code I wrote does so:

1.1. fills the header structure with H

1.2. fills the items table with LLLLL

1.3. calls the BAPI

1.4. clears the items table

2.1. fills the header table with the new H

2.2. fills the items table with LLLL

2.3. calls the BAPI

2.4. clears the items table

3.1. fills the header table with the new H

3.2. fills the items table with LL

3.3. calls the BAPI

3.4. clears the items table

...

and so on.

On the other side, if you want to identify the LLL's that go together with an H, you should "link" these records together, by populating a field with the same value for the same document, and with different values for different documents.

For example, assume that you populate field BELNR. Then you may have your internal table like this:


reg_type  belnr
--------------
H         1
L         1
L         1
L         1
L         1
H         2
L         2
L         2
L         2
H         3
L         3

...that means one document with header and 4 items, another one with header and 3 items, and a last one with a header and just one item. Then you may SORT STABLE the table with key belnr.

Please answer back if this doesn't meet your requirement, preferrably with some examples of your source table and your desired target table.

Kind regards,

Alvaro

Read only

Former Member
0 Likes
747

Gurus, Thanks for the replies..But still i am not able to split the documents...What i really want to achieve is that I split documents with HLLL values and store all of it in one internal table and not in separate header and internal table....

So if i have an internal table with data in from HLLL HLLL HLL HLLLLL...Then i want to divide it into separate docs of HLLL each....and then call BAPI with this internal table ....

Kindly help...

Thanks.