ABAP QUERY - ITS URGENT

Hi Experts,
In this scenario we have one Material – Mat1 and 2 plants namely, P1 and P2. At time of execution, in the selection screen, if we give for example: Mat1 and P1, data is displayed for that particular material and plant. Where as if we give MAT1 for P1 and P2 , the material again displayed for P1 which is in first row and it is not displaying the material for P2 which is in 2nd row.
If we interchange P2 is in first row, the material is displayed and it is not displaying for P1 which is in 2nd row.
In general – Any material for any plant which is in   2nd row is not displayed only zeros are visible.
Kindly locate the solution for the above query in the below program.                                                                               
Specification Name      :  Production Tracker                       
REPORT  zpp_ptk                                 .
TYPE-POOLS : slis.
TABLES : pbed,
         mara,
         mast,
         marc,
         makt,
         pbid,
         pbim,
         stpo,
         t001w,
         scal,
         kna1,
         knmt,
         equi,
         a304,
         konp,
         zcalendar,
         am60x.
DATA :   gt_sort TYPE slis_t_sortinfo_alv,
         gt_fieldcat TYPE slis_t_fieldcat_alv,
         gt_fieldcat1 TYPE slis_fieldcat_alv,
         gt_events TYPE slis_t_event ,
         gv_pc_start(2) TYPE n,
         gv_pcno(6),
         BEGIN OF gt_pbed OCCURS 0,
         matnr TYPE matnr,
         p_matnr TYPE matnr,
         plnmg TYPE plnmg,
         entmg TYPE entmg,
         perxx TYPE perxx,
         ojtxb TYPE ojtxb,
         ojtxp TYPE ojtxp,
         backlog TYPE plnmg,
         future  TYPE plnmg,
         END OF gt_pbed,
         l_knumh LIKE a304-knumh,            " added by ****** 08.06.2005
         l_datab LIKE a304-datab,           " added by ****** 08.06.2005
         BEGIN OF it_date1 OCCURS 0,
         it_date1 TYPE zstartdt,
         enddt TYPE zenddt,
         sapweekno TYPE zsapweekno,
         END OF it_date1,
         BEGIN OF gt_matnr OCCURS 0,
         matnr TYPE matnr,
         plnmg TYPE plnmg,
         entmg TYPE entmg,
         END OF gt_matnr,
         BEGIN OF gt_stock OCCURS 0,
         matnr TYPE matnr,
         stock TYPE entmg,
         END OF gt_stock,
         gt_fpbed LIKE gt_pbed OCCURS 0 WITH HEADER LINE,
         it_zcalendar LIKE zcalendar OCCURS 0 WITH HEADER LINE,
         l_counter TYPE i,
         l_plus15  LIKE scal-week,
         l_wfpweekno LIKE scal-week,
         l_selectedweekno LIKE scal-week,
         BEGIN OF gt_backlog OCCURS 0,
         matnr TYPE matnr,
         backlog TYPE entmg,
         END OF gt_backlog,
         gt_future LIKE gt_backlog OCCURS 0 WITH HEADER LINE,
         gt_output TYPE zpp_rollplan OCCURS 0 WITH HEADER LINE,
         BEGIN OF gt_out OCCURS 0,
         head(15) TYPE c,
         matnr TYPE matnr,
         stock TYPE labst,
         backlog TYPE plnmg,
         week1 TYPE wmeng,
         week2 TYPE wmeng,
         week3 TYPE wmeng,
         week4 TYPE wmeng,
         week5 TYPE wmeng,
         week6 TYPE wmeng,
         week7 TYPE wmeng,
         week8 TYPE wmeng,
         week9 TYPE wmeng,
         week10 TYPE wmeng,
         week11 TYPE wmeng,
         week12 TYPE wmeng,
         week13 TYPE wmeng,
         END OF gt_out,
       BEGIN OF gt_out26 OCCURS 0,
       head(15) TYPE c,
       matnr TYPE matnr,
       stock TYPE labst,
       backlog TYPE plnmg,
       week1 TYPE wmeng,
       week2 TYPE wmeng,
       week3 TYPE wmeng,
       week4 TYPE wmeng,
       week5 TYPE wmeng,
       week6 TYPE wmeng,
       week7 TYPE wmeng,
       week8 TYPE wmeng,
       week9 TYPE wmeng,
       week10 TYPE wmeng,
       week11 TYPE wmeng,
       week12 TYPE wmeng,
       week13 TYPE wmeng,
       week14 TYPE wmeng,
       week15 TYPE wmeng,
       week16 TYPE wmeng,
       week17 TYPE wmeng,
       week18 TYPE wmeng,
       week19 TYPE wmeng,
       week20 TYPE wmeng,
       week21 TYPE wmeng,
       week22 TYPE wmeng,
       week23 TYPE wmeng,
       week24 TYPE wmeng,
       week25 TYPE wmeng,
       week26 TYPE wmeng,
       END OF gt_out26,
       BEGIN OF it_week OCCURS 0,
       it_week TYPE zsapweekno,
       END OF it_week,
         dd(4) TYPE c,
         cc(2) TYPE c,
         dd1(6) TYPE c,
        l_val1(7)  TYPE c,
        l_val2(7)  TYPE c,
        l_val3(7)  TYPE c,
        l_val4(7)  TYPE c,
        l_val5(7)  TYPE c,
        l_val6(7)  TYPE c,
        l_val7(7)  TYPE c,
        l_val8(7)  TYPE c,
        l_val9(7)  TYPE c,
        l_val10(7)  TYPE c,
        l_val11(7)  TYPE c,
        l_val12(7)  TYPE c,
        l_val13(7)  TYPE c,
        l_val14(7)  TYPE c,
        l_val15(7)  TYPE c,
        l_val16(7)  TYPE c,
        l_val17(7)  TYPE c,
        l_val18(7)  TYPE c,
        l_val19(7)  TYPE c,
        l_val20(7)  TYPE c,
        l_val21(7)  TYPE c,
        l_val22(7)  TYPE c,
        l_val23(7)  TYPE c,
        l_val24(7)  TYPE c,
        l_val25(7)  TYPE c,
        l_val26(7)  TYPE c,
        it_ph TYPE plnmg,
        it_dm TYPE dbmng,
        it_mard LIKE mard OCCURS 0 WITH HEADER LINE,
        it_tot1 TYPE p DECIMALS 3,
        it_tot1_2  TYPE p DECIMALS 3,
       it_tot2 TYPE p DECIMALS 3,
       it_tot2_2  TYPE p DECIMALS 3,
       it_tot3 TYPE p DECIMALS 3,
       it_tot3_2  TYPE p DECIMALS 3,
       it_tot4 TYPE p DECIMALS 3,
       it_tot4_2  TYPE p DECIMALS 3,
       it_tot5 TYPE p DECIMALS 3,
       it_tot5_2  TYPE p DECIMALS 3,
       it_tot6 TYPE p DECIMALS 3,
       it_tot6_2  TYPE p DECIMALS 3,
       it_tot7 TYPE p DECIMALS 3,
       it_tot7_2  TYPE p DECIMALS 3,
       it_tot8 TYPE p DECIMALS 3,
       it_tot8_2  TYPE p DECIMALS 3,
       it_tot9 TYPE p DECIMALS 3,
       it_tot9_2  TYPE p DECIMALS 3,
       it_tot10 TYPE p DECIMALS 3,
       it_tot10_2  TYPE p DECIMALS 3,
       it_tot11 TYPE p DECIMALS 3,
       it_tot11_2  TYPE p DECIMALS 3,
       it_tot12 TYPE p DECIMALS 3,
       it_tot12_2  TYPE p DECIMALS 3,
       it_tot13 TYPE p DECIMALS 3,
       it_tot13_2  TYPE p DECIMALS 3,
       it_tot14 TYPE p DECIMALS 3,
       it_tot14_2  TYPE p DECIMALS 3,
       it_tot15 TYPE p DECIMALS 3,
       it_tot15_2  TYPE p DECIMALS 3,
       it_tot16 TYPE p DECIMALS 3,
       it_tot16_2  TYPE p DECIMALS 3,
       it_tot17 TYPE p DECIMALS 3,
       it_tot17_2  TYPE p DECIMALS 3,
       it_tot18 TYPE p DECIMALS 3,
       it_tot18_2  TYPE p DECIMALS 3,
       it_tot19 TYPE p DECIMALS 3,
       it_tot19_2  TYPE p DECIMALS 3,
       it_tot20 TYPE p DECIMALS 3,
       it_tot20_2  TYPE p DECIMALS 3,
       it_tot21 TYPE p DECIMALS 3,
       it_tot21_2  TYPE p DECIMALS 3,
       it_tot22 TYPE p DECIMALS 3,
       it_tot22_2  TYPE p DECIMALS 3,
       it_tot23 TYPE p DECIMALS 3,
       it_tot23_2  TYPE p DECIMALS 3,
       it_tot24 TYPE p DECIMALS 3,
       it_tot24_2  TYPE p DECIMALS 3,
       it_tot25 TYPE p DECIMALS 3,
       it_tot25_2  TYPE p DECIMALS 3,
       it_tot26 TYPE p DECIMALS 3,
       it_tot26_2  TYPE p DECIMALS 3,
       it_back1 TYPE p DECIMALS 3,
       it_back2 TYPE p DECIMALS 3,
       it_back3 TYPE p DECIMALS 3,
       it_back4 TYPE p DECIMALS 3,
       it_back5 TYPE p DECIMALS 3,
       it_back6 TYPE p DECIMALS 3,
       it_back7 TYPE p DECIMALS 3,
       it_back8 TYPE p DECIMALS 3,
       it_back9 TYPE p DECIMALS 3,
       it_back10 TYPE p DECIMALS 3,
       it_back11 TYPE p DECIMALS 3,
       it_back12 TYPE p DECIMALS 3,
       it_back13 TYPE p DECIMALS 3,
       it_back14 TYPE p DECIMALS 3,
       it_back15 TYPE p DECIMALS 3,
       it_back16 TYPE p DECIMALS 3,
       it_back17 TYPE p DECIMALS 3,
       it_back18 TYPE p DECIMALS 3,
       it_back19 TYPE p DECIMALS 3,
       it_back20 TYPE p DECIMALS 3,
       it_back21 TYPE p DECIMALS 3,
       it_back22 TYPE p DECIMALS 3,
       it_back23 TYPE p DECIMALS 3,
       it_back24 TYPE p DECIMALS 3,
       it_back25 TYPE p DECIMALS 3,
       it_back26 TYPE p DECIMALS 3,
       it_pbhi LIKE pbhi OCCURS 0 WITH HEADER LINE,
       int1 TYPE i,
       int2 TYPE i,
       int3 TYPE i,
       int4 TYPE i,
       int5 TYPE i,
       int6 TYPE i,
       int7 TYPE i,
       int8 TYPE i,
       int9 TYPE i,
       int10 TYPE i,
       int11 TYPE i,
       int12 TYPE i,
       int13 TYPE i,
       int14 TYPE i,
       int15 TYPE i,
       int16 TYPE i,
       int17 TYPE i,
       int18 TYPE i,
       int19 TYPE i,
       int20 TYPE i,
       int21 TYPE i,
       int22 TYPE i,
       int23 TYPE i,
       int24 TYPE i,
       int25 TYPE i,
       int26 TYPE i,
