Query regarding inner join

Hi
Can anyone explain me the error in this select query and give me the correct answer.
select 1begda 1endda 2kostl 2persg 2anvsh 3pernr into
corresponding fields of table i_emp from
( ( pa0000 as 1 innerjoin pa0001 as 2 on 1pernr = 2pernr )
join pa0003 as 3 on 3pernr = pa0002pernr )
for all entries in pa0002
where 2~pernr = pa0002-pernr.
Requirement is :
retreive data from 4 tables :PA0000,PA0001,PA0002,PA0003 based on pernr field.
From PA0000 we need begda and endda.
From PA0001 we need kostl and persg and anvsh.
From PA0002 we need to concatenate VORNA and NACHN fieldsand put this in display_name field of i_emp.How to do this in innerjoin.
From PA0003 we need pernr field.
Structure of t_emp is:
types:begin of t_emp,
         start_date like pa0000-begda,
         end_date like pa0000-endda,
         cost_centre like pa0001-kostl,
         active_status like pa0001-persg,
         display_name(80) type c,
         perno like pa0003-pernr,
         activity_type like zpm_activity_typ-lstar,
         contract_id like pa0001-anvsh,
        end of t_emp.
data:i_emp type standard table of t_emp.
Please tell me the exact select query.The perfect one.
Points will definitely be given.This is really urgent.
Please help me.
Thanking you
chandrika.

Make use of Logical databse PNP (mention in attributes of prgram) and copy this code below ,it will work and dont forget to award me points -
*& Report  ZGILL_TEST11                                                *
REPORT  ZGILL_TEST11                   message-id rp
                             line-size 250
                             line-count 65          .
tables: pernr.
infotypes: 0000,
           0001,
           0002,
           0003.
constants: c_1(1)       type c               value '1'.
Internal Table for Output
data: begin of t_output occurs 0    ,
       pernr like pernr-pernr       ,
       name(80),
       begda like p0000-begda       ,
       endda like p0000-endda       ,
       kostl like p0001-kostl,
       persg like p0001-persg,
       ansvh like p0001-ansvh.
data: end of t_output           .
Start-of-selection.
get pernr.
  clear t_output.
Read Infotype 0
  rp-provide-from-last p0000 space pn-begda pn-endda.
  check pnp-sw-found eq c_1.
Read Infotype 1
  rp-provide-from-last p0001 space pn-begda pn-endda.
  check pnp-sw-found eq c_1.
Read Infotype 2
  rp-provide-from-last p0002 space pn-begda pn-endda.
  check pnp-sw-found eq c_1.
  rp-provide-from-last p0003 space pn-begda pn-endda.
   check pnp-sw-found eq c_1.
Gather all the required information related to the emp
  move: pernr-pernr to t_output-pernr,
        p0000-begda to t_output-begda,
        p0000-endda to t_output-endda,
        p0001-kostl to t_output-kostl,
        p0001-persg to t_output-persg,
        p0001-ansvh to t_output-ansvh.
concatenate p0002-vorna p0002-nachn  into t_output-name separated by space.
append t_output.
end-of-selection.
perform print_report.

