Skip to Content
0
Former Member
Mar 30, 2009 at 07:30 AM

Need help to modify a report written using Field-Groups Concept. - Part1

60 Views

Hello ABAP Experts,

I need your help to modify the following report with following requirement as I have least knowledge

about the field-group concept. Thats is the reason, I am pasting the whole code. As it is part of our

production requirement. I really appreciate your help, If its sent modifying the code required.

Modification required in the report.

To allow the sales representatives to see billed shipments and open orders for the current month.

1) Selection Screen Changes:

u2022 Add selection by Sales group and Customer group

u2022 Add sort by: 3. Ship-to / Material

u2022 Add another selection box

[ ] Open Orders and Shipments with the current month

2) For the new selection box, subtotal sales quantity and delivery quantity.

If delivered, make the sales quantity zero in the subtotal

Current report displays, in Selection Screen

Sales org:

Person Name:

Material:

Plant:

Sales Office:

Ship to Name:

Ship to Number:

Sorts Report by : 1. Person Name 2. Material

Check Boxes : 1. Open Orders 2. Delayed Orders.

report  zorder  LINE-SIZE 170
                  LINE-COUNT 58
                  MESSAGE-ID zv
                  NO STANDARD PAGE HEADING.

TABLES:
cdhdr,                                 "Change Doc Header
cdpos,                                 "Change Doc Item
kna1,                                  "Customer master
likp,                                  "Delivery Header
lips,                                  "Delivery Item
 *lips,                                 "Delivery Item
zvbpa_lfa1,                            "Vendor Master
makt,                                  "Material Desc
t001w,                                 "Plant
tvkbt,                                 "Sales Office
tvko,                                  "Sales Organizations
vbak,                                  "Sales Header
vbap,                                  "Sales Item
zvvbak,                                "Sales Hdr - Time calc
vbup,                                  "Item status
vbep,                                  "Sales Schedule Line
vbfa,                                  "Flow documents
vbpa,                                  "Partners
vbrk,                                  "Billing Header
vbrp.                                  "Billing Item

SELECT-OPTIONS:
  s_vkorg FOR vbak-vkorg OBLIGATORY,
  s_ernam FOR vbak-ernam,
  s_matnr FOR vbap-matnr,
  s_werks FOR vbap-werks,
  s_vkbur FOR vbak-vkbur,
  s_name1 FOR kna1-name1,
  s_kunnr FOR kna1-kunnr.

SELECTION-SCREEN ULINE.


SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(49) text-c20.
PARAMETERS: p_sort TYPE n DEFAULT '1'.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 19(40) text-022.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 19(40) text-023.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 19(40) text-024.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN COMMENT 19(40) text-070.
SELECTION-SCREEN ULINE.

SELECTION-SCREEN BEGIN OF BLOCK b20 WITH FRAME.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:p_open AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN COMMENT 5(48) text-072.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:p_delay AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN COMMENT 5(48) text-073.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b20.

DATA:
vbeln(11),                             "Document number
cancel_dt TYPE d,                      "Cancellation Date
BEGIN OF tabkey,                       "Tabkey
mandant LIKE sy-mandt,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
END OF tabkey,
name1_sp1 LIKE lfa1-name1,             "Sales Carrier Name
name1_sp2 LIKE lfa1-name1,             "Delivery Carrier Name
datum-1 TYPE d,                        "Current Dt Less 1
datum-14 TYPE d,                       "Current Dt Less 14
datum-90 TYPE d,                       "Current Dt Less 90
rpt_hdr1(170),                         "Report Header 1
rpt_hdr2(170),                         "Report Header 2
rpt_hdr3(170),                         "Report Header 3
cb_hdr1(170),                          "Control Break Header 1
line_pos1 TYPE i,                      "Line Print Position HDR1
line_pos2 TYPE i,                      "Line Print Position HDR2
line_pos3 TYPE i,                      "Line Print Position DET2
status,                                "Order Status
open,                                  "Open Order
delayed VALUE 'D',                     "Delayed Order
v_comp(30).                            "Company Text Field

***
DATA: v_flagh2.  " Flag for header 2 & 3
DATA: ls_comwa LIKE vbco6. "Structure for flow information
DATA: t_vbfa_tab TYPE STANDARD TABLE OF vbfa WITH HEADER LINE."Itab
for flow information
data: g_trans_id type vttk-tdlnr. "get transport id from flow
  information
  data  v_sales_org_cpimex type vkorg value  '3300'.

