Friday, September 24, 2010

Random number creation

use one of the function modules

SYSTEM_GET_UNIQUE_ID
SDOK_UNIQUE_ID_GET
STREE_GET_UNIQUE_ID
QF05_RANDOM_INTEGER
SYSTEM_UUID_C_CREATE
NUMBER_GET_NEXT Creat a number Range object using transction SNRO.

Download code to the desktop with screens

run REPTRAN in se38.this will download the data to the desktop

Function Modules for date conversions

FM LIST WITH RESPECT TO DAY, WEEK, AND MONTH.

CALCULATE_DATE : Calculates the future date based on the input .

DATE_TO_DAY : Returns the Day for the entered date.

DATE_COMPUTE_DAY : Returns weekday for a date

DATE_GET_WEEK : Returns week for a date

RP_CALC_DATE_IN_INTERVAL : Add days / months to a date

MONTHS_BETWEEN_TWO_DATES : To get the number of months between the two dates.

END_OF_MONTH_DETERMINE_2 : Determines the End of a Month.

HR_HK_DIFF_BT_2_DATES : Find the difference between two dates in years, months and days.

FIMA_DAYS_AND_MONTHS_AND_YEARS : Find the difference between two dates in years, months and days.

MONTH_NAMES_GET : Get the names of the month

WEEK_GET_FIRST_DAY : Get the first day of the week

HRGPBS_HESA_DATE_FORMAT : Format the date in dd/mm/yyyy format

SD_CALC_DURATION_FROM_DATETIME : Find the difference between two date/time and report the difference in hours

L_MC_TIME_DIFFERENCE : Find the time difference between two date/time

HR_99S_INTERVAL_BETWEEN_DATES : Difference between two dates in days, weeks, months

LAST_DAY_OF_MONTHS : Returns the last day of the month

DATE_CHECK_PLAUSIBILITY :Check for the invalid date.

Check box in alv program

REPORT ZTEST .

type-pools: slis.

*Table declaration
tables: vbak,vbap.

*internal table
data: begin of i_sales occurs 0,
vbeln like vbak-vbeln,
erdat like vbak-erdat,
audat like vbak-audat,
kunnr like vbak-kunnr,
vkorg like vbak-vkorg,
matnr like vbap-matnr,
netpr like vbap-netpr,
check type c, "checkbox
end of i_sales.

data: begin of i_final occurs 0,
vbeln like vbak-vbeln,
erdat like vbak-erdat,
audat like vbak-audat,
kunnr like vbak-kunnr,
vkorg like vbak-vkorg,
matnr like vbap-matnr,
netpr like vbap-netpr,
end of i_final.

data: v_fieldcat type slis_fieldcat_alv,
gt_fieldcat type slis_t_fieldcat_alv,
gt_layout type slis_layout_alv,
gt_sort type slis_sortinfo_alv,
fieldcat like line of gt_fieldcat.

*Selection screen
parameters: p_vkorg like vbak-vkorg.
select-options: s_vbeln for vbak-vbeln.

*start of selection.
start-of-selection.
perform get_data.
perform fill_fieldcatalog.
perform write_data.
*-----------------------------------------------------------------
* get data
*-----------------------------------------------------------------
FORM get_data .
select a~vbeln
a~erdat
a~audat
a~kunnr
a~vkorg
b~matnr
b~netpr
into corresponding fields of table i_sales
from vbak as a inner join vbap as b on a~vbeln = b~vbeln
where a~vkorg = p_vkorg
and a~vbeln in s_vbeln.

ENDFORM. " get_data
*-----------------------------------------------------------------
* write_data
*-----------------------------------------------------------------
FORM write_data .
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
I_CALLBACK_PF_STATUS_SET = 'GUI_SET'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IS_LAYOUT = gt_layout
IT_FIELDCAT = gt_fieldcat
TABLES
T_OUTTAB = i_sales .

ENDFORM. " write_data
*-----------------------------------------------------------------
* fill catalog
*-----------------------------------------------------------------
FORM fill_fieldcatalog .

