Posting Document BAPI_ACC_DOCUMENT_POST
some time requirements to post document with help of this documents we can post the documents
*&---------------------------------------------------------------------*
*& Include ZFI_R_INS_POST_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form CLEAR_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM clear_data .
ENDFORM. " CLEAR_DATA
*&---------------------------------------------------------------------*
*& Form F_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_feth_data.
SELECT * FROM zfi_ins_sale INTO TABLE gt_app WHERE ztrn IN s_ztrn
AND post_doc EQ ' '
AND l1_app NE 'R'
AND l2_app NE 'R'
AND l2_app EQ 'A'.
ENDFORM. " F_DISPLAY
*&---------------------------------------------------------------------*
*& Form F_PROCESS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_process .
LOOP AT gt_app INTO gs_app.
MOVE-CORRESPONDING gs_app TO gs_final.
APPEND gs_final TO gt_final.
CLEAR: gs_final,gs_app.
ENDLOOP.
ENDFORM. " F_PROCESS
*&---------------------------------------------------------------------*
*& Form F_FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_fieldcatalog .
CLEAR: gs_field, gt_field.
REFRESH: gt_field.
gs_field-fieldname = 'ZTRN'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Transaction Number'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'CUSTOMER'.
gs_field-seltext_l = 'Institutional Customer'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'DELAR_CODE'.
gs_field-seltext_l = 'DEALER CODE'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'DELAR_NAME'.
gs_field-seltext_l = 'DEALER NAME'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'DELAR_CITY'.
gs_field-seltext_l = 'DEALER CITY'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'MODEL'.
gs_field-seltext_l = 'Model'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'QTY'.
gs_field-seltext_l = 'QTY'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'PRICE_SM'.
gs_field-seltext_l = 'Price Showroom'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'TOTAL_PM'.
gs_field-seltext_l = 'Total Price'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'CREDIT_AM'.
gs_field-seltext_l = 'Credit Amount'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'PO_NUM'.
gs_field-seltext_l = 'PO Number'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'PO_DATE '.
gs_field-seltext_l = 'PO DATE'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'DO_VALU'.
gs_field-seltext_l = 'DEL discount value'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'DIS_VALUE'.
gs_field-seltext_l = 'Discount value'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'CLAM_AM'.
gs_field-seltext_l = 'Claim Amount'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'CUST_NAME'.
gs_field-seltext_l = 'Customer Name'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'CUST_FN'.
gs_field-seltext_l = 'Customer Firm Name'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'PHONE_NUM'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Phone Number'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'L1APPBY'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Approval name L1'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'L1_APP'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Approval L1'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'L1_TIMESSTAM'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Approval L1 Date Time'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'L1APPBY'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Approval name L2'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'L2_APP'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Approval L2'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'L2_TIMESSTAM'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Approval L2 Date Time'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'CREATED_BY'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Created by'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'CREATION_ON'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Creation Time'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
ENDFORM. " F_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form F_ALV_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_alv_display .
CLEAR: gs_lay.
* gs_lay-colwidth_optimize = 'X'.
* gs_lay-zebra = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = 'X'
i_buffer_active = space
i_default = 'X'
i_save = 'A'
i_callback_program = sy-repid
i_callback_pf_status_set = 'PF-STATUS'
i_callback_user_command = 'USER_COMMAND'
i_callback_top_of_page = 'TOP_OF_PAGE'
is_layout = gs_lay
it_fieldcat = gt_field
TABLES
t_outtab = gt_final.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM. " F_ALV_DISPLAY
*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM top_of_page.
CLEAR: gt_header, gs_header.
REFRESH : gt_header.
* •title
gs_header-typ = 'H'.
gs_header-info = 'Institutional Sales post document:'.
APPEND gs_header TO gt_header.
CLEAR gs_header.
* •date
gs_header-typ = 'S'.
gs_header-key = 'Run Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO gs_header-info. "todays date
APPEND gs_header TO gt_header.
CLEAR: gs_header.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = gt_header.
ENDFORM. "top_of_page
*&---------------------------------------------------------------------*
*& Form pf-status
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM pf-status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'PF_STATUS1'.
ENDFORM. "pf-status
*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.
DATA : li_count TYPE i.
* rs_selfield TYPE slis_selfield.
DATA: lv_case TYPE sy-ucomm.
DATA: gd_repid LIKE sy-repid,
ref_grid TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref_grid.
CALL METHOD ref_grid->check_changed_data.
lv_case = sy-ucomm.
CASE lv_case.
WHEN 'POST'.
DATA : it_documentheader TYPE TABLE OF bapiache09,
wa_documentheader TYPE bapiache09.
DATA : lv_obj_type TYPE bapiache09-obj_type,
lv_obj_key TYPE bapiache09-obj_key,
lv_obj_sys TYPE bapiache09-obj_sys.
DATA : it_accountgl TYPE TABLE OF bapiacgl09,
wa_accountgl TYPE bapiacgl09,
it_accountreceivable TYPE TABLE OF bapiacar09,
wa_accountreceivable TYPE bapiacar09,
it_accountpayable TYPE TABLE OF bapiacap09,
wa_accountpayable TYPE bapiacap09,
it_currencyamount TYPE TABLE OF bapiaccr09,
wa_currencyamount TYPE bapiaccr09,
it_extension1 TYPE TABLE OF bapiacextc,
wa_extension1 TYPE bapiacextc,
it_criteria TYPE TABLE OF bapiackec9,
wa_criteria TYPE bapiackec9,
it_valuefield TYPE TABLE OF bapiackev9,
wa_valuefield TYPE bapiackev9,
it_return TYPE TABLE OF bapiret2,
lw_return TYPE bapiret2,
it_extension2 TYPE TABLE OF bapiparex,
wa_extension2 TYPE bapiparex.
DATA : gv_prctr TYPE cska-kstar,
lv_bldat TYPE c LENGTH 8,
lv_budat TYPE c LENGTH 8,
posnr_acc TYPE posnr_acc,
item_text TYPE string,
item_text1 TYPE string,
lv_new_text TYPE string,
lv_new_text1 TYPE string,
header_start.
posnr_acc = posnr_acc + 1.
LOOP AT gt_final INTO gs_final.
CONCATENATE 'For-' gs_final-qty '-' gs_final-model INTO lv_new_text.
CONCATENATE gs_final-delar_code lv_new_text INTO item_text SEPARATED BY space.
CONCATENATE 'For-' gs_final-qty '-' gs_final-model INTO lv_new_text1.
CONCATENATE gs_final-customer lv_new_text1 INTO item_text1 SEPARATED BY space .
*****************************************To fill wa_documentheader*********************************************
wa_documentheader-username = sy-uname.
wa_documentheader-header_txt = 'INSTITUTIONAL SALES'.
wa_documentheader-comp_code = '50AG'.
wa_documentheader-doc_date = sy-datum.
wa_documentheader-pstng_date = sy-datum. " h fs
wa_documentheader-trans_date = sy-datum.
wa_documentheader-doc_type = 'DG'.
wa_documentheader-ref_doc_no = 'REF-006'.
wa_documentheader-vatdate = sy-datum.
**********************************************account receivable*****************************************************************
wa_accountreceivable-itemno_acc = posnr_acc.
wa_accountreceivable-customer = gs_final-customer.
wa_accountreceivable-pmnttrms = '0001'.
wa_accountreceivable-bline_date = sy-datum.
* wa_accountreceivable-alloc_nmbr = 'text any'.
wa_accountreceivable-item_text = item_text1.
wa_accountreceivable-businessplace = 'HR02' .
wa_accountreceivable-sectioncode = 'MNSR'.
wa_accountreceivable-profit_ctr = '1000'.
APPEND wa_accountreceivable TO it_accountreceivable .
CLEAR:wa_accountreceivable.
******************************* currencyamount**************************************
wa_currencyamount-itemno_acc = posnr_acc.
wa_currencyamount-currency = 'INR'.
wa_currencyamount-amt_doccur = gs_final-credit_am.
APPEND wa_currencyamount TO it_currencyamount .
CLEAR : wa_currencyamount.
posnr_acc = posnr_acc + 1.
wa_accountreceivable-itemno_acc = posnr_acc.
wa_accountreceivable-customer = gs_final-delar_code.
wa_accountreceivable-pmnttrms = '0001'.
wa_accountreceivable-bline_date = sy-datum.
* wa_accountreceivable-alloc_nmbr = 'text any'.
wa_accountreceivable-item_text = item_text.
wa_accountreceivable-businessplace = 'HR02' .
wa_accountreceivable-sectioncode = 'MNSR'.
wa_accountreceivable-profit_ctr = '1000'.
APPEND wa_accountreceivable TO it_accountreceivable .
CLEAR:wa_accountreceivable.
wa_currencyamount-itemno_acc = posnr_acc.
wa_currencyamount-currency = 'INR'.
wa_currencyamount-amt_doccur = gs_final-credit_am * -1.
APPEND wa_currencyamount TO it_currencyamount .
CLEAR : wa_currencyamount.
*****************************************************************************************************
* wa_extension2-structure = 'GST_PARTNER'.
* wa_extension2-valuepart1 = '0000000001'.
* wa_extension2-valuepart2 = '0000000014'.
* APPEND wa_extension2 TO it_extension2.
* CLEAR:wa_extension2.
* wa_extension2-structure = 'PLACE_SUPPLY'.
* wa_extension2-valuepart1 = '0000000001'.
* wa_extension2-valuepart2 = '0000000007'.
* APPEND wa_extension2 TO it_extension2.
* CLEAR:wa_extension2.
* wa_extension2-structure = 'BUPLA'.
* wa_extension2-valuepart1 = 'MNSR'.
* APPEND wa_extension2 TO it_extension2.
* CLEAR:wa_extension2.
* wa_extension2-structure = 'INVOICE'.
* wa_extension2-valuepart1 = 'X'.
* APPEND wa_extension2 TO it_extension2.
* CLEAR:wa_extension2.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = wa_documentheader
IMPORTING
obj_type = lv_obj_type
obj_key = lv_obj_key
obj_sys = lv_obj_sys
TABLES
* accountgl = it_accountgl
accountreceivable = it_accountreceivable
currencyamount = it_currencyamount
extension2 = it_extension2
return = it_return.
READ TABLE it_return INTO lw_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
LOOP AT it_return INTO lw_return.
lw_output-type = lw_return-type.
lw_output-number = lw_return-number.
lw_output-message = lw_return-message.
APPEND lw_output TO gt_output.
CLEAR lw_output.
ENDLOOP.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = lw_return.
READ TABLE it_return INTO lw_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
IMPORTING
return = lw_return.
LOOP AT it_return INTO lw_return.
lw_output-type = lw_return-type.
lw_output-number = lw_return-number.
lw_output-message = lw_return-message.
APPEND lw_output TO gt_output.
CLEAR lw_output.
ENDLOOP.
ELSE.
********************************* updating table ********************************************************************
UPDATE zfi_ins_sale SET post_doc = lv_obj_key+0(10)
post_year = lv_obj_key+14(4)
WHERE ztrn = gs_final-ztrn
AND customer = gs_final-customer
AND delar_code = gs_final-delar_code.
********************************************************************************************************************
READ TABLE it_return INTO lw_return WITH KEY type = 'S'
number = '605'.
IF sy-subrc EQ 0.
lw_output-type = 'S'.
lw_output-number = lw_return-number.
CONCATENATE lw_return-message_v2+0(10) lw_return-message_v2+14(4)
INTO lw_output-message SEPARATED BY '-'.
CONCATENATE 'Document'(048) lw_output-message
'has been Posted Successfully'(050)
INTO lw_output-message SEPARATED BY space.
APPEND lw_output TO gt_output.
CLEAR lw_output.
ENDIF.
ENDIF.
ENDIF.
CLEAR: gs_final,item_text,wa_documentheader.
REFRESH:it_accountgl[],it_accountreceivable[],it_currencyamount[],it_extension2[],it_return[].
ENDLOOP.
WHEN 'BACK2'.
CALL TRANSACTION 'ZINST_POST'.
LEAVE PROGRAM.
SET SCREEN 0.
LEAVE LIST-PROCESSING.
ENDCASE.
ENDFORM. "user_command
*&---------------------------------------------------------------------*
*& Form F_SENT_APPROVAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_sent_approval .
ENDFORM. " F_SENT_APPROVAL
*&---------------------------------------------------------------------*
*& Form F_FILL_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_fill_table .
ENDFORM. " F_FILL_TABLE
*&---------------------------------------------------------------------*
*& Include ZFI_R_INS_POST_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form CLEAR_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM clear_data .
ENDFORM. " CLEAR_DATA
*&---------------------------------------------------------------------*
*& Form F_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_feth_data.
SELECT * FROM zfi_ins_sale INTO TABLE gt_app WHERE ztrn IN s_ztrn
AND post_doc EQ ' '
AND l1_app NE 'R'
AND l2_app NE 'R'
AND l2_app EQ 'A'.
ENDFORM. " F_DISPLAY
*&---------------------------------------------------------------------*
*& Form F_PROCESS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_process .
LOOP AT gt_app INTO gs_app.
MOVE-CORRESPONDING gs_app TO gs_final.
APPEND gs_final TO gt_final.
CLEAR: gs_final,gs_app.
ENDLOOP.
ENDFORM. " F_PROCESS
*&---------------------------------------------------------------------*
*& Form F_FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_fieldcatalog .
CLEAR: gs_field, gt_field.
REFRESH: gt_field.
gs_field-fieldname = 'ZTRN'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Transaction Number'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'CUSTOMER'.
gs_field-seltext_l = 'Institutional Customer'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'DELAR_CODE'.
gs_field-seltext_l = 'DEALER CODE'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'DELAR_NAME'.
gs_field-seltext_l = 'DEALER NAME'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'DELAR_CITY'.
gs_field-seltext_l = 'DEALER CITY'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'MODEL'.
gs_field-seltext_l = 'Model'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'QTY'.
gs_field-seltext_l = 'QTY'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'PRICE_SM'.
gs_field-seltext_l = 'Price Showroom'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'TOTAL_PM'.
gs_field-seltext_l = 'Total Price'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'CREDIT_AM'.
gs_field-seltext_l = 'Credit Amount'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'PO_NUM'.
gs_field-seltext_l = 'PO Number'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'PO_DATE '.
gs_field-seltext_l = 'PO DATE'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'DO_VALU'.
gs_field-seltext_l = 'DEL discount value'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'DIS_VALUE'.
gs_field-seltext_l = 'Discount value'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'CLAM_AM'.
gs_field-seltext_l = 'Claim Amount'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'CUST_NAME'.
gs_field-seltext_l = 'Customer Name'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'CUST_FN'.
gs_field-seltext_l = 'Customer Firm Name'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'PHONE_NUM'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Phone Number'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'L1APPBY'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Approval name L1'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'L1_APP'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Approval L1'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'L1_TIMESSTAM'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Approval L1 Date Time'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'L1APPBY'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Approval name L2'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'L2_APP'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Approval L2'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'L2_TIMESSTAM'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Approval L2 Date Time'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'CREATED_BY'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Created by'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
gs_field-fieldname = 'CREATION_ON'.
* gs_field-edit = 'X'.
gs_field-seltext_l = 'Creation Time'.
gs_field-tabname = 'gt_final'.
* gs_field-emphasize = 'C1'.
APPEND gs_field TO gt_field.
CLEAR gs_field.
ENDFORM. " F_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form F_ALV_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_alv_display .
CLEAR: gs_lay.
* gs_lay-colwidth_optimize = 'X'.
* gs_lay-zebra = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = 'X'
i_buffer_active = space
i_default = 'X'
i_save = 'A'
i_callback_program = sy-repid
i_callback_pf_status_set = 'PF-STATUS'
i_callback_user_command = 'USER_COMMAND'
i_callback_top_of_page = 'TOP_OF_PAGE'
is_layout = gs_lay
it_fieldcat = gt_field
TABLES
t_outtab = gt_final.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM. " F_ALV_DISPLAY
*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM top_of_page.
CLEAR: gt_header, gs_header.
REFRESH : gt_header.
* •title
gs_header-typ = 'H'.
gs_header-info = 'Institutional Sales post document:'.
APPEND gs_header TO gt_header.
CLEAR gs_header.
* •date
gs_header-typ = 'S'.
gs_header-key = 'Run Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO gs_header-info. "todays date
APPEND gs_header TO gt_header.
CLEAR: gs_header.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = gt_header.
ENDFORM. "top_of_page
*&---------------------------------------------------------------------*
*& Form pf-status
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM pf-status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'PF_STATUS1'.
ENDFORM. "pf-status
*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.
DATA : li_count TYPE i.
* rs_selfield TYPE slis_selfield.
DATA: lv_case TYPE sy-ucomm.
DATA: gd_repid LIKE sy-repid,
ref_grid TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref_grid.
CALL METHOD ref_grid->check_changed_data.
lv_case = sy-ucomm.
CASE lv_case.
WHEN 'POST'.
DATA : it_documentheader TYPE TABLE OF bapiache09,
wa_documentheader TYPE bapiache09.
DATA : lv_obj_type TYPE bapiache09-obj_type,
lv_obj_key TYPE bapiache09-obj_key,
lv_obj_sys TYPE bapiache09-obj_sys.
DATA : it_accountgl TYPE TABLE OF bapiacgl09,
wa_accountgl TYPE bapiacgl09,
it_accountreceivable TYPE TABLE OF bapiacar09,
wa_accountreceivable TYPE bapiacar09,
it_accountpayable TYPE TABLE OF bapiacap09,
wa_accountpayable TYPE bapiacap09,
it_currencyamount TYPE TABLE OF bapiaccr09,
wa_currencyamount TYPE bapiaccr09,
it_extension1 TYPE TABLE OF bapiacextc,
wa_extension1 TYPE bapiacextc,
it_criteria TYPE TABLE OF bapiackec9,
wa_criteria TYPE bapiackec9,
it_valuefield TYPE TABLE OF bapiackev9,
wa_valuefield TYPE bapiackev9,
it_return TYPE TABLE OF bapiret2,
lw_return TYPE bapiret2,
it_extension2 TYPE TABLE OF bapiparex,
wa_extension2 TYPE bapiparex.
DATA : gv_prctr TYPE cska-kstar,
lv_bldat TYPE c LENGTH 8,
lv_budat TYPE c LENGTH 8,
posnr_acc TYPE posnr_acc,
item_text TYPE string,
item_text1 TYPE string,
lv_new_text TYPE string,
lv_new_text1 TYPE string,
header_start.
posnr_acc = posnr_acc + 1.
LOOP AT gt_final INTO gs_final.
CONCATENATE 'For-' gs_final-qty '-' gs_final-model INTO lv_new_text.
CONCATENATE gs_final-delar_code lv_new_text INTO item_text SEPARATED BY space.
CONCATENATE 'For-' gs_final-qty '-' gs_final-model INTO lv_new_text1.
CONCATENATE gs_final-customer lv_new_text1 INTO item_text1 SEPARATED BY space .
*****************************************To fill wa_documentheader*********************************************
wa_documentheader-username = sy-uname.
wa_documentheader-header_txt = 'INSTITUTIONAL SALES'.
wa_documentheader-comp_code = '50AG'.
wa_documentheader-doc_date = sy-datum.
wa_documentheader-pstng_date = sy-datum. " h fs
wa_documentheader-trans_date = sy-datum.
wa_documentheader-doc_type = 'DG'.
wa_documentheader-ref_doc_no = 'REF-006'.
wa_documentheader-vatdate = sy-datum.
**********************************************account receivable*****************************************************************
wa_accountreceivable-itemno_acc = posnr_acc.
wa_accountreceivable-customer = gs_final-customer.
wa_accountreceivable-pmnttrms = '0001'.
wa_accountreceivable-bline_date = sy-datum.
* wa_accountreceivable-alloc_nmbr = 'text any'.
wa_accountreceivable-item_text = item_text1.
wa_accountreceivable-businessplace = 'HR02' .
wa_accountreceivable-sectioncode = 'MNSR'.
wa_accountreceivable-profit_ctr = '1000'.
APPEND wa_accountreceivable TO it_accountreceivable .
CLEAR:wa_accountreceivable.
******************************* currencyamount**************************************
wa_currencyamount-itemno_acc = posnr_acc.
wa_currencyamount-currency = 'INR'.
wa_currencyamount-amt_doccur = gs_final-credit_am.
APPEND wa_currencyamount TO it_currencyamount .
CLEAR : wa_currencyamount.
posnr_acc = posnr_acc + 1.
wa_accountreceivable-itemno_acc = posnr_acc.
wa_accountreceivable-customer = gs_final-delar_code.
wa_accountreceivable-pmnttrms = '0001'.
wa_accountreceivable-bline_date = sy-datum.
* wa_accountreceivable-alloc_nmbr = 'text any'.
wa_accountreceivable-item_text = item_text.
wa_accountreceivable-businessplace = 'HR02' .
wa_accountreceivable-sectioncode = 'MNSR'.
wa_accountreceivable-profit_ctr = '1000'.
APPEND wa_accountreceivable TO it_accountreceivable .
CLEAR:wa_accountreceivable.
wa_currencyamount-itemno_acc = posnr_acc.
wa_currencyamount-currency = 'INR'.
wa_currencyamount-amt_doccur = gs_final-credit_am * -1.
APPEND wa_currencyamount TO it_currencyamount .
CLEAR : wa_currencyamount.
*****************************************************************************************************
* wa_extension2-structure = 'GST_PARTNER'.
* wa_extension2-valuepart1 = '0000000001'.
* wa_extension2-valuepart2 = '0000000014'.
* APPEND wa_extension2 TO it_extension2.
* CLEAR:wa_extension2.
* wa_extension2-structure = 'PLACE_SUPPLY'.
* wa_extension2-valuepart1 = '0000000001'.
* wa_extension2-valuepart2 = '0000000007'.
* APPEND wa_extension2 TO it_extension2.
* CLEAR:wa_extension2.
* wa_extension2-structure = 'BUPLA'.
* wa_extension2-valuepart1 = 'MNSR'.
* APPEND wa_extension2 TO it_extension2.
* CLEAR:wa_extension2.
* wa_extension2-structure = 'INVOICE'.
* wa_extension2-valuepart1 = 'X'.
* APPEND wa_extension2 TO it_extension2.
* CLEAR:wa_extension2.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = wa_documentheader
IMPORTING
obj_type = lv_obj_type
obj_key = lv_obj_key
obj_sys = lv_obj_sys
TABLES
* accountgl = it_accountgl
accountreceivable = it_accountreceivable
currencyamount = it_currencyamount
extension2 = it_extension2
return = it_return.
READ TABLE it_return INTO lw_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
LOOP AT it_return INTO lw_return.
lw_output-type = lw_return-type.
lw_output-number = lw_return-number.
lw_output-message = lw_return-message.
APPEND lw_output TO gt_output.
CLEAR lw_output.
ENDLOOP.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = lw_return.
READ TABLE it_return INTO lw_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
IMPORTING
return = lw_return.
LOOP AT it_return INTO lw_return.
lw_output-type = lw_return-type.
lw_output-number = lw_return-number.
lw_output-message = lw_return-message.
APPEND lw_output TO gt_output.
CLEAR lw_output.
ENDLOOP.
ELSE.
********************************* updating table ********************************************************************
UPDATE zfi_ins_sale SET post_doc = lv_obj_key+0(10)
post_year = lv_obj_key+14(4)
WHERE ztrn = gs_final-ztrn
AND customer = gs_final-customer
AND delar_code = gs_final-delar_code.
********************************************************************************************************************
READ TABLE it_return INTO lw_return WITH KEY type = 'S'
number = '605'.
IF sy-subrc EQ 0.
lw_output-type = 'S'.
lw_output-number = lw_return-number.
CONCATENATE lw_return-message_v2+0(10) lw_return-message_v2+14(4)
INTO lw_output-message SEPARATED BY '-'.
CONCATENATE 'Document'(048) lw_output-message
'has been Posted Successfully'(050)
INTO lw_output-message SEPARATED BY space.
APPEND lw_output TO gt_output.
CLEAR lw_output.
ENDIF.
ENDIF.
ENDIF.
CLEAR: gs_final,item_text,wa_documentheader.
REFRESH:it_accountgl[],it_accountreceivable[],it_currencyamount[],it_extension2[],it_return[].
ENDLOOP.
WHEN 'BACK2'.
CALL TRANSACTION 'ZINST_POST'.
LEAVE PROGRAM.
SET SCREEN 0.
LEAVE LIST-PROCESSING.
ENDCASE.
ENDFORM. "user_command
*&---------------------------------------------------------------------*
*& Form F_SENT_APPROVAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_sent_approval .
ENDFORM. " F_SENT_APPROVAL
*&---------------------------------------------------------------------*
*& Form F_FILL_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_fill_table .
ENDFORM. " F_FILL_TABLE
Comments
Post a Comment