Similar Messages

  • Regarding Inner join query

    Hi Guriji,s
    I wrote one inner join query. it is working fine. but when i exceute this query it is fetching the data only 261 movement type but but i also fetch the data movement type 201. for this plz tell me the correction in this query.
    select amatnr awerks abwart bbudat into table t_itab from mseg as a inner join mkpf as b
          on amblnr = bmblnr
             where awerks in plant and  abwart =  '261' or a~bwart = '201'
           and  btcode2 = 'mb1a' or btcode2 = 'mfbf' .
    thanks.

    Hi Sachin
    try to use like below
    select amatnr awerks abwart bbudat into table t_itab from mseg as a inner join mkpf as b
    on amblnr = bmblnr
    where awerks in plant and  ( abwart = '261' or a~bwart = '201' )
    and  ( btcode2 = 'mb1a' or btcode2 = 'mfbf' ).
    or try to fill ranges like select-options or use like
    select amatnr awerks abwart bbudat into table t_itab from mseg as a inner join mkpf as b
    on amblnr = bmblnr
    where awerks in plant and  abwart in ('261', '201')
    and btcode2 = 'mb1a' or btcode2 = 'mfbf' .
    Regards
    Praveen

  • Query with INNER joins

    Hi
    How can we optimize instead of inner joins. or any other idea to improve it.
    Thanks in advance!
    Regards,
    LKRao

    What is 'it'?
    Read {message:id=9360002} and {message:id=9360003} , and adjust your post accordingly.
    Without a query, execution plan, database version, index information, etc. etc., I wouldn't know how to be of any help here...perhaps other volunteers have a crystal ball, but I forgot mine accidentally this morning...

  • Select query for inner join

    Hi all,
    give me the query with innerjoin
    Based on the input values of Material number (MARC-MATNR) from selection screen check and get the Special Procurement type details from MARC-SOBSL and Material description details from MAKT-MAKTX.
    basha....
    Moderator message - instead of asking, you should try to write the code yourself and get back to the forum if you have a specific question.
    Edited by: Rob Burbank on Apr 19, 2009 4:46 PM

    Hi,
    Please Test the following Sample Code it is according to your requirement hope will solve out your problem,
    TABLES: marc.
    SELECt-OPTIONS somatnr for marc-matnr.
    TYPES: BEGIN OF ty_matnr,
      matnr LIKE marc-matnr,
      sobsl LIKE marc-sobsl,
      maktx LIKE makt-maktx,
      END OF ty_matnr.
    DATA: it_matnr TYPE STANDARD TABLE OF ty_matnr WITH HEADER LINE.
    SELECT marc~matnr marc~sobsl makt~maktx
      into CORRESPONDING FIELDS OF TABLE it_matnr
      from marc INNER JOIN makt on ( marc~matnr eq makt~matnr )
      WHERE marc~matnr in somatnr.
    Best Regards,
    Faisal

  • Select Query with Inner Join

    Dear Experts,
    I have writen a inner join code with MKPF and MSEG which taking too much time, while I have used index.
    Indexes are:
    MSEG
    MATNR
    WERKS
    LGORT
    BWART
    SOBKZ
    MKPF
    BUDAT
    MBLNR
    My Select Query is :
      SELECT B~MATNR
                   B~MAT_KDAUF
                   B~MAT_KDPOS
                   B~BWART
                   B~MENGE
                   B~MEINS
                   B~AUFNR
        INTO TABLE IT_MSEG
        FROM MKPF AS A
          INNER JOIN MSEG AS B
             ON AMBLNR EQ BMBLNR
            AND AMJAHR EQ BMJAHR
        WHERE A~BUDAT IN BUDAT
          AND B~MATNR IN MATNR
          AND B~WERKS IN WERKS
          AND B~LGORT IN LGORT
          AND B~BWART IN BWART.

    hi,
    you can use  for all entries  it will work faster then joins
    About it:*
    FOR ALL ENTRIES WHERE
    Syntax
    ... FOR ALL ENTRIES IN itab WHERE ... col operator itab-comp ...
    Effect
    If the addition FOR ALL ENTRIES is specified before the language element WHERE, then the components comp of the internal table itab can be used as operands when comparing with relational operators.
    The internal table itab must have a structured line type and the component comp must be compatible with the column col.
    The logical expression sql_cond of the WHERE condition can comprise various logical expressions by using AND and OR. However, if FOR ALL ENTRIES is specified, there must be at least one Comparison with a column of the internal table itab, which can be specified either statistically or dynamically (Release 6.40 and higher). In a statement with a SELECTstatement with FOR ALL ENTRIES, the addition ORDER BY can only be used with the addition PRIMARY KEY.
    The whole logical expression sql_cond is evaluated for each individual line of the internal table itab. The resulting set of the SELECT statement is the union of the resulting sets from the individual evaluations. Duplicate lines are automatically removed from the resulting set. If the internal table itab is empty, the whole WHERE statement is ignored and all lines in the database are put in the resulting set.
    Notes
    In Release 6.10 and higher, the same internal table can be specified after FOR ALL ENTRIES and after INTO.
    The addition FOR ALL ENTRIES is only possible before WHERE conditions of the SELECT statement.
    Example
    Exporting all flight data for a specified departure city. The relevant airlines and flight numbers are first put in an internal table entry_tab, which is evaluated in the WHERE condition of the subsquent SELECT statement.
    PARAMETERS p_city TYPE spfli-cityfrom.
    TYPES: BEGIN OF entry_tab_type,
             carrid TYPE spfli-carrid,
             connid TYPE spfli-connid,
           END OF entry_tab_type.
    DATA: entry_tab   TYPE TABLE OF entry_tab_type,
          sflight_tab TYPE SORTED TABLE OF sflight
                           WITH UNIQUE KEY carrid connid fldate.
    SELECT carrid connid
           FROM spfli
           INTO CORRESPONDING FIELDS OF TABLE entry_tab
           WHERE cityfrom = p_city.
    SELECT carrid connid fldate
           FROM sflight
           INTO CORRESPONDING FIELDS OF TABLE sflight_tab
           FOR ALL ENTRIES IN entry_tab
           WHERE carrid = entry_tab-carrid AND
                 connid = entry_tab-connid.
    hope it will help you
    Rahul sharma
    Edited by: RAHUL SHARMA on Sep 11, 2008 8:10 AM

  • Issue when suming the field in Select query using inner join

    Hi All,
    SELECT A~OI_SHNUM
           A~FORWAGENT        
           A~ROUTE
           A~SHTYP
           A~DTSHP_EACT
           A~/BIC/GTCLICENS
           A~/BIC/GTCADD04
           A~COMP_CODE
           SUM( C~GRS_WGT_DL )
           C~UNIT_OF_WT
      INTO TABLE I_LAYONE
      FROM ( ( /BIC/ANTCD000200 AS A
      INNER JOIN /BIC/AGSSD000700 AS B ON BOI_SHNUM = AOI_SHNUM )
      INNER JOIN /BIC/AGSSD000600 AS C ON CDELIV_NUMB = BDELIV_NUMB ).
    I need to sum the field C~GRS_WGT_DL
    While compiling it show the error given below
    The field "C~UNIT_OF_WT" from the SELECT list is is missing in the
    GROUP BY clause. is missing in the GROUP BY clause. is missing in the
    GROUP BY clause. is missing in the GROUP BY clause. is missing in the
    GROUP BY clause. is "C~UNIT_OF_W
    with regards,
    Thambe

    Hi,
    Try the following SQL statement. Hope it helps you.
    SELECT A~OI_SHNUM
    A~FORWAGENT
    A~ROUTE
    A~SHTYP
    A~DTSHP_EACT
    A~/BIC/GTCLICENS
    A~/BIC/GTCADD04
    A~COMP_CODE
    SUM( C~GRS_WGT_DL )
    C~UNIT_OF_WT
    INTO TABLE I_LAYONE
    FROM ( ( /BIC/ANTCD000200 AS A
    INNER JOIN /BIC/AGSSD000700 AS B ON BOI_SHNUM = AOI_SHNUM )
    INNER JOIN /BIC/AGSSD000600 AS C ON CDELIV_NUMB = BDELIV_NUMB )
    GROUP BY
    A~OI_SHNUM
    A~FORWAGENT
    A~ROUTE
    A~SHTYP
    A~DTSHP_EACT
    A~/BIC/GTCLICENS
    A~/BIC/GTCADD04
    A~COMP_CODE.
    Murthy.

  • Query on inner join

    Hello experts,
    i 'd like to join the tables BKPF and BSEG using the joins concept. let me know the statement for this so that i get the output as desired. USING selection screen concept as well.
    BKPF-BELNR,
    BKPF-BUKRS
    BKPF-GJAHR ( FISCAL YEAR)
    BSEG-WRBTR (VOUCHAR AMOUNT)
    BSEG-WRBTR( CREDIT )
    BSEG-WRBTR( DEBIT)
    Regards,
    CHK

    I tried using the Same, not working.
    ROB: any suggestion.
    Code:
    select *
    INTO TABLE BSEGitab
    FROM bkpf AS a
    INNER JOIN bseg AS b
    ON abelnr= bbelnr
    WHERE a~LIFNR IN Vendor
    and b~BUDAT LE Ikeydate.

  • Syntax errors in update query with inner joins and sub query.

    Below is the query:
    UPDATE sp_CFQ_Coord_Corrections 
    INNER JOIN (CFQ_Coord_Corrections 
    INNER JOIN CFQ_Referrals ON CFQ_Coord_Corrections.CorrID = CFQ_Referrals.RecID) 
    ON sp_CFQ_Coord_Corrections.ID = CFQ_Referrals.RecID 
    SET CFQ_Coord_Corrections.MatchFound = 1, 
    CFQ_Coord_Corrections.RecTblID = [CFQ_Referrals].[RecTblID], 
    sp_CFQ_Coord_Corrections.MatchFound = 1
    WHERE (((CFQ_Coord_Corrections.MatchFound)=0) 
    AND ((sp_CFQ_Coord_Corrections.MatchFound)=0) 
    AND ((CFQ_Coord_Corrections.RecImported)=1) 
    AND ((CFQ_Referrals.RecFileName)='COORDCORR_SPOINT') 
    AND ((CFQ_Referrals.RecCombKey)='No.Match') 
    AND ((sp_CFQ_Coord_Corrections.RecImported)=1));
    Error messages seen when executed:
    Msg 156, Level 15, State 1, Line 3
    Incorrect syntax near the keyword 'INNER'.
    Msg 102, Level 15, State 1, Line 10
    Incorrect syntax near 'CFQ_Coord_Corrections'.
    Please help.....

    Below is the query:
    UPDATE sp_CFQ_Coord_Corrections 
    INNER JOIN (CFQ_Coord_Corrections 
    INNER JOIN CFQ_Referrals ON CFQ_Coord_Corrections.CorrID = CFQ_Referrals.RecID) 
    ON sp_CFQ_Coord_Corrections.ID = CFQ_Referrals.RecID 
    SET CFQ_Coord_Corrections.MatchFound = 1, 
    CFQ_Coord_Corrections.RecTblID = [CFQ_Referrals].[RecTblID], 
    sp_CFQ_Coord_Corrections.MatchFound = 1
    WHERE (((CFQ_Coord_Corrections.MatchFound)=0) 
    AND ((sp_CFQ_Coord_Corrections.MatchFound)=0) 
    AND ((CFQ_Coord_Corrections.RecImported)=1) 
    AND ((CFQ_Referrals.RecFileName)='COORDCORR_SPOINT') 
    AND ((CFQ_Referrals.RecCombKey)='No.Match') 
    AND ((sp_CFQ_Coord_Corrections.RecImported)=1));
    Error messages seen when executed:
    Msg 156, Level 15, State 1, Line 3
    Incorrect syntax near the keyword 'INNER'.
    Msg 102, Level 15, State 1, Line 10
    Incorrect syntax near 'CFQ_Coord_Corrections'.
    Please help.....
    sp_CFQ_Coord_Corrections is a table and not a stored procedure.
    are these both tables "sp_CFQ_Coord_Corrections" and "CFQ_Coord_Corrections" different ??

  • Query contain inner join to external DB

    Hi every body,
    I have created a new sql query that contain inner join to external db of the production software. The query also uses parameters for filter data by date .
    I succeeded to create a qurey that will work including inner join to the external DB and parameters,
    Here is the query:
    SELECT T0.DocNum, T0.DocDate, T0.CardCode, T0.CardName, T1.ItemCode, T1.Dscription, T1.Quantity, T1.TotalSumSy, T1.LineTotal, T0.Canceled, T2.Family
       FROM  [XXX].dbo.AllItems T2
         RIGHT OUTER JOIN INV1 T1 ON T1.ItemCode=          T2.ItemPN collate SQL_Latin1_General_CP1_CI_AS
         INNER JOIN OINV T0 ON T1.DocEntry = T0.DocEntry
         INNER JOIN OITM T3 ON T1.ItemCode = T3.ItemCode
         INNER JOIN OITB T4 ON T3.ItmsGrpCod = T4.ItmsGrpCod
         INNER JOIN OCRD T5 ON T0.CardCode = T5.CardCode
         INNER JOIN OACT T6 ON T1.AcctCode = T6.AcctCode
    Where T0.DocDate BETWEEN [%0] AND [%1]
    but when I add a union statement the query does not work again.
    If I remove the parameters every thing is working fine.
    what is the problem with my query?
    Thank you all very much.

    SBO does not manage correctly variables in complicated query.  There is a note about it:
    Note 730960 - SAP Business One does not identify variables in long queries
    https://websmp130.sap-ag.de/sap/bc/bsp/spn/sapnotes/index2.htm?numm=730960
    This note describe the method to get the parameters in variables and their usage.

  • Query on Inner Joins

    Hi experts,
    I want to join the following fields balm, comh, comhr, balhdr, edidc.
    I don't have common fields comhr and balhdr.
    I have written an SQL query like this, will it work? what about performance
    Please let me know.
      select comh~msid
             comh~mscla
             comh~sedat
             comh~seuzt
             comhr~bid
             balhdr~extnumber
             balm~lognumber
             balm~msgid
             balm~msgv1
             balm~msgv2
             balm~msgv4
        into corresponding fields of
       table i_comhr
        from comh
        inner join comhr on comhmsid = comhrmsid
        inner join balhdr on comhmsid = balhdrextnumber
        inner join balm on balhdrlognumber = balmlognumber
        where comh~sedat in credatc
          and comh~seuzt in cretimc
          and comh~werk in werk
          and comh~source in source
          and comh~mscla in mscla
          and comh~errkz = errkz
          and comh~tstkz in tstkz.
    thanx,
    jeevi.

    Hi,
    Inner join can be used on matching keys only then it will display relevent data otherwise if keys are not matching it will not select the data.
    Performance wise it is not at all recommeded to join mistmatch keys.
    inseead u can do one thing , select data from comh and comhr into one itab using inner join and balhdr balm in other itab using inner join then u can read both itabs and can update data, anyway there u may need one link bet itabs that u can use for select stmt.
    Hope following program will help u ...
    Check this program,similar requirement.On click it is leading to transaction and bdc prcoess goes on.
    * INCLUDE Z48M_KB11N_MAN_POST_F01 *
    *& Form GET_DATA
    * text
    * --> p1 text
    * <-- p2 text
    FORM GET_DATA.
    DATA : L_AMOUNT LIKE EKPO-MENGE.
    DATA : LV_POSID TYPE PRPS-PSPNR.
    DATA : LV_POSID_OLD TYPE PS_POSID.
    DATA : LV_POSID_NEW TYPE PS_POSID.
    DATA : LV_EBELN TYPE EKPO-EBELN,
    LV_EBELP TYPE EKPO-EBELP,
    LV_MESG_ID(20) TYPE C,
    LV_MESG_NO(3) TYPE C.
    CLEAR : G_T_BALHDR,G_T_BALHDR_FINAL.
    REFRESH : G_T_BALHDR,G_T_BALHDR_FINAL.
    *To get the PO num,item,mesg id,mesg no and text of mesg.
    SELECT *
    FROM BALHDR
    INTO CORRESPONDING FIELDS OF TABLE G_T_BALHDR
    WHERE OBJECT EQ 'Z48MMIGO' AND
    SUBOBJECT EQ 'ZKB11N'.
    IF NOT G_T_BALHDR[] IS INITIAL.
    LOOP AT G_T_BALHDR.
    CLEAR : G_T_T100.
    REFRESH : G_T_T100.
    CLEAR : LV_EBELN,LV_EBELP,LV_MESG_ID,LV_MESG_NO.
    LV_EBELN = G_T_BALHDR-EXTNUMBER(10).
    LV_EBELP = G_T_BALHDR-EXTNUMBER+13(5).
    LV_MESG_ID = G_T_BALHDR-EXTNUMBER+19(2).
    LV_MESG_NO = G_T_BALHDR-EXTNUMBER+22(3).
    SELECT SINGLE *
    FROM T100
    INTO CORRESPONDING FIELDS OF G_T_T100
    WHERE SPRSL = SY-LANGU AND
    ARBGB = LV_MESG_ID AND
    MSGNR = LV_MESG_NO.
    IF SY-SUBRC = 0.
    G_T_BALHDR_FINAL-LOGNUM = G_T_BALHDR-LOGNUMBER.
    G_T_BALHDR_FINAL-OBJECT = G_T_BALHDR-OBJECT.
    G_T_BALHDR_FINAL-SUBOBJECT = G_T_BALHDR-SUBOBJECT.
    G_T_BALHDR_FINAL-EBELN = LV_EBELN.
    G_T_BALHDR_FINAL-EBELP = LV_EBELP.
    G_T_BALHDR_FINAL-MESG = G_T_T100-TEXT.
    APPEND G_T_BALHDR_FINAL.
    ENDIF.
    ENDLOOP.
    ENDIF.
    IF NOT G_T_BALHDR_FINAL[] IS INITIAL.
    CLEAR : G_T_EKPO.
    REFRESH : G_T_EKPO.
    *To get the amount,currency and new a/c assignment.
    SELECT A~EBELN A~LIFNR A~WAERS B~EBELP B~NETPR B~MENGE B~MEINS
    C~PS_PSP_PNR
    INTO CORRESPONDING FIELDS OF TABLE G_T_EKPO
    FROM ( EKKO AS A INNER JOIN EKPO AS B
    ON A~EBELN = B~EBELN
    INNER JOIN EKKN AS C
    ON B~EBELN = C~EBELN AND
    B~EBELP = C~EBELP )
    FOR ALL ENTRIES IN G_T_BALHDR_FINAL
    WHERE A~EBELN = G_T_BALHDR_FINAL-EBELN AND
    B~EBELP = G_T_BALHDR_FINAL-EBELP.
    ENDIF.
    IF NOT G_T_EKPO[] IS INITIAL.
    CLEAR : G_T_PO_LIFNR.
    REFRESH : G_T_PO_LIFNR.
    *To get the Cost element.
    SELECT *
    FROM Z48M_IN_PO_LIFNR
    INTO CORRESPONDING FIELDS OF TABLE G_T_PO_LIFNR
    FOR ALL ENTRIES IN G_T_EKPO
    WHERE LIFNR = G_T_EKPO-LIFNR AND
    PRJKT = 'X'.
    ENDIF.
    SORT G_T_BALHDR_FINAL BY EBELN EBELP.
    CLEAR : G_T_FINAL.
    REFRESH : G_T_FINAL.
    LOOP AT G_T_BALHDR_FINAL.
    SORT G_T_EKPO BY EBELN EBELP.
    READ TABLE G_T_EKPO WITH KEY EBELN = G_T_BALHDR_FINAL-EBELN
    EBELP = G_T_BALHDR_FINAL-EBELP
    BINARY SEARCH.
    IF SY-SUBRC = 0.
    CLEAR : L_AMOUNT.
    L_AMOUNT = G_T_EKPO-NETPR * G_T_EKPO-MENGE.
    CLEAR : LV_POSID_NEW.
    CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT'
    EXPORTING
    INPUT = G_T_EKPO-PS_PSP_PNR
    IMPORTING
    OUTPUT = LV_POSID_NEW.
    READ TABLE G_T_PO_LIFNR WITH KEY LIFNR = G_T_EKPO-LIFNR
    PRJKT = 'X'
    BINARY SEARCH.
    IF SY-SUBRC = 0.
    CLEAR : LV_POSID.
    *To get the old a/c assignment.
    SELECT SINGLE PSPNR
    INTO LV_POSID
    FROM PRPS
    WHERE PSPHI EQ G_T_PO_LIFNR-PSPNR AND
    STUFE EQ 1.
    IF SY-SUBRC = 0.
    CLEAR : LV_POSID_OLD.
    CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT'
    EXPORTING
    INPUT = LV_POSID
    IMPORTING
    OUTPUT = LV_POSID_OLD.
    *Fill the final tab.
    G_T_FINAL-LOGNUM = G_T_BALHDR_FINAL-LOGNUM.
    G_T_FINAL-OBJECT = G_T_BALHDR_FINAL-OBJECT.
    G_T_FINAL-SUBOBJECT = G_T_BALHDR_FINAL-SUBOBJECT.
    G_T_FINAL-EBELN = G_T_EKPO-EBELN.
    G_T_FINAL-EBELP = G_T_EKPO-EBELP.
    G_T_FINAL-NETPR = G_T_EKPO-NETPR.
    G_T_FINAL-MENGE = G_T_EKPO-MENGE.
    WRITE L_AMOUNT UNIT G_T_EKPO-MEINS TO G_T_FINAL-AMOUNT.
    G_T_FINAL-WAERS = G_T_EKPO-WAERS.
    G_T_FINAL-KSTAR = G_T_PO_LIFNR-KSTAR.
    G_T_FINAL-POSID_OLD = LV_POSID_OLD.
    G_T_FINAL-POSID_NEW = LV_POSID_NEW.
    G_T_FINAL-MESG = G_T_BALHDR_FINAL-MESG.
    APPEND G_T_FINAL.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDLOOP.
    ENDFORM. " GET_DATA
    *& Form DISPLAY_DATA
    * text
    * --> p1 text
    * <-- p2 text
    FORM DISPLAY_DATA.
    IF G_T_FINAL[] IS INITIAL.
    MESSAGE S114(KB).
    EXIT.
    ENDIF.
    * Populating the field catalog to the alv list
    PERFORM FIELDCAT_POPULATION.
    * Displaying report in ALV list format
    PERFORM ALV_DISPLAY.
    ENDFORM. " DISPLAY_DATA
    *& Form FIELDCAT_POPULATION
    * text
    * --> p1 text
    * <-- p2 text
    FORM FIELDCAT_POPULATION.
    DATA: L_FIELDCAT TYPE SLIS_FIELDCAT_ALV. " For column heading
    CLEAR : G_T_FIELDCAT,
    G_T_FIELDCAT[].
    * PO Number
    CLEAR L_FIELDCAT.
    L_FIELDCAT-TABNAME = 'G_T_FINAL'.
    L_FIELDCAT-FIELDNAME = 'EBELN'.
    L_FIELDCAT-SELTEXT_M = TEXT-001.
    L_FIELDCAT-COL_POS = 1.
    L_FIELDCAT-KEY = 'X'.
    L_FIELDCAT-OUTPUTLEN = 15.
    L_FIELDCAT-HOTSPOT = 'X'.
    APPEND L_FIELDCAT TO G_T_FIELDCAT.
    CLEAR L_FIELDCAT.
    * PO item
    CLEAR L_FIELDCAT.
    L_FIELDCAT-TABNAME = 'G_T_FINAL'.
    L_FIELDCAT-FIELDNAME = 'EBELP'.
    L_FIELDCAT-SELTEXT_M = TEXT-002.
    L_FIELDCAT-COL_POS = 2.
    L_FIELDCAT-OUTPUTLEN = 10.
    APPEND L_FIELDCAT TO G_T_FIELDCAT.
    CLEAR L_FIELDCAT.
    * Message
    CLEAR L_FIELDCAT.
    L_FIELDCAT-TABNAME = 'G_T_FINAL'.
    L_FIELDCAT-FIELDNAME = 'MESG'.
    L_FIELDCAT-SELTEXT_M = TEXT-003.
    L_FIELDCAT-COL_POS = 3.
    L_FIELDCAT-OUTPUTLEN = 80.
    APPEND L_FIELDCAT TO G_T_FIELDCAT.
    CLEAR L_FIELDCAT.
    ENDFORM. " FIELDCAT_POPULATION
    *& Form ALV_DISPLAY
    * text
    * --> p1 text
    * <-- p2 text
    FORM ALV_DISPLAY.
    * Assign Report ID
    CALL_BACK_PRG = SY-REPID.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = CALL_BACK_PRG
    I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
    IT_FIELDCAT = G_T_FIELDCAT
    TABLES
    T_OUTTAB = G_T_FINAL[]
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2.
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM. " ALV_DISPLAY
    *& Form USER_COMMAND
    * text
    * --> p1 text
    * <-- p2 text
    FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
    RS_SELFIELD TYPE SLIS_SELFIELD.
    DATA : L_DATE1 TYPE SY-DATUM,
    L_DATE2 TYPE SY-DATUM,
    L_YEAR(4),
    L_MONTH(2),
    L_DATE(2).
    CLEAR : L_DATE,L_DATE1,L_DATE2,L_YEAR,L_MONTH.
    L_DATE1 = SY-DATUM.
    L_YEAR = L_DATE1(4).
    L_MONTH = L_DATE1+4(2).
    L_DATE = L_DATE1+6(2).
    CONCATENATE L_DATE L_MONTH L_YEAR INTO L_DATE2 .
    CASE R_UCOMM.
    WHEN '&IC1'. "doubleclick
    CHECK RS_SELFIELD-FIELDNAME = 'EBELN'.
    READ TABLE G_T_FINAL INDEX RS_SELFIELD-TABINDEX.
    IF SY-SUBRC = 0.
    READ TABLE G_T_TEMP WITH KEY LOGNUM = G_T_FINAL-LOGNUM.
    IF SY-SUBRC = 0.
    MESSAGE I899(KB) WITH TEXT-004.
    ELSE.
    SET PARAMETER ID 'BES' FIELD G_T_FINAL-EBELN.
    PERFORM BDC_DYNPRO USING 'SAPLK23F1' '1220'.
    PERFORM BDC_FIELD USING 'COHEADER-SEND_REC_REL'
    '05SAP'.
    PERFORM BDC_FIELD USING 'RK23F-STATUS'
    'S'.
    PERFORM BDC_FIELD USING 'COHEADER-BLDAT'
    L_DATE2.
    PERFORM BDC_FIELD USING 'COHEADER-BUDAT'
    L_DATE2.
    PERFORM BDC_FIELD USING 'COHEADER-PERIO'
    L_MONTH.
    PERFORM BDC_FIELD USING 'RK23F-KSTAR'
    G_T_FINAL-KSTAR.
    PERFORM BDC_FIELD USING 'RK23F-WTGBTR'
    G_T_FINAL-AMOUNT.
    PERFORM BDC_FIELD USING 'RK23F-WAERS'
    G_T_FINAL-WAERS.
    PERFORM BDC_FIELD USING 'RK23F-SPSPNR'
    G_T_FINAL-POSID_OLD.
    PERFORM BDC_FIELD USING 'BDC_CURSOR'
    'RK23F-EPSPNR'.
    PERFORM BDC_FIELD USING 'RK23F-EPSPNR'
    G_T_FINAL-POSID_NEW.
    PERFORM BDC_DYNPRO USING 'SAPLK23F1' '1220'.
    PERFORM BDC_FIELD USING 'BDC_OKCODE'
    '=BACK'.
    PERFORM BDC_FIELD USING 'COHEADER-SEND_REC_REL'
    '05SAP'.
    PERFORM BDC_FIELD USING 'RK23F-STATUS'
    'S'.
    PERFORM BDC_FIELD USING 'COHEADER-BLDAT'
    L_DATE2.
    PERFORM BDC_FIELD USING 'COHEADER-BUDAT'
    L_DATE2.
    PERFORM BDC_FIELD USING 'COHEADER-PERIO'
    L_MONTH.
    PERFORM BDC_DYNPRO USING 'SAPLSPO1' '0100'.
    PERFORM BDC_FIELD USING 'BDC_OKCODE'
    '=NO'.
    PERFORM BDC_DYNPRO USING 'SAPLK23F1' '1220'.
    PERFORM BDC_FIELD USING 'BDC_CURSOR'
    'RK23F-KSTAR'.
    PERFORM BDC_FIELD USING 'RK23F-WAERS'
    G_T_FINAL-WAERS.
    *perform bdc_dynpro using 'SAPLK23F1' '1200'.
    *perform bdc_field using 'BDC_CURSOR'
    * 'COHEADER-SEND_REC_REL'.
    *perform bdc_field using 'BDC_OKCODE'
    * '=PVAR'.
    *perform bdc_field using 'COHEADER-SEND_REC_REL'
    * '05SAP'.
    *perform bdc_field using 'RK23F-STATUS'
    * 'L'.
    *perform bdc_field using 'COHEADER-BLDAT'
    * l_date2.
    *perform bdc_field using 'COHEADER-BUDAT'
    * l_date2.
    *perform bdc_field using 'COHEADER-PERIO'
    * l_month.
    *perform bdc_dynpro using 'SAPLK23F1' '1200'.
    *perform bdc_field using 'BDC_CURSOR'
    * 'RK23F-STATUS'.
    *perform bdc_field using 'BDC_OKCODE'
    * '=LISI'.
    *perform bdc_field using 'COHEADER-SEND_REC_REL'
    * '05SAP'.
    *perform bdc_field using 'RK23F-STATUS'
    * 'S'.
    *perform bdc_field using 'COHEADER-BLDAT'
    * l_date2.
    *perform bdc_field using 'COHEADER-BUDAT'
    * l_date2.
    *perform bdc_field using 'COHEADER-PERIO'
    * l_month.
    *perform bdc_dynpro using 'SAPLK23F1' '1220'.
    *perform bdc_field using 'BDC_OKCODE'
    * '/00'.
    *perform bdc_field using 'COHEADER-SEND_REC_REL'
    * '05SAP'.
    *perform bdc_field using 'RK23F-STATUS'
    * 'S'.
    *perform bdc_field using 'COHEADER-BLDAT'
    * l_date2.
    *perform bdc_field using 'COHEADER-BUDAT'
    * l_date2.
    *perform bdc_field using 'COHEADER-PERIO'
    * l_month.
    *perform bdc_field using 'RK23F-KSTAR'
    * g_t_final-kstar.
    *perform bdc_field using 'RK23F-WTGBTR'
    * g_t_final-amount.
    *perform bdc_field using 'RK23F-WAERS'
    * g_t_final-waers.
    *perform bdc_field using 'RK23F-SPSPNR'
    * g_t_final-posid_old.
    *perform bdc_field using 'BDC_CURSOR'
    * 'RK23F-EPSPNR'.
    *perform bdc_field using 'RK23F-EPSPNR'
    * g_t_final-posid_new.
    *perform bdc_dynpro using 'SAPLK23F1' '1220'.
    *perform bdc_field using 'BDC_OKCODE'
    * '=BACK'.
    *perform bdc_field using 'COHEADER-SEND_REC_REL'
    * '05SAP'.
    *perform bdc_field using 'RK23F-STATUS'
    * 'S'.
    *perform bdc_field using 'COHEADER-BLDAT'
    * l_date2.
    *perform bdc_field using 'COHEADER-BUDAT'
    * l_date2.
    *perform bdc_field using 'COHEADER-PERIO'
    * l_month.
    *perform bdc_dynpro using 'SAPLSPO1' '0100'.
    *perform bdc_field using 'BDC_OKCODE'
    * '=NO'.
    *perform bdc_dynpro using 'SAPLK23F1' '1220'.
    *perform bdc_field using 'BDC_CURSOR'
    * 'RK23F-KSTAR'.
    *perform bdc_field using 'RK23F-WAERS'
    * g_t_final-waers.
    CALL TRANSACTION 'KB11N' USING G_T_BDC MODE 'A' MESSAGES
    INTO G_T_MESSAGE.
    IF NOT G_T_MESSAGE[] IS INITIAL.
    READ TABLE G_T_MESSAGE WITH KEY MSGTYP = 'S'.
    IF SY-SUBRC = 0.
    DELETE FROM BALHDR WHERE LOGNUMBER = G_T_FINAL-LOGNUM AND
    OBJECT = G_T_FINAL-OBJECT AND
    SUBOBJECT = G_T_FINAL-SUBOBJECT.
    COMMIT WORK.
    G_T_TEMP = G_T_FINAL.
    APPEND G_T_TEMP.
    ENDIF.
    ENDIF.
    *refresh g_t_bdc.
    CLEAR G_T_BDC.
    REFRESH G_T_BDC.
    ENDIF.
    ENDIF.
    ENDCASE.
    ENDFORM. " USER_COMMAND
    *& Form bdc_dynpro
    * text
    * -->P_0510 text
    * -->P_0511 text
    FORM BDC_DYNPRO USING PROGRAM
    DYNPRO.
    CLEAR G_T_BDC.
    G_T_BDC-PROGRAM = PROGRAM.
    G_T_BDC-DYNPRO = DYNPRO.
    G_T_BDC-DYNBEGIN = 'X'.
    APPEND G_T_BDC.
    ENDFORM. " bdc_dynpro
    *& Form bdc_field
    * text
    * -->P_0555 text
    * -->P_G_T_FINAL_WAERS text
    FORM BDC_FIELD USING FNAM
    FVAL.
    IF FVAL <> SPACE.
    CLEAR G_T_BDC.
    G_T_BDC-FNAM = FNAM.
    G_T_BDC-FVAL = FVAL.
    APPEND G_T_BDC.
    ENDIF.
    ENDFORM. " bdc_field
    Jogdand M B

  • Trying to convert SELECT query to Update query with INNER JOINS

    Assalam O Alaikum!
    I've tried to convert this query of mine but failed.
    I wish to use it for update datasource in data GridView. I'm fetching data with it but converting it to update is not helping giving multiple errors.
    I tried to share the pic but they don't let me do so. Its actually a gridView with check boxes. check the item and update it..
    Here is the query. Please help me with that.
    <pre>
    SELECT [rightsId], [saveRights], [updateRights],
    [viewRights], [deleteRights], [printRights],
    [processRights], [verifyRights], [unProcessRights],
    [unVerifyRights], CONVERT(VARCHAR(100),tblGroup.groupId)as groupId, convert(varchar(100),tblmenu.[menuId])as menuid
    FROM [tblRights] inner join tblMenu ON
    tblMenu.menuId=tblRights.menuId INNER JOIN
    tblGroup ON tblGroup.groupId=tblRights.rightsId
    </pre>

    code is fine the above query works fine with the fetching(select) but when I try to write it with update it doesn't. Here is the asp code. I'm doing nothing with c# or vb.
      <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
                DataSourceID="ratGrid" AutoGenerateColumns="False"
                CssClass="GridViewStyle" Width="100%" AllowSorting="True" AutoGenerateEditButton="True" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2">
                <Columns>
                    <asp:BoundField DataField="rightsId" HeaderText="rightsId" ItemStyle-Width="75px" SortExpression="rightsId" Visible="False">
                    <ItemStyle Width="75px" />
                    </asp:BoundField>
                    <asp:CheckBoxField DataField="saveRights" HeaderText="Save" SortExpression="saveRights" />
                    <asp:CheckBoxField DataField="updateRights" HeaderText="Update" SortExpression="updateRights" />
                    <asp:CheckBoxField DataField="viewRights" HeaderText="View" SortExpression="viewRights" />
                    <asp:CheckBoxField DataField="deleteRights" HeaderText="Delete" SortExpression="deleteRights" />
                    <asp:CheckBoxField DataField="printRights" HeaderText="Print" SortExpression="printRights" />
                    <asp:CheckBoxField DataField="processRights" HeaderText="Process" SortExpression="processRights" />
                    <asp:CheckBoxField DataField="verifyRights" HeaderText="Verify" SortExpression="verifyRights" />
                    <asp:CheckBoxField DataField="unProcessRights" HeaderText="UnProcess" SortExpression="unProcessRights" />
                    <asp:CheckBoxField DataField="unVerifyRights" HeaderText="UnVerify" SortExpression="unVerifyRights" />
                    <asp:BoundField DataField="groupId" HeaderText="groupId" ReadOnly="True" SortExpression="groupId" Visible="False" />
                    <asp:BoundField DataField="menuid" HeaderText="menuid" SortExpression="menuid" ReadOnly="True" Visible="False" />
                </Columns>
                <RowStyle CssClass="RowStyle" BackColor="#FFF7E7" ForeColor="#8C4510" />
                <PagerStyle CssClass="PagerStyle" ForeColor="#8C4510" HorizontalAlign="Center" />
                <SelectedRowStyle CssClass="SelectedRowStyle" BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
                <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
                <HeaderStyle CssClass="HeaderStyle" BackColor="#A55129" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle CssClass="AltRowStyle" />
                <SortedAscendingCellStyle BackColor="#FFF1D4" />
                <SortedAscendingHeaderStyle BackColor="#B95C30" />
                <SortedDescendingCellStyle BackColor="#F1E5CE" />
                <SortedDescendingHeaderStyle BackColor="#93451F" />
            </asp:GridView>
            <asp:SqlDataSource ID="ratGrid"
                 runat="server"
                ConnectionString="<%$ ConnectionStrings:Conn_Str %>"
                SelectCommand="SELECT [rightsId], [saveRights], [updateRights],
    [viewRights], [deleteRights], [printRights],
    [processRights], [verifyRights], [unProcessRights],
    [unVerifyRights], CONVERT(VARCHAR(100),tblGroup.groupId)as groupId, convert(varchar(100),tblmenu.[menuId])as menuid
    FROM [tblRights] inner join tblMenu ON
    tblMenu.menuId=tblRights.menuId INNER JOIN
    tblGroup ON tblGroup.groupId=tblRights.rightsId"
               FilterExpression="menuId like '{0}%' and [groupId] like '{1}%'" >
                            <FilterParameters>
                <asp:ControlParameter ControlID="ddlmenu" Name="menu"
                        PropertyName="SelectedValue" Type="String" />
                <asp:ControlParameter ControlID="ddlgroup" Name="Country"
                        PropertyName="SelectedValue" Type="String" />
                </FilterParameters>
            </asp:SqlDataSource>
    Your table needs key(s) and you need to assign the key as DataKeys property for the GridView to make your UpDate and Delete work without coding.

  • How to re-write this big SELECT Query with INNER JOINs?

    Hi Experts
    I have a performance killer SELECT query with an inner join of 3 tables u2013 VBAP, VBAK and VBEP together, which populates records to an internal table INT_COLL_ORD. Based on these records selected, in another SELECT query, records are fetched from VBUK table to the internal table INT_VBUK.
    SELECT A~VBELN A~POSNR A~MATNR A~KWMENG A~KBMENG A~ERDAT A~ERZET A~PSTYV D~AUART E~ETTYP E~EDATU
    INTO TABLE INT_TAB_RES
    FROM VBAP AS A INNER JOIN VBAK AS D
    ON D~VBELN EQ A~VBELN AND D~MANDT EQ A~MANDT
    INNER JOIN VBEP AS E
    ON E~VBELN EQ A~VBELN AND E~POSNR EQ A~POSNR AND E~MANDT EQ A~MANDT
    WHERE  A~VBELN IN s_VBELN AND
           D~auart in s_auart AND
           D~vkorg in s_vkorg AND
           D~vbtyp eq 'C'     AND
           ( ( matnr LIKE c_prefix_sp AND zz_msposnr NE 0 AND kbmeng EQ 0 )
           OR ( matnr LIKE c_prefix_fp AND kwmeng NE A~kbmeng ) ) AND
           A~ABGRU EQ SPACE AND
           A~MTVFP IN R_MTVFP AND
           A~PRCTR IN R_PRCT AND
           E~ETENR EQ '1'.
    SORT INT_COLL_ORD BY VBELN POSNR ETTYP.
    DELETE ADJACENT DUPLICATES FROM INT_TAB_RES COMPARING VBELN POSNR.
    CHECK NOT INT_TAB_RES [] IS INITIAL.
    SELECT VBELN UVALL CMGST INTO TABLE INT_VBUK
    FROM VBUK FOR ALL ENTRIES IN INT_TAB_RES
    WHERE VBELN = INT_TAB_RES-VBELN AND UVALL NE 'A'.
    Now, the requirement is:
    I want to split this query. Like, first join VBAK and VBUK first. With this selection, go to the inner join of VBAP and VBEP (on key VBELN) to get the results. How can I re-write this Query?
    Please help.
    Thx n Rgds

    Hi Nagraj
    As of your suggestion, I have re-written the query as below:
    * Declarations
    TYPES: BEGIN OF TYP_COLL_ORD,
            VBELN  LIKE VBAK-VBELN,
            POSNR  LIKE VBUP-POSNR,
            MATNR  LIKE VBAP-MATNR,
            KWMENG LIKE VBAP-KWMENG,
            KBMENG LIKE VBAP-KBMENG,
            ERDAT  LIKE VBAK-ERDAT,
            ERZET  LIKE VBAK-ERZET,
            PSTYV  LIKE VBAP-PSTYV,
            AUART  LIKE VBAK-AUART, u201Calready exists in type
            ETTYP  LIKE VBEP-ETTYP,
            EDATU  LIKE VBEP-EDATU.
    TYPES: END OF TYP_COLL_ORD.
    DATA: INT_COLL_ORD TYPE TABLE OF TYP_COLL_ORD WITH HEADER LINE.
    TYPES: BEGIN OF TYP_VBUK,
            AUART  LIKE VBAK-AUART, u201Chave added this field
            VBELN  LIKE VBUK-VBELN,
            UVALL  LIKE VBUK-UVALL,
            CMGST  LIKE VBUK-CMGST.
    TYPES: END OF TYP_VBUK.
    DATA: INT_VBUK TYPE TABLE OF TYP_VBUK WITH HEADER LINE.
    *QUERY#1 u2013 for VBAK & VBUK Join
    SELECT A~AUART B~VBELN B~UVALL B~CMGST
    INTO TABLE INT_VBUK
    FROM VBAK AS A INNER JOIN VBUK AS B
    ON A~VBELN EQ B~VBELN
    WHERE A~VBELN IN s_VBELN AND
    A~auart in s_auart AND
    A~vkorg in s_vkorg AND
    A~vbtyp eq 'C' AND
    B~UVALL NE 'A'.
    IF NOT INT_VBUK[] IS INITIAL.
    SORT INT_VBUK BY VBELN.
    DELETE ADJACENT DUPLICATES FROM INT_VBUK COMPARING VBELN.
    *QUERY#2 u2013 for VBAP & VBEP Join
    SELECT A~VBELN A~POSNR A~MATNR A~KWMENG A~KBMENG A~ERDAT A~ERZET A~PSTYV B~ETTYP B~EDATU
    INTO TABLE INT_COLL_ORD
    FROM VBAP AS A INNER JOIN VBEP AS B
    ON B~VBELN EQ A~VBELN AND B~POSNR EQ A~POSNR AND B~MANDT EQ A~MANDT
    FOR ALL ENTRIES IN INT_VBUK
    WHERE A~VBELN = INT_VBUK-VBELN AND
    ( ( matnr LIKE c_prefix_sp AND zz_msposnr NE 0 AND kbmeng EQ 0 )
    OR ( matnr LIKE c_prefix_fp AND kwmeng NE A~kbmeng ) ) AND
    A~ABGRU EQ SPACE AND
    A~MTVFP IN R_MTVFP AND
    A~PRCTR IN R_PRCT AND
    B~ETENR EQ '1'.
    ENDIF.
      SORT INT_COLL_ORD BY  VBELN POSNR ETTYP.
      DELETE ADJACENT DUPLICATES FROM INT_COLL_ORD
        COMPARING VBELN POSNR.
      CHECK NOT INT_COLL_ORD[] IS INITIAL.
      LOOP AT INT_COLL_ORD.
        CLEAR: L_MTART,L_ATPPR,L_ETTYP.
        IF L_PREVIOUS_ETTYP NE INT_COLL_ORD-ETTYP OR
          L_PREVIOUS_AUART NE INT_COLL_ORD-AUART.
          READ TABLE INT_OVRCTL WITH KEY AUART = INT_COLL_ORD-AUART ETTYP = INT_COLL_ORD-ETTYP.
          CHECK SY-SUBRC NE 0.
    Now, the issue is:
    Please note that declaration for INT_COLL_ORD has a field AUART, which is used in further parts of program (see the statement just above)
    But, since neither VBAP nor VBEP contains AUART field, it cannot be fetched through the QUERY#2. So this value is not populated into INT_COLL_ORD through SELECT Query.
    Since this field is used in later part of program & that the internal table has no value for this field, it dumps!!
    How to include this value into the INT_COLL_ORD?
    Plz suggest....

  • Urgent: Regarding Inner join relation b/w MSEG, MKPF, MARA and MAKT

    I have written o code like below for inner join. However, The program has take much more time to give out put. Could any one please correct the below inner join statement. Its very urgent.
    Thanks for your help.
    SELECT  mseg~mblnr
              mseg~matnr
              mseg~werks
              mseg~charg
              mseg~lifnr
              mseg~bualt
              mseg~erfmg
              mseg~ebeln
              mseg~ebelp
              mkpf~budat   
              mara~zzshelf_life                              
              makt~maktx
              FROM mseg
              INNER JOIN mkpf
                ON mkpfmblnr EQ msegmblnr
              INNER JOIN mara
                ON msegmatnr EQ maramatnr
              INNER JOIN makt
                ON maramatnr EQ maktmatnr
              INTO TABLE gt_mat_doc
              WHERE  mseg~matnr IN s_matnr
                AND  mseg~werks IN s_werks
                AND  mseg~lifnr IN s_lifnr
                AND  mseg~bwart EQ p_bwart
                AND  ( msegebeln NE ' ' AND msegebeln IN s_ebeln )
                AND  mkpf~budat IN s_budat
                AND  mara~mtart IN s_mtart
                AND  makt~spras EQ sy-langu.

    Hi,
    Do like this
    Types: begin of ty_mesg_mkpf,
             mblnr type mseg-mblnr,
             matnr type mseg-matnr,
             werks type mseg-werks,
             charg type mseg-charg,
             lifnr type mseg-lifnr,
             bualt type mseg-bualt,
             erfmg type mseg-erfmg,
             ebeln type mseg-ebeln,
             ebelp type mseg-ebelp,
             budat type mkpf-budat,
           end of ty_mseg_mkpf,
           Begin og ty_mara_makt,
            matnr type mara-matnr,
            zzshelf_life type mara-zzshelf_life,
            maktx type makt-maktx,
           end of ty_mara_makt.
    Data: it_mseg_mkpf type table of ty_mseg_mkpf,
          wa_mseg_mkpf type ty_mseg_mkpf,
          it_mara_makt type table of ty_mara_makt,
          wa_mara_makt type ty_mara_makt.
    SELECT m1~mblnr
    m1~matnr
    m1~werks
    m1~charg
    m1~lifnr
    m1~bualt
    m1~erfmg
    m1~ebeln
    m1~ebelp
    m2~budat
    FROM mseg
    INTO TABLE it_mseg_mkpf
    INNER JOIN mkpf
    ON m1mblnr EQ m2mblnr
    WHERE m1~matnr IN s_matnr
    AND m1~werks IN s_werks
    AND m1~lifnr IN s_lifnr
    AND m1~bwart EQ p_bwart
    AND ( m1ebeln NE ' ' AND m1ebeln IN s_ebeln )
    AND m2~budat IN s_budat
    if sy-subrc = 0.
    Select m3~matnr
    m3~zzshelf_life
    m4~maktx from mara as m3
    INNER JOIN makt as m4
    ON m3matnr EQ m4matnr
    INTO TABLE it_mara_makt
    where m3~mtart IN s_mtart
    AND m4~spras EQ sy-langu.
    endif.
    loop at it_mseg_mkpf into wa_mseg_mkpf.
    Move necessary field values from wa_mseg_mkpf to wa_mat_doc.
    Read table it_mara_makt into wa_mara_makt with key matnr = wa_mseg_mkpf-matnr.
    if sy-subrc = 0.
      move remaining field values to wa_mat_doc.
      append wa_mat_doc to gt_mat_doc.
      clear wa_mat_doc.
    endif.
    endloop.
    Regards,
    Satish

  • Delete query using inner join

    I need to delete records from a table using inner join from other tables. See below for the table structure and records.
    CREATE TABLE STUDENT (ROLL_NO NUMBER(10),NAME VARCHAR2(100),DEPT_NO NUMBER(10),JOIN_DATE DATE);
    CREATE TABLE DEPART (DEPT_NO NUMBER(10), DEPT_NAME VARCHAR2(100));
    CREATE TABLE ACTIVE_DEPT (DEPT_NO NUMBER(10), IS_ACTIVE VARCHAR2(1));
    INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(1,'SAM',10,SYSDATE-10);
    INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(2,'ALEX',10,SYSDATE -10);
    INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(3,'FRANK',20,SYSDATE -10);
    INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(4,'WAYNE',20,SYSDATE+1);
    INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(5,'KRUL',30,SYSDATE -10);
    INSERT INTO STUDENT (ROLL_NO,NAME,DEPT_NO,JOIN_DATE) VALUES(6,'ALICE',40,SYSDATE -10);
    INSERT INTO DEPART (DEPT_NO,DEPT_NAME) VALUES (10,'DEPT1');
    INSERT INTO DEPART (DEPT_NO,DEPT_NAME) VALUES (20,'DEPT2');
    INSERT INTO DEPART (DEPT_NO,DEPT_NAME) VALUES (30,'DEPT3');
    INSERT INTO ACTIVE_DEPT (DEPT_NO,IS_ACTIVE) VALUES (10,'Y');
    INSERT INTO ACTIVE_DEPT (DEPT_NO,IS_ACTIVE) VALUES (20,'N');
    INSERT INTO ACTIVE_DEPT (DEPT_NO,IS_ACTIVE) VALUES (30,'Y');
    DELETE FROM STUDENT WHERE (STUDENT.DEPT_NO) IN (SELECT D.dept_no FROM DEPART D,ACTIVE_DEPT AD WHERE D.DEPT_NO = AD.DEPT_NO AND AD.IS_ACTIVE = 'N');The above delete query will delete two records from the STUDENT table. Now i want to include another condition say, join_date should be a past date (join_date < trunc(sysdate)).
    How to include this condition in the above delete statement. I know i can do this using a subquery but i wont prefer that option. Basically i don't have much idea about join in delete statements.
    Please help.

    Is this you need ?
    DELETE FROM student WHERE join_date < TRUNC(SYSDATE)
                                            AND student.dept_no IN (SELECT D.dept_no
                                                                      FROM depart d,active_dept ad
                                                                     WHERE d.dept_no = ad.dept_no AND ad.is_active = 'N');Only one record is deleted. -> 3,'FRANK',20,SYSDATE -10
    >
    Balaji      wrote:
    Yes. But here we are getting the dept_no from the sub query, is there a better way to achieve this without sub query?
    >
    As far I know you need to have sub query in this case.
    You can close this thread if answered. If you have any further queries please post it so that someone can help you.
    Edited by: Lokanath Giri on २० मार्च, २०१२ ५:०५ अपराह्न

  • Convert SSRS dropdown MDX query to INNER JOIN w/ NONEMPTY? Having hard time with this.

    I'm having an incredibly hard time with this, mostly because I'm very new with MDX.
    I created a simple report (with AdventureWorksDW) whose datasource is an SSAS cube. I select a datekey from the dropdown menu, and the report displays [Measures].[Order Quantity] for that day.
    The problem is that the dropdown displays every single value from the dimdate dimension. DimDate goes from 20050101 to 20201231, so the dropdown is very long.
    How can I alter the SSRS-generated MDX so that it does an INNER JOIN with Fact table and only the dates shown in the dropdown are the ones where there's data in the Fact table?
    Currently, the fact table only has 2 days of data (20141015, 20141016), which means that the dropdown should only display those two dates. I'm including the generated code MDX that populates the dropdown menu:
    WITH MEMBER [Measures].[ParameterCaption] AS
    [Dim Date].[Date Key].CURRENTMEMBER.MEMBER_CAPTION
    MEMBER [Measures].[ParameterValue] AS
    [Dim Date].[Date Key].CURRENTMEMBER.UNIQUENAME
    MEMBER [Measures].[ParameterLevel] AS
    [Dim Date].[Date Key].CURRENTMEMBER.LEVEL.ORDINAL
    SELECT {[Measures].[ParameterCaption],
    [Measures].[ParameterValue], [Measures].[ParameterLevel]}
    ON COLUMNS , [Dim Date].[Date Key].ALLMEMBERS ON ROWS
    FROM [Adventure Works cube]
    Any help is appreciated.
    VM

    Hi vmhatup,
    you can get rid of blank data using nonempty function and get rid of negative values using filter function nonempty should be inside of filter so it applies first, otherwise it is too slow.
    Your statement could look like this
    WITH MEMBER [Measures].[ParameterCaption] AS
    [Dim Date].[Date Key].CURRENTMEMBER.MEMBER_CAPTION
    MEMBER [Measures].[ParameterValue] AS
    [Dim Date].[Date Key].CURRENTMEMBER.UNIQUENAME
    MEMBER [Measures].[ParameterLevel] AS
    [Dim Date].[Date Key].CURRENTMEMBER.LEVEL.ORDINAL
    SELECT {[Measures].[ParameterCaption],
    [Measures].[ParameterValue], [Measures].[ParameterLevel]}
    ON COLUMNS
    , filter(
    nonempty([Dim Date].[Date Key].[Date Key],measures.measureName)
    ,measure.measurename >0
    ON ROWS
    FROM [Adventure Works cube]
    Jiri Neoral

Maybe you are looking for

  • Beginners Guide "Create an initial ramdisk environment" hooks needed

    In the guide at this location: https://wiki.archlinux.org/index.php/Be - nvironment it addresses when the mkinitcpio.conf hooks line needs changes. Is it really the case that installing to a external USB spinning drive with root there,  requires a ch

  • Error in Disk Repair - PLS HELP

    Dear All, I have posted a message a week ago, about Error in Verifying Permission and Onyx Error -1. Then ~Bee (thanks for the suggestion, really appreciate it) replied and suggested me to try Disk Repair. I tried it this morning and the result was n

  • Applet is not opening in jsp

    Hi, I am using an applet in my application, which creates charts. But its not opening, its giving exceptions. I create jar using jar cvf command. After that i aslo sign and verify this jar using jar signer. My jsp and this jar file are in the same di

  • Import/Export Financial Statement version in OB58

    Hi all, In OB58, we can define financial statement structure for balance sheet and Profit loss report. Is there any way to import FSV from external file in to SAP ? as well as export from SAP to  external file ? Thank you very much, Sylvecat.

  • How does "Forms Table Test" work?

    Hey guys, I want to use a "forms table test" on the order management lines form, but it doesn't show any reaction. In which forms do I use table forms test? best regards dewi