sort i_sales by vbeln.
clear v_fieldcat.
*for check box

v_fieldcat-col_pos = 1.
v_fieldcat-fieldname = 'CHECK'.
v_fieldcat-seltext_m = 'chek'.
v_fieldcat-checkbox = 'X'.
v_fieldcat-input = 'X'.
v_fieldcat-edit = 'X'.
append v_fieldcat to gt_fieldcat.

clear v_fieldcat.
v_fieldcat-col_pos = 2.
v_fieldcat-fieldname = 'VBELN'.
v_fieldcat-seltext_m = 'Sales Document'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.

v_fieldcat-col_pos = 3.
v_fieldcat-fieldname = 'ERDAT'.
v_fieldcat-seltext_m = 'Creation Date'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.

v_fieldcat-col_pos = 4.
v_fieldcat-fieldname = 'AUDAT'.
v_fieldcat-seltext_m = 'Document Date'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.

v_fieldcat-col_pos = 5.
v_fieldcat-fieldname = 'KUNNR'.
v_fieldcat-seltext_m = 'Customer'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.

v_fieldcat-col_pos = 6.
v_fieldcat-fieldname = 'VKORG'.
v_fieldcat-seltext_m = 'Sales Organization'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.

v_fieldcat-col_pos = 7.
v_fieldcat-fieldname = 'MATNR'.
v_fieldcat-seltext_m = 'Material'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.

v_fieldcat-col_pos = 8.
v_fieldcat-fieldname = 'NETPR'.
v_fieldcat-seltext_m = 'Net Value'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.

endform.

*&---------------------------------------------------------------------*
*& Form GUI_SET
*&---------------------------------------------------------------------*
FORM GUI_SET USING RT_EXTAB TYPE SLIS_T_EXTAB .


SET PF-STATUS 'GETDATA' .

ENDFORM. "GUI_SET
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*

FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
R_SELFIELD TYPE SLIS_SELFIELD.


CASE R_UCOMM.
WHEN 'DATA'.
CLEAR I_FINAL.
CLEAR I_SALES.
REFRESH I_FINAL.

LOOP AT i_sales .
if i_sales-check = 'X'.
i_final-vbeln = i_sales-vbeln.
i_final-erdat = i_sales-erdat.
i_final-audat = i_sales-audat.
i_final-kunnr = i_sales-kunnr.
i_final-vkorg = i_sales-vkorg.
i_final-matnr = i_sales-matnr.
i_final-netpr = i_sales-netpr.

IF NOT I_FINAL-VBELN IS INITIAL.
append i_final .
ENDIF.

endif.
ENDLOOP.
PERFORM final_display.

endcase.

ENDFORM. "USER_COMMAND
*&---------------------------------------------------------------------*
*& Form final_display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form final_display .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
IS_LAYOUT = gt_LAYOUT
IT_FIELDCAT = gt_fieldcat

TABLES
t_outtab = i_final .

endform. " final_display

Password program

REPORT zpassword.


SELECTION-SCREEN BEGIN OF SCREEN 500 AS WINDOW TITLE title.

Parameters: p_name like sy-uname,
p_pas like sy-uname lower case.
SELECTION-SCREEN skip 1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(70) text-001.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF SCREEN 500.

title = 'HAI VENKAT LOGIN PLEASE'.

CALL SELECTION-SCREEN '0500' STARTING AT 10 10 ending at 70 14.


data: begin of it_user occurs 0,
name like sy-uname,
password like sy-uname,
end of it_user.

it_user-name = 'venkat'.
it_user-password = 'venkat'.
append it_user.

it_user-name = 'srinivas'.
it_user-password = 'srinivas'.
append it_user.

it_user-name = 'preethi'.
it_user-password = 'preethi'.
append it_user.

it_user-name = 'vidya'.
it_user-password = 'vidya'.
append it_user.


