You are on page 1of 22

*&---------------------------------------------------------------------*

*& Report Z_ALV_DEMO_TOTAL_TEXT


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT

z_alv_demo_total_text.

* Type declaration for final table to display the output


TYPES: BEGIN OF ty_mara,
srno TYPE char40, " Storing the total text
matnr TYPE matnr, " Material
ersda TYPE ersda, " Creation date
ernam TYPE ernam, " Created by
laeda TYPE laeda, " Last change date
aenam TYPE aenam, " Last change by
vpsta TYPE vpsta, " Maintenance status
brgew TYPE brgew, " Gross weight
ntgew TYPE ntgew, " Net weight
gewei TYPE gewei, " Weight Unit
END OF ty_mara.
* Type declaration for table storing temp. data
TYPES: BEGIN OF ty_mara_tmp,
matnr TYPE matnr, " Material
ersda TYPE ersda, " Creation date
ernam TYPE ernam, " Created by
laeda TYPE laeda, " Last change date
aenam TYPE aenam, " Last change by
vpsta TYPE vpsta, " Maintenance status
brgew TYPE brgew, " Gross weight
ntgew TYPE ntgew, " Net weight
gewei TYPE gewei, " Weight Unit
END OF ty_mara_tmp.
* Internal table for storing final data
DATA: i_mara TYPE STANDARD TABLE OF ty_mara INITIAL SIZE 0.
* Work area for final table
DATA: w_mara TYPE ty_mara.
* Internal table for storing temp. data
DATA: i_mara_tmp TYPE STANDARD TABLE OF ty_mara_tmp INITIAL SIZE 0.
* Work area for temp. table
DATA: w_mara_tmp TYPE ty_mara_tmp.
* Object variable for ALV grid
DATA: oref1 TYPE REF TO cl_gui_alv_grid.
* Field catalog table for ALV grid
DATA: fieldcat TYPE lvc_t_fcat.
* Workarea for field catalog table
DATA: w_field TYPE lvc_s_fcat.
* Internal table for storing info. for ALV grid
data: i_sort2 TYPE STANDARD TABLE OF lvc_s_sort INITIAL SIZE 0.
* Workarea for sort table
DATA: wa_sort2
TYPE lvc_s_sort.
* Workarea for ALV layout
data: wa_layout
TYPE lvc_s_layo.
START-OF-SELECTION.
* Fetch data
SELECT matnr

" Material

ersda
" Creation date
ernam
" Created by
laeda
" Last change date
aenam
" Last change by
vpsta
" Maintenance status
brgew
" Gross weight
ntgew
" Net weight
gewei
" Weight Unit
FROM mara
INTO TABLE i_mara_tmp
UP TO 100 ROWS.
CHECK sy-subrc = 0.
* Populate final table
LOOP AT i_mara_tmp INTO w_mara_tmp.
*
*

Storing the Total text need to be displayed in


ALV
w_mara-srno = 'Total weight (Gross & Net)'.
w_mara-matnr = w_mara_tmp-matnr.
w_mara-ersda = w_mara_tmp-ersda.
w_mara-ernam

= w_mara_tmp-ernam .

w_mara-laeda = w_mara_tmp-laeda.
w_mara-aenam = w_mara_tmp-aenam.
w_mara-vpsta = w_mara_tmp-vpsta.
w_mara-brgew = w_mara_tmp-brgew.
w_mara-ntgew = w_mara_tmp-ntgew.
w_mara-gewei = w_mara_tmp-gewei.
APPEND w_mara TO i_mara.
ENDLOOP.
* Calling the screen to display ALV
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*&
Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*
Display ALV report
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
IF oref1 IS INITIAL.
*
*
*

Create ALV grid object


In this case we have not created any custom container in the screen,
Instead of that dummy container name is passed
CREATE OBJECT oref1
EXPORTING
i_parent
= cl_gui_custom_container=>screen0
EXCEPTIONS
error_cntl_create = 1
error_cntl_init
= 2
error_cntl_link
= 3
error_dp_create
= 4
OTHERS
= 5
.
CHECK sy-subrc = 0.

*
*
*

Preparing the field catalog


ZDEMO: Defined in DDIC, it's structure is same as TYPE ty_mara
defined in the program
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING

