SQL Command conversion in abap code

Hi,
I want to implement the UNION, INTERSECT and MINUS SQL commands in abap code. Please give me the appropriate solutions asap.
For Example:
select field1, field2, . field_n
from tables
<b>UNION</b>
select field1, field2, . field_n
from tables;
select field1, field2, . field_n
from tables
<b>MINUS</b>
select field1, field2, . field_n
from tables;
select field1, field2, . field_n
from tables
<b>INTERSECT</b>
select field1, field2, . field_n
from tables;
Thanks,
Ravi

Hi Ravi
Check out this procedure...
DATA: FRANKFURT(4) TYPE X,
      FRISCO(4)    TYPE X,
      INTERSECT(4) TYPE X,
      UNION(4)     TYPE X,
      BIT          TYPE I.
DATA: CARRID TYPE SPFLI-CARRID,
      CARRIER LIKE SORTED TABLE OF CARRID
                          WITH UNIQUE KEY TABLE LINE.
DATA WA TYPE SPFLI.
SELECT CARRID FROM SCARR INTO TABLE CARRIER.
SELECT CARRID CITYFROM FROM SPFLI
                       INTO CORRESPONDING FIELDS OF WA.
  WRITE: / WA-CARRID, WA-CITYFROM.
  READ TABLE CARRIER FROM WA-CARRID TRANSPORTING NO FIELDS.
  CASE WA-CITYFROM.
    WHEN 'FRANKFURT'.
      SET BIT SY-TABIX OF FRANKFURT.
    WHEN 'SAN FRANCISCO'.
      SET BIT SY-TABIX OF FRISCO.
  ENDCASE.
ENDSELECT.
INTERSECT = FRANKFURT BIT-AND FRISCO.
UNION     = FRANKFURT BIT-OR  FRISCO.
SKIP.
WRITE 'Airlines flying from Frankfurt and San Francisco:'.
DO 32 TIMES.
  GET BIT SY-INDEX OF INTERSECT INTO BIT.
    IF BIT = 1.
      READ TABLE CARRIER INDEX SY-INDEX INTO CARRID.
      WRITE CARRID.
    ENDIF.
ENDDO.
SKIP.
WRITE 'Airlines flying from Frankfurt or San Francisco:'.
DO 32 TIMES.
  GET BIT SY-INDEX OF UNION INTO BIT.
    IF BIT = 1.
      READ TABLE CARRIER INDEX SY-INDEX INTO CARRID.
      WRITE CARRID.
    ENDIF.
ENDDO.
This produces the following output list:
The program uses four hexadecimal fields with length 4 - FRANKFURT, FRISCO, INTERSECT, and UNION. Each of these fields can represent a set of up to 32 elements. The basic set is the set of all airlines from database table SCARR. Each bit of the corresponding bit sequences representes one airline. To provide an index, the external index table CARRIER is created and filled with the airline codes from table SCARR. It is then possible to identify an airline using the internal index of table CARRIER.
In the SELECT loop for database table SPFLI, the corresponding bit for the airline is set either in the FRANKFURT field or the FRISCO field, depending on the departure city. The line number SY-TABIX is determined using a READ statement in which no fields are transported.
The intersection and union of FRANKFURT and FRISCO are constructed using the bit operations BIT-AND and BIT-OR.
The bits in INTERSECT and UNION are read one by one and evaluated in two DO loops. For each position in the fields with the value 1, a READ statement retrieves the airline code from the table CARRIER.
Comparing Bit Sequences
Use the following three operators to compare the bit sequence of the first operand with that of the second:
<operator>
Meaning
O
bits are one
Z
bits are zero
M
bits are mixed
The second operand must have type X. The comparison takes place over the length of the second operand. The first operand is not converted to type X.
The function of the operators is as follows:
O (bits are one)
The logical expression
<f> O <hex>
is true if the bit positions that are 1 in <hex>, are also 1 in <f>. In terms of set operations with bit sequences, this comparison is the same as finding out whether the set represented by <hex> is a subset of that represented by <f>.
Z (bits are zero)
The logical expression
<f> Z <hex>
is true if the bit positions that are 1 in <hex>, are 0 in <f>.
M (bits are mixed)
The logical expression
<f> M <hex>
is true if from the bit positions that are 1 in <hex>, at least one is 1 and one is 0 in <f>.
Caution: The following programs are no longer supported in Unicode systems:
REPORT demo_log_expr_bits .
DATA: text(1) TYPE c VALUE 'C',
      hex(1) TYPE x,
      i TYPE i.
