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

Comparing screen input in program in module pool programming(table control)

Former Member
0 Likes
1,078

Experts,

I am a newbie in ABAP. I am working dialog programming where I am replicating PR creation. I am asking user to enter item number, material number and plant. I am validating material number and plant using chain and endchain. This validation is working fine and it throws error message if user enters invalid input. I am able to see corresponding details (corresponding details like unit of measure, delivery date and short text etc. if values entered are correct.) when user clicks on ADD button. Now I have one problem. If user enters same item number twice it should throw error message. I am not able to figure out how it should be done. I thought to set flag = 'X' after user enters item number.

I am using table control. The validation part for material number(matnr) and plant (werks) work fine. I am getting problem while checking entered item number to check duplication.

User should not enter the same item number again.

In my structure i have defined a variable called checkflag(1) type c. and i am doing it now following way. Right now my checkflag code is commented.

Following is my snippet for the same.

Please let me know your ideas/suggestions and advices.

DATA : counter TYPE i,
         itmno1 TYPE i.

  SELECT SINGLE matnr
       FROM mara INTO matno WHERE matnr = it_pr-matnr.
  SELECT SINGLE werks
         FROM t001w INTO plant WHERE werks = it_pr-werks.
  SELECT SINGLE matnr werks
         FROM marc INTO (matno,plant)
    WHERE matnr = it_pr-matnr AND werks = it_pr-werks.
  itmno1 = it_pr-bnfpo.
  IF ok_code = 'ADD'.

    IF it_pr-matnr <> matno OR it_pr-werks <> plant AND it_pr-bnfpo = ''.
      MESSAGE 'Not a Valid material number or plant. Please enter valid values.' TYPE 'E'.

    ELSEIF it_pr-matnr = matno AND it_pr-werks = plant AND it_pr-bnfpo <> ''.

      SELECT SINGLE maktx FROM makt INTO stext WHERE matnr = it_pr-matnr.
      SELECT SINGLE meins FROM mara INTO tmeins WHERE matnr = it_pr-matnr.
      SELECT SINGLE lpein FROM eban INTO tlpein WHERE matnr = it_pr-matnr.



*      if it_pr-bnfpo = itmno1.
*        it_pr-checkflag = 'X'.
*      endif.
*
      READ TABLE it_pr WITH TABLE KEY
      checkflag = it_pr-checkflag
      bnfpo = it_pr-bnfpo
      maktx = it_pr-maktx
      matnr = it_pr-matnr
      eindt = it_pr-eindt
      meins = it_pr-meins
      werks = it_pr-werks
      lpein = it_pr-lpein.

*      if it_pr-checkflag = 'X'.
*          message 'Please enter another item number.' TYPE 'E'.
*          endif.

      IF sy-subrc <> 0.
        it_pr-bnfpo = itmno1.
        it_pr-maktx = stext.
        it_pr-lpein = tlpein.
        it_pr-meins = tmeins.
        APPEND it_pr.
      ENDIF.
      IF sy-subrc = 0.
        MESSAGE 'Please enter another item number.' TYPE 'E'.
      ENDIF.
    ENDIF.
  ENDIF.

3 REPLIES 3
Read only

Former Member
0 Likes
548

you want to check that in item number input field ...user should not enter same value again right?

so for that you can take another internal table having same structure which you have used for table control.

now in pai, between loop and endloop. you can take all the values in some internal table itab and check when user enters value , that time it will come in tc interanl table , so you can check in itab and throw erro if repeated.

Read only

Former Member
0 Likes
548

When you are validating the input data, there you can also validate the data that are duplicate. in the table control deep structure there is a field current_line. Check if the item number exists in any other line other than the current_line (the line you are currently processing). If it is there, then throw an error message.

Read only

0 Likes
548

Indeed thank you very much @medha24 and @gargi sarkar.

If I use current-line, I will have to skip first entry as first entry should be appended. Then only I would be able to compare it with newly entered value. I will have to use loop end loop within the PAI. I have already written this code in the validation PAI itself.

I am not getting how I should use loop endloop effectively so that control will go to the next iteration effectively. Right now with this code, I am getting partial success if I enter item number in bulk (more than one item number as input at same time). later, even though I enter correct values I get error message as it doesn't find next entry in the table. It only appends first records only. Therefore, I am looking to enter first entry without any check and later entries should be compared and appended. I would appreciate your ideas/suggestions.

Thank you.

Best reagrds.