*forecast purpose
        p_fnavl TYPE c VALUE 'X',
        it_zcal LIKE zcalendar OCCURS 0 WITH HEADER LINE,
       BEGIN OF it_mkpf OCCURS 0,
       mblnr TYPE mblnr,
       budat TYPE budat,
       END OF it_mkpf,
      it_mseg LIKE mseg OCCURS 0 WITH HEADER LINE,
      st_date TYPE zstartdt,
      en_date TYPE zenddt.
*BUDAT
SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001..
SELECT-OPTIONS   : s_matnr FOR pbim-matnr OBLIGATORY.
PARAMETERS       : p_werks TYPE werks_d OBLIGATORY,
                   p_dispo TYPE dispo,
                   p_mov TYPE bwart OBLIGATORY DEFAULT '321',
                   p_date1 TYPE pbed-wdatu DEFAULT '20070401'. "  MODIF ID ABC..
*SELECT-OPTIONS    : p_date2 FOR pbed-wdatu.
PARAMETERS : p_date2  TYPE wdatu.
SELECTION-SCREEN  : END OF BLOCK blk1.
SELECTION-SCREEN  : BEGIN OF BLOCK bb1 WITH FRAME TITLE text-002 .
PARAMETERS        : p_13week RADIOBUTTON GROUP grp1,
                    p_26week RADIOBUTTON GROUP grp1.
SELECTION-SCREEN  : END OF BLOCK bb1.
SELECT-OPTIONS    : s_week FOR zcalendar-sapweekno NO-DISPLAY.
AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    IF screen-name = 'P_DATE1'.
      screen-input = '0'.
      screen-active = '1'.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.
INITIALIZATION.
START-OF-SELECTION.
  IF  '20070401' > p_date2.
    MESSAGE 'Please Give Greater that 01.04.2007 ' TYPE 'I'.
    LEAVE LIST-PROCESSING.
  ENDIF.
  SELECT SINGLE sapweekno INTO s_week-low
  FROM zcalendar
  WHERE startdt >=  p_date2. "-high AND enddt >= p_date2-low.
  s_week-option = 'EQ'.
  s_week-sign   = 'I'.
  APPEND s_week.
  SELECT * FROM zcalendar INTO TABLE it_zcalendar.
  SELECT * FROM mard INTO TABLE it_mard WHERE matnr IN s_matnr.
*********************FOR 13 WEEK*********************************************************************
  IF p_13week EQ 'X'.
    LOOP AT s_week.
      s_week-high = s_week-low + 12.
      MODIFY s_week TRANSPORTING high.
      SELECT SINGLE startdt FROM zcalendar INTO st_date WHERE sapweekno = s_week-low.
      SELECT SINGLE enddt FROM zcalendar INTO en_date WHERE  sapweekno = s_week-high.
      SELECT mblnr budat FROM mkpf INTO TABLE it_mkpf WHERE budat GE st_date AND budat LE en_date.
     SELECT * FROM mseg INTO TABLE it_mseg FOR ALL ENTRIES IN it_mkpf WHERE mblnr = it_mkpf-mblnr
               AND matnr IN s_matnr
               AND werks = p_werks
               and shkzg = 'S'
               AND bwart IN ('321','322','101','102','131','132') .
      LOOP AT it_mkpf.
        SELECT * FROM mseg INTO it_mseg WHERE mblnr = it_mkpf-mblnr
                        AND matnr IN s_matnr
                        AND werks = p_werks
                        AND shkzg = 'S'
                        AND bwart IN ('321','322','101','102','131','132') .
          APPEND it_mseg.
          CLEAR it_mseg.
        ENDSELECT.
      ENDLOOP.
    ENDLOOP.
    PERFORM get_pbid.
    BREAK-POINT.
    PERFORM s_week_days.
    PERFORM get_backlog.
    PERFORM gt_out.
    PERFORM build_fieldccatlog1.
    PERFORM 13alv.
  ENDIF.
******************END OF 13 WEEK*************************************************************************
*****************For 26 th Week*************************************************************************
  IF p_26week EQ 'X'.
    LOOP AT s_week.
      s_week-high = s_week-low + 25.
      MODIFY s_week TRANSPORTING high.
      SELECT SINGLE startdt FROM zcalendar INTO st_date WHERE sapweekno = s_week-low.
      SELECT SINGLE enddt FROM zcalendar INTO en_date WHERE  sapweekno = s_week-high.
      SELECT mblnr budat FROM mkpf INTO TABLE it_mkpf WHERE budat GE st_date AND budat LE en_date.
      SELECT * FROM mseg INTO TABLE it_mseg FOR ALL ENTRIES IN it_mkpf WHERE mblnr = it_mkpf-mblnr
                AND matnr IN s_matnr
                AND werks = p_werks
                AND shkzg = 'S'
                AND bwart IN ('321','322','101','102') .
    ENDLOOP.
    PERFORM get_pbid.
    PERFORM s_26week_days.
    PERFORM gt_out26.
    PERFORM build_fieldccatlog1.
    PERFORM 26alv.
  ENDIF.
**************END OF 26 TH WEEK **********************************************************************
*&      Form  get_pbid
      text
FORM get_pbid .
  DATA : lv_line TYPE i,
         lv_perxx LIKE scal-week.
  DATA it_dispo(1) TYPE c. " ashish
