Skip to Content
-4

how to display perfect value in report?

Hello All,

Please help me out in this, I am searching for solution for past 10 days.

I have requirement that report should be displayed as replica of standard. But Budget amount is getting very huge in custom report compare to standard.


Standard report Image

Custom Report Image.
You can see budget column is getting 5 times added when compared to standard.

Suggest me any correction please.

How to stop adding budget column for multiple addition? Here is my code

Perform read_data_cc.
FORM read_data_cc.
  LOOP AT it_cosp INTO wa_cosp WHERE wrttp = '04' OR wrttp = '21'.
    READ TABLE it_csks INTO wa_csks WITH KEY objnr = wa_cosp-objnr.
    READ TABLE it_cskt INTO wa_cskt WITH KEY kostl = wa_csks-kostl.
    IF sy-subrc = 0.
      MOVE wa_csks-kostl TO wa_final_cc-kostl.
      MOVE wa_cosp-gjahr TO wa_final_cc-gjahr.
      MOVE wa_cskt-ktext TO wa_final_cc-ktext.
    ENDIF.
    IF wa_cosp-wrttp = '04'.
      wa_final_cc-actual = ( wa_cosp-wtg001 + wa_cosp-wtg002 + wa_cosp-wtg003 + wa_cosp-wtg004 + wa_cosp-wtg005+ wa_cosp-wtg006 + wa_cosp-wtg007 + wa_cosp-wtg008 + wa_cosp-wtg009 + wa_cosp-wtg010+ wa_cosp-wtg011 + wa_cosp-wtg012 + wa_cosp-wtg013 + wa_cosp-wtg014 + wa_cosp-wtg015 + wa_cosp-wtg016 ).

    ELSEIF wa_cosp-wrttp = '21'.
      wa_final_cc-commit = ( wa_cosp-wtg001 + wa_cosp-wtg002 + wa_cosp-wtg003 + wa_cosp-wtg004 + wa_cosp-wtg005+ wa_cosp-wtg006 + wa_cosp-wtg007 + wa_cosp-wtg008 + wa_cosp-wtg009 + wa_cosp-wtg010+ wa_cosp-wtg011 + wa_cosp-wtg012 + wa_cosp-wtg013 + wa_cosp-wtg014 + wa_cosp-wtg015 + wa_cosp-wtg016 ).

    ENDIF.

    READ TABLE it_bppe INTO wa_bppe WITH KEY objnr = wa_cosp-objnr wrttp = '41' BINARY SEARCH.

    IF sy-subrc = 0.

      wa_final_cc-budget = ( wa_bppe-wtp01 + wa_bppe-wtp02 + wa_bppe-wtp03 + wa_bppe-wtp04 +  wa_bppe-wtp05 + wa_bppe-wtp06 + wa_bppe-wtp07 + wa_bppe-wtp08 + wa_bppe-wtp09 + wa_bppe-wtp10 + wa_bppe-wtp11 + wa_bppe-wtp12 + wa_bppe-wtp13 + wa_bppe-wtp14 + wa_bppe-wtp15 + wa_bppe-wtp16 ).

    ENDIF.
    wa_final_cc-allot = ( wa_final_cc-actual ) + ( wa_final_cc-commit ).
    wa_final_cc-avail = ( wa_final_cc-budget ) - ( wa_final_cc-allot ).
    COLLECT wa_final_cc INTO it_final_cc.
    SORT it_final_cc.
    CLEAR wa_final_cc.
  ENDLOOP.
ENDFORM.



As you can see above, which i wrote code to display actual,commit, budget, allot and available as shown in above pic.
I want only to loop budget column  for one time,as shown in below pic budget column should be add only one time which is a standard report.
I tried in many ways like,keepingdoloopforonly budget column,bykeepingsy-index=1,by keeping sy-tabix =1 for budget but not getting perfect result for   budget column.