i_structure_name
CHANGING
ct_fieldcat
EXCEPTIONS
inconsistent_interface
program_error
OTHERS
IF sy-subrc = 0.

= 'ZDEMO'
= fieldcat
= 1
= 2
= 3.

LOOP AT fieldcat INTO w_field.

IF w_field-fieldname = 'BRGEW' OR
w_field-fieldname = 'NTGEW'.
Summation for Gross & Net weight
w_field-do_sum = 'X'.
MODIFY fieldcat FROM w_field TRANSPORTING do_sum.
ENDIF.

*
*

IF w_field-fieldname = 'SRNO'.
Hide this field so that it can display it's content i.e.
Total text in Subtotal level
w_field-tech = 'X'.
w_field-no_out = 'X'.
MODIFY fieldcat FROM w_field TRANSPORTING tech no_out.
ENDIF.
CLEAR w_field.
ENDLOOP.
ENDIF.

*
*

Populate Sort table with SRNO field so that we can display the total
text in it's subtotal level
wa_sort2-spos = 1.
wa_sort2-fieldname = 'SRNO'.
wa_sort2-up = 'X'.
wa_sort2-subtot = 'X'.
APPEND wa_sort2 TO i_sort2.

Hide the total line


wa_layout-no_totline = 'X'.

Display the ALV grid


CALL METHOD oref1->set_table_for_first_display
EXPORTING
is_layout
= wa_layout
CHANGING
it_outtab
= i_mara[]
it_fieldcatalog
= fieldcat
it_sort
= i_sort2
EXCEPTIONS
invalid_parameter_combination = 1
program_error
= 2
too_many_lines
= 3
OTHERS
= 4.
IF sy-subrc <> 0.
ENDIF.

Set the focus on the grid


CALL METHOD cl_gui_alv_grid=>set_focus
EXPORTING
control
= oref1
EXCEPTIONS
cntl_error
= 1
cntl_system_error = 2
OTHERS
= 3.
IF sy-subrc <> 0.
ENDIF.

ENDIF.
ENDMODULE.

" STATUS_0100

OUTPUT

------- - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - REPORT z_demo_alv_jg.


***********************************************************************
* TYPE-POOLS
*
***********************************************************************
TYPE-POOLS: slis.
***********************************************************************
* INTERNAL TABLES/WORK AREAS/VARIABLES
*
***********************************************************************
DATA: i_fieldcat TYPE slis_t_fieldcat_alv,
i_index TYPE STANDARD TABLE OF i WITH HEADER LINE,
w_field TYPE slis_fieldcat_alv,
p_table LIKE dd02l-tabname,
dy_table TYPE REF TO data,
dy_tab TYPE REF TO data,
dy_line TYPE REF TO data.
***********************************************************************
* FIELD-SYMBOLS
*
***********************************************************************
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
<dyn_wa> TYPE ANY,
<dyn_field> TYPE ANY,
<dyn_tab_temp> TYPE STANDARD TABLE.
***********************************************************************
* SELECTION SCREEN
*
***********************************************************************
PARAMETERS: tabname(30) TYPE c,
lines(5) TYPE n.
***********************************************************************
* START-OF-SELECTION
*
***********************************************************************
START-OF-SELECTION.
* Storing table name
p_table = tabname.
* Create internal table dynamically with the stucture of table name
* entered in the selection screen
CREATE DATA dy_table TYPE STANDARD TABLE OF (p_table).
ASSIGN dy_table->* TO <dyn_table>.
IF sy-subrc <> 0.
MESSAGE i000(z_zzz_ca_messages) WITH ' No table found'.
LEAVE TO LIST-PROCESSING.
ENDIF.
* Create workarea for the table
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
* Create another temp. table
CREATE DATA dy_tab TYPE STANDARD TABLE OF (p_table).
ASSIGN dy_tab->* TO <dyn_tab_temp>.

SORT i_fieldcat BY col_pos.


* Select data from table
SELECT * FROM (p_table)
INTO TABLE <dyn_table>
UP TO lines ROWS.
REFRESH <dyn_tab_temp>.
* Display report
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program
= sy-repid
i_structure_name
= p_table
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'SET_PF_STATUS'
TABLES
t_outtab
= <dyn_table>
EXCEPTIONS
program_error
= 1
OTHERS
= 2.
IF sy-subrc <> 0.
ENDIF.
*&---------------------------------------------------------------------*
*&
Form SET_PF_STATUS
*&---------------------------------------------------------------------*
*
Setting custom PF-Status
*----------------------------------------------------------------------*
*
-->RT_EXTAB
Excluding table
*----------------------------------------------------------------------*
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'Z_STANDARD'.
ENDFORM.