hex = 0.
DO 256 TIMES.
  i = hex.
  IF text O hex.
    WRITE: / hex, i.
  ENDIF.
  hex = hex + 1.
ENDDO.
The output is as follows:
00          0
01          1
02          2
03          3
40         64
41         65
42         66
43         67
Here, the bit structure of the character 'C' is compared to all hexadecimal numbers HEX between '00' and 'FF' (255 in the decimal system), using the operator O. The decimal value of HEX is determined by using the automatic type conversion during the assignment of HEX to I. If the comparison is true, the hexadecimal number and its decimal value are displayed on the screen. The following table shows the bit sequences of the numbers:
Thanks
Ashok

Similar Messages

  • SQL Command for deleting T-Code for roles

    Hi Experts
    I want to delete the transaction from the role name by using SQL Command in MS-SQL Server  instead of going to /npfcg -> zwa_xyz (role name for user) and transaction code is CR01,CR01,CA01 Etc.,
    I have so many transaction code which is taking time to delete one by one.
    So is there any SQL Statement to delete the t-code for that rolename
    Delete from tablename where t-code=xyz and rolename in ('zwa_xyz',zwa_123')
    regards

    Hey,
    SAP does not support executing update/insert/delete SQLs on their tables,
    (the only SQL they support are select, and updates that they publish in their official site, such as notes in service.sap.com/notes)
    is is probably due to the fact that sap contains about 30,000 of table,
    and sometimes SAP uses cluster tables (which are difficult to handle in DB)
    in addition, each and every SP adds/remove table or changes existing tables.
    For example, you probably don't know that changing rule, would
    create a change document (cluster table - CDHDR, CDPOS and etc),
    If you want, it is very easy to get the full list of the table (and the sql) that are updated
    (as I mentioned before, it is not recommended to run this sql, because it is not supported!!!)
    just run transaction ST05 while deleting transaction from role,
    when you display the list, press shift+F8 (or summerized trace from the menu),
    and they search (Ctrl+F) the words: update or insert or delete.
    You can use standard API such as BAPIs (such as BAPI_USER_*)/IDOCs(such as USERCHANGE),
    and execute them from the portal and any other place (even in EXCEL or OS->meaning command line).
    Here more information on executing RFCs:
    1. in order to execute an RFC from excel, you should install SAP gui on the client that would execute the RFCs to the SAP, and you would have to write VBA code.
    2. in order to execute an RFC from command line, this is a little bit more difficult,
    sap provide RFC sdk (in service.sap.com/SWDC)
    3. in order to execute an RFC from .net you can use the .net connector,
    more information is here:
    NW RFC SDK - is there a guide somewhere?
    4. You can also, execute an RFC using Web service,
    by creating web-service from the RFC in SE37.
    I guess It will take more time to develop this they just executing the SQL.
    If you need more information in executing an RFC,
    please decide which option is your favorite,
    and I would add information...

  • SQL Command to Check ABAP Support Patches and JSPM Patch

    Dear all,
    We have setup an DiasterRecovery System of the BI Production System .
    os: aix 6.1
    Database: Oracle 11.2
    BUT , Our DR System is in Physical Standby mode.
    Generally, we see the ABAP Patch version in SAP GUI ( System -- System status).
    Likewise, Is there any SQL Command available to check the version ABAP Patches (
    SAP_BASIS, SAP_ABAP, PI_Cont add on, PI_BASIS AND BW Patch - SAP_BW)
    Is there any sql command to check the version of JSPM or JAVA Patch
    regards,
    gayathri.K

    Hi Gayathri,
    BUT , Our DR System is in Physical Standby mode.
    Generally, we see the ABAP Patch version in SAP GUI ( System -- System status).
    Likewise, Is there any SQL Command available to check the version ABAP Patches (
    SAP_BASIS, SAP_ABAP, PI_Cont add on, PI_BASIS AND BW Patch - SAP_BW)
    You can perform sql query on CVERS table.
    For eg: Select * from <schema>.CVERS ;
    This will list all the entries with all the columns from CVERS table.
    Hope this helps.
    Regards,
    Deepak Kori

  • EXIT command behaviour in ABAP code?

    Hi Experts,
    Pls. let me clarify that, the behaviour of EXIT command, like,
    - in IF statement
    - in LOOP
    - in PERFORM/FORM
    -in DO
    thanq

    to exit out of the event blocks and the loops we will use exit command.
    see these links for more info.
    http://help.sap.com/saphelp_nw70/helpdata/en/9f/db9af135c111d1829f0000e829fbfe/content.htm
    terminating the loop using exit
    DO 10 TIMES.
      IF sy-index = 3.
        EXIT.
      ENDIF.
      WRITE sy-index.
    ENDDO.
    The list output is:
    1 2
    module exit input.
    if ok_code = 'REFR'.
    call transaction 'ZMEDEMP'.
    elseif ok_code = 'BACK'.
    set screen 0.
    leave to screen 0.
    elseif ok_code = 'EXIT'.
    leave program.
    endif.
    endmodule.
    For E.g
    AT EXIT-COMMAND code.
    In your flow logic, you create a module as so:
    MODULE md_exit_command AT EXIT-COMMAND.
    Then in PF-status, you configure the Cancel (red button on toolbar) as exit button by setting Type of button as 'E'. Put OKCODE as 'CANC'.
    Then, in the module
    MODULE md_xit_command INPUT.
    CASE OKCODE.
    WHEN 'CANC'. LEAVE TO SCREEN 0. ENDCASE.
    ENDMODULE.
    Also refer,
    AT Exit
    Reward points..

  • UNIX command in ABAP code

    Hi All,
    I need to use unix command (MOVE) in ABAP code for transfering a file from one directory to another directory.
    Can any one help with how to used unix commands in ABAP?
    Thanks in advance.
    Regards,
    Hemendra

    The recommended approach always used to be to use transaction SM69 to define a "soft" command name to the operating system command so that it could be configured to work across Windows, Unix etc.  For example:
    Command name       OS         Type             OS command                                 Parameters for operating system command 
    Z_FILE_MOVE        SunOS      Customer    mv                                                 ? ?   
    You can then call function module SXPG_COMMAND_EXECUTE (quite well documented) to actually perform the command passing in the appropriate number of parameters.
    Jonathan

  • How to see the abap code in sql language.

    hello gurus,
      very simply put,i dont know sql,but have to write some basic select queries to talk to oracle db...
    i would like to see the SQL transaltion of the ABAP code which i cant write.
    for eg: SELECT SINGLE * FROM MARA WHERE MATNR = 'XXXX'.
    How wud u write this on ORACLE.
    i would also like to see for all entries etc...
    NOW,i have tries st05..it doesnt give meaningful sql..
    pls help

    hai
    i wrote this in se38
    report zdsd.
    data wmatnr type mara.
    select single * from mara into wmatnr where matnr = '0001'.
    write wmatnr.
    _from st05_
           41 PROGDIR    REOPEN      0      0 SELECT WHERE "NAME" = 'ZTEST123' AND "STATE" = 'A'
        1,182 PROGDIR    FETCH       1      0
            4 DWINACTIV  REOPEN      0      0 SELECT WHERE "OBJECT" = 'REPS' AND "OBJ_NAME" = 'ZTEST123'
          592 DWINACTIV  FETCH       0   1403
            8 MARA       REOPEN      0      0 SELECT WHERE "MANDT" = '001' AND "MATNR" = '0001'
        9,388 MARA       FETCH       1      0
    i would like
    select matnr
    into :vi_matnr
    from PPS_SUB_BDZ.lm1_lagerpl
    where matnr = '0001'
    basicaly i need to work on new database (NON SAP) by making connections..
    i write the code in FM's in ABAP.
    I write Select queries between EXEC SQL. and
    ENDEXEC.
    I have to use SELECT SINGLE...FOR ALL ENTRIES ...counterparts now...

  • Read data from SharePoint using ABAP sql command

    We need to read data from a SharePoint site and update the sap object services with the information. There is a lot of information on how to put data into Sharepoint from SAP, but we need to get data from SharePoint and put it into SAP. Is it possible to retrieve data from SharePoint using sql command in ABAP program? If it is possible, what do we need to do to have SAP recognize where to get the SharePoint data?
    Richard Newman

    Hi Newman,
    You can use native sql in your abap code to read data from SharePoint's database. But I would suggest you to generate a SharePoint webservice which can provide you the neccessary data so that you can consume this webservice in ABAP
    (Will be quite faster than native sql).
    Regards,
    Ozcan.

  • UTL_HTTP, different error codes: APEX SQL Commands vs. Oracle SQL Developer

    Hi, omniscient all!
    I have a code sample where I try to request some URL from an inactive server:
    declare
      l_text varchar2(32000);
    begin
      l_text := utl_http.request('http://inactive.url:7777');
    exception
      when others then
        declare
          l_errcode number := utl_http.get_detailed_sqlcode;
        begin
          dbms_output.put_line(l_errcode);
          dbms_output.put_line(sqlerrm(l_errcode));
        end;
    end;
    /When I run it in Oracle SQL Developer it shows:
    anonymous block completed
    -12541
    ORA-12541: TNS:no listenerWhen I run it in the APEX 4.0 SQL Commands window it shows:
    -29263
    ORA-29263: HTTP protocol error
    Statement processed.The question is: why?
    In real world, I need to make a HTTP POST request (no problem) and catch some exceptions. But instead of the usual ORA-12541 error APEX throws an ORA-29261 one.

    Any thoughts?

  • SQ01 DIsplay Problem (Can v write abap code ) Sql Query

    Hi
    Need help in SQL Query
    I generated one sql query which has the following output in general .
    Customer   name   description   amount
    asrq1  sharekhan      Amount payed      10
    asrq1  sharekhan     Amount Advance     20
    asrq1  sharekhan    Amount due             30
    but i need the output in the following way
    Customer  name  AMount payed     Amount  Advance                  Amount Due
    asrq1   sharekhan  10    20     30
    and iam new this sql query but came to know we can write code ..but iam unable to initiliaze to write
    a peace of code as i dont know what are the select-options defined ..i saw in the include but didnt got it
    % comes prefix of select-options,and iam unable to get he internal table which is displayed in the query .
    can anyone help me in this answers will be awarded points.

    First, I will suggest to go for ABAP report for this kinda requirement.
    If you really want to go for it through SQ01, even then you will have to write some ABAP to display the records in one row. You will need to create three custom fields.
    I will give Psudo for one field:
    Field Name := ZAmountPayed
    Select Amount_Payed into varAmountPayed from Table Where Emp# = '12345'
    ZAmountPayed := varAmountPayed
    Convert the above into relative ABAP code and create 2 more similar fields, and you should be all set.
    You have to know the table names and any other calculations to get the right data.

  • Code block works in SQL Command Processor but not in application

    Hello forum,
    Been struggling with this for a few days without success:
    I have a form with a popup LOV called P6_POPUP, a file browse item called P6_BROWSE, a SUBMIT button, and a Process with the following code:
    declare
    q_image_id number;
    begin
    select host_family_photos_seq.nextval into q_image_id from dual;
    insert into host_family_photos (image_id, file_object_id, image_name)
    select q_image_id, id, filename
    from htmldb_application_files where filename = :P6_BROWSE;
    update host_family set image_id = q_image_id where family_name = :P6_POPUP;
    end;
    The Process Point is set to On Submit after Computations and Validations and When Button Pressed is set to the Submit button.
    When I run the page the file is imported into HTMLDB_APPLICATION_FILES
    but the insert and update do not occur.
    The URL header after submitting is as follows:
    http://127.0.0.1:8080/apex/f?p=115:1:480837828458787::NO:::&success_msg=Photo%20Imported%2FB87C5A54684B0DF005D09D0DFE6E98D6%2F
    However if I run the above code in the APEX SQL Command window and supply the required variables it works every time - most confusing.
    Not sure what to try from here.
    thanks for your time,
    Brett

    Scott:
    I always thought that the File Browse item maps to the NAME column in the view (below) and that is guaranteed to be unique. The NAME column seems to have a system-generated "F1234" id embedded in it (to guarantee uniqueness, I thought).
    In other words, when we put a File Browse item on the page, submitting the page uploads the file into the HTMLDB_APPLICATION_FILES table and the way to access that record (to copy/move it into our own custom table) is by doing
    from htmldb_application_files
    where name = :P1_BROWSEThanks
    SQL> desc htmldb_application_files
    Name                                      Null?    Type
    ID                                        NOT NULL NUMBER
    FLOW_ID                                   NOT NULL NUMBER
    NAME                                      NOT NULL VARCHAR2(90)
    FILENAME                                           VARCHAR2(400)
    TITLE                                              VARCHAR2(255)
    MIME_TYPE                                          VARCHAR2(48)
    DOC_SIZE                                           NUMBER
    DAD_CHARSET                                        VARCHAR2(128)
    CREATED_BY                                         VARCHAR2(255)
    CREATED_ON                                         DATE
    UPDATED_BY                                         VARCHAR2(255)
    UPDATED_ON                                         DATE
    LAST_UPDATED                                       DATE
    CONTENT_TYPE                                       VARCHAR2(128)
    BLOB_CONTENT                                       BLOB
    LANGUAGE                                           VARCHAR2(30)
    DESCRIPTION                                        VARCHAR2(4000)
    FILE_TYPE                                          VARCHAR2(255)
    FILE_CHARSET                                       VARCHAR2(128)

  • SQL Command code for multiple value string parameter

    Hi,
    I'm using crystal 2008 and there is a check box for multiple value  SQL Command  I need some help in writing the SQL Command code  for oracle (or sql server) for a multiple value STRING  parameter.
    Thanks in advance,
    Marilyn

    I could be wrong here, but I do not believe you can pass a multiple valued parameter to an SQL Command data source.  How I have gotten around this in the past is to put the "real" report into a subreport.  In the main report, create a formula field (basic syntax):
    formula = join({?parameter}, "|")
    Then, use this to pass the selected values to the subreport's parameter (call it {?sr-parm}).  The SQL Command in the subreport can then use that (MS SQL):
    select *
    from table
    where charindex(table.field, '{?sr-parm}') > 0
    HTH,
    Carl

  • Is it possible to write an abap code be SAP SQL query.(ECC 6)

    hello guys,
    Is it possible to write an abap code be SAP SQL query.
    Scenario : table A has a field say f1 of length 10 and table B has a field say s1 of lenght 20. in sap sql i am able to link all the other tables but i am not able to link
    table Af1 --->Table Bs1. as the length doesnot match. so is it possibel that using abap code I can pick 10 characters from table A field f1 adjust it to 20 characters using abap and map it to field s1 of table B.
    Please let me know how to accomplish this if possible.
    thanks in advance!!

    Herm,
    Adding code is done in the infoset.
    Please do following:
    > Goto SQ02
    > Type in the infoset that the basis for your query, <change>
    > Press <code> OR <shift><f8>
    > Tou'll see 4 tabs: Extras, Selections, Code, Enhancements.
    > GoTo tab Code
    > Choose the coding section (<f4> gives you an overview)
    > Enter the code.
    You may set a breakpoint to see what the query in SQ01 will do with it.
    Succes!
    Frank

  • Data Conversion or Sql Command

    We are importing mdb data to SQL Server and require data type casting. Which is better to use and gives better performance?
    - Data Conversion
    - SQL Command (with casting)
    Thanks,
    Darren

    Using the sql cast will give you a performance benefit over using the data conversion transformation.  We should probably shelve the transformation unless if we are in a situation where we can’t return the data with the type we would like for the destination
    (ex. flat files or stored procedures).
    Check this short and sweet article :
    here
    If this post answers your query, please click "Mark As Answer" or "Vote as Helpful".

  • Modify SQL command from code

    Edit SQL command from code for example from delphi.

    Yes and No
    See [Rules of Engagement|Welcome and Rules of Engagement;

  • Drop triggers in code causes SQL command not properly ended.

    running the following command in SQL developer giving the following error
    ORA-00933: SQL command not properly ended.
    What am I doing wrong
    Begin 
    For I In (Select Trigger_Name, Owner From Dba_Triggers Where Trigger_Name Like 'ABC%' And Owner = 'my_schema')
      Loop 
        Execute Immediate 'DROP TRIGGER '||I.Owner||'.'||I.Trigger_Name; 
      End Loop; 
    End;Edited by: Mo2 on Apr 16, 2010 12:21 PM
    Edited by: Mo2 on Apr 16, 2010 12:24 PM

    Mo2 wrote:
    yes it has.
    an example of the names is BIN$+i6ls2WnR/Svz0wA5LSG8A==$0
    As a matter of fact those triggers get created by the database after I drop the tables. is there a way to avoid creating them?
    drop trigger BIN$+i6ls2WnR/Svz0wA5LSG8A==$0;
    drop trigger BIN$+i6ls2WnR/Svz0wA5LSG8A==$0
    ERROR at line 1:
    ORA-00933: SQL command not properly endedYes oracle complains about this while dropping it.
    These objects get created if you have recyclebin on.
    You can either off your recyclebin or you can purge these objects from recyclebin after dropping it. Make sure that you would not require this feature or objects in future.
    Regards
    Anurag

Maybe you are looking for

  • Need help in HR-ABAP programming stuff

    Hi Alls I have been assigned to work in HR-ABAP.I have gud exp in normal ABAP but i am totally new for hr-abap.Could please help to me as u guys are helping to others. What are teh basic things i need to know , so  i can start working.. Please send m

  • File transfers not working

    my file transfers have suddenly stopped working, they start and crap out around a quarter of the way through. the majority of people that im talking to are not on ichat but aim on windows. what can i do, and if i have to delete and re install how do

  • Transporting a Structure: Sending & Receiving Systems Don't Match?

    I copied a Z1 structure to a Z5 structure in system A(sending system). Because System B(receiving system) already had a similar structure Z1 I did not want to overwrite. The only difference between both Z1s in system A and system B were some include

  • 2 iPads in close proximity?

    I am visiting my dad. He has a 3G iPad and I have a wifi only iPad. My iPad is working fine - my dads seems to have stopped connecting to servers, no connection, and is behaving strangely. They are both 1 week old iPads and so are updated with latest

  • Database error. The database error is: (CS) WIS 10901

    Hi guys i am using SAP BusinessObjects Edge BI 3.1 and created one report using webi, saved and exported to CMS when i opened it in Infoview it works fine but when i refresh it then i am getting below mentioned error:- Refreshing a document in Web In