LOOP AT s_matnr. " TODAY
  BREAK-POINT.
  SELECT SINGLE diber INTO it_dispo FROM marc WHERE matnr = s_matnr-low
                                                AND werks = p_werks.
  IF it_dispo NE 'X'.
    SELECT * FROM pbim WHERE matnr = s_matnr-low
                         AND werks EQ p_werks
                         AND loevr = space.
      SELECT startdt enddt sapweekno INTO TABLE it_date1 FROM zcalendar WHERE sapweekno GE s_week-low AND sapweekno LE s_week-high.
     SORT by s_matnr p_werks.
      LOOP AT it_date1.
        SELECT * FROM pbhi INTO TABLE it_pbhi WHERE bdzei = pbim-bdzei AND ( pdatu GE it_date1-it_date1 AND pdatu LE it_date1-enddt ).
        IF sy-subrc EQ 0.
          DELETE it_pbhi WHERE aenam = 'ABBAU'.
          LOOP AT it_pbhi.
            it_ph =  it_ph + it_pbhi-plnmg.
            it_dm = it_dm + it_pbhi-dbmng.
          ENDLOOP.
          it_ph = it_ph - it_dm.
          gt_pbed-matnr = s_matnr-low.
          gt_pbed-plnmg = it_ph.
          gt_pbed-perxx = it_date1-sapweekno.
          APPEND gt_pbed.
          CLEAR it_pbhi.
          CLEAR it_ph.
          CLEAR it_dm.
          REFRESH it_pbhi.
          CLEAR gt_pbed.
        ELSE.
        ENDIF.
      ENDLOOP.
    ENDSELECT.
  ELSE.
    SORT BY s_matnr p_werks.
    LOOP AT s_matnr.
      SELECT * FROM pbid WHERE  matnr =  s_matnr-low
                         AND   werks = p_werks
                         AND   loevr EQ space.
****PHANI
     SELECT * FROM pbed WHERE bdzei = pbid-bdzei.
       MOVE-CORRESPONDING pbed TO gt_pbed.
       PERFORM convert_to_week USING pbed-pdatu
                            CHANGING gt_pbed-perxx.
     check gt_pbed-perxx in r_week.
       gt_pbed-matnr = pbid-matnr.
     PERFORM GET_PARENT USING gt_bom-MATNR
                     CHANGING gt_pbed-p_matnr
                              GT_pbed-OJTXB.
       COLLECT gt_pbed.
       CLEAR gt_pbed.
*PHANI
data it_date1 type ZSTARTDT.
        SELECT startdt enddt sapweekno INTO TABLE it_date1 FROM zcalendar WHERE sapweekno GE s_week-low AND sapweekno LE s_week-high.
        LOOP AT it_date1.
          SELECT * FROM pbhi INTO TABLE it_pbhi WHERE bdzei = pbid-bdzei AND ( pdatu GE it_date1-it_date1 AND pdatu LE it_date1-enddt ).
          IF sy-subrc EQ 0.
            DELETE it_pbhi WHERE aenam = 'ABBAU'.
            LOOP AT it_pbhi.
              it_ph =  it_ph + it_pbhi-plnmg.
              it_dm = it_dm + it_pbhi-dbmng.
            ENDLOOP.
            it_ph = it_ph - it_dm.
            gt_pbed-matnr = s_matnr-low.
            gt_pbed-plnmg = it_ph.
            gt_pbed-perxx = it_date1-sapweekno.
            APPEND gt_pbed.
            CLEAR it_pbhi.
            CLEAR it_ph.
            CLEAR it_dm.
            REFRESH it_pbhi.
            CLEAR gt_pbed.
          ELSE.
          ENDIF.
        ENDLOOP.
      ENDSELECT.
    ENDLOOP.
  ENDIF.
ENDFORM.                    " get_pbid
*&      Form  convert_to_week
      text
     -->IV_DATE    text
     -->XV_WEEK    text
FORM convert_to_week USING iv_date
                 CHANGING xv_week.
  DATA : lv_week LIKE scal-week.
  CALL FUNCTION 'DATE_GET_WEEK'
    EXPORTING
      date = iv_date
    IMPORTING
      week = lv_week.
  xv_week = lv_week.
ENDFORM.                    "CONVERT_TO_WEEK
*&      Form  get_stock
      text
FORM get_stock .
  DATA : lv_stock LIKE mard-insme.
  LOOP AT gt_pbed.
    READ TABLE gt_stock WITH KEY matnr = gt_pbed-matnr.
    CHECK sy-subrc NE 0.
    SELECT SUM( labst ) INTO lv_stock FROM mard
    WHERE matnr = gt_pbed-matnr AND   werks = p_werks.
    SELECT SUM( insme ) INTO gt_stock-stock FROM mard
    WHERE matnr = gt_pbed-matnr AND   werks = p_werks.
    gt_stock-stock = gt_stock-stock + lv_stock.
    gt_stock-matnr = gt_pbed-matnr.
    APPEND gt_stock.
  ENDLOOP.
ENDFORM.                    " get_stock
FORM s_week_days .
  DELETE gt_pbed WHERE perxx < s_week-low. " and perxx > s_week-high.
  CONCATENATE 'WEEK' '-' s_week-low+4(2) INTO l_val1.
  s_week-low4(2) = s_week-low4(2) + 1.
  CONCATENATE 'WEEK' '-' s_week-low+4(2) INTO l_val2.
  s_week-low4(2) = s_week-low4(2) + 1.
  CONCATENATE 'WEEK' '-' s_week-low+4(2) INTO l_val3.
  s_week-low4(2) = s_week-low4(2) + 1.
  CONCATENATE 'WEEK' '-' s_week-low+4(2) INTO l_val4.
  s_week-low4(2) = s_week-low4(2) + 1.
  CONCATENATE 'WEEK' '-' s_week-low+4(2) INTO l_val5.
  s_week-low4(2) = s_week-low4(2) + 1.
  CONCATENATE 'WEEK' '-' s_week-low+4(2) INTO l_val6.
  s_week-low4(2) = s_week-low4(2) + 1.
  CONCATENATE 'WEEK' '-' s_week-low+4(2) INTO l_val7.
  s_week-low4(2) = s_week-low4(2) + 1.
  CONCATENATE 'WEEK' '-' s_week-low+4(2) INTO l_val8.
  s_week-low4(2) = s_week-low4(2) + 1.
  CONCATENATE 'WEEK' '-' s_week-low+4(2) INTO l_val9.
  s_week-low4(2) = s_week-low4(2) + 1.
  CONCATENATE 'WEEK' '-' s_week-low+4(2) INTO l_val10.
  s_week-low4(2) = s_week-low4(2) + 1.
  CONCATENATE 'WEEK' '-' s_week-low+4(2) INTO l_val11.
  s_week-low4(2) = s_week-low4(2) + 1.
  CONCATENATE 'WEEK' '-' s_week-low+4(2) INTO l_val12.
  s_week-low4(2) = s_week-low4(2) + 1.
  CONCATENATE 'WEEK' '-' s_week-low+4(2) INTO l_val13.
ENDFORM.                    " s_week_days
*&      Form  build_fieldccatlog
      text