"SET_PF_STATUS

*&---------------------------------------------------------------------*
*&
Form user_command
*&---------------------------------------------------------------------*
*
Handling custom function codes
*----------------------------------------------------------------------*
*
-->R_UCOMM
Function code value
*
-->RS_SELFIELD Info. of cursor position in ALV
*----------------------------------------------------------------------*
FORM user_command USING
r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
* Local data declaration
DATA: li_tab TYPE REF TO data,
l_line TYPE REF TO data.
* Local field-symbols
FIELD-SYMBOLS:<l_tab> TYPE table,
<l_wa> TYPE ANY.
* Create table
CREATE DATA li_tab TYPE STANDARD TABLE OF (p_table).
ASSIGN li_tab->* TO <l_tab>.
* Create workarea
CREATE DATA l_line LIKE LINE OF <l_tab>.
ASSIGN l_line->* TO <l_wa>.
CASE r_ucomm.
*

When a record is selected

WHEN '&IC1'.
*

Read the selected record


READ TABLE <dyn_table> ASSIGNING <dyn_wa> INDEX
rs_selfield-tabindex.
IF sy-subrc = 0.

Store the record in an internal table


APPEND <dyn_wa> TO <l_tab>.

Fetch the field catalog info


CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name
= 'Z_DEMO_PDF_JG'
i_structure_name
= p_table
CHANGING
ct_fieldcat
= i_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error
= 2
OTHERS
= 3.
IF sy-subrc = 0.

Make all the fields input enabled except key fields


w_field-input = 'X'.
MODIFY i_fieldcat FROM w_field TRANSPORTING input
WHERE key IS INITIAL.
ENDIF.

Display the record for editing purpose


CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program
= sy-repid
i_structure_name
= p_table
it_fieldcat
= i_fieldcat
i_screen_start_column = 10
i_screen_start_line
= 15
i_screen_end_column
= 200
i_screen_end_line
= 20
TABLES
t_outtab
= <l_tab>
EXCEPTIONS
program_error
= 1
OTHERS
= 2.
IF sy-subrc = 0.

*
*
*
*

Read the modified data


READ TABLE <l_tab> INDEX 1 INTO <l_wa>.
If the record is changed then track its index no.
and populate it in an internal table for future
action
IF sy-subrc = 0 AND <dyn_wa> <> <l_wa>.
<dyn_wa> = <l_wa>.
i_index = rs_selfield-tabindex.
APPEND i_index.
ENDIF.
ENDIF.
ENDIF.

*
*

When save button is pressed


WHEN 'SAVE'.
Sort the index table
SORT i_index.

Delete all duplicate records


DELETE ADJACENT DUPLICATES FROM i_index.
LOOP AT i_index.

*
*

Find out the changes in the internal table


and populate these changes in another internal table
READ TABLE <dyn_table> ASSIGNING <dyn_wa> INDEX i_index.
IF sy-subrc = 0.
APPEND <dyn_wa> TO <dyn_tab_temp>.
ENDIF.
ENDLOOP.

Lock the table


CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
mode_rstable
= 'E'
tabname
= p_table
EXCEPTIONS
foreign_lock
= 1
system_failure = 2
OTHERS
= 3.
IF sy-subrc = 0.

Modify the database table with these changes


MODIFY (p_table) FROM TABLE <dyn_tab_temp>.
REFRESH <dyn_tab_temp>.

Unlock the table


CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
mode_rstable = 'E'
tabname
= p_table.
ENDIF.
ENDCASE.
rs_selfield-refresh = 'X'.

ENDFORM.

"user_command

ALV(Interactive) report with using classes

Added by Sreesudha Gullapalli, last edited by Sreesudha Gullapalli on Mar 26, 2009 (view change)
This report will take delivery document number and delivery date from user and fetches details from delivery table and
fetches
corresponding sales order details and billing details and displays sales order details with ALV list.
Report sales_order_report .
*"Table declarations..............................................................
TABLES: likp. " SD Document: Delivery Header Data
*"Selection Screen Elements.....................................................

