Negative Condition checking in read statement

Hi,
i have table, which i have to read,  key on which i am going to read that will be determined dynamically. now i have to check the value for the key field is initial or not. i can't use a loop here as it doesn't allow me to mention where condition field dynamically.
thanks & regards,
prabhu

Hi use this:
DATA: BEGIN OF it OCCURS 0,     "your dynamic table
        field1 TYPE c,
        field2 TYPE c,
      END OF it.
it-field1 = '1'.
it-field2 = 'A'.
APPEND it.
it-field1 = ''.
it-field2 = 'B'.
APPEND it.
it-field1 = '2'.
it-field2 = 'C'.
APPEND it.
FIELD-SYMBOLS: <struct> TYPE ANY,
               <comp>   TYPE ANY.
LOOP AT it ASSIGNING <struct>.   "loop at your dynamic table
  ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <struct> TO <comp>.   "FIELD1 is determined dynamically
  IF sy-subrc = 0 AND <comp> is not initial.  
    WRITE <comp>.   "will write out <comp> for each entry which has non initial value in <comp> (here FIELD1)
  ENDIF.
ENDLOOP.
Please note that your <lfs> must hold name 'FIELD1' inside, than you can replace it with below code
  ASSIGN COMPONENT <lfs> OF STRUCTURE <struct> TO <comp>. 
Regards
Marcin
One thing to be added here:
You can't read table comparing its key field with negative condition NE , only comparison EQ are allowed in READ TABLE statement, that's why I chose above approach.
Edited by: Marcin Pciak on May 26, 2009 4:51 PM