It will be more helpful if you suggest any solution.
I am waiting for solution.
Thanks,
Harish
stnd-cc-rpt.jpg (45.6 kB)
custm-cc-rpt.jpg (41.4 kB)
Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Jun 07, 2018 at 01:25 PM

    debug!

    It is only the first line which has 5 times the value, the second line has it 8 times, the third and forth line just 2 times and the fifth line 3 times.

    check your internal table, maybe they are already wrongly filled before you get to the coding part which you shared.

    Add comment
    10|10000 characters needed characters exceeded

    • I debugged it, because of Budget is under loop condition. it is getting adding again and again.

      I placed it out of loop but last line of budget only getting added for number of times. and remaining from 1 to 4 th line the value is 0.

      Any suggestion please

  • Jun 11, 2018 at 10:51 AM

    Hi Harish,

    In this case don’t use COLLECT wa_final_cc INTO it_final_cc and also don’t clear wa_final_cc but after the corresponding loop read the final table with key Kostl equal ADMIN and assign the total Budget value from wa_final_cc.


    LOOP AT...
    ...
    ENDLOOP.
    
    FIELD-SYMBOLS: <FS_FINAL_CC> LIKE LINE OF IT_FINAL_CC.
    
    READ TABLE IT_FINAL_CC[] ASSIGNING <FS_FINAL_CC>
      WITH KEY KOSTL = 'ADMIN'.
    
    IF SY-SUBRC EQ 0.
       <FS_FINAL_CC>-BUDGET = WA_FINAL_CC-BUDGET. 
    ENDIF. 
    

    Regards,

    Add comment
    10|10000 characters needed characters exceeded

    • Hello @roberto.forti

      Thanks for code for which you have provided in my previous question. (As i asked this question twice they(SAP Community Moderator) have deleted my question which you have answered.

      https://answers.sap.com/questions/540319/how-to-loop-only-budget.html?childToView=540737#answer-540737

      Below is the code for which i am fetching data from database tables.

      FORM get_data_cc .

      SELECT kokrs
      kostl
      objnr
      bukrs FROM csks INTO TABLE it_csks WHERE kokrs IN s_kokrs AND kostl IN s_kostl AND bukrs IN s_bukrs.
      SELECT kostl
      ktext FROM cskt INTO TABLE it_cskt WHERE kostl IN s_kostl.
      IF sy-subrc = 0.
      SORT it_csks ASCENDING.
      SELECT lednr objnr gjahr wrttp wtg001 wtg002 wtg003 wtg004
      wtg005 wtg006 wtg007 wtg008 wtg009 wtg010 wtg011 wtg012 wtg013 wtg014
      wtg015 wtg016 FROM cosp INTO TABLE it_cosp FOR ALL ENTRIES IN it_csks WHERE objnr = it_csks-objnr AND gjahr = sy-datum+0(4).
      IF sy-subrc = 0 AND it_cosp IS NOT INITIAL.
      SORT it_cosp ASCENDING.
      ENDIF.
      SELECT lednr objnr wrttp gjahr wtp01 wtp02 wtp03 wtp04
      wtp05 wtp06 wtp07 wtp08 wtp09 wtp10 wtp11 wtp12 wtp13 wtp14
      wtp15 wtp16 FROM bppe INTO TABLE it_bppe FOR ALL ENTRIES IN it_csks WHERE objnr = it_csks-objnr AND gjahr = sy-datum+0(4).
      IF sy-subrc = 0 AND it_bppe IS NOT INITIAL.
      SORT it_bppe ASCENDING.
      ENDIF.
      ENDIF.

      ENDFORM.

      Now i will pass the data to the final internal table to display the ALV Grid Output.

      Here is the code which we are passing to final internal table.

      FORM read_data_cc.

      LOOP AT it_cosp INTO wa_cosp WHERE wrttp = '04' OR wrttp = '21'.

      READ TABLE it_csks INTO wa_csks WITH KEY objnr = wa_cosp-objnr.
      READ TABLE it_cskt INTO wa_cskt WITH KEY kostl = wa_csks-kostl.

      IF sy-subrc = 0.
      MOVE wa_csks-kostl TO wa_final_cc-kostl.
      MOVE wa_cosp-gjahr TO wa_final_cc-gjahr.
      MOVE wa_cskt-ktext TO wa_final_cc-ktext.
      ENDIF.
      IF wa_cosp-wrttp = '04'.
      wa_final_cc-actual = ( wa_cosp-wtg001 + wa_cosp-wtg002 + wa_cosp-wtg003 + wa_cosp-wtg004 + wa_cosp-wtg005
      + wa_cosp-wtg006 + wa_cosp-wtg007 + wa_cosp-wtg008 + wa_cosp-wtg009 + wa_cosp-wtg010
      + wa_cosp-wtg011 + wa_cosp-wtg012 + wa_cosp-wtg013 + wa_cosp-wtg014 + wa_cosp-wtg015
      + wa_cosp-wtg016 ).
      ELSEIF wa_cosp-wrttp = '21'.
      wa_final_cc-commit = ( wa_cosp-wtg001 + wa_cosp-wtg002 + wa_cosp-wtg003 + wa_cosp-wtg004 + wa_cosp-wtg005
      + wa_cosp-wtg006 + wa_cosp-wtg007 + wa_cosp-wtg008 + wa_cosp-wtg009 + wa_cosp-wtg010
      + wa_cosp-wtg011 + wa_cosp-wtg012 + wa_cosp-wtg013 + wa_cosp-wtg014 + wa_cosp-wtg015
      + wa_cosp-wtg016 ).
      ENDIF.


      COLLECT wa_final_cc INTO it_final_cc.

      SORT it_final_cc.

      ENDLOOP.

      DATA: lv_tabix TYPE sytabix, "Index of Internal Tables
      wa_bppe1 LIKE LINE OF it_bppe,
      wa_bppe2 LIKE LINE OF it_bppe.

      SORT it_bppe ASCENDING BY wrttp.

      *CO Object: Cost Totals for External Postings
      READ TABLE it_bppe INTO wa_bppe1 BINARY SEARCH WITH KEY wrttp = '41' . "Budget

      IF sy-subrc EQ 0.
      "Index of Internal Tables
      lv_tabix = sy-tabix.
      LOOP AT it_bppe INTO wa_bppe2 FROM lv_tabix.

      IF ( wa_bppe1-wrttp NE wa_bppe2-wrttp ).
      EXIT.
      ELSE.
      wa_final_cc-budget = ( wa_bppe2-wtp01 + wa_bppe2-wtp02 + wa_bppe2-wtp03 + wa_bppe2-wtp04
      + wa_bppe2-wtp05 + wa_bppe2-wtp06 + wa_bppe2-wtp07 + wa_bppe2-wtp08
      + wa_bppe2-wtp09 + wa_bppe2-wtp10 + wa_bppe2-wtp11 + wa_bppe2-wtp12
      + wa_bppe2-wtp13 + wa_bppe2-wtp14 + wa_bppe2-wtp15 + wa_bppe2-wtp16 ).

      wa_final_cc-allot = ( wa_final_cc-commit ) + ( wa_final_cc-actual ).
      wa_final_cc-avail = ( wa_final_cc-allot ) - ( wa_final_cc-budget ).

      COLLECT wa_final_cc INTO it_final_cc .

      CLEAR sy-tabix.

      ENDIF.

      CLEAR: wa_bppe2,
      wa_final_cc.

      ENDLOOP.

      ENDIF.

      ENDFORM.

      here is a problem.

      As below picture shows budget field was adding to Last record i.e, test but it should be added to admin instead.

      and also as below picture when it will cross the collect statement the sytabix becomes 5.

      and last column of final table was getting multiple times added as shown in below picture.

      I debugged many times and changed code accordingly but no use.

      Please i need your suggestion which will be lot help full.

      capture.jpg (58.3 kB)
      capture1.jpg (109.7 kB)
      capture2.jpg (41.2 kB)
  • Jun 12, 2018 at 01:49 PM

    Hello @roberto.forti,

    If i will use append instead of collect the result will be as below picture.

    and where should i implement your peace of code i.e, field symbols code, i mean after it_final_cc or or it_bppe loop ?

    i placed your code after it_bppe as code shows below.

      DATA: lv_tabix TYPE sytabix, "Index of Internal Tables
    
            wa_bppe1 LIKE LINE OF it_bppe,
    
            wa_bppe2 LIKE LINE OF it_bppe.
    
    
    
      SORT it_bppe ASCENDING BY wrttp.
    
    
    
    *CO Object: Cost Totals for External Postings
    
      READ TABLE it_bppe INTO wa_bppe1 BINARY SEARCH WITH KEY wrttp = '41' . "Budget
    
    
    
      IF sy-subrc EQ 0.
    
        "Index of Internal Tables
    
        lv_tabix = sy-tabix.
    
    
    
        LOOP AT it_bppe INTO wa_bppe2 FROM sy-tabix.
    
    
    
          IF ( wa_bppe1-wrttp NE wa_bppe2-wrttp ).
    
            EXIT.
    
          ELSE.
    
            wa_final_cc-budget = ( wa_bppe2-wtp01 + wa_bppe2-wtp02 + wa_bppe2-wtp03 + wa_bppe2-wtp04
    
                                  +  wa_bppe2-wtp05 + wa_bppe2-wtp06 + wa_bppe2-wtp07 + wa_bppe2-wtp08
    
                                  + wa_bppe2-wtp09 + wa_bppe2-wtp10 + wa_bppe2-wtp11 + wa_bppe2-wtp12
    
                                  + wa_bppe2-wtp13 + wa_bppe2-wtp14 + wa_bppe2-wtp15 + wa_bppe2-wtp16 ).
    
    
    
            wa_final_cc-allot = ( wa_final_cc-commit ) + ( wa_final_cc-actual ).
    
            wa_final_cc-avail = ( wa_final_cc-allot ) - ( wa_final_cc-budget ).
    
    
    
            COLLECT wa_final_cc INTO it_final_cc .
    
    
    
          ENDIF.
    
    
    
    *    CLEAR wa_final_cc.
    
    
    
        ENDLOOP.
    
    
    
    
    
      FIELD-SYMBOLS: <fs_final_cc> LIKE LINE OF it_final_cc.
    
    
    
      READ TABLE it_final_cc[] ASSIGNING <fs_final_cc>
    
        WITH KEY kostl = 'ADMIN'.
    
    
    
      IF sy-subrc EQ 0.
    
        <fs_final_cc>-budget = wa_final_cc-budget.
    
      ENDIF.
    
    
    
      ENDIF.


    append.jpg (95.3 kB)
    field-symbol.jpg (35.9 kB)
    Add comment
    10|10000 characters needed characters exceeded

    • Harish, we are discussing Budget '41' logic then don't use collect and append statment for this specific new logic but consider assigning values added/summarized into work area fields (wa_final_cc-budget, wa_final_cc-allot and wa_final_cc-avail) into corresponding fields from internal table it_final_cc as sent.

      Regards,