How to use collect statement properly

In PBID table , i will get 4 rows for a material . I will get the corresponding values of bdzei from the same table . Now i will pass this bdzei into pbhi table. then i will get some 200 rows of data. I have to sum up the field plnmg , by grouping the laeda field of pbhi. In short, i need to know the sum of pbhi-plnmg for a particular pbhi-laeda . I know a way to do it. But i want to know how to use the COLLECT statement for this purpose. My output should contain oly 1 line for 1 material ..
PBID table                      
Matnr   BDZEI
p4471   457
        1002
        2309
        2493
PBHI table
BDZEI     LAEDA         PLNMG
1002     06.08.2004     0.000          
1002     06.08.2004     83.000
457      07.08.2004     12.000          
457     07.08.2004     24.000
Reqd O/p
MATNR   LAEDA        PLNMG
p4471  06.08.2004    83
p4471  07.08.2004    36
Hope u understood my situation .please help me out ...
Thanking you in advance ..
Shankar

REPORT zppr_zpipr NO STANDARD PAGE HEADING LINE-SIZE 150 LINE-COUNT 63.
TABLES: pbid,
        pbhi,
        makt,
        mseg,
        mkpf.
DATA: BEGIN OF it_pbid OCCURS 0,
      matnr LIKE pbid-matnr,        " Material
      status TYPE c LENGTH 4,       " For distinguishing materials from pbid and pbim .. will contain space for PBID and 'PBIM' for PBIM
      bdzei LIKE pbid-bdzei,
      laeda LIKE pbhi-laeda,
end of it_pbid.
DATA: BEGIN OF it_pbim OCCURS 0,
      matnr LIKE pbid-matnr,        " Material
      status TYPE c LENGTH 4,       " For distinguishing materials from pbid and pbim .. will contain space for PBID and 'PBIM' for PBIM
      bdzei LIKE pbim-bdzei,
      laeda LIKE pbhi-laeda,
end of it_pbim.
DATA: BEGIN OF it_pbid_pbim OCCURS 0,
      matnr LIKE pbid-matnr,        " Material
      laeda LIKE pbhi-laeda,        " Reduction Date
      dbmng LIKE pbhi-dbmng,        " Planned quantity in the data base
      plnmg LIKE pbhi-plnmg,        " Planned quantity
      status TYPE c LENGTH 4,       " For distinguishing materials from pbid and pbim .. will contain space for PBID and 'PBIM' for PBIM
      mblnr LIKE mseg-mblnr,        " Material Doc Number
      pbfnr LIKE pbid-pbdnr,        " Plan Number
      maktx LIKE makt-maktx,         " Matl Desc
      aenam LIKE pbhi-aenam,        " User Changed
      erfmg LIKE mseg-erfmg,        " Qty Invoiced
      budat LIKE mkpf-budat,        " Invoice date
      bdzei LIKE pbid-bdzei,        " Independent requirements pointer
      werks LIKE pbid-werks,        " plant
      pirrednqty TYPE i,            " PIR Reduction Quantity        = pbih-plnmg - pbih-dbmng
      diff TYPE i,                  " Difference
      slno TYPE i,                  " Sl No
END OF it_pbid_pbim.
DATA: BEGIN OF it_allrows OCCURS 0.
        INCLUDE STRUCTURE it_pbid_pbim.
DATA: END OF it_allrows.
*DATA: BEGIN OF it_final OCCURS 0.
       INCLUDE STRUCTURE it_pbid_pbim.
*DATA: END OF it_final.
DATA: BEGIN OF line,
      matnr LIKE pbid-matnr,        " Material
      laeda LIKE pbhi-laeda,        " Reduction Date
      plnmg LIKE pbhi-plnmg,        " Planned quantity
      maktx LIKE makt-maktx,        " Matl Desc
      dbmng LIKE pbhi-dbmng,        " Planned quantity in the data base
      mblnr LIKE mseg-mblnr,        " Material Doc Number
      pbfnr LIKE pbid-pbdnr,        " Plan Number
      aenam LIKE pbhi-aenam,        " User Changed
      erfmg LIKE mseg-erfmg,        " Qty Invoiced
      budat LIKE mkpf-budat,        " Invoice date
      bdzei LIKE pbid-bdzei,        " Independent requirements pointer
      werks LIKE pbid-werks,        " plant
      pirrednqty TYPE i,            " PIR Reduction Quantity        = pbih-plnmg - pbih-dbmng
      diff TYPE i,                  " Difference
      slno TYPE i,                  " Sl No
      status TYPE c LENGTH 4,       " For distinguishing materials from pbid and pbim .. will contain space for PBID and 'PBIM' for PBIM
END OF line.
DATA Itfinal1 LIKE STANDARD TABLE
            OF LINE
          WITH DEFAULT KEY.
DATA ITfinal LIKE ITfinal1.
DATA: BEGIN OF it_dates OCCURS 0,
      date TYPE sy-datum,
END OF it_dates.
DATA: l_slno TYPE i.
DATA: l_zebra TYPE c.
SELECT-OPTIONS:
      s_werks FOR pbid-werks obligatory.
SELECT-OPTIONS:
      s_matnr FOR pbid-matnr.
SELECT-OPTIONS:
      s_pbdnr FOR pbid-pbdnr.
SELECT-OPTIONS:
      s_laeda FOR pbhi-laeda obligatory.
parameter:
      c_print type checkbox.
SELECT matnr bdzei FROM pbid INTO (it_pbid-matnr, it_pbid-bdzei) WHERE werks IN s_werks AND matnr IN s_matnr AND pbdnr IN s_pbdnr.
  it_pbid-status = 'PBID'.
  APPEND it_pbid.
move-corresponding it_pbid to it_pbid_pbim.
Append it_pbid_pbim.
ENDSELECT.
SELECT matnr bdzei FROM pbim INTO  (it_pbim-matnr,it_pbim-bdzei) WHERE werks IN s_werks AND matnr IN s_matnr AND pbdnr IN s_pbdnr.
  APPEND it_pbim.