***
  FIELD-GROUPS:
  header,
  order.

  INSERT
  status                                 "Status
  vbak-vkbur                             "Sales Office
  vbak-ernam                             "Created By
  kna1-kunnr                             "Customer
  kna1-name1                             "Customer Name
  vbap-matnr                             "Material
  vbap-werks                             "Plant
  vbep-lddat                             "Load Dt
  vbap-vbeln                             "Sales Document
  INTO header.

  INSERT
  kna1-ort01                             "City
  kna1-regio                             "Region
  likp-traid                             "Transport ID
  lips-vbeln                             "Delivery Document
  lips-ntgew                             "Net Wt
  lips-gewei                             "Unit of Weight
  vbap-kwmeng                            "Order Qty
  vbap-vrkme                             "Sales Unit
  vbak-bstnk                             "Customer PO
  vbak-erdat                             "Sales Create Dt
  vbak-ihrez                             "PO Release
  vbak-vdatu                            "Req Delivery Dt
  vbak-vzeit                            "Req Delivery Time
  vbfa-vbeln                             "Goods issue doc
  vbrk-vbeln                             "Billing Document
  name1_sp1                              "Sales Carrier
  name1_sp2                              "Delivery Carrier

  INTO order.

INITIALIZATION.

AT SELECTION-SCREEN.

  IF NOT p_sort BETWEEN 1 AND 2.
    MESSAGE e022 WITH p_sort.
  ENDIF.

* Report 1 or more of cancelled, delayed or open
  IF p_open IS INITIAL AND
     p_delay IS INITIAL.

    MESSAGE e023.

  ENDIF.

START-OF-SELECTION.

* Load Company Name
  WRITE 'XYZ INC'(000) TO v_comp.

* Calculate Date Range
  datum-1 = sy-datum - 1.
  datum-14 = sy-datum - 14.
  datum-90 = sy-datum - 90.

* Compose Parameter Header
  PERFORM parm_hdr.

** Compose Report Header
  v_flagh2 = 1.
  PERFORM data_selection.

END-OF-SELECTION.

* Determine Sort
  CASE p_sort.
    WHEN 1.
      SORT BY status vbak-ernam kna1-name1 kna1-kunnr
              vbep-lddat vbap-vbeln.
    WHEN 2.
      SORT BY status vbap-matnr vbap-werks vbep-lddat
              vbap-vbeln.
  ENDCASE.

  LOOP.
    AT NEW status.
      CASE status.
        WHEN delayed.
          WRITE 'Delayed Orders'(061) TO rpt_hdr1.
        WHEN OTHERS.
          WRITE 'Open Orders'(062) TO rpt_hdr1.
      ENDCASE.
      NEW-PAGE.
    ENDAT.
    AT NEW vbak-ernam.
      IF p_sort = 1.
        CLEAR cb_hdr1.

        WRITE 'CAA:'(064) TO cb_hdr1.
        WRITE vbak-ernam TO cb_hdr1+5.
        NEW-PAGE.
      ENDIF.
    ENDAT.
    AT NEW vbap-matnr.
      IF p_sort = 2.
        CLEAR makt.
        SELECT SINGLE * FROM makt
            WHERE spras = sy-langu AND
                  matnr = vbap-matnr.
        CLEAR cb_hdr1.
        WRITE 'Material:'(042) TO cb_hdr1.
        WRITE vbap-matnr TO cb_hdr1+10.
        WRITE makt-maktx TO cb_hdr1+21.
        NEW-PAGE.
      ENDIF.
    ENDAT.
    AT NEW vbap-werks.

      AT order.
        RESERVE 3 LINES.
        SKIP 1.
        NEW-LINE.

* Indicate new open item
        WRITE vbap-vbeln TO vbeln.
* Find Transport ID

