Skip to Content

If else based on tables in AMDP

Hello,

I need to compare three tables and determine a field from it i.e if the field is available in the table 1, retrieve the same else retrieve from table 2 or else from table 3.

Can someone give me pointers as to how to arrive at this logic?

Thank you.

Regards,

Prem

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Jul 20, 2016 at 10:06 AM

    Hi,

    Based on your explanation I am providing below way...

    prem kumar wrote:

    I need to compare three tables and determine a field from it i.e if the field is available in the table 1, retrieve the same else retrieve from table 2 or else from table 3.

    declare field nvarchar(100);

    select field_name into field

    FROM "PUBLIC"."TABLE_COLUMNS"

    WHERE ("SCHEMA_NAME" = 'SCHEMANAME' AND "TABLE_NAME" = 'TABLENAME' AND COLUMN_NAME = 'FIELD');

    if :field_name = 'FIELD' Then

    else

    end if;

    -Amol S

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi,

      prem kumar wrote:

      My requirement is to retrieve data from the table 1 based on few conditions , if table 1 has data then retrieve the same and stop further processing. If there is no data , then check if table 2 has data else table 3.

      Yes we can write it in different way too.. without joining all tables together....

      Since I don't know complete business logic of your side.

      Might be below query will solve the issue..

      declare lv_count nvarchar(1000);
      it_table1 = select * from Table1 ;
      select count(*) from :it_table1 into :lv_count;
      if :lv_count = 0 then
      it_table2 = select * from Table2;
      select count(*) from :it_table2 into :lv_count;
      if :lv_count = 0 then
      it_table3 = select * from table3;
      end if;
      end if;
      
      

      -Amol S

  • Posted on Jul 20, 2016 at 06:04 AM

    Do something like below:

    select <field> from table1 into lv_field where <specify conditions>.

    if sy-subrc NE 0.

    select <field> from table2 into lv_field where <specify conditions>.

    if sy-subrc NE 0.


    select <field> from table3 into lv_field where <specify conditions>.


    endif.

    endif.


    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.