SELECT-OPTIONS:
s_deldoc FOR likp-vbeln, " Delivery
s_dldate FOR likp-lfdat. " Delivery Date
*"--------------------------------------------------------------------------------------*
* Type declaration of the structure to hold specified delivery header data *
*"---------------------------------------------------------------------------------------*
TYPES :
BEGIN OF type_s_likp,
vbeln TYPE likp-vbeln, " Delivery
lfdat TYPE likp-lfdat, " Delivery Date
kunnr TYPE likp-kunnr, " Ship-to party
END OF type_s_likp.
*"---------------------------------------------------------------------------------------*
* Type declaration of the structure to hold specified delivery item data

*"---------------------------------------------------------------------------------------*
TYPES :
BEGIN OF type_s_lips,
vbeln TYPE lips-vbeln, " Delivery
posnr TYPE lips-posnr, " Delivery Item
vgbel TYPE lips-vgbel, " Document number of the reference document
vgpos TYPE lips-vgpos, " Item number of the reference item
lfimg TYPE lips-lfimg, " Actual quantity delivered (insales units)
vrkme TYPE lips-vrkme, " Sales unit
END OF type_s_lips.
*"--------------------------------------------------------------------------------------*
* Type declaration of the structure to hold specified data in Customer Master *
*"---------------------------------------------------------------------------------------*
TYPES :
BEGIN OF type_s_kna1,
kunnr TYPE kna1-kunnr, " Customer Number 1
name1 TYPE kna1-name1, " Name 1
END OF type_s_kna1.
*" Type declarations..........................................................................

*"------------------------------------------------------------------------------------------------*
* Type declaration of the structure to hold specified sales document header data *
*"------------------------------------------------------------------------------------------------*
TYPES :
BEGIN OF type_s_vbak,
vbeln TYPE vbak-vbeln, " Sales Document
erdat TYPE vbak-erdat, " Date on Which Record Was Created
aufnr TYPE vbak-aufnr, " Order Number
END OF type_s_vbak.
*"----------------------------------------------------------------------------------------------*
* Type declaration of the structure to hold specified sales document item data *
*"---------------------------------------------------------------------------------------------*
TYPES :
BEGIN OF type_s_vbap,
vbeln TYPE vbak-vbeln, " Sales Document
posnr TYPE vbap-posnr, " Sales Document Item
matnr TYPE vbap-matnr, " Material Number
arktx TYPE vbap-arktx, " Short text for sales orderitem
kwmeng TYPE vbap-kwmeng, " Cumulative Order Quantity in sales Units
vrkme TYPE vbap-vrkme, " Sales unit
END OF type_s_vbap.
*"--------------------------------------------------------------------------------------------*
* Type declaration of the structure to hold specified billing item data
*"--------------------------------------------------------------------------------------------*
TYPES :
BEGIN OF type_s_vbrp,
vbeln TYPE vbrp-vbeln, " Billing Document
posnr TYPE vbrp-posnr, " Billing item
vgbel TYPE vbrp-vgbel, " Document number of the reference document
vgpos TYPE vbrp-vgpos, " Item number of the reference item
fklmg TYPE vbrp-fklmg, " Billing quantity in stockkeeping unit
vrkme TYPE vbrp-vrkme, " Sales unit
END OF type_s_vbrp.
*"-------------------------------------------------------------------------------------------*

* Type declaration of the structure to hold specified sales socument

* header,sales document item data,delivery item data,billing item data

*"-------------------------------------------------------------------------------------------*
TYPES:
BEGIN OF type_s_order,
vbeln TYPE vbap-vbeln, " Sales Document
posnr TYPE vbap-posnr, " Sales Document Item
erdat TYPE vbak-erdat, " Date on Which Record Was Created
kunnr TYPE likp-kunnr, " Sold-to party
name1 TYPE kna1-name1, " Name 1
aufnr TYPE vbak-aufnr, " Order Number
matnr TYPE vbap-matnr, " Material Number
arktx TYPE vbap-arktx, " Short text for sales orderitem
kwmeng TYPE vbap-kwmeng, " Cumulative Order Quantity in sales Units
vrkme TYPE vbap-vrkme, " Sales unit
vbeln1 TYPE lips-vbeln, " Delivery
posnr1 TYPE lips-posnr, " Delivery Item
lfimg TYPE lips-lfimg, " Actual quantity delivered in sales units
vrkme1 TYPE lips-vrkme, " Sales unit
vbeln2 TYPE vbrp-vbeln, " Billing Document
posnr2 TYPE vbrp-posnr, " Billing item
fklmg TYPE vbrp-fklmg, " Billing quantity in stockkeeping unit
vrkme2 TYPE vbrp-vrkme, " Sales unit
END OF type_s_order.
*" Data declarations......................................................................
*"-------------------------------------------------------------------------------------------*
* Work variables

