FM to convert Date Entered to a standard format
Hello All,
Is there any FM to convert the date entered (in the format given in SU01) to a standard format
(Eg: DD.MM.YYYY). Is there any FM that does the reverse of it.
Please help us out with your suggesstions.
Thanks,
Seetharaman V
Hi seetharaman,
please refer the following link for using the conversion exit for date in BSP application.
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/72d7ac11-0501-0010-63a2-cc6960569926
hpe this ll help.
thnks.
Similar Messages
-
How to convert date into dd mon yyyy format
hi all,
i have a problem in date format i am using date like below .
<%java.util.Date date = new java.util.Date();%>
i am inserting date into a table and its storing like this
insert into tablename (d_date) values (date)
and its inserting date like below
Sun Oct 19 09:05:45 GMT+03:00 2003
i want to fetch date in dd mon yyyy format.
with this format i want to make a select query.i struck with the format conversion.
how to do this.
any comments please.
any helphi all,
i understand now where i am wrong.
the below code is not working why because in my server where i am executing code the regional setting month value is in arabic.
i executed the same code in a different server where date and time jones are english its working fine.
All the problem is in regional setting and not the jsp code.
<%
String whtEverDateFormatYouWAnt = "dd MMM yy";
String str = new SimpleDateFormat(whtEverDateFormatYouWAnt).format(new SimpleDateFormat("EEE MMM dd HH:mm:ss vvv yyyy").parse("Sun Oct 19 09:05:45 GMT+03:00 2003"));
out.print(str);
%>
Thanks a lot for the excellent solution.
Thanks again. -
Converting dat/timestamp field into desired format
Hi all
How do I convert sysdate or current_timestamp to the following format?
August 26, 2002 11:44:00 AM PDT
I am struggling mainly with the timezone portion (PDT) etc.
Would appreciate any help - Thanx!:)
Regards
Menon:)You won't be able to add the timezone to the date format itself. You'll rather have to tack on the literal string to the end of the date string.
select to_char(sysdate,'fmMonth dd, yyyy hh:mi:ss AM')||' PDT' from dual;
Armand -
Convert date in BST to GMT format
Here date and cal.getTime() return date in BST format. But my requirement is date should be converted to GMT format and then compared with cal.getTime() which is in BST format.
Object o = timeStamp.get(TIMESTAMP_OBJECT);
java.util.Date date = (java.util.Date) o;
Calendar cal = Calendar.getInstance();
getBDO().setLastDespatch(isLastDespatch(cal.getTime(), date));
public static boolean isLastDespatch(Date counterDate, Date lastDespatchDate)
if (counterDate.before(lastDespatchDate))
// last despatch timestamp before
return false;
else
// last despatch timestamp expired, therefore tell clerk
return true;
}I tried
Object g = date.toGMTString();
But I am not able to convert this object to again Date...NewComer_forum wrote:
I tried with below code but throwing exceptions
String g = date.toGMTString();
SimpleDateFormat date1 = new SimpleDateFormat(g);
You of course read the Javadoc, and so know that the argument to the constructor SimpleDateFormat(String) is the pattern by which you want to parse, and not the string you want to parse itself, right? I mean, you didn't just try one random thing to prove that you gave it a minimal effort before coming back here for more handholding, correct?
Do me a favour and try my suggestion before continuing. I don't know for sure that it will work, but I think it's likely. -
Convert Date in dd-MM-yy format
I am taking parameter as date in front end and I am comparing it with database through view object through executeParams. But both the date formats are different, that's why I can't compare both formats. Please suggest me to compare both formats in dd-MM-yy format. I am taking parameter by inputDate component.
Hi,
Use this code inside your where clause
apply_date=to_date('"+getdate()+"','rrrr-mm-dd')in the 'apply_date' write your table column name which you want to compare.
getDate() is date type 'value binding' of InputDate component.
RAFAT -
SQL LOADER Problem when data is loaded but not come in standard formate
Hi guys,
I got problem when sql loader run data loaded successfully in table but UOM data not come in standard formate.
UOM table column contains the Unit of measure data but in my excel sheet it's look like :
EXCEl SHEET DATA:
1541GAFB07080 0 Metres
1541GAFE10040 109.6 Metres
1541GAFE10050 594.2 Metres
1541GAFE10070 126.26 Metres
1541GAFE14040 6.12 Metres
1541GAFE14050 0 Metres
1541SAFA05210 0 Metres
1541SAFA07100 0 Metres
1551EKDA05210 0 Nos
1551EKDA07100 0 Nos
1551EKDA07120 0 Nos
1551EKDA07140 0 Nos
1551EKDA07200 0 Nos.
1551EKDA08160 0 Nos.
1551EKDA08180 0 Nos.
1551EKDA08200 0 Nos.
1551EKDA10080 41 Nos.
1551EKDA10140 85 Nos.
.ctl file :
OPTIONS (silent=(header,feedback,discards))
LOAD DATA
INFILE *
APPEND
INTO TABLE XXPL_PO_REQUISITION_STG
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY'"'
TRAILING NULLCOLS
( ITEM_CODE CHAR,
ITEM_DESCRIPTION CHAR "TRIM(:ITEM_DESCRIPTION)",
QUANTITY,
UOM,
NEED_BY_DATE,
PROJECT,
TASK_NAME,
BUYER,
REQ_TYPE,
STATUS,
ORGANIZATION_CODE,
LOCATION,
SUBINVENTORY,
LINE_NO,
REQ_NUMBER,
LOADED_FLAG CONSTANT 'N',
SERIAL_NO "XXPL_PRREQ_SEQ.NEXTVAL",
CREATED_BY,
CREATION_DATE SYSDATE,
LAST_UPDATED_BY,
LAST_UPDATED_DATE,
LAST_UPDATED_LOGIN
Some output came in table like:
W541WDCA05260 0 Metres|
W541WDCA05290 3 Metres|
W541WDCA05264 4 Metres|
W541WDCA05280 8 Metres|
1551EADA04240 0 Nos|
1551EADA07100 0 Nos|
1551EKDA10080 0 Nos.|
1551EKDA10080 41 Nos.|
proble in | delimiter...how to remove it ' | ' from my table when sqlloader program runnig ...... where i can change in .ctl file or excel file....it's urgent guys olz help me ..
thanksHi,
How are you extracting the data to Excel sheet ?
Please check the format type of the column in Excel sheet for UOM.
There is no issue in the SQL loader control file, but issue is there in your source excel file. (Try using a different method to extract the data to Excel sheet.)
Regards,
Yuvaraj.C -
Converting string to date in mm/dd/yyyy format
Hi,
I used simpledateformat to convert date to "MM/dd/yyyy" format.
Now when i want to insert into db, i want the value as date object instead of string [returned by format method of SimpleDateFormat]
what should i do?
Date dt = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
System.out.println("Formatted date is coming as "+sdf.format(dt));
Date dt1 = sdf.parse(sdf.format(dt);
System.out.println("parsed date is coming as " +dt1);
output :
1 SOP returns 11/07/2007 [current date]
2 SOP returns Wed Nov 07 00:00:00 GMT+05:30 2007If you are using PreparedStatements setDate method, you need a java.sql.Date object, not a Java.util.Date object. You can create an sql.Date object from a util.Date object as follows:
java.sql.Date sqlDate = new java.sql.Date(dt.getTime());And, if you are not using PreparedStatement and its setDate method, then change now.
Doing
Date dt1 = sdf.parse(sdf.format(dt));is meaningless. You format the date to string, then parse the string back to a date? Why? Why not just use the original Date object? And you won't get a sql.Date object that way, either, as the DateFormat classes return a util.Date object.
Edit: And for more info:
A Date does not have a format. It is simply a number. The "format" only comes into play when printing the String representation of the Date, and that is not handled by the Date object itself (except when calling toString either explicitly or implicitly). -
How to convert date format to MM/DD/YYYY
Hi,
How to convert date format to MM/DD/YYYY.
Thanks,
Senthilhi,
tri with this function module
data :l_date(10) type c
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
DATE_INTERNAL = SY-DATUM
IMPORTING
DATE_EXTERNAL = l_date.
this function module converts date from 20050601 to external format which is specified in user profile
cheers,
sasi -
Convert date from YYYYMMDD to DDMMYYYY
Please help if anyone knows any function module to convert date from YYYYMMDD to DDMMYYYY format..
Thanks in Advance,
manjariHello.
Simply do like this:
DATA: datum TYPE char10.
WRITE sy-datum TO datum <format option>.
<format options>:
DD/MM/YY and MM/DD/YY:
Both additions have the same effect. The date output has a two-digit year value and a separator. The separator and the order are taken from the definition for date output in the user master record.
DD/MM/YYYY und MM/DD/YYYY:
Both additions have the same effect. The date output has a four-digit year value and separator. The separator and the order are taken from the definition for date output in the user master record.
DDMMYY und MMDDYY:
Both additions have the same effect. The date output has a two-digit year value and no separator. The order is taken from the definition for date output in the user master record.
YYMMDD:
This addition provides a date output with a two-digit year value without a separator in the format YYMMDD.
Regards.
Valter Oliveira. -
Standard Inport Package is getting failed at Convert Data Task
Hi All,
When running standard import package on any application, it's getting failed at Convert Data Task.
Do any body faced similar kind of issue, please let me know what might be the cause or any solution to the above issue would be appreciated.
Regards,
Sreekanth.Hi,
The format of dimension members in the external file is different from the BPC internal format. Check your conversion file. The problem is with your conversion file.
For example:
In the external file Time dimension values is given as Jan, Feb, Mar etc..
In BPC asume you are maintaining time dimension members as 2008.Jan, 2008.Feb etc.
Then you should define this in conversion file. Jan should be replaced by 2008.Jan when it enter BPC application. Also, the values you define in the Internal format should be maintained as master data (dimension members).
regards,
Lokesh Nandula -
How to convert date format into sap standard format?
Hi All,
In SAPUI5 screen i have one simple form in form i have date field which is format (MM/DD/YYYY). but i am getting POST error while inserting the data in to sap table.
I want convert date format in sap format (YYYY/MM/DD).
One more issue, when i am fetching the data from sap table,but the date display with time and time zone.
eg. Sat Aug 02 2014 05:30:00 GMT+0530 (India Standard Time)
I want to display only date.
Thanks,
Prashant.Now i am using <DatePicker id="Emp_fsdate" displayFormat="yyyy-MM-dd"/>
I checked in console, but date is display like mm/dd/yy
In my controller.js file i have written code
OData.request
requestUri: "http:sap/opu/odata/sap/ZSERVICE_FINAL_SRV/es_sodata",
method: "GET",
headers:
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/atom+xml",
"DataServiceVersion": "2.0",
"X-CSRF-Token":"Fetch"
function (data, response){
var header_xcsrf_token = response.headers['x-csrf-token'];
OData.request
requestUri:
"http://sap/opu/odata/sap/ZSERVICE_FINAL_SRV/es_sodata",
method: "POST",
headers:
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/atom+xml",
"DataServiceVersion": "2.0",
"Accept": "application/atom+xml,application/atomsvc+xml,application/xml",
"X-CSRF-Token": header_xcsrf_token
data:
Empid:Emp_id,
Empname:Emp_name,
Start_Date:Emp_sdate,
// End_Date:Emp_edate,
Status:Emp_status,
City:Emp_city,
Location:Emp_location,
and in my CREATE_ENTITY method
method ES_SODATA_CREATE_ENTITY.
DATA: ls_request_input_data TYPE zcl_zservice_final_mpc=>ts_et_sodata,
ls_userinfo TYPE zsodata.
DATA ls_temp TYPE sy-datum.
* Read Request Data
io_data_provider->read_entry_data( IMPORTING es_data = ls_request_input_data ).
* Fill workarea to be inserted
ls_userinfo-Empid = ls_request_input_data-Empid.
ls_userinfo-Empname = ls_request_input_data-Empname.
ls_userinfo-Start_Date = ls_request_input_data-Start_Date.
ls_userinfo-End_Date = ls_request_input_data-End_Date.
ls_userinfo-Status = ls_request_input_data-Status.
ls_userinfo-City = ls_request_input_data-City.
ls_userinfo-Location = ls_request_input_data-Location.
* Insert Data in table ZUSERINFO
INSERT zsodata FROM ls_userinfo.
IF sy-subrc = 0.
er_entity = ls_request_input_data. "Fill Exporting parameter ER_ENTITY
ENDIF.
endmethod.
But still i am getting an error
POST http://sap/opu/odata/sap/ZSERVICE_FINAL_SRV/es_sodata 500 (Internal Server Error)
I am able to insert all field except date field. How to insert date field in sap table. -
Converting any date string to GMT standard
Hi All,
I want to convert any date string to GMT standard.
The date string may be like this.
"Sat Sep 15 14:23:40 IST 2001"
I have tried to change my defaultTimeZone .
But I don't know why it's not working.
Is there something to do with Locals?
Can anyone please tell me the way to
accomplish that ?
Thanks in advance.
SujoyJava stores all the dates in GMT Format , considering the machines TimeZone Setting ....and also i guess date has methods like toGMTString() and toLocaleString() . To convert the date to GMT i guess u can just say toGMTString() of the date . If u have the stringified version of date
just make a new Date(String) and then calling toGMTString of it . -
Convert data to MSWORD, MSEXCEL or PDF
Hi,
I have a requirement of sending SAP std report output as an attachment via email. I am thinking of using SUBMIT TO MEMORY or SPOOL and then get the data from there and convert and send as file attachment using SO_DOCUMENT_SEND_API1 or class CL_BCS. The file is required to be sent as MSWORD or MSEXCEL or PDF which can be decided by having a parameter on selection screen..
But I am not sure on how to convert data after retrieving it back from Memory or spool. There are a few function modules to convert. Can anyone give me the names please in each case like
For Spool to PDF function CONVERT_ABAPSPOOLJOB_2_PDF can be used
For Spool to Excel ?
For Spool to Word ?
For memory to PDF ?
For memory to Word ?
For memory to Excel ?
Regards,
VinHi,
I just had the same reuirement and i did it few days back . here is the code ...juz modify it accordingly.
The program will send my ABAP report as a PDF attachment to the USER>
REPORT ZRMM0055 NO STANDARD PAGE HEADING
MESSAGE-ID ZZ
LINE-SIZE 255
LINE-COUNT 65.
TABLES DECLARATION *
TABLES : MARD, " Storage Location Data for Material
MARC, " Plant Data for Material
MSEG,
SSCRFIELDS. " Fields on selection screens
Internal Tables declaration. *
*---Internal Table to hold the MARD table data
DATA : BEGIN OF IT_MARD OCCURS 0,
MATNR LIKE MARD-MATNR, " Material Number
WERKS LIKE MARD-WERKS, " Plant
LGORT LIKE MARD-LGORT, " Storage Location
LMINB LIKE MARD-LMINB, " Reorder Point
LABST LIKE MARD-LABST, " Stock at storage loc
END OF IT_MARD.
*---Internal table to hold data from MSEG, MKPF, MAKT
DATA : BEGIN OF IT_MSEG OCCURS 0,
MATNR LIKE MARD-MATNR, " Material Number
WERKS LIKE MARD-WERKS, " Plant
LGORT LIKE MARD-LGORT, " Storage Location
MENGE LIKE MSEG-MENGE, " Quantity
MEINS LIKE MSEG-MEINS, " UOM
LIFNR LIKE MSEG-LIFNR, " Account Number of Vendor
SHKZG LIKE MSEG-SHKZG, " Credit/Debit Indicator
EBELN LIKE EKPO-EBELN,
MENGE1 LIKE EKPO-MENGE, " Open PO qty
EINDT LIKE EKET-EINDT,
DISPO LIKE MARC-DISPO, " MRP controller
EKGRP LIKE MARC-EKGRP, " Purchasing Group
MAKTX LIKE MAKT-MAKTX,
END OF IT_MSEG.
*----Internal table to hold the data from EKPO and EKET table
DATA : BEGIN OF IT_EKPO OCCURS 0,
EBELN LIKE EKPO-EBELN, " PO document
EBELP LIKE EKPO-EBELP, " Item
MATNR LIKE MARD-MATNR, " Material Number
WERKS LIKE MARD-WERKS, " Plant
LGORT LIKE MARD-LGORT, " Storage Location
MENGE LIKE EKPO-MENGE, " Quantity
EINDT LIKE EKET-EINDT, " Delivery Date
END OF IT_EKPO.
*--Internal Table to hold the final data
DATA : BEGIN OF IT_FINAL OCCURS 0,
MATNR LIKE MARD-MATNR, " Material Number
MAKTX LIKE MAKT-MAKTX, " Material Description
LMINB LIKE MARD-LMINB, " Reorder Point
MEINS LIKE MSEG-MEINS, " UOM
LABST LIKE MARD-LABST, " On hand inventory at storageloc
TOT_LABST LIKE MARD-LABST, " Total On hand at plant
ISSUE LIKE MSEG-MENGE, " YTD issue
RECEIPT LIKE MSEG-MENGE, " YTD receipts
DISPO LIKE MARC-DISPO, " MRP controller
EKGRP LIKE MARC-EKGRP, " Purchasing Group
MENGE LIKE EKPO-MENGE, " Open PO Quantity
EINDT LIKE EKET-EINDT, " Next Delivery Date
LIFNR LIKE MSEG-LIFNR, " Vendor
EBELN LIKE MSEG-EBELN, " PO number
END OF IT_FINAL.
*----Internal table to hold YTD data
DATA : BEGIN OF IT_YTD OCCURS 0,
MENGE LIKE MSEG-MENGE,
MEINS LIKE MSEG-MEINS,
SHKZG LIKE MSEG-SHKZG,
END OF IT_YTD.
DATA : BEGIN OF X_MSEG,
MBLNR LIKE MSEG-MBLNR,
MJAHR LIKE MSEG-MJAHR,
MATNR LIKE MARD-MATNR, " Material Number
WERKS LIKE MARD-WERKS, " Plant
LGORT LIKE MARD-LGORT, " Storage Location
MENGE LIKE MSEG-MENGE, " Quantity
MEINS LIKE MSEG-MEINS, " UOM
LIFNR LIKE MSEG-LIFNR, " Account Number of Vendor
SHKZG LIKE MSEG-SHKZG, " Credit/Debit Indicator
EBELN LIKE EKPO-EBELN,
MENGE1 LIKE EKPO-MENGE, " Open PO Qty
EINDT LIKE EKET-EINDT,
DISPO LIKE MARC-DISPO, " MRP controller
EKGRP LIKE MARC-EKGRP, " Purchasing Group
MAKTX LIKE MAKT-MAKTX,
END OF X_MSEG.
DATA: V_LMINB(16) TYPE C,
S_LABST(16) TYPE C,
V_TOT_LABST(16) TYPE C,
S_ISSUE(16) TYPE C,
S_RECEIPT(16) TYPE C,
V_MENGE(16) TYPE C,
V_EINDT(8) TYPE C.
DATA: T_PDF LIKE TLINE OCCURS 100 WITH HEADER LINE.
VARIABLES DECLARATION *
DATA : V_SUM TYPE MSEG-MENGE, " Variable for adding GI's to Stock
V_TEMP TYPE MSEG-MENGE, " Variable for adding GI's to Stock
V_TABIX TYPE SY-TABIX, " Loop count
V_ISSUE LIKE MSEG-MENGE, " Variable for calculating YTD issues
V_RECEIPT LIKE MSEG-MENGE, " Var for Calculating YTD Receipts
V_LABST LIKE MARD-LABST, " Var for Total On hand inv at plant
V_MJAHR LIKE MSEG-MJAHR, " Variable for holding the Year
f_color.
*----Declaration to send Email
DATA: IT_PDF LIKE TLINE OCCURS 10 WITH HEADER LINE,
IT_XI_PDF LIKE TLINE OCCURS 0 WITH HEADER LINE,
IT_HTML LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
IT_XI_TEMP LIKE BAPIQCMIME OCCURS 0 WITH HEADER LINE,
IT_XI_MIME(255) TYPE C OCCURS 0 WITH HEADER LINE.
DATA:
LS_DOCDATA TYPE SODOCCHGI1,
LT_OBJPACK TYPE TABLE OF SOPCKLSTI1 WITH HEADER LINE,
LT_OBJHEAD TYPE TABLE OF SOLISTI1 WITH HEADER LINE,
LT_OBJTXT TYPE TABLE OF SOLISTI1 WITH HEADER LINE,
LT_OBJBIN TYPE TABLE OF SOLISTI1 WITH HEADER LINE,
LT_RECLIST TYPE TABLE OF SOMLRECI1 WITH HEADER LINE,
LT_LISTOBJECT TYPE TABLE OF ABAPLIST WITH HEADER LINE,
LT_LISTOBJECTLN(1000) TYPE C,
L_TAB_LINES TYPE I,
L_ATT_TYPE LIKE SOODK-OBJTP.
DATA: IT_OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
Internal table for Single List with Column Length 255
DATA : IT_OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
Internal table for Single List with Column Length 255
DATA : IT_OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
Internal table for Structure of the API Recipient List
DATA : IT_RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
Structure of the API Recipient List
DATA: X_DOC_CHNG LIKE SODOCCHGI1.
SELECTION-SCREEN *
SELECTION-SCREEN BEGIN OF BLOCK S1 WITH FRAME TITLE TEXT-001.
PARAMETERS:
P_WERKS LIKE MARD-WERKS OBLIGATORY. " Plant
SELECT-OPTIONS:
S_BUKRS for mseg-bukrs, " Company code
S_LGORT FOR MARD-LGORT OBLIGATORY, " Storage Location
S_MATNR FOR MARD-MATNR, " Material Number
S_DISPO FOR MARC-DISPO, " MRP Controller
S_DATE FOR SY-DATUM DEFAULT SY-DATUM OBLIGATORY. " Date Range
SELECTION-SCREEN END OF BLOCK S1.
SELECTION-SCREEN BEGIN OF BLOCK S2 WITH FRAME TITLE TEXT-002.
PARAMETERS:
P_MAIL TYPE C AS CHECKBOX. " Mail to user Group
SELECT-OPTIONS:
S_UNAME FOR SY-UNAME NO INTERVALS. " Usergroup id
SELECTION-SCREEN END OF BLOCK S2.
Initialization
INITIALIZATION.
AT S E L E C T I O N - S C R E E N
AT SELECTION-SCREEN.
CHECK SSCRFIELDS-UCOMM EQ 'ONLI'.
PERFORM VALIDATE_MAIL.
PERFORM VALIDATE_DATA.
START-OF-SELECTION *
START-OF-SELECTION.
PERFORM FETCH_DATA.
END-OF-SELECTION *
END-OF-SELECTION.
IF NOT IT_FINAL[] IS INITIAL.
PERFORM DOWNLOAD_DISPLAY_REPORT.
ENDIF.
TOP-OF-PAGE *
TOP-OF-PAGE.
PERFORM PAGE_HEADER.
*& Form Fetch_DATA
Pick data
FORM FETCH_DATA .
DATA : V_EBELN LIKE EKPO-EBELN,
V_EBELP LIKE EKPO-EBELP,
V_MENGE LIKE EKPO-MENGE,
V_EINDT LIKE EKET-EINDT,
V_DISPO LIKE MARC-DISPO,
V_EKGRP LIKE MARC-EKGRP,
V_MAKTX LIKE MAKT-MAKTX.
*----Select data from MARD Table
SELECT MATNR " Material Number
WERKS " Plant
LGORT " Storage Location
LMINB " Reorder Point Level
LABST " Stock with unrestricted use
INTO TABLE IT_MARD
FROM MARD
WHERE MATNR IN S_MATNR AND
WERKS = P_WERKS . "AND
LGORT IN S_LGORT.
D~LMINB <> SPACE .
IF SY-SUBRC = 0.
LOOP AT IT_MARD.
CLEAR : V_EBELN, V_EBELP, V_MENGE, V_EINDT.
*---select data from EKPO table
SELECT EBELN
EBELP
MENGE
UP TO 1 ROWS
FROM EKPO
INTO (V_EBELN, V_EBELP, V_MENGE)
WHERE MATNR = IT_MARD-MATNR AND
WERKS = IT_MARD-WERKS AND
LGORT = IT_MARD-LGORT AND
BUKRS IN S_BUKRS AND
ELIKZ = SPACE.
ENDSELECT.
IF SY-SUBRC = 0.
X_MSEG-EBELN = V_EBELN.
X_MSEG-MENGE1 = V_MENGE.
SELECT EINDT
UP TO 1 ROWS
FROM EKET
INTO V_EINDT
WHERE EBELN = V_EBELN AND
EBELP = V_EBELP.
ENDSELECT.
IF SY-SUBRC = 0.
X_MSEG-EINDT = V_EINDT.
ENDIF.
ENDIF.
*---Select Data from MARC table.
CLEAR : V_DISPO, V_EKGRP.
SELECT DISPO
EKGRP
UP TO 1 ROWS
FROM MARC
INTO (V_DISPO, V_EKGRP)
WHERE MATNR = IT_MARD-MATNR AND
WERKS = IT_MARD-WERKS AND
DISPO IN S_DISPO.
ENDSELECT.
IF SY-SUBRC = 0.
X_MSEG-DISPO = V_DISPO.
X_MSEG-EKGRP = V_EKGRP.
else.
continue.
ENDIF.
*---select Material Description from MAKT
CLEAR V_MAKTX.
SELECT SINGLE MAKTX
FROM MAKT
INTO V_MAKTX
WHERE MATNR = IT_MARD-MATNR AND
SPRAS = SY-LANGU.
IF SY-SUBRC = 0.
X_MSEG-MAKTX = V_MAKTX.
ENDIF.
*----Select data from MSEG Table
SELECT MBLNR
MJAHR
MATNR " Material Number
WERKS " Plant
LGORT " Storage Location
MENGE " Quantity
MEINS " UOM
LIFNR " Account No of Vendor
SHKZG " Credit/Debit Indicator
FROM MSEG
INTO X_MSEG
WHERE MATNR = IT_MARD-MATNR AND
WERKS = IT_MARD-WERKS AND
LGORT = IT_MARD-LGORT AND
BUKRS IN S_BUKRS.
*---Subroutine to check whether the document is in the given date range
PERFORM CHECK_DATE.
ENDSELECT.
ENDLOOP.
ELSE.
STOP.
ENDIF.
*----Select YTD receipts and Issues to date from MSEG
CLEAR : V_MJAHR, V_ISSUE, V_RECEIPT.
IF S_DATE[] IS NOT INITIAL.
V_MJAHR = S_DATE+3(4).
ELSE.
V_MJAHR = SY-DATUM+0(4).
ENDIF.
SELECT MENGE
MEINS
SHKZG
FROM MSEG
INTO TABLE IT_YTD
WHERE WERKS = P_WERKS AND
MJAHR = V_MJAHR.
*--Calculating YTD receipts and Issues
IF SY-SUBRC = 0.
LOOP AT IT_YTD.
IF IT_YTD-SHKZG = 'S'.
V_ISSUE = V_ISSUE + IT_YTD-MENGE.
ELSE.
V_RECEIPT = V_RECEIPT + IT_YTD-MENGE.
ENDIF.
ENDLOOP.
IT_FINAL-ISSUE = V_ISSUE.
IT_FINAL-RECEIPT = V_RECEIPT.
ENDIF.
*-----Logic for printing the material
LOOP AT IT_MSEG.
V_TABIX = SY-TABIX.
AT NEW MATNR.
*----Logic for calculation of Total On hand inv at plant.
*---Sum of all MARD-LABST.
CLEAR V_LABST.
LOOP AT IT_MARD WHERE MATNR = IT_MSEG-MATNR.
V_LABST = V_LABST + IT_MARD-LABST.
ENDLOOP.
IT_FINAL-TOT_LABST = V_LABST.
ENDAT.
AT NEW LGORT.
CLEAR : V_SUM.
ENDAT.
READ TABLE IT_MARD WITH KEY MATNR = IT_MSEG-MATNR
WERKS = IT_MSEG-WERKS
LGORT = IT_MSEG-LGORT.
IF SY-SUBRC = 0 AND IT_MARD-LMINB > 0.
*---Logic for adding/Subtracting GR/GI
IF V_TABIX = 1.
IF IT_MSEG-SHKZG = 'S'.
V_TEMP = IT_MARD-LABST + IT_MSEG-MENGE.
ELSE.
V_TEMP = IT_MARD-LABST - IT_MSEG-MENGE.
ENDIF.
ENDIF.
IF IT_MARD-LABST < IT_MARD-LMINB. "Stock < Reorder Point
*---Check for any goods receipts on the given day. SHKZG = 'S'
IF IT_MSEG-SHKZG = 'S' .
IF V_TABIX = 1.
V_SUM = V_TEMP.
ELSE.
V_SUM = V_SUM + IT_MSEG-MENGE.
ENDIF.
IF V_SUM < IT_MARD-LMINB.
IT_FINAL-MATNR = IT_MARD-MATNR.
IT_FINAL-MAKTX = IT_MSEG-MAKTX.
IT_FINAL-LMINB = IT_MARD-LMINB.
IT_FINAL-MEINS = IT_MSEG-MEINS.
IT_FINAL-LABST = IT_MARD-LABST.
IT_FINAL-DISPO = IT_MSEG-DISPO.
IT_FINAL-EKGRP = IT_MSEG-EKGRP.
IT_FINAL-LIFNR = IT_MSEG-LIFNR.
IT_FINAL-ISSUE = V_ISSUE.
IT_FINAL-RECEIPT = V_RECEIPT.
IT_FINAL-TOT_LABST = V_LABST.
IT_FINAL-EBELN = IT_MSEG-EBELN.
IT_FINAL-MENGE = IT_MSEG-MENGE1.
IT_FINAL-EINDT = IT_MSEG-EINDT.
APPEND IT_FINAL.
CLEAR IT_FINAL.
ENDIF.
ELSE.
*--- If there is no Goods receipt mov't type on the given day, then
*---add all the goods issues to the storage location stock.
*---Goos Receipt = 'S' , Goods Issue = 'H'.
IF V_TABIX = 1.
V_SUM = V_TEMP.
ELSE.
V_SUM = V_SUM - IT_MSEG-MENGE.
ENDIF.
IF V_SUM < IT_MARD-LMINB.
IT_FINAL-MATNR = IT_MARD-MATNR.
IT_FINAL-MAKTX = IT_MSEG-MAKTX.
IT_FINAL-LMINB = IT_MARD-LMINB.
IT_FINAL-MEINS = IT_MSEG-MEINS.
IT_FINAL-LABST = IT_MARD-LABST.
IT_FINAL-DISPO = IT_MSEG-DISPO.
IT_FINAL-EKGRP = IT_MSEG-EKGRP.
IT_FINAL-LIFNR = IT_MSEG-LIFNR.
IT_FINAL-ISSUE = V_ISSUE.
IT_FINAL-RECEIPT = V_RECEIPT.
IT_FINAL-TOT_LABST = V_LABST.
IT_FINAL-EBELN = IT_MSEG-EBELN.
IT_FINAL-MENGE = IT_MSEG-MENGE1.
IT_FINAL-EINDT = IT_MSEG-EINDT.
APPEND IT_FINAL.
CLEAR IT_FINAL.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " Fetch_DATA
*& Form check_date
text
FORM CHECK_DATE .
DATA: LV_BLDAT LIKE MKPF-BLDAT.
SELECT SINGLE BLDAT
FROM MKPF
INTO LV_BLDAT
WHERE MBLNR = X_MSEG-MBLNR AND
MJAHR = X_MSEG-MJAHR AND
BLDAT IN S_DATE.
IF SY-SUBRC = 0.
MOVE : X_MSEG-MATNR TO IT_MSEG-MATNR,
X_MSEG-WERKS TO IT_MSEG-WERKS,
X_MSEG-LGORT TO IT_MSEG-LGORT,
X_MSEG-MENGE TO IT_MSEG-MENGE,
X_MSEG-MEINS TO IT_MSEG-MEINS,
X_MSEG-LIFNR TO IT_MSEG-LIFNR,
X_MSEG-SHKZG TO IT_MSEG-SHKZG,
X_MSEG-EBELN TO IT_MSEG-EBELN,
X_MSEG-MENGE1 TO IT_MSEG-MENGE1,
X_MSEG-EINDT TO IT_MSEG-EINDT,
X_MSEG-DISPO TO IT_MSEG-DISPO,
X_MSEG-EKGRP TO IT_MSEG-EKGRP,
X_MSEG-MAKTX TO IT_MSEG-MAKTX.
APPEND IT_MSEG.
CLEAR IT_MSEG.
ENDIF.
ENDFORM. " check_date
*& Form PAGE_HEADER
To Print page header and other details
FORM PAGE_HEADER . "#EC CALLED
*---Page header
ULINE AT /1(150).
FORMAT COLOR COL_BACKGROUND INTENSIFIED ON .
WRITE:/ 'Run Date:'(t08), SY-DATUM, 50 'Stanley Works'(t07),
110 'Page No:'(t09), SY-PAGNO LEFT-JUSTIFIED.
WRITE:/ 'Run Time:'(t10), SY-UZEIT, 47 SY-TITLE, 110 SY-UNAME.
WRITE:/ 'Source :'(t11), SY-SYSID, 110 SY-CPROG .
ULINE AT /1(150).
WRITE :/1 'Safety Stock Report for Plant :'(t13),P_WERKS.
ENDFORM. "PAGE_HEADER
*& Form VALIDATE_DATA
Subroutine to Validate selection screen data
FORM VALIDATE_DATA .
DATA V_TEMP(20) TYPE C. "#EC NEEDED
*--Validation for Plant.
CLEAR V_TEMP.
SELECT SINGLE WERKS
INTO V_TEMP
FROM T001W
WHERE WERKS = P_WERKS.
IF SY-SUBRC NE 0.
MESSAGE E001(ZZ) WITH 'Invalid Plant'(t03). "#EC *
ENDIF.
*--Validation for Storage Location.
CLEAR V_TEMP.
IF NOT S_LGORT[] IS INITIAL.
SELECT LGORT INTO V_TEMP UP TO 1 ROWS
FROM T001L
WHERE LGORT IN S_LGORT.
ENDSELECT.
IF SY-SUBRC NE 0.
MESSAGE E001(ZZ) WITH 'Invalid Storage Location'(t04).
ENDIF.
ENDIF.
*--Validation for Material Number.
CLEAR V_TEMP.
IF NOT S_MATNR[] IS INITIAL.
SELECT MATNR
INTO V_TEMP
UP TO 1 ROWS
FROM MARA
WHERE MATNR IN S_MATNR.
ENDSELECT.
IF SY-SUBRC NE 0.
MESSAGE E001(ZZ) WITH 'Invalid Material Number'(t05).
ENDIF.
ENDIF.
*--Validation for MRP controller.
CLEAR V_TEMP.
IF NOT S_DISPO[] IS INITIAL.
SELECT DISPO INTO V_TEMP UP TO 1 ROWS
FROM T024D
WHERE DISPO IN S_DISPO.
ENDSELECT.
IF SY-SUBRC NE 0.
MESSAGE E001(ZZ) WITH 'Invalid MRP Controller'(t06).
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_DATA
*& Form validate_mail
Validate user id
FORM VALIDATE_MAIL .
IF P_MAIL = 'X' AND S_UNAME[] IS INITIAL.
MESSAGE E001(ZZ) WITH 'Enter User Mail id'(t01).
ENDIF.
ENDFORM. " validate_mail
*& Form SEND_MAIL
Send email to SAP inbox
FORM SEND_MAIL .
Structures and internal tables for the send data
DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE,
OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE,
OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,
RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
DATA: DOC_CHNG LIKE SODOCCHGI1,
TAB_LINES LIKE SY-TABIX.
Data for the status output after sending
DATA: SENT_TO_ALL LIKE SONV-FLAG.
CLEAR: IT_RECLIST, IT_RECLIST[],
IT_OBJTXT , IT_OBJTXT[],
IT_OBJPACK, IT_OBJPACK[],
IT_OBJBIN , IT_OBJBIN[],X_DOC_CHNG.
LOOP AT IT_HTML.
OBJBIN-LINE = IT_HTML-LINE.
APPEND OBJBIN.
CLEAR OBJBIN.
ENDLOOP.
Create the document which is to be sent
DOC_CHNG-OBJ_NAME = 'List'(012).
DOC_CHNG-OBJ_DESCR = 'Mail'(m05).
Heading
OBJTXT-LINE = 'Safety Stock Report attached'(014).
APPEND OBJTXT.
CLEAR OBJTXT.
Size
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
Fill the fields of the packing_list for the main document:
CLEAR OBJPACK-TRANSF_BIN.
The document needs no header (head_num = 0)
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
Body
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'(m02).
APPEND OBJPACK.
Create the attachment (the list itself)
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
Fill the fields of the packing_list for the attachment:
OBJPACK-TRANSF_BIN = 'X'.
Header
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
Body
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'PDF'(m01).
OBJPACK-OBJ_NAME = 'Attachment'(m03).
OBJPACK-OBJ_DESCR = 'Mail with pdf Attachment'(018).
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK.
*-Fill the mail recipient list
LOOP AT S_UNAME.
RECLIST-RECEIVER = S_UNAME-LOW.
RECLIST-REC_TYPE = 'B'.
APPEND RECLIST.
CLEAR: RECLIST.
ENDLOOP.
*-Send the document by calling the SAPoffice API1 module for sending
*-documents with attachments
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL = SENT_TO_ALL
TABLES
PACKING_LIST = OBJPACK
OBJECT_HEADER = OBJHEAD
CONTENTS_BIN = OBJBIN
CONTENTS_TXT = OBJTXT
RECEIVERS = RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
OPERATION_NO_AUTHORIZATION = 4
OTHERS = 99.
CASE SY-SUBRC .
WHEN 0.
MESSAGE s001 WITH 'Mail has been sent successfully'(003).
WHEN OTHERS.
MESSAGE s001 WITH 'Problem in sending the mail'(004).
ENDCASE.
ENDFORM. " SEND_MAIL
*& Form download_display_report
Download and dispaly report
FORM DOWNLOAD_DISPLAY_REPORT .
DATA: X_PARAMS TYPE PRI_PARAMS,
V_VALID.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
IMMEDIATELY = ' '
LAYOUT = 'X_65_255'
NO_DIALOG = 'X'
IMPORTING
OUT_PARAMETERS = X_PARAMS
VALID = V_VALID.
IF V_VALID <> SPACE.
NEW-PAGE PRINT ON PARAMETERS X_PARAMS NO DIALOG.
PERFORM DISPLAY_REPORT.
NEW-PAGE PRINT OFF.
PERFORM CONV_TO_PDF_DOWNLOAD.
ENDIF.
PERFORM DISPLAY_REPORT.
ENDFORM. " download_display_report
*& Form DISPLAY_REPORT
Display the report
FORM DISPLAY_REPORT .
ULINE AT /0(204).
write:/1 sy-vline no-gap, (10)'Material'(032),
sy-vline no-gap, (40)'Description'(031),
sy-vline no-gap, (15)'Reorder pt'(030),
sy-vline no-gap, (03)'BUn'(029),
sy-vline no-gap, (13)'OnHandQty'(023),
sy-vline no-gap, (13)'OnHandPlnt'(024),
sy-vline no-gap, (13)'YTD issues'(025),
sy-vline no-gap, (13)'YTD Receipts'(026),
sy-vline no-gap, (08)'MRPcntrl'(027),
sy-vline no-gap, (04)'POgrp'(028),
sy-vline no-gap, (13)'POqty'(019),
sy-vline no-gap, (10)'NextDelvDt'(020),
sy-vline no-gap, (10)'Vendor'(021),
sy-vline no-gap, (10)'PO#'(022),
sy-vline no-gap.
ULINE AT /0(204).
loop at it_final.
PERFORM COLOR_SWAP.
write:/1 sy-vline no-gap, (10)it_final-matnr,
sy-vline no-gap, (40)it_final-maktx,
sy-vline no-gap, (15)it_final-lminb, "#EC UOM_IN_MES
sy-vline no-gap, (03)it_final-meins,
sy-vline no-gap, (13)it_final-labst, "#EC UOM_IN_MES
sy-vline no-gap, (13)it_final-tot_labst, "#EC UOM_IN_MES
sy-vline no-gap, (13)it_final-issue, "#EC UOM_IN_MES
sy-vline no-gap, (13)it_final-receipt, "#EC UOM_IN_MES
sy-vline no-gap, (08)it_final-dispo,
sy-vline no-gap, (04)it_final-ekgrp,
sy-vline no-gap, (13)it_final-menge, "#EC UOM_IN_MES
sy-vline no-gap, (10)it_final-eindt,
sy-vline no-gap, (10)it_final-lifnr,
sy-vline no-gap, (10)it_final-ebeln,
sy-vline no-gap.
endloop.
ULINE AT /0(204).
skip 2.
WRITE:/ '******End of Report*******'.
ENDFORM. " DISPLAY_REPORT
*& Form CONV_TO_PDF_DOWNLOAD
Convert to PDF
FORM CONV_TO_PDF_DOWNLOAD .
DATA: V_NUMBYTES TYPE I,
V_SPOOLNO TYPE TSP01-RQIDENT.
CLEAR IT_PDF.
REFRESH IT_PDF.
WAIT UP TO 2 SECONDS.
V_SPOOLNO = SY-SPONO.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
SRC_SPOOLID = V_SPOOLNO
NO_DIALOG = ' '
IMPORTING
PDF_BYTECOUNT = V_NUMBYTES
TABLES
PDF = IT_PDF.
IF SY-SUBRC = 0. "#EC *
PERFORM PAGE_FORMAT.
ENDIF.
ENDFORM. " CONV_TO_PDF_DOWNLOAD
*& Form page_format
Format the page
FORM PAGE_FORMAT .
DATA : L_LINES TYPE I,
L_TEMP(500) TYPE C,
L_OFFSET TYPE P,
L_LINESLEN(2) TYPE P,
L_MIMELEN(2) TYPE P,
L_TABIX LIKE SY-TABIX.
CLEAR : IT_XI_PDF,
IT_XI_TEMP.
REFRESH : IT_XI_PDF,
IT_XI_TEMP.
IT_XI_PDF[] = IT_PDF[].
Reformat the line to 255 characters wide (code from SAP)
CLEAR: L_TEMP, L_OFFSET, IT_XI_TEMP.
DESCRIBE TABLE IT_XI_PDF LINES L_LINES.
DESCRIBE FIELD IT_XI_PDF LENGTH L_LINESLEN IN CHARACTER MODE.
DESCRIBE FIELD IT_XI_TEMP LENGTH L_MIMELEN IN CHARACTER MODE.
LOOP AT IT_XI_PDF.
L_TABIX = SY-TABIX.
MOVE IT_XI_PDF TO L_TEMP+L_OFFSET.
IF L_TABIX = L_LINES.
L_LINESLEN = STRLEN( IT_XI_PDF ).
ENDIF.
L_OFFSET = L_OFFSET + L_LINESLEN.
IF L_OFFSET GE L_MIMELEN.
CLEAR IT_XI_TEMP.
IT_XI_TEMP = L_TEMP(L_MIMELEN).
APPEND IT_XI_TEMP.
SHIFT L_TEMP BY L_MIMELEN PLACES.
L_OFFSET = L_OFFSET - L_MIMELEN.
ENDIF.
IF L_TABIX = L_LINES.
IF L_OFFSET GT 0.
CLEAR IT_XI_TEMP.
IT_XI_TEMP = L_TEMP(L_OFFSET).
APPEND IT_XI_TEMP.
ENDIF.
ENDIF.
ENDLOOP.
CLEAR : IT_XI_MIME,
IT_XI_MIME[].
LOOP AT IT_XI_TEMP.
IT_XI_MIME(255) = IT_XI_TEMP-LINE.
APPEND IT_XI_MIME.
CLEAR IT_XI_MIME.
ENDLOOP.
Final Data
CLEAR : IT_HTML,
IT_HTML[].
IT_HTML[] = IT_XI_MIME[].
For sending mail
PERFORM SEND_MAIL .
ENDFORM. " page_format
Form : color_swap
Description : Subroutine for color
form color_swap.
if flag is set
if f_color eq 'X'.
clear f_color.
switch off the intensity
format color col_normal intensified off.
else.
if flag is not set.
f_color = 'X'.
switch on the intensity
format color col_normal intensified on.
endif.
endform. " color_swap -
Converting date format from in mapping
hi xi friends.
in my scenario i just want to convert date format from 12022007 which is file to 12.02.2007 which is in target bapi.
waiting for u.
bye.
regards.
seeta ram.Hi,
if I understood you correctly you want to transform from ddMMyyyy (your format in the external file) to yyyyMMdd (format of ABAP datatype DATS):
Then all you need to do is to use the standard function TransformDate (as already described above).
Enter in the field "Format of source Date": ddMMyyyy
Enter in the field "Target Format": yyyyMMdd
That's it.
Regards,
Helmut -
Im getting an error when running a procedure that includes this code.
I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql
DECLARE @retval AS DECIMAL(12,2)
DECLARE @MonthVal VARCHAR(20), @SpreadKeyVal INT
DECLARE @sqlcmd AS NVARCHAR(150)
DECLARE @paramdef NVARCHAR(150)
SET @MonthVal = 'Month' + CAST(@MonthNumber AS VARCHAR(2) );
SET @SpreadKeyVal = @SpreadKey; --CAST(@SpreadKey AS VARCHAR(10) );
SET @sqlcmd = N' SELECT @retvalout = @MonthVal FROM dbo.CourseSpread WHERE CourseSpreadId = @SpreadKeyVal';
SET @paramdef = N'@MonthVal VARCHAR(20), @SpreadKeyVal INT, @retvalout DECIMAL(12,2) OUTPUT'
--default
SET @retval = 0.0;
EXECUTE sys.sp_executesql @sqlcmd,@paramdef, @MonthVal = 'Month4',@SpreadKeyVal = 1, @retvalout = @retval OUTPUT;
SELECT @retval
DECLARE @return_value DECIMAL(12,2)
EXEC @return_value = [dbo].[GetSpreadValueByMonthNumber]
@SpreadKey = 1,
@MonthNumber = 4
SELECT 'Return Value' = @return_value
Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to numeric.Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for:
https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
>> I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql <<
This is so very, very wrong! A column is an attribute of an entity. The idea that you are so screwed up that you have no idea if you want
the shoe size, the phone number or something else at run time of this entity.
In Software Engineering we have a principle called cohesion that says a model should do one and only one task, have one and only one entry point, and one and only one exit point.
Hey, on a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, your mindset is that level of sillyity and absurdity.
Do you know that SQL is a declarative language? This family of languages does not use local variables!
Now think about “month_val” and what it means. A month is a temporal unit of measurement, so this is as silly as saying “liter_val” in your code. Why did you use “sp_” on a procedure? It has special meaning in T-SQL.
Think about how silly this is:
SET @month_val = 'Month' + CAST(@month_nbr AS VARCHAR(2));
We do not do display formatting in a query. This is a violation of at the tiered architecture principle. We have a presentation layer. But more than that, the INTERVAL temporal data type is a {year-month} and never just a month. This is fundamental.
We need to see the DDL so we can re-write this mess. Want to fix it or not?
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL
Maybe you are looking for
-
HP Color LaserJet 3550 offline
Our HP Color Laserjet 3550 printer has gone offline today. The first PC to have the issue was a windows 7 ultimate x64 machine, then various XP pro x86 machines and finally it's now showing offline on our server (Windows 2003 SBS x86). I can't figu
-
Line of best fit in scatter plots
when making a line of best fit ( in this case a curve of best fit) how do I extend the curve beyond my data so that I can extrapolate information? Can I do this or will I have to do it manually? (print it out and draw it myself)
-
Downloading an app, prompts me I can't download 23 apps
When I download an app from the app store, after I give my apple id password, it will tell me 23 apps cannot be downloaded at this time (including whatsapp and some others..) I don't need to download these apps and there is no update for whatsapp.. s
-
Howto make tabs show up in the title bar
There was a version of safari that had the tabs in the title bar anyone know how to mac that happen on windows? found this for OS X, but stuck with winblows at work http://jkontherun.com/2009/03/11/how-to-get-safari-4-for-mac-tabs-out-of-the-tit leba
-
Unable to Read and/or write "*"
The above is part of the error msg I get when trying to burn Disc #3 (after song #2) of my new box set of Richard Thompson tunes. So to be clear, it copied in the first two songs, started on the third, then stopped and displayed the error msg. I've t