FORM build_fieldcatlog .
  CLEAR gt_fieldcat1.
  gt_fieldcat1-fieldname = 'MATNR'.
  gt_fieldcat1-tabname = 'GT_OUT'.
  gt_fieldcat1-seltext_l = 'MATERIAL'.
  APPEND gt_fieldcat1 TO gt_fieldcat.
  CLEAR gt_fieldcat1.
  gt_fieldcat1-fieldname = 'WERKS'.
  gt_fieldcat1-tabname = 'GT_OUT'.
  gt_fieldcat1-seltext_m = 'WERKS'.
  APPEND gt_fieldcat1 TO gt_fieldcat.
  CLEAR gt_fieldcat1.
  gt_fieldcat1-fieldname = 'HEAD'.
  gt_fieldcat1-tabname = 'GT_OUT'.
  gt_fieldcat1-seltext_l = 'REF'.
  APPEND gt_fieldcat1 TO gt_fieldcat.
  CLEAR gt_fieldcat1.
  gt_fieldcat1-fieldname = 'STOCK'.
  gt_fieldcat1-tabname = 'GT_OUT'.
  gt_fieldcat1-seltext_l = 'FG-STOCK'.
  APPEND gt_fieldcat1 TO gt_fieldcat.
  CLEAR gt_fieldcat1.
  gt_fieldcat1-fieldname = 'BACKLOG'.
  gt_fieldcat1-tabname = 'GT_OUT'.
  gt_fieldcat1-seltext_l = 'BACKLOG'.
  APPEND gt_fieldcat1 TO gt_fieldcat.
  dd = sy-datum+0(4).
  cc = l_val1+5(2).
  CONCATENATE dd cc INTO dd1.
  LOOP AT it_zcalendar WHERE sapweekno = dd1.
    CONCATENATE 'WEEK-' it_zcalendar-wfpweekno+4(2) INTO l_val1.
    CLEAR gt_fieldcat1.
    gt_fieldcat1-fieldname = 'WEEK1'.
    gt_fieldcat1-tabname = 'GT_OUT'.
    gt_fieldcat1-seltext_l = l_val1.
    APPEND gt_fieldcat1 TO gt_fieldcat.
  ENDLOOP.
  CLEAR : cc,dd1.
  cc = l_val2+5(2).
  CONCATENATE dd cc INTO dd1.
  LOOP AT it_zcalendar WHERE sapweekno = dd1.
    CONCATENATE 'WEEK-' it_zcalendar-wfpweekno+4(2) INTO l_val2.
    CLEAR gt_fieldcat1.
    gt_fieldcat1-fieldname = 'WEEK2'.
    gt_fieldcat1-tabname = 'GT_OUT'.
    gt_fieldcat1-seltext_l = l_val2.
    APPEND gt_fieldcat1 TO gt_fieldcat.
  ENDLOOP.
  CLEAR : cc,dd1.
  cc = l_val3+5(2).
  CONCATENATE dd cc INTO dd1.
  LOOP AT it_zcalendar WHERE sapweekno = dd1.
    CONCATENATE 'WEEK-' it_zcalendar-wfpweekno+4(2) INTO l_val3.
    CLEAR gt_fieldcat1.
    gt_fieldcat1-fieldname = 'WEEK3'.
    gt_fieldcat1-tabname = 'GT_OUT'.
    gt_fieldcat1-seltext_l = l_val3.
    APPEND gt_fieldcat1 TO gt_fieldcat.
  ENDLOOP.
  CLEAR : cc,dd1.
  cc = l_val4+5(2).
  CONCATENATE dd cc INTO dd1.
  LOOP AT it_zcalendar WHERE sapweekno = dd1.
    CONCATENATE 'WEEK-' it_zcalendar-wfpweekno+4(2) INTO l_val4.
    CLEAR gt_fieldcat1.
    gt_fieldcat1-fieldname = 'WEEK4'.
    gt_fieldcat1-tabname = 'GT_OUT'.
    gt_fieldcat1-seltext_l = l_val4.
    APPEND gt_fieldcat1 TO gt_fieldcat.
  ENDLOOP.
  CLEAR : cc,dd1.
  cc = l_val5+5(2).
  CONCATENATE dd cc INTO dd1.
  LOOP AT it_zcalendar WHERE sapweekno = dd1.
    CONCATENATE 'WEEK-' it_zcalendar-wfpweekno+4(2) INTO l_val5.
    CLEAR gt_fieldcat1.
    gt_fieldcat1-fieldname = 'WEEK5'.
    gt_fieldcat1-tabname = 'GT_OUT'.
    gt_fieldcat1-seltext_l = l_val5.
    APPEND gt_fieldcat1 TO gt_fieldcat.
  ENDLOOP.
  CLEAR : cc,dd1.
  cc = l_val6+5(2).
  CONCATENATE dd cc INTO dd1.
  LOOP AT it_zcalendar WHERE sapweekno = dd1.
    CONCATENATE 'WEEK-' it_zcalendar-wfpweekno+4(2) INTO l_val6.
    CLEAR gt_fieldcat1.
    gt_fieldcat1-fieldname = 'WEEK6'.
    gt_fieldcat1-tabname = 'GT_OUT'.
    gt_fieldcat1-seltext_l = l_val6.
    APPEND gt_fieldcat1 TO gt_fieldcat.
  ENDLOOP.
  CLEAR : cc,dd1.
  cc = l_val7+5(2).
  CONCATENATE dd cc INTO dd1.
  LOOP AT it_zcalendar WHERE sapweekno = dd1.
    CONCATENATE 'WEEK-' it_zcalendar-wfpweekno+4(2) INTO l_val7.
    CLEAR gt_fieldcat1.
    gt_fieldcat1-fieldname = 'WEEK7'.
    gt_fieldcat1-tabname = 'GT_OUT'.
    gt_fieldcat1-seltext_l = l_val7.
    APPEND gt_fieldcat1 TO gt_fieldcat.
  ENDLOOP.
  CLEAR : cc,dd1.
  cc = l_val8+5(2).
  CONCATENATE dd cc INTO dd1.
  LOOP AT it_zcalendar WHERE sapweekno = dd1.
    CONCATENATE 'WEEK-' it_zcalendar-wfpweekno+4(2) INTO l_val8.
    CLEAR gt_fieldcat1.
    gt_fieldcat1-fieldname = 'WEEK8'.
    gt_fieldcat1-tabname = 'GT_OUT'.
    gt_fieldcat1-seltext_l = l_val8.
    APPEND gt_fieldcat1 TO gt_fieldcat.
  ENDLOOP.
  CLEAR : cc,dd1.
  cc = l_val9+5(2).
  CONCATENATE dd cc INTO dd1.
  LOOP AT it_zcalendar WHERE sapweekno = dd1.
    CONCATENATE 'WEEK-' it_zcalendar-wfpweekno+4(2) INTO l_val9.
    CLEAR gt_fieldcat1.
    gt_fieldcat1-fieldname = 'WEEK9'.
    gt_fieldcat1-tabname = 'GT_OUT'.
    gt_fieldcat1-seltext_l = l_val9.
    APPEND gt_fieldcat1 TO gt_fieldcat.
  ENDLOOP.
  CLEAR : cc,dd1.
  cc = l_val10+5(2).
  CONCATENATE dd cc INTO dd1.
  LOOP AT it_zcalendar WHERE sapweekno = dd1.
    CONCATENATE 'WEEK-' it_zcalendar-wfpweekno+4(2) INTO l_val10.
    CLEAR gt_fieldcat1.
    gt_fieldcat1-fieldname = 'WEEK10'.
    gt_fieldcat1-tabname = 'GT_OUT'.
    gt_fieldcat1-seltext_l = l_val10.
    APPEND gt_fieldcat1 TO gt_fieldcat.
  ENDLOOP.
  CLEAR : cc,dd1.
  cc = l_val11+5(2).
  CONCATENATE dd cc INTO dd1.
  LOOP AT it_zcalendar WHERE sapweekno = dd1.
    CONCATENATE 'WEEK-' it_zcalendar-wfpweekno+4(2) INTO l_val11.
    CLEAR gt_fieldcat1.
    gt_fieldcat1-fieldname = 'WEEK11'.
    gt_fieldcat1-tabname = 'GT_OUT'.
    gt_fieldcat1-seltext_l = l_val11.
    APPEND gt_fieldcat1 TO gt_fieldcat.
  ENDLOOP.
  CLEAR : cc,dd1.
  cc = l_val12+5(2).
  CONCATENATE dd cc INTO dd1.
  LOOP AT it_zcalendar WHERE sapweekno = dd1.
    CONCATENATE 'WEEK-' it_zcalendar-wfpweekno+4(2) INTO l_val12.
    CLEAR gt_fieldcat1.
    gt_fieldcat1-fieldname = 'WEEK12'.
    gt_fieldcat1-tabname = 'GT_OUT'.
    gt_fieldcat1-seltext_l = l_val12.
    APPEND gt_fieldcat1 TO gt_fieldcat.
  ENDLOOP.
  CLEAR : cc,dd1.
  cc = l_val13+5(2).
  CONCATENATE dd cc INTO dd1.
  LOOP AT it_zcalendar WHERE sapweekno = dd1.
    CONCATENATE 'WEEK-' it_zcalendar-wfpweekno+4(2) INTO l_val13.
    CLEAR gt_fieldcat1.
    gt_fieldcat1-fieldname = 'WEEK13'.
    gt_fieldcat1-tabname = 'GT_OUT'.
    gt_fieldcat1-seltext_l = l_val13.
    APPEND gt_fieldcat1 TO gt_fieldcat.
  ENDLOOP.
ENDFORM.                    " build_fieldccatlog
*&      Form  13alv
      text
FORM 13alv .
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
   EXPORTING
  I_INTERFACE_CHECK              = ' '
  I_BYPASSING_BUFFER             =
  I_BUFFER_ACTIVE                = ' '
  I_CALLBACK_PROGRAM             = ' '
  I_CALLBACK_PF_STATUS_SET       = ' '
  I_CALLBACK_USER_COMMAND        = ' '
  I_STRUCTURE_NAME               =
  IS_LAYOUT                      =
      it_fieldcat                    = gt_fieldcat
  IT_EXCLUDING                   =
  IT_SPECIAL_GROUPS              =
  IT_SORT                        =
  IT_FILTER                      =
  IS_SEL_HIDE                    =
  I_DEFAULT                      = 'X'
  I_SAVE                         = ' '
  IS_VARIANT                     =
  IT_EVENTS                      =
  IT_EVENT_EXIT                  =
  IS_PRINT                       =
  IS_REPREP_ID                   =
  I_SCREEN_START_COLUMN          = 0
  I_SCREEN_START_LINE            = 0
  I_SCREEN_END_COLUMN            = 0
  I_SCREEN_END_LINE              = 0
IMPORTING
  E_EXIT_CAUSED_BY_CALLER        =
  ES_EXIT_CAUSED_BY_USER         =
    TABLES
      t_outtab                       = gt_out
EXCEPTIONS
  PROGRAM_ERROR                  = 1
  OTHERS                         = 2
ENDFORM.                                                    " 13alv
*&      Form  gt_out
      text
FORM gt_out .
  LOOP AT s_matnr.
    AT NEW low.
      gt_out-matnr = s_matnr-low.