*"-------------------------------------------------------------------------------------------*
DATA :
w_container TYPE REF TO cl_gui_custom_container," Reference variable for
"container
w_grid TYPE REF TO cl_gui_alv_grid. " Reference variable for grid
*" Field String declarations..............................................................
*"------------------------------------------------------------------------------------------*

* Field string variable to hold sales socument header,sales document


* item data,delivery item data,billing item data,fieldcatalog,layout record

*
*

*"-------------------------------------------------------------------- --------------------*
DATA :
fs_kna1 TYPE type_s_kna1, " Holds Customer master record
fs_vbak TYPE type_s_vbak, " Holds sales header record
fs_vbap TYPE type_s_vbap, " Holds sales item record
fs_likp TYPE type_s_likp, " Holds delivery header record
fs_lips TYPE type_s_lips, " Holds delivery item record
fs_vbrp TYPE type_s_vbrp, " Holds billing item record
fs_order TYPE type_s_order, " Holds sales order record
fs_cat TYPE lvc_s_fcat, " Holds fieldcatalog record
fs_lay TYPE lvc_s_layo. " Holds layout record
*" Internal Table declarations...........................................................
**"-----------------------------------------------------------------------------------------*
** Internal Table to hold hold sales socument header,sales document

* item data,delivery item data,billing item data,fieldcatalog,layout records

**"-------------------------------------------------------------------------------------------*
DATA :
t_kna1 LIKE
STANDARD TABLE
OF fs_kna1, " Internal table to hold customer master records
t_vbak LIKE
STANDARD TABLE
OF fs_vbak, " Internal table to hold sales header records
t_vbap LIKE
STANDARD TABLE
OF fs_vbap, " Internal table to hold sales item records
t_likp LIKE
STANDARD TABLE
OF fs_likp, " Internal table to hold delivery header records
t_lips LIKE
STANDARD TABLE
OF fs_lips, " Internal table to hold delivery item records

t_vbrp LIKE
STANDARD TABLE
OF fs_vbrp, " Internal table to hold billing item records
t_order LIKE
STANDARD TABLE
OF fs_order, " Internal table to hold sales order records
t_cat TYPE lvc_t_fcat. " Internal table to hold field
" catalog records
*"------------------------------------------------------------------------------------------------*
* AT SELECTION-SCREEN EVENT *
*"------------------------------------------------------------------------------------------------*
AT SELECTION-SCREEN .
PERFORM check_for_initial.
*"--------------------------------------------------------------------------------------------------*
* AT SELECTION-SCREEN ON S_DELDOC EVENT *
*"--------------------------------------------------------------------------------------------------*
AT SELECTION-SCREEN ON s_deldoc.
PERFORM check_delivery_document.
*"-------------------------------------------------------------------------------------------------*
* AT SELECTION-SCREEN ON S_DLDATE EVENT *
*"------------------------------------------------------------------------------------------------*
AT SELECTION-SCREEN ON s_dldate.
PERFORM check_delivery_date.
*"------------------------------------------------------------------------------------------------*
* START-OF-SELECTION EVENT *
*"-------------------------------------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM data_selection.
*&--------------------------------------------------------------------------------------------------*
*& Form DATA_SELECTION
*&---------------------------------------------------------------------*
* This subroutine is used to select required fields from sales header,
* sales item,delivery header,delivery item ,customer master tables
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine
*----------------------------------------------------------------------*
FORM data_selection .

* Get delivery document number,delivery date,customer number from


