Sample code for Interactive ALV reports( Fetch records from VBAK, on clicking any output record, navigate to Sales Doc Tcode)
*&---------------------------------------------------------------------*
*& Form ALV_DISPLAY
*&---------------------------------------------------------------------*
FORM alv_display .
PERFORM build_fieldcatalog.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_bypassing_buffer = 'X'
i_callback_program = sy-repid
i_callback_user_command = 'USER_COMMAND'
* i_grid_title = 'Interactive ALV'
it_fieldcat = i_fieldcatalog[]
is_layout = w_layout
it_sort = i_sort
i_default = 'X'
i_save = 'A'
is_variant = w_variant
it_events = i_grid_event
TABLES
t_outtab = i_vbak[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. " ALV_DISPLAY
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
FORM user_command USING u_com LIKE sy-ucomm sel_field TYPE slis_selfield.
* CLEAR fcat1.
DATA: t_doc TYPE vbeln.
CLEAR: w_vbak.
CASE u_com.
WHEN '&IC1'.
READ TABLE i_vbak INTO w_vbak INDEX sel_field-tabindex.
IF sy-subrc = 0.
t_doc = w_vbak-vbeln.
SET PARAMETER ID 'AUN' FIELD t_doc.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDFORM. "user_command
Monday, August 23, 2010
Thursday, August 12, 2010
FM for Downloading data to apps -windows folder
soon after close dataset, embed this code.. pass your file path..thats it
*************
lv_additional_parameters = lv_filename.
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
EXPORTING
commandname = 'ZCHMODR'
additional_parameters = lv_additional_parameters. "'/sap_report/ED2/report/ finance/productcosting/TEst_ UNIX.txt'
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
***************
TRINT_SPLIT_FILE_AND_PATH
SUBST_GET_FILE_LIST file path validation
*************
lv_additional_parameters = lv_filename.
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
EXPORTING
commandname = 'ZCHMODR'
additional_parameters = lv_additional_parameters. "'/sap_report/ED2/report/
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
***************
TRINT_SPLIT_FILE_AND_PATH
SUBST_GET_FILE_LIST file path validation
Basic FMs regularly used in Programs
Simple Pop up message with YES No selection
lv_text = text-116.
popup_to_confirm text-032 lv_text c_true lv_answer.
CHECK lv_answer EQ '1'.
FM to convert date into User Profile date
lv_text = text-116.
popup_to_confirm text-032 lv_text c_true lv_answer.
CHECK lv_answer EQ '1'.
FM to convert date into User Profile date
CALL FUNCTION '/SAPDII/SPP05_CONVERT_DATE'
EXPORTING
if_date = lv_date
IMPORTING
ef_date = lv_date.
Finding the Last day of a Month:
Language Key:
CONVERSION_EXIT_ISOLA_INPUT Convert two-digit ISO language -> one-digit SAP language key
CONVERSION_EXIT_ISOLA_ OUTPUTConvert One-digit SAP Lang. Key to Two-digit ISO Lang. Key
Currency Key:
CURRENCY_CODE_ISO_TO_SAP Translates ISO currency key into the SAP internal currency key
CURRENCY_CODE_SAP_TO_ISO Translates an SAP internal currency key into the ISO code
UOM:
UNIT_OF_MEASURE_ISO_TO_SAP Convert an ISO measurement unit code into the SAP code
UNIT_OF_MEASURE_SAP_TO_ISO Converts an SAP measurement unit code into ISO code
ISO_TO_SAP_CURRENCY_CODE
Report to check the status of Object : RSDDCHECK
Finding the Last day of a Month:
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
day_in = w_order_ccard-cc_valid_t
IMPORTING
last_day_of_month = w_order_ccard-cc_valid_t
EXCEPTIONS
day_in_no_date = 1
OTHERS = 2.
EXPORTING
day_in = w_order_ccard-cc_valid_t
IMPORTING
last_day_of_month = w_order_ccard-cc_valid_t
EXCEPTIONS
day_in_no_date = 1
OTHERS = 2.
- DATE_COMPUTE_DAY
- GET_WEEK_INFO_BASED_ON_DATE
Language Key:
CONVERSION_EXIT_ISOLA_INPUT Convert two-digit ISO language -> one-digit SAP language key
CONVERSION_EXIT_ISOLA_
Currency Key:
CURRENCY_CODE_ISO_TO_SAP Translates ISO currency key into the SAP internal currency key
CURRENCY_CODE_SAP_TO_ISO Translates an SAP internal currency key into the ISO code
UOM:
UNIT_OF_MEASURE_ISO_TO_SAP Convert an ISO measurement unit code into the SAP code
UNIT_OF_MEASURE_SAP_TO_ISO Converts an SAP measurement unit code into ISO code
ISO_TO_SAP_CURRENCY_CODE
Report to check the status of Object : RSDDCHECK
Dynamically Setting up values for a field( not a DDIC data element)
* Set Value in Deal Type list
IF li_list IS INITIAL.
l_id = 'G_DLTP'.
w_value-key = c_a.
w_value-text = text-034.
APPEND w_value TO li_list.
w_value-key = c_b.
w_value-text = text-035.
APPEND w_value TO li_list.
w_value-key = c_c.
w_value-text = text-036.
APPEND w_value TO li_list.
CALL FUNCTION 'VRM_SET_ VALUES'
EXPORTING
id = l_id
values = li_ list
EXCEPTIONS
id_illegal_name = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
IF li_list IS INITIAL.
l_id = 'G_DLTP'.
w_value-key = c_a.
w_value-text = text-034.
APPEND w_value TO li_list.
w_value-key = c_b.
w_value-text = text-035.
APPEND w_value TO li_list.
w_value-key = c_c.
w_value-text = text-036.
APPEND w_value TO li_list.
CALL FUNCTION 'VRM_SET_
EXPORTING
id = l_id
values = li_
EXCEPTIONS
id_illegal_name = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE
WITH sy-msgv1
ENDIF.
ENDIF.
BAPI_MATERIAL_AVAILABILITY issues
https://forums.sdn.sap.com/message.jspa?messageID=5996074
Hi all,
The reason for returning a commited quantity as 9999999999: So the issue is completely at Master data maintenance level.
details as follows:
There are 2 Cases: 1. ATP check for the Req Date & Req Quant.
2. ATP check for entire Material-Plant-Storage Loc
In either of the cases: Initially a checks for the Stock level at plant level takes place, then depending on stock availability the BAPI calculates the ATP quant.
IF the stock at plant level = 0.
• Then first RLT (Replenishment Lead Time) is calculated (as per Material master data) and then it calculates the RLT Date as follows
IF Req Date = Passed.
RLT Date = Req Date + RLT time
ELSE.
RLT Date = Current Date + RLT time
ENDIF.
Finally at the time of ATP calculation for Zero stock another check at this RLT date happens, as follows.
IF RLT Date GT (Req Date-If passed otherwise Rundate).
ATP check gets populated depending on current date’s available stock.
ELSE.
Means The ATP check is irrelevant, as no stock available and no visibility for stock updation. So a hard coded “9999999999.000” value is being populated to output Quantity field.
ENDIF.
Edited by: 19740_SANTHI on Mar 1, 2010 7:33 AM
Edited by: 19740_SANTHI on Mar 1, 2010 7:35 AM
Hi all,
The reason for returning a commited quantity as 9999999999: So the issue is completely at Master data maintenance level.
details as follows:
There are 2 Cases: 1. ATP check for the Req Date & Req Quant.
2. ATP check for entire Material-Plant-Storage Loc
In either of the cases: Initially a checks for the Stock level at plant level takes place, then depending on stock availability the BAPI calculates the ATP quant.
IF the stock at plant level = 0.
• Then first RLT (Replenishment Lead Time) is calculated (as per Material master data) and then it calculates the RLT Date as follows
IF Req Date = Passed.
RLT Date = Req Date + RLT time
ELSE.
RLT Date = Current Date + RLT time
ENDIF.
Finally at the time of ATP calculation for Zero stock another check at this RLT date happens, as follows.
IF RLT Date GT (Req Date-If passed otherwise Rundate).
ATP check gets populated depending on current date’s available stock.
ELSE.
Means The ATP check is irrelevant, as no stock available and no visibility for stock updation. So a hard coded “9999999999.000” value is being populated to output Quantity field.
ENDIF.
Edited by: 19740_SANTHI on Mar 1, 2010 7:33 AM
Edited by: 19740_SANTHI on Mar 1, 2010 7:35 AM
Multiple ALV grids in Single report Output
How to display two different ALV grids in single output report.
************************************************************************
* ALV DECLARATION *
************************************************************************
DATA: i_fieldcatalog TYPE slis_t_fieldcat_alv,
w_layout TYPE slis_layout_alv,
w_eve TYPE slis_alv_event,
i_eve TYPE slis_t_event,
i_sort TYPE slis_t_sortinfo_alv,
i_grid_event TYPE slis_t_event,
* Internal table for ALV filter display rows
i_filter TYPE slis_t_filter_alv,
w_grid_event TYPE slis_alv_event,
w_variant LIKE disvariant,
i_icons TYPE slis_t_extab.
Initiate Top of page Events for each ALV lists:
*&---------------------------------------------------------------------*
*& Form TOP_OF_PAGE1
*&---------------------------------------------------------------------*
FORM top_of_page1.
FORMAT COLOR COL_NEGATIVE.
WRITE:/ 'Error Report:'.
FORMAT COLOR OFF .
ENDFORM. "top_of_page
*&---------------------------------------------------------------------*
*& Form TOP_OF_PAGE2
*&---------------------------------------------------------------------*
FORM top_of_page2.
FORMAT COLOR COL_POSITIVE.
WRITE / 'Success Report:'.
FORMAT COLOR OFF.
ENDFORM. "top_of_page
Build field catalogs for each ALV grid.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELD_CATALOG_E
*&---------------------------------------------------------------------*
*
FORM build_field_catalog_e .
DATA: l_position TYPE i,
lw_fieldcatalog TYPE slis_fieldcat_alv.
CONSTANTS: c_table(7) VALUE 'I_ERROR',
c_fcval1(5) VALUE 'BBYNR'.
CLEAR lw_fieldcatalog.
l_position = l_position + 1.
lw_fieldcatalog-fieldname = c_fcval1. "'BBYNR'.
lw_fieldcatalog-tabname = c_table.
lw_fieldcatalog-col_pos = l_position.
lw_fieldcatalog-seltext_l = text-012. "'Bonus Buy'.
lw_fieldcatalog-outputlen = '12'.
APPEND lw_fieldcatalog TO i_fieldcatalog.
CLEAR lw_fieldcatalog.
l_position = l_position + 1.
lw_fieldcatalog-fieldname = c_fcval25. "'VKORG'.
lw_fieldcatalog-tabname = c_table.
lw_fieldcatalog-col_pos = l_position.
lw_fieldcatalog-seltext_l = text-041. "'Sales Org'.
APPEND lw_fieldcatalog TO i_fieldcatalog.
ENDFORM. " BUILD_FIELD_CATALOG_E
Here is the sample code:
DATA lv_repid LIKE sy-repid.
* Start of Multiple ALV steps
lv_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = lv_repid.
REFRESH: i_fieldcatalog[],i_eve.
CLEAR: w_eve.
w_eve-name = 'TOP_OF_PAGE'.
w_eve-form = 'TOP_OF_PAGE1'.
APPEND w_eve TO i_eve.
PERFORM build_field_catalog_e.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = w_layout
it_fieldcat = i_fieldcatalog[]
i_tabname = 'I_ERROR'
it_events = i_eve
TABLES
t_outtab = i_error[].
REFRESH: i_fieldcatalog[],i_eve.
CLEAR: w_eve.
w_eve-name = 'TOP_OF_PAGE'.
w_eve-form = 'TOP_OF_PAGE2'.
APPEND w_eve TO i_eve.
PERFORM build_field_catalog.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = w_layout
it_fieldcat = i_fieldcatalog[]
i_tabname = 'I_FINAL'
it_events = i_eve
TABLES
t_outtab = i_final[].
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'.
************************************************************************
* ALV DECLARATION *
************************************************************************
DATA: i_fieldcatalog TYPE slis_t_fieldcat_alv,
w_layout TYPE slis_layout_alv,
w_eve TYPE slis_alv_event,
i_eve TYPE slis_t_event,
i_sort TYPE slis_t_sortinfo_alv,
i_grid_event TYPE slis_t_event,
* Internal table for ALV filter display rows
i_filter TYPE slis_t_filter_alv,
w_grid_event TYPE slis_alv_event,
w_variant LIKE disvariant,
i_icons TYPE slis_t_extab.
Initiate Top of page Events for each ALV lists:
*&---------------------------------------------------------------------*
*& Form TOP_OF_PAGE1
*&---------------------------------------------------------------------*
FORM top_of_page1.
FORMAT COLOR COL_NEGATIVE.
WRITE:/ 'Error Report:'.
FORMAT COLOR OFF .
ENDFORM. "top_of_page
*&---------------------------------------------------------------------*
*& Form TOP_OF_PAGE2
*&---------------------------------------------------------------------*
FORM top_of_page2.
FORMAT COLOR COL_POSITIVE.
WRITE / 'Success Report:'.
FORMAT COLOR OFF.
ENDFORM. "top_of_page
Build field catalogs for each ALV grid.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELD_CATALOG_E
*&---------------------------------------------------------------------*
*
FORM build_field_catalog_e .
DATA: l_position TYPE i,
lw_fieldcatalog TYPE slis_fieldcat_alv.
CONSTANTS: c_table(7) VALUE 'I_ERROR',
c_fcval1(5) VALUE 'BBYNR'.
CLEAR lw_fieldcatalog.
l_position = l_position + 1.
lw_fieldcatalog-fieldname = c_fcval1. "'BBYNR'.
lw_fieldcatalog-tabname = c_table.
lw_fieldcatalog-col_pos = l_position.
lw_fieldcatalog-seltext_l = text-012. "'Bonus Buy'.
lw_fieldcatalog-outputlen = '12'.
APPEND lw_fieldcatalog TO i_fieldcatalog.
CLEAR lw_fieldcatalog.
l_position = l_position + 1.
lw_fieldcatalog-fieldname = c_fcval25. "'VKORG'.
lw_fieldcatalog-tabname = c_table.
lw_fieldcatalog-col_pos = l_position.
lw_fieldcatalog-seltext_l = text-041. "'Sales Org'.
APPEND lw_fieldcatalog TO i_fieldcatalog.
ENDFORM. " BUILD_FIELD_CATALOG_E
Here is the sample code:
DATA lv_repid LIKE sy-repid.
* Start of Multiple ALV steps
lv_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = lv_repid.
REFRESH: i_fieldcatalog[],i_eve.
CLEAR: w_eve.
w_eve-name = 'TOP_OF_PAGE'.
w_eve-form = 'TOP_OF_PAGE1'.
APPEND w_eve TO i_eve.
PERFORM build_field_catalog_e.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = w_layout
it_fieldcat = i_fieldcatalog[]
i_tabname = 'I_ERROR'
it_events = i_eve
TABLES
t_outtab = i_error[].
REFRESH: i_fieldcatalog[],i_eve.
CLEAR: w_eve.
w_eve-name = 'TOP_OF_PAGE'.
w_eve-form = 'TOP_OF_PAGE2'.
APPEND w_eve TO i_eve.
PERFORM build_field_catalog.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = w_layout
it_fieldcat = i_fieldcatalog[]
i_tabname = 'I_FINAL'
it_events = i_eve
TABLES
t_outtab = i_final[].
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'.
Giving a Pop up for multiple selection after PAI
Example: If user wants to print a form from a standard tcode like Orders or Areements -- and based on the status of document he wants to print the document with or without Units on the form. He doesn't want to edit the Tcode to allow the option, instead he likes to get a pop up showing the options as soon as he selects the Print button.
Inside the smartform processing program: call the below FM to give the Pop Up and take the inputs to program based on that.
*&---------------------------------------------------------------------*
*&
**** Popup inside a program to select -- Begin
*&
*&---------------------------------------------------------------------*
DATA: d_endpos_col TYPE int4 VALUE 25,
d_endpos_row TYPE int4 VALUE 5,
d_startpos_row TYPE int4 VALUE 10,
d_startposcol TYPE int4 VALUE 10,
d_title TYPE char80,
d_choice LIKE sy-tabix.
DATA: BEGIN OF int_valtab OCCURS 0,
data(100),
END OF int_valtab.
DATA: w_valtab LIKE LINE OF int_valtab.
MOVE: 'This is row 1' TO int_valtab-data.
APPEND int_valtab.
CLEAR int_valtab.
MOVE: 'This is row 2' TO int_valtab-data.
APPEND int_valtab.
CLEAR int_valtab.
MOVE: 'Display Table' TO d_title.
CALL FUNCTION 'POPUP_WITH_TABLE_DISPLAY'
EXPORTING
endpos_col = d_endpos_col
endpos_row = d_endpos_row
startpos_col = d_startposcol
startpos_row = d_startpos_row
titletext = d_title
IMPORTING
choise = d_choice
TABLES
valuetab = int_valtab
EXCEPTIONS
break_off = 1
OTHERS = 2.
READ TABLE int_valtab INTO w_valtab INDEX d_choice.
WRITE:/ 'Selection is -- ',
w_valtab.
*&---------------------------------------------------------------------*
*&
**** Popup inside a program to select -- End
*&
*&---------------------------------------------------------------------*
Inside the smartform processing program: call the below FM to give the Pop Up and take the inputs to program based on that.
*&---------------------------------------------------------------------*
*&
**** Popup inside a program to select -- Begin
*&
*&---------------------------------------------------------------------*
DATA: d_endpos_col TYPE int4 VALUE 25,
d_endpos_row TYPE int4 VALUE 5,
d_startpos_row TYPE int4 VALUE 10,
d_startposcol TYPE int4 VALUE 10,
d_title TYPE char80,
d_choice LIKE sy-tabix.
DATA: BEGIN OF int_valtab OCCURS 0,
data(100),
END OF int_valtab.
DATA: w_valtab LIKE LINE OF int_valtab.
MOVE: 'This is row 1' TO int_valtab-data.
APPEND int_valtab.
CLEAR int_valtab.
MOVE: 'This is row 2' TO int_valtab-data.
APPEND int_valtab.
CLEAR int_valtab.
MOVE: 'Display Table' TO d_title.
CALL FUNCTION 'POPUP_WITH_TABLE_DISPLAY'
EXPORTING
endpos_col = d_endpos_col
endpos_row = d_endpos_row
startpos_col = d_startposcol
startpos_row = d_startpos_row
titletext = d_title
IMPORTING
choise = d_choice
TABLES
valuetab = int_valtab
EXCEPTIONS
break_off = 1
OTHERS = 2.
READ TABLE int_valtab INTO w_valtab INDEX d_choice.
WRITE:/ 'Selection is -- ',
w_valtab.
*&---------------------------------------------------------------------*
*&
**** Popup inside a program to select -- End
*&
*&---------------------------------------------------------------------*
Subscribe to:
Posts (Atom)