How to construct Dynamic Join in ABAP?

Hello ALL,
I am typically faced with a situvation where in I need to write a dynamic JOIN SQL statement in ABAP.
For example :
REPORT ZTEST .
PARAMETERS: TBLNAME(50) DEFAULT 'SPFLI'.
DATA: TOTAL_ROWS TYPE P.
SELECT COUNT(*) FROM (TBLNAME) INTO TOTAL_ROWS.
WRITE: / TBLNAME, TOTAL_ROWS.
In the above example, here the fetch from Table is dynamic.
Where as if i have to conisder the following SQL statement which is a normal JOIN statement in ABAP,
select
  mara~matnr
  marc~werks
  from mara
  join marc on maramatnr = marcmatnr
  into table it_join
  where mara~mtart = 'FERT' and
        marc~werks = '3000'.
How do i convert this into DYNAMIC JOIN STATEMENT</b> .
Looking forward to your responses.
Thank you

Hi,
This is from the ABAP keyword help in 6.40, not sure if it works in previous releases or not.
Example
Dynamic specification of the inner joins. The column specification after SELECT is also dynamic.
PARAMETERS: p_cityfr TYPE spfli-cityfrom,
            p_cityto TYPE spfli-cityto.
DATA: BEGIN OF wa,
         fldate TYPE sflight-fldate,
         carrname TYPE scarr-carrname,
         connid   TYPE spfli-connid,
       END OF wa.
DATA itab LIKE SORTED TABLE OF wa
               WITH UNIQUE KEY fldate carrname connid.
DATA: column_syntax TYPE string,
      dbtab_syntax TYPE string.
column_syntax = `ccarrname pconnid f~fldate`.
dbtab_syntax = `( ( scarr AS c `
  & ` INNER JOIN spfli AS p ON pcarrid  = ccarrid`
  & ` AND p~cityfrom = p_cityfr`
  & ` AND p~cityto   = p_cityto )`
  & ` INNER JOIN sflight AS f ON fcarrid = pcarrid `
  & ` AND fconnid = pconnid )`.
SELECT (column_syntax)
       FROM (dbtab_syntax)
       INTO CORRESPONDING FIELDS OF TABLE itab.
LOOP AT itab INTO wa.
  WRITE: / wa-fldate, wa-carrname, wa-connid.
ENDLOOP.
Regards
Vilmos

