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

table logic

Karan_Chopra_
Active Participant
0 Likes
1,054

I have 2 columns for table controls <col1> <col2> for which i need to input values

I can have multiple same values for col1 and cols 2 seperately but not together , means both in combination shud form a unique key if not then need to display messgae

col1 col2

a b

a c

d b

a c -


> Not allowed (display msg when save is pressed in table control)

How to do it???

9 REPLIES 9
Read only

Former Member
0 Likes
1,029

Try declaring your internal table with UNIQUE KEY.

Regards,

Kiran

Read only

Karan_Chopra_
Active Participant
0 Likes
1,029

but how does this help

is thr some logic for that

Read only

0 Likes
1,029

what kiran meant was to declare the internal table as sorted type with unique key ( your two fields).

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,029

if you are validating it in a chain statement, then read the same internal table with the values 'a' and 'c'.

read itab with key f1 = 'a' f2 = 'b' transporting no fields.

if sy-subrc = 0.

Then the value exists.

else.

valid.

endif.

Read only

Karan_Chopra_
Active Participant
0 Likes
1,029

I cannot expicilt provide values as it can be for many combination or i dont know before hand which values are repeated

Read only

0 Likes
1,029

HI Karan,

In PAI,

loop at itab.
chain.
field : itab-col1, itab-col2.
module validate on request.
module validate.
endchain.
module update_tc.
endloop.

in Program

module validate.
read table itab with key col1 = itab-col1  " This is newly entered Value in Table Control
              col2 = itab-col2. " This is newly entered Value in Table Control
if sy-subrc = 0.
message 'These values are already Entered' Type 'E'.
endif.
endmodule.
module update_tc.
describe table itab lines tc-lines.
if tc-current_line > tc-lines.
append itab. " You pass newly enterd Row into Internal table in the Program
else.
modify itab index tc-current_line. " Or Modify the Existing row in the Program Itab
endif.
"Here  you update the Values back to Program Internal Table
endmodule

Cheerz

Ram

Read only

0 Likes
1,029

You no need to provide the values explicitly, that was just a logic.

Read only

Former Member
0 Likes
1,029

requirement is pretty tricky ..

Im substituting ur column to field f1 and f2.


report zvij57.
data: begin of itab occurs 0,
         f1(10) type c,
         f2(10) type c,
         end of itab.

*populate itab for say db
itab-f1 = 'a'. itab-f2 = 'b'. append itab.
itab-f1 = 'a'. itab-f2 = 'c'. append itab.
itab-f1 = 'd'. itab-f2 = 'c'. append itab.
itab-f1 = 'a'. itab-f2 = 'c'. append itab.
itab-f1 = 'd'. itab-f2 = 'c'. append itab.


sort itab by f1 f2.


data : lv_flag type c,
lv_cnt type i,
lv_val(10) type c.

loop at itab  .
  at new f1.
    lv_flag = 'X'.
  ENDAT.
  if lv_flag eq 'X'.
    lv_val = itab-f2.
    lv_flag = ''.
  endif.

  if lv_val = itab-f2.
    add 1 to lv_cnt .
  else.
    lv_val = itab-f2.
  endif.

  if lv_cnt ge 2.
    write :/ 'duplicate entry for', itab-f1 ,itab-f2.
  endif.
  at end of f1.
    clear : lv_flag, lv_val, lv_cnt.
  endat.

endloop.


Execute this and check if this meets your requirement.

Br,

Vijay.

Read only

0 Likes
1,029

i have to refine further this logic and now it looks fine to me .


REPORT  Zvij57.

data: begin of itab occurs 0,
         f1(10) type c,
         f2(10) type c,
         f3 type i,
         end of itab.

*populate itab for say db

itab-f1 = 'a'.  itab-f2 = 'e'. append itab.
itab-f1 = 'a'. itab-f2 = 'b'. append itab.
itab-f1 = 'a'. itab-f2 = 'c'. append itab.
itab-f1 = 'd'. itab-f2 = 'c'. append itab.
itab-f1 = 'a'. itab-f2 = 'c'. append itab.
itab-f1 = 'd'. itab-f2 = 'c'. append itab.
itab-f1 = 'a'. itab-f2 = 'd'. append itab.
itab-f1 = 'b'. itab-f2 = 'c'. append itab.
itab-f1 = 'a'. itab-f2 = 'g'. append itab.



sort itab by f1 f2.


data : lv_flag type c,
lv_cnt type i,
lv_val(10) type c.

loop at itab.
write :/ itab-f1 , 15 itab-f2.
endloop.

skip 10 .
write :/ sy-uline(30).

loop at itab  .
  at new f2.
    lv_flag = 'X'.
  ENDAT.
  if lv_flag eq 'X'.

    lv_val = itab-f2.
    lv_flag = ''.
  endif.
  if lv_val = itab-f2.
    add 1 to lv_cnt .
  endif.
  itab-f3 = lv_cnt.
  modify itab index sy-tabix.
  if lv_cnt eq 2.
    write :/ 'duplicate entry for', itab-f1 ,itab-f2, itab-f3.
  endif.
  at end of f2.
    clear : lv_cnt.
  endat.
endloop.

occurance 2 should throw an error message before the save in the PAI . any occurance of 2 will stop the entry into DB ..

Br,

Vijay.