Append it_pbid_pbim.
ENDSELECT.
*break-point.
START-OF-SELECTION.
  LOOP AT s_laeda.
    it_dates-date = s_laeda-low.
    APPEND it_dates.
  ENDLOOP.
  DATA: l_startdate LIKE sy-datum.
  IF s_laeda-high EQ space.
  ELSE.
    l_startdate = s_laeda-low + 1.
    DO.
      IF l_startdate <= s_laeda-high.
        it_dates-date = l_startdate.
        APPEND it_dates.
      ELSE.
        it_dates-date = sy-datum.
        EXIT.
      ENDIF.
      l_startdate = l_startdate + 1.
    ENDDO.
  ENDIF.
*break-point.
  LOOP AT it_pbim.
    LOOP AT it_dates.
      it_pbim-laeda = it_dates-date.
      it_pbim-status = 'PBIM'.
      MODIFY it_pbim TRANSPORTING laeda status.
      MOVE-CORRESPONDING it_pbim TO it_pbid_pbim.
      APPEND it_pbid_pbim.
    ENDLOOP.
  ENDLOOP.
break-point.
  l_zebra = 'X'.
  DATA: l_toterfmg LIKE mseg-erfmg.
  DATA: l_erfmg LIKE mseg-erfmg.
  data: l_totpir type i.
**************************************PBID*************************************
  LOOP AT it_pbid.
    move-corresponding it_pbid to it_pbid_pbim.
       append it_pbid_pbim.
    SELECT SINGLE maktx FROM makt INTO (it_pbid_pbim-maktx) WHERE matnr = it_pbid-matnr.
    MODIFY table it_pbid_pbim TRANSPORTING maktx.
    SELECT aenam laeda FROM pbhi INTO (it_pbid_pbim-aenam,it_pbid_pbim-laeda) WHERE bdzei = it_pbid-bdzei AND aenam = 'Abbau-'.
       MODIFY TABLE it_pbid_pbim TRANSPORTING aenam laeda. " debug here
    select single sum( dbmng )  sum( plnmg ) FROM pbhi INTO (it_pbid_pbim-dbmng,it_pbid_pbim-plnmg) WHERE bdzei = it_pbid-bdzei AND aenam = 'Abbau-' and laeda = it_pbid_pbim-laeda..
       MODIFY TABLE it_pbid_pbim TRANSPORTING dbmng plnmg. " debug here
   endselect.
    it_pbid_pbim-pirrednqty = it_pbid_pbim-dbmng - it_pbid_pbim-plnmg.
       MODIFY table it_pbid_pbim TRANSPORTING pirrednqty.
    IF ( it_pbid_pbim-laeda IN s_laeda AND it_pbid_pbim-aenam EQ 'Abbau-' ).
      MOVE-CORRESPONDING it_pbid_pbim TO it_allrows.
      append it_allrows.
    ELSEIF NOT it_pbid_pbim-laeda IN s_laeda.
          delete it_pbid_pbim index sy-tabix.           " debug here
    ENDIF.
    ENDSELECT.
  ENDLOOP.
**************************************PBIM*************************************
  LOOP AT it_pbim.
    move-corresponding it_pbim to it_pbid_pbim.
       append it_pbid_pbim.
    SELECT SINGLE maktx FROM makt INTO (it_pbid_pbim-maktx) WHERE matnr = it_pbim-matnr.
       MODIFY table it_pbid_pbim TRANSPORTING maktx.
    SELECT aenam laeda FROM pbhi INTO (it_pbid_pbim-aenam,it_pbid_pbim-laeda) WHERE bdzei = it_pbim-bdzei AND aenam = 'Abbau-'.
       MODIFY TABLE it_pbid_pbim TRANSPORTING aenam laeda. " debug here
    select single sum( dbmng )  sum( plnmg ) FROM pbhi INTO (it_pbid_pbim-dbmng,it_pbid_pbim-plnmg) WHERE bdzei = it_pbim-bdzei AND aenam = 'Abbau-' and laeda = it_pbid_pbim-laeda..
       MODIFY TABLE it_pbid_pbim TRANSPORTING dbmng plnmg. " debug here
    it_pbid_pbim-pirrednqty = it_pbid_pbim-dbmng - it_pbid_pbim-plnmg.
       MODIFY table it_pbid_pbim TRANSPORTING pirrednqty.
    IF ( it_pbid_pbim-laeda IN s_laeda AND it_pbid_pbim-aenam EQ 'Abbau-' ).
      MOVE-CORRESPONDING it_pbid_pbim TO it_allrows.
      append it_allrows.
    ELSEIF NOT it_pbid_pbim-laeda IN s_laeda.
          delete it_pbid_pbim index sy-tabix.           " debug here
    ENDIF.
    ENDSELECT.
  ENDLOOP.
sort it_allrows by matnr laeda status.
**********************************ALL ROWS************************
loop at it_allrows.
  line-matnr = it_allrows-matnr.
  line-laeda = it_allrows-laeda.
  line-plnmg = it_allrows-plnmg.
  line-dbmng = it_allrows-dbmng.
line-mblnr = it_allrows-mblnr.
line-pbfnr = it_allrows-pbfnr.
  line-maktx = it_allrows-maktx.
line-aenam = it_allrows-aenam.
line-erfmg = it_allrows-erfmg.
line-budat = it_allrows-budat.
  line-bdzei = it_allrows-bdzei.
line-werks = it_allrows-werks.
  line-pirrednqty = it_allrows-pirrednqty.
  line-diff = it_allrows-diff.
  line-slno = it_allrows-slno.
  line-status = it_allrows-status.
  collect line into itfinal1.
endloop.
loop at itfinal1 into line.
  collect line into itfinal.
    write: / line-matnr, line-plnmg, line-dbmng,line-laeda,line-status..
endloop.
skip 4.
loop at itfinal into line.
  write: / line-matnr, line-plnmg, line-dbmng,line-laeda,line-status..
endloop.
break-point.

