㈠ 在ABAP開發中如何獲取選擇日期前一個月的固定日期
沒有實現的類,可以自己寫一個。
這有一個類。你可以試一下:
package com;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.event.DocumentListener;
import javax.swing.text.DateFormatter;
import com.shiji.pastoral.common.arithmetic.CalculateDate;
import com.shiji.pastoral.common.arithmetic.GlobalStatus;
import com.shiji.pastoral.server.common.method.DebugPrint;
/**
* 日期控制項
*
* @author 2008-5-23 上午11:38:14
*/
public class DatePanel extends JPanel {
private CalculateDate cal = new CalculateDate();
public JFormattedTextField hotelFormattedTextField;
public JButton dateButton;
private Window dialog;
private String labelName; // 每個Date的名稱都不一樣
private int x; // 跳出日期控制項的x軸
private int y; // 跳出日期控制項的y軸
public static String initDate = "1900-01-01";// CalculateDate.dateToString(CalculateDate.NULLDATE);
// // 系統默認Date
private boolean judge;
private String type = "-";
private static String time;
private JRadioButton enableRadioButton;
private boolean allowEmptyStr = true;// 是否允許文本框為空
public FocusAdapter f;
/**
* 系統初始化構造函數
*
* @author 2008-7-22 上午11:38:27
*
*/
public DatePanel() {
this(false);
}
public DatePanel(JDialog dialog) {
this(dialog, true);
}
public DatePanel(boolean showRadioBox) {
super();
dialog = DFrame.frame;
initGUI();
enableRadioButton.setVisible(showRadioBox);
}
/**
* 舊的方法,不建議使用,最終還是要刪除的。。。by Jimmy
*
* @deprecated
* @param dialog
* @param labelName
* @param judge
*/
public DatePanel(Window dialog, String labelName, boolean judge,
boolean showRadioBox) {
super();
this.dialog = dialog;
this.labelName = labelName;
this.judge = judge;
initGUI();
enableRadioButton.setVisible(showRadioBox);
}
public DatePanel(Window dialog, String labelName, boolean judge) {
this(dialog, labelName, judge, false);
}
public DatePanel(Window dialog, boolean judge) {
super();
this.dialog = dialog;
this.labelName = "";
this.judge = judge;
initGUI();
enableRadioButton.setVisible(false);
}
private void initGUI() {
this.setPreferredSize(new java.awt.Dimension(139, 21));
BorderLayout thisLayout = new BorderLayout();
this.setLayout(thisLayout);
this.add(getDateButton(), BorderLayout.EAST);
this.add(getHotelFormattedTextField(), BorderLayout.CENTER);
this.add(getEnableRadioButton(), BorderLayout.WEST);
}
private JFormattedTextField getHotelFormattedTextField() {
// MaskFormatter mf = null;
// try {
// mf = new MaskFormatter("####-##-##");
// // mf.(false);
// } catch (Exception e) {
// e.printStackTrace();
// }
/*
* hotelFormattedTextField = new JFormattedTextField();
* hotelFormattedTextField.setDocument(new DateLimited(
* hotelFormattedTextField, new SimpleDateFormat("yyyy" + type + "MM" +
* type + "dd"))); hotelFormattedTextField.setText(initDate);
* hotelFormattedTextField.addFocusListener(new FocusAdapter() { public
* void focusLost(FocusEvent evt) { if
* (hotelFormattedTextField.getText().indexOf(" ") != -1 && judge) {
* JOptionPane.showMessageDialog(dialog, "Date is null!");
* hotelFormattedTextField.setText(" " + type + " " + type + " ");
* hotelFormattedTextField.requestFocus(); } } });
*/
// if(dateFormatType.trim().isEmpty()||dateFormatType==null)
// dateFormatType = CalculateDate.dateFormatType;// "yyyy-MM-dd";
DateFormat dateFormat = new SimpleDateFormat(
CalculateDate.dateFormatType);
DateFormatter df = new DateFormatter(dateFormat);
hotelFormattedTextField = new JFormattedTextField(df);
hotelFormattedTextField
.setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT);
hotelFormattedTextField.setBorder(new SoftBevelBorder(
BevelBorder.LOWERED, null, null, null, null));
hotelFormattedTextField.setFont(new java.awt.Font(null, 1, 12));
hotelFormattedTextField.setValue(CalculateDate.HotelDate);
if (allowEmptyStr)
hotelFormattedTextField.setText("");// 設置為空時間
else
hotelFormattedTextField.setValue(CalculateDate.HotelDate);
hotelFormattedTextField.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent evt) {
if (hotelFormattedTextField.getText().trim().isEmpty()
&& allowEmptyStr) {
// DebugPrint.onePrint("現在輸入的是空串");
hotelFormattedTextField
.setFocusLostBehavior(JFormattedTextField.PERSIST);// 不執行任何操作,不獲取新的
// AbstractFormatter
// 也不更新該值。
} else {
hotelFormattedTextField
.setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT);// 恢復顯示以匹配
// getValue,這可能丟失當前的編輯內容
if (hotelFormattedTextField.isEditValid()) {
// DebugPrint.onePrint("現在輸入的是有效值");
hotelFormattedTextField.setFocusLostBehavior(JFormattedTextField.PERSIST);
if (CalculateDate.isNullDate(getDate())) {
// DebugPrint.onePrint("現在輸入的時間是空時間");
hotelFormattedTextField.setText("");
}else if(getDate().compareTo(CalculateDate.NULLDATE)<0){
DefinedOptionPane.showMessageDialog(null,GlobalStatus.lang("Invalid Date can't less than 1900-01-01"), 1);
setDate(CalculateDate.getHotelDate(GlobalStatus.userStructure.getHotelID()));
}else if(getDate().compareTo(CalculateDate.MAXDATE)>0){
DefinedOptionPane.showMessageDialog(null,GlobalStatus.lang("Invalid Date can't more than 3000-12-31"), 1);
setDate(CalculateDate.getHotelDate(GlobalStatus.userStructure.getHotelID()));
}
} else {
if (!hotelFormattedTextField.getText().trim().isEmpty()) {
// DebugPrint.onePrint("現在輸入的是無法效值");
DefinedOptionPane
.showMessageDialog(null,
GlobalStatus.lang("Invalid Date: ")
+ hotelFormattedTextField
.getText(), 1);
// hotelFormattedTextField.setText(initDate);
}
}
}
}
});
return hotelFormattedTextField;
}
private int getX(MouseEvent evt) {
int x1 = evt.getXOnScreen() - evt.getX()
- hotelFormattedTextField.getWidth();
int x2 = DFrame.width - CalendarDialog.width;
DebugPrint.jimmyPrintMsg(x1, x2);
return x1 > 0 ? Math.min(x1, x2) : 0;
}
private int getY(MouseEvent evt) {
int y1 = evt.getYOnScreen() + dateButton.getHeight() - evt.getY();
int y2 = DFrame.height - CalendarDialog.height;
if (y1 > y2)
y1 = evt.getYOnScreen() - evt.getY() - CalendarDialog.height;
return y1;
}
private JButton getDateButton() {
if (dateButton == null) {
dateButton = new JButton();
dateButton.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("img/down.png")));
dateButton.setPreferredSize(new java.awt.Dimension(20, 21));
dateButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt) {
x = getX(evt);
y = getY(evt);
}
});
dateButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
time = CalculateDate.dateToString(new CalendarDialog(
dialog, x, y, getDate()).getDate());
} catch (RuntimeException e) {
time = CalculateDate.dateToString(new CalendarDialog(
dialog, x, y, new Date()).getDate());
}
hotelFormattedTextField.setText(time.length() == 10
? time
: initDate);
hotelFormattedTextField.requestFocus();
time = initDate;
}
});
}
return dateButton;
}
/**
* 設置日期..不推薦用這個。。沒測試過one
*
* @author 2008-8-5 上午10:37:33
*
* @param date
*/
public void setDate(String date) {
// setDate(new CalculateDate().stringToDate(date));
// hotelFormattedTextField.setValue(CalculateDate.dateFormat(new
// CalculateDate().stringToDate(date), dateFormatType));
if (date.trim().isEmpty())
hotelFormattedTextField.setText("");
else
setDate(CalculateDate.stringToDateExp(date));
}
public String getText() {
return CalculateDate.dateToString(getDate());
}
/**
* 獲取日期
*
* @author 2008-8-5 上午10:37:46
*
* @return
*/
public Date getDate() {
// Date returndate;
// returndate = new CalculateDate().stringToDate(hotelFormattedTextField
// .getText());
if (hotelFormattedTextField.getText().trim().isEmpty()) {
// DebugPrint.onePrint("現在的日期是" + cal.stringToDate("1900-01-01"));
return cal.stringToDate("1900-01-01");
} else {
// DebugPrint.onePrint("現在的日期是"+
// cal.stringToDate(hotelFormattedTextField.getText()));
return cal.stringToDate(hotelFormattedTextField.getText());
}
}
/**
*
*
* @author Administrator 2008-9-16 下午02:33:24
*
* @param date
*/
public void setDate(Date date) {
// hotelFormattedTextField.setText(date != null ? new CalculateDate()
// .dateToString(date) : initDate);
if (CalculateDate.isNullDate(date))
hotelFormattedTextField.setText("");
else
hotelFormattedTextField.setText(CalculateDate.dateToString(date));
}
/**
* 設置文本框是否能為空
*
* @author One 2009-6-4上午10:09:14
*
* @param allow
*/
public void setAllowEmptyStr(boolean allow) {
allowEmptyStr = allow;
}
/**
* 設置錯誤日期的顏色
*
* @author One 2009-6-10下午04:27:58
*
* @param error
*/
public void setColour(boolean error) {
if (error)
hotelFormattedTextField.setForeground(Color.RED);
else
hotelFormattedTextField.setForeground(Color.BLACK);
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
hotelFormattedTextField.setEnabled(enabled);
dateButton.setEnabled(enabled);
enableRadioButton.setSelected(enabled);
}
private JRadioButton getEnableRadioButton() {
if (enableRadioButton == null) {
enableRadioButton = new JRadioButton();
enableRadioButton.setSelected(true);
enableRadioButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
setEnabled(enableRadioButton.isSelected());
}
});
}
return enableRadioButton;
}
public static void main(String[] args) {
JDialog frame = new JDialog();
frame.getContentPane().add(new DatePanel());
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
/**
* @author rainbow 2009-7-14 下午12:01:55
* @param listener
*
*/
public void addDocumentListener(DocumentListener listener) {
hotelFormattedTextField.getDocument().addDocumentListener(listener);
}
/**
* @author rainbow 2009-7-14 下午12:01:58
* @param listener
*
*/
public void removeDocumentListener(DocumentListener listener) {
hotelFormattedTextField.getDocument().removeDocumentListener(listener);
}
}
㈡ abap 中 select 語句 s_month(選擇屏幕輸入,列如:201612(年度加上期間)) A IN S_MONTH(前四位值),
另外定義兩個選擇變數。
RANGES:S_A FOR BKPF-GJAHR,
S_B FOR BKPF-MONAT.
根據輸入信息給兩個選擇變數賦值
LOOP AT s_month.
S_A-SIGN = S_MONTH-SIGN.
S_A-OPTION = S_MONTH-OPTION.
S_A-LOW = S_MONTH-LOW+0(4).
S_A-HIGH = S_MONTH-HIGH+0(4).
APPEND S_A.
S_B-SIGN = S_MONTH-SIGN.
S_B-OPTION = S_MONTH-OPTION.
S_B-LOW = S_MONTH-LOW+4(2).
S_B-HIGH = S_MONTH-HIGH+4(2).
APPEND S_B.
ENDLOOP.
然後得到的選擇變數取值
A IN S_A
B IN S_B
㈢ ABAP 日期條件問題請教
別寫NOT BETWEEN,寫了很容易造成Full table scan,效率太差
㈣ ABAP如何檢查字元串是否為日期或時間格式
1、底下函數是檢查日期的合法性的函數
CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
EXPORTING
date = v_date
EXCEPTIONS
plausibility_check_failed = 1
OTHERS = 2.
IF sy-subrc NE 0. "如果返回非0,則日期不合法
.
.
ENDIF.
2、底下函數是檢查時間合法性的函數
CALL FUNCTION 'TIME_CHECK_PLAUSIBILITY'
EXPORTING
time = v_time
EXCEPTIONS
plausibility_check_failed = 1
OTHERS = 2.
IF sy-subrc NE 0. "如果返回非0,則時間不合法
.
.
ENDIF.
㈤ abap取得系統日期之前幾個月
sy-datum+4(2)
㈥ 請教問題:ABAP中的幣別轉換
SAP中的貨幣轉換函數:CURRENCY_CONVERTING_FACTOR【CURRENCY_CONVERTING_FACTOR】在SAP系統中,對於曰幣、韓幣這類特殊貨幣的處理是有特殊規則的。 具體的處理邏輯為:首先根據幣別到DB表TCURX中讀取相應的小數位數CURRDEC。如果沒有維護相應幣別信息則默認CURRDEC = 2。如果 CURRDEC GT 5.就報錯。然後默認轉換比率是100。在CURRDEC NE 0的情況下循環CURRDEC次,每次將轉換比率除以10 。 所以如果表TCURX中的CURRDEC = 0就默認轉換比率為100。當表TCURX中沒有找到相應數據時則默認CURRDEC = 2。轉換比率也就是100 / 10 / 10 = 1.其他的比如如果表TCURX中的CURRDEC = 4,則轉換比率應該為 100 / 10 / 10 / 10 / 10 = 0.01我們在SE16中看到的貨幣金額基本上都經過了這個轉換,如曰元,都是除以100後存入資料庫的。所以當我們從資料庫中讀取曰元金額時也應該作相應的轉換,乘以100 。簡單的使用Function CURRENCY_CONVERTING_FACTOR。輸入幣別,就可以得到相應的轉換比率了。 函數中所涉及的常用選項:EXPORTING: CURRENCY: 將被處理的貨幣種別編號IMPORTING: FACTOR: 轉換後得到的貨幣比率 示範代碼:FORM BRF_AP USING F_BETRAG "金額 F_CURRENCY. " 貨幣代碼DATA: S_FACTORTYPEP DECIMALS 3.CALL FUNCTION 'CURRENCY_CONVERTING_FACTOR' EXPORTING CURRENCY = F_CURRENCY IMPORTING FACTOR = S_FACTOR EXCEPTIONS TOO_MANY_DECIMALS = 1 OTHERS = 2.IF S_FACTOR NE 0. F_BETRAG = F_BETRAG / S_FACTOR.ENDIF.ENDFORM. 到思互圈子網站查看回答詳情>>
㈦ SAP ABAP如何解決外系統輸入日期的問題
標準的做法是事先跟外系統約定日期格式,一旦確定以後,不符合格式的數據一律視為非法數據。
㈧ SAP ABAP 顯示年月日時分秒的數據類型
這是年月日時分秒在一個欄位的數據類型
DATA: lv_timestamp TYPE timestamp. "UTC Time Stamp in Short Form (YYYYMMDDhhmmss)
GET TIME STAMP FIELD lv_timestamp.
WRITE:/ lv_timestamp.
不過還是定義兩個欄位,一個日期一個時間,一般都用這種
然後用sy-datum和sy-uzeit獲取的系統伺服器時區時間比較方便
㈨ SAP提示不能按日期確定來自RMB的匯率,這個問題怎麼解決
匯率是波動的,一般企業會月度維護當月的成本結算匯率。
按你圖所示,錯誤發生的原因是:沒有維護3月的匯率。
㈩ SAP 定價日期跟發票校驗什麼關系
在開票條件中使用