AT SELECTION-SCREEN OUTPUT.
loop at screen.
check screen-name eq 'P_PAS'.
move: 1 to screen-invisible.
modify screen.
endloop.

start-of-selection.

if p_pas = 'venkat'.
write:/ 'venkat this is working'.
endif.

Selection screen with radio buttons

report ztest .

TABLES: vbak, ltak.
DATA:
err_sw.
PARAMETERS: rb1 RADIOBUTTON GROUP rb1 USER-COMMAND sel DEFAULT 'X'.
PARAMETERS: rb2 RADIOBUTTON GROUP rb1.

SELECTION-SCREEN: SKIP 1.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
SELECT-OPTIONS: s_auart FOR vbak-auart DEFAULT 'ZRE'
NO INTERVALS MODIF ID rb1.
SELECT-OPTIONS: s_date FOR vbak-erdat MODIF ID rb1.
SELECTION-SCREEN: END OF BLOCK b1.

SELECTION-SCREEN: BEGIN OF BLOCK b2 WITH FRAME TITLE text-t02.
SELECT-OPTIONS: s_tanum FOR ltak-tanum MODIF ID rb2.
SELECT-OPTIONS: s_bdatu FOR ltak-bdatu MODIF ID rb2.
SELECTION-SCREEN: END OF BLOCK b2.

AT SELECTION-SCREEN OUTPUT.
IF rb1 = 'X'.
PERFORM hide_rb2_options.
ELSE.
PERFORM hide_rb1_options.
ENDIF.

INITIALIZATION.

START-OF-SELECTION.
CLEAR err_sw.
IF rb1 = 'X'.
IF s_auart IS INITIAL
OR s_date IS INITIAL.
MESSAGE i208(00) WITH 'Required field not entered'.
err_sw = 'X'.
ENDIF.
ELSE.
IF s_tanum IS INITIAL
OR s_bdatu IS INITIAL.
MESSAGE i208(00) WITH 'Required field not entered'.
err_sw = 'X'.
ENDIF.
ENDIF.

CHECK err_sw NE 'X'.

WRITE:/ 'Hi!'.

*&---------------------------------------------------------------------*
*& Form hide_rb2_options
*&---------------------------------------------------------------------*
FORM hide_rb2_options.
LOOP AT SCREEN.
CASE screen-group1.
WHEN 'RB1'.
screen-active = 1.
MODIFY SCREEN.
WHEN 'RB2'.
screen-active = 0.
MODIFY SCREEN.
ENDCASE.
ENDLOOP.
ENDFORM. " hide_rb2_options
*&---------------------------------------------------------------------*
*& Form hide_rb1_options
*&---------------------------------------------------------------------*
FORM hide_rb1_options.
LOOP AT SCREEN.
CASE screen-group1.
WHEN 'RB2'.
screen-active = 1.
MODIFY SCREEN.
WHEN 'RB1'.
screen-active = 0.
MODIFY SCREEN.
ENDCASE.
ENDLOOP.

ENDFORM. " hide_rb1_options

Input only through the f4 help

report ztest .


PARAMETERS:p_matnr(18) TYPE c MODIF ID mid.

DATA:BEGIN OF itab OCCURS 0,
matnr TYPE matnr,
END OF itab.

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN .
IF screen-group1 EQ 'MID'.
screen-input = '0'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_matnr.

LOOP AT SCREEN .
IF screen-group1 EQ 'MID'.
screen-input = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.

IF itab IS INITIAL.

itab-matnr = 'ABC123456788'.
APPEND itab.

itab-matnr = 'BCS123456788'.
APPEND itab.

itab-matnr = 'DFC123456788'.
APPEND itab.

itab-matnr = 'ASW123456788'.
APPEND itab.

ENDIF.


CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'MATNR'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'P_MATNR'
value_org = 'S'
TABLES
value_tab = itab.

LOOP AT SCREEN .
IF screen-group1 EQ 'MID'.
screen-input = '0'.
MODIFY SCREEN.
ENDIF.
endloop.