Similar Messages

  • How to use collect statement for below

    data : begin of itab,
             n(3) type c,
          n1 type n,
          k(5) type c,
          end of itab.
    select n n1 from into itab table /zteest.
    *internal table has
    n      n1    k
    gar    100  uji
    hae    90   iou
    gar    90   uji
    hae    87   iou
    I want
    gar 190
    hae 177
    How to use collect statement as n1 is n ..?
    let me know..
    Thanks

    try this..
    DATA : BEGIN OF itab OCCURS 0,
    n(3) TYPE c,
    n1(3) TYPE p DECIMALS 2,
    k(5) TYPE c,
    END OF itab.
    itab-n = 'gar'.
    itab-n1 = 100.
    itab-k = 'uji'.
    COLLECT itab .CLEAR itab.
    itab-n = 'hae'.
    itab-n1 = 90.
    itab-k = 'iou'.
    COLLECT itab .CLEAR itab.
    itab-n = 'gar'.
    itab-n1 = 90.
    itab-k = 'uji'.
    COLLECT itab .CLEAR itab.
    itab-n = 'hae'.
    itab-n1 = 87.
    itab-k = 'iou'.
    COLLECT itab .CLEAR itab.

  • How to use collect statement

    hi everybody,
    how to use collect statement to get the total amount paid to different vendor payments 
    data : begin of wa occurs 0,
            bukrs type bsak-bukrs,
            lifnr type bsak-lifnr,
            land1 type lfa1-land1,
            name1 like lfa1-name1,
            dmbtr like bsak-dmbtr,
            count type i value 0,
            tot_vend  type i,
            vend type i.
    data :end of wa.
    data : itab like table of wa.
      select distinct bukrs lifnr waers from bsak into
    corresponding fields of wa
              where bukrs in s_bukrs
              and   lifnr in s_lifnr
              and   bschl in s_bschl.
    i want the total amount paid according to vendor i am  using this way but i am not getting
      loop at itab into wa.
    wa-dmbtr = bsak-dmbtr.
    collect wa-dmbtr into itab.
    modify itab from wa transporting dmbtr.
    i am unalbe to get it
    can anybody help me regarding this if possible with example.
    thanks in advance,
    regards,
    venu.

    Hi Venu,
    types: BEGIN OF ty,
            NAME(20),
            SALES TYPE I,
          END   OF ty.
    data : itab type standard table of ty,
    itab1 type standard table of ty,
    wa type ty,
    wa1 type ty.
    wa-NAME = 'Duck'.  wa-SALES = 10.
    append wa to itab.
    wa-NAME = 'Tiger'. wa-SALES = 20.
    append wa to itab.
    wa-NAME = 'Duck'.  wa-SALES = 30.
    append wa to itab.
    loop at itab into wa.
    wa1 = wa.
    collect wa1 into itab1.
    endloop.
    loop at itab1 into wa1.
    write : / wa1-name , wa1-sales.
    endloop.
    COLLECT is used to create unique or compressed datsets. The key fields are the default key fields of the internal table itab .
    If you use only COLLECT to fill an internal table, COLLECT makes sure that the internal table does not contain two entries with the same default key fields.
    <b>If, besides its default key fields, the internal table contains number fields (see also ABAP/4 number types ), the contents of these number fields are added together if the internal table already contains an entry with the same key fields.</b>
    If the default key of an internal table processed with COLLECT is blank, all the values are added up in the first table line.
    In the program you mentioned yesterday,I am not able to get the logic since many lines are commented.

  • How to use perform statements in sap scripts

    how to use perform statements in sap scripts . and pls send me one progam for this
    thnaks
    raja

    Hi Raja,
    <b>PERFORM</b> key work is used to include subroutine in sapscript form...
    But the processing is lttle bit different form the one we use in ABAP.
    Here the paramters passed to form is stored in internal table of name-value table. there are two table one for inbound parameter and other for outbound parameters.
    Check out the example below to see how this is used..
    <b>Definition in the SAPscript form:</b>
    /: PERFORM GET_BARCODE IN PROGRAM QCJPERFO
    /: USING &PAGE&
    /: USING &NEXTPAGE&
    /: CHANGING &BARCODE&
    /: ENDPERFORM
    / &BARCODE&
    <b>Coding of the calling ABAP program:</b>
    REPORT QCJPERFO.
    FORM GET_BARCODE TABLES IN_PAR STUCTURE ITCSY
    OUT_PAR STRUCTURE ITCSY.
    DATA: PAGNUM LIKE SY-TABIX, "page number
    NEXTPAGE LIKE SY-TABIX. "number of next page
    READ TABLE IN_PAR WITH KEY ‘PAGE’.
    CHECK SY-SUBRC = 0.
    PAGNUM = IN_PAR-VALUE.
    READ TABLE IN_PAR WITH KEY ‘NEXTPAGE’.
    CHECK SY-SUBRC = 0.
    NEXTPAGE = IN_PAR-VALUE.
    READ TABLE OUT_PAR WITH KEY ‘BARCODE’.
    CHECK SY-SUBRC = 0.
    IF PAGNUM = 1.
    OUT_PAR-VALUE = ‘|’. "First page
    ELSE.
    OUT_PAR-VALUE = ‘||’. "Next page
    ENDIF.
    IF NEXTPAGE = 0.
    OUT_PAR-VALUE+2 = ‘L’. "Flag: last page
    ENDIF.
    MODIFY OUT_PAR INDEX SY-TABIX.
    ENDFORM.
    Hope this is clear to understand...
    Enjoy SAP.
    Pankaj Singh.

  • How to use union statement with declare & set function?

    Hi Experts,
            i  have small query about how to use union statement with declare & set function?
    Example as below :
    DECLARE @name AS date
    Declare @name2  AS date
    /* SELECT FROM [2013].[dbo].[OINV] T0 */
    /* WHERE */
    SET @name = /* T0.DocDate */ '[%1]'
    SET @name2 = /* T0.DocDate */ '[%2]'
    select  '2013',t5.U_salmannm,t1.CardName,t2.sumapplied as CollectionAmount,t2.DcntSum ,t3.DocTotal as InvoiceTotal,
    datediff(dd,t3.DocDate,t1.Docdate) as Days
    from 2013.dbo.orct t1
    inner join 2013.dbo.RCT2 t2 on t1.DocNum = t2.DocNum
    left join 2013.dbo.oinv t3 on
    t3.docentry = t2.baseAbs
    inner join 2013.dbo.ocrd t4 on t1.Cardcode = t4.CardCode
    inner join [2013].[dbo].[@CQ_RTSM] t5 on t4.U_BeatCode = t5.U_RoutCode
    where t2.DcntSum <> 0.000000 and t3.DocDate between [%1] and [%2]
    Union
    /* SELECT FROM [2014].[dbo].[OINV] T0 */
    /* WHERE */
    SET @name = /* T0.DocDate */ '[%1]'
    SET @name2 = /* T0.DocDate */ '[%2]'
    select  '2014',t5.U_salmannm,t1.CardName,t2.sumapplied as CollectionAmount,t2.DcntSum ,t3.DocTotal as InvoiceTotal,
    datediff(dd,t3.DocDate,t1.Docdate) as Days
    from 2014.dbo.orct t1
    inner join 2014.dbo.RCT2 t2 on t1.DocNum = t2.DocNum
    left join 2014.dbo.oinv t3 on
    t3.docentry = t2.baseAbs
    inner join 2014.dbo.ocrd t4 on t1.Cardcode = t4.CardCode
    inner join [2014].[dbo].[@CQ_RTSM] t5 on t4.U_BeatCode = t5.U_RoutCode
    where t2.DcntSum <> 0.000000 and t3.DocDate between [%1] and [%2]

    You have to create stored procedure in SQL only .
    Like u must have create for Crystal .
    You can execute procedure in query manager but you have to enter parameter manually..
    example
    Exec @Test '20140101' '20140501'
    Every time user has to enter it manually in yyyymmdd format in case of date parameters.
    Example
    Create Proc [@Test]
    as begin
    DECLARE @name AS date
    Declare @name2  AS date
    /* SELECT FROM [2013].[dbo].[OINV] T0 */
    /* WHERE */
    select  '2013',t5.U_salmannm,t1.CardName,t2.sumapplied as CollectionAmount,t2.DcntSum ,t3.DocTotal as InvoiceTotal,
    datediff(dd,t3.DocDate,t1.Docdate) as Days
    from 2013.dbo.orct t1
    inner join 2013.dbo.RCT2 t2 on t1.DocNum = t2.DocNum
    left join 2013.dbo.oinv t3 on
    t3.docentry = t2.baseAbs
    inner join 2013.dbo.ocrd t4 on t1.Cardcode = t4.CardCode
    inner join [2013].[dbo].[@CQ_RTSM] t5 on t4.U_BeatCode = t5.U_RoutCode
    where t2.DcntSum <> 0.000000 and t3.DocDate between @Name and @Name2
    Union
    /* SELECT FROM [2014].[dbo].[OINV] T0 */
    /* WHERE */
    select  '2014',t5.U_salmannm,t1.CardName,t2.sumapplied as CollectionAmount,t2.DcntSum ,t3.DocTotal as InvoiceTotal,
    datediff(dd,t3.DocDate,t1.Docdate) as Days
    from 2014.dbo.orct t1
    inner join 2014.dbo.RCT2 t2 on t1.DocNum = t2.DocNum
    left join 2014.dbo.oinv t3 on
    t3.docentry = t2.baseAbs
    inner join 2014.dbo.ocrd t4 on t1.Cardcode = t4.CardCode
    inner join [2014].[dbo].[@CQ_RTSM] t5 on t4.U_BeatCode = t5.U_RoutCode
    where t2.DcntSum <> 0.000000 and t3.DocDate between
    between @Name and @Name2
    end

  • How to use CASE statement in WDA

    Hi All,
       Can any one Please expain me ' How to use CASE statement in Web dynpro ABAP? '
      Please give me an example also.
    Thanks in Advance !

    Hi,
    The usage of case statement in webdynpro is same as used in general ABAP.
    Data: l_id type string.
    l_id = wdevent->get_string( 'ID' ).
    case l_id.
    when 'BTN1'.
    when 'BTN2'.
    when 'OTHERS'.
    endcase.
    Regards,
    Radhika.

  • How to use multiple statements inside the "THEN" block of CASE statement?

    Below is the code:
    SET @strTempString = case @strKeyMode
    WHEN 'AUTO/CYCLE'
    THEN  @strRefID + '|' + @strRetID
    WHEN 'CYCLE'
    THEN  @strRefID + '|' + @strRetID
    WHEN 'COMMERCIAL'
    THEN  @strRefID + '|' + @strRetID
    WHEN 'ISNAP'
    THEN  set @strFName = ltrim(rtrim((Left(dbo.CleanTheStringAdv(@strFName + '  ', 2) + '  ', 2))))
    '' + @strRefID + '|' + @strLName + '|' + @strFName + '|' + @strZIPorPolType
    WHEN 'ASNAP'
    THEN  @strRefID + '|' + @strRetID
    WHEN 'MOAT'
    THEN  @strRefID + '|' + @strRetID
    else '0'
    end 
    The first 3 conditions are understandable. How to use multiple statements in 4th case?
    Here I first want to set the value as:
    set @strFName = ltrim(rtrim((Left(dbo.CleanTheStringAdv(@strFName + '  ', 2) + '  ', 2))))
    and then return the string '' + @strRefID + '|' + @strLName + '|' + @strFName + '|' + @strZIPorPolType to @strTempString. 
    Please help me remove the syntax errors.
    Thanks in advance.

    Try below SQL
    DECLARE @strKeyMode varchar(20) = 'ISNAP'
    DECLARE @SQL VARCHAR(MAX)
    DECLARE @strRefID int=1
    DECLARE @strRetID INT=2
    --FIRST WAY
    IF @strKeyMode ='AUTO/CYCLE'
    SELECT CAST(@strRefID as varchar(10))
    ELSE IF @strKeyMode ='CYCLE'
    SELECT @sql = CAST(@strRefID as varchar(10)) + '|' + CAST(@strRetID as varchar(10))
    ELSE IF @strKeyMode='ISNAP'
    SELECT @sql = CAST(@strRefID as varchar(10)) + '|' + CAST(@strRetID as varchar(10))+'test'+'abc'
    ELSE
    SELECT @SQL='ABC'
    print @sql
    ----SECOND WAY
    SELECT @SQL = CASE @strKeyMode
    WHEN 'AUTO/CYCLE' THEN CAST(@strRefID as varchar(10))
    WHEN 'CYCLE' THEN CAST(@strRefID as varchar(10)) + '|' + CAST(@strRetID as varchar(10))
    WHEN 'ISNAP' THEN CAST(@strRefID as varchar(10)) + '|' + CAST(@strRetID as varchar(10))+'test'+'abc'
    ELSE 'No Record'
    END
    PRINT (@SQL)
    --Prashanth

  • How to use " PERFORM ", STATEMENT WITH OFFSET

    hI,
    How we use Perform statement with offset, like
      Example:   " PERFORM READ_SEGRELEASE USING INT_EDIDC+11."
    My requirement is to use Perform with Automatic length declaration.
    Automatic length declaration in PERFORM statement
    Kindly Explain and Provide some Example programm written in this situation.
    Thanks,
    P.N.Kumar

    Hiere is an example of what you probably require:
    DATA:
    lv_offset        TYPE syoffi,
    lv_length        TYPE flength,
    lv_field          TYPE string.
    lv_field  = 'This is my value: hello world'.
    lv_length = 5.
    lv_offset = 18.
    PERFORM read_segrelease USING lv_field
                                                            lv_length
                                                            lv_offset.
    *&      Form  READ_SEGRELEASE
    *       text
    *      -->P_LV_FIELD  text
    *      -->P_LV_LENGTH  text
    *      -->P_LV_OFFSET  text
    FORM read_segrelease USING    p_lv_field         TYPE string
                                                         p_lv_length      TYPE flength
                                                         p_lv_offset      TYPE syoffi.
      DATA:
      lv_result    TYPE string.
      lv_result = p_lv_field+p_lv_offset(p_lv_length).
      WRITE: / lv_result.
    ENDFORM.                    " READ_SEGRELEASE

  • How to use collective confirmation CO12

    can any body explain me how to use collective confirmation CO12 with screen dump.
    Plz help

    Hi Viswa,
    Prerequisites:
    You can predefine values to identify confirmations and to determine default values in Conf. parameters for collective confirmation/fast entry (Customizing for Shop Floor Control by choosing Operations ® Confirmation ® Confirmation Parameters Collective Entry/Fast Entry):
        Identifying the confirmation
    You can identify an individual confirmation either by the confirmation number or the order number/operation number.
        Suggest actual data
    You can define whether and when (after entry, during saving) quantities (see Determining a Default for Yield) or activities are suggested. The default setting is that no quantities are suggested and activities are determined during saving. Personnel data and dates are always suggested.
    Procedure:
        Choose Logistics ® Production ® Shop floor control ® Confirmation ® Enter ® For operation ® Collective entry.
        The screen for collective entry of confirmations appears.
        In this screen you can enter confirmations in a table (table control). You enter a new confirmation in each line. You can control the appearance of the table yourself.
    You can change the type of confirmation identification during input. To do so choose Other view.
    Enter all the data needed for the confirmations. Each line corresponds to a new confirmation. In this line you have all the fields that are available in single entry of a time ticket confirmation.
    On the top line of the screen you can enter default values (for example unit of measure, personnel number) that are copied to all confirmations. Enter the values and choose This graphic is explained in the accompanying text. You can save these default values for a specific user, so that they are preset the next time the user logs on. You can also delete these defaults.
    With this function, you can let the system suggest actual data (quantities, activities, dates, personnel data). To do so, select the confirmations, choose This graphic is explained in the accompanying text Propose actual data, set the indicator for the relevant actual data and choose This graphic is explained in the accompanying text. This data overwrites data that you may have already entered.
        Save your confirmations.
    Note
    To reach the Actual data screen for the selected confirmations choose This graphic is explained in the accompanying text. Here you have the complete functionality of time ticket confirmation. From this screen you can go to the detail screens and to the goods movement overview. If several confirmation have been selected, you can switch between the individual confirmations.
    Note
    You can switch to the goods movement overview from the collective entry screen (choose This graphic is explained in the accompanying text Goods movements). In this screen the goods movements for the selected confirmations are displayed.
    You can check and, if necessary, change the goods movements. When you go back to the collective entry screen, the GM indicator is set for the selected confirmations (goods movements for confirmations already determined). As soon as you save a confirmation, the goods movements are also posted.
    For more information choose the GOODS MOVEMENT OVER VIEW.
    Regards,
    Madhu.G
    Edited by: madhu333mac on Jan 11, 2012 11:34 PM

  • HOW TO USE PERFORM STATEMENT IN SMARTFORMS

    Hi,
    Can anyone tell me how to use call subroutine in smartform?
    Thanks & Regards,
    Gauarv.

    Hi,
    Hope this helps you..
    You can use the PERFORM command to call an ABAP subroutine
    (form) from
    any program, subject to the normal ABAP runtime
    authorization
    checking. You can use such calls to subroutines for
    carrying out
    calculations, for obtaining data from the database that is
    needed at
    display or print time, for formatting data, and so on.
    PERFORM commands, like all control commands, are executed
    when a
    document is formatted for display or printing.
    Communication between a
    subroutine that you call and the document is by way of
    symbols whose
    values are set in the subroutine.
    The system does not execute the PERFORM command within
    SAPscript
    replace modules, such as TEXT_SYMBOL_REPLACE or
    TEXT_INCLUDE_REPLACE.
    The replace modules can only replace symbol values or
    resolve include
    texts, but not interpret SAPscript control commands.
    Syntax in a form window:
    /: PERFORM <form> IN PROGRAM <prog>
    /: USING &INVAR1&
    /: USING &INVAR2&
    /: CHANGING &OUTVAR1&
    /: CHANGING &OUTVAR2&
    /: ENDPERFORM
    INVAR1 and INVAR2 are variable symbols and may be of any of
    the four
    SAPscript symbol types.
    OUTVAR1 and OUTVAR2 are local text symbols and must
    therefore be
    character strings.
    The ABAP subroutine called via the command line stated
    above must be
    defined in the ABAP report prog as follows:
    FORM <form> TABLES IN_TAB STRUCTURE ITCSY
    OUT_TAB STRUCTURE ITCSY.
    ENDFORM.
    The values of the SAPscript symbols passed with /: USING...
    are now
    stored in the internal table IN_TAB . Note that the system
    passes the
    values as character string to the subroutine, since the
    field Feld
    VALUE in structure ITCSY has the domain TDSYMVALUE (CHAR
    80). See the
    example below on how to access the variables.
    The internal table OUT_TAB contains names and values of the
    CHANGING
    parameters in the PERFORM statement. These parameters are
    local text
    symbols, that is, character fields. See the example below
    on how to
    return the variables within the subroutine.
    From within a SAPscript form, a subroutine GET_BARCODE in
    the ABAP
    program QCJPERFO is called. Then the simple barcode
    contained there
    ('First page', 'Next page', 'Last page') is printed as
    local variable
    symbol.

  • HOW TO USE "WITH" STATEMENT IN MESSAGES

    MESSAGE e001 WITH WERKS  SY-REPID
    TELL ME HOW TO USE "WITH" IN MESSAGES SEND SYANTAX AND EXAMPLE CODE

    Messages e001(zz) with Var1 var2 var3.
    For this statement to be valie, the variables var1 var2 var3 should be defined alrteady in the program.
    and in se91, you should define a message class (Say ZZ ).
    In that message class you can create a message with number (Say 001) with place holders (&).
    001: & is a sampele message for & hgh  & hjknkn
    The & will get replaced by the variables var1 var2 var3 in the run time.
    YOu can also create success messages if yo say:
    Messages S001(zz) with Var1 var2 var3.
    Information
    Messages I001(zz) with Var1 var2 var3.
    Warning:
    Messages W001(zz) with Var1 var2 var3.
    Abend:
    Messages a001(zz) with Var1 var2 var3.
    REFER sample programs : DEMO_MESSAGES       
    DEMO_MESSAGES_SIMPLE
    Regards,
    Ravi
    Message was edited by:
            Ravi Kanth Talagana

  • How to use prepared statement by Application Module on ADF?

    Hello
    i am using a prepared statement on the view side of my project,
    this is my code, i'm not sure about using this code.
    AppModuleGFTImpl am = (AppModuleGFTImpl) Configuration.createRootApplicationModule(amDef,config);
    try {
    ps =am.getDBTransaction().createPreparedStatement("Select * from XXXXXX where kullanici_id=? and sifre=?",0);
    ps.setString(1, kullanici);
    ps.setString(2, sifre);
    rs = ps.executeQuery();
    if (rs.next()) {
    girebilir = true;
    } else {
    girebilir = false;
    ps.close();
    rs.close();
    //am.getDBTransaction().closeTransaction(); ? I'm not Sure
    //Configuration.releaseRootApplicationModule(am, true); ? I'm not Sure
    Is it True? How we use this code on the project view side? Must we close Transaction, or release application Module.
    thanks for interest.
    sorry my english.

    Hello, for the SP you can use something like this in your application module
      private static final String BULKSTAMMENN =
        "begin IVA_OWNER.IVA_UI_ALGEMEEN_PCK.USM_SNELLE_INVOER_GUI( P_RLE_ID => :1, P_AANTAL => :2, P_OJR_JAAR => :3, P_RAS_ID => :4, P_TOELICHTING => :5, P_SUCCES => :6 ); end;";
    public void bulkStamen ( int rasId, int telerId, int jaar, int aantal, String toelichting ) {
        CallableStatement bulkStamenSP = null;
        try {
          bulkStamenSP = getDBTransaction().createCallableStatement( BULKSTAMMENN, 0 );
          bulkStamenSP.setInt( 1, telerId );
          bulkStamenSP.setInt( 2, aantal );
          bulkStamenSP.setInt( 3, jaar );
          bulkStamenSP.setInt( 4, rasId );
          bulkStamenSP.setString( 5, toelichting );
          bulkStamenSP.registerOutParameter( 6, Types.VARCHAR );
          bulkStamenSP.executeUpdate();
        } catch ( Exception e ) {
          log.warning( "Aanroep naar " + BULKSTAMMENN + " gefaald, " + e.getMessage() );
        } finally {
          if ( bulkStamenSP != null ) {
            try {
              bulkStamenSP.close();
            } catch ( Exception e ) {
              log.warning( e.getMessage() );
        log.info( "Stammen bulk uitgevoerd voor " + rasId + " " + telerId + " " + jaar + " " + aantal + " " +
                  toelichting );
      }You can then drag this method onto your page or right into your task flow if your using JDev 11.
    Also you can access it from a backing bean although the methods above are preferred
    -Anton

  • How to use collect?

    hi all ,
    i want to add net value of all the line items which are in the same group
    am using collect but am unable to do that.
    plz suggest me what to do?
    DATA: BEGIN OF del_grp_data occurs 0,
            vbeln like vbap-vbeln,  " Sales document
            grkor like vbap-grkor,  " Delivery group
            netwr like vbap-netwr, "net value
            posnr like vbap-posnr,  " Sales document item
             End OF del_grp_data.
    SELECT vbeln grkor pstyv netwr
        posnr
       FROM   vbap
        INTO corresponding fields of  TABLE del_grp_data
        FOR ALL ENTRIES IN orders_vbeln
        WHERE vbeln eq orders_vbeln-vbeln.
    loop at del_grp_data.
    collect ord_grp_data .
    endloop.
    Regards,
    Amit.

    Basic form
    COLLECT [wa INTO] itab.
    Addition:
    ... SORTED BY f
    Cannot Use Short Forms in Line Operations.
    Effect
    COLLECT allows you to create unique or summarized datasets. The system first tries to find a table entry corresponding to the table key. (See also Defining Keys for Internal Tables). The key values are taken either from the header line of the internal table itab, or from the explicitly-specified work area wa. The line type of itab must be flat - that is, it cannot itself contain any internal tables. All the components that do not belong to the key must be numeric types ( ABAP Numeric Types).
    If the system finds an entry, the numeric fields that are not part of the table key (see ABAPNumeric Types) are added to the sum total of the existing entries. If it does not find an entry, the system creates a new entry instead.
    The way in which the system finds the entries depends on the type of the internal table:
    STANDARD TABLE:
    The system creates a temporary hash administration for the table to find the entries. This means that the runtime required to find them does not depend on the number of table entries. The administration is temporary, since it is invalidated by operations like DELETE, INSERT, MODIFY, SORT, ...). A subsequent COLLECT is then no longer independent of the table size, because the system has to use a linear search to find entries. For this reason, you should only use COLLECT to fill standard tables. U
    SORTED TABLE:
    The system uses a binary search to find the entries. There is a logarithmic relationship between the number of table entries and the search time.
    HASHED TABLE:
    The system uses the internal hash administration of the table to find records. Since (unlike standard tables), this remains intact even after table modification operations, the search time is always dependent on the number of table entries.
    For standard tables and SORTED TABLEs, the system field SY-TABIX contains the number of the existing or newly-added table entry after the APPEND. With HASHED TABLEs, SY-TABIX is set to 0.
    Notes
    COLLECT allows you to create a unique or summarized dataset, and you should only use it when this is necessary. If neither of these characteristics are required, or where the nature of the table in the application means that it is impossible for duplicate entries to occur, you should use INSERT [wa INTO] TABLE itab instead of COLLECT. If you do need the table to be unique or summarized, COLLECT is the most efficient way to achieve it.
    If you use COLLECT with a work area, the work area must be compatible with the line type of the internal table.
    If you edit a standard table using COLLECT, you should only use the COLLECT or MODIFY ... TRANSPORTING f1 f2 ... statements (where none of f1, f2, ... may be in the key) enthalten sein). Only then can you be sure that:
    -The internal table actually is unique or summarized
    -COLLECT runs efficiently. The check whether the dataset
    already contains an entry with the same key has a constant
    search time (hash procedure).
    If you use any other table modification statements, the check for entries in the dataset with the same key can only run using a linear search (and will accordingly take longer). You can use the function module ABL_TABLE_HASH_STATE to test whether the COLLECT has a constant or linear search time for a given standard table.
    Example
    Summarized sales figures by company:
    TYPES: BEGIN OF COMPANY,
            NAME(20) TYPE C,
            SALES    TYPE I,
          END OF COMPANY.
    DATA: COMP    TYPE COMPANY,
          COMPTAB TYPE HASHED TABLE OF COMPANY
                                    WITH UNIQUE KEY NAME.
    COMP-NAME = 'Duck'.  COMP-SALES = 10. COLLECT COMP INTO COMPTAB.
    COMP-NAME = 'Tiger'. COMP-SALES = 20. COLLECT COMP INTO COMPTAB.
    COMP-NAME = 'Duck'.  COMP-SALES = 30. COLLECT COMP INTO COMPTAB.
    Table COMPTAB now has the following contents:
               NAME    | SALES
              Duck    |   40
              Tiger   |   20
    Addition
    ... SORTED BY f
    Effect
    COLLECT ... SORTED BY f is obsolete, and should no longer be used. It only applies to standard tables, and has the same function as APPEND ... SORTED BY f, which you should use instead. (See also Obsolete Language Elements).
    Note
    Performance:
    Avoid unnecessary assignments to the header line when using internal tables with a header line. Whenever possible, use statements that have an explicit work area.
    For example, " APPEND wa TO itab." is approximately twice as fast as " itab = wa. APPEND itab.". The same applies to COLLECT and INSERT.
    The runtime of a COLLECT increases with the width of the table key and the number of numeric fields whose contents are summated.
    Note
    Non-Catchable Exceptions:
    COLLECT_OVERFLOW: Overflow in an integer field during addition
    COLLECT_OVERFLOW_TYPE_P: Overflow in a type P field during addition.
    TABLE_COLLECT_CHAR_IN_FUNCTION: COLLECT on a non-numeric field.
    Related
    APPEND, WRITE ... TO, MODIFY, INSERT
    Additional help
    Inserting SummarizedTable Lines

  • How to use hide statement

    hi experts,
                  I am working with interactive report using hide statement.for thr first time it is working properly but the next time it is not working properly.Hope some clear statement has to be given ..
    Please give some simple progarm for interactiev report in list using hide statement.
    regards,
    mani

    HIDE dobj.
    Effect
    This statement stores the content of a variable dobj together with the current list line whose line number is contained in sy-linno in the hide area of the current list level. The data type of the variables dobj must be flat and no field symbols can be specified that point to rows of internal tables, and no class attributes can be specified. The stored values can be read as follows:
    For each user action in a displayed screen list that leads to a list result, all the row values stored using HIDE - that is, the row on which the screen cursor is positioned at the time of the event - are assigned to the respective variables.
    If a list row of an arbitrary list level is read or modified using the statements READ LINE or MODIFY LINE, all the values of this row stored using HIDE are assigned to the respective variables.
    Notes
    The HIDE statement works independently of whether the list cursor was set. In particular, variables for empty list rows can be stored - that is, rows in which the list cursor was positioned using statements like SKIP.
    The HIDE statement should be executed immediately at the statement that has set the list cursor in the row.
    Outside of classes, prior to release 7.0, for dobj constants and literals could still be specified. However, it was not possible to read them at list events and in the READ LINE statement.
    Example
    Storing square numbers and cubic numbers for a list of numbers. The example shows that arbitrary variables can be stored independently of row content. In the real situation, one would more likely store only the number and execute the calculation, when required, in the the event block for AT LINE-SELECTION.
    REPORT ...
    DATA: square TYPE i,
    cube TYPE i.
    START-OF-SELECTION.
    FORMAT HOTSPOT.
    DO 10 TIMES.
    square = sy-index ** 2.
    cube = sy-index ** 3.
    WRITE / sy-index.
    HIDE: square, cube.
    ENDDO.
    AT LINE-SELECTION.
    WRITE: square, cube.
    HIDE f.
    The contents of f related to the current output line are stored. If this line is selected, f is filled automatically with the stored value.
    The selection can be made using:
    AT LINE-SELECTION
    AT PFx
    AT USER-COMMAND
    READ LINE
    You do not have to output the field with WRITE in order to be able to store its value.
    The HIDE statement does not support structures that contain tables (deep structures).
    System fields that are particularly useful in interactive reporting are listed in the system fields for lists documentation.
    You cannot save lines or components of lines of an internal table that is addressed using a field symbol to the HIDE area. (Compare the ASSIGNING addition to the READ and LOOP statements). Assign the contents of the line or component to a global variable and save this instead.
    You can only write variables to the HIDEarea.
    In ABAP Objects, the following statements acause an error message:
    CONSTANTS f.
    HIDE: '...', f.
    Correct syntax:
    DATA: f1, f2.
    HIDE: f1, f2.
    Cause:
    Interactive list events cause the fields hidden by the HIDE command to be overwritten with values in the HIDE area, which means that they must be changeable.n.
    Reward points if useful.

  • Issue while using Collect statement in program

    Hi friend's,
    i have some issue regarding Collect statement..
    Issue is somthing like this,i have created a structure and internal table and work area with same type,
    u can look in below code..i wann to collect 'enmng' f'ield value whose matnr,charg,mvt type ,aufnr,rsnum are same but rspos and lgort are differnt for this i need to collect 'ENMNG' field value can any one tel me what to do...it not collectng value instead of this it append entire row...
    types: begin of ty_resb,
            rsnum   type resb-rsnum,                "Resrvation Number
            rspos   type resb-rspos,                "item position
            xloek   type resb-xloek,                "Item Deleted  if = 'X'
            matnr   type resb-matnr,                "Material Number
            lgort   type resb-lgort,                "Storage location  'REJT'
            charg   type resb-charg,                "Batch No
            enmng   type resb-enmng,                "Quantity withdrawn should be greater then '0'
            enwrt   type resb-enwrt,                "Value Withdrawn
            aufnr   type resb-aufnr,                "Order
            bwart   type resb-bwart,                "Movement type
       end of ty_resb.
    data:tt_resb  type table of  ty_resb ,
          tt_resb1 type table of ty_resb ,
          tt_resb2 type standard table of ty_resb ,
    **workarea.
          ts_resb type ty_resb,
          ts_resb2 type ty_resb,
          ts_resb1 type ty_resb.
    **move data to another internal table
    tt_resb1[] = tt_resb[].
    sort tt_resb  by rsnum rspos matnr charg bwart lgort aufnr .
    sort tt_resb1 by rsnum rspos matnr charg bwart lgort aufnr.
    DELETE adjacent duplicates from tt_resb  comparing rsnum rspos matnr charg bwart lgort aufnr .
    DELETE adjacent duplicates from tt_resb1 comparing rsnum rspos matnr charg bwart lgort aufnr.
    loop at tt_resb into ts_resb .
    clear:ts_resb1,ts_resb2.
    read table tt_resb1 into ts_resb1 with key rsnum = ts_resb-rsnum rspos = ts_resb-rspos matnr = ts_resb-matnr
                                                charg = ts_resb-charg aufnr = ts_resb-aufnr binary search.
    if ts_resb1-bwart = '261' .
        move ts_resb1-aufnr to ts_resb2-aufnr.
        move ts_resb1-matnr to ts_resb2-matnr.
        move ts_resb1-charg to ts_resb2-charg.
        move ts_resb1-bwart to ts_resb2-bwart.
        move ts_resb1-enwrt to ts_resb2-enwrt.
        move ts_resb1-lgort to ts_resb2-lgort.
        move ts_resb1-enmng to ts_resb2-enmng.
        collect ts_resb2 into tt_resb2.
    endif.
    clear ts_resb.
    endloop.
    Regard's,
    shaikh khalid.

    Hi Shaikh,
    I have added new declarations as highlighted below and new lines within your loop:
    Execute your program in debug mode and see what happens to the internal tt_collect I added. The collect will sum the fields enmng for all entries that  have same value on the fields matnr,charg,mvt type ,aufnr,rsnum.
    Question from me: what do you want to do with the collected/Summed up entries?
    types: begin of ty_resb,
            rsnum   type resb-rsnum,                "Resrvation Number
            rspos   type resb-rspos,                "item position
            xloek   type resb-xloek,                "Item Deleted  if = 'X'
            matnr   type resb-matnr,                "Material Number
            lgort   type resb-lgort,                "Storage location  'REJT'
            charg   type resb-charg,                "Batch No
            enmng   type resb-enmng,                "Quantity withdrawn should be greater then '0'
            enwrt   type resb-enwrt,                "Value Withdrawn
            aufnr   type resb-aufnr,                "Order
            bwart   type resb-bwart,                "Movement type
       end of ty_resb.
    data:tt_resb  type table of  ty_resb ,
          tt_resb1 type table of ty_resb ,
          tt_resb2 type standard table of ty_resb ,
    types: begin of ty_collect,
      rsnum   type resb-rsnum,
      matnr   type resb-matnr,
      charg   type resb-charg,
      bwart   type resb-bwart,
      aufnr   type resb-aufnr, 
      enmng   type resb-enmng,
           end of ty_collect.
    data: tt_collect type table of ty_collect,
          ts_collect type ty_collect.
    **workarea.
          ts_resb type ty_resb,
          ts_resb2 type ty_resb,
          ts_resb1 type ty_resb.
    **move data to another internal table
    tt_resb1[] = tt_resb[].
    sort tt_resb  by rsnum rspos matnr charg bwart lgort aufnr .
    sort tt_resb1 by rsnum rspos matnr charg bwart lgort aufnr.
    DELETE adjacent duplicates from tt_resb  comparing rsnum rspos matnr charg bwart lgort aufnr .
    DELETE adjacent duplicates from tt_resb1 comparing rsnum rspos matnr charg bwart lgort aufnr.
    loop at tt_resb into ts_resb .
    clear:ts_resb1,ts_resb2.
    read table tt_resb1 into ts_resb1 with key rsnum = ts_resb-rsnum rspos = ts_resb-rspos matnr = ts_resb-matnr
                                                charg = ts_resb-charg aufnr = ts_resb-aufnr binary search.
    if ts_resb1-bwart = '261' .
        move ts_resb1-aufnr to ts_resb2-aufnr.
        move ts_resb1-matnr to ts_resb2-matnr.
        move ts_resb1-charg to ts_resb2-charg.
        move ts_resb1-bwart to ts_resb2-bwart.
        move ts_resb1-enwrt to ts_resb2-enwrt.
        move ts_resb1-lgort to ts_resb2-lgort.
        move ts_resb1-enmng to ts_resb2-enmng.
        collect ts_resb2 into tt_resb2.
         move-corresponding ts_resb1 to ts_collect.
         collect ts_collect into tt_collect
    endif.
    clear ts_resb.
    clear ts_collect.
    endloop.

Maybe you are looking for