* Fill the structure LS_COMWA
        ls_comwa-mandt = sy-mandt.
        ls_comwa-vbeln = vbap-vbeln.

        CALL FUNCTION 'RV_ORDER_FLOW_INFORMATION'
          EXPORTING
            comwa    = ls_comwa
          TABLES
            vbfa_tab = t_vbfa_tab.
        IF sy-subrc EQ 0.

          READ TABLE t_vbfa_tab WITH KEY vbtyp_n = '8'.
          IF sy-subrc EQ 0.

            SELECT SINGLE tdlnr INTO g_trans_id
              FROM vttk WHERE tknum = t_vbfa_tab-vbeln.

            CONDENSE g_trans_id.
          ENDIF.
        ENDIF.

        IF vbak-erdat >= datum-1.
          vbeln+10 = 'N'.
        ENDIF.

        CASE p_sort.
          WHEN 1.
            WRITE 1 vbak-vkbur.
            WRITE 8 kna1-name1.
            WRITE 44 vbeln.
            WRITE 56 vbap-matnr.
            WRITE:
                75 vbap-kwmeng LEFT-JUSTIFIED,
                 vbap-vrkme,
                100 vbak-bstnk,
                 vbak-ihrez,
                134 vbak-vdatu,
                    vbak-vzeit,
                154 vbep-lddat.
            WRITE 166 vbap-werks.
            NEW-LINE.
            WRITE:
              5  kna1-ort01,
              41 kna1-regio.
            IF name1_sp2 IS INITIAL.
              WRITE:
                45 name1_sp1,
                ' '.
            ELSE.
              WRITE 45 name1_sp2.
              IF name1_sp1 = name1_sp2.
                WRITE ' '.
              ELSE.
                WRITE '*'.
              ENDIF.
            ENDIF.

            IF  vbak-vkorg =  v_sales_org_cpimex .
              WRITE  81 g_trans_id.
            ELSE.
              WRITE  81 likp-traid.
            ENDIF.

            WRITE:
              102 lips-vbeln,
              115 lips-ntgew NO-ZERO LEFT-JUSTIFIED,
                  lips-gewei,
              140 vbfa-vbeln,
              152 vbrk-vbeln.
          WHEN 2.
            WRITE 1 vbak-ernam.
            WRITE 14 vbak-vkbur.
            WRITE 21 kna1-name1.
            WRITE 57 vbeln.
            WRITE:
                69 vbap-kwmeng LEFT-JUSTIFIED,
                    vbap-vrkme,
                92 vbak-bstnk,
                    vbak-ihrez,
                126 vbak-vdatu,
                  vbak-vzeit,
                146 vbep-lddat.
            WRITE 162 vbap-werks.
            NEW-LINE.
            WRITE:
              5  kna1-ort01,
              41 kna1-regio.
            IF name1_sp2 IS INITIAL.
              WRITE:
                45 name1_sp1,
                ' '.
            ELSE.
              WRITE 45 name1_sp2.
              IF name1_sp1 = name1_sp2.
                WRITE ' '.
              ELSE.
                WRITE '*'.
              ENDIF.
            ENDIF.

            IF  vbak-vkorg =  v_sales_org_cpimex .
              WRITE  81 g_trans_id.
            ELSE.
              WRITE  81 likp-traid.
            ENDIF.

            WRITE:
               102 lips-vbeln,
               115 lips-ntgew NO-ZERO LEFT-JUSTIFIED,
                   lips-gewei,
               140 vbfa-vbeln,
               152 vbrk-vbeln.
        ENDCASE.
      ENDAT.
    ENDLOOP.

*---------------------------------------------------------------------*
*       FORM PARM_HDR                                                 *
*---------------------------------------------------------------------*
FORM parm_hdr.
  WRITE 'Program selections'(101) TO rpt_hdr1.
  WRITE 'Sign'(102) TO rpt_hdr1+29.
  WRITE 'Option'(103) TO rpt_hdr1+34.
  WRITE 'From'(104) TO rpt_hdr1+41.
  WRITE 'To'(105) TO rpt_hdr1+77.
ENDFORM.                    "PARM_HDR
*---------------------------------------------------------------------*
*       FORM RPT_HDR                                                  *
*---------------------------------------------------------------------*
FORM rpt_hdr.
  CASE p_sort.
    WHEN 1.               "When sort by CAA
      WRITE 1'SOff'(066).
      WRITE 8'Customer'(009).
      WRITE 44'Sales Doc'(010).
      WRITE 56'Material'(031).
      WRITE 75'Sales Qty'(011).
      WRITE 100'Customer PO'(012).
      WRITE 134'Req.Del.Dt & Tm'(014).
      WRITE 154'Load Dt'(015).
      WRITE 166'Plnt'(016).
      NEW-LINE.
      WRITE 5'City'(017).
      WRITE 41'Reg'(069).
      WRITE 45'Carrier'(018).
      WRITE 81'Transport ID'(019).
      WRITE 102'Dlvry Doc'(021).
      WRITE 115'Dlvry Qty'(025).
      WRITE 140'PGI Doc'(026).
      WRITE 152'Billng Doc'(027).
    WHEN 2.               "When sort by Material
      WRITE 1'Created By'(008).
      WRITE 14'SOff'(066).
      WRITE 21'Customer'(009).
      WRITE 57'Sales Doc'(010).
      WRITE 69'Sales Qty'(011).
      WRITE 92'Customer PO'(012).
      WRITE 126'Req.Del.Dt & Tm'(014).
      WRITE 146'Load Dt'(015).
      WRITE 162'Plnt'(016).
      NEW-LINE.
      WRITE 5'City'(017).
      WRITE 41'Reg'(069).
      WRITE 45'Carrier'(018).
      WRITE 81'Transport ID'(019).
      WRITE 102'Dlvry Doc'(021).
      WRITE 115'Dlvry Qty'(025).
      WRITE 140'PGI Doc'(026).
      WRITE 152'Billng Doc'(027).
  ENDCASE.
ENDFORM.                    "RPT_HDR

INCLUDE zrpthdri.

WRITE:
/ rpt_hdr1.

ULINE.
IF v_flagh2 <> 0.
  PERFORM rpt_hdr.  "Write secondary header
  ULINE.
* Control Break Header
  WRITE / cb_hdr1.

ENDIF.

Continued in Part-2

Thanks a ton in advance.

Mythili Sharma

Edited by: Mythili sharma on Mar 30, 2009 3:32 AM

Edited by: Rob Burbank on Mar 30, 2009 10:46 AM