* delivery header table
SELECT vbeln " Delivery
lfdat " Delivery Date
kunnr " Customer Number 1
FROM likp
INTO TABLE t_likp
WHERE vbeln IN s_deldoc
AND lfdat IN s_dldate.
IF sy-subrc EQ 0.
* Get Customer name for customer numbers from Customer master table
SELECT kunnr " Customer Number 1
name1 " Name 1
FROM kna1
INTO TABLE t_kna1
FOR ALL ENTRIES IN t_likp
WHERE kunnr EQ t_likp-kunnr.
IF sy-subrc EQ 0.
* Get delivery item number,sales document number,sales item number,
* delivery quantity from delivery item table
SELECT vbeln " Delivery
posnr " Delivery Item
vgbel " Document number of
" reference document
vgpos " Item number of reference item
lfimg " Actual quantity delivered
vrkme " Sales unit
FROM lips
INTO TABLE t_lips
FOR ALL ENTRIES IN t_likp
WHERE vbeln EQ t_likp-vbeln.
IF sy-subrc EQ 0.

* Get sales document number,item number,material,material description,


* ordered quantity from sales item table
SELECT vbeln " Sales Document
posnr " Sales Document Item
matnr " Material Number
arktx " Short text for sales order
" item
kwmeng " Cumulative Order Quantity
vrkme " Sales unit
FROM vbap
INTO TABLE t_vbap
FOR ALL ENTRIES IN t_lips
WHERE vbeln EQ t_lips-vgbel
AND posnr EQ t_lips-vgpos.
IF sy-subrc EQ 0.
* Get sales document number ,created date,purchase order number from
* sales header tableSELECT vbeln " Sales Document
erdat " Date on Which Record Was
" Created
aufnr " Order Number
FROM vbak
INTO TABLE t_vbak
FOR ALL ENTRIES IN t_lips
WHERE vbeln EQ t_lips-vgbel.
IF sy-subrc EQ 0.* Get billing document number,billing item,reference delivery document
* number,delivery item number,billing item from billing item table
SELECT vbeln " Billing Document
posnr " Billing item
vgbel " Document number of the
" reference document
vgpos " Item number of the
" reference
" item

fklmg " Billing quantity in


" stockkeeping unit
vrkme " Sales unit
FROM vbrp
INTO TABLE t_vbrp
FOR ALL ENTRIES IN t_lips
WHERE vgbel EQ t_lips-vbeln
AND vgpos EQ t_lips-posnr.
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ELSE.
* Display message if records are not found for entered values
MESSAGE S000.
EXIT.
ENDIF. " IF SY-SUBRC EQ 0
* Looping Delivery item internal table to assign values to order
* internal table
LOOP AT t_lips INTO fs_lips.
* Get delivery date and customer number for delivery document number
* from delivery header internal table
READ TABLE t_likp WITH KEY vbeln = fs_lips-vbeln
INTO fs_likp.
* Get customer name for customer number from customer master internal
* table
IF sy-subrc EQ 0.
READ TABLE t_kna1 WITH KEY kunnr = fs_likp-kunnr
INTO fs_kna1.
* Get sales document number,item number,ordered quantity for delivery
* document number,item number from sales item internal table
IF sy-subrc EQ 0.
READ TABLE t_vbap WITH KEY vbeln = fs_lips-vgbel

posnr = fs_lips-vgpos INTO fs_vbap.


* Get goods issue date and purchase order number for sales document
* number from sales header internal table
IF sy-subrc EQ 0.
READ TABLE t_vbak WITH KEY vbeln = fs_vbap-vbeln INTO fs_vbak.
IF sy-subrc EQ 0.
* Get billing document number,billing item,billing quantity for delivery
* document number,delivery item number from billing item internal table
READ TABLE t_vbrp WITH KEY vgbel = fs_lips-vbeln
vgpos = fs_lips-posnr INTO
fs_vbrp.
* Assign sales,delivery,billing fields into respective fields of sales
* order internal table
IF sy-subrc EQ 0.
fs_order-vbeln = fs_vbap-vbeln.
fs_order-posnr = fs_vbap-posnr.
fs_order-erdat = fs_vbak-erdat.
fs_order-kunnr = fs_likp-kunnr.
fs_order-name1 = fs_kna1-name1.
fs_order-aufnr = fs_vbak-aufnr.
fs_order-matnr = fs_vbap-matnr.
fs_order-arktx = fs_vbap-arktx.
fs_order-kwmeng = fs_vbap-kwmeng.
fs_order-vrkme = fs_vbap-vrkme.
fs_order-vbeln1 = fs_lips-vbeln.
fs_order-posnr1 = fs_lips-posnr.
fs_order-lfimg = fs_lips-lfimg.
fs_order-vrkme1 = fs_lips-vrkme.
fs_order-vbeln2 = fs_vbrp-vbeln.
fs_order-posnr2 = fs_vbrp-posnr.
fs_order-fklmg = fs_vbrp-fklmg.

