A sample using function DATE_GET_WEEK
Report try05.
DATA: xweek(6) TYPE n,
xdt TYPE d.
xdt = '20050101'.
CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING
DATE = xdt
IMPORTING
WEEK = xweek
EXCEPTIONS
DATE_INVALID = 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.
WRITE:/ xdt.
WRITE:/ xweek.
FM or any other means by which we can get the DAY for a particular date?
Yes, DATE_COMPUTE_DAY
Sample code:
clear: hold_day_of_week.
CALL FUNCTION 'DATE_COMPUTE_DAY'
EXPORTING
DATE = workdate
IMPORTING
DAY = day_of_week_num
EXCEPTIONS
OTHERS = 8.
CASE day_of_week_num.
WHEN 1.
hold_day_of_week = 'Monday'.
WHEN 2.
hold_day_of_week = 'Tuesday'.
WHEN 3.
hold_day_of_week = 'Wednesday'.
WHEN 4.
hold_day_of_week = 'Thursday'.
WHEN 5.
hold_day_of_week = 'Friday'.
WHEN 6.
hold_day_of_week = 'Saturday'.
WHEN 7.
hold_day_of_week = 'Sunday'.
WHEN OTHERS.
hold_day_of_week = 'invalid'.
ENDCASE.
or
You can use DATE_COMPUTE_DAY to get the day number of the week (for example, today gives 5)
then use WEEKDAY_GET which returns an itab with seven entries (one for each day of the week.)
You enter in this itab and get the field langt to get the day name.
During developing a report I came across this situation:
I've select option in which I want first date of the current month in LOW of select option and Last date of current month in HIGH of select month. Which FUNCTION MODULES are used for this?
There's one way to do this, though it's not a straight idea.
There's a function module 'OIL_LAST_DAY_OF_PREVIOUS_MONTH' that is used to determine the last day of the previous month. from this you can derive the first date of the current month.
Sample:
parameters : date1 like sy-datum.
CALL FUNCTION 'OIL_LAST_DAY_OF_PREVIOUS_MONTH'
EXPORTING
I_DATE_OLD = date1
IMPORTING
E_DATE_NEW = date1
.
data date2 like sy-datum.
date2 = date1 + 1.
write date2.
If you put 27.12.2005 as the input date, date2 you will get as 01.12.2005.
Or else you can use the following code:
v_startdate = sy-datum.
v_startdate+6(2) = '01'.
v_enddate = v_startdate.
if v_enddate+4(2) >= '01' AND v_enddate >= '11'.
v_endate+4(2) = v_enddate+4(2) + 1.
elseif v_enddate = '12'.
v_enddate+4(2) = '01'.
v_enddate+(4) = v_enddate+(4) + 1.
endif.
v_enddate = v_enddate - 1.
Instead of checking your Purchase Order History one at a time, you can now mass display or print them with this customized abap report.
*
* Mass display or print Purchase Order History
*
* You can request report by :
* 1. Change date
* 2. User Name
* 3. Purchase Order Number
* 4. Vendor Code
*
* Written by : SAP Basis, ABAP Programming and Other IMG Stuff
*
REPORT ZPOCHANGE LINE-SIZE 132 NO STANDARD PAGE HEADING
LINE-COUNT 065(001)
MESSAGE-ID VR.
TABLES: DD04T,
CDHDR,
CDPOS,
DD03L,
DD41V,
T685T,
VBPA,
TPART,
KONVC,
EKKO.
SELECT-OPTIONS: XUDATE FOR CDHDR-UDATE,
XNAME FOR CDHDR-USERNAME,
XEBELN FOR EKKO-EBELN,
XLIFNR FOR EKKO-LIFNR.
SELECTION-SCREEN SKIP.
* TEXT-001 - Sorting Sequence
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
PARAMETERS: SUDATE RADIOBUTTON GROUP R1,
SNAME RADIOBUTTON GROUP R1,
SOBID RADIOBUTTON GROUP R1.
SELECTION-SCREEN END OF BLOCK BLK1.
DATA: WFLAG,
WCHANGENR LIKE CDHDR-CHANGENR.
DATA: INDTEXT(60) TYPE C.
DATA: BEGIN OF ICDHDR OCCURS 50.
INCLUDE STRUCTURE CDHDR.
DATA: END OF ICDHDR.
DATA: BEGIN OF ICDSHW OCCURS 50.
INCLUDE STRUCTURE CDSHW.
DATA: END OF ICDSHW.
DATA: BEGIN OF EKKEY,
EBELN LIKE EKET-EBELN,
EBELP LIKE EKET-EBELP,
ETENR LIKE EKET-ETENR,
END OF EKKEY.
DATA: BEGIN OF ITAB OCCURS 50,
BEGIN OF EKKEY,
EBELN LIKE EKET-EBELN,
EBELP LIKE EKET-EBELP,
ETENR LIKE EKET-ETENR,
END OF EKKEY,
CHANGENR LIKE CDHDR-CHANGENR,
UDATE LIKE CDHDR-UDATE,
UTIME LIKE CDHDR-UTIME,
USERNAME LIKE CDHDR-USERNAME,
CHNGIND LIKE CDSHW-CHNGIND,
FTEXT LIKE CDSHW-FTEXT,
OUTLEN LIKE CDSHW-OUTLEN,
F_OLD LIKE CDSHW-F_OLD,
F_NEW LIKE CDSHW-F_NEW,
END OF ITAB.
DATA: OLD_OBJECTID LIKE CDHDR-OBJECTID.
FIELD-SYMBOLS:
, .
SELECT * FROM EKKO WHERE EBELN IN XEBELN AND
LIFNR IN XLIFNR.
CLEAR CDHDR.
CLEAR CDPOS.
CDHDR-OBJECTCLAS = 'EINKBELEG'.
CDHDR-OBJECTID = EKKO-EBELN.
PERFORM GETCHGDOCS.
ENDSELECT.
IF SUDATE = 'X'.
SORT ITAB BY UDATE EKKEY-EBELN CHANGENR EKKEY-EBELP
EKKEY-ETENR.
ELSEIF SNAME = 'X'.
SORT ITAB BY USERNAME EKKEY-EBELN CHANGENR EKKEY-EBELP
EKKEY-ETENR.
ELSE.
SORT ITAB BY EKKEY-EBELN CHANGENR EKKEY-EBELP EKKEY-ETENR.
ENDIF.
LOOP AT ITAB.
CLEAR: INDTEXT, EKKEY.
CASE ITAB-CHNGIND.
WHEN 'U'.
INDTEXT(50) = ITAB-FTEXT.
INDTEXT+51 = TEXT-020.
CONDENSE INDTEXT.
WHEN 'D'.
INDTEXT = TEXT-021.
WHEN 'E'.
INDTEXT(5) = ITAB-FTEXT.
INDTEXT+51 = TEXT-021.
CONDENSE INDTEXT.
WHEN 'I'.
INDTEXT = TEXT-022.
ENDCASE.
RESERVE 4 LINES.
IF WCHANGENR NE ITAB-CHANGENR.
WCHANGENR = ITAB-CHANGENR.
EKKEY = ITAB-EKKEY.
WRITE:/ ITAB-UDATE UNDER 'Change Date',
ITAB-UTIME UNDER 'Time',
ITAB-USERNAME UNDER 'User Name',
ITAB-EKKEY-EBELN UNDER 'PO No',
ITAB-EKKEY-EBELP UNDER 'Item',
ITAB-EKKEY-ETENR UNDER 'Sch No',
INDTEXT UNDER 'Changes'.
ELSEIF ITAB-EKKEY NE EKKEY.
WRITE:/ ITAB-EKKEY-EBELP UNDER 'Item',
ITAB-EKKEY-ETENR UNDER 'Sch No',
INDTEXT UNDER 'Changes'.
ENDIF.
CASE ITAB-CHNGIND.
WHEN 'U'.
ASSIGN ITAB-F_OLD(ITAB-OUTLEN) TO .
ASSIGN ITAB-F_NEW(ITAB-OUTLEN) TO .
WRITE: / TEXT-023 UNDER 'Changes',
.
WRITE: / TEXT-024 UNDER 'Changes',
.
WHEN 'E'.
ASSIGN ITAB-F_OLD(ITAB-OUTLEN) TO .
WRITE: TEXT-023 UNDER 'Changes',
.
ENDCASE.
SKIP.
ENDLOOP.
TOP-OF-PAGE.
WRITE:/ SY-DATUM,SY-UZEIT,
50 'P U R C H A S E O R D E R H I S T O R Y',
120 'Page', SY-PAGNO.
WRITE: / SY-REPID,
60 'Purchase Orders Changes'.
SKIP.
ULINE.
IF SUDATE = 'X'.
WRITE:/001 'Change Date',
014 'Time',
024 'User Name',
038 'PO No',
050 'Item',
057 'Sch No',
065 'Changes'.
ELSEIF SOBID = 'X'.
WRITE:/001 'PO No',
013 'Item',
020 'Sch No',
028 'Change Date',
041 'Time',
051 'User Name',
065 'Changes'.
ELSE.
WRITE:/001 'User Name',
015 'Change Date',
028 'Time',
038 'PO No',
050 'Item',
057 'Sch No',
065 'Changes'.
ENDIF.
ULINE.
FORM GETCHGDOCS.
CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'
EXPORTING
DATE_OF_CHANGE = CDHDR-UDATE
OBJECTCLASS = CDHDR-OBJECTCLAS
OBJECTID = CDHDR-OBJECTID
TIME_OF_CHANGE = CDHDR-UTIME
USERNAME = CDHDR-USERNAME
TABLES
I_CDHDR = ICDHDR
EXCEPTIONS
NO_POSITION_FOUND = 1
OTHERS = 2.
CHECK SY-SUBRC EQ 0.
DELETE ICDHDR WHERE CHANGE_IND EQ 'I'.
CHECK NOT ICDHDR[] IS INITIAL.
LOOP AT ICDHDR.
CHECK ICDHDR-UDATE IN XUDATE.
CHECK ICDHDR-USERNAME IN XNAME.
CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'
EXPORTING CHANGENUMBER = ICDHDR-CHANGENR
IMPORTING HEADER = CDHDR
TABLES EDITPOS = ICDSHW
EXCEPTIONS NO_POSITION_FOUND = 1
OTHERS = 2.
CHECK SY-SUBRC EQ 0.
LOOP AT ICDSHW.
CHECK ICDSHW-TEXT_CASE EQ SPACE.
MOVE-CORRESPONDING ICDSHW TO ITAB.
MOVE-CORRESPONDING ICDHDR TO ITAB.
MOVE ICDSHW-TABKEY+3 TO ITAB-EKKEY.
APPEND ITAB.
ENDLOOP.
ENDLOOP.
ENDFORM.
*
* END OF PROGRAM
4.6x
REPORT ZMMCHGHISTORY NO STANDARD PAGE HEADING
LINE-SIZE 195 LINE-COUNT 60.
* Change doc listing
* Grouped into 3 chg types: 1. Part revision 2. Price change 3. Others
TABLES:
CDHDR, CDPOS, MARA, MAKT, MARD.
FIELD-GROUPS: HEADER.
DATA: BEGIN OF CHGDOC OCCURS 50.
INCLUDE STRUCTURE CDRED.
DATA: END OF CHGDOC.
DATA:
CHGTYPE(1),
PLANT(4),
MATNR1 LIKE CHGDOC-OBJECTID.
SELECT-OPTIONS:
XMATNR FOR CDHDR-OBJECTID, "Material
XUDATE FOR CDHDR-UDATE, "Change Date
XUNAME FOR CDHDR-USERNAME, "User Name
XTCODE FOR CDHDR-TCODE, "Transaction Code
XWERKS FOR MARD-WERKS. "Plants
SELECTION-SCREEN SKIP.
*Filter change type
SELECTION-SCREEN BEGIN OF BLOCK CHG0 WITH FRAME TITLE TEXT-001.
PARAMETERS : XCHG1 AS CHECKBOX DEFAULT 'X',
XCHG2 AS CHECKBOX DEFAULT 'X',
XCHG3 AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK CHG0.
START-OF-SELECTION.
INSERT:
CHGDOC-OBJECTID "Material
CHGTYPE "Change type
PLANT
CHGDOC-CHANGENR
CHGDOC-USERNAME
CHGDOC-UDATE
CHGDOC-TCODE
CHGDOC-TABNAME
CHGDOC-TABKEY
CHGDOC-CHNGIND
CHGDOC-FNAME
CHGDOC-FTEXT
CHGDOC-TEXTART
CHGDOC-OUTLEN
CHGDOC-F_OLD
CHGDOC-F_NEW
INTO HEADER.
SELECT * FROM MARA WHERE MATNR IN XMATNR.
MATNR1 = MARA-MATNR.
CALL FUNCTION 'CHANGEDOCUMENT_READ'
EXPORTING
* ARCHIVE_HANDLE = 0
* CHANGENUMBER = ' '
* DATE_OF_CHANGE = '00000000'
OBJECTCLASS = 'MATERIAL'
OBJECTID = MATNR1
* TABLEKEY = ' '
* TABLENAME = ' '
* TIME_OF_CHANGE = '000000'
* USERNAME = ' '
* LOCAL_TIME = ' '
TABLES
EDITPOS = CHGDOC
EXCEPTIONS
NO_POSITION_FOUND = 1
WRONG_ACCESS_TO_ARCHIVE = 2
TIME_ZONE_CONVERSION_ERROR = 3
OTHERS = 4.
LOOP AT CHGDOC.
CHECK: CHGDOC-UDATE IN XUDATE,
CHGDOC-USERNAME IN XUNAME,
CHGDOC-TCODE IN XTCODE.
* Chg type: 1. Part revision, 2. Price change, 3. Others
CASE CHGDOC-TCODE.
WHEN 'MM01' OR 'MM02' OR 'MM03'. CHGTYPE = '1'.
WHEN 'MR21'. CHGTYPE = '2'.
WHEN OTHERS. CHGTYPE = '3'.
ENDCASE.
* Filter chg type
IF ( CHGTYPE = '1' AND XCHG1 <> 'X' ) OR
( CHGTYPE = '2' AND XCHG2 <> 'X' ) OR
( CHGTYPE = '3' AND XCHG3 <> 'X' ).
CONTINUE.
ENDIF.
* Plant is a substring of tabkey
PLANT = CHGDOC-TABKEY+21(4).
IF NOT ( XWERKS IS INITIAL ) AND NOT ( PLANT IS INITIAL ).
CHECK PLANT IN XWERKS.
ENDIF.
EXTRACT HEADER.
ENDLOOP.
ENDSELECT.
END-OF-SELECTION.
SORT.
LOOP.
* Material
AT NEW CHGDOC-OBJECTID.
SELECT SINGLE * FROM MAKT WHERE MATNR = CHGDOC-OBJECTID.
FORMAT INTENSIFIED ON.
SKIP. SKIP.
WRITE:/' *** Material:', (18) CHGDOC-OBJECTID, MAKT-MAKTX.
ENDAT.
* Change type
AT NEW CHGTYPE.
FORMAT INTENSIFIED ON.
SKIP.
CASE CHGTYPE.
WHEN '1'. WRITE:/ ' ** Change type: PARTS REVISION'.
WHEN '2'. WRITE:/ ' ** Change type: PRICE CHANGE'.
WHEN '3'. WRITE:/ ' ** Change type: OTHERS'.
ENDCASE.
SKIP.
ENDAT.
SHIFT CHGDOC-F_OLD LEFT DELETING LEADING SPACE.
SHIFT CHGDOC-F_NEW LEFT DELETING LEADING SPACE.
FORMAT INTENSIFIED OFF.
WRITE:
/ PLANT UNDER 'Plant',
(50) CHGDOC-FTEXT UNDER 'Field',
(45) CHGDOC-F_OLD UNDER 'Old value',
(45) CHGDOC-F_NEW UNDER 'New value'.
AT NEW CHGDOC-CHANGENR.
FORMAT INTENSIFIED OFF.
WRITE:
CHGDOC-CHANGENR UNDER 'Change doc',
CHGDOC-TCODE UNDER 'Tcod',
CHGDOC-USERNAME UNDER 'User name ',
CHGDOC-UDATE UNDER 'Date ' DD/MM/YY.
ENDAT.
AT END OF CHGDOC-OBJECTID.
SKIP.
ULINE.
SKIP.
ENDAT.
ENDLOOP.
TOP-OF-PAGE.
WRITE: / SY-DATUM, SY-UZEIT,
50 'ABC PTE LTD',
100 'page', SY-PAGNO,
/ SY-REPID,
48 'Change Documents Report',
100 SY-UNAME.
SKIP.
ULINE.
WRITE:/3
'Change doc',
'Tcod',
'User name ',
'Date ',
'Plant',
(50) 'Field',
(45) 'Old value',
(45) 'New value'.
ULINE.
*** End of Program