************BEGIN OF FIRST WEEK******************************
      LOOP AT gt_pbed WHERE matnr = s_matnr-low AND perxx4(2) = l_val15(2).
        gt_out-week1 = gt_pbed-plnmg.
        LOOP AT it_zcalendar WHERE sapweekno = gt_pbed-perxx.
          IF p_mov = '321'.
            LOOP AT it_mkpf WHERE budat  GE it_zcalendar-startdt AND budat LE it_zcalendar-enddt.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '321'.
                it_tot1 = it_tot1 + it_mseg-erfmg.
                CLEAR it_mseg.
              ENDLOOP.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '322'.
                it_tot1_2 = it_tot1_2 + it_mseg-erfmg.
                CLEAR it_mseg.
              ENDLOOP.
            ENDLOOP.
          ENDIF.
          IF p_mov = '101'.
            LOOP AT it_mkpf WHERE budat  GE it_zcalendar-startdt AND budat LE it_zcalendar-enddt.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '101'.
                it_tot1 = it_tot1 + it_mseg-erfmg.
                CLEAR it_mseg.
              ENDLOOP.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '102'.
                it_tot1_2 = it_tot1_2 + it_mseg-erfmg.
                CLEAR it_mseg.
              ENDLOOP.
            ENDLOOP.
          ENDIF.
          IF p_mov = '131'.
            LOOP AT it_mkpf WHERE budat  GE it_zcalendar-startdt AND budat LE it_zcalendar-enddt.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '131'.
                it_tot1 = it_tot1 + it_mseg-erfmg.
                CLEAR it_mseg.
              ENDLOOP.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '132'.
                it_tot1_2 = it_tot1_2 + it_mseg-erfmg.
                CLEAR it_mseg.
              ENDLOOP.
            ENDLOOP.
          ENDIF.
          CLEAR gt_pbed.
        ENDLOOP.
      ENDLOOP.
      it_tot1 = it_tot1 - it_tot1_2.
      it_back1 = gt_out-week1 - it_tot1.
      CLEAR it_zcalendar.
END OF FIRST WEEK ************************
**********************SECOND WEEK***************************************
      LOOP AT gt_pbed WHERE matnr = s_matnr-low AND perxx4(2) = l_val25(2).
        int2 = int2 + 1.
        CHECK int2  = 1.
        gt_out-week2 = gt_pbed-plnmg.
        LOOP AT it_zcalendar WHERE sapweekno = gt_pbed-perxx.
          IF p_mov = '321'.
            LOOP AT it_mkpf WHERE budat  GE it_zcalendar-startdt AND budat LE it_zcalendar-enddt.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '321'.
                it_tot2 = it_tot2 + it_mseg-erfmg.
                CLEAR it_mseg.
              ENDLOOP.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '322'.
                it_tot2_2 = it_tot2_2 + it_mseg-erfmg.
                CLEAR it_mseg.
              ENDLOOP.
            ENDLOOP.
          ENDIF.
          IF p_mov = '101'.
            LOOP AT it_mkpf WHERE budat  GE it_zcalendar-startdt AND budat LE it_zcalendar-enddt.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '101'.
                it_tot2 = it_tot2 + it_mseg-erfmg.
                CLEAR it_mseg.
              ENDLOOP.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '102'.
                it_tot2_2 = it_tot2_2 + it_mseg-erfmg.
                CLEAR it_mseg.
              ENDLOOP.
            ENDLOOP.
          ENDIF.
          IF p_mov = '131'.
            LOOP AT it_mkpf WHERE budat  GE it_zcalendar-startdt AND budat LE it_zcalendar-enddt.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '131'.
                it_tot1 = it_tot1 + it_mseg-erfmg.
                CLEAR it_mseg.
              ENDLOOP.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '132'.
                it_tot1_2 = it_tot1_2 + it_mseg-erfmg.
                CLEAR it_mseg.
              ENDLOOP.
            ENDLOOP.
          ENDIF.
          CLEAR gt_pbed.
        ENDLOOP.
      ENDLOOP.
      it_tot2 = it_tot2 - it_tot2_2.
      it_back2 = gt_out-week2 - it_tot2.
      it_back2 = it_back2 + it_back1.
      CLEAR it_zcalendar.
********************************End of The Second week***********************************************
*********************Third week*************************************************************************
      LOOP AT gt_pbed WHERE matnr = s_matnr-low AND perxx4(2) = l_val35(2).
        int1 = int1 + 1.
        CHECK int1 =  1.
        gt_out-week3 = gt_pbed-plnmg.
        LOOP AT it_zcalendar WHERE sapweekno = gt_pbed-perxx.
          IF p_mov = '321'.
            LOOP AT it_mkpf WHERE budat  GE it_zcalendar-startdt AND budat LE it_zcalendar-enddt.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '321'.
                it_tot3 = it_tot3 + it_mseg-erfmg.
                CLEAR it_mseg.
              ENDLOOP.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '322'.
                it_tot3_2 = it_tot3_2 + it_mseg-erfmg.
                CLEAR it_mseg.
              ENDLOOP.
            ENDLOOP.
          ENDIF.
          IF p_mov = '101'.
            LOOP AT it_mkpf WHERE budat  GE it_zcalendar-startdt AND budat LE it_zcalendar-enddt.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '101'.
                it_tot3 = it_tot3 + it_mseg-erfmg.
                CLEAR it_mseg.
              ENDLOOP.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '102'.
                it_tot3_2 = it_tot3_2 + it_mseg-erfmg.
                CLEAR it_mseg.
              ENDLOOP.
            ENDLOOP.
          ENDIF.
          IF p_mov = '131'.
            LOOP AT it_mkpf WHERE budat  GE it_zcalendar-startdt AND budat LE it_zcalendar-enddt.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '131'.
                it_tot3 = it_tot3 + it_mseg-erfmg.
                CLEAR it_mseg.
              ENDLOOP.
              LOOP AT it_mseg WHERE mblnr = it_mkpf-mblnr AND matnr = s_matnr-low AND bwart = '132'.
                it_tot3_2 = it_tot3_2 + it_mseg-erfmg.
              

My first question to you would be ...you have defined the plant code as parameters so you can enter multiple plants...change that to a select-option and you would be able to display all the results.
Regards
Anurag