fs_order-vrkme2 = fs_vbrp-vrkme.
APPEND fs_order TO t_order.
CLEAR fs_order.
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDLOOP. " LOOP AT T_LIPS INTO FS_LIPS
* Check if the final table is initia
lIF t_order IS INITIAL.
MESSAGE S000.
EXIT.
ELSE.
* Calling screen to display the sales order records
CALL SCREEN 1500.
ENDIF. " IF T_ORDER IS INITIAL
ENDFORM. " DATA_SELECTION
*&---------------------------------------------------------------------*
*& Form CHECK_FOR_INITIAL
*&---------------------------------------------------------------------*
* This subroutine is used to validate selection screen elements
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine
*----------------------------------------------------------------------*
FORM check_for_initial .
* Check if either delivery document number and delivery date is not
* entered
IF s_deldoc IS INITIAL AND s_dldate IS INITIAL.
MESSAGE E001 display like 'S'.
ENDIF. " IF S_DELDOC IS INITIAL AND....
ENDFORM. " CHECK_FOR_INITIAL
*&---------------------------------------------------------------------*
*& Form CHECK_DELIVERY_DOCUMENT
*&---------------------------------------------------------------------*
* This subroutine is used to perform validation on delivery document

* number
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine
*----------------------------------------------------------------------*
FORM check_delivery_document .
* Check if high value is entered without lowvalue
IF s_deldoc-low IS INITIAL AND s_deldoc-high IS NOT INITIAL.
MESSAGE E004 display like 'S'.
ELSE.
* Check if delivery document is in delivery header table
SELECT vbeln " Sales Document
FROM likp
UP TO 1 ROWS
INTO fs_likp-vbeln
WHERE vbeln IN s_deldoc.
ENDSELECT.
* Displays message if there is no record for entered delivery document
* number
IF sy-subrc NE 0.
MESSAGE E002 DISPLAY LIKE 'S'.
ENDIF. " IF SY_SUBRC NE 0
CLEAR fs_likp.
ENDIF. " IF S_DELDOC-LOW IS INITIAL...
ENDFORM. " CHECK_DELIVERY_DOCUMENT
*&---------------------------------------------------------------------*
*& Form CHECK_DELIVERY_DATE
*&---------------------------------------------------------------------*
* This subroutine is used to perform validation on goods issue date
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine
*----------------------------------------------------------------------*
FORM check_delivery_date .
* Check if high value is entered without lowvalue
IF s_dldate-low IS INITIAL AND s_dldate-high IS NOT INITIAL.
MESSAGE E004 DISPLAY LIKE 'S'.

ELSE.
* Check if delivery date is in delivery header table
SELECT lfdat " Date on which record is created
FROM likp
UP TO 1 ROWS
INTO fs_likp-lfdat
WHERE lfdat IN s_dldate.
ENDSELECT.
CLEAR fs_likp.
* Displays message if there is no record for entered delivery date
IF sy-subrc NE 0.
MESSAGE E003 DISPLAY LIKE 'S'.
ENDIF. " IF SY_SUBRC NE 0
ENDIF. " IF S_DLDATE-LOW IS INITIAL...
ENDFORM. " CHECK_DELIVERY_DATE
*&---------------------------------------------------------------------*
*& Module STATUS_1500 OUTPUT
*&---------------------------------------------------------------------*
* This module is used to hold pfstatus for the ALV list display
*----------------------------------------------------------------------*
MODULE status_1500 OUTPUT.
* Holds pf-status for the screen 1500
SET PF-STATUS 'SALES_ORDER'.
* Assigns title to the list output
SET TITLEBAR 'SALES'.
ENDMODULE. " STATUS_1500 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_1500 INPUT
*&---------------------------------------------------------------------*
* This module is used to hold user command for screen navigation
*----------------------------------------------------------------------*
MODULE user_command_1500 INPUT.
* Navigates screen on back,exit,return user commands
CASE sy-ucomm.

