0% found this document useful (0 votes)
17 views4 pages

Sales Order Allocation

The document outlines an ABAP report for sales order allocation, which includes data selection from various tables related to sales orders and inventory. It defines a structure for final output, processes data to determine allocation status, and provides functionality for exporting data to Excel. The report also includes event handling for user interactions and displays the processed data in a user-friendly format.

Uploaded by

Charanya Nam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

Sales Order Allocation

The document outlines an ABAP report for sales order allocation, which includes data selection from various tables related to sales orders and inventory. It defines a structure for final output, processes data to determine allocation status, and provides functionality for exporting data to Excel. The report also includes event handling for user interactions and displays the processed data in a user-friendly format.

Uploaded by

Charanya Nam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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

*& Report ZVS_SALES_ORDER_ALLOCATION


*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zvs_sales_order_allocation.

TABLES: vbak, vbap, vbkd, mard, mslb.


TYPES: BEGIN OF ty_final,
vbeln TYPE vbak-vbeln,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,
werks TYPE vbap-werks,
kwmeng TYPE vbap-kwmeng,
labst TYPE mard-labst,
zalloc_quty TYPE kwmeng,
zstatus TYPE char10,
END OF ty_final.

DATA: it_final TYPE TABLE OF ty_final,


wa_final TYPE ty_final.

DATA:lv_filename TYPE string,


lv_path TYPE string,
lv_fullpath TYPE string,
lv_result TYPE i,
lv_default TYPE string,
lv_fname TYPE string.

DATA: lt_fieldcat TYPE REF TO slis_t_fieldcat_alv.


DATA: it_request TYPE TABLE OF bapideliciousrequest,
it_cr_items TYPE TABLE OF bapideliciouscreateditems,
it_return TYPE TABLE OF bapiret2.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.


SELECT-OPTIONS: s_vkorg FOR vbak-vkorg.
PARAMETERS: p_vbeln TYPE vbak-vbeln.
PARAMETERS: p_lprio TYPE vbap-lprio.
SELECT-OPTIONS: s_auart FOR vbak-auart.
SELECTION-SCREEN END OF BLOCK b1.

*&---------------------------------------------------------------------*
*& -------------EVENT CLASSES-------------------
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
CLASS cl_local DEFINITION.
PUBLIC SECTION.
METHODS: get_handler FOR EVENT added_function OF cl_salv_events_table
IMPORTING e_salv_function.
ENDCLASS.

CLASS cl_local IMPLEMENTATION.


METHOD: get_handler.

CASE e_salv_function.
WHEN ’CR_DELVERY’.
SET PARAMETER ID ’VL’ FIELD wa_final-vbeln.
CALL TRANSACTION ’VL01’.
MESSAGE : s005(zmessage_cl).

WHEN ’ALLO_STOCK’.
MESSAGE : s000(zmessage_cl).

CALL FUNCTION ’BAPI_DELIVERYPROCESSING_EXEC’ " USING BAPI FOR SALES DELIVERY


PROCESS...
TABLES
request = it_request
createditems = it_cr_items
return = it_return.

CALL FUNCTION ’BAPI_TRANSACTION_COMMIT’. " COMMITING BAPI TO DATABASE...


LOOP AT it_return INTO DATA(wa_return).
IF wa_return = ’E’.
MESSAGE: e003(zmessage_cl).
ENDIF.
ENDLOOP.
WHEN ’EXPO_EXCEL’. " EXCEL DOWNLOAD...
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = ’File Directory’
default_extension = ’XLS’
initial_directory = ’D:\’
CHANGING
filename = lv_filename
path = lv_path
fullpath = lv_fullpath
user_action = lv_result.
lv_fname = lv_fullpath.

CALL FUNCTION ’GUI_DOWNLOAD’


EXPORTING
bin_filesize = ’’
filename = lv_fname
filetype = ’DAT’
TABLES
data_tab = it_final
* fieldnames = t_final
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

WHEN ’SAVE’.
MESSAGE: s004(zmessage_cl).
WHEN ’BACK’.
LEAVE PROGRAM.
ENDCASE.
ENDMETHOD.
ENDCLASS.

*&---------------------------------------------------------------------*
*& -------------START OF SELECTION-------------------
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
START-OF-SELECTION.
SELECT vbak~vbeln , vbak~auart, vbak~vkorg, vbak~vdatu , vbap~posnr,
vbap~matnr, vbap~werks, vbap~kwmeng, vbap~lfmng, vbap~kbmeng,
vbap~lprio, vbkd~konda, mard~labst, mard~insme, mard~speme,
mslb~charg , mslb~lblab
FROM vbak
INNER JOIN vbap
ON vbak~vbeln = vbap~vbeln
INNER JOIN vbkd
ON vbkd~vbeln = vbap~vbeln
AND vbkd~posnr = vbap~posnr
INNER JOIN mard
ON mard~matnr = vbap~matnr
INNER JOIN mslb
ON mslb~matnr = mard~matnr
AND mslb~werks = mard~werks
WHERE vbak~vkorg IN @s_vkorg
AND vbak~vbeln = @p_vbeln
AND vbap~lprio = @p_lprio
AND vbak~auart IN @s_auart
INTO TABLE @DATA(it_sales_data).
IF it_sales_data IS NOT INITIAL.
SORT it_sales_data BY vbeln posnr matnr.
ENDIF.

*&---------------------------------------------------------------------*
*& -------------DATA PROCESSING -------------------
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
LOOP AT it_sales_data INTO DATA(wa_sales) .
IF wa_sales-labst > wa_sales-kwmeng.
it_final = VALUE #( BASE it_final ( zalloc_quty = wa_sales-kwmeng
zstatus = ’ALLOCATED’ ) ) .

ELSEIF wa_sales-labst < wa_sales-kwmeng.


it_final = VALUE #( BASE it_final ( zalloc_quty = wa_sales-kwmeng
zstatus = ’NOT ALLOCATED’ ) ).
ENDIF.
it_final = VALUE #( BASE it_final ( vbeln = wa_sales-vbeln
posnr = wa_sales-posnr
matnr = wa_sales-matnr
werks = wa_sales-werks
kwmeng = wa_sales-kwmeng
labst = wa_sales-labst ) ) .

it_request = VALUE #( BASE it_request ( document_numb = wa_sales-vbeln


document_item = wa_sales-posnr
material = wa_sales-matnr
plant = wa_sales-werks ) ) .

it_cr_items = VALUE #( BASE it_cr_items ( document_numb = wa_sales-vbeln


document_item = wa_sales-posnr
material = wa_sales-matnr ) ) .
ENDLOOP.

SET PF-STATUS ’FUNL_BUTTONS’. " PF STATUS ...

*&---------------------------------------------------------------------*
*& -------------DISPLAYING THE DATA-------------------
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = DATA(obj)
CHANGING
t_table = it_final.
CATCH cx_salv_msg.
ENDTRY.
CALL METHOD obj->if_salv_gui_om_table_info~set_screen_status
EXPORTING
report = sy-repid
pfstatus = ’FUNL_BUTTONS’
.
CALL METHOD obj->if_salv_gui_om_table_info~get_event
RECEIVING
value = DATA(lo_event).

DATA(obj1) = NEW cl_local( ).

SET HANDLER obj1->get_handler FOR lo_event. " SETTING EVENT HANDLER ...

obj->display( ) .

You might also like