Similar Messages

  • Error when executing query its urgent

    hi,
    when iam executing my query in query designer through web morning i got the result in web.
    but when iam executing the same query in wad it is throughing an error like (System error in program SAPLRRK0 and form GET_FIELD_POSITION-01-))
    now again i check that one in querydesigner again it is showing the same error in querydesigner also
    vijay

    Hi,
    Refer Note 931975 - Problems when you execute a query
    Symptom
    At runtime, a query contains a generated ABAP program and a data structure, which is stored in the shared buffer. Due to the gap described here, the version of the ABAP program may not correspond to the version of the data structure.
    This causes several terminations when you execute this query:
    X299 Brain SAPLRRK0; Form GET_FIELD_POSITION-01-,
    X299 Brain SAPLRRK0; Form APPEND_KHANDLE_1-02-,
    ASSIGN COMPONENT L_FIELDNAME OF STRUCTURE C_SX_GVAR, and others.
    Other terms
    RSIX, SX_REPORT,
    Reason and Prerequisites
    The error can occur if one person changes a query and another person simultaneously executes the query. A query may also be changed implicitly if one of the objects used in the query is changed in another query.
    Solution
    The attached corrections apply only to Releases 3.X. An advance correction cannot be provided for NetWeaver 2004s.
    Before you implement the attached correction (in 3.X), you must change the two following method interfaces. Otherwise syntax errors occur in the CL_RSR_REPORT_RSIX class and the RRI0 function group when you implement the corrections.
    1. In Transaction SE24: Change the MODIFY method of the CL_RSR_REPORT_RSIX class as follows:
                  Insert the I_S_RKB1D import parameter with the type RSR_S_RKB1D.
    2. In Transaction SE24: Change the READ_SX_REPORT method of the CL_RSR_REPORT_RSIX class.
                  Delete all existing import parameters (that is, I_GENUNIID, I_DVERS, I_IDVERS and I_GENTIME) and insert the I_S_RKB1D import parameter with the type RSR_S_RKB1D.
    After you implement the corrections, you must delete the incorrect information in the shared buffer. To do this, enter '/$SYNC' in the command field in every application server. Alternatively, you can also call RSRT -> Environment -> Generate Queries. As a result, all queries are regenerated but all OLAP caches are rejected.
    BW 3.0B
               Import Support Package 31 for 3.0B (BW 3. 0B Patch 31 or SAPKW30B31) into your BW system. The Support Package is available when Note 0872272 "SAPBWNews BW 3.0B Support Package 31", which describes this Support Package in more detail, is released for customers.
    BW 3.10 Content
               Import Support Package 25 for 3.10 (BW 3. 10 Patch 25 or SAPKW31025) into your BW system. The Support Package is available when Note 0872274 "SAPBWNews BW 3.1 Content Support Package 25", which describes this Support Package in more detail, is released for customers.
    BW 3.50
               Import Support Package 17 for 3.5 (BW 3. 50 Patch 17 or SAPKW35017) into your BW system. The Support Package is available when Note 0872277 "SAPBWNews BW Support Package 17 NetWeaver'04 Stack 17", which describes this Support Package in more detail, is released for customers.
    SAP NetWeaver 2004s BI
               Import Support Package 08 for SAP NetWeaver 2004s BI (BI Patch 08 or SAPKW70008) into your BI system. The Support Package is available when Note 0872280 "SAPBINews BI 7.0 Support Package 08", which describes this Support Package in more detail, has been released for customers.
               In urgent cases, you can use the correction instructions.
    To provide information in advance, the notes mentioned above may be released before the Support Package is available. In this case, however, the short text of the notes still contains the words "preliminary version".
    Thanks

  • Want A query (Its Urgent)

    Hi,I have a table as below..
    AFPFTRAN
    code date type amt
    12 10-04-05 T 1
    13 11-05-05 F 2
    12 10-05-05 T 3
    13 05-04-05 F 4
    12 12-04-05 T 5
    13 15-05-05 F 7
    I want details as below:
    date
    Apr May ---
    code T F T F ---
    12 6 0 3 0
    13 0 4 0 9
    I want to get sum(amt) of T,F in particular month for particular emp.
    Hope...I'm clear now...
    Pls Its urgent

    use something like following
    select code, sum(decode(to_char(date, 'MM'), '01', decode(type, 'T', AMT, 0), 0)) Mon01_Type_T, sum(decode(to_char(date, 'MM', '02', decode(type, 'F', AMT, 0), 0)) Mon01_Type_F, .......(for all months and type)
    from Your_table_name
    group by code
    I hope it will work the way you want,
    Regards

  • Org Hierarchy Query(its urgent)

    Hii Gurus,
    Our client have the follwing requirement.
    They need to see the parent node of the 0ORGUNIT in a separate column.
    We do not know what it will take to accomplish this (enhancing 0ORGUNIT doesn't seem to be an option at this point),
    Can u give me other options so that we can get.
    As is:
    Table
    ClaenderYear/Month        Organizational unit
    JAN2008                             60006395
    JAN2008                                 20000000
    JAN2008                                    20000026
    JAN2008                                      20000040
    To be:
      Table
    ClaenderYear/Month        Organizational unit               Parent Node
    JAN2008                             60006395
    JAN2008                                 20000000                      60006395
    JAN2008                                    20000026                   20000000
    JAN2008                                      20000040                 20000026
    Thanks,
    Babu

    Yep that;s always the issue yeah when hierachy is activated in the report, all becomes messy.
    0ORGunit is master data. Add another info object "ZPORGUNIT", then reference this to 0ORGUNIT.
    Hope this helps.

  • Java-SQL Query, Its Urgent.....................

    hi,
    my problem is that i want to get data from the oracle database(SQL) and then put it into a JTABLE.
    The data seems to come correctly into the ResultSet rs Object, but i dont know how to put the data from the rs Object into the JTable.
    Please reply,

    Hi,
    If this is really important, I suggest that you post your question in the Swing Forums. As it is more appropriate for that forum, and you will get a quicker response.
    Damian Sutton.

  • How to transport ABAP Query

    Hi ,
        i would like to know if it's possible to transport ABAP Query from one server to another using CTS. eg: development server to test server. plus can we assign a transaction code to an ABAP Query.
    its very urgent.
    Plz respond.
    Rgds,
    BPNR....

    Hi Reddy,
    For the second part of question :
    When you create a abap query SAP generates a program at the background. You can copy that program to a Zprogram and assingn a Tcode to it.( You can add some more features to the report like drilldown etc.. )
    Your technical consultant should be able to help you out on this .
    Regards
    Balaji

  • ABAP QUERY STEPS

    Hi Friends,
    can i send me Creation of ABAP QUERY...
    REGARDS,

    What Is SAP Queries
    Many times a need arises for SAP Users and Functional Consultants to generate quick reports without getting any ABAP coding done – time taken to complete the coding in development, transport and test it in QA system and then transport to production – is sometimes too long. In such cases, ABAP/4 query is a tool provided by SAP for generating these kind of reports.
    Type of Report Desired:
    Before starting to write an ABAP query, its advisable to decide the type of report that the user wants. ABAP query provides the following type of reports:
    Basic List Simple report
    Statistics Report containing statistical functions like Average &Percentage
    Ranked List Report written for analytical purpose
    The output is always seen in the order of Basic List, then Statistics and then Ranked List if any. One ABAP query can have one basic list, maximum of 9 statistics and maximum of 9 ranked lists.
    In a nutshell, an ABAP/4 query can be designed in four steps
    - Creation of a user group
    - Creation of functional area
    - Assignment of user group to functional area
    - Creation of the query based on functional area
    The various objects that form an ABAP query can be created in the following 2 ways:
    - Tools => ABAP/4 Workbench => Utilities => ABAP/4 Query
    OR
    - By executing the transaction codes mentioned below:
    SQ01 ABAP/4 Query
    SQ02 Functional Area
    SQ03 User group
    Step I - Create Functional Area
    In the functional area section, the user indicates from which part of the SAP database the data is going to be retrieved and how the data is to be retrieved by the query. One functional area can be assigned to many user groups. A functional area can be created with or without a logical database. To create a functional area with a logical database, one has to mention the name of the database and then select the fields from the tables that form the logical database.
    ABAP Query Authorizations: To use an ABAP query, the user must have appropriate authorizations. Two ways of providing authorizations to the users are as follows:
    - User groups
    The user should be a part of at least one user group to run the corresponding ABAP query. This automatically restricts the access of the user to specific functional areas, and thus the corresponding underlying logical databases.
    - Authorizations
    The authorization object S_QUERY should be used to give proper authorizations to the user for a query. This authorization object has a field named ACTVT which can take values 02 for Change, 23 for Maintain and 67 for Translate.
    This value determines whether the user can create and modify the query. The possible authorizations in the object are as follows:
    S_QUERY_ALL Change, maintain and translate query
    S_QUERY_UPD Change and Translate
    Though the general concept of an ABAP query is moderately difficult, the results and the long term use of the ABAP query is worth the effort.
    Creating the ABAP Query
    To create the query use the menu path Environment => Queries
    · Give a name to the query and click on the Create button
    · Give the description of the query in the next screen. Specify the output length and select the processing option from the Further Processing Options box. The data can be displayed in various formats such as table, download to a file, and display in Word etc.
    · Click on the Next screen icon. Select the functional group screen. All the functional groups created in the functional area are displayed. Select the groups that you desire – fields from only these groups will be displayed in the output. Click on the respective check boxes and click on the Next Screen icon.
    · The Select Field screen gets displayed. Select all the fields from the user group that you need to display on the output of the query. If required, specify the short names for the fields using the menu path Edit => Short Names => Switch On/Off or you can also change the selection text contains in the order you want to appear on the selection screen. You can also maintain column headers for the fields by using the menu path Edit => Column Header => Maintain. 
    ·         Click on the Next Screen icon to get the Selections Screen. Here you can check against the fields that you require to be shown on the selection screen.
    ·         Now we need to specify the output type for the query as Basic List, Statistics or Ranked List. Choose the option Basic List.
    ·         On the Basic List line structure screen the following things can be done
    o        Specify the report layout in detail – lines on which the fields will appear.
    o        Order in which the fields will appear in the output
    o        Sort order for the fields – this is optional.
    o        For the numeric fields you can check against the fields for which you require totals in the output.
    o        Beautify the output according to the options provided.
    ·         Click on the next screen icon, to specify the control levels as mentioned below
    o        Specify the sort order. The default sort order is ascending and can be changed to descending if required.
    o        Totals for each field selected for sorting can be displayed
    o        To display the output of a field in a box click on the check box against box. To display a line after the output of a field, click on the check box against BlnkLn
    o        To display the output of a field on a new page click on the check box against New Page
    ·         Click on the next screen icon to get the List Line options Screen. Here you can specify the background color for displaying the output.
    ·         Click on the next screen icon to get the Field Output Option screen. In this you can specify the following:
    o        Change the output length or the display positions of the fields
    o        Specify the display position of the unit for quantity or currency fields. Click left radio button to display it before the figure, middle radio button to display it after the figure while last radio button to hide the unit altogether.
    o        Specify color for the column of every field under the Format option.
    o        Specify the label against the output of sort fields.
    ·         Click on the Next screen option to go to the Basic List Header screen. Here you can specify
    o        Give page header and page footer for the output
    o        Include user name and date by specifying &N and &D respectively.
    After providing all the above options you can save the query and execute it by clicking the Execute button twice
    Regards,
    Maha

  • Hi All how to add new payscale  for an employee in sap hr-abap,its urgent

    Hi All ,
    how to add new payscale for an employee  in sap hr-abap,its urgent.
    Message was edited by:
            bharat kumar
    Message was edited by:
            bharat kumar

    Hi
    If that field which you wants to add is available in one of the structures like EKKO,EKPO then you can add that field just beside the other fields
    If that field is not there in the any of the structures then you can define a variable using define command
    /: DEFINE  &VAR&
    / &VAR&  = <some value>
    or you can write subroutines to fetch the data from outside tables and can use those fields data in the script
    <b>Reward points for useful Answers</b>
    Regards
    Anji

  • Hi All,Please send me abap-hr material .Its urgent please.

    Hi All,Please send me abap-hr material .Its urgent please.

    These are the FAQ's that might helps you
    http://www.sap-img.com/human/hr-faq.htm
    http://www.sapgenie.com/faq/hr.htm
    http://www.sapgenie.com/sapfunc/index.htm
    http://www.sap-img.com/abap/sample-hr-reports-allocate-petrol-allowance.htm
    http://www.sap-img.com/hr021.htm
    http://www.sap-img.com/human/hr-faq.htm
    http://www.sap-img.com/human/finding-the-list-of-hr-module-tables.htm
    additional info......
    Download the ABAP e-book for HR in the below link under the section 'Free ABAP eBook Download'
    http://www.sap-img.com
    Also have a look at the following links-
    http://www.sapbrain.com/TUTORIALS/FUNCTIONAL/HR_tutorial.html
    http://www.sapdevelopment.co.uk/hr/hrhome.htm
    http://planetsap.com/index.htm
    http://www.atomhr.com/library_full.htm
    http://www.sap-basis-abap.com/saphr.htm
    http://help.sap.com/saphelp_erp2005/helpdata/en/60/d8d8c7576311d189270000e8322f96/frameset.htm
    http://www.sapfriends.com/sapstuff.html
    http://www.atomhr.com/know_preview/Reading_Payroll_Results_with_ABAP.htm
    http://searchsap.techtarget.com/originalContent/0,289142,sid21_gci1030179,00.html?track=NL-142&ad=500911#Payroll
    http://www.sap-press.com/product.cfm?account=&product=H967
    http://www.sapdevelopment.co.uk/hr/payres_abap.htm
    http://www.sapdevelopment.co.uk/hr/payres_tcode.htm
    http://help.sap.com/printdocu/core/Print46c/en/Data/Index_en.htm
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/PAPA/PAPA.pdf
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/PAPD/PAPD.pdf
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/PYINT/PYINT_BASICS.pdf
    http://www.atomhr.com/training/Technical_Topics_in_HR.htm
    http://www.planetsap.com/hr_abap_main_page.htm
    you can see some Standard Program examples in this one..
    http://www.sapdevelopment.co.uk/programs/programshr.htm
    http://searchsap.techtarget.com/originalContent/0,289142,sid21_gci1030179,00.html?Offer=SAlgwn12604#Certification

  • Urgent Requirement-- ABAP Query

    Hi,
    I have a developed ABAP Query by the name "YCOPM_Bill_PUR".
    In this query, I have an additional field "indicator". For this field, there is some code written, wherein either of the values "N" or "O" are assigned to this "indiactor" field. Now, the query should generate the output, only when indicator = N i.e. only those records should be displayed in the output for which the indicator field has value 'N'.
    Records having indicator field value as "O", should not be displayed.
    I want to know the place where I can write this condition and keep a control on the records displayed in the output.
    Currently, the query output displays all records (irrespective of whether indicator = 'N' or 'O').
    I have added the field indicator on the selection screen.
    But, I want to know where can I write the condition :
    if indicator = 'N'.
    endif.
    In "SQ02", there would be some place where i can write the above condition so that the output is trigerred only for those particular records. If possible, please do let me know.
    In short, I need to know, where are the output fields getting populated and where can I write this code to control the output.
    Please help me out.
    Thanks & Regards,
    Tejas Savla

    Hi Pooja,
                  Thanks a lot for your quick reply.
    I have done the same . i.e. i have written the code for that particular field (indicator) in SQ02 and generated the infoset. Now, the correct value ('O' or 'N') gets assigned to the indicator field.
    But, my problem is different.
    I need to find the location, where the all the output(report output) fields are getting populated, so that I can place a condition on my additional field (indicator) and control the fields to be displayed in the output.
    In short, I need to know, if there exists a location where I can place a condition such as "Display the output, only if field indicator = 'O' ".
    I hope you got my query.
    Thanks in advance.
    Regards,
    Tejas Savla

  • ABAP QUERY - Urgent

    Hello Friends,
    I have used SQVI for ABAP query but look slike it is only for inner join.
    Is there a way that I could do left outer join, or any other way.
    Please suggest.
    Ster

    hi Ster,
    in SQVI there is this graphical tool to link the tables. Just right click the thin line between the two fileds and choose 'left outer join'
    hope this helps
    ec

  • Transport abap query from one client to another--v--urgent---v----urgent

    hi,
    i have an abap query in one client and want to copy to another client.can i do this if so what are the steps involved .i tried the options like in query go to environment and then to transport .i also tried to do by running the programe RSAQR3TR.but it was transporting in the same client .i want to transfer into another client.plz help me out asap .

    hi,
    Create a request related to that Table Definition and add data content in the request like
    R3TR-TABL-<table name>
    R3TR-TABU-<table name>
    R3TR-TABD-<table name>
    and release the request
    Take the DATA files and CO files related to that request in a Pen drive and put the same into the new server DATA and CO files and import using STMS.
    For new program, it gets transported along with the program.
    For changed program (which has already been transported once), you need to include texts in transport request - just go to Selection texts, save them in the transport request and you're all set.
    whenever you assign a request number to the program
    and also the selection texts willbe stored under that request number
    so when u release the program
    the selection texts will also go
    after releasing the request if you change only the seleciton texts
    only the changes done to selection texts will reach the target
    and the rest of the things remain same
    so when ever you release a request all the things under that request
    will go

  • ABAP QUERY PROGRAM OUTPUT SHOULD DISPLAY FROM SAP SCRIPT.

    THIS IS MY URGENT REQUIREMENT ...
    I DONT KNOW ABAP QUERY PROGRAM ..
    PLEASE SUGGEST ME A WAY ON THIS ....
    Functional requirements
    Introduction
    The wish of the customer is a printable customer overview. All desired fields will be shown in a new query called ZZADDRSS_CO. Double entries are taken for granted because of the data taken from the sales area and because of multiple contact persons. The customer accepts this. It should be made possible that the user creates and saves its own variant.
    A second overview is needed, another ABAP will be developed for this requirement. This ABAP will show all the customer data and this list will have the possibility to be printed.
    Solution
    New Query ZZADDRESS_CO
    The desired fields of attachment 1 need to be shown in the query.
    The selection criteria are shown in attachment 2.
    The column names of the additional data have to changed in the query.
    Customer Overview.
    Functional specification.
    On behalf of this customer overview a standard SAP transaction will be used (transaction VC/2).This transaction will be extended.
    The fields are shown on screen with the described headers. Printing of the overview will be done via SAP script. The script makes use of a fixed layout of the data.
    The selection criteria are specified in attachment 2.
    The layout of the customer overview and the SAP Script are specified in attachment 3.
    Specification.
    The next steps need to be performed.
    1.     A routine per infoblock need to be created in Include RV77UNNN. In this routine the data is retrieved and written down to the screen and script,
    Example LST1_901 . In include RV77SNNN you can find the standard infoblocks.
    2.     Adapt via transaction SE16 table TFRM.
    3.     Create a new view in the customizing (sales and distribution- Sales support-sales summary-Assign Reporting Views).Assign the new view to the infoblocks.(Example view 001 is assigned to block 901).
    4.     In customizing it is not possible to assign the correct window and element to the infoblock .so this is done via SE16 in table T182A.
    5.     Adapt script. Copy script SD-SALES-SUMMARY to a Z-SALES_SUMM.
    Assign this new version to the new view in customizing. Create in the main window the element who writes the data on behalf of the print.
    Attachment 1 Desired fields
    Header: Address
    ~ Customer number                          KNA1-KUNNR
    ~ Title                                               KAN1-ANRED
    ~ Name1                                           ADRC-NAME1
    ~ Name2                        ADRC-NAME2
    ~ Name3                                           ADRC-NAME3
    ~ Name4                                           ADRC-NAME4
    ~ PO Box                                         ADRC-PO_BOX
    ~ PO Box POSTAL CODE             ADRC-POST_CODE2
    ~ PO Box city                                  ADRC-PO_BOX_LOC
    ~ Telephone no1                              ADR2-TEL_NUMBER   1ST RECORD
    ~ Telephone no2                              ADR2-TEL_NUMBER   2ND RECORD
    ~ Fax number1                                 ADR3-FAX_NUMBER 1ST RECORD
    ~ Fax number2                                ADR3-FAX_NUMBER 2ND RECORD
    ~ E-mail                                            ADR6-SMTP_ADDR
    ~ Search item                                   ADRC-SORT1
    ~ Notes                                            ADRT-REMARK
    Header: control data
    ~ VAT registration number              KAN1-STCEG
    Header: Payment transactions
    ~Bank country key                         KNBK-BANKS
    ~Bank key                                      KNBK-BANKL
    ~Bank Account number                 KNBK-BANKN
    Header: Marketing
    ~ Industry key                                   KNA1-BRSCH
    ~ Industry code 1                              KNA1-BRAN1
    ~ Industry code 2                              KNA1-BRAN2
    ~ Industry code 3                                KNA1-BRAN3
    ~ Industry code 4                                KNA1-BRAN4
    ~ Industry code 5                               KNA1-BRAN5
    ~Annual sales, currency, year           KNA1-UMSA1, KNA1-UWAER, KNA1-UMAH
    ~ Yearly no of employees, year      KAN1-JMZAH, KNA1-JMJAH       
    ~ Fiscal year variant                          KNA1-PERIV
    ~Legal status                                      KNA1-GFORM
    Header: Correspondence
    ~ Our account number at customer            KNB1-EIKTO
    Header: sales
    ~ Sales office                                              KNVV-VKBUR
    ~ Customer group                                       KNVV-KDGRP
    ~ ABC-classification                                  KNVV-KLABC
    Header: Invoice
    ~Tax classification                          KNVI-TAXKD
    ~Terms of payment key                    KNVV-ZTERM
    ~
    Header: Contact Persons
    ~Title                                   KNVK-ANRED
    ~Name                                   KNVK-NAME1
    ~Advertising material                         KNVK-NMAIL
    ~Martial Status                         KNVK-FAMST
    ~Notes                                   KNVK-PARAU
    ~Function                              KNVK-PAFKT
    ~Department                              KNVK-ABTNR
    Header: Partnerroles
    ~Personnel Number                         KNVP-PERNR
    ~Name of employee                         PA0001-ENAME
    Header: Additional Data
    ~Attribute 1                              KNA1-KATR1
    ~Creation date                              KNA1-ERDAT
    ~Attribute 2                              KNA1-KATR2
    ~Change date of field KNA1-KATR2          CDHDR-UDATE
    ~Attribute 3                              KNA1-KATR3
    ~Attribute 4                              KNA1-KATR4          
    ~Attribute 5                              KNA1-KATR5
    ~Attribute 6                              KNA1-KATR6
    Attachment 2 Selection fields
    ~Customer number
    ~Sales office
    ~Personnel Number
    ~Sales Organization (default NL01)
    ~Industry key
    ~Industry codes (1 till 5)
    ~ABC- classification
    ~Creation date
    ~Attribute 1
    ~Attribute 2
    ~Attribute 3
    ~Attribute 4
    ~Attribute 5
    Attachment 3 Customer overview + SAP Script
    Customer master data sheet: 11490                 Page1
    Requested by karen Dunnewold                Date: 25.08.2004
    Address
    (Default SAP script ADDRESS statement)
    Title
    Name1
    Street + number
    PO Box city
    Country
    Search term: ADRC-SORT1
    Telephone 1:      ADR2-TEL_NUMBER     2: ADR2-TEL_NUMBER
    Fax 1:          ADR3-FAX_NUMBER     2: ADR3-FAX_NUMBER
    E-mail:          ADR6-SMTP_ADDR     
    Notes:           ADRT-REMARK
    PO BOX
    ADRC-PO_BOX
    ADRC-POST_CODE2 ADRC-PO_BOX_LOC
    T005T-LANDX (T005T-LAND1 = ADRC-COUNTRY)
    Control data
    VAT registration number:     KNA1-STCEG
    Payment transactions
    Country: KNBK-BANKS Bank-key: KNBK u2013 BANKL Bank account: KNBK-BANKN
    Marketing
    Industry           KNA1-BRSCH     Industry Description
    Industry code1          KNA1-BRAN1     Industry Description
    Industry code2          KNA1-BRAN2     Industry Description
    Industry code3          KNA1-BRAN3     Industry Description
    Industry code4          KNA1-BRAN4     Industry Description
    Industry code5          KNA1-BRAN5     Industry Description
    Figures
    Annual Sales          KNA1-UMSA1, KNA1-UWAER in KNA1-UMAH
    Employees          KNA1-JMZAH                         in KNA1-JMJAH
    Legal status            KNA1-GFORM description
    Customer master data sheet 11490                         Page 2
    Requested by karen Dunnewold                         Date: 25.08.2004
    Contact Persons
    KNVK-ANRED
    Mailings: KNVK-NMAIL           Notes: KNVK-PARAU
    KNVK-ANRED
    Mailings: KNVK-NMAIL           Notes: KNVK-PARAU
    Correspondence
    Our account number at customer      KNB1-EIKTO
    Sales
    Sales office          KNVV-VKBUR     Description
    Customer group     KNVV-KDGRP     Description
    ABC-classify          KNVV-KLABC
    Currency          KNVV-WAERS
    Invoice
    Terms of payment key KNVV-ZTERM      Tax classification KNV1-TAXKD
                                  Description     
    Partner (Leave SAP default)
    Partnerrole               Number          Name
    KNVP-PARVW          KNVP-KUNNR     NAME1
    KNVP-PARVW          KNVP-KUNNR     NAME1
    Additional data
    Attribute1          kna1-katr1     Description
    Attribute2          kna1-katr2     Description
    Attribute3          kna1-katr3     Description
    Attribute4          kna1-katr4     Description
    Attribute5          kna1-katr5     Description
    Attribute6          kna1-katr6     Description

    hi narayana
    i think u need to write a driving program and a provided with a smatform u sit along with the SD consultant.
    ur further views can be shared.
    Rgs,
    Venkat.

  • ABAP query problem.

    Hi All,
    I have one ABAP query which has been created for vendor details. Its using standard sap LDB KDF. Now there are some fields in vendor classification which are not there in LDB. so i need to add these fields in ABAP query.
    those fields are in other tables, ehich are not been used in standard LDB.
    Can anybody suggest me. Its really urgent issue.
    Regards
    Azad.
    If any further clarification required about the problem please get back to me.

    Azad,
    You will need to change the Infoset using tcode SQ02 (Probably copy current infoset and change in the new one), in new info set you can add tables and even custom fields with ABAP code behind them.
    Thanks.

  • ABAP Query(HR)

    I am using ABAP query using LDB. I want to fetch the record(current) within a particular dates for the corresponding pernr.
    But when i gives validity dates it fetches all the record for the particular pernr.
    Actually our requirement is to display only current status record for particular date periods.
    Plz help.Its urgent.

    Hi
    use the following code
    GET PERNR.
    <b>rp_provide_from_last p0001 space pnpbegda pnpendda.</b>
    this will fetch the only last record for that PERNR.
    use this and see
    <b>Reward points for useful Answers</b>
    Regards
    Anji

Maybe you are looking for

  • Import java.*; question

    Hi, My understanding of the import keyword is somewhat similar to includes in C/C++ but the "*" is somewhat confusing. Is it not a wildcard meaning to 'include' all that is necessary in the subcategories? For example, I quite often see import java.aw

  • Is it possible to Change the pooling interval time in XI3.0 or XI3.1

    Hi, For every 15 sec the CMS will check the scheduled jobs status and act accordingly ,by default the value will be 15 sec now We want to change the pooling interval time to 1 min. -- Where do i have to change the pooling interval time. -- Is it poss

  • DTP-ABAP run time error- Urgent

    Hi All I had put Sales order as the key in my COPA DSO,due to which i was getting summarised records, nw i removed this key and put the Lowest granular detail key and i.e BW doc # (0doc_num) & then i have activated my DSO.Now when i do the DTP frm CO

  • Initialisation data load failure

    Hi all, My initialisation data load for 0EC_PCA_3 failed with an error message "Selected No does not agree with transferred no." , the data processing is ok. I am pasting the shrot dump from the source system below. Error analysis                    

  • I don´t get any Java Script referral on the: Exc in ev handl: Error: Bad NPObject as private data, what is then my problem?

    Exc in ev handl: Error: Bad NPObject as private data This is the pop up that keeps annoying me in FF. You send me the question: The box that the error is in says something about JavaScript? I´m answering NO!