Skip to Content
0
Former Member
May 21, 2010 at 12:36 PM

Select Query

104 Views

Hi all,

After spending some hours I wrote a query which is needed for my project.There are some problems in the query and Iam not 100 % sure wheather it will work.Thats why the post here.(some of the field names wont be exactly right)

FORM BOM_Test.
data: lv_cdpos_cond type string.     
lv_cdpos_cond = 'cdpos~feldname = '.
concatenate lv_cdpos_cond  'Fmenge'
'and cdpos~chngid = ' 'I'
'OR cdpos~chngid = '  'U'
  'OR cdpos~chngid = ' 'D'
  'and cdpos~tabname = ' 'stpos' INTO lv_cdpos_cond SEPARATED BY space.
  select cdhdr~username cdhdr~udate cdpos~changeid cdpos~valuenew
         cdpos~valueold cdpos~tabname cdpos~feldname stpos~stlr
         stpos~stlr stpos~position stpos~component mast~material
          mara~mattxt into CORRESPONDING FIELDS OF TABLE gt_ditab
         from cdhdr
         INNER JOIN cdpos on cdhdr~OBJECTCLAS = cdpos~OBJECTCLAS
          and cdhdr~changenr = cdpos~changenr
        INNER JOIN stpos on cdpos~tabkey = stpos~(
            mandt+bomtype+bom+nodetype+counter)
        INNER join mast on stpos~stlnr = mast~stlnr
        INNER JOIN mara on mast~matnr = mara~matnr
        where cdhdr~objectclas = 'stue'
        and cdhdr~udate in so_date
        and lv_cdpos_cond and lv_stpos_cond
        and mast~matnr in so_matrange
        and mara-matnr = mast~matnr.
Endform.

I have to select some data from 5 different tables(CDHDR,CDPOS,stpos.mast and mara). As Iam trying it on a test machine from home.Anyway its still not a compilable select query as there are still some holes to plug in.The purpose of this query is to get the changed BOM data.Iam using 1 string in my Select query lv_cdpos_cond to make the query readable. But the strings inside the strings like 'I','U' or 'D' is not concateneted as a string.How could it be done .Also will the "OR " condition in the string lv_cdpos_cond work(if it is used directly in the select query) in the sql query.

The innerJoin " INNER JOIN stpos on cdpostabkey = stpos( mandtbomtypebomnodetypecounter)" :Here the cdpos~tabkey is a concateneted value from the fields(mandtbomtypebomnodetypecounter) in stpos. how to make a join condition here.

Will this query work :).Will it be a performant query.Would be nice if some one could post a edited query if there are problems in my the query.(spend 2 hrs to write this,Thats why 😊)

Thanks kOH

Edited by: Kohinoor72 on May 21, 2010 2:47 PM