Similar Messages

  • How to create dynamic parameters in ABAP report?

    Hello all,
    Kindly please help with one query asap.
    Actually i have one table in which two fields are there. One is Student name and another is age. Now i will create a report with two input parameters.
    My first parameter will be student name and second will be age. Here i will put only name of the student and while executing i want in second parameter the age of that student will come dynamically.
    So please let me know asap. will be thankful to you.

    hi,
    i am failing to see relevance of this post in WebDynpro for ABAP forum.  Requesting moderator to move to ABAP general forum.

  • How to use Dynamic SQL in ABAP

    If I have mara table and I have an selection screen where I have allowed user to select the fields of MARA,Now What I want is depending on his selection we should be able to execute the sql command.
    E.g.
    Tables: mara.
    selection-screen
    MATNR , ERSDA , ERNAM , MTART , MEINS.
    NOW THE OUTPUT SHOULD BE ABLE TO DISPLAY ONLY THE SELECTED FIELD VALUE.

    Hello Nandan,
    Try the following code. It works.
    tables: mara.
    data: tablename  type tabname,
          fname      type fieldname,
          fieldnames type fieldname occurs 0.
    field-symbols : <fs_tableline> type any,
                    <fs_fieldval>  type any.
    initialization.
      tablename = 'MARA'.
      assign (tablename) to <fs_tableline> .
      fname = 'MATNR'.
      append fname to fieldnames.
      fname = 'MTART'.
      append fname to fieldnames.
    select (fieldnames)
      from (tablename)
      up to 20 rows
      into corresponding fields of <fs_tableline>.
      loop at fieldnames into fname.
        assign component fname of structure <fs_tableline> to <fs_fieldval>.
        write : <fs_fieldval>.
      endloop.
      new-line.
    endselect.
    The <b>tables</b> statement is very important. You should at least have the list of the tables which you expect the user to enter.
    Please do get back if you have any doubts. If you think the question is answered, please reward the points to the useful answers and close the thread.
    Regards,
    Anand Mandalika.

  • How to add Image dynamically in Webdynpro ABAP

    Hi Experts,
    How to add Image dynamically in Webdynpro ABAP.
    My requirement is i maintain all the images in a table.
    image source has to pick the table URl dynamically and display.
    is that possible in webdynpro?
    and also please give the suggesion,
    without using MIME objects is that anyway to get images?
    Thanks in advance.
    Regrads,
    Jeyanthi

    Hi,
      are those icons wou want to display then. he following code will be useful.
    data : lo_IMG type ref to CL_WD_IMAGE.
    LO_IMG = cl_wd_IMAGE=>new_IMAGE( id = img_id SOURCE = 'ICON_BW_APD_TARGET' tooltip = sts_tltp ).
    lo_cont->add_child( the_child = lo_img ).
    here lo_cont is the container where you want to add the image dynamically and source is the attribiute through which you can change the ICON image. this thing you can getit from data base table and change accordingly.
    Regards,
    Anil kumar G

  • [How-to] Evaluate dynamically an ABAP Constant

    Hello,
    Do you know how I can dynamically/programatically retrieve the value of a defined constant in an ABAP Class having the name of the Constant.
    I tried using the CLASSDESCR of the class to retrieve all attributes of type "constant", but I am not able to get the constant-value.
    Thanks for your help,
    Laurent

    Laurent Chavanis wrote:
    Hello,
    >
    > Do you know how I can dynamically/programatically retrieve the value of a defined constant in an ABAP Class having the name of the Constant.
    >
    > I tried using the CLASSDESCR of the class to retrieve all attributes of type "constant", but I am not able to get the constant-value.
    >
    > Thanks for your help,
    > Laurent
    Seems you are trying to do something like this, not sure though
    DATA:
      lv_const_name TYPE char30 VALUE 'ALIGN_AT_BOTTOM'.
    FIELD-SYMBOLS:
    <fs_cons_value> TYPE ANY.
    ASSIGN cl_gui_calendar=>(lv_const_name) TO <fs_cons_value>.
    IF sy-subrc IS INITIAL.
      WRITE :<fs_cons_value>.
    ENDIF.
    You can only access constants defined as 'Public' using the above technique.
    -Rajesh.

  • What is a dynamic join in SAP HANA?

    What is a dynamic join in SAP HANA and how it works? Please explain me with the example , how to use it?
    Message was edited by: Tom Flanagan

    Hi Sree,
    In very simple and basic terms:
    If you have table A and B with columns C1, C2, and C3 used in multi-column join (with Dynamic join set to true) from both the tables, then depending upon which columns you select in the query, ONLY those columns will be used in the join.
    For ex. if you select C1, C2 in the select statement, then the join will happen only on C1 and C2, C3 will not be used in the join criteria, even if the join definition involves all the 3 columns.
    Regards,
    Ravi

  • Dynamic configuration in ABAP Mapping

    Dear All,
    I have requirement to use the filename's name in the mapping to the target message.
    e.g: Filename is Victor.303, i need to take this 303 and map it to the target message.
    I understand i can get that value using dynamic configuration in Adapter-Specific Attributes.
    But all the samples are using Java code used in UDF.
    How to do the same in ABAP Mapping?
    I tried:
       record =  dynamic_configuration->get_record( namespace = 'http://sap.com/xi/XI/System/File'
                                                        name = 'FileName').
    But record-value return blank.
    Best Regards,
    Victor.

    Dear Prateek,
    I changed my code with:
      DATA: record TYPE mpp_dynamic.
      CALL METHOD dynamic_configuration->get_record
        EXPORTING
          namespace = 'http://sap.com/xi/XI/System/File'
          name      = 'FileName'
        RECEIVING
          record    = record.
    but record-value still return as blank.
    I have doubt in this, do i need to populate the FileName in the dynamic configuration (in the graphical mapping) first before i can get the value in the ABAP mapping? or System should filled it and i just can use it directly in the ABAP mapping?
    How we know what is the available name and namespace in that dynamic configuration-->get record??
    (e.g: my case is FileName, and in the link that you gave is ERROR.)
    Any link for this?
    Best Regards,
    Victor.

  • How to create dynamic context based on a structure defined in the program?

    Hi Experts,
             I need to create a dynamic context based on a structure wa_struc which i have define programatically.
    When I pass wa_struc to structure_name parameter of create_nodeinfo_from_struc, i get a runtime error:
    "Parameter STRUCTURE_NAME contains an invalid value wa_struc."
    How to create dynamic context based on a structure defined in the program?
    I have written the code like this:
    TYPES: BEGIN OF t_type,
                v_carrid TYPE sflight-carrid,
                v_connid TYPE sflight-connid,
             END OF t_type.
      Data:  i_struc type table of t_type,
             wa_struc type t_type.
      data: dyn_node   type ref to if_wd_context_node.
      data: rootnode_info   type ref to if_wd_context_node_info.
      rootnode_info = wd_context->get_node_info( ).
      clear i_struc. refresh i_struc.
      select carrid connid into corresponding fields of table i_struc from sflight where carrid = 'AA'.
    cl_wd_dynamic_tool=>create_nodeinfo_from_struct(
      parent_info = rootnode_info
      node_name = 'dynflight'
      structure_name = 'wa_struc'
      is_multiple = abap_true ).
    dyn_node = wd_context->get_child_node( name = 'dynflight' ).
    dyn_node->bind_table( i_struc ).
    Thanks
    Gopal
    Message was edited by: gopalkrishna baliga

    Hi Michelle,
              First of all Special thanks for your informative answers to my other forum questions. I really appreciate your help.
    Coming back to this question I am still waiting for an answer. Please help. Note that my structure is not in a dictionary.
    I am trying to create a new node. That is
    CONTEXT
    - DYNFLIGHT
    CARRID
    CONNID
    As you see above I am trying to create 'DYNFLIGHT' along with the 2 attributes which are inside this node. The structure of the node that is, no.of attributes may vary based on some condition. Thats why I am trying to create a node dynamically.
    Also I cannot define the structure in the ABAP dictionary because it changes based on condition
    I have updated my code like the following and I am getting error:
    TYPES: BEGIN OF t_type,
    CARRID TYPE sflight-carrid,
    CONNID TYPE sflight-connid,
    END OF t_type.
    Data: i_struc type table of t_type,
    dyn_node type ref to if_wd_context_node,
    rootnode_info type ref to if_wd_context_node_info,
    i_node_att type wdr_context_attr_info_map,
    wa_node_att type line of wdr_context_attr_info_map.
    wa_node_att-name = 'CARRID'.
    wa_node_att-TYPE_NAME = 'SFLIGHT-CARRID'.
    insert wa_node_att into table i_node_att.
    wa_node_att-name = 'CONNID'.
    wa_node_att-TYPE_NAME = 'SFLIGHT-CONNID'.
    insert wa_node_att into table i_node_att.
    clear i_struc. refresh i_struc.
    select carrid connid into corresponding fields of table i_struc from sflight where carrid = 'AA'.
    rootnode_info = wd_context->get_node_info( ).
    rootnode_info->add_new_child_node( name = 'DYNFLIGHT'
    attributes = i_node_att
    is_multiple = abap_true ).
    dyn_node = wd_context->get_child_node( 'DYNFLIGHT' ).
    dyn_node->bind_table( i_struc ).
    l_ref_interfacecontroller->set_data( dyn_node ).
    But now I am getting the following error :
    The following error text was processed in the system PET : Line types of an internal table and a work area not compatible.
    The error occurred on the application server FMSAP995_PET_02 and in the work process 0 .
    The termination type was: RABAX_STATE
    The ABAP call stack was:
    Method: IF_WD_CONTEXT_NODE~GET_STATIC_ATTRIBUTES_TABLE of program CL_WDR_CONTEXT_NODE_VAL=======CP
    Method: GET_REF_TO_TABLE of program CL_SALV_WD_DATA_TABLE=========CP
    Method: EXECUTE of program CL_SALV_WD_SERVICE_MANAGER====CP
    Method: APPLY_SERVICES of program CL_SALV_BS_RESULT_DATA_TABLE==CP
    Method: REFRESH of program CL_SALV_BS_RESULT_DATA_TABLE==CP
    Method: IF_SALV_WD_COMP_TABLE_DATA~MAP_FROM_SOURCE_DATA of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_COMP_TABLE_DATA~MAP_FROM_SOURCE of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_COMP_TABLE_DATA~UPDATE of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_VIEW~MODIFY of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_COMPONENT~VIEW_MODIFY of program CL_SALV_WD_A_COMPONENT========CP
    -Gopal
    Message was edited by: gopalkrishna baliga

  • How to include dynamic action in bdc

    Hi All,
    I want to update infotype 17 when an employee has joined through PA40 (Joining action).So i have written a dynamic action for this .But this dynamic ation does not get called in bdc for joining action.
    So infotype 17 is not maintained if we do joining through bdc.
    I have tried with user-exit zxpadu02 also, calling hr_infotype_operation on saving infotype 0001.But it gives return as 'Employee does not exist'.
    Since that infotype 0001 is still not saved.
    So what to do.
    Yogesh

    Hi Amit,
    For your information we can call dynamic action from BDC.
    go through this link
    how to include dynamic actions in bdc

  • Reg dynamic actions in abap-hr

    Hi Gurus ,
    What is dynamic actions in abap-hr ,can any body explains it
    with an example ...
    Thanks & Regards
    Suman

    hi dynamic actions changes or create the infotype record on maintainance  of another infotype.
    like after hiring a person if u want to default joining date in 0041 infotype.
    then u will check molga.
    p too1p-molga=40
    p is used to check conditions.
    then u will insert the records in 0041
    i ins,0041,,,(p0000-begda),(p0000-endda)/d
    /d is for processing in background.
    then u will default values in 0000
    w p0041-dar01 = 'hd'
    w p0041-dat01 = p0000-begda.
    w is for defaulting value.
    go to spro-personnel management - personnel administration-customizing procedures-dynamic action .
    here u have documentation.

  • About inner join in abap

    hi
        i am new to sap , i dont no about inner join in abap coding
    plz send me some notes or coding.
                            thank u.
                                                              your regrads
                                                                    divya.

    hi
    use this links
    INNER JOIN  and OUTER JOINhttp://help.sap.com/erp2005_ehp_03/helpdata/EN/cf/21ec77446011d189700000e8322d00/frameset.htm
    JOINED TABLES
    http://help.sap.com/erp2005_ehp_03/helpdata/EN/0f/49bd6a5d5049edba7b3afe6c7956e3/frameset.htm
    u will find all thins related to joins with example and how to use it
    Cheers
    Snehi
    Edited by: snehi chouhan on Jul 25, 2008 9:45 AM

  • Self join using ABAP Query

    Hello all,
    How to create a self join using ABAP Query?
    Say, I have this table EKBE with belnr (materials doc num) and lfbnr (reference material doc num). I have to pick the PO's from EKBE whose belnr doesnt have any lfbnr.
    Regards
    Madhumathi A

    hi madhu,
    tables : ekbe.
    data itab like standard table of ekbe with header line.
    select * from ekbe into table itab where belnr >< 0 and lfbnr = ' '.
    loop at itab.
    write :/ itab-belnr,itab-lfbnr.
    endloop.
    check this code this works to select the orders whose belnr doesnt have any lfbnr
    reward points if useful.

  • SUBQUERY with INNER JOIN in ABAP

    Hi Expert
    How Can I write SUBQUERY with INNER JOIN in ABAP.
    thanks

    Thanks Sidhharth for your Respose
    Actually I need data from VBAP, VBAK, VBUP, VBUK and VBKD with all functional validation satisfied for a sales order item data. The requirement is to report all item data with other information from table VBAK, VBUP, VBUK and VBKD in a corresponding record with ALL data in VBAP.
    Your help is appriciated.
    see the below query for reference
    select   alias_vbap~vbeln from  vbap as
    alias_vbap inner join vbak as alias_vbak
    on  alias_vbapvbeln eq  alias_vbakvbeln
    "and  alias_vbak~bukrs_vf eq '2400'
    inner join vbuk as alias_vbuk
    on alias_vbukvbeln = alias_vbapvbeln
    inner join vbup as alias_vbup
    on alias_vbupvbeln = alias_vbapvbeln
    and alias_vbupposnr = alias_vbapposnr
    left OUTER join veda as alias_veda
    on alias_vedavbeln = alias_vbapvbeln
    and alias_vedavposn = alias_vbapposnr
    left outer join vbkd as alias_vbkd
    on alias_vbkdvbeln = alias_vbapvbeln
    and alias_vbkdposnr = alias_vbapposnr

  • Inner join in ABAP and exporting the data

    Hi,
    I want to use inner join in ABAP for retrieving data from 2 tables and export that data.How will i do it?

    Hi,
    Refer following code
    *--Select query to pick the data from table VBRK
    VBRP and VBPA using inner join
      SELECT a~vbeln                            "Billing document
             a~fkdat                            "Billing date
             a~fktyp                            "Billing category
             a~fkart                            "Billing type
             a~vtweg                            "Distribution channel
             a~knumv                            "Number of doc condition
             b~posnr                            "Billing item
             b~matnr                            "Material Number
             b~werks                            "Plant
             b~vgbel                            "Referance
             b~netwr                            "Net value of billing item
             b~wavwr                            "Cost in document currency
             c~kunnr                            "Partner function
             FROM vbrk AS a
             INNER JOIN vbrp AS b
             ON avbeln EQ bvbeln
             INNER JOIN vbpa AS c
             ON  bvbeln EQ cvbeln
            AND bposnr EQ cposnr
             INTO CORRESPONDING FIELDS OF TABLE it_vbrp
             WHERE fkdat IN s_erdat
             AND   parvw EQ 'ZS'.
      IF sy-subrc EQ 0.
    *--Sort table by
        SORT it_vbrp BY vgbel1.
      ENDIF.
    Regards,
    Prashant

  • How to create dynamic strcture and accepting runtime value in work area

    Hi,
    I am using RFC_READ_TABLE for  joining more than table  and written select query but  into clause work area value is passed but it is short dump is displaying with too few many fields  in into clause .work area WA need some casting type conversion which accepts the some run time value  and should have some structure  for it.how to create dynamic structure?

    hi
    good
    go through this and use in your report accordingly.
    If you are trying to read some information from SAP and you can't find the right BAPI then RFC_READ_TABLE can do the job for you.
    RFC_READ_TABLE is powerful RFC it gives you the access to all tables and views in SAP. I basically used RFC_READ_TABLE for Material Master Search application on the Intranet.
    Now you may say there are lots of BAPI for this functionality. You are right but I had to work around the BAPI to get Prices (Moving Average Price) and it just did not work very well. Because of the nature of the application I had to use RFC_READ_TABLE because then I can use powerful SQL expression for searching. RFC_READ_TABLE give you the ability to code the where clause which is quite enough.
    I have included part of the code use in asp page to read ENT1027 for Mgroup and M description & number but without object creation. The other part of the code reads MBEW for price & quantity.
    Code
    lt;%
    '#######################Diming the Structures
    Call BAPIRFC.DimAs("Rfc_Read_Table", "FIELDS", MaterialSelection_RS)
    Call BAPIRFC.DimAs("Rfc_Read_Table", "OPTIONS", Selection_RS)
    '########################Search Type########################
    ' C contanis
    ' S Start with
    ' E Ends with
    if searchtype = "C" then
    FormatedSearch_Keyword = "%" & Search_Keyword & "%"
    elseif searchtype = "S" then
    FormatedSearch_Keyword = Search_Keyword & "%"
    else searchtype = "E" then
    FormatedSearch_Keyword = "%" & Search_Keyword
    end if
    '################# Flaged for deletion Materials #####################
    if showdeleted = "No"  then
    Selection_RS.AddNew Array("TEXT"),Array("LVORM <> 'X' AND")
    end if
    '############## users can search three material group ################
    '############## GROUPS: OFFICESUP TECOMHARD TECOMSOFT ###############
    '##USER STILL CAN NAROW THEIR SEARCH BY SELECTING ON OF THREE#########
    if MGroup = "ALL"  then
    Selection_RS.AddNew Array("TEXT"),Array("MATKL IN ('OFFICESUP','TECOMHARD','TECOMSOFT')")
    else
    Selection_RS.AddNew Array("TEXT"),Array("MATKL = '"& MGroup &"' and ")
    end if
    '#######################ADDING SEARCH KEYWORD TO STRUCTURE##############
    if not  Search_Keyword = "" then
    Selection_RS.AddNew Array("TEXT"),Array(" MAKTG LIKE '" & FormatedSearch_Keyword &  "'")
    end if
    Selection_RS.Update
    '#######################ADD RETURNED FIELDS#########################
    MaterialSelection_RS.AddNew array("FIELDNAME","OFFSET","LENGTH","TYPE","FIELDTEXT"),array("MATNR","000000","000000" ,"","")
    MaterialSelection_RS.AddNew array("FIELDNAME","OFFSET","LENGTH","TYPE","FIELDTEXT"),array("MATKL","000000","000000" ,"","")
    MaterialSelection_RS.AddNew array("FIELDNAME","OFFSET","LENGTH","TYPE","FIELDTEXT"),array("MAKTG","000000","000000" ,"","")
    MaterialSelection_RS.Update
    call BAPIRFC.Rfc_Read_Table("ENT1027", Material_RS, MaterialSelection_RS, Selection_RS, "~", "", "0", "0")
    If Err.Number > 0 then
                   Response.Write "Error:" & "<BR>"
                   Response.Write "   Err.number...... " & Err.Number & "<BR>"
                   Response.Write "   Err.Description. " & Err.Description & "<BR>"
    end if
    '###########LOOP THROUGH RECORDSET
    if not Material_RS is nothing then
    do while not Material_RS.eof
    loop
    end if
    %>
    thanks
    mrutyun^

Maybe you are looking for

  • 13" mac book pro power supply weight?

    What does a 13" mac book pro power supply weigh

  • Random spacing between contents page sub headers (CS2, WINXPSP2)

    Hi, I'm a new user to Adobe Indesign CS2. I was creating a table of contents when I encountered this unusual problem. Here is a sample of what happens below: 2. System 2.4 system components 2.4.1 Intelligence Manager features........... 9 2.4.2 Video

  • Field Reference

    Dear All, Scenario: I Have 11 Plants now I need to set Field reference for Material Type FERT on 6 Plants in which Batch Management Indicator is a REQUIRED FIELD & in rest of the plants its an optional field. Can i create Field reference at plant lev

  • Droid X Unrecognized by V Cast Media Manager

    Hi, I got my Droid X 4 days ago, and decided today to put some of my music and videos on it so I downloaded V Cast Media Manager to my computer.  Unfortunately, although my computer and my phone acknowledge that there is a USB connection, V Cast does

  • Trial Photoshop did not download

    Adobe Download Assistant downloaded, but trial Photoshop did not download...Now what?