Saturday 16 March 2013

Validating Select-options in SAP ABAP

Generally , while validating select-options we write the code as below.

*It is only partially correct , refer the codes below
select matnr from mara into lv_mara
                             where matnr in so_matnr.
if sy-subrc is not initial.
   "error message
endif.

but above code , is wrong . Now suppose the user enters two material number , 0000000002 and
0000000045 where the 2nd one does not exist in the system .But sy-subrc will become 0 , and the error message will not be executed .
So , we have to consider the following codes that will help !!!

REPORT  ztestr_14.

TABLES : mara.

SELECT-OPTIONS : so_matnr FOR mara-matnr.

TYPES : BEGIN OF ty_matnr,
          matnr TYPE matnr,
        END OF   ty_matnr.

DATA : li_matnr TYPE STANDARD TABLE OF ty_matnr.
FIELD-SYMBOLS : <fls_matnr> TYPE ty_matnr.

IF so_matnr IS NOT INITIAL.

  SELECT matnr FROM mara
               INTO TABLE li_matnr
               WHERE matnr IN so_matnr.

  IF sy-subrc IS INITIAL.

    SORT li_matnr ASCENDING BY matnr.

    LOOP AT so_matnr.

      READ TABLE li_matnr ASSIGNING <fls_matnr>
                          WITH KEY  matnr = so_matnr-low
                          BINARY SEARCH.

      IF sy-subrc IS NOT INITIAL.

        PERFORM error_handling USING text-e01 so_matnr-low.

      ENDIF.

    ENDLOOP.

    IF so_matnr-high IS NOT INITIAL.

      READ TABLE li_matnr ASSIGNING <fls_matnr>
                          WITH KEY  matnr = so_matnr-high
                          BINARY SEARCH.

      IF sy-subrc IS NOT INITIAL.

        PERFORM error_handling USING text-e01 so_matnr-high.

      ENDIF.

    ENDIF.

  ELSE.

     PERFORM error_handling USING text-e01 so_matnr-low.

  ENDIF.

ENDIF.

form ERROR_HANDLING  using    p_text_e01 TYPE string
                              value type any.

       DATA : lv_message TYPE string.
       CONSTANTS : lc_plach1 TYPE char2 VALUE '&1'.
        CLEAR : lv_message.
        lv_message = p_text_e01." where text-e01 = Material number &1 does not exist
        REPLACE lc_plach1 WITH value
        INTO lv_message.
        MESSAGE e000(zh) WITH lv_message.

endform.                    " ERROR_HANDLING

10 comments:

  1. It really only makes sense to validate range table entries that have an "option" value of 'EQ', so I espouse the use of this simple hunk of code:
    LOOP AT so_kunnr.
    IF so_kunnr-option = 'EQ'.
    SELECT SINGLE kunnr INTO ld_kunnr FROM kna1
    WHERE kunnr = so_kunnr-low.
    IF sy-subrc <> 0.
    MESSAGE e537.
    ENDIF.
    ENDIF.
    ENDLOOP.

    Cheers,
    TerryB

    ReplyDelete
    Replies
    1. THANK YOU

      Delete
    2. Sap Abap : Validating Select-Options In Sap Abap >>>>> Download Now

      >>>>> Download Full

      Sap Abap : Validating Select-Options In Sap Abap >>>>> Download LINK

      >>>>> Download Now

      Sap Abap : Validating Select-Options In Sap Abap >>>>> Download Full

      >>>>> Download LINK gT

      Delete
  2. What's up colleagues, good paragraph and pleasant arguments commented here, I am genuinely enjoying by these.


    Review my web blog: option bot review

    ReplyDelete
  3. I know this web site presents quality based articles or reviews and other information, is there any other web site which presents
    these kinds of stuff in quality?

    my webpage: binary matrix pro

    ReplyDelete
  4. There is definately a great deal to find out about this topic.
    I really like all of the points you have made.

    Also visit my web site binary Options daily

    ReplyDelete
  5. Do you have a spam problem on this site; I also am a blogger, and I
    was wondering your situation; many of us have developed some nice practices and we are looking to exchange methods with
    other folks, please shoot me an e-mail if interested.


    Feel free to visit my web page ... binary options trading

    ReplyDelete
  6. After looking into a number of the articles on your blog, I rewlly appreciate your
    waay of writing a blog. I bookmarked it to my bookmark website list
    and will be checking backk in the near future. Please ceck outt my
    web site as well and leet me know your opinion.

    Here is my blog plst ... extremely accurate most really profitable double choices investments alerts currency trading technique system application continuous outcome profits examinationuncover how astonishing system catch any market health problem predict forthcoming current market motions

    ReplyDelete
  7. It's a pity you don't have a donate button! I'd without a doubt donate to this brilliant blog!
    I guess for now i'll settle for bokmarking and adding
    your RSS feed to my Googe account. I look forward to new updates aand will share this site with my Facebook group.
    Taalk soon!

    Have a look at my wwblog - incredibly accurate most profitable binary alternatives investments alerts forex structure technique program continuous outcome gains reviewsee how amazing solution find any current market problem calculate forthcoming markets motions

    ReplyDelete
  8. Sap Abap : Validating Select-Options In Sap Abap >>>>> Download Now

    >>>>> Download Full

    Sap Abap : Validating Select-Options In Sap Abap >>>>> Download LINK

    >>>>> Download Now

    Sap Abap : Validating Select-Options In Sap Abap >>>>> Download Full

    >>>>> Download LINK rH

    ReplyDelete