Sap Bapi 创建采购申请单(100)

Discussion in 'ActiveX 控件' started by huapoint, Sep 20, 2010.

  1. hu

    huapoint New Member Member

    var abc: TDate;
    MLDText, Notes: string;
    Funct, ActFunct, NUMBERS, AUTOMATIC_SOURCES, REQ_ITEMS, REQ_ITEMSROW, Commit, CommitRBack, Rst, Ret: Variant;begin
    ShortDateFormat := 'yyyy-MM-dd';
    LongDateFormat := 'yyyy-MM-dd';
    Notes := '';
    if not SapConnState then
    begin
    MessageDlg('Not Connected to Sap Rfc, Create Pr Failed.', MTInformation, [mbOK], 0);
    Exit;
    end;

    abc := Date;
    Funct := sapFunctions1.add('BAPI_REQUISITION_CREATE');
    NUMBERS := Funct.exports('NUMBER');
    AUTOMATIC_SOURCES := Funct.exports('AUTOMATIC_SOURCE');
    REQ_ITEMS := Funct.tables.item('REQUISITION_ITEMS');
    Ret := Funct.tables.item('RETURN');
    REQ_ITEMSROW := REQ_ITEMS.rows.add;
    REQ_ITEMSROW.Value('MATERIAL') := '100001';//物料号 REQ_ITEMSROW.Value('ACCTASSCAT') := 'F';
    //科目分配类别(无SAP码则必填)F或K REQ_ITEMSROW.Value('Doc_Type') := 'NB';
    //采购申请凭证类型 REQ_ITEMSROW.Value('CREATED_BY') := '513404';
    //创建人 REQ_ITEMSROW.Value('Plant') := '1000';
    //工厂 REQ_ITEMSROW.Value('Unit') := 'PCS';
    //采购申请计量单位 REQ_ITEMSROW.Value('Quantity') := 5;
    //采购申请数量 REQ_ITEMSROW.Value('Short_Text') := 'TLH Test';
    //短文本(必填) REQ_ITEMSROW.Value('MAT_GRP') := '001';
    REQ_ITEMSROW.Value('PUR_GROUP') := '001';
    REQ_ITEMSROW.Value('DELIV_DATE') := DATE;
    //FormatDateTime('dd.MM.yyyy',date);
    //项目交货日期 //REQ_ITEMSROW.Value('DEL_DATCAT') := 'D';
    //日期类型 (日,周,月,间隔) REQ_ITEMSROW.Value('PREQ_DATE') := DATE;
    //FormatDateTime('dd.MM.yyyy',date);//下单(请求)日期 //REQ_ITEMSROW.Value('CURRENCY') := 'CNY';
    //货币码 REQ_ITEMSROW.Value('TRACKINGNO') := '123456';
    //需求跟踪号 if not funct.call then
    begin
    CommitRBack := sapFunctions1.add('BAPI_TRANSACTION_ROLLBACK');
    CommitRBack.Call;
    MLDText := funct.imports('PURCHASEORDER');
    MessageDlg('Purcaseorder ' + MLDText + ' Create Failed.', MTInformation, [mbOK], 0);
    end else
    if funct.call then
    begin
    Commit := sapFunctions1.add('BAPI_TRANSACTION_COMMIT');
    Commit.Call;
    MLDText := ' 消息类型:[' + Ret.Value(1, 'Type') + '] 消息文本:[' + Ret.Value(1, 'MESSAGE') + ']';
    Notes := REQ_ITEMSROW.Value('PREQ_NO');
    MessageDlg('SAP消息反馈...' + #13#13 + MLDText + #13#13 + '采购申请编号:' + Notes, MTInformation, [mbOK], 0);
    end;
    end;