&---------------------------------------------------------------------
*& Report ZSD_BILLING_CREATE
&---------------------------------------------------------------------
*&DEVELOPER : SUMIT
&---------------------------------------------------------------------
REPORT zsd_billing_create.
TABLES : zdi_data .
DATA: itbill_data TYPE STANDARD TABLE OF bapivbrk,
wtbill_data TYPE bapivbrk,
it_return TYPE STANDARD TABLE OF bapiret1,
wa_return TYPE bapiret1,
it_success TYPE STANDARD TABLE OF bapivbrksuccess,
wa_success TYPE bapivbrksuccess.
DATA: s_dlv TYPE likp-vbeln,
wa_likp TYPE likp,
wa_lips TYPE lips,
wa_vbak TYPE vbak.
DATA : LV_VBELN TYPE VBELN .
DATA : LV_MSG TYPE CHAR100 .
TYPES:BEGIN OF ty_data,
vbeln TYPE vbeln,
* ref_doc type char10 ,
END OF ty_data.
TYPES:BEGIN OF ty_final,
vbeln_de TYPE vbeln,
vbeln(120) TYPE c,
END OF ty_final.
TYPES : BEGIN OF TY_FF ,
SELECT(1) ,
MSG(100) .
INCLUDE STRUCTURE zdi_data .
TYPES END OF TY_FF .
DATA: it_data TYPE STANDARD TABLE OF TY_FF , "" TY_DATA,
wa_data TYPE TY_FF.
DATA:it_final TYPE TABLE OF ty_final,
wa_final TYPE ty_final.
DATA:it_fcat TYPE slis_t_fieldcat_alv,
wa_fcat TYPE slis_fieldcat_alv.
DATA:w_col TYPE i.
DATA: it_raw TYPE truxs_t_text_data.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
SELECT-OPTIONS : s_del FOR zdi_data-delivery .
SELECT-OPTIONS : s_di FOR zdi_data-di_number .
SELECT-OPTIONS : s_ul FOR zdi_data-unloading_location .
SELECT-OPTIONS : s_pl FOR zdi_data-plant_location .
SELECT-OPTIONS : s_dd FOR zdi_data-del_date .
SELECT-OPTIONS : s_dt FOR zdi_data-del_time .
SELECTION-SCREEN END OF BLOCK b1.
**
**AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.
** PERFORM GET_FILE_NAME.
START-OF-SELECTION.
SELECT * FROM zdi_data INTO CORRESPONDING FIELDS OF TABLE it_data
WHERE delivery IN s_del AND di_number IN s_di AND unloading_location IN s_ul AND plant_location IN s_pl
AND del_date IN s_dd AND del_time IN s_dt AND billed = '' .
REFRESH:it_final[].
PERFORM display.
* PERFORM CALL_BAPI_FOR_BILLING.
END-OF-SELECTION.
&---------------------------------------------------------------------
*& Form PREPARE_BILLING_DATA
&---------------------------------------------------------------------
*& text
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM prepare_billing_data .
ENDFORM.
&---------------------------------------------------------------------
*& Form CALL_BAPI_FOR_BILLING
&---------------------------------------------------------------------
*& text
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM call_bapi_for_billing .
DATA: blg_msg TYPE string.
REFRESH: it_success[], it_return[].
CLEAR: wa_success, blg_msg.
IF itbill_data[] IS NOT INITIAL.
CALL FUNCTION 'BAPI_BILLINGDOC_CREATEMULTIPLE'
TABLES
billingdatain = itbill_data
return = it_return
success = it_success.
** Check the return table.
LOOP AT it_return INTO wa_return WHERE type = 'E' OR type = 'A'.
* WRITE: / WA_RETURN-MESSAGE.
wa_final-vbeln_de = wa_data-delivery.
wa_final-vbeln = wa_return-message.
lv_msg = wa_return-message.
APPEND wa_final TO it_final.
CLEAR: wa_return,wa_final.
ENDLOOP.
IF it_success[] IS NOT INITIAL.
COMMIT WORK AND WAIT.
READ TABLE it_success INTO wa_success INDEX 1.
CLEAR: blg_msg.
wa_final-vbeln_de = wa_data-delivery.
wa_final-vbeln = wa_success-bill_doc.
LV_VBELN = wa_success-bill_doc.
APPEND wa_final TO it_final.
CLEAR: wa_final.
UPDATE zdi_data SET billed = 'X' bill_NO = wa_success-bill_doc WHERE delivery = wa_data-delivery .
ENDIF.
ENDIF.
ENDFORM.
&---------------------------------------------------------------------
*& Form GET_FILE_NAME
&---------------------------------------------------------------------
*& text
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM get_file_name .
** CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
** EXPORTING
** FIELD_NAME = 'P_FNAME'
** CHANGING
** FILE_NAME = P_FNAME.
ENDFORM.
&---------------------------------------------------------------------
*& Form READ_EXCEL_DATA
&---------------------------------------------------------------------
*& text
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM read_excel_data .
** DATA L_FNAME TYPE RLGRAP-FILENAME.
** L_FNAME = P_FNAME.
** CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
** EXPORTING
** I_LINE_HEADER = '1'
** I_TAB_RAW_DATA = IT_RAW
** I_FILENAME = L_FNAME
** TABLES
** I_TAB_CONVERTED_DATA = IT_DATA.
ENDFORM.
&---------------------------------------------------------------------
*& Form DISPLAY
&---------------------------------------------------------------------
*& text
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM display .
CLEAR wa_fcat.
wa_fcat-fieldname = 'SELECT'.
wa_fcat-tabname = 'IT_DATA'.
wa_fcat-edit = 'X'.
wa_fcat-checkbox = 'X'.
wa_fcat-seltext_m = 'Select'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'DELIVERY'.
wa_fcat-tabname = 'IT_DATA'.
wa_fcat-seltext_m = 'Delivery No.'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'DI_NUMBER'.
wa_fcat-tabname = 'IT_DATA'.
wa_fcat-seltext_m = 'DI Number'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'DEL_DATE'.
wa_fcat-tabname = 'IT_DATA'.
wa_fcat-seltext_m = 'Del Date'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'DEL_TIME'.
wa_fcat-tabname = 'IT_DATA'.
wa_fcat-seltext_m = 'Del Time'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'KDMT'.
wa_fcat-tabname = 'IT_DATA'.
wa_fcat-seltext_m = 'Customer Part'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'UNLOADING_LOCATION'.
wa_fcat-tabname = 'IT_DATA'.
wa_fcat-seltext_m = 'Unload LOcation'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'PLANT_LOCATION'.
wa_fcat-tabname = 'IT_DATA'.
wa_fcat-seltext_m = 'P Location'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'LFIMG'.
wa_fcat-tabname = 'IT_DATA'.
wa_fcat-seltext_m = 'Inv Qty'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'BILL_NO'.
wa_fcat-tabname = 'IT_DATA'.
wa_fcat-seltext_m = 'Billing No'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'MSG'.
wa_fcat-tabname = 'IT_DATA'.
wa_fcat-seltext_m = 'Remarks'.
APPEND wa_fcat TO it_fcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'SET_PF'
I_DEFAULT = 'X'
* IS_LAYOUT = LAYOUT
it_fieldcat = it_fcat
i_save = 'A'
TABLES
t_outtab = it_data[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
FORM set_pf USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZSTATUS'.
ENDFORM.
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
data : ref_grid type ref to cl_gui_alv_grid.
if ref_grid is initial.
call function 'GET_GLOBALS_FROM_SLVC_FULLSCR'
importing
e_grid = ref_grid.
endif.
if not ref_grid is initial.
call method ref_grid->check_changed_data.
endif.
DATA: lv_message TYPE c LENGTH 100.
CASE r_ucomm.
WHEN 'DBILL' .
.
LOOP AT it_data ASSIGNING FIELD-SYMBOL(<FSSS>) WHERE SELECT = 'X' .
CLEAR: wtbill_data, wa_vbak, wa_likp, wa_lips , LV_VBELN , lv_msg .
REFRESH: itbill_data[].
s_dlv = <FSSS>-delivery.
SELECT SINGLE * FROM likp INTO wa_likp WHERE vbeln = s_dlv.
SELECT SINGLE * FROM lips INTO wa_lips WHERE vbeln = s_dlv.
SELECT SINGLE * FROM vbak INTO wa_vbak WHERE vbeln = wa_lips-vgbel.
wtbill_data-ref_doc = <FSSS>-delivery.
wtbill_data-ref_doc_ca = 'J'.
APPEND wtbill_data TO itbill_data.
PERFORM call_bapi_for_billing.
<FSSS>-BILL_NO = LV_VBELN .
if LV_VBELN is INITIAL .
<FSSS>-msg = lv_msg .
else .
<FSSS>-msg = 'SUCCESS' .
endif .
* CLEAR <FSSS>.
ENDLOOP .
ENDCASE.
RS_SELFIELD-REFRESH = 'X'.
ENDFORM.
No comments:
Post a Comment