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: 

Internal table logic - help required

Former Member
0 Kudos

Hi,

I am working on BSEG table to determine offsetting line count and amount total for a posting line item and need
a small logic .

I have a table of currency fields like below and the table is such ( like BSEG ) that each line item will balance
itself with other line item . For example

Item

10      100
20      100-
30      200
40      250
50      450-
60      200-
70      200
80      600
90      100
100     200
110     300


If you see 10 & 20 balance out similarly ( 30,40 will balance with line item 50 ) , ( 60 & 70 balance each other ) ,
( 90,100, 110 balance with 80 ).

My requirement - If I loop on item 50 with amount 450- I need to get the posnr of the two items which balance
this amount ( which is 30 and 40 ).  If I loop on item 80 with amount 600 then I need to get item 90. 100 and 110.

Please provide me a logic which will provide me the index of ther required item lines.

Regards
Praneeth


1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor
0 Kudos

Add a "group" column to the internal table, and fill it with a logic like


wa_sum = 0.
wa_group = 1.
LOOP AT itab ASSIGNING <fs>.
   <fs>-group = wa_group.
   ADD <fs>-amount TO wa_sum.
   IF wa_sum IS INITIAL.
     aff 1 to wa_group.
   ENDIF.
ENDLOOP.

Regards,

Raymond

5 REPLIES 5

former_member199214
Participant
0 Kudos

Hi praneeth,

First get the number which are below your input (should consider the  .

Get the first of the result and add with remaining one by one so that it would get tallied with your input 450.

Once the condition satisfies, your requirement will be achieved.

Regards,

SindhujaVC

raymond_giuseppi
Active Contributor
0 Kudos

Add a "group" column to the internal table, and fill it with a logic like


wa_sum = 0.
wa_group = 1.
LOOP AT itab ASSIGNING <fs>.
   <fs>-group = wa_group.
   ADD <fs>-amount TO wa_sum.
   IF wa_sum IS INITIAL.
     aff 1 to wa_group.
   ENDIF.
ENDLOOP.

Regards,

Raymond

0 Kudos

Hi Raymond,

Your logic worked perfectly for my requirement. The line items were divided into groups which made my further processing in the logic easy.

Thank You.

Praneeth

Former Member
0 Kudos

Hi, execute this code.. might be helpful to you

TYPES: BEGIN OF test,

         a TYPE i,

         b TYPE i,

       END OF test.

DATA: itab TYPE TABLE OF test,

       wa  TYPE test,

       wa1 TYPE test,

       c   TYPE i,

       d   TYPE i,

       n1  TYPE i,

       n2  TYPE i.

PARAMETERS p TYPE i.

wa-a = 1.

wa-b = 20.

APPEND wa TO itab.

wa-a = 2.

wa-b = 30.

APPEND wa TO itab.

wa-a = 3.

wa-b = 10.

APPEND wa TO itab.

wa-a = 4.

wa-b = 10.

APPEND wa TO itab.

wa-a = 5.

wa-b = 20.

APPEND wa TO itab.

READ TABLE itab INTO wa WITH KEY a = p.

c = wa-b.

LOOP AT itab INTO wa WHERE a GT p.

   n1 = wa-a.

   IF c EQ wa-b.

     EXIT.

   ENDIF.

   LOOP AT itab INTO wa1 WHERE a GT wa-a.

     IF wa-a = wa1-a.

       EXIT.

     ENDIF.

     n2 = wa1-a.

     d  = wa-b + wa1-b.

     IF c EQ d.

       EXIT.

     ENDIF.

   ENDLOOP.

   IF wa-a = wa1-a.

     EXIT.

   ELSEIF c EQ d.

     EXIT.

   ELSE.

     CLEAR: n1, n2.

   ENDIF.

ENDLOOP.

WRITE: n1 , n2.

0 Kudos

Hi,

Can you make use of the field SHKZG (Debit/Credit Indicator) in BSEG, for that.

where H- credit and S debit

Regards

Sree