Skip to Content
author's profile photo
Former Member

generating report logic

Hi All

I am using an internal table with fields

Estimator order Lost Open

A 1 0 0

A 0 1 0

B 1 0 0

C 0 0 1

which shows estimator, order field which shows the quote converted to order, similarly lost and open.

Now I want to summarize this into anoter internal table where output should be like

Estimator Total_quotes Converted_to_order Lost Open

A 2 1 1 0

B 1 1 0 0

C 1 0 0 1

the total no of quotes is the total number of records with that estimator,

converted to order is the total number of quotes converted to order and similary with lost and open.

can any one provide with th logic please

regards

AJ

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

5 Answers

  • Best Answer
    author's profile photo
    Former Member
    Oct 11, 2007 at 02:03 PM

    Please refer this program...it exactly solves ur problem.....

    just change field names and add fields which u want......

    var1 is estimator

    var2 is converted to order/lost/open " u can use 3 fields here......

    var3 " extra field in my case......

    var4 total quotes

    data : begin of itab occurs 0,

    var1 type c,

    var2 type i,

    var3 type i,

    end of itab.

    data : begin of itab1 occurs 0,

    var1 type c,

    var2 type i,

    var3 type i,

    var4 type i,

    end of itab1.

    data : v_cnt type i.

    itab-var1 = 'A'.

    itab-var2 = 1.

    itab-var3 = 0.

    append itab.

    clear itab.

    itab-var1 = 'A'.

    itab-var2 = 2.

    itab-var3 = 5.

    append itab.

    clear itab.

    itab-var1 = 'B'.

    itab-var2 = 1.

    itab-var3 = 0.

    append itab.

    clear itab.

    itab-var1 = 'C'.

    itab-var2 = 1.

    itab-var3 = 0.

    append itab.

    clear itab.

    loop at itab.

    at new var1.

    itab1-var1 = itab-var1.

    clear v_cnt.

    endat.

    v_cnt = v_cnt + 1.

    at end of var1.

    sum.

    itab1-var2 = itab-var2.

    itab1-var4 = v_cnt.

    append itab1.

    clear itab1.

    endat.

    endloop.

    loop at itab1.

    write :/ itab1-var1, itab1-var2,itab1-var3,itab1-var4.

    endloop.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 11, 2007 at 01:52 PM

    AJ,

    You can use Control Break Events in the Loop......

    AT FIRST -


    > Gets triggered before the first row is looped

    AT NEW Estimator -


    > for every change in Estimator AT NEW gets triggered

    AT END OF Estimator -


    > At the end of every change in Estimator

    AT LAST.----


    > After last record

    Hope this helps..

    Chandra.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 11, 2007 at 02:00 PM

    HI,

    U can use <b>Collect</b> Statement.

    Try this,

    Data : begin of wa1,

    ....

    ....

    ....

    .....

    end of wa1,

    itab1 like table of wa1 with non-unique key Estimator.

    Data : Begin of wa2,

    ...

    ...

    ...

    ...

    ...

    end of wa2,

    itab2 like table of wa2.

    loop at itab1 into wa1.

    collect itab1 into wa1.

    endloop.

    move-corresponding itab1 into itab2.

    Regards,

    Padmam.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 11, 2007 at 02:04 PM
    
    REPORT z.
    
    DEFINE fill.
      wa_a-estimator = &1.
      wa_a-order     = &2.
      wa_a-lost      = &3.
      wa_a-open      = &4.
    
      append wa_a to it_a.
    END-OF-DEFINITION.
    
    TYPES:
      BEGIN OF t_a,
        estimator TYPE char10,
        order     TYPE i,
        lost      TYPE i,
        open      TYPE i,
      END OF t_a,
    
      BEGIN OF t_b,
        estimator TYPE char10,
        amount    TYPE i,
        order     TYPE i,
        lost      TYPE i,
        open      TYPE i,
      END OF t_b.
    
    DATA:
      wa_a        TYPE t_a,
      it_a        TYPE STANDARD TABLE OF t_a,
    
      wa_b        TYPE t_b,
      it_b        TYPE STANDARD TABLE OF t_b.
    
    FIELD-SYMBOLS:
      <p_a>       TYPE t_a,
      <p_b>       TYPE t_b.
    
    START-OF-SELECTION.
      fill 'A' 1 0 0.
      fill 'A' 0 1 0.
      fill 'B' 1 0 0.
      fill 'C' 0 0 1.
    
      LOOP AT it_a ASSIGNING <p_a>.
        WRITE:/ <p_a>-estimator,
                <p_a>-order,
                <p_a>-lost,
                <p_a>-open.
      ENDLOOP.
    
      LOOP AT it_a ASSIGNING <p_a>.
    
        READ TABLE it_b WITH KEY estimator = <p_a>-estimator
          ASSIGNING <p_b>.
    
        IF sy-subrc = 0.
          <p_b>-order  = <p_b>-order + <p_a>-order.
          <p_b>-lost   = <p_b>-lost  + <p_a>-lost.
          <p_b>-open   = <p_b>-open  + <p_a>-open.
          <p_b>-amount = <p_b>-amount + 1.
        ELSE.
          wa_b-estimator = <p_a>-estimator.
          wa_b-lost      = <p_a>-lost.
          wa_b-order     = <p_a>-order.
          wa_b-open      = <p_a>-open.
          wa_b-amount    = 1.
          APPEND wa_b TO it_b.
        ENDIF.
    
      ENDLOOP.
    
      LOOP AT it_b ASSIGNING <p_b>.
        WRITE:/ <p_b>-estimator,
                <p_b>-amount,
                <p_b>-order,
                <p_b>-lost,
                <p_b>-open.
      ENDLOOP.
    
    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 11, 2007 at 02:19 PM

    hi AJ,

    try it:

    DATA: BEGIN OF itab1 OCCURS 0,

    estim,

    order,

    lost,

    open,

    END OF itab1,

    BEGIN OF itab2 OCCURS 0,

    estim,

    total,

    conve,

    lost,

    open,

    END OF itab2,

    i_tempa LIKE STANDARD TABLE OF itab2 WITH HEADER LINE,

    i_tempb LIKE STANDARD TABLE OF itab2 WITH HEADER LINE,

    i_tempc LIKE STANDARD TABLE OF itab2 WITH HEADER LINE.

    itab1-estim = 'A'.

    itab1-order = 1.

    itab1-lost = 0.

    itab1-open = 0.

    APPEND itab1.

    itab1-estim = 'A'.

    itab1-order = 0.

    itab1-lost = 1.

    itab1-open = 0.

    APPEND itab1.

    itab1-estim = 'B'.

    itab1-order = 1.

    itab1-lost = 0.

    itab1-open = 0.

    APPEND itab1.

    itab1-estim = 'C'.

    itab1-order = 0.

    itab1-lost = 0.

    itab1-open = 1.

    APPEND itab1.

    LOOP AT itab1.

    CASE itab1-estim.

    WHEN 'A'.

    i_tempa-estim = 'A'.

    i_tempa-total = i_tempa-total + 1.

    i_tempa-conve = i_tempa-conve + itab1-order.

    i_tempa-lost = i_tempa-lost + itab1-lost.

    i_tempa-open = i_tempa-open + itab1-open.

    WHEN 'B'.

    i_tempb-estim = 'B'.

    i_tempb-total = i_tempb-total + 1.

    i_tempb-conve = i_tempb-conve + itab1-order.

    i_tempb-lost = i_tempb-lost + itab1-lost.

    i_tempb-open = i_tempb-open + itab1-open.

    WHEN 'C'.

    i_tempc-estim = 'C'.

    i_tempc-total = i_tempc-total + 1.

    i_tempc-conve = i_tempc-conve + itab1-order.

    i_tempc-lost = i_tempc-lost + itab1-lost.

    i_tempc-open = i_tempc-open + itab1-open.

    ENDCASE.

    ENDLOOP.

    append i_tempa to itab2.

    append i_tempb to itab2.

    append i_tempc to itab2.

    loop at itab2.

    write: / itab2.

    endloop.

    Regards

    Allan Cristian

    Add comment
    10|10000 characters needed characters exceeded