WHEN 'BACK' OR '%EX' OR 'RW'.


SET SCREEN '0'.
ENDCASE. " CASE SY-UCOMM
ENDMODULE. " USER_COMMAND_1500 INPUT
*&---------------------------------------------------------------------*
*& Module SALES_DISPLAY OUTPUT
*&---------------------------------------------------------------------*
* This module is used to populate fieldcatalogue and layout and *
* create container and grid and call method of grid to display sales *
* order *
*----------------------------------------------------------------------*
MODULE sales_display OUTPUT.
* Calling subroutine to populate values into fieldcatalogue
PERFORM pop_fcat USING 'VBELN'(006) 'Sales Doc.'(007) '1' .
PERFORM pop_fcat USING 'POSNR'(008) 'Item'(009) '2' .
PERFORM pop_fcat USING 'ERDAT'(010) 'Goods Issue'(011) '3' .
PERFORM pop_fcat USING 'KUNNR'(012) 'Sold-to Party'(013) '4' .
PERFORM pop_fcat USING 'NAME1'(014) 'Sold-to Desciption'(015) '5' .
PERFORM pop_fcat USING 'AUFNR'(016) 'Purchase Order No.'(017) '6' .
PERFORM pop_fcat USING 'MATNR'(018) 'Material'(019) '7' .
PERFORM pop_fcat USING 'ARTKX'(020) 'Material Description'(021) '8'.
PERFORM pop_fcat USING 'KWMENG'(022) 'Ordered Quantity'(023) '9' .
PERFORM pop_fcat USING 'VRKME'(024) 'Sales Unit'(025) '10' .
PERFORM pop_fcat USING 'VBELN1'(026) 'Delivery Doc. No.'(027) '11' .
PERFORM pop_fcat USING 'POSNR1'(028) 'Delivery Item '(029) '12' .
PERFORM pop_fcat USING 'LFIMG'(030) 'Delivery Quantity'(031) '13' .
PERFORM pop_fcat USING 'VRKME1'(032) 'Sales Unit'(025) '14' .
PERFORM pop_fcat USING 'VBELN2'(033) 'Billing doc. No.'(034) '15' .
PERFORM pop_fcat USING 'POSNR2'(035) 'Billing Item'(036) '16' .
PERFORM pop_fcat USING 'FKLMG'(037) 'Billing Quantity'(038) '17' .
PERFORM pop_fcat USING 'VRKME2'(039) 'Sales Unit'(025) '18' .
* Assigning title of layout
fs_lay-grid_title = 'List to display sales order details'(040).
* Creating container for displaying records

CREATE OBJECT w_container


EXPORTING
* parent =
container_name = 'CCONTAINER' .
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Creating grid for the container
CREATE OBJECT w_grid
EXPORTING
* i_shellstyle = 0
* i_lifetime =
i_parent = w_container.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF. " IF SY_SUBRC NE 0
* Calling method of grid to display table contents
CALL METHOD w_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'FS_ORDER'
is_layout = fs_lay
CHANGING
it_outtab = t_order
it_fieldcatalog = t_cat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc NE 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno


WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF. " IF SY_SUBRC NE 0
ENDMODULE. " SALES_DISPLAY OUTPUT
*&---------------------------------------------------------------------*
*& Form POP_FCAT
*&---------------------------------------------------------------------*
* This subroutine is used to populate fieldcatalogue for required
* fields
*----------------------------------------------------------------------*
* -->P_FNAME Holds fieldname
* -->P_CTEXT Holds column text
* -->P_CPOS Holds column position
*----------------------------------------------------------------------*
FORM pop_fcat USING value(p_fname) TYPE c
value(p_ctext) TYPE c
value(p_cpos) TYPE i.
* Assigning fieldname,column text,column position to field catalog
fs_cat-fieldname = p_fname.
fs_cat-coltext = p_ctext.
fs_cat-col_pos = p_cpos.
APPEND fs_cat TO t_cat.
CLEAR fs_cat.
ENDFORM. " POP_FCAT

You might also like