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: 

Cyclic Validation

0 Kudos

There is a internal table with 3 columns

Sample data of it as below.

XX YY err

a b

a l

a m

b n

b x

b y

c w

c t

x d

d a

n c

n p

n i

n j

p q

q r

r s

s d

For all cyclic records, err column have to be set as X.

Cycllic records are those where YY = XX in a cyclic manner.

Starting from first record, search starts and all records with XX = b are searched.

b n, b x, b y are found,

Then we search with YY of what is found, and so on.

Cyclic record set (1) in the above example

a b

b n

n p

p q

q r

r s

s d

d a

Cyclic record Set(2) in the above example

a b

b x

x d

d a

So after execution the output should be as below

XX YY err

a b X

a l

a m

b n X

b x X

b y

c w

c t

x d X

d a X

n c

n p X

n i

n j

p q X

q r X

r s X

s d X

Can anyone suggest some logic?

1 ACCEPTED SOLUTION

r010101010
Active Participant
0 Kudos

You can try the iterative call of a subroutine: here is the algorithm.

Loop at ITAB.

PERFORM F_CYCLE tables ITAB

using ITAB-YY

Endloop.

*------------------------------

FORM F_CYCLE.

Loop at ITAB where XX = YY into LS_LINE.

SET the ITAB-ERR = 'X'.

PERFORM F_CYCLE tables ITAB

using LS_LINE-YY

Endloop.

ENDFORM.

12 REPLIES 12

srikanthnalluri
Active Participant

Do you have an dynamic internal table and you want to set other columns?Please rephrase your question once again.

Jean_Sagi
Participant

The truth I didn't understand your question. It would be helpful a before and after example of what you want to achieve...

0 Kudos

I modified the question to make it more understandable.

0 Kudos

Please use the COMMENT button to reply to someone asking for details. ANSWER is only to propose a solution.

matt
Active Contributor

What have you tried? It looks straightforward to me - one or two DO loops, reads from the table, storing interim results.

For each element - next elements. Do this recursively until you end up repeating or the chain ends. Effectively you're looking for loops in a hierarchy.

0 Kudos

These are records of input excel file that are taken in an internal table.

The number of loops cannot be defined, as number and pattern of records changes when you change the data.

Can you show me the logic in ABAP that you are proposing please.

matt
Active Contributor

Can you show me the logic in ABAP that you are proposing please.

Nope. That is an exercise left to the programmer who is being paid to program the solution.

It doesn't matter where the data comes from, why mention it? Furthermore, there's nothing in what I've said that indicates that the number of loops has to be defined. You start at one element, test all possibilities there, then take the next element and test all possibilities there until there are no elements remaining. There's scope for some optimisation as if you have A->B, then you obviously don't need to check B again.

0 Kudos

Matthew, how do you know the number of times, the DO loop will run?

0 Kudos

You don't. But when you reach the end of a chain, you can leave the loop using exit.

0 Kudos

Please use the COMMENT button to reply to someone asking for details. ANSWER is only to propose a solution.

Sandra_Rossi
Active Contributor
0 Kudos

Fun algorithm... As a human, can you solve the problem without a computer? Yes -> convert your logic into an algorithm and convert it into a program. No -> you won't be able to code the program.

r010101010
Active Participant
0 Kudos

You can try the iterative call of a subroutine: here is the algorithm.

Loop at ITAB.

PERFORM F_CYCLE tables ITAB

using ITAB-YY

Endloop.

*------------------------------

FORM F_CYCLE.

Loop at ITAB where XX = YY into LS_LINE.

SET the ITAB-ERR = 'X'.

PERFORM F_CYCLE tables ITAB

using LS_LINE-YY

Endloop.

ENDFORM.