Similar Messages

  • Multiple condition check using if statement.

    Hi
    i NEED to check two conditions using if statment. I was wondering whether it is possible.
    say fields zx and zy in an internal table itab. if one of those is intiial i have to display a message.
    i tried this way
    if itab-zx or itab-zy is initial.
    error message.
    endif.
    It gives me error in syntax check.
    I think i can check for first field using if and second one with elseif but for that matter of fact i have like 10 fields .out of which even one is initial i have to throw a message saying 'DATA CANNOT BE SAVED'.
    Please suggest me how to go about this.
    Thanks in advance.

    Hi Swathi,
    You have to loop your internal table and then check.
    Try this code.
    LOOP AT itab.
      IF itab-z1 IS INITIAL OR
         itab-z2 IS INITIAL OR
         itab-z3 IS INITIAL OR
         itab-z4 IS INITIAL OR
         itab-z5 IS INITIAL OR
         itab-z6 IS INITIAL OR
         itab-z7 IS INITIAL OR
         itab-z8 IS INITIAL OR
         itab-z9 IS INITIAL OR
         itab-z10 IS INITIAL.
        MESSAGE 'DATA CANNOT BE SAVED' TYPE 'E'.
      ELSE.
        " Processing if none of the fields are Initial
      ENDIF.
    ENDLOOP.
    Regards,
    Arun Sambargi.

  • Condition Checking with " IF " statement....

    Hi All,
    In one of my requirement ,the existing scenario is like this: IF currency is USD, then call subroutine X
    ELSE call subroutine Y. i.e  if po_headers-waers = 'USD'
                                             Perform fill_bdc_table using  ' '  'RV61A-KOEIN(01)' 'US4'.
                                             else.
                                             Perform fill_bdc_table using  ' '  'RV61A-KOEIN(01)'  po_headers-waers .
                                             endif.
    (The above code first check if  po_header currency value is 'USD' then it calls subroutine to convert the currency to US4,else it calls other subroutine to convert currency as per po_header currency value.) 
    Now my new requirement is : if po_header currency value is USD and po item value(po_items-netpr) is greater than '10000000.00', then call subroutine to convert it into USD, else for po_header currency value USD and po item value(po_items-netpr) is lesser than '10000000.00', call subroutine to convert into US4(as written above US4 code line).
    I have inserted code for the condition like this:
                                                                                    if po_headers-waers = 'USD'
                                                 and po_items-netpr GE '10000000.00'.
                                             Perform fill_bdc_table using  ' '  'RV61A-KOEIN(01)'  po_headers-waers.
                                          else.
                                             Perform fill_bdc_table using  ' '  'RV61A-KOEIN(01)'  'US4'.
                                              endif.
    But it only satisfies one condition i.e for po_items-netpr >= '10000000.00' with currency as USD , it is converting to USD,but for  po_items-netpr < '10000000.00' with currency as USD, it is not converting to US4.where i am missing the steps? can you all through some light.
    Thanx.
    Deb

    hi,
    Modify the code as following.
    if po_headers-waers = 'USD' .
      if po_items-netpr GE '10000000.00'.
        Perform fill_bdc_table using ' ' 'RV61A-KOEIN(01)' po_headers-waers.
      else.
        Perform fill_bdc_table using ' ' 'RV61A-KOEIN(01)' 'US4'.
      endif.
    endif.
    Regards
    Sharath

  • Can put condition in read statement for a particular fild please suggest?

    hi i have a requirement as belo
    1 ) i am reading a table with read statement now i want to read with one more condition like
    where status<> Z
    to add to this read statement as below can i add the above condition to the below statement?? let me know
    how to check on this one more condition in below read statement
    loop at itrecord1 into wa_Record
    READ TABLE it_main INTO wa_inv_master  WITH KEY
    /'                                 CUSIP = wa_record-primarykeyfield1  BINARY SEARCH.
    here one more condition i need to put whilereading that where statu <>z which is best way todo
              IF SY-SUBRC = 0.
                 APPEND wa_record TO itrecord1.
                 clear wa_record.
              else.
                 APPEND wa_record TO itrecord2.
                 clear : wa_record.
              ENDIF.
          ENDLOOP.
    so how to put the condition in above statment can  put in the read statement as that is most convinient will that work?
    regards
    arora

    Hello arora.
    You can restrict the READ to an internal table, using "n" conditions in WITH KEY statement.
    Use:
    READ TABLE it_main INTO wa_inv_master
      WITH KEY cusip = wa_record-primarykeyfield1
               field2 = wa_record-field2
               fieldn = wa_record-fieldn
        BINARY SEARCH.
    Remember that if you want restrictions like ">=", "<=", "<" or "<", must use LOOP, not READ.
    Regards.
    Valter Oliveira.

  • Problem in writing a Read Statement

    Hi,
    In my Table control I have a POSITION button which is used to find the record in the table.
    I have written the following code.
      CALL FUNCTION 'POPUP_GET_VALUES'
        EXPORTING
    *   NO_VALUE_CHECK        = ' '
          popup_title           = 'Find the record'
    *   START_COLUMN          = '5'
    *   START_ROW             = '5'
    * IMPORTING
    *   RETURNCODE            =
        TABLES
          fields                = lt_tab
    EXCEPTIONS
       error_in_fields       = 1
       OTHERS                = 2
    I have five primary keys in my table, so that in the pop up I am getting all the five fields.
    The user will enter any of the five fields , I want to write a read statement based on the fields entered by the user.
    Could anybody help in writing the Read  statement.
    Or could any one help me in writing out the FIND functionality for a table control
    Regards
    Edited by: SAP LEARNER on Jun 15, 2010 1:40 PM

    Hi,
    I do not know what fields will be filled up.
    as there are 5 PK fields so 5! chances will be there for the where condition in the READ statement.
    How can I do it.
    I tried in the following way.
    I created a structure with the primary key fields and I filled the structure with the user filled values.
    Then I used it in the read statement as below, but it did not work.
        LOOP AT lt_tab .
          IF lt_tab-fieldname = 'SOCIEDAD'.
            lw_pk-sociedad = lt_tab-value.
          ENDIF.
          IF lt_tab-fieldname = 'NATURAL_YEAR'.
            lw_pk-natural_year = lt_tab-value.
          ENDIF.
          IF lt_tab-fieldname = 'CICLO_DE_VENTAS'.
            lw_pk-ciclo_de_ventas = lt_tab-value.
          ENDIF.
          IF lt_tab-fieldname = 'MODEL_VERSION'.
            lw_pk-model_version = lt_tab-value.
          ENDIF.
        ENDLOOP.
        DATA:lw_yrwbw010 TYPE ty_yrwbw010.
        READ TABLE t_yrwbw010 INTO lw_yrwbw010 WITH KEY lw_pk.
         IF sy-subrc = 0.
          table-top_line = sy-tabix.
         ENDIF.
      ENDIF.
    @Rob Burbank
    Could you please help me !! I could not find that in F1 help.
    @ Keshav.T         
    Could you please elaborate it please

  • How to give read statement checking condition

    hi,
    i am trying to give like this, but it throws an error can u tell me how to give a read statement checking two conditions.
    READ TABLE I_RSEG INTO WA_TAB_RSEG WITH KEY BELNR = WA_TAB_RBCO-BELNR
                                                          AND GJAHR = WA_TAB_RBCO-GJAHR
                                                          AND BUZEI = WA_TAB_RBCO-BUZEI.

    Hi Anitha,
              READ statement wont have 'AND's in them. Your statement will work fine without having 'AND's. Lets try by omitting 'AND's in ur statement.
    Please change the code as follows.
    1)
    READ TABLE I_RSEG INTO WA_TAB_RSEG WITH KEY BELNR = WA_TAB_RBCO-BELNR
    GJAHR = WA_TAB_RBCO-GJAHR
    BUZEI = WA_TAB_RBCO-BUZEI.
    2)sort i_resg by belnr gjahr buzei.
    READ TABLE I_RSEG INTO WA_TAB_RSEG WITH KEY BELNR = WA_TAB_RBCO-BELNR
    GJAHR = WA_TAB_RBCO-GJAHR
    BUZEI = WA_TAB_RBCO-BUZEI binary search.
    The above statement will fetch u particular record faster than the above READ statement.
    Thanks,
    Vinay
    Message was edited by: Vinaykumar Gorrela

  • How can I use a READ statement for the checking date =sydatum?

    Hello,
         I need use a READ statement on an internal table ITAB (with feild var1) and check whether feild var1<= sydatum(i.e. var1 greater than or equal to sy-datum)....how can I implement this??
    Regards,
    Shashank.

    Hi,
    try this short example.
    DATA: BEGIN OF ITAB OCCURS 0,
            DATE LIKE SY-DATUM,
          END   OF ITAB.
    ITAB-DATE = '20000101'. APPEND ITAB.
    ITAB-DATE = '20010101'. APPEND ITAB.
    ITAB-DATE = '20020101'. APPEND ITAB.
    ITAB-DATE = '20030101'. APPEND ITAB.
    ITAB-DATE = '20040101'. APPEND ITAB.
    ITAB-DATE = '20050101'. APPEND ITAB.
    ITAB-DATE = '20060101'. APPEND ITAB.
    ITAB-DATE = '20070101'. APPEND ITAB.
    ITAB-DATE = SY-DATUM.   APPEND ITAB.
    ITAB-DATE = '20080101'. APPEND ITAB.
    LOOP AT ITAB WHERE DATE < SY-DATUM.
      WRITE: / 'before', ITAB-DATE.
    ENDLOOP.
    LOOP AT ITAB WHERE DATE = SY-DATUM.
      WRITE: / 'equal ', ITAB-DATE.
    ENDLOOP.
    LOOP AT ITAB WHERE DATE > SY-DATUM.
      WRITE: / 'after ', ITAB-DATE.
    ENDLOOP.
    Regards, Dieter

  • Conditionally checking checkboxes

    Hi.
    I need a checkbox for which the checking operation is conditional -- in certain illegal states of the containing frame and its components none of the checkboxes should change their state. I do not want to use checkbox.setEnabled(false). The changeListener does not sound good either.
    (Also I had to prevent combobox popup from appearing on same conditions. I was able to solve that by implementing my own ComboBoxUI with show() method modified. I can't think of a similar approach for the checkboxes at the moment.)
    Any ideas how to do it?

    That sure is an interesting link, rkconner, thank you, I think I'll need to read something like this soon.
    As for current case -- I have a really complex page (lots and lots of them, actually), with some fields disabled, and others enabled. Some fields need verification and the focus (generally) should not be able to leave such field unless the field value is legal. The legality is determined by querying a remote database.
    When I click an enabled checkbox, the verify() method for recently focused field starts. If the remote query returns negative response, I shouldn't be able to change the checkbox value, until the recent field is considered legal. So, I can't use setEnabled(false) for the checkbox, because, when I change the illegal value to a legal one, the checkbox should become changable instantly. I mean, I should be able to launch the verification process by clicking the checkbox.
    That's why I'm looking for another solution. Still looking :)

  • Read statement with repeated key field

    Hi Experts ,
    We  are in the process of UCCHECK in an upgrade program and come across an issue with read statement using repeated key fields which is not allowed in a unicode compatable environment.
                READ TABLE it_vbpa WITH KEY
                                          vbeln = l_vbeln
                                          parvw = '0'
                                          parvw = 'ZN'.
    I checked this in 4.6c environment and observed that the Read statement uses the last key value for reading and doesnt consider other values even if the last value is not present in the table  .
    I want to know if I can use only that last value for read statement ? If so, what was the use of the repeated key fields in a read statement?
    Thanks and Regards
    Sanu

    Hi,
    Your main aim in a upgrade would be to successfully replicate the 4.6x functionalities in the ECC 6 version with the unicode checks. So it would be a safe option to only consider the last key condition. I dont have access to a 4.6C environment. May be it was a mistake corrected by SAP in the new version.
    Vikranth

  • IF-conditions check order

    Hi all,
    I'd like to ask if it's safe to write such constructions:
    if ((s == null) || (s.toString.equals(""))) {
    I wonder whether it's guaranteed that firstly the condition (s == null) would be checked. If it is so, then we could be quiet of this code to be safe, otherwise - we could not.

    Serge_HID wrote:
    Hi all,
    I'd like to ask if it's safe to write such constructions:
    if ((s == null) || (s.toString.equals(""))) {
    I wonder whether it's guaranteed that firstly the condition (s == null) would be checked. If it is so, then we could be quiet of this code to be safe, otherwise - we could not.If you would have written it in that form;
    if ((s == null) | (s.toString.equals(""))) {
      }it would check all the statements. But || && checks the other statements if it is needed. For example if the first statement is true then the || operand doesn't need to check the next statement and if the first statement is false then the && operand doesn't need to check the next statement.

  • Condition Checking

    Hi,
      Is there anyway i can ensure, let's say my "net income" is larger than 2 million before the user can submit the data? is there some sort of condition checking or locking mechanism that does this?
      any input on this?
    cheers

    You can have something like that for submission
    please check into help online the follow link
    http://name of your application server/osoft/help/admin/helpstart.htm#Setting_application_set_parameters.htm
    It is not exactly what you want but you can do something using this approach.
    You can change the work status settings for each application. Changing the work status settings involves identifying three to five 'work status dimensions,' and then defining specific members for the remaining non-work status dimensions used for validation purposes. You must determine which account you will use for validation of the data at the time the work status is changed. The validation account must be &rdquor;0u201D at the intersection of the 3-5 variable members and the members designated for the non-work status dimensions.  If the account is not &rdquor;0u201D then the owner/manager cannot set the work status.  This is an option feature.
    The dimensions you select as the work status dimensions are the variables in your business process. For example, the entity, category, and time might change based on who is submitting data, but the account, data source, reporting currency, etc., remains static. (Typically, Time is a work status dimension since data is usually segregated based on time.)
    For example, lets say that you set Entity, Category, and Timeas your work status dimensions for a given application. You then set your other current view members to the following:  Account: Validation; DataSrc: TotalAdj; Intco: All_Intco; and RptCurrency: LC. In addition to assigning work status dimensions, you also specify which dimension is the 'owner dimension.' The owner dimension includes the Owner property. The owner property determines who can edit a work status setting. The following figure shows this setup, where Entity is the Owner dimension.
    A user attempts to post data to the current view shown in the following table. The system checks the 'validation' account to make sure the intersection equals zero (0). If so, the data is posted, and a success message is displayed. The user can now set the work state to 'submitted' on that intersection. Subsequent submissions to that exact intersection will be rejected. Users can only send data to the same intersection if the Entity, Category, or Time member changes.
    Account
    <All>
    Category
    Actual
    DataSrc
    <All>
    Entity
    SalesNE
    Intco
    <All>
    RptCurrency
    <All>
    Time
    Feb.2007
    To change work status settings for applications
    From the Admin Console, expand the Application node.
    Expand the application for which you want to change the work status setting.
    Select Work Status Settings.
    In the Work State column, select Yes for each dimension you want to use to control the work status settings. Select Owner for the dimension that contains the Owner property.
    In the Member Validation column, select a member for each non-work status dimensions. (Use the browse button to open the Member Lookup.)
    From the action pane, select Save Work Status Settings.

  • Smart Groups using a combined negative condition don't seem to work

    I have two manually created Groups. Let's call them 'All' and 'Some'. If I create a Smart Group so:
    Contains cards which match all of the following conditions
    Card is member of All
    Card is not a member of Some
    I would expect the result to give me all those cards in All that are not in Some.
    It doesn't. It yields all the cards in All. In other words the negative condition "not a member of" is being ignored.
    Anyone else found this?
    Is there a workaround?
    Thanks

    I have had similar problems. If you are certain you have the appropriate criteria checked, The match "any" or match "all" on the top level which ever is right, then the rating "is" the criteria you want and scroll down to make sure nothing else is limiting your search, all obvious I know, and then you have checked to make sure in the browser search field "Showing all" is displayed and it still doesn't work, then I simply do this. Delete the smart album or web gallery and create a new one with the criteria you want. It doesn't make sense to me, but it has worked many times when my Smart albums get stupid. I have a similar unanswered question here.
    http://discussions.apple.com/message.jspa?messageID=6613369#6613369
    As far as the greyed out criteria, I don't think that has happened to me.
    PS is this in Aperture2?

  • Check the Row state in Application Module.

    Hi All,
    I have an EOVO in my page. Is there any way to check the row state in Application module??
    My requirement is if any row is created for the EOVO , just delete it.
    Please suggest suitable methods to fulfill this requirement...
    Regards,
    Tarun

    Yes, you can check the status of the rows of a VO in Application Module(AM)
    In AM, get the instance of the VO and loop through it's rows and check the status of the rows as
    In row you have a method called getNewRowState(). It will return values like Row.STATUS_INITIALIZDED etc.
    Check the javadoc of oracle.jbo.Row for possible values and explanations about the status.
    So ideally you have to write a condition as follows. This is a sample code..just use as a guide.
    if (row.getNewRowState() = oracle.jbo.Row.STATUS_INITIALIZED){
    row.remove();
    Regards,
    Peddi.

  • Problem with READ Statement in the field routine of the Transformation

    Hi,
    I have problem with read statement with binary search in the field routine of the transformation.
    read statement is working well when i was checked in the debugging mode, it's not working properly for the bulk load in the background. below are the steps i have implemented in my requirement.
    1. I selected the record from the lookuo DSO into one internal table for all entried in source_packeage.
    2.i have read same internal table in the field routine for each source_package entry and i am setting the flag for that field .
    Code in the start routine
    select source accno end_dt acctp from zcam_o11
    into table it_zcam
    for all entries in source_package
    where source = source_package-source
         and accno = source_package-accno.
    if sy-subrc = 0.
    delete it_zcam where acctp <> 3.
    delete it_zcam where end_dt initial.
    sort it_zcam by surce accno.
    endif.
    field routine code:
    read table it_zcam with key source = source_package-source
                                                 accno  = source_package-accno
                                                 binary search
                                                 transportin no fields.
    if sy-subrc = 0.
    RESULT  = 'Y'.
    else.
    RESULT = 'N'.
    endif.
    this piece of code exist in the other model there its working fine.when comes to my code it's not working properly, but when i debug the transformation it's working fine for those accno.
    the problem is when i do full load the code is not working properly and populating the wrong value in the RESULT field.
    this field i am using in the report filter.
    please let me know if anybody has the soluton or reason for this strage behaviour.
    thanks,
    Rahim.

    i suppose the below is not the actual code. active table of dso would be /bic/azcam_o1100...
    1. is the key of zcam_o11 source and accno ?
    2. you need to get the sortout of if endif (see code below)
    select source accno end_dt acctp from zcam_o11
    into table it_zcam
    for all entries in source_package
    where source = source_package-source
    and accno = source_package-accno.
    if sy-subrc = 0.
    delete it_zcam where acctp 3.
    delete it_zcam where end_dt initial.
    endif.
    sort it_zcam by surce accno.
    field routine code:
    read table it_zcam with key source = source_package-source
    accno = source_package-accno
    binary search
    transportin no fields.
    if sy-subrc = 0.
    RESULT = 'Y'.
    else.
    RESULT = 'N'.
    endif.

  • Issue with read statement with one more key missing in mapping

    Hi All ,
    I have such data in two internals table :
    IT_bdc
    vbeln            posnr
    90000593     10
    90000576     10
    90000672     10
    90000672     20
    90000672     30
    it_konv
    kbetr          vbeln
    6250          90000576
    12160000          90000593
    500000          90000672
    600000          90000672
    700000          90000672
    My current program statement is :
    LOOP AT it_bdc.
    READ TABLE it_konv WITH KEY
          vbeln = it_bdocs-vbeln.
      currency =   it_konv-waers.
    endloop.
    as you can see the posnr is missing in it_konv how can i modify this read statement so
    that vbeln posnr from it_bdc should get correct kbetr from it_konv.
    Kindly help in this mapping.

    Hi
    sort it_konv by vbeln
    then
    loop at it_bdc.
    read table it_konv with key vbeln = it_bdc-vbeln binary search.
    if sy-subrc = 0.
    perform your logic/task.
    endif.
    endloop.
    also it depends what you want to do after reading it_konv.
    in my logic if there is a vbeln in it_konv which s present in it_bdc then sy-subrc will be 0
    and you can perform your logic.
    and if there will be no matching vbeln in it_konv then sy-subrc will not be 0.
    check the values in debugging.
    Thanks
    Lalit

Maybe you are looking for