Pages

Friday, July 27, 2012

SAP ABAP Report using Period as Column Headers


Good Day!

This is my first blog about SAP Abap. I love this programming language though quite very complex not mentioning the thousands of tables it had.
With this, I want to share some tips in creating reports using ALV. There are times when top management want to have a report like product trending in a certain period. Is it possible to create ALV column header using the period as inputted by the user? Just like the sample picture below.


The above output can be done by putting some limitations on period being entered. Period covered should only be approximately 1 year and below, unless you love to through a lot of pain, well, most proggy dork love to do it. For this sample report, I restrict period higher than 1 year. I guess you can do how to do it, co'z even a 5th grader can do it. lol..

Okay! Let's start!
In the Data declaration, I have this code in internal table.

  BEGIN OF alv_Tab occurs 100,
         AGENT(25),              
         KUNNR   LIKE KNA1-KUNNR,
         NAME1   LIKE KNA1-NAME1,
         ARKTX   LIKE VBAP-ARKTX,
         QTY01   LIKE VBAP-KWMENG,
         QTY02   LIKE VBAP-KWMENG,
         QTY03   LIKE VBAP-KWMENG,
         QTY04   LIKE VBAP-KWMENG,
         QTY05   LIKE VBAP-KWMENG,
         QTY06   LIKE VBAP-KWMENG,
         QTY07   LIKE VBAP-KWMENG,
         QTY08   LIKE VBAP-KWMENG,
         QTY09   LIKE VBAP-KWMENG,
         QTY10   LIKE VBAP-KWMENG,
         QTY11   LIKE VBAP-KWMENG,
         QTY12   LIKE VBAP-KWMENG,
         TOTQTY  LIKE VBAP-KWMENG,
  END OF Alv_Tab.


And in the Form Field Catalog, do this.


nCol = 3.
dDate = pDate-low.
ld_color = 0.
WHILE dDate <= pDate-High.
    CLEAR: xField, cWhat, xMonth, cMon.
    nCol = nCol + 1.

    xMonth = dDate+4(2).
    xYear  = dDate+2(2).
    PERFORM Get_Month_Desc.  ""This function will just get the month desc. in 3                              ""chars

    CONCATENATE cMon '-' xYear INTO cWhat.
    CONCATENATE 'QTY' xMonth INTO xField.
    int_fcat-fieldname   = xField.
    int_fcat-seltext_m   = cWhat.
    int_fcat-col_pos     = nCol.
    int_fcat-outputlen   = 17.
    int_fcat-do_sum      = 'X'.
    int_fcat-no_zero     = 'X'.
    append int_fcat to int_fcat.
    clear  int_fcat.

    CALL FUNCTION 'MONTH_PLUS_DETERMINE'
      EXPORTING
           MONTHS        = 1
           OLDDATE       = dDate
     IMPORTING
           NEWDATE        = dDate.
ENDWHILE.


That's it folks. I know this blog quite edgy, so sorry for that, it's my first time.





No comments:

Post a Comment