2009 年 03 月 12日, 星期四

关于AT New的几个说明

1、AT New事件触发说明
如 AT New f.
f 是内表的一个字段,当f字段或者f字段左边的字段内容发生变化是该事件后面的语句都会执行。
TYPES: BEGIN OF COMPANIES_TYPE,
NAME(30),
PRODUCT(20),
SALES TYPE I,
END OF COMPANIES_TYPE.

DATA: COMPANIES TYPE STANDARD TABLE OF COMPANIES_TYPE WITH
NON-UNIQUE DEFAULT KEY INITIAL SIZE 20,
WA_COMPANIES TYPE COMPANIES_TYPE.

...

LOOP AT COMPANIES INTO WA_COMPANIES.
AT NEW PRODUCT.
NEW-PAGE.
WRITE / WA_COMPANIES-NAME WA_COMPANIES-PRODUCT.
ENDAT.
WRITE: / WA_COMPANIES-PRODUCT, WA_COMPANIES-SALES.
AT END OF NAME.
SUM.
WRITE: / WA_COMPANIES-NAME, WA_COMPANIES-SALES.
ENDAT.
ENDLOOP.

这个样例当name变化时,AT new事件也会执行。

举例:字段a b c d

1 1 1 1

1 1 1 2

1 2 1 1

at new c ,当循环第一,二行时,字段a b 都未发生变化,那就循环继续,当循环第三行时,字段b变化了,也就是说c左边的字段发生变化了,那本次循环结束,开始新的循环。把第三行换成1 1 2 1,字段a b 未发生变化,只有c发生变化,也就是说c发生变化,则循环停止,开始新的循环。在at new f 时,不考虑字段f之后的字段内容变化,也就是后面说的(All character type fields (on the right) are filled with "*" after the current control level key. ),在字段f之后系统将默认为"*",也就是说f之后的内容不管相同与否,都视为“*”,不将其考虑,不在at new 事件的考虑范围之内。

2、AT New 发生时工作区的字段的值

  • All character type fields (on the right) are filled with "*" after the current control level key.
  • All other fields (on the right) are set to their initial values after the current control level key.
  • AT NEW <f> │ AT END OF <f>.
    ...
    ENDAT.
    如果字段 <f> 或当前摘录 记录中的排 序关键字的 较高层字段 中包含其它 值,并且该 值与摘
    录数 据集前面的 记录(对于 AT NEW)或 后续记录( 对于 AT END)中 的值不同, 将产生控
    制 中断,并且 系统将处理 AT-ENDAT 中的语句块 。字段 <f> 必须是 HEADER 字段组的一 部
    分。

    如果摘录数 据集没有排 序,则系统 将忽略 AT-ENDAT 中的语句块 。
    在决定控制 中断时,系 统将忽略未 在摘录过程 中定义的 <f> 的字段内容 (空值)。
    系统将一个 接一个地处 理循环中的 所有 AT...ENDAT 处理块。所 以要当心它 们的顺序。 在
    控制级逻 辑内,请保 持排序顺序 。该顺序不 一定是 HEADER 字段组中的 字段的顺序 ,但可
    以是 在 SORT 语句中确定 的顺序。
  • When you perform a sort using the SORTstatement, control levels are defined in the extract dataset. For general information about control levels, refer to Processing Internal Tables in Loops The control level hierarchy of an extract dataset corresponds to the sequence of the fields in the header field group. After sorting, you can use the ATstatement within a LOOP loop to program statement blocks that the system processes only when the control level changes.

    AT NEW f | AT END OF f.
    ...

    ENDAT.

    A control break occurs when the value of the field f or a superior field in the current record has a different value from the previous record (AT NEW) or the subsequent record (AT END). Field f must be part of the header field group.

    If the extract dataset is not sorted, the AT - ENDAT block is never executed. Furthermore, all extract records with the value HEX null in the field f are ignored when the control breaks are determined.

    The AT... ENDAT blocks in a loop are processed in the order in which they occur. This sequence should be the same as the sort sequence. This sequence must not necessarily be the sequence of the fields in the header field group, but can also be the one determined in the SORT statement.

    If you have sorted an extract dataset by the fields f1, f2, …, the processing of the control levels should be written between the other control statements in the LOOP loop as follows:

    LOOP.
    AT FIRST.... ENDAT.
    AT NEW f
    1....... ENDAT.
    AT NEW f
    2.......
    ENDAT.
    ...
    AT fg
    i.....
    ENDAT.
    Single record processing without control statement
    ...

    AT END OF f
    2.... ENDAT.
    AT END OF f
    1....
    ENDAT.
    AT LAST..... ENDAT.
    ENDLOOP.

    You do not have to use all of the statement blocks listed here, but only the ones you require.

    Example

    REPORT demo_extract_at_new.

    DATA: t1(4) TYPE c, t2 TYPE i.

    FIELD-GROUPS: header.

    INSERT t2 t1 INTO header.

    t1 ='AABB'. t2 = 1. EXTRACT header.
    t1 ='BBCC'. t2 = 2. EXTRACT header.
    t1 ='AAAA'. t2 = 2. EXTRACT header.
    t1 ='AABB'. t2 = 1. EXTRACT header.
    t1 ='BBBB'. t2 = 2. EXTRACT header.
    t1 ='BBCC'. t2 = 2. EXTRACT header.
    t1 ='AAAA'. t2 = 1. EXTRACT header.
    t1 ='BBBB'. t2 = 1. EXTRACT header.
    t1 ='AAAA'. t2 = 3. EXTRACT header.
    t1 ='AABB'. t2 = 1. EXTRACT header.

    SORT BY t1 t2.

    LOOP.

    AT FIRST.
    WRITE 'Start of LOOP'.
    ULINE.
    ENDAT.

    AT NEW t1.
    WRITE / ' New T1:'.
    ENDAT.

    AT NEW t2.
    WRITE / ' New T2:'.
    ENDAT.

    WRITE: /14 t1, t2.

    AT END OF t2.
    WRITE / 'End of T2'.
    ENDAT.

    AT END OF t1.
    WRITE / 'End of T1'.
    ENDAT.

    AT LAST.
    ULINE.
    ENDAT.

    ENDLOOP.

    This program creates a sample extract, containing the fields of the header field group only. After the sorting process, the extract dataset has several control breaks for the control levels T1 and T2, which are indicated in the following figure:

    This graphic is explained in the accompanying text

    In the LOOP loop, the system displays the contents of the dataset and the control breaks it recognized as follows:

    This graphic is explained in the accompanying text


  • ultraluck 发表于:2009.03.12 22:12 ::分类: ( SAP ABAP ) ::阅读:(29次) :: 评论 (0) :: 引用 (0)

    2008 年 11 月 13日, 星期四

    send mail by sap

    *&---------------------------------------------------------------------*
    *& Report ZEMAIL_ATTACH *
    *& *
    *&---------------------------------------------------------------------*
    *& Example of sending external email via SAPCONNECT *
    *& *
    *&---------------------------------------------------------------------*

    REPORT ZEMAIL_ATTACH .
    TABLES: ekko.

    PARAMETERS: p_email TYPE somlreci1-receiver
    DEFAULT 'test@sapdev.co.uk'.

    TYPES: BEGIN OF t_ekpo,
    ebeln TYPE ekpo-ebeln,
    ebelp TYPE ekpo-ebelp,
    aedat TYPE ekpo-aedat,
    matnr TYPE ekpo-matnr,
    END OF t_ekpo.
    DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
    wa_ekpo TYPE t_ekpo.

    TYPES: BEGIN OF t_charekpo,
    ebeln(10) TYPE c,
    ebelp(5) TYPE c,
    aedat(8) TYPE c,
    matnr(18) TYPE c,
    END OF t_charekpo.
    DATA: wa_charekpo TYPE t_charekpo.

    DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
    WITH HEADER LINE.
    DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
    WITH HEADER LINE.

    DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
    t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
    t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    w_cnt TYPE i,
    w_sent_all(1) TYPE c,
    w_doc_data LIKE sodocchgi1,
    gd_error TYPE sy-subrc,
    gd_reciever TYPE sy-subrc.


    ************************************************************************
    *START_OF_SELECTION
    START-OF-SELECTION.
    * Retrieve sample data from table ekpo
    PERFORM data_retrieval.

    * Populate table with detaisl to be entered into .xls file
    PERFORM build_xls_data_table.


    ************************************************************************
    *END-OF-SELECTION
    END-OF-SELECTION.
    * Populate message body text
    perform populate_email_message_body.

    * Send file by email as .xls speadsheet
    PERFORM send_file_as_email_attachment
    tables it_message
    it_attach
    using p_email
    'Example .xls documnet attachment'
    'XLS'
    'filename'
    ' '
    ' '
    ' '
    changing gd_error
    gd_reciever.

    * Instructs mail send program for SAPCONNECT to send email(rsconn01)
    PERFORM initiate_mail_execute_program.


    *&---------------------------------------------------------------------*
    *& Form DATA_RETRIEVAL
    *&---------------------------------------------------------------------*
    * Retrieve data form EKPO table and populate itab it_ekko
    *----------------------------------------------------------------------*
    FORM data_retrieval.
    SELECT ebeln ebelp aedat matnr
    UP TO 10 ROWS
    FROM ekpo
    INTO TABLE it_ekpo.
    ENDFORM. " DATA_RETRIEVAL


    *&---------------------------------------------------------------------*
    *& Form BUILD_XLS_DATA_TABLE
    *&---------------------------------------------------------------------*
    * Build data table for .xls document
    *----------------------------------------------------------------------*
    FORM build_xls_data_table.
    CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode
    con_tab TYPE x VALUE '09'. "OK for non Unicode

    *If you have Unicode check active in program attributes thnen you will
    *need to declare constants as follows
    *class cl_abap_char_utilities definition load.
    *constants:
    * con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
    * con_cret type c value cl_abap_char_utilities=>CR_LF.


    CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
    INTO it_attach SEPARATED BY con_tab.
    CONCATENATE con_cret it_attach INTO it_attach.
    APPEND it_attach.

    LOOP AT it_ekpo INTO wa_charekpo.
    CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp
    wa_charekpo-aedat wa_charekpo-matnr
    INTO it_attach SEPARATED BY con_tab.
    CONCATENATE con_cret it_attach INTO it_attach.
    APPEND it_attach.
    ENDLOOP.
    ENDFORM. " BUILD_XLS_DATA_TABLE


    *&---------------------------------------------------------------------*
    *& Form SEND_FILE_AS_EMAIL_ATTACHMENT
    *&---------------------------------------------------------------------*
    * Send email
    *----------------------------------------------------------------------*
    FORM send_file_as_email_attachment tables pit_message
    pit_attach
    using p_email
    p_mtitle
    p_format
    p_filename
    p_attdescription
    p_sender_address
    p_sender_addres_type
    changing p_error
    p_reciever.


    DATA: ld_error TYPE sy-subrc,
    ld_reciever TYPE sy-subrc,
    ld_mtitle LIKE sodocchgi1-obj_descr,
    ld_email LIKE somlreci1-receiver,
    ld_format TYPE so_obj_tp ,
    ld_attdescription TYPE so_obj_nam ,
    ld_attfilename TYPE so_obj_des ,
    ld_sender_address LIKE soextreci1-receiver,
    ld_sender_address_type LIKE soextreci1-adr_typ,
    ld_receiver LIKE sy-subrc.

    ld_email = p_email.
    ld_mtitle = p_mtitle.
    ld_format = p_format.
    ld_attdescription = p_attdescription.
    ld_attfilename = p_filename.
    ld_sender_address = p_sender_address.
    ld_sender_address_type = p_sender_addres_type.


    * Fill the document data.
    w_doc_data-doc_size = 1.

    * Populate the subject/generic message attributes
    w_doc_data-obj_langu = sy-langu.
    w_doc_data-obj_name = 'SAPRPT'.
    w_doc_data-obj_descr = ld_mtitle .
    w_doc_data-sensitivty = 'F'.

    * Fill the document data and get size of attachment
    CLEAR w_doc_data.
    READ TABLE it_attach INDEX w_cnt.
    w_doc_data-doc_size =
    ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
    w_doc_data-obj_langu = sy-langu.
    w_doc_data-obj_name = 'SAPRPT'.
    w_doc_data-obj_descr = ld_mtitle.
    w_doc_data-sensitivty = 'F'.
    CLEAR t_attachment.
    REFRESH t_attachment.
    t_attachment[] = pit_attach[].

    * Describe the body of the message
    CLEAR t_packing_list.
    REFRESH t_packing_list.
    t_packing_list-transf_bin = space.
    t_packing_list-head_start = 1.
    t_packing_list-head_num = 0.
    t_packing_list-body_start = 1.
    DESCRIBE TABLE it_message LINES t_packing_list-body_num.
    t_packing_list-doc_type = 'RAW'.
    APPEND t_packing_list.

    * Create attachment notification
    t_packing_list-transf_bin = 'X'.
    t_packing_list-head_start = 1.
    t_packing_list-head_num = 1.
    t_packing_list-body_start = 1.

    DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
    t_packing_list-doc_type = ld_format.
    t_packing_list-obj_descr = ld_attdescription.
    t_packing_list-obj_name = ld_attfilename.
    t_packing_list-doc_size = t_packing_list-body_num * 255.
    APPEND t_packing_list.

    * Add the recipients email address
    CLEAR t_receivers.
    REFRESH t_receivers.
    t_receivers-receiver = ld_email.
    t_receivers-rec_type = 'U'.
    t_receivers-com_type = 'INT'.
    t_receivers-notif_del = 'X'.
    t_receivers-notif_ndel = 'X'.
    APPEND t_receivers.

    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
    document_data = w_doc_data
    put_in_outbox = 'X'
    sender_address = ld_sender_address
    sender_address_type = ld_sender_address_type
    commit_work = 'X'
    IMPORTING
    sent_to_all = w_sent_all
    TABLES
    packing_list = t_packing_list
    contents_bin = t_attachment
    contents_txt = it_message
    receivers = t_receivers
    EXCEPTIONS
    too_many_receivers = 1
    document_not_sent = 2
    document_type_not_exist = 3
    operation_no_authorization = 4
    parameter_error = 5
    x_error = 6
    enqueue_error = 7
    OTHERS = 8.

    * Populate zerror return code
    ld_error = sy-subrc.

    * Populate zreceiver return code
    LOOP AT t_receivers.
    ld_receiver = t_receivers-retrn_code.
    ENDLOOP.
    ENDFORM.


    *&---------------------------------------------------------------------*
    *& Form INITIATE_MAIL_EXECUTE_PROGRAM
    *&---------------------------------------------------------------------*
    * Instructs mail send program for SAPCONNECT to send email.
    *----------------------------------------------------------------------*
    FORM initiate_mail_execute_program.
    WAIT UP TO 2 SECONDS.
    SUBMIT rsconn01 WITH mode = 'INT'
    WITH output = 'X'
    AND RETURN.
    ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM


    *&---------------------------------------------------------------------*
    *& Form POPULATE_EMAIL_MESSAGE_BODY
    *&---------------------------------------------------------------------*
    * Populate message body text
    *----------------------------------------------------------------------*
    form populate_email_message_body.
    REFRESH it_message.
    it_message = 'Please find attached a list test ekpo records'.
    APPEND it_message.
    endform. " POPULATE_EMAIL_MESSAGE_BODY

    ultraluck 发表于:2008.11.13 04:01 ::分类: ( SAP ABAP ) ::阅读:(321次) :: 评论 (0) :: 引用 (0)

    2008 年 11 月 01日, 星期六

    Make E-mail Sender of PO the PO Creators Name

    Make E-mail Sender of PO the PO Creators Name

    ABAP Code Needed to Make E-mail Sender of PO the PO Creators Name

    1) Do the config and user email data setup as noted elsewhere this is supplemental ABAP help ONLY.

    2) Apply OSS note 561593, this is a release independent note.

    3) on SE37, edit function module RV_MESSAGES_MAINTENANCE, this is custom programming logic.

    Look for this context block:

    context begin
    * Änderung prüfen 
    ------------------------------------------------------
      CLEAR MEX_UPDAT.
      READ TABLE WNAST INDEX 1.
      IF SY-TFILL = 0.
    * emtpy WNAST -> no existing output in the database
        READ TABLE VNAST INDEX 1.
        IF SY-TFILL > 0.
    * filled VNAST -> new output added
          MEX_UPDAT = 'X'.
        ELSE.
          READ TABLE XNAST INDEX 1.
          IF SY-TFILL > 0.
    * filled XNAST -> new output added
            MEX_UPDAT = 'X'.
          ENDIF.
        ENDIF.
      ELSE.
    context end
    insert this logic:
    insert begin
    *if external e-mail get created by name
    *note: vstat=0 means this item has not been sent yet, even if it is a 
    repeat output
    *      nacha=5 means that the medium is 5-external send
      tables: ekko.
      loop at vnast where vstat = 0 and nacha = '5'.
        select single * from ekko into ekko
         where ebeln eq vnast-objky.
        if sy-subrc = 0.
          vnast-usnam = ekko-ernam.
          modify vnast.
        endif.
      endloop.
    insert end 
    context begin
    * non-empty WNAST -> output existed before
        LOOP AT VNAST.
          IF VNAST-UPDAT NE SPACE.
            MEX_UPDAT = 'X'.
            EXIT.
          ENDIF.
          NAST_KEY = VNAST.
          READ TABLE WNAST WITH KEY
            MANDT      =    NAST_KEY-MANDT ...
    context end 
    The PO being sent must use the SMTP communication strategy, a 1 in the Number of Messages field, and the Print immediately box checked on. *-- By DF

    Enhancement for sending mail when the purchase order is releaed

    When we release any object in me29n transaction then mail has to be send to vendor that the puchase order has been
    released. The code that is to be written in the enhacement for the same is:

    *&---------------------------------------------------------------------*
    *&  Include           ZXM06U44
    *&---------------------------------------------------------------------*
    *Data Declaration
    DATA : rel_ind LIKE i_ekko-frgke.
    rel_ind = i_ekko-frgke.
    *Release PO when final authorized person process PO
    IF sy-tcode EQ 'ME29N' AND rel_ind EQ 2.
    
    *Internal table to get vendor name and address number
      DATA : BEGIN OF it_vname OCCURS 0,
             name1 LIKE lfa1-name1,
             adrnr LIKE lfa1-adrnr,
             END OF it_vname.
    *Internal table to get email_if with address number
      DATA : BEGIN OF it_vemail OCCURS 0,
             email LIKE adr6-smtp_addr,
             END OF it_vemail.
    *Emiail subject
      DATA : psubject(40) TYPE c .
    
    *Data declaration for mail FM
      DATA:   it_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
              it_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
              it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
              it_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
              gd_cnt TYPE i,
              gd_sent_all(1) TYPE c,
              gd_doc_data LIKE sodocchgi1,
              gd_error TYPE sy-subrc.
    
    *Internal table for message body
      DATA:   it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                      WITH HEADER LINE,
              it_messagewa LIKE LINE OF it_message        .
    
      psubject = 'PO Regarding'.
    
    *Accessing name and address number of a vendor
      SELECT SINGLE name1 adrnr FROM lfa1 INTO it_vname WHERE lifnr EQ 
    i_ekko-lifnr.
    
    *Accessing mail id of a vendor
      SELECT SINGLE smtp_addr FROM adr6 INTO it_vemail WHERE addrnumber EQ 
    it_vname-adrnr.
    
    * Mail Text
      clear it_message.
      REFRESH it_message.
      CONCATENATE 'Dear' it_vname-name1 ',' INTO it_messagewa SEPARATED BY 
    space.
      APPEND  it_messagewa TO it_message.
      APPEND 'Please issue the items for the following PO Number .' TO 
    it_message.
      CLEAR it_messagewa.
      CONCATENATE 'PO NUmber : ' i_ekko-ebeln  INTO it_messagewa SEPARATED 
    BY space.
      APPEND it_messagewa TO it_message.
      APPEND 'you can view it at www.mindteck/sap/mm/login.' TO it_message.
      APPEND 'Regards,' TO it_message.
      APPEND 'Anand.' TO it_message.
    
    * Fill the document data.
      gd_doc_data-doc_size = 1.
    
    * Populate the subject/generic message attributes
      gd_doc_data-obj_langu = sy-langu.
      gd_doc_data-obj_name  = 'SAPRPT'.
      gd_doc_data-obj_descr = psubject.
      gd_doc_data-sensitivty = 'F'.
    
    * Describe the body of the message
      CLEAR it_packing_list.
      REFRESH it_packing_list.
      it_packing_list-transf_bin = space.
      it_packing_list-head_start = 1.
      it_packing_list-head_num = 0.
      it_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES it_packing_list-body_num.
      it_packing_list-doc_type = 'RAW'.
      APPEND it_packing_list.
    
    * Add the recipients email address
      CLEAR it_receivers.
      REFRESH it_receivers.
      it_receivers-receiver = it_vemail-email.
      it_receivers-rec_type = 'U'.
      it_receivers-com_type = 'INT'.
      it_receivers-notif_del = 'X'.
      it_receivers-notif_ndel = 'X'.
      APPEND it_receivers.
    
    * Call the FM to post the message to SAPMAIL
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data                    = gd_doc_data
          put_in_outbox                    = 'X'
          commit_work                      = 'X'
       IMPORTING
         sent_to_all                      = gd_sent_all
    *   NEW_OBJECT_ID                    =
        TABLES
          packing_list                     = it_packing_list
    *   OBJECT_HEADER                    =
    *   CONTENTS_BIN                     =
          contents_txt                     = it_message
    *   CONTENTS_HEX                     =
    *   OBJECT_PARA                      =
    *   OBJECT_PARB                      =
          receivers                        = it_receivers
       EXCEPTIONS
         too_many_receivers               = 1
         document_not_sent                = 2
         document_type_not_exist          = 3
         operation_no_authorization       = 4
         parameter_error                  = 5
         x_error                          = 6
         enqueue_error                    = 7
         OTHERS                           = 8
                .
      IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    
    * Store function module return code
      gd_error = sy-subrc.
    
    * Get it_receivers return code
      LOOP AT it_receivers.
      ENDLOOP.
    ENDIF.
    This we need to write in the mm06e005. In this enhacement in this enhacement there is a function exit exit_sapmm06e_013 in this I had wrote the code for the same enhacement.
    *-- Praveen Kumar (praveen417@gmail.com)
    ultraluck 发表于:2008.11.01 10:16 ::分类: ( SAP ABAP ) ::阅读:(97次) :: 评论 (0) :: 引用 (0)

    send a mail via sap

    ***********************************************************************
    * Program Name: ztest_mail
    * Title : Send email via sap
    * Author :
    * Create Date :
    * Description : Send email via sap
    ***********************************************************************
    report ztest_mail.

    ************************************************************************
    * DATA
    ************************************************************************
    data:
    gt_mail type zsmm0012_mail occurs 0 with header line,
    objpack like sopcklsti1 occurs 2 with header line,
    objhead like solisti1 occurs 1 with header line,
    objbin like solisti1 occurs 10 with header line,
    objtxt like solisti1 occurs 10 with header line,
    reclist like somlreci1 occurs 5 with header line,
    doc_chng like sodocchgi1,
    tab_lines like sy-tabix,
    otf like itcoo occurs 100 with header line,
    cancel,
    pdf like tline occurs 100 with header line,
    doctab like docs occurs 1 with header line,
    numbytes type i,
    arc_idx like toa_dara,
    pdfspoolid like tsp01-rqident,
    jobname like tbtcjob-jobname,
    jobcount like tbtcjob-jobcount.
    ************************************************************************
    * SELECTION-SCREEN *
    ************************************************************************
    parameters:
    spoolno like tsp01-rqident,
    download as checkbox default ' ',
    p_file like rlgrap-filename default 'C:tempfile.pdf'.

    ************************************************************************
    * START-OF-SELECTION
    ************************************************************************
    start-of-selection.


    clear: doc_chng,objtxt,objtxt[],reclist,reclist[],
    objpack,objpack[].
    doc_chng-obj_name = 'SENDFILE'.
    doc_chng-obj_descr = 'Send External Mail'.
    objtxt+0(40) = 'Price Change Error List'.
    append objtxt.
    clear objtxt.
    objtxt+0(10) = 'Po Number'.
    objtxt+11(5) = 'Item'.
    objtxt+17(9) = 'Pur.Group'.
    objtxt+27(18) = 'Pur.Group.Desc'.
    objtxt+46(8) = 'MRP Ctrl'.
    objtxt+56(18) = 'MRP Ctrl Desc'.
    objtxt+75(60) = 'Error Message'.
    append objtxt.
    clear objtxt.
    * Creation of the document to be sent
    * File Name
    gt_mail-ebeln = '10001'.
    gt_mail-ebelp = 10.
    gt_mail-ekgrp = '99'.
    gt_mail-eknam = 'test 99'.
    gt_mail-dispo = 'zzz'.
    gt_mail-dsnam = 'test zzz'.
    gt_mail-errea = 'Error error'.
    append gt_mail.

    gt_mail-ebeln = '100010000'.
    gt_mail-ebelp = 10.
    gt_mail-ekgrp = '9'.
    gt_mail-eknam = 'test 9'.
    gt_mail-dispo = 'zzz'.
    gt_mail-dsnam = 'test zzz'.
    gt_mail-errea = 'Error error'.
    append gt_mail.


    gt_mail-ebeln = '10001000'.
    gt_mail-ebelp = 10.
    gt_mail-ekgrp = '99'.
    gt_mail-eknam = 'test 99'.
    gt_mail-dispo = 'zzz'.
    gt_mail-dsnam = 'test zzz'.
    gt_mail-errea = 'Error error'.
    append gt_mail.

    gt_mail-ebeln = '100010'.
    gt_mail-ebelp = 10.
    gt_mail-ekgrp = '999'.
    gt_mail-eknam = 'test 999'.
    gt_mail-dispo = 'zzz'.
    gt_mail-dsnam = 'test zzz'.
    gt_mail-errea = 'Error error'.
    append gt_mail.
    loop at gt_mail.

    objtxt+0(10) = gt_mail-ebeln.
    objtxt+11(5) = gt_mail-ebelp.
    objtxt+17(9) = gt_mail-ekgrp.
    objtxt+27(18) = gt_mail-eknam.
    objtxt+46(8) = gt_mail-dispo.
    objtxt+56(18) = gt_mail-dsnam.
    objtxt+75(60) = gt_mail-errea.
    append objtxt.
    clear objtxt.
    endloop.


    * call function 'GUI_DOWNLOAD'
    * exporting
    ** BIN_FILESIZE =
    * filename = 'C:ERROR_LOG.TXT'
    ** FILETYPE = 'ASC'
    ** APPEND = ' '
    ** WRITE_FIELD_SEPARATOR = ' '
    ** HEADER = '00'
    ** TRUNC_TRAILING_BLANKS = ' '
    ** WRITE_LF = 'X'
    ** COL_SELECT = ' '
    ** COL_SELECT_MASK = ' '
    ** DAT_MODE = ' '
    ** CONFIRM_OVERWRITE = ' '
    ** NO_AUTH_CHECK = ' '
    ** CODEPAGE = ' '
    ** IGNORE_CERR = ABAP_TRUE
    ** REPLACEMENT = '#'
    ** WRITE_BOM = ' '
    ** TRUNC_TRAILING_BLANKS_EOL = 'X'
    ** WK1_N_FORMAT = ' '
    ** WK1_N_SIZE = ' '
    ** WK1_T_FORMAT = ' '
    ** WK1_T_SIZE = ' '
    ** WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE
    ** SHOW_TRANSFER_STATUS = ABAP_TRUE
    ** IMPORTING
    ** FILELENGTH =
    * tables
    * data_tab = gt_mail
    ** FIELDNAMES =
    ** EXCEPTIONS
    ** FILE_WRITE_ERROR = 1
    ** NO_BATCH = 2
    ** GUI_REFUSE_FILETRANSFER = 3
    ** INVALID_TYPE = 4
    ** NO_AUTHORITY = 5
    ** UNKNOWN_ERROR = 6
    ** HEADER_NOT_ALLOWED = 7
    ** SEPARATOR_NOT_ALLOWED = 8
    ** FILESIZE_NOT_ALLOWED = 9
    ** HEADER_TOO_LONG = 10
    ** DP_ERROR_CREATE = 11
    ** DP_ERROR_SEND = 12
    ** DP_ERROR_WRITE = 13
    ** UNKNOWN_DP_ERROR = 14
    ** ACCESS_DENIED = 15
    ** DP_OUT_OF_MEMORY = 16
    ** DISK_FULL = 17
    ** DP_TIMEOUT = 18
    ** FILE_NOT_FOUND = 19
    ** DATAPROVIDER_EXCEPTION = 20
    ** CONTROL_FLUSH_ERROR = 21
    ** OTHERS = 22
    * .
    * if sy-subrc <> 0.
    ** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    ** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    * endif.
    *

    describe table objtxt lines tab_lines.
    read table objtxt index tab_lines.
    doc_chng-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).
    * Completing the recipient list
    * reclist-receiver = 'khsu@abeam.com'.
    * reclist-rec_type = 'U'.
    * append reclist.
    reclist-receiver = 'AB_KAOWEN'.
    reclist-rec_type = 'B'.
    append reclist.

    ** Creation of the entry for the compressed document
    * clear objpack-transf_bin.
    * objpack-head_start = 1.
    * objpack-head_num = 0.
    * objpack-body_start = 1.
    * objpack-body_num = tab_lines.
    * objpack-doc_type = 'RAW'.
    * append objpack.

    * Creation of the entry for the compressed attachment
    *OBJPACK-TRANSF_BIN = 'X'.
    OBJPACK-HEAD_START = 1.
    OBJPACK-HEAD_NUM = 1.
    OBJPACK-BODY_START = 1.
    OBJPACK-BODY_NUM = TAB_LINES.
    OBJPACK-DOC_TYPE = 'RAW'.
    OBJPACK-OBJ_NAME = 'ERROR_LOG.TXT'.
    OBJPACK-OBJ_DESCR = 'ERROR LOG'.
    OBJPACK-DOC_SIZE = TAB_LINES * 255.
    APPEND OBJPACK.

    * Sending the document
    call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    exporting
    document_data = doc_chng
    put_in_outbox = 'X'
    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.
    write: / 'Result of the send process:'.
    loop at reclist.
    write: / reclist-receiver(48), ':'.
    if reclist-retrn_code = 0.
    write 'The document was sent'.
    else.
    write 'The document could not be sent'.
    endif.
    endloop.
    when 1.
    write: / 'No authorization for sending to the specified number',
    'of recipients'.
    when 2.
    write: / 'Document could not be sent to any recipient'.
    when 4.
    write: / 'No send authorization'.
    when others.
    write: / 'Error occurred while sending'.
    endcase.


    ultraluck 发表于:2008.11.01 10:04 ::分类: ( SAP ABAP ) ::阅读:(127次) :: 评论 (0) :: 引用 (0)

    Sending mail with attachment

    Sending mail with attachment

    *
    * This program will allowed you to send email with attachment.
    * First, specify the attachment file from your local hardisk and execute.
    * Next, specify the sender email address and click the send button.
    *
    * Written by : SAP Basis, ABAP Programming and Other IMG Stuff
    * http://www.sap-img.com
    *
    report y_cr17_mail.

    data method1 like sy-ucomm.
    data g_user like soudnamei1.
    data g_user_data like soudatai1.
    data g_owner like soud-usrnam.
    data g_receipients like soos1 occurs 0 with header line.
    data g_document like sood4 .
    data g_header like sood2.
    data g_folmam like sofm2.
    data g_objcnt like soli occurs 0 with header line.
    data g_objhead like soli occurs 0 with header line.
    data g_objpara like selc occurs 0 with header line.
    data g_objparb like soop1 occurs 0 with header line.
    data g_attachments like sood5 occurs 0 with header line.
    data g_references like soxrl occurs 0 with header line.

    data g_authority like sofa-usracc.
    data g_ref_document like sood4.
    data g_new_parent like soodk.
    data: begin of g_files occurs 10 ,
    text(4096) type c,
    end of g_files.

    data : fold_number(12) type c,
    fold_yr(2) type c,
    fold_type(3) type c.

    parameters ws_file(4096) type c default 'c:debugger.txt'.
    * Can me any file fromyour pc ....either xls or word or ppt etc ...
    g_user-sapname = sy-uname.
    call function 'SO_USER_READ_API1'
    exporting
    user = g_user
    * PREPARE_FOR_FOLDER_ACCESS = ' '
    importing
    user_data = g_user_data
    * EXCEPTIONS
    * USER_NOT_EXIST = 1
    * PARAMETER_ERROR = 2
    * X_ERROR = 3
    * OTHERS = 4
    .
    if sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.

    fold_type = g_user_data-outboxfol+0(3).
    fold_yr = g_user_data-outboxfol+3(2).
    fold_number = g_user_data-outboxfol+5(12).
    clear g_files.

    refresh : g_objcnt,
    g_objhead,
    g_objpara,
    g_objparb,
    g_receipients,
    g_attachments,
    g_references,
    g_files.

    method1 = 'SAVE'.
    g_document-foltp = fold_type.
    g_document-folyr = fold_yr.
    g_document-folno = fold_number.
    g_document-objtp = g_user_data-object_typ.
    *g_document-OBJYR = '27'.
    *g_document-OBJNO = '000000002365'.
    *g_document-OBJNAM = 'MESSAGE'.
    g_document-objdes = 'sap-img.com testing by program'.
    g_document-folrg = 'O'.
    *g_document-okcode = 'CHNG'.
    g_document-objlen = '0'.
    g_document-file_ext = 'TXT'.

    g_header-objdes = 'sap-img.com testing by program'.
    g_header-file_ext = 'TXT'.

    call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
    exporting
    method = method1
    office_user = sy-uname
    ref_document = g_ref_document
    new_parent = g_new_parent
    importing
    authority = g_authority
    tables
    objcont = g_objcnt
    objhead = g_objhead
    objpara = g_objpara
    objparb = g_objparb
    recipients = g_receipients
    attachments = g_attachments
    references = g_references
    files = g_files
    changing
    document = g_document
    header_data = g_header
    * FOLMEM_DATA =
    * RECEIVE_DATA =
    .

    * File from the pc to send...
    method1 = 'ATTCREATEFROMPC'.

    g_files-text = ws_file.
    append g_files.

    call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
    exporting
    method = method1
    office_user = g_owner
    ref_document = g_ref_document
    new_parent = g_new_parent
    importing
    authority = g_authority
    tables
    objcont = g_objcnt
    objhead = g_objhead
    objpara = g_objpara
    objparb = g_objparb
    recipients = g_receipients
    attachments = g_attachments
    references = g_references
    files = g_files
    changing
    document = g_document
    header_data = g_header
    .

    method1 = 'SEND'.

    g_receipients-recnam = 'MK085'.
    g_receipients-recesc = 'B'.
    g_receipients-sndex = 'X'.
    append g_receipients.

    call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
    exporting
    method = method1
    office_user = g_owner
    ref_document = g_ref_document
    new_parent = g_new_parent
    importing
    authority = g_authority
    tables
    objcont = g_objcnt
    objhead = g_objhead
    objpara = g_objpara
    objparb = g_objparb
    recipients = g_receipients
    attachments = g_attachments
    references = g_references
    files = g_files
    changing
    document = g_document
    header_data = g_header.

    *-- End of Program


    ultraluck 发表于:2008.11.01 10:03 ::分类: ( SAP ABAP ) ::阅读:(77次) :: 评论 (0) :: 引用 (0)

    2008 年 10 月 20日, 星期一

    用BAPI_PO_CHANGE修改(ME23N)PO出貨日期的方法

    用BAPI_PO_CHANGE修改(ME23N)PO出貨日期的方法

    * Call BAPI function

    DATA: lt_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
    lt_poschedule LIKE bapimeposchedule OCCURS 0 WITH HEADER LINE,
    lt_poschedulex LIKE bapimeposchedulx OCCURS 0 WITH HEADER LINE,
    l_line TYPE i,
    l_flag(1),
    l_ebeln LIKE ekko-ebeln,
    l_werks LIKE ekpo-werks.

    LOOP AT it_itab.
    CLEAR: l_line, l_flag.
    lt_poschedule-po_item = it_itab-ebelp.
    lt_poschedule-sched_line = '0001'.
    lt_poschedule-del_datcat_ext = 'D'.
    lt_poschedule-delivery_date = it_itab-eindt.
    APPEND lt_poschedule.
    CLEAR lt_poschedule.
    *上面要轉的參數,在下面都要給'X'值.如po_itemx = 'X'.
    lt_poschedulex-po_item = it_itab-ebelp.
    lt_poschedulex-po_itemx = 'X'.
    lt_poschedulex-sched_line = '0001'.
    lt_poschedulex-sched_linex = 'X'.
    lt_poschedulex-del_datcat_ext = 'X'.
    lt_poschedulex-delivery_date = 'X'.
    APPEND lt_poschedulex.
    CLEAR lt_poschedulex.
    DESCRIBE TABLE lt_poschedule LINES l_line.
    AT END OF ebeln.
    CLEAR l_ebeln.
    l_werks = it_itab-werks.
    l_ebeln = it_itab-ebeln.
    CALL FUNCTION 'BAPI_PO_CHANGE'
    EXPORTING
    *PO NO.
    purchaseorder = it_itab-ebeln
    *TEST RUN
    testrun = p_test
    TABLES
    return = lt_return
    poschedule = lt_poschedule
    poschedulex = lt_poschedulex.
    LOOP AT lt_return.
    IF lt_return-type = 'E' OR lt_return-type = 'A'
    OR ( lt_return-type = 'I' AND lt_return-id = 'VD' ).
    g_text = lt_return-message.
    PERFORM add_error_log USING g_text 'X'.
    l_flag = 'X'.
    ENDIF.
    ENDLOOP.
    IF l_flag = 'X'.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    DELETE it_itab WHERE werks = l_werks AND ebeln = l_ebeln.
    ENDIF.
    IF l_flag = space AND p_test IS INITIAL.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
    wait = 'X'.
    ENDIF.
    CLEAR: lt_poschedule, lt_poschedule[], lt_return, lt_return[],
    lt_poschedulex, lt_poschedulex[].
    ENDAT.
    ENDLOOP.

    SORT it_error BY ebeln ebelp.
    DELETE ADJACENT DUPLICATES FROM it_error.
    DELETE it_itab WHERE flag = 'X'.
    DESCRIBE TABLE it_itab LINES g_success
    ultraluck 发表于:2008.10.20 18:06 ::分类: ( SAP ABAP ) ::阅读:(50次) :: 评论 (0) :: 引用 (0)

    實用且常用的FN:Upload Excel File Into Internal Table

    實用且常用的FN:Upload Excel File Into Internal Table

    调用主體:

    FORM upload_data_to_it_excel .
    CALL FUNCTION 'ZIEB_UPLOAD_EXCEL_INTO_ITAB'
    EXPORTING
    filename = p_path
    i_begin_col = 1
    i_begin_row = 4
    i_end_col = 17
    i_end_row = 30000
    TABLES
    itab = it_excel.

    ENDFORM. " UPLOAD_DATA_TO_IT_EXCEL

    FN中的import項參數

    FILENAME LIKE RLGRAP-FILENAME Local file for upload/download

    I_BEGIN_COL TYPE I

    I_BEGIN_ROW TYPE I

    I_END_COL TYPE I

    I_END_ROW TYPE I

    FN中的TABLES項參數

    ITAB

    FN的Source code如下:

    FUNCTION ZIEB_UPLOAD_EXCEL_INTO_ITAB .
    *"----------------------------------------------------------------------
    *"*"Local Interface:
    *" IMPORTING
    *" REFERENCE(FILENAME) LIKE RLGRAP-FILENAME
    *" REFERENCE(I_BEGIN_COL) TYPE I
    *" REFERENCE(I_BEGIN_ROW) TYPE I
    *" REFERENCE(I_END_COL) TYPE I
    *" REFERENCE(I_END_ROW) TYPE I
    *" TABLES
    *" ITAB
    *"----------------------------------------------------------------------
    DATA : T_INTERN LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
    DATA : L_TABIX LIKE SY-TABIX.
    DATA : L_BEGCOL TYPE I,
    L_BEGROW TYPE I,
    L_ENDCOL TYPE I,
    L_ENDROW TYPE I,
    L_PATH LIKE RLGRAP-FILENAME.

    MOVE : I_BEGIN_COL TO L_BEGCOL,
    I_BEGIN_ROW TO L_BEGROW,
    I_END_COL TO L_ENDCOL,
    I_END_ROW TO L_ENDROW,
    FILENAME TO L_PATH.

    FIELD-SYMBOLS : <FIELD> TYPE ANY.

    ** upload excel file by standard function
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
    FILENAME = L_PATH
    I_BEGIN_COL = L_BEGCOL
    I_BEGIN_ROW = L_BEGROW
    I_END_COL = L_ENDCOL
    I_END_ROW = L_ENDROW
    TABLES
    INTERN = T_INTERN
    EXCEPTIONS
    INCONSISTENT_PARAMETERS = 1
    UPLOAD_OLE = 2
    OTHERS = 3.
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    ** 刪除第一筆
    DELETE T_INTERN WHERE ROW = 1.

    ** standard function output internal table convert to...
    ** get the same row of value into one row split by 'TAB'
    REFRESH : ITAB.
    SORT T_INTERN BY ROW COL.
    LOOP AT T_INTERN.
    AT NEW ROW.
    L_TABIX = SY-TABIX.
    CLEAR : ITAB.
    ENDAT.

    AT END OF ROW.
    DO.
    ASSIGN COMPONENT SY-INDEX OF STRUCTURE ITAB TO <FIELD>.
    IF SY-SUBRC = 0.
    READ TABLE T_INTERN INDEX L_TABIX.
    IF SY-SUBRC = 0 AND T_INTERN-COL = SY-INDEX.
    <FIELD> = T_INTERN-VALUE.
    ADD 1 TO L_TABIX.
    ENDIF.
    ELSE.
    EXIT.
    ENDIF.
    ENDDO.

    APPEND ITAB.
    ENDAT.
    ENDLOOP.
    ENDFUNCTION.


    ultraluck 发表于:2008.10.20 16:09 ::分类: ( SAP ABAP ) ::阅读:(58次) :: 评论 (0) :: 引用 (0)

    不用SE11建Structure传Internal Table到Smartforms的方法

    不用SE11建Structure传Internal Table到Smartforms的方法

    nterface 里定义参数的时候不是刚才定义的结构,激活的时候会报错。

    例如:在程式中定義一個Internal table

    *** Internal table for item
    DATA: BEGIN OF it_item OCCURS 0,
    ebeln LIKE zpudnrlma0001-ebeln,
    ebelp LIKE zpudnrlma0001-ebelp,
    matnr LIKE ekpo-matnr,
    maktx LIKE makt-maktx,
    menge LIKE ekpo-menge,
    meins LIKE ekpo-meins,
    lgort LIKE ekpo-lgort,
    lgpbe LIKE mard-lgpbe,
    werks LIKE ekpo-werks,
    labst LIKE mard-labst,
    END OF it_item.

    轉data到smartforms

    CALL FUNCTION func_module_name
    EXPORTING
    control_parameters = control_parameters
    wa_header = wa_header
    it_item = it_item[]
    IMPORTING
    document_output_info = l_ssfcrespd
    EXCEPTIONS
    user_canceled = 4.

    到smartforms定義Internal table
    path: global settings->global definitions->types

    *** Internal table for item
    TYPES: BEGIN OF st_item,
    ebeln LIKE zpudnrlma0001-ebeln,
    ebelp LIKE zpudnrlma0001-ebelp,
    matnr LIKE ekpo-matnr,
    maktx LIKE makt-maktx,
    menge LIKE ekpo-menge,
    meins LIKE ekpo-meins,
    lgort LIKE ekpo-lgort,
    lgpbe LIKE mard-lgpbe,
    werks LIKE ekpo-werks,
    labst LIKE mard-labst,
    END OF st_item.

    TYPES: tt_item TYPE STANDARD TABLE OF st_item.

    然後在定義smartforms的Internal table
    path: global settings->form interface->import

    IT_ITEM TYPE TT_ITEM

    輸出時用& IT_ITEM-ebeln&就可以了.


    ultraluck 发表于:2008.10.20 16:05 ::分类: ( SAP ABAP ) ::阅读:(34次) :: 评论 (0) :: 引用 (0)

    访问Domain的Value Range有两种方法:

    访问Domain的Value Range有两种方法:

    1、直接访问表
    dd07l和dd07T
    select * from dd07l
    where domname = 'domname' and
    as4local = active.

    2、使用SAP的标准函数
    call function 'DD_DOMVALUES_GET'
    exporting
    domname = p_domname
    importing
    rc = l_subrc
    tables
    dd07v_tab = l_dd07v
    exceptions
    wrong_textflag = 1
    others = 2.

    3、使用SAP的标准函数

    PERFORM get_domain TABLES it_beskz USING 'BESKZ'.

    CALL FUNCTION 'DDIF_DOMA_GET'
    EXPORTING
    name = p_value
    state = 'A'
    langu = sy-langu
    TABLES
    dd07v_tab = lt_dd07v
    EXCEPTIONS
    illegal_input = 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.

    CLEAR p_desc.
    READ TABLE it_beskz WITH KEY domvalue_l = p_beskz.
    IF sy-subrc = 0.
    p_desc = it_beskz-ddtext.
    ENDIF.


    ultraluck 发表于:2008.10.20 16:01 ::分类: ( SAP ABAP ) ::阅读:(26次) :: 评论 (0) :: 引用 (0)

    众多BOM组件一次性导出系统的处理

    众多BOM组件一次性导出系统的处理


    由于工作需要现需要将导入系统的所有BOM组件导出系统进行核对,但是由于组件数据量太多不能
    成功导出,会因为时间过长造成处理错误.另外EXCEL表格最大容量为65536,在处理导出的数据时也
    存在不能正常打开文件的情况,请问各仁兄有何高见解决这两个问题.
    可以写段调用 BAPI 的 VB 程序,把 BOM 读到任何数据库里去。
    You can develop one simple program to finish this task, in this program, you should
    use BOM explore function (or logical table) to store components of BOM to internal
    table, and use download function to save content of internal table to local file
    (txt format), open this local file use other tools, e.g. Microsoft Access, in
    access, you can import your original BOM and create new query to compare them.
    我有一段导出程序,如果你有开发权限可以用一下。
    REPORT ZPPBOMDOWN NO STANDARD PAGE HEADING line-size 213 line-count 65.
    TABLEs: MAST,STKO,STpo,STAS,MAKT,zusr03.
    data: begin of imast occurs 0,
    matnr like mast-matnr,
    maktx like makt-maktx,
    stlnr like mast-stlnr,
    stlal like mast-stlal,
    stlan like mast-stlan,
    end of imast.
    data: begin of istko occurs 0,
    stlnr like stko-stlnr,
    stlty like stko-stlty,
    stlal like stko-stlal,
    bmeng like stko-bmeng,
    bmein like stko-bmein,
    datuv like stko-datuv,
    end of istko.
    data: begin of istas occurs 0,
    stlnr like stas-stlnr,
    stlty like stas-stlty,
    stlal like stas-stlal,
    stlkn like stas-stlkn,
    end of istas.
    data: begin of istpo occurs 0,
    stlnr like stpo-stlnr,
    menge like stpo-menge,
    meins like stpo-meins,
    idnrk like stpo-idnrk,
    maktx like makt-maktx,
    stlkn like stpo-stlkn,
    ausch like stpo-ausch,
    posnr like stpo-posnr,
    stlty like stpo-stlty,
    end of istpo.
    SELECTION-SCREEN: BEGIN OF BLOCK INPUT.
    PARAMETERS: IWERKS LIKE MAST-WERKS OBLIGATORY.
    SELECT-OPTIONS: IMATNR FOR MAST-MATNR.
    PARAMETERS: ISTLAN LIKE MAST-STLAN OBLIGATORY.
    SELECTION-SCREEN: END OF BLOCK INPUT.

    AT SELECTION-SCREEN ON BLOCK input.
    INCLUDE ZSDIAUTH.
    CALL FUNCTION 'Z_PP_AUTH_CHECK'
    EXPORTING
    WERKS = IWERKS
    tables
    zwerks = duozhi.

    top-of-page.
    write:/02 '工厂:',iwerks.
    write: 80 '*********************'.
    write: 180 '列印日期:',sy-datum.
    write:/02 'BOM用途:',istlan.
    write: 80 '* BOM资料下载明细表 *'.
    select single * from zusr03 where bname = sy-uname.
    write: 180 '列印者:',zusr03-name1+0(10).
    if imatnr-low <> ' '.
    write:/02 '物料号码:',imatnr-low.
    if imatnr-high <> ' '.
    write: '-',imatnr-high.
    endif.
    else.
    write:/02 '物料号码:'.
    endif.
    write: 80 '*********************'.
    write: 180 '页数:',sy-pagno.
    uline.
    write:/00 'BOM表头物料',19 'BOM表头物料名称',60 '组件数量',
    79 '单位',83 'BOM组件料号',102 'BOM组件名称',
    143 '部件废品(%)',154 '项目',159 'BOM套数',166 '表头基本数量',
    184 '表头单位',192 '有效期始于',203 'BOM用途'.
    uline.

    START-OF-SELECTION.
    SELECT * FROM MAST WHERE WERKS = IWERKS
    AND MATNR IN IMATNR
    AND STLAN = ISTLAN.
    IMAST-MATNR = MAST-MATNR.
    SELECT SINGLE * FROM MAKT WHERE MATNR = MAST-MATNR.
    IF SY-SUBRC = 0.
    IMAST-MAKTX = MAKT-MAKTX.
    ENDIF.
    IMAST-STLNR = MAST-STLNR.
    IMAST-STLAL = MAST-STLAL.
    imast-stlan = mast-stlan.
    APPEND IMAST.
    CLEAR IMAST.
    endselect.
    LOOP AT IMAST.
    SELECT SINGLE * FROM STKO WHERE STLNR = IMAST-STLNR
    AND STLAL = IMAST-STLAL
    AND LOEKZ NE 'X'.
    ISTKO-STLNR = STKO-STLNR.
    ISTKO-STLTY = STKO-STLTY.
    ISTKO-STLAL = STKO-STLAL.
    istko-datuv = stko-datuv.
    istko-bmeng = stko-bmeng.
    istko-bmein = stko-bmein.
    APPEND ISTKO.
    CLEAR ISTKO.
    * ENDSELECT.
    ENDLOOP.
    LOOP AT ISTKO.
    SELECT * FROM STAS WHERE STLNR = ISTKO-STLNR
    AND STLTY = ISTKO-STLTY
    AND STLAL = ISTKO-STLAL.
    ISTAS-STLNR = STAS-STLNR.
    ISTAS-STlTY = STAS-STlTY.
    ISTAS-STLKN = STAS-STLKN.
    istas-stlal = stas-stlal.
    APPEND ISTAS.
    CLEAR ISTAS.
    ENDSELECT.
    ENDLOOP.
    LOOP AT ISTAS.
    SELECT * FROM STPO WHERE STLNR = ISTAS-STLNR
    AND STLTY = ISTAS-STlTY
    AND STLKN = ISTAS-STLKN.
    istpo-stlnr = stpo-stlnr.
    istpo-menge = stpo-menge.
    istpo-meins = stpo-meins.
    istpo-stlkn = stpo-stlkn.
    istpo-idnrk = stpo-idnrk.
    select single * from makt where matnr = stpo-idnrk.
    if sy-subrc = 0.
    istpo-maktx = makt-maktx.
    endif.
    istpo-ausch = stpo-ausch.
    istpo-posnr = stpo-posnr.
    istpo-stlty = stpo-stlty.
    append istpo.
    clear istpo.
    ENDSELECT.
    ENDLOOP.
    loop at imast.
    loop at istko where stlnr = imast-stlnr
    and stlal = imast-stlal.
    * and loekz <> 'X'.
    write:/00 imast-matnr,
    19 imast-maktx,
    159 istko-stlal,
    166 istko-bmeng,
    184 istko-bmein,
    192 istko-datuv,
    203 imast-stlan.
    loop at istas where stlnr = istko-stlnr
    and stlal = istko-stlal
    and stlty = istko-stlty.
    loop at istpo where stlnr = istas-stlnr
    and stlkn = istas-stlkn
    and stlty = istas-stlty.
    write:/60 istpo-menge,79 istpo-meins,83 istpo-idnrk,
    102 istpo-maktx,143 istpo-ausch,
    154 istpo-posnr.
    endloop.
    endloop.
    endloop.
    uline.
    endloop.

    系统报没有:ZSDIAUTH
    那一部分是我们自己的权限检查,你把它‘*’掉就可以了 查看全文
    ultraluck 发表于:2008.10.20 15:58 ::分类: ( SAP ABAP ) ::阅读:(89次) :: 评论 (0) :: 引用 (0)

    用BAPI_MATERIAL_SAVEDATA对MRP Controller(MM01的MRP1视图中)作change的方法

    FORM change_mpr_controller .
    DATA: st_headdata LIKE bapimathead ,
    st_plantdata LIKE bapi_marc ,
    st_plantdatax LIKE bapi_marcx ,
    st_return LIKE bapiret2 .

    LOOP AT it_tab.
    CLEAR: st_headdata, st_plantdata, st_plantdatax, st_return.
    st_headdata-material = it_tab-matnr .
    st_headdata-mrp_view = 'X' .

    st_plantdata-plant = it_tab-werks .
    st_plantdata-mrp_ctrler = it_tab-new .

    st_plantdatax-plant = it_tab-werks .
    st_plantdatax-mrp_ctrler = 'X' .

    * Call Function to change the MRP Controller.
    CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
    EXPORTING
    headdata = st_headdata
    plantdata = st_plantdata
    plantdatax = st_plantdatax
    IMPORTING
    return = st_return.

    IF st_return-type = 'E' OR st_return-type = 'A'.
    CLEAR it_err.
    MOVE-CORRESPONDING it_tab TO it_err .
    it_err-errmg = st_return-message .
    APPEND it_err.
    CLEAR it_err.
    DELETE it_tab INDEX sy-index.

    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

    ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
    wait = '1'.
    ENDIF.
    ENDLOOP.

    ENDFORM. " change_mpr_controller


    ultraluck 发表于:2008.10.20 15:55 ::分类: ( SAP ABAP ) ::阅读:(41次) :: 评论 (0) :: 引用 (0)

    2008 年 08 月 18日, 星期一

    ABAP/4中参数的传递[转]

    在ABAP/4中参数的传递可分成 1. Call By Reference:
    传参数时将资料的存放地址(address)传至参数中, 也就是子程序中的参数变量与外部实际
    变量共享地址内的值, 又称为 Call By Address, 若在子程序中地址中的值改变了, 外部实
    际变量的值也会跟着改变.
    语法:
    FORM <subr> [USING <f1> <f2>…] [CHANGING <f1>…]
    PERFORM <subr> [USING <f1> <f2>…] [CHANGING <f1>…]
    Using 之后接在子程序中不会改变的变量, CHANGING接会改变值的变量
    但实际上USING之后的参数在子程序中也可将值改变
    Example:
    SUM = 0.
    NUM1 = 100. NUM2=200.
    PERFORM ADD USING NUM1 NUM2 CHANGING SUM.
    WRITE: / NUM1,NUM2,SUM “ SUM 由 0 变成 300
    FORM ADD USING NUM1 NUM2 CHANGING SUM.
    SUM = NUM1 + NUM2.
    ENDFORM.
    执行结果:
    100 200 300

    2. Call By Value
    传参数时将数据的值复制一份至另一地址中, 所以在子程序中参数变量值改变, 并不会影
    响外部实际变量的值.
    语法:
    FORM <subr> USING VALUE(<f1>…)
    使用 VALUE(<f1>)表示 <f1>是 Call By Value的传递
    PERFORM <subr> USING <f1>
    Example:
    SUM = 0.
    NUM1 = 5.
    PERFORM MULTI USING NUM1 CHANGING SUM.
    WRITE: / NUM1,SUM “NUM1值还是5, SUM 由 0 变成 120
    FORM MULTI USING VALUE(NUM1) CHANGING SUM.
    SUM = 1.
    WHILE NUM1 > 1
    SUM = SUM * NUM1.
    NUM1 = NUM1 – 1.
    ENDWHILE..
    ENDFORM.
    执行结果:
    5 120

    3. Call By Value and Return Result
    传入参数值的方式同Call By Value, 但在子程序结束执行时会将传入的参数值复制
    一份传回给外部实际变量.
    语法:
    FORM ….. CHANGING VALUE(<f1>)
    PERFORM …. CHANGING …. <f1>
    Example:
    SUM = 0.
    NUM1 = 100. NUM2=200.
    PERFORM ADD USING NUM1 NUM2 CHANGING SUM.
    WRITE: / NUM1,NUM2,SUM “ SUM 由 0 变成 300
    FORM ADD USING NUM1 NUM2 CHANGING VALUE(S).
    S = NUM1 + NUM2.
    WRITE: / NUM1,NUM2,SUM “得到结果为 100 200 0
    ENDFORM.
    执行结果:
    100 200 0 “在子程序中 SUM值尚未改变
    100 200 300 “返回程序时, 将变量 S的值复制给 SUM
    “所以 SUM值变成 300
    ultraluck 发表于:2008.08.18 12:02 ::分类: ( SAP ABAP ) ::阅读:(45次) :: 评论 (0) :: 引用 (0)

    2008 年 07 月 22日, 星期二

    IDOC 创建,增强,管理,配置

    创建IDOC:
    第一步:WE31 创建IDOC所包含的字段.
    第二步:WE30 创建IDOC 把Segment分配给IDOC
    第三步:WE81 创建信息类型
    第四步:WE82 把IDOC类型与信息类型对应.
    第五步:WE57 Assign Message & Idoc Type to a Function Module for Data Process
    第六步:SM59 Define a RFC connection for Idoc transfer
    第七步:WE21 Define a Port ( Assign a RFC destination which created in SM59 )
    第八步:WE41/42 Creat Process Code
    第九步:WE20 Define a Partner Profiles( Also creat a Outbound parameters with Port, or Inbound parameters with Process code )
    管理IDOC:
    WE02 显示IDOC,可以根据时间,IDOC类型查找IDOC,查看成功,出错信息。
    WE46 IDOC管理(出入)
    WE60 IDOC类型文档(可以查看IDOC结构,和每个字段的描述.
    WE19 根据IDOC号进行IDOC处理,可以修改IDOC值进行补发动作,处理分为内向和外向。
    消息配置:
    WE20 配置伙伴消息进和出IDOC类型
    WE21 配置伙伴,
    ultraluck 发表于:2008.07.22 19:39 ::分类: ( SAP ABAP ) ::阅读:(48次) :: 评论 (0) :: 引用 (0)

    2008 年 06 月 12日, 星期四

    BOM展开和反查函数[转]

    BOM展开和反查函数

    CSS4 BOM 展开
    CS_BOM_EXPLOSION_MAT BOM explosion (old version); as of 3.0, use CS_BOM_EXPL_MAT_V2
    CS_BOM_EXPL_MAT_V2 BOM explosion for material

    CSS5 BOMs: 反查清单
    CS_WHERE_USED_MAT Bills of material; where-used list
    CS_WHERE_USED_MAT_ANY Bills of material; where-used list as material or class item
    CS_WHERE_USED_MAT_VIA_CLA Bills of material; where-used list via classes
    -------------------------------------------------------------
    三个方法:
    1.CS15
    2.FM:CS_WHERE_USED_MAT
    3.根据表:STAS和STPO
    第三个方法弄不好效率会比较差
    --------------------------------------------------------------

    知不知道反查BOM的函数?就是输入项为IDNRK,得出MATNR。反查BOM的函数我这有一个,CALL FUNCTION 'CS_WHERE_USED_MAT' 大概是反查激活的,不知未激活的可不可以查?
    写个原型: CALL FUNCTION 'CS_WHERE_USED_MAT'
    EXPORTING
    DATUB = PM_DATUB
    DATUV = PM_DATUV
    MATNR = ITAB1-MATNR
    * POSTP = pm_postp
    * RETCODE_ONLY = ' '
    STLAN = PM_STLAN
    WERKS = ITAB1-WERKS
    MCLMT = '00000000'
    MNSTL = ''
    MXSTL = ''
    STLTP = ''
    NEWSI = ''
    IMPORTING
    TOPMAT = SELPOOL
    TABLES
    WULTB = LTB
    EQUICAT = EQUICAT "YHG110068
    KNDCAT = KNDCAT "YHG110068
    MATCAT = MATCAT "YHG110068
    STDCAT = STDCAT "YHG110068
    TPLCAT = TPLCAT "YHG110068
    EXCEPTIONS
    CALL_INVALID = 1
    MATERIAL_NOT_FOUND = 2
    NO_WHERE_USED_REC_FOUND = 3
    NO_WHERE_USED_REC_SELECTED = 4
    NO_WHERE_USED_REC_VALID = 5
    CX_SY_DYN_CALL_ILLEGAL_TYPE = 6
    OTHERS = 7.
    反查激活的BOM.反查未激活的怎么处理?

     查看全文
    ultraluck 发表于:2008.06.12 11:41 ::分类: ( SAP ABAP ) ::阅读:(141次) :: Permanent link :: 引用 (0)

    2008 年 06 月 10日, 星期二

    修改sap 系统的搜索帮助

    客户提出一个需求,修改as03查找资产号,按存货号查询多加入一个搜索参数资产冻结日,原来有七个。调试as03发现,调用动态屏幕号来找一些类似标签页的东东。函数是:DD_SHLP_CALL_FROM_DYNP

    输入参数:
    HELP_INFOS:

    CALL T
    OBJECT F
    PROGRAM SAPLAPFS
    DYNPRO 0100
    TABNAME ANLA
    FIELDNAME ANLN1
    FIELDTYPE CHAR
    KEYWORD 资产
    FIELDLNG 12
    FLDVALUE EMND4322
    MCOBJ
    SPRAS Z
    MENUFUNCT HC
    MESSAGEID
    MESSAGENR
    MESSAGE
    TITLE 显示资产: 初始屏幕
    DYNPROFLD ANLA-ANLN1
    DYNPROFLAG
    CHECKTABLE ANLH
    CHECKFIELD ANLN1
    VALEXIST
    TCODE AS03
    PFKEY NEU_FIRST
    DOCUKEY
    REPORT
    DOCUID FE
    DOCUOBJECT
    HEADERTEXT
    F1SYSHEL
    MSGV1
    MSGV2
    MSGV3
    MSGV4
    SHOW N
    POV 4
    CUROW 22
    CUCOL 0
    SY_DYN
    DYNPPROG SAPLAIST
    STEPL 0
    SELECTART F
    输入参数:DYNPSELECT
    FLDNAME FLDINH
    MANDT
    BUKRS ABSC
    ANLN1
    输出我们要的选择屏幕
    你要加的字段在搜锁帮助AANLA中
    而这个帮助的字段在视图M_AANLA中
    视图:M_AANLA包括字段:
    MANDT CLNT 3 集团
    BUKRS CHAR 4 公司代码
    ANLKL CHAR 8 资产分类
    MCOA1 CHAR 30 匹配码搜索的搜索条件
    KTOGR CHAR 8 科目定位码
    AKTIV DATS 8 资产资本化日期
    ANLN1 CHAR 12 主资产号
    ANLN2 CHAR 4 资产次级编号
    在这个视图中增加一个字段,
    DEAKT
    需要修改这个标准的视图,我没有对象权限参数需要在sap官方网站注册,才能实现

    ultraluck 发表于:2008.06.10 11:41 ::分类: ( SAP ABAP ) ::阅读:(55次) :: Permanent link :: 引用 (0)

    2008 年 05 月 21日, 星期三

    ABAP--使用SLIN事务码进行ABAP程序扩展语法检查,提高程序开发的质量[转]

    TCODE: SLIN

    或者在SE38 界面的菜单: 程序-》语法-》扩展程序检查

    就会弹出下面的界面,用户可以根据自己的需求设置检查点,并根据检查结果修改程序,使自己的代码更加可靠。另外在SE38 界面的菜单: 程序-》语法-》Code Inspector 提供了从另外的一些角度来检查程序的合理性。


    ultraluck 发表于:2008.05.21 17:21 ::分类: ( SAP ABAP ) ::阅读:(54次) :: Permanent link :: 引用 (0)

    2008 年 05 月 14日, 星期三

    金额的阿拉伯数据转汉字的函数![转]

    FUNCTION zfi_convert_to_capitalization.
    *"----------------------------------------------------------------------
    *"*"Local interface:
    *" IMPORTING
    *" REFERENCE(P_AMOUNT) TYPE WERTV8
    *" EXPORTING
    *" REFERENCE(P_CAPITALIZATION) TYPE STRING
    *"----------------------------------------------------------------------
    DATA:
    v_s00(2) VALUE '零',
    v_s01(2) VALUE '壹',
    v_s02(2) VALUE '贰',
    v_s03(2) VALUE '叁',
    v_s04(2) VALUE '肆',
    v_s05(2) VALUE '伍',
    v_s06(2) VALUE '陆',
    v_s07(2) VALUE '柒',
    v_s08(2) VALUE '捌',
    v_s09(2) VALUE '玖',
    v_w00(2) VALUE '',
    v_w01(2) VALUE '拾',
    v_w02(2) VALUE '佰',
    v_w03(2) VALUE '仟',
    v_w04(2) VALUE '万',
    v_w05(4) VALUE '拾万',
    v_w06(4) VALUE '佰万',
    v_w07(4) VALUE '仟万',
    v_w08(2) VALUE '亿',
    v_w09(4) VALUE '拾亿',
    v_w10(4) VALUE '佰亿',
    v_w11(4) VALUE '仟亿',
    v_w12(4) VALUE '万亿',
    v_sy(2) VALUE '元',
    v_sj(2) VALUE '角',
    v_sf(2) VALUE '分',
    v_amount(16),"将金额转换成字符型
    v_len TYPE i,"v_amount或p_capitalization的长度
    v_var(5),"v_s0,v_s1,...,v_w0,v_w1,...
    v_num(2) TYPE n,"每一位的数值
    v_s_num(2),"v_s0,v_s1,...中的值
    v_weight(2) TYPE n,"权数
    v_w_num(4),"v_w0,v_w1,...中的值
    v_flag0 TYPE i VALUE 1,"是否输出'零',0不输出,1输出
    v_n TYPE i VALUE 0.
    v_amount = p_amount.
    SHIFT v_amount LEFT DELETING LEADING space.
    SHIFT v_amount LEFT DELETING LEADING '0'.
    *-计算分-----------------------------------------
    v_len = strlen( v_amount ).
    v_len = v_len - 1.
    v_num = v_amount+v_len(1).
    IF v_num <> '0'.
    CONCATENATE 'v_s' v_num INTO v_var.
    WRITE (v_var) TO v_s_num.
    CONCATENATE v_s_num v_sf p_capitalization INTO p_capitalization.
    ENDIF.
    *-计算角-----------------------------------------
    v_len = strlen( v_amount ).
    v_len = v_len - 2.
    v_num = v_amount+v_len(1).
    IF v_num <> '0'.
    CONCATENATE 'v_s' v_num INTO v_var.
    WRITE (v_var) TO v_s_num.
    CONCATENATE v_s_num v_sj p_capitalization INTO p_capitalization.
    ENDIF.
    *-输出‘整’字-------------------------------------
    IF p_capitalization = ' '.
    CONCATENATE '整' p_capitalization INTO p_capitalization.
    ENDIF.
    *-计算整数---------------------------------------
    v_len = strlen( v_amount ).
    v_len = v_len - 3.
    if v_len = 0.
    exit.
    endif.
    v_amount = v_amount(v_len)." 整数部分
    *-输出‘元’字-------------------------------------
    CONCATENATE v_sy p_capitalization INTO p_capitalization.
    v_n = v_len - 1.
    v_weight = 0.
    DO v_len TIMES.
    * 从个位开始
    v_num = v_amount+v_n(1).
    IF v_num <> '0'.
    CONCATENATE 'v_s' v_num INTO v_var.
    WRITE (v_var) TO v_s_num.
    CONCATENATE 'v_w' v_weight INTO v_var.
    WRITE (v_var) TO v_w_num.
    CONCATENATE v_s_num v_w_num p_capitalization INTO p_capitalization.
    v_flag0 = 1.
    ELSE.
    IF v_flag0 = 1.
    CONCATENATE 'v_s' v_num INTO v_var.
    WRITE (v_var) TO v_s_num.
    CONCATENATE v_s_num p_capitalization INTO p_capitalization.
    v_flag0 = 0.
    ENDIF.
    ENDIF.
    v_weight = v_weight + 1.
    v_n = v_n - 1.
    ENDDO.
    *-删除个位可能出现'零'的情况-----------------
    SEARCH p_capitalization FOR '元'.
    IF sy-subrc = 0.
    v_n = sy-fdpos - 2.
    IF p_capitalization+v_n(2) = v_s00.
    v_len = strlen( p_capitalization ).
    CONCATENATE p_capitalization(v_n) p_capitalization+sy-fdpos INTO p_capitalization.
    ENDIF.
    ENDIF.
    ENDFUNCTION.

    ultraluck 发表于:2008.05.14 10:44 ::分类: ( SAP ABAP ) ::阅读:(5349次) :: Permanent link :: 引用 (0)

    2008 年 04 月 16日, 星期三

    ABAP-报表的事件

    > >

    一, 首先介绍一下ABAP的程序的类型:

    Program type(程序类型)

    Introductory statement(类型描述)

    1

    REPORT(报表)

    M

    PROGRAM(屏幕程序)

    F

    FUNCTION-POOL(函数组)

    K

    CLASS-POOL(类组)

    J

    CLASS-POOL(接口组)

    T

    TYPE-POOL(类型池)

    二, 下面介绍报表中用到的事件以及作用:

    1. LOAD-OF-PROGRAM:程序开始执行时候自动调用

    这个事件在SUBMITCALL TRANSACTIONPERFORM等执行的时候系统会自动调用这个事件。所以无需声明即可。

    2. INITIALIZATION

    1.只能用于报表程序

    2.在选择屏幕出现之前执行,如果用逻辑数据库的话,这个是唯一能够修改选择屏幕初始值的地方。

    3.通常的用法是在这里给选择屏幕中的字段赋值。

    3. AT SELECTION-SCREEN

    1.其实就像一个FORM,所以在这个事件里声明的变量都是局部变量。

    2.根据SY-UCOMM这个系统变量可以判断用户的命令

    3.在这个事件里响应的是屏幕上选择条件中的事件,例如CHECKBOX的选择与否,RADIOBUTTON的选择,LISTBOX的选择等等。所以分为以下几个方面:

    1. ... ON psel :在PARAMETER变化是触发的事件

    2. ... ON END OF sel SELECT-OPTION触发的事件

    3. ... ON VALUE-REQUEST FOR psel_low_high :选择的帮助(F4)

    4. ... ON HELP-REQUEST FOR psel_low_high :选择的帮助(F1)

    5. ... ON RADIOBUTTON GROUP radi :单选按钮事件

    6. ... ON BLOCK block :框架的触发事件

    7. ... OUTPUT :响应屏幕上的事件,修改选择屏幕的唯一方法

    4. START-OF-SELECTION

    报表程序必须执行的事件,在进入第二屏幕之前触发。

    5. GET

    获得逻辑数据库的值。前提是必须首先声明逻辑数据库。

    6. END-OF-SELECTION

    第二屏幕显示完毕,结束处理。

    7. MODULE

    这个是当你调用自己定义的屏幕时,响应屏幕事件的方法。

    8. ENDMODULE

    9. CHECK

    只对逻辑数据库使用,检查是否取得数据。

    10. REJECT

    同样只对逻辑数据库使用,退出。

    11. STOP

    结束一个处理块。

    12. RETURN

    返回一个处理块。

    三, 附加说明:

    1. SET PF-STATUS

    基本语法格式:SET PF-STATUS pfstat.

    扩展:

    1. ... EXCLUDING f oder ... EXCLUDING itab

    2. ... IMMEDIATELY

    3. ... OF PROGRAM progname

    这个是设置屏幕菜单,命令行等的命令,详细地信息我会在后面关于菜单设计的时候说明。

    2. SET TITLEBAR

    设置屏幕标题,在屏幕显示之前调用。


    ultraluck 发表于:2008.04.16 17:06 ::分类: ( SAP ABAP ) ::阅读:(52次) :: Permanent link :: 引用 (0)

    ABAP-报表的事件

    > >

    一, 首先介绍一下ABAP的程序的类型:

    Program type(程序类型)

    Introductory statement(类型描述)

    1

    REPORT(报表)

    M

    PROGRAM(屏幕程序)

    F

    FUNCTION-POOL(函数组)

    K

    CLASS-POOL(类组)

    J

    CLASS-POOL(接口组)

    T

    TYPE-POOL(类型池)

    二, 下面介绍报表中用到的事件以及作用:

    1. LOAD-OF-PROGRAM:程序开始执行时候自动调用

    这个事件在SUBMITCALL TRANSACTIONPERFORM等执行的时候系统会自动调用这个事件。所以无需声明即可。

    2. INITIALIZATION

    1.只能用于报表程序

    2.在选择屏幕出现之前执行,如果用逻辑数据库的话,这个是唯一能够修改选择屏幕初始值的地方。

    3.通常的用法是在这里给选择屏幕中的字段赋值。

    3. AT SELECTION-SCREEN

    1.其实就像一个FORM,所以在这个事件里声明的变量都是局部变量。

    2.根据SY-UCOMM这个系统变量可以判断用户的命令

    3.在这个事件里响应的是屏幕上选择条件中的事件,例如CHECKBOX的选择与否,RADIOBUTTON的选择,LISTBOX的选择等等。所以分为以下几个方面:

    1. ... ON psel :在PARAMETER变化是触发的事件

    2. ... ON END OF sel SELECT-OPTION触发的事件

    3. ... ON VALUE-REQUEST FOR psel_low_high :选择的帮助(F4)

    4. ... ON HELP-REQUEST FOR psel_low_high :选择的帮助(F1)

    5. ... ON RADIOBUTTON GROUP radi :单选按钮事件

    6. ... ON BLOCK block :框架的触发事件

    7. ... OUTPUT :响应屏幕上的事件,修改选择屏幕的唯一方法

    4. START-OF-SELECTION

    报表程序必须执行的事件,在进入第二屏幕之前触发。

    5. GET

    获得逻辑数据库的值。前提是必须首先声明逻辑数据库。

    6. END-OF-SELECTION

    第二屏幕显示完毕,结束处理。

    7. MODULE

    这个是当你调用自己定义的屏幕时,响应屏幕事件的方法。

    8. ENDMODULE

    9. CHECK

    只对逻辑数据库使用,检查是否取得数据。

    10. REJECT

    同样只对逻辑数据库使用,退出。

    11. STOP

    结束一个处理块。

    12. RETURN

    返回一个处理块。

    三, 附加说明:

    1. SET PF-STATUS

    基本语法格式:SET PF-STATUS pfstat.

    扩展:

    1. ... EXCLUDING f oder ... EXCLUDING itab

    2. ... IMMEDIATELY

    3. ... OF PROGRAM progname

    这个是设置屏幕菜单,命令行等的命令,详细地信息我会在后面关于菜单设计的时候说明。

    2. SET TITLEBAR

    设置屏幕标题,在屏幕显示之前调用。


    ultraluck 发表于:2008.04.16 17:06 ::分类: ( SAP ABAP ) ::阅读:(59次) :: Permanent link :: 引用 (0)

    关于SAP内表及工作区

    内表(internal table)和工作区(work area)的区别

    ABAP/4的Internal Table如同其他语言的数组结构,在操作上可以有复制,删除,新增等功能,可以存很多条记录,并且ABAP的这种用法,对行数没什么限制。
    WORK AREA就是其他语言的结构,象自定义的一个类型一样,但一旦创建一个Internal Table之后,WORK AREA就成了外界跟Intertal Table的交流口,每条记录的进入和取出都得通过它。并且在清除它们的时候要分开来清除。

    要用 MODIFY 语句更改行 ,请使用:
    语法
    MODIFY <itab> [FROM <wa>] [INDEX <idx>].
    FROM 选项中指定 的工作区域 <wa> 代替 <itab> 中的行。如 果表格有表 头行,可以 忽略 FROM 选项。这样 ,表格工作 区域就代替 行。
    如果使用 INDEX 选项,则新 行代替索引 为 <idx> 的现有行。 如果替换成 功,则将 SY-SUBRC 设置为0。 如果内表包 含的行少于 <idx>, 则不更改任 何行并且 SY-SUBRC 包含4。
    如果使用没 有 INDEX 选项的 MODIFY 语句,则系 统只能在 LOOP - ENDLOOP 块中通过更 改当前行( 例如由 SY-TABIX 返回其索引 的行)来处 理它。
    modify 是用来更新内表的!


    ultraluck 发表于:2008.04.16 17:04 ::分类: ( SAP ABAP ) ::阅读:(50次) :: Permanent link :: 引用 (0)

    SAP系统包含的表

    > 透明表
    每个透明表在数据库中有一个相应的物理表。物理表的名称和数据字典中的逻辑表
    定义的名称一致。所有事务和应用数据存贮在透明表中。
    结构
    结构在数据库不存在数据记录。结构用于在程序之间或程序与屏幕之间的接口定义。
    附加结构
    附加结构定义字段的子集,该字段属于其他表格或结构,但是在修正管理中作为单
    独的对象。
    存贮表
    存储表可以用来存贮控制数据(例如:屏幕顺序,程序参数或临时数据)。几个存
    储表可以组合成一个表库。该表库和数据库中的一物理表库相一致。它包含了各组
    合库分派给它的所有记录。
    簇表
    连续的文本如文档之类可以存贮在簇表中。几个簇表可以组合成一个表簇。对这种
    表类型,不同表中的几个逻辑行组合到一物理记录。这可以实现一对象接一对象地
    存贮或访问,访问簇中的表的一个前提是,至少关键字的一部分必须相符合。几个
    簇表存贮在数据库中 一个相应的表里。
    ultraluck 发表于:2008.04.16 17:03 ::分类: ( SAP ABAP ) ::阅读:(49次) :: Permanent link :: 引用 (0)

    2008 年 04 月 09日, 星期三

    ABAP字符串常用操作

    Process Internal DataByte String and Character String Processing
    CONCATENATE 连接字符串 [SEPARATED BY 分割符]
    find

    SPLIT 拆分子串
    ------------------------------------------------------
    取前八位
    data a type c(30).
    a = '88888888abcdefg'.
    a = a(6). "取前6位
    a = a+6(1). "取第7位
    a = a+6 . "取第六位后的所有字符
    -------------------------------------------------------
    拆分
    split XXX at into table XXX
    SPLIT dobj AT sep INTO
    { {result1 result2 ...} | {TABLE result_tab} }
    [IN {BYTE|CHARACTER} MODE].
    --------------------------------------------------------
    拼接
    DATA NAME (30).
    NAME(10) = ' Dr.',
    NAME+10(10) = 'Michael',
    NAME+20(10) = 'Hofmann'.
    CONDENSE NAME.
    WRITE NAME.
    -------------------------------------------------------
    去空格
    CONDENSE
    -------------------------------------------------------
    查找
    Search for all occurrences of the string "now" in a string literal using a WHILE loop. After every successful search, the search range is redefined to start after the found location. This enables you to find all occurrences of the search string even in releases before 7.0.
    DATA: patt TYPE string VALUE `now`,
    text TYPE string,
    off TYPE i,
    moff TYPE i,
    mlen TYPE i.
    off = 0.
    WHILE sy-subrc = 0.
    FIND patt IN SECTION OFFSET off OF
    `Everybody knows this is nowhere`
    MATCH OFFSET moff
    MATCH LENGTH mlen.
    IF sy-subrc = 0.
    WRITE / moff.
    off = moff + mlen.
    ENDIF.
    ENDWHILE.
    ------------------------------------------------------------
    补零
    数字前补零
    用途:
    在查语句中,'00006' 和 '6' 是不同的字符,
    而SAP会自动将查询条件变量前面的零去掉。导致查询条件不正确,
    这时候要用CONVERSION_EXIT_ALPHA_INPUT进行补零。
    call function 'CONVERSION_EXIT_ALPHA_INTPUT'
    exporting
    input = &1
    importing
    output = &1.

    注意:变量类型要与数据库字段类型一直,否则补零的位数不正确。
    去零
    数字前去零
    用途:
    在输出的时候,'00006' 和 '6' 是不同的字符,要求把前面的零去掉
    这时候要用CONVERSION_EXIT_ALPHA_OUTPUT进行去零。
    call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
    exporting
    input = &1
    importing
    output = &1.

    ------------------------------------------------------------
    字符串长度
    strlen( char_var )
    ------------------------------------------------------------
    回车符
    A Virtual Characterstic is a normal Characterstic,The Only difference is the data will be Updated at the time of Query Execution.Just Create a Characterstic add this Char to the Cube.You need to write some ABAP Code to Update this Char.
    You will find the Doumentation and Example in SMOD for Virtual Characterstics and Keyfigures.
    for Documentation and Example.
    Goto Tcode SMOD -> Enter Enhancement as RSR00002 ,Select the Radio button Documentation -> Click on Display
    用sap的类CL_ABAP_CHAR_UTILITIES( TYPE-POOLS: abap.).
    CL_ABAP_CHAR_UTILITIES中有字符常量:如:CR_LF,HORIZONTAL_TAB,NEWLINE等等.
    -------------------------------------------------
    是否全是数字
    if aaa CO '01234567888889 '.
    ---------------------------------------------------
    数学函数
    ABAP 代码编辑器中 strlen F1。
    ABAP - Keyword documentation
    ABAP By Theme
    Built-in Type, Data Objects, and Functions
    Built-in Functions
    Mathematical Functions
    ------------------------------------------------------------
     查看全文
    ultraluck 发表于:2008.04.09 10:47 ::分类: ( SAP ABAP ) ::阅读:(249次) :: Permanent link :: 引用 (0)

    2008 年 03 月 20日, 星期四

    ABAP常用fuction

    ABAP常用fuction

    -----------------------------------------------------
    获取生产定单状态
    -----------------------------------------------------
    call function 'STATUS_TEXT_EDIT'
    EXPORTING
    flg_user_stat = 'X'
    objnr = LO_OBJNR
    only_active = 'X'
    spras = sy-langu
    IMPORTING
    line = ls_statu
    EXCEPTIONS
    object_not_found = 01.


    使用:objnr 状态对象号,only_active 激活的 ,


    -----------------------------------------------------

    --------------------------------------------------
    获取每个月的最后一天
    ---------------------------------------------------
    CALL FUNCTION 'LAST_DAY_OF_MONTHS'
    EXPORTING
    day_in = date
    IMPORTING
    last_day_of_month = date1.

    -------------------------------------------------------

    --------------------------------------------------------------
    去掉前面0
    *&--------------------------------------------------------------------*
    *& Form frm_alpha_output 去零
    *&--------------------------------------------------------------------*
    DEFINE alpha_minus.
    call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
    exporting
    input = &1
    importing
    output = &1.
    END-OF-DEFINITION.

    ---------------------------------------------------
    前面加0
    ---------------------------------------------------
    call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
    input = &1
    importing
    output = &1.

    ------------------------------------------------

    踢用户
    TH_DELETE_USER
    ---------------------------------------
    CALL FUNCTION 'CUT_2BYTES_STRINGS'
    EXPORTING
    I_STR = T_STR
    I_LEN = 4
    IMPORTING
    O_STR = T_TXT04
    T_STR 输入字符 I_LEN 长度 T_TXT04输出字符

    -------------------------------------------
    金额转换成大写
    ---------------------------------------------
    CALL FUNCTION 'SPELL_AMOUNT'
    EXPORTING
    AMOUNT = T_AMOUNT10
    CURRENCY = 'RMB'
    LANGUAGE = '1'
    IMPORTING
    IN_WORDS = S_AMWORD2
    EXCEPTIONS
    NOT_FOUND = 1
    TOO_LARGE = 2
    OTHERS = 3.
    --------------------------------------------------------
    用于比较新内表和原内表内容,key_length指原表'record'中所有字段的长度,
    -------------------------------------------------------------------

    *CALL FUNCTION 'CTVB_COMPARE_TABLES'
    * EXPORTING
    * TABLE_OLD = RECORD[] "原内表
    * TABLE_NEW = RECORD2[] "新内表
    * KEY_LENGTH = 91
    * IMPORTING
    * TABLE_DEL = RECORD3[]
    ** TABLE_ADD = RECORD4[]
    ** TABLE_MOD = RECORD5[]


    --------------------------------------------------
    把SAP里的负号放到前面来的函数
    CLOI_PUT_SIGN_IN_FRONT
    --------------------------------------------------
    使用示例

    DATA : t(10) TYPE c VALUE '65465-' .

    CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
    CHANGING
    value = t.

    write : t .

    -------------------------------------------
    通过这个日期得出那天是星期几
    DAY_IN_WEEK

    ----------------------------------------
    用来得到将来/过去的日期的
    RP_CALC_DATE_IN_INTERVAL

    -------------------------------------------
    日期的加减
    BKK_ADD_MONTH_TO_DATE
    --------------------------------------------------------------------


    一组有用的用户交互窗口函数
    POPUP_TO_CONFIRM_LOSS_OF_DATA 显示有YES/NO的弹出窗口,提示用户未保存的数据将丢失

    POPUP_TO_CONFIRM_STEP 提示是否确认操作的弹出窗口

    POPUP_TO_CONFIRM_WITH_MESSAGE 可以显示定制的提示信息的确认窗口

    POPUP_TO_CONFIRM_WITH_VALUE 显示确认用户对某个特定对象的操作的弹出窗口

    POPUP_TO_DECIDE 将待确认选项以单选按钮的方式显示的弹出窗口

    POPUP_TO_DECIDE_WITH_MESSAGE 带消息的确认窗口

    POPUP_TO_DISPLAY_TEXT 显示多行信息的窗口

    POPUP_TO_SELECT_MONTH 月份选择窗口

    POPUP_WITH_TABLE_DISPLAY 有表格对象的确认窗口

    -------------------------------------------------------------------------------
    一组操纵客户端文件系统的函数
    GUI_CREATE_DIRECTORY 在PC上建立文件目录

    GUI_DELETE_FILE 删除PC上的文件

    GUI_DOWNLOAD 文件下载函数

    GUI_EXEC 执行PC上的程序,或者打开文件

    GUI_GET_DESKTOP_INFO 得到PC客户端的系统信息,比如操作系统等

    GUI_REMOVE_DIRECTORY 删除PC目录

    GUI_RUN 运行PC程序(ShellExecute)

    GUI_UPLOAD 从PC上传程序

    -------------------------------------------------------------------
    判断某天是否是假日
    HOLIDAY_CHECK_AND_GET_INFO
    -------------------------------------------------------------------
    ABAP_DOCU_DOWNLOAD
    Download ABAP documentation in HTML format.
    ---------------------------------------------------------------------
    GET_CURRENT_YEAR
    得到当前的财政年(fiscal year)

    ---------------------------------------------------------------------
    察看某日期的属性,包括该日期是星期几,第几天(周2=2),是不是公共假期等,需要输入国家日历。

    DAY_ATTRIBUTES_GET

    Return useful information about a day. Will tell you the day of the week as a word (Tuesday), the day of the week (2 would be Tuedsay), whether the day is a holiday, and more.(provided by Francois Henrotte)?

    -----------------------------------------------------------------------------------------------------


    CLPB_IMPORT :从剪贴板导入internal table
    CLPB_EXPORT:从internal table输入到剪贴板

    示例程序:GRCLPB_1

    在SE38环境下的程序名输入栏输入'DEMO*'后按F4,你可以查到SAP所有的DEMO示例程序,会学到很多ABAP功能的实现方法,输入'BCALV*'后按F4,你可以查到很多ALV示例程序

    SHIFT str LEFT DELETING LEADING '0'.如果要在layout显示不出前面的0 格式: &字段(zc)&
    如果要在layout显示不出小数点后面的0 格式: &字段(.0)&

    金额的阿拉伯数据转汉字的函数!

    FUNCTION zfi_convert_to_capitalization.
    *"----------------------------------------------------------------------
    *"*"Local interface:
    *" IMPORTING
    *" REFERENCE(P_AMOUNT) TYPE WERTV8
    *" EXPORTING
    *" REFERENCE(P_CAPITALIZATION) TYPE STRING
    *"----------------------------------------------------------------------
    DATA:
    v_s00(2) VALUE '零',
    v_s01(2) VALUE '壹',
    v_s02(2) VALUE '贰',
    v_s03(2) VALUE '叁',
    v_s04(2) VALUE '肆',
    v_s05(2) VALUE '伍',
    v_s06(2) VALUE '陆',
    v_s07(2) VALUE '柒',
    v_s08(2) VALUE '捌',
    v_s09(2) VALUE '玖',
    v_w00(2) VALUE '',
    v_w01(2) VALUE '拾',
    v_w02(2) VALUE '佰',
    v_w03(2) VALUE '仟',
    v_w04(2) VALUE '万',
    v_w05(4) VALUE '拾万',
    v_w06(4) VALUE '佰万',
    v_w07(4) VALUE '仟万',
    v_w08(2) VALUE '亿',
    v_w09(4) VALUE '拾亿',
    v_w10(4) VALUE '佰亿',
    v_w11(4) VALUE '仟亿',
    v_w12(4) VALUE '万亿',
    v_sy(2) VALUE '元',
    v_sj(2) VALUE '角',
    v_sf(2) VALUE '分',
    v_amount(16),"将金额转换成字符型
    v_len TYPE i,"v_amount或p_capitalization的长度
    v_var(5),"v_s0,v_s1,...,v_w0,v_w1,...
    v_num(2) TYPE n,"每一位的数值
    v_s_num(2),"v_s0,v_s1,...中的值
    v_weight(2) TYPE n,"权数
    v_w_num(4),"v_w0,v_w1,...中的值
    v_flag0 TYPE i VALUE 1,"是否输出'零',0不输出,1输出
    v_n TYPE i VALUE 0.
    v_amount = p_amount.
    SHIFT v_amount LEFT DELETING LEADING space.
    SHIFT v_amount LEFT DELETING LEADING '0'.
    *-计算分-----------------------------------------
    v_len = strlen( v_amount ).
    v_len = v_len - 1.
    v_num = v_amount+v_len(1).
    IF v_num <> '0'.
    CONCATENATE 'v_s' v_num INTO v_var.
    WRITE (v_var) TO v_s_num.
    CONCATENATE v_s_num v_sf p_capitalization INTO p_capitalization.
    ENDIF.
    *-计算角-----------------------------------------
    v_len = strlen( v_amount ).
    v_len = v_len - 2.
    v_num = v_amount+v_len(1).
    IF v_num <> '0'.
    CONCATENATE 'v_s' v_num INTO v_var.
    WRITE (v_var) TO v_s_num.
    CONCATENATE v_s_num v_sj p_capitalization INTO p_capitalization.
    ENDIF.
    *-输出‘整’字-------------------------------------
    IF p_capitalization = ' '.
    CONCATENATE '整' p_capitalization INTO p_capitalization.
    ENDIF.
    *-计算整数---------------------------------------
    v_len = strlen( v_amount ).
    v_len = v_len - 3.
    if v_len = 0.
    exit.
    endif.
    v_amount = v_amount(v_len)." 整数部分
    *-输出‘元’字-------------------------------------
    CONCATENATE v_sy p_capitalization INTO p_capitalization.
    v_n = v_len - 1.
    v_weight = 0.
    DO v_len TIMES.
    * 从个位开始
    v_num = v_amount+v_n(1).
    IF v_num <> '0'.
    CONCATENATE 'v_s' v_num INTO v_var.
    WRITE (v_var) TO v_s_num.
    CONCATENATE 'v_w' v_weight INTO v_var.
    WRITE (v_var) TO v_w_num.
    CONCATENATE v_s_num v_w_num p_capitalization INTO p_capitalization.
    v_flag0 = 1.
    ELSE.
    IF v_flag0 = 1.
    CONCATENATE 'v_s' v_num INTO v_var.
    WRITE (v_var) TO v_s_num.
    CONCATENATE v_s_num p_capitalization INTO p_capitalization.
    v_flag0 = 0.
    ENDIF.
    ENDIF.
    v_weight = v_weight + 1.
    v_n = v_n - 1.
    ENDDO.
    *-删除个位可能出现'零'的情况-----------------
    SEARCH p_capitalization FOR '元'.
    IF sy-subrc = 0.
    v_n = sy-fdpos - 2.
    IF p_capitalization+v_n(2) = v_s00.
    v_len = strlen( p_capitalization ).
    CONCATENATE p_capitalization(v_n) p_capitalization+sy-fdpos INTO p_capitalization.
    ENDIF.
    ENDIF.
    ENDFUNCTION.


    ultraluck 发表于:2008.03.20 10:44 ::分类: ( SAP ABAP ) ::阅读:(86次) :: Permanent link :: 引用 (0)

    2008 年 03 月 06日, 星期四

    通过二次开发在SAP R/3中实现库存日清功能【转】

    通过二次开发在SAP R/3中实现库存日清功能

    通过二次开发在SAP R/3中实现库存日清功能

    作者:冯强

    大型电子制造企业大多采用按生产计划配送物料的方式,配送中心通过产品物料清单(BOM)、计划、实时库存进行MRP运算的结果,按生产线(成本中心)齐套物料。保管员、配套员的日常工作非常饱满,每个工作日后的盘存(日清)就显得非常重要,库存准确与否将对下一个工作日配套质量产生重要的影响。SAP R/3有标准的盘点流程,但在实际操作中应用于日清盘存过于繁琐,它更适用于财务月度(年度)的盘存。

    日清盘存由于只能在日常收货、配发工作完成后进行,所以对时间的要求很严格,应该做到简洁和高效。按照常规的盘存要求,应对库存地所有物料进行清点,但这在日清盘存中是绝对做不到的。我们采取的日清盘存方式,是根据保管员当日的收货、发货、转储物料凭证,对发生过库存变更的物料进行统计,打印出日清盘存表供保管员清点实物。由于当日发生过库存变更的物料占库存物料种类的比例一般不会太高,这样在大幅减轻日清盘存工作量的情况下,可以尽可能的提高盘存的精确度。

    程序清单如下,用ABAP开发,在SAP R/3 4.5D上测试通过,关于程序说明见程序注解。

    PROGRAM ZMTHD NO STANDARD PAGE HEADING LINE-SIZE 164 MESSAGE-ID Z1.

    *$-------------------------------------------------------------------

    *& 查询并导出当日有收发的保管员库存清单 Author: Frank Feng(FQ)

    *& (不分批次) 2003.10.15

    *& last modify: 2004.06.15

    *$-------------------------------------------------------------------

    TABLES:MSEG,MKPF,MARD,MARA,MAKT,T001W.

    *MSEG:物料凭证表,收货、发货、转储凭证均保存在这个表中

    *MKPF:物料凭证抬头表,凭证日期是保存在这个表中,根据日期汇集物料凭证,

    * 然后根据物料凭证在MSEG中获得物料凭证明细

    *MARD:库存地物料库存

    *MARA:常规物料数据,包括物料代码、计量单位、旧物料号等

    *MAKT:物料描述

    *T001W:工厂部门数据,用于权限检查

    * 定义数据结构

    TYPES: BEGIN OF SFKC_TYPE,

    B_MBLNR LIKE MSEG-MBLNR, "物料凭证编号

    B_WERKS LIKE MSEG-WERKS, "工厂

    B_LGORT LIKE MSEG-LGORT, "库存地

    B_MATNR LIKE MSEG-MATNR, "物料代码

    B_BISMT LIKE MARA-BISMT, "旧物料号

    B_MAKTX LIKE MAKT-MAKTX, "物料描述

    B_MEINS(4), "基本计量单位

    B_LABST LIKE MARD-LABST, "非限制库存

    B_INSME LIKE MARD-INSME, "质检库存

    B_SPEME LIKE MARD-SPEME, "冻结库存

    B_LGPBE LIKE MARD-LGPBE, "我们是用“仓位”记录保管员姓名

    END OF SFKC_TYPE.

    TYPES: BEGIN OF LIST_TYPE,

    B_WERKS LIKE MSEG-WERKS, "工厂

    B_LGORT LIKE MSEG-LGORT, "库存地

    B_MATNR LIKE MSEG-MATNR, "物料代码

    B_BISMT LIKE MARA-BISMT, "旧物料号

    B_MAKTX LIKE MAKT-MAKTX, "物料描述

    B_MEINS(4), "基本计量单位

    B_LABST LIKE MARD-LABST, "非限制库存

    B_INSME LIKE MARD-INSME, "质检库存

    B_SPEME LIKE MARD-SPEME, "冻结库存

    B_LGPBE LIKE MARD-LGPBE, "仓位-->保管员

    END OF LIST_TYPE.

    DATA: FQ_ITAB TYPE STANDARD TABLE OF SFKC_TYPE WITH HEADER LINE,

    LI_ITAB TYPE STANDARD TABLE OF LIST_TYPE WITH HEADER LINE.

    DATA: BEGIN OF IWERKS OCCURS 0,

    WERKS LIKE T001W-WERKS,

    END OF IWERKS.

    DATA: TOTALLINE(5) TYPE N VALUE 0. "日清表的总行数(记录数)

    *&------------------------------------------------------------------

    *日清表条件输入(我们默认工厂是2010,可以根据实际需求更改)

    SELECTION-SCREEN BEGIN OF BLOCK FQ WITH FRAME TITLE TEXT-001.

    SELECTION-SCREEN SKIP 1.

    SELECT-OPTIONS: V_WERKS FOR MSEG-WERKS MEMORY ID WRK NO INTERVALS

    OBLIGATORY DEFAULT '2010', "工厂

    V_LGORT FOR MSEG-LGORT MEMORY ID LAG, "库存地

    V_LGPBE FOR MARD-LGPBE, "仓位-->保管员

    JZ_DATE FOR MKPF-BUDAT DEFAULT SY-DATUM TO SY-DATUM.

    "记帐日期

    PARAMETERS: V_MJAHR(4) DEFAULT SY-DATUM(4).

    SELECTION-SCREEN END OF BLOCK FQ.

    *&-------------------------------------------------------------------

    INCLUDE .

    START-OF-SELECTION.

    * 根权限对象ZAUTHOR进行权限检查,如不要求,可以去除

    SELECT WERKS FROM T001W INTO TABLE IWERKS WHERE WERKS IN V_WERKS.

    LOOP AT IWERKS.

    AUTHORITY-CHECK OBJECT 'ZAUTHOR'

    ID 'ZQQ_WERKS' FIELD IWERKS-WERKS.

    IF SY-SUBRC NE 0.

    MESSAGE A722 WITH IWERKS-WERKS.

    ENDIF.

    ENDLOOP.

    CLEAR T001W.

    CLEAR IWERKS.

    *根据记账日期区间汇集相关物料凭证

    SELECT * FROM MKPF

    WHERE MJAHR = V_MJAHR AND BUDAT IN JZ_DATE.

    IF SY-SUBRC = 0.

    FQ_ITAB-B_MBLNR = MKPF-MBLNR.

    APPEND FQ_ITAB.

    ENDIF.

    ENDSELECT.

    CLEAR MKPF.

    LOOP AT FQ_ITAB.

    SELECT * FROM MSEG WHERE MBLNR = FQ_ITAB-B_MBLNR AND "more lines

    MJAHR = SY-DATUM(4).

    IF SY-SUBRC EQ 0.

    LI_ITAB-B_WERKS = MSEG-WERKS.

    LI_ITAB-B_LGORT = MSEG-LGORT.

    LI_ITAB-B_MATNR = MSEG-MATNR.

    APPEND LI_ITAB.

    ENDIF.

    ENDSELECT.

    ENDLOOP.

    CLEAR FQ_ITAB.

    CLEAR FQ_ITAB[].

    CLEAR MSEG.

    *删除不符的凭证明细

    DELETE LI_ITAB WHERE NOT ( B_WERKS IN V_WERKS AND B_LGORT IN V_LGORT )

    OR B_WERKS IS INITIAL OR B_LGORT IS INITIAL.

    SORT LI_ITAB BY B_WERKS B_LGORT B_MATNR.

    *压缩内表,保证按工厂、库存地、物料号关键字记录唯一

    DELETE ADJACENT DUPLICATES FROM LI_ITAB

    COMPARING B_WERKS B_LGORT B_MATNR.

    CONDENSE TOTALLINE.

    * 遍历汇集的工厂库存地物料库存,写入表中

    LOOP AT LI_ITAB.

    SELECT * FROM MARD WHERE WERKS = LI_ITAB-B_WERKS AND

    LGORT = LI_ITAB-B_LGORT AND

    MATNR = LI_ITAB-B_MATNR.

    IF SY-SUBRC EQ 0 AND MARD-LVORM IS INITIAL.

    LI_ITAB-B_LABST = MARD-LABST.

    LI_ITAB-B_INSME = MARD-INSME.

    LI_ITAB-B_SPEME = MARD-SPEME.

    LI_ITAB-B_LGPBE = MARD-LGPBE.

    ENDIF.

    ENDSELECT.

    SELECT * FROM MARA WHERE MATNR = LI_ITAB-B_MATNR.

    IF SY-SUBRC = 0.

    LI_ITAB-B_BISMT = MARA-BISMT.

    LI_ITAB-B_MEINS = MARA-MEINS.

    ENDIF.

    ENDSELECT.

    SELECT * FROM MAKT WHERE MATNR = LI_ITAB-B_MATNR

    AND SPRAS = SY-LANGU.

    IF SY-SUBRC = 0.

    LI_ITAB-B_MAKTX = MAKT-MAKTX.

    ENDIF.

    ENDSELECT.

    MODIFY LI_ITAB.

    ENDLOOP.

    IF NOT V_LGPBE IS INITIAL.

    DELETE LI_ITAB WHERE NOT ( B_LGPBE IN V_LGPBE ).

    ENDIF.

    CLEAR MARD.

    CLEAR MARA.

    CLEAR MAKT.

    LOOP AT LI_ITAB.

    TOTALLINE = TOTALLINE + 1.

    ENDLOOP.

    END-OF-SELECTION.

    IF TOTALLINE EQ 0.

    WRITE: / '没有满足选定条件的物料' COLOR 3.

    ELSE.

    SORT LI_ITAB BY B_WERKS B_LGORT B_LGPBE B_MATNR.

    WRITE: /3 ICON_GREEN_LIGHT,'程序运行成功,',

    TOTALLINE,''.

    PERFORM LISTOUT. "执行日清表写屏程序

    ENDIF.

    START-OF-SELECTION.

    SET PF-STATUS 'LIST'.

    AT USER-COMMAND.

    CASE SY-UCOMM.

    WHEN 'DOWNLOAD'.

    PERFORM DOWNLOAD. "下载日清表格到文本

    WHEN 'TOXLS'.

    PERFORM TOEXCEL. "导出日清表格到Excel

    ENDCASE.

    END-OF-SELECTION.

    *&--------------------------------------------------------------------

    *&---------------------------------------------------------------------*

    *& Form LISTOUT

    *&---------------------------------------------------------------------*

    * text

    *----------------------------------------------------------------------*

    * --> p1 text

    * <-- p2 text

    *----------------------------------------------------------------------*

    * 在屏幕上写日清表

    FORM LISTOUT.

    SET LEFT SCROLL-BOUNDARY COLUMN 33.

    ULINE 0(162).

    WRITE:/73 '保管员库存日清核对表' .

    WRITE:/.

    ULINE 1(162).

    WRITE: AT /1 SY-VLINE, AT 2 '工厂',

    6 SY-VLINE, 7 '库存地',

    13 SY-VLINE, 14 '物料代码',

    32 SY-VLINE, 33 '旧物料号',

    51 SY-VLINE, 52 '物料描述',

    92 SY-VLINE, 93 '单位',

    97 SY-VLINE, 98 '非限制库存',

    115 SY-VLINE, 116 '质检库存',

    133 SY-VLINE, 134 '冻结库存',

    151 SY-VLINE, 152 '保管员',162 SY-VLINE.

    ULINE 0(162).

    DATA: COLORCH TYPE I VALUE 0.

    LOOP AT LI_ITAB.

    IF COLORCH EQ 0.

    WRITE: /1 SY-VLINE, 2 LI_ITAB-B_WERKS COLOR 1,

    6 SY-VLINE, 7 ' ' COLOR 1,8 LI_ITAB-B_LGORT COLOR 1,

    12 ' ' COLOR 1,

    13 SY-VLINE, 14 LI_ITAB-B_MATNR COLOR 1,

    32 SY-VLINE, 33 LI_ITAB-B_BISMT COLOR 1," delete by FQ

    51 SY-VLINE, 52 LI_ITAB-B_MAKTX COLOR 1,

    92 SY-VLINE, 93 LI_ITAB-B_MEINS COLOR 1,76 ' ' COLOR 1,

    97 SY-VLINE, 98 LI_ITAB-B_LABST COLOR 1,

    115 SY-VLINE,116 LI_ITAB-B_INSME COLOR 1,

    133 SY-VLINE,134 LI_ITAB-B_SPEME COLOR 1,

    151 SY-VLINE,152 LI_ITAB-B_LGPBE COLOR 1,162 SY-VLINE.

    COLORCH = 1.

    ELSE.

    WRITE: /1 SY-VLINE, 2 LI_ITAB-B_WERKS COLOR 2,

    6 SY-VLINE, 7 ' ' COLOR 2,8 LI_ITAB-B_LGORT COLOR 2,

    12 ' ' COLOR 2,

    13 SY-VLINE, 14 LI_ITAB-B_MATNR COLOR 2,

    32 SY-VLINE, 33 LI_ITAB-B_BISMT COLOR 2,"delete by fq

    51 SY-VLINE, 52 LI_ITAB-B_MAKTX COLOR 2,

    92 SY-VLINE,93 LI_ITAB-B_MEINS COLOR 2,76 ' ' COLOR 2,

    97 SY-VLINE, 98 LI_ITAB-B_LABST COLOR 2,

    115 SY-VLINE,116 LI_ITAB-B_INSME COLOR 2,

    133 SY-VLINE,134 LI_ITAB-B_SPEME COLOR 2,

    151 SY-VLINE,152 LI_ITAB-B_LGPBE COLOR 2,162 SY-VLINE.

    COLORCH = 0.

    ENDIF.

    ENDLOOP.

    ULINE 0(162).

    ENDFORM. " LISTOUT

    *&---------------------------------------------------------------------*

    *& Form DOWNLOAD

    *&---------------------------------------------------------------------*

    * text

    *----------------------------------------------------------------------*

    * --> p1 text

    * <-- p2 text

    *----------------------------------------------------------------------*

    *下载日清表到文本

    FORM DOWNLOAD.

    DATA: CANCELUSER TYPE C,OUTFILE LIKE RLGRAP-FILENAME.

    CALL FUNCTION 'DOWNLOAD'

    EXPORTING

    FILENAME = 'd:bgcheck.txt'

    FILETYPE = 'DAT'

    ITEM = '输出日清表(不分批次)'

    MODE = ' '

    IMPORTING

    ACT_FILENAME = OUTFILE "user out filename

    CANCEL = CANCELUSER

    TABLES

    DATA_TAB = LI_ITAB .

    ultraluck 发表于:2008.03.06 17:10 ::分类: ( SAP ABAP ) ::阅读:(111次) :: Permanent link :: 引用 (0)

    2008 年 01 月 16日, 星期三

    bapi 数据更新注意事项

    更新模块的定义需要考虑:

    选择属性“更新模块” 单选按钮。

    跟其他函数模块一样,更新模块也有接口。更新函数模块的 接口只包括IMPORTING 和TABLES 参数,而且必须用引用 字段或结构来定义类型。

    在更新模块的输出和异常参数被忽略。

    函数模块包含实际的数据库更新语

    日志表的条目从会话程序生成。函数模块必须用附加 关键字IN UPDATE TASK 来调用,这确保了函数模 块不会立即执行。来自于函数模块接口的数据都被写 入日志表。

    对于会话程序中的每个CALL FUNCTION ... IN UPDATE TASK 语句,系统在日志表生成一个条目, 包含了更新函数模块的名字和相关参数。


    ultraluck 发表于:2008.01.16 17:04 ::分类: ( SAP ABAP ) ::阅读:(65次) :: Permanent link :: 引用 (0)

    sap 权限控制

    权限检查

    在SAP 访问许可的检查中需要重要考虑的一点是它只 是一个活动分享处理。系统在程序中没有默认的权限 检查,这意味着如果程序没有请求检查,就什么都不 会做。

    在程序中这个检查过程基于一个简单的ABAP 命令, 关键字为AUTHORITY-CHECK。

    当在程序中进行权限检查时,指定的用户在某个授权 中需要访问的对象的对象和值,但是不需要指定授权 的名字。这里的授权是指参数文件。

    在AUTHORITY-CHECK 语句中,必须指定对象的所 有字段,否则,返回码就不是0。如果不想为某个字 段执行检查,在字段中输入DUMMY。(在ECC5 里 已经不是这样了)

    重要:AUTHORITY-CHECK 语句执行权限检查,并 把相应的返回码放在sy-subrc 中。在检查返回码时, 应该指定对于缺失权限的处理(例如:中止程序、显 示消息、跳到某个代码行)。

    使用ABAP 编辑器中的“模式” 按钮来插入 AUTHORITY-CHECK 命令,这个模式会插入权限对 象中全部字段。

    如果不使用“模式” 按钮,就必须记得权限对象和所有 字段,注意都必须用单引号括起来的大写字母。

    AUTHORITY-CHECK 的重要的返回码有:

    0:用户权限中包含请求的值。

    4:用户不具有请求的值。

    8:检查不成功,因为有字段没有指定。

    AUTHORITY-CHECK 的关键字文档包含了所有可能 的返回码。


    ultraluck 发表于:2008.01.16 15:21 ::分类: ( SAP ABAP ) ::阅读:(66次) :: Permanent link :: 引用 (0)

    sap bapi 锁参数用法【转】

    字段名


    要被锁定的键必须在这里传递。

    另一个参数X_<field> 定义了当每个锁字段<field> 传递初始 值时锁的行为。如果给<field> 和X_<field> 指定了初始值, 关于<field> 的通用锁就会被初始化。如果<field> 指定了初 始值而X_<field> 为X,锁就设置<field> 为它实际的初始值。

    传输锁的参数

    当事务结束或者相应的DEQUEUE 函数模块被调用,锁就被 移除。然而,如果事务调用了更新子程序的话就不是这样 了,这时,参数必须检查锁是否已经被移除。

    传输锁的参数

    参数_SCOPE 控制了锁或者锁释放如果被传递给更新程序, 有以下选择:

    _SCOPE = 1:锁和锁释放不传递给更新程序。当事务结束时锁 被移除。

    _SCOPE = 2:锁或锁释放传递给更新程序。更新程序负责移除 锁。请求了锁的交互式程序不再对锁行为有影响。这是 ENQUEUE 函数模块的标准设置。

    _SCOPE = 3:锁或锁释放也传递给更新程序。锁必须从交互式 程序和更新程序中同时移除。这是DEQUEUE 函数模块的标准 设置。

    锁模式参数

    参数MODE_<tab> 定义了锁对象里的每个基础表tab。对于 这个基础表的锁模式可以用这个参数动态设置。这个参数的 可用值包括S(共享)、E(排他)、X(排他但不累积)。 在锁对象中创建表时指定的锁模式就是这个参数的缺省值, 但是如果有必要的话,这个缺省值可以在函数模块被调用时 被覆盖。

    如果带有锁模式的锁通过调用函数模块DEQUEUE 被移除, 这个调用必须具有跟参数MODE_<tab> 相同的值。

    控制锁传输

    参数_COLLECT 控制了锁请求或锁释放应该是直接执行还是 应该先被写入本地锁容器。这个参数具有下列值:

    初始值:锁请求或锁释放被直接发送给锁服务器。

    X:锁请求或锁释放被放在本地锁容器中。收集在这个锁容器中 的锁请求和锁释放可以在以后调用函数模块 FLUSH_ENQUEUE 时成组的发送给锁服务器。锁限制的行为(只对ENQUEUE)

    ENQUEUE 函数模块还有一个参数_WAIT。这个参数决定了 当锁被限制时的行为。有以下选择:

    初始值:如果锁尝试由于一个冲突锁而失败了,就会触发 FOREIGN_LOCK 的异常。

    X:如果锁尝试由于一个冲突锁而失败了,锁尝试会等待一段时 间后再试。只有在首次锁尝试过后一定时间后才会触发 FOREIGN_LOCK 异常。等待时间和时间限制都由特征参数来 定义。

    控制锁条目的删除(只对DEQUEUE)

    DEQUEUE 还有一个参数_SYNCHRON,用来监控锁条目被 删除时的行为。

    如果传递了X,DEQUEUE 函数会一直等待,直到条目被从锁 表中移除。

    否则,它就异步删除,就是说,如果系统的锁表在锁被移除后 直接读取,锁表的条目可能依然存在。


    ultraluck 发表于:2008.01.16 14:59 ::分类: ( SAP ABAP ) ::阅读:(63次) :: Permanent link :: 引用 (0)

    2008 年 01 月 15日, 星期二

    系统对锁的处理

    有三种不同的锁模式:

    模式E 的写锁:如果想要把数据写入数据库(修改、创建或 删除),就设置成这种锁。可以累积使用

    模式S 的读锁:如果想要确保程序运行过程中从数据库读出 的数据不被其他用户修改,就设置这种锁。但是在程序中并 不想去修改数据。

    模式X 的写锁:跟模式E 类似,模式X 用来把数据写入数据 库。技术上的差异在于,当程序被执行时,模式X 的锁不会 累积。

    写锁(E 或X)意味着任何其他用户的锁尝试都会被拒绝, 不管尝试的锁是哪种模式的。

    如果被锁定的数据记录是模式S(共享),其他用户可以再 设置模式S 的锁,而其他锁模式(E 或X)的尝试则会被拒 绝。

    sap 三种锁定模式

     查看全文

    ultraluck 发表于:2008.01.15 16:41 ::分类: ( SAP ABAP ) ::阅读:(60次) :: Permanent link :: 引用 (0)

    SAP系统包含的表

    透明表
    每个透明表在数据库中有一个相应的物理表。物理表的名称和数据字典中的逻辑表
    定义的名称一致。所有事务和应用数据存贮在透明表中。
    结构
    结构在数据库不存在数据记录。结构用于在程序之间或程序与屏幕之间的接口定义。
    附加结构
    附加结构定义字段的子集,该字段属于其他表格或结构,但是在修正管理中作为单
    独的对象。
    存贮表
    存储表可以用来存贮控制数据(例如:屏幕顺序,程序参数或临时数据)。几个存
    储表可以组合成一个表库。该表库和数据库中的一物理表库相一致。它包含了各组
    合库分派给它的所有记录。
    簇表
    连续的文本如文档之类可以存贮在簇表中。几个簇表可以组合成一个表簇。对这种
    表类型,不同表中的几个逻辑行组合到一物理记录。这可以实现一对象接一对象地
    存贮或访问,访问簇中的表的一个前提是,至少关键字的一部分必须相符合。几个
    簇表存贮在数据库中 一个相应的表里。
    ultraluck 发表于:2008.01.15 16:09 ::分类: ( SAP ABAP ) ::阅读:(66次) :: Permanent link :: 引用 (0)

    2008 年 01 月 13日, 星期日

    What is the different between ALE, IDOC and BAPI?

    What is the different between ALE, IDOC and BAPI?

    ALE

    ALE is SAP proprietary technology that enables data communications between two or more SAP R/3 systems and/or R/3 and external systems. When a new enterprise resource planning (ERP) solution such as R/3 is implemented, companies have to interface the ERP system with legacy systems or other ERP systems.

    ALE provides intelligent mechanisms where by clients can achieve integration as well as distribution of applications and data.

    ALE technology facilitates rapid application prototyping and application interface development, thus reducing implementation time.

    The ALE components are inherently integrated with SAP applications and are robust, leading to a highly reliable system.

    ALE comes with application distribution/integration scenarios as well as a set of tools, programs, data definitions, and methodologies that you can easily configure to get an interface up and running.

    BAPI

    BAPIs provide a stable, standardized method for third-party applications and components to integrate into the Business Framework. These interfaces are being specified as part of SAP's initiative with customers, partners and leading standards organizations. Also, SAP has implemented the emerging Object Application Group (OAG) specifications with BAPIs.

    Pros and Cons for both BAPI and Call Transaction

    BAPI
    One of the big plusses for BAPIs is that the interface and function are not supposed to change. This is a big plus when you do upgrades or hot packs because the transaction can change (format, required inputs etc) which means you then need to update the call transaction.

    Some of the BAPIs are better documented and easier to use than others.

    You usually need to perform the BAPI that actually does the COMMIT after you call your BAPI.

    The Program coding for calling a BAPI is usually cleaner than setting up the screen flow etc for the Call Transaction.

    You don't need to worry about special data circumstances interrupting the normal data flow of the screens and causing errors because of that.

    BAPIs probably have better performance since they don't do the screen flow processing.

    In general if the BAPI exists for the transaction you want to perform and you can figure out how to use it the BAPI is probably the best way to go.

    This is just from my experience working with both BAPI and Call Transaction. I have had some very good successes with BAPIs, but very occasionally found that I could not get the BAPI to perform the update I needed.

    ABAP Tips by: Heather R Woytash

    The interface concept of the classic R/3 is based on two different strategies: Remote Function Calls (RFC) and data exchange through IDoc message documents. RFC makes direct and synchronous calls of a program in the remote system. If the caller is an external program it will call an RFC-enabled function in R/3 and if the calling program is the R/3 system it will call an
    RFC-function in another R/3-system or it will call a non-R/3 program through a gateway-proxy (usually rfcexec.exe). BAPIs are a subset of the RFC-enabled function modules, especially designed as Application Programming Interface (API) to the SAP business object, or in other words: are function modules officially released by SAP to be called from external programs.

    IDocs are text encoded documents with a rigid structure that are used to exchange data between R/3 and a foreign system. Instead of calling a program in the destination system directly, the data is first packed into an IDoc and then sent to the receiving system, where it is analyzed and properly processed. Therefore an IDoc data exchange is always an
    asynchronous process. The significant difference between simple RFC-calls and IDoc data exchange is the fact, that every action performed on IDocs are protocolled by R/3 and IDocs can be reprocessed if an error occurred in one of the message steps.

    While IDocs have to be understood as a data exchange protocol, EDI and ALE are typical use cases for IDocs. R/3 uses IDocs for both EDI and ALE to deliver data to the receiving system. ALE is basically the scheduling mechanism that defines when and between which partners and what kind of data will be exchanged on a regular or event triggered basis. Such a set-up is called an ALE-scenario.

    The philosophical difference between EDI and ALE can be pinned as follows: If we send data to an external partner, we generally speak of EDI, while ALE is a mechanism to reliable replicate data between trusting systems to store a redundant copy of the IDoc data. The difference is made clear, when we think of a purchase order that is sent as an IDoc. If we send the purchase order to a supplier then the supplier will store the purchase order as a sales order. However, if we send the purchase order via ALE to another R/3 system, then the receiving system will store the purchase order also as a purchase order.

    ABAP Tips by: Subhash


    ultraluck 发表于:2008.01.13 22:30 ::分类: ( SAP ABAP ) ::阅读:(81次) :: Permanent link :: 引用 (0)

    BAPI Conventions

    BAPI Conventions
    Methods
    Parameters
    Standardized BAPIs
    Standardized Parameters
    Important things to remember..
    BAPI/ALE Integration

    Methods

    • If the BAPI to be implemented is a standardized BAPI, use the generic names, for example, GetList, GetDetail.
    • The method name must be in English (maximum 30 characters).
    • The individual components of a BAPI name are separated by the use of upper and lower case.Example: GetList
      Underscores ("_") are not allowed in BAPI names.
    • Each BAPI has a return parameter that is either an export parameter or an export table.
    • So that customers can enhance BAPIs, each BAPI must have an ExtensionIn and an ExtensionOut parameter.

    Parameters

    • If standardized parameters are used, you have to use the names specified for standardized parameters.
    • BAPI parameter names should be as meaningful as possible. Poorly chosen names include abbreviations and technical names (e.g. "flag", table names, etc.).
      The parameter and field names must be in English with a maximum of 30 characters.
    • The components of a parameter name in the BOR are separated by upper and lower case letters to make them easier to read. Example: CompanyCodeDetail
    • Values that belong to each other semantically should be grouped together in one structured parameter, instead of using several scalar parameters.
    • For ISO-relevant fields (country, language, unit of measure, currency), additional fields for ISO codes are provided.
    • Unit of measure fields must accompany all quantity fields and currency identifiers must accompany currency amount fields.

    Standardized BAPIs

    Some BAPIs provide basic functions and can be used for most SAP business object types. These BAPIs should be implemented the same for all business object types. Standardized BAPIs are easier to use and prevent users having to deal with a number of different BAPIs. Whenever possible, a standardized BAPI must be used in preference to an individual BAPI.

    The following standardized BAPIs are provided:

    Reading instances of SAP business objects

    GetList ( )With the BAPI GetList you can select a range of object key values, for example, company codes and material numbers.
    The BAPI GetList() is a class method.
    GetDetail()With the BAPI GetDetail() the details of an instance of a business object type are retrieved and returned to the calling program. The instance is identified via its key. The BAPI GetDetail() is an instance method.

    BAPIs that can create, change or delete instances of a business object type

    The following BAPIs of the same object type have to be programmed so that they can be called several times within one transaction. For example, if, after sales order 1 has been created, a second sales order 2 is created in the same transaction, the second BAPI call must not affect the consistency of the sales order 2. After completing the transaction with a COMMIT WORK, both the orders are saved consistently in the database.


    Create( ) and
    CreateFromData( )
    The BAPIs Create() and CreateFromData() create an instance of an SAP business object type, for example, a purchase order. These BAPIs are class methods.
    Change( )The BAPI Change() changes an existing instance of an SAP business object type, for example, a purchase order. The BAPI Change () is an instance method.
    Delete( ) and Undelete( )The BAPI Delete() deletes an instance of an SAP business object type from the database or sets a deletion flag.
    The BAPI Undelete() removes a deletion flag. These BAPIs are instance methods.
    Cancel ( )Unlike the BAPI Delete(), the BAPI Cancel() cancels an instance of a business object type. The instance to be cancelled remains in the database and an additional instance is created and this is the one that is actually canceled. The Cancel() BAPI is an instance method.
    Add<subobject> ( ) and Remove<subobject> ( )The BAPI Add<subobject> adds a subobject to an existing object instance and the BAPI and Remove<subobject> removes a subobject from an object instance. These BAPIs are instance methods.

    BAPIs for Mass Data Processing

    The BAPIs listed above for creating and changing data can also be used for mass processing. For more information see BAPIs for Mass Data Transfer [Extern]

    BAPIs for Replicating Business Object Instances

    Replicate( ) and SaveReplica( )The BAPIs Replicate() and SaveReplica() are implemented as methods of replicable business object types. They enable specific instances of an object type to be copied to one or more different systems. These BAPIs are used mainly to transfer data between distributed systems within the context of Application Link Enabling (ALE). These BAPIs are class methods.

    Other Less Used Standardized BAPIs

    • Programming GetStatus() BAPIs [Extern]
    • Programming ExistenceCheck() BAPIs [Extern]

    Standardized Parameters

    There are some parameters that can be created for various BAPIs because they contain the same or the equivalent data in all BAPIs. They should be implemented the same in all BAPIs.


    Address parametersSpecific reference structures are defined for address parameters in BAPIs. You should copy these structures to use in your BAPI, especially if the underlying object type uses the central address management (CAM).
    Change ParametersIn BAPIs that cause database changes (for example, Change() and Create() BAPIs) you must be able to distinguish between parameter fields that contain modified values and parameter fields that have not been modified. This distinction is made through the use of standardized parameters.
    Extension parametersThe parameters ExtensionIn and ExtensionOut provides customers with a mechanism that enables BAPIs to be enhanced without modifications.
    Return ParametersEach BAPI must have an export return parameter for returning messages to the calling application. To provide application programmers with a consistent error handling process for BAPI calls, all return parameters must be implemented in the same, standardized way.
    Selection ParametersStandardized selection parameters are used in BAPIs that can be used to search for specific instances of a business object type (e.g. in GetList() ). These parameters enable the BAPI caller to specify the relevant selection criteria.
    Test Run ParametersThe parameter TestRun is used in write BAPIs (Create() and Change() ), to check the entries for the object instance in the database before actually creating the object instance. The creation of the object instance is only simulated and data is not updated.
    Text Transfer ParametersTo transfer BAPI documentation texts (e.g. the documentation of a business object type), you have to create standardized text transfer parameters.

    Important things to remember..

    It is important to follow the guidelines below when develop9ng BAPIs:
    • BAPIs must not contain CALL TRANSACTIO or SUBMIT REPORT
    • BAPIs must not invoke a COMMIT WORK. instead use the BAPI TransactionCommit to execute the commit after the BAPI has executed.
    • BAPI structures must not use includes.
    • There should be no functional dependecies between two BAPIs
    • BAPIs must perform there own authorization check
    • BAPIs should not use dialogs
    • BAPIs must not cause the program to abort or terminate. re4levant messages must be communicated through the return parameter.

    BAPI/ALE Integration

    When you use the BAPIs for asynchronous messagning, the application in the sendig systen calls the generated ALE IDoc interface isntead of the BAPI.

    Asynchronous BAPIs use the ALE interface this way:

    • Creates an IDOC from the BAPI data
    • Sends the IDOC to the target system
    • Receives the IDOC in trhe target system, crreates the BAPI data from the IDoc and calls the BAPI
    An ALE interface for a BAPi is created in transaction BDBG.
    ultraluck 发表于:2008.01.13 22:19 ::分类: ( SAP ABAP ) ::阅读:(73次) :: Permanent link :: 引用 (0)

    2008 年 01 月 09日, 星期三

    创建BAPI程序的步骤

    创建BAPI程序的步骤

    1.定义BAPI Structure (Structure不能在BAPI中重复使用,因为一旦BAPI被释放,其Structure被冻结)T-CODESE11

    2.创建FUNCTION MODULET-CODESE37

    每个BAPI必须有自己的Function GroupFunction Group属性必须为RFC

    3.创建Business Object(T-CODESWO1)

    4.使用BAPI WIZARD创建API Method (T-CODE:SWO1:Utilities--API methods--methods)

    这样BAPI可以被外部程序调用

    5.Function Module符合BOR Method

    4.释放BAPI Function Module,

    释放Business Object Type,(先释放对象类型在释放对象类型下的组件)

    释放BAPI作为BOR的一种Method

    PathCODESWO1àEditàchange release statusàObject typeàTo modeled、、、、


    ultraluck 发表于:2008.01.09 10:45 ::分类: ( SAP ABAP ) ::阅读:(61次) :: Permanent link :: 引用 (0)

    2007 年 12 月 05日, 星期三

    SAP ABAP报表介绍

    一, 首先介绍一下ABAP的程序的类型:
    Program type(程序类型)Introductory statement(类型描述)
    1 REPORT(报表)
    M PROGRAM(屏幕程序)
    F FUNCTION-POOL(函数组)
    K CLASS-POOL(类组)
    J CLASS-POOL(接口组)
    T TYPE-POOL(类型池)
    二, 下面介绍报表中用到的事件以及作用:
    1. LOAD-OF-PROGRAM:程序开始执行时候自动调用
    这个事件在SUBMIT,CALL TRANSACTION,PERFORM等执行的时候系统会自动调用这个事件。所以无需声明即可。

    2. INITIALIZATION
    (1).只能用于报表程序
    (2).在选择屏幕出现之前执行,如果用逻辑数据库的话,这个是唯一能够修改选择屏幕初始值的地方。
    (3).通常的用法是在这里给选择屏幕中的字段赋值。
    3. AT SelectION-SCREEN
    (1).其实就像一个FORM,所以在这个事件里声明的变量都是局部变量。
    (2).根据SY-UCOMM这个系统变量可以判断用户的命令
    (3).在这个事件里响应的是屏幕上选择条件中的事件,例如CHECKBOX的选择与否,RADIOBUTTON的选择,LISTBOX的选择等等。所以分为以下几个方面:



    1. ... ON psel :在PARAMETER变化是触发的事件
    2. ... ON END OF sel :Select-OPTION触发的事件
    3. ... ON VALUE-REQUEST FOR psel_low_high :选择的帮助(F4)
    4. ... ON HELP-REQUEST FOR psel_low_high :选择的帮助(F1)
    5. ... ON RADIOBUTTON GROUP radi :单选按钮事件
    6. ... ON BLOCK block :框架的触发事件
    7. ... OUTPUT :响应屏幕上的事件,修改选择屏幕的唯一方法
    4. START-OF-SelectION
    报表程序必须执行的事件,在进入第二屏幕之前触发。
    5. GET
    获得逻辑数据库的值。前提是必须首先声明逻辑数据库。
    6. END-OF-SelectION
    第二屏幕显示完毕,结束处理。
    7. MODULE
    这个是当你调用自己定义的屏幕时,响应屏幕事件的方法。
    8. ENDMODULE
    9. CHECK
    只对逻辑数据库使用,检查是否取得数据。
    10. REJECT
    同样只对逻辑数据库使用,退出。
    11. STOP
    结束一个处理块。
    12. RETURN
    返回一个处理块。
    三, 附加说明:
    1. SET PF-STATUS:
    基本语法格式:SET PF-STATUS pfstat.
    扩展:
    1. ... EXCLUDING f oder ... EXCLUDING itab
    2. ... IMMEDIATELY
    3. ... OF PROGRAM progname
    这个是设置屏幕菜单,命令行等的命令,详细地信息我会在后面关于菜单设计的时候说明。
    2. SET TITLEBAR:
    设置屏幕标题,在屏幕显示之前调用。


    ultraluck 发表于:2007.12.05 12:00 ::分类: ( SAP ABAP ) ::阅读:(57次) :: Permanent link :: 引用 (0)

    SAP Query 应用

    QUERY是SAP的一项简单报表工具,它可为没有编程基础的用户用来生成简单的报表。第一次接触QUERY的时候,感觉也不是很复杂,因为它有图形化的界面,你可在上面托托拽拽,然后就可以见到你要的报表,可是这只是简单的应用,其实每个工具功能都是比较完善的,QUERY也不例外。


    QUERY是SAP的一项简单报表工具,它可为没有编程基础的用户用来生成简单的报表。第一次接触QUERY的时候,感觉也不是很复杂,因为它有图形化的界面,你可在上面托托拽拽,然后就可以见到你要的报表,可是这只是简单的应用,其实每个工具功能都是比较完善的,QUERY也不例外。

    要全面的理解QUERY,首先看一下QUICKVIWER。
    事务代码:SQVI。
    我感觉这是QUERY的一个简化,大体流程基本一致,但是在许多方面的功能都“缩水“了。体现如下:
    1。Quick Viewer所生成的报表是用户自定义的报表,只能由此用户自己使用、维护
    2。Quick Viewer只能使用存于数据库内的数据,不能进行计算(除小计、累计)
    3。提供与SAP内部工具如EIS,ABC,ALV及外部工具如Word,Excel借口
    4。无须也无法利用用户组、Functional area统一管理
    5。无法传输

    比较而言,QUERY就比较完善了,可是做起来也比较麻烦一下:
    1。生成用户组
    SAP菜单→工具→ABAP工作台→实用程序→SAP查询→用户组
    T-Code:SQ03
    2。创建Functional area(功能区)
    SAP菜单→工具→ABAP工作台→实用程序→SAP查询→信息集
    T-Code:SQ02
    3。创建SAP Query
    SAP菜单→工具→ABAP工作台→实用程序→SAP查询→查询
    T-Code:SQ01

    这些组件之间的关系有:
    1。Query的管理包括建立Functional area(功能区)和User Group(用户组),并将功能区分配到相应的用户组中去。
    2。Functional area(功能区)中定义query中需引用的表和字段。
    3。只有当一个用户属于至少一个用户组才可以创建、运行Queries。一个用户可以属于几个用户组。用户组中的用户享有相同的权力。
    4。当Functional area(功能区)分配给了某用户组,该用户组的成员即可以访问此功能区。


    ultraluck 发表于:2007.12.05 11:59 ::分类: ( SAP ABAP ) ::阅读:(71次) :: Permanent link :: 引用 (0)

    两个SQL语句写法的性能测试

    测试表: MARA,MAKT MARA表的记录数大约为44000 ======================================= 测试一:

    DATA: BEGIN OF it_mara OCCURS 0,

    matnr LIKE mara-matnr,

    maktx LIKE makt-maktx,

    END OF it_mara.

    第一种写法:

    SELECT matnr INTO it_mara FROM mara. APPEND it_mara.

    ENDSELECT.

    平均运行结果: 366,740微秒

    第二种写法:

    SELECT matnr INTO TABLE it_mara FROM mara.

    平均运行结果: 148,360微秒 =======================================

    测试二:

    DATA: BEGIN OF it_mara OCCURS 0,

    matnr LIKE mara-matnr,

    maktx LIKE makt-maktx,

    END OF it_mara.

    DATA: BEGIN OF it_makt OCCURS 0,

    matnr LIKE mara-matnr,

    maktx LIKE makt-maktx,

    END OF it_makt.

    第一种写法:

    LOOP AT it_mara.

    SELECT SINGLE maktx INTO it_mara-maktx FROM makt WHERE matnr = it_mara-matnr AND spras = sy-langu. MODIFY it_mara TRANSPORTING maktx.

    ENDLOOP.

    平均运行结果: 13,327,526微秒

    第二种写法:

    SELECT matnr maktx INTO TABLE it_makt FROM makt FOR ALL ENTRIES IN it_mara WHERE matnr = it_mara-matnr and spras = sy-langu. 平均运行结果: 5,787,685微秒

    =======================================


    ultraluck 发表于:2007.12.05 11:55 ::分类: ( SAP ABAP ) ::阅读:(55次) :: Permanent link :: 引用 (0)

    使用AT SELECTION-SCREEN事件验证用户输入条件的反思

    使用AT SELECTION-SCREEN事件验证用户输入条件的反思

    回想一下,为什么要在AT SELECTION-SCREEN事件验证用户输入条件?好像是第一次做ABAP培训中老师提到的,当时也没有觉得有什么问题,以后在程序中也就按照这样的思路去写代码了.像下面简单的代码,对我来说已经是司空见惯了.

    SELECT-OPTIONS: s_matnr FOR mara-matnr.

    AT SELECTION-SCREEN.
    IF s_matnr[] IS INITIAL.
    MESSAGE e001 WITH '请输入物料号!'.
    ENDIF.


    从逻辑上来看没什么问题,这样可以确实要求用户必须输入物料号这个条件.
    但是当用户输入多个物料号的时候,麻烦来了.用户一般已经在其它地方将需要输入的物料号复制到剪贴板上,希望能一次粘贴到选择条件中.但是有了上面的语句,用户必须复制一个物料号,粘贴到s_matnr对应的编辑框内,然后切换回物料号列表的窗口,复制剩余的物料号,点击"多项选择"按钮再进行粘贴,无形中多出了三个操作步骤.

    如果每天使用这样的报表使用几次,那可能也算不了什么.但是如果要几十甚至上百次使用这样的报表,您不觉得烦吗?

    如果在AT SELECTION-SCREEN事件中写了比较复杂的验证代码,那就更麻烦了.因为用户每次点击"多项选择"按钮都会触发AT SELECTION-SCREEN中的所有代码,那么对于用户来说,每次操作都需要一定时间的等待!另外一方面,AT SELECTION-SCREEN中的所有代码在触发START-OF-SELECTION事件前还会执行一次,对系统来说也是不必要的资源浪费.

    还是看看关于AT SELECTION-SCREEN的Online help吧!
    You should only perform very expensive checks with AT SELECTION-SCREEN

    考虑到上面的情况,大多数情况下面,我们还是把验证用户输入条件的代码放在START-OF-SELECTION事件处理中比较合适.

    ---------------------------------------------------

    对AT SELECTION-SCREEN又做了一些研究,如果在事件处理中加一些限制条件后,基本上和写在START-OF-SELECTION事件中效果相同,不过出错时的提示界面更友好,用户可以直接修改输入值,这也是使用START-OF-SELECTION事件不好的地方.代码框架如下:

    IF sscrfields-ucomm = 'ONLI' OR
    sscrfields-ucomm = 'PRIN' OR
    sscrfields-ucomm = 'SJOB'.
    * Your code here
    ENDIF.


    ultraluck 发表于:2007.12.05 11:50 ::分类: ( SAP ABAP ) ::阅读:(68次) :: Permanent link :: 引用 (0)

    ABAP中的事件详讲

    ABAP中的事件详讲 查看全文
    ultraluck 发表于:2007.12.05 11:06 ::分类: ( SAP ABAP ) ::阅读:(58次) :: Permanent link :: 引用 (0)

    2007 年 11 月 12日, 星期一

    ABAP/4开发环境1[转贴]

    ABAP/4开发环境1[转贴]

    ABAP/4表面看起来很简单,其实是一个复杂的语言。初学者常常感到很迷惑。只有知其然,你才能掌握这个语言。只有知其然并且知其所以然,你才能对这个令人兴奋的知识领域了解别人不了解的内容。
    正如熟练的程序员所知道的那样,初学者很快也会知道,创建ABAP/4程序不仅仅是创建一个程序。它常常涉及到创建开发对象(development object)用来支持所创建的程序。
    什么是R/3?
    R/3是为大公司数据处理所设计的一套集成的应用程序。是由德国的SAP公司开发的(SAPSystems Applications and Products for data processing)。R/3由运行环境和一组用SAP4GL语言ABAP/4编写的应用程序所组成。设计这些应用程序是为了满足大型商业应用数据处理的需要。R/3和其以前的版本R/2在制造业非常流行。
    R/3的目的是什么?
    R/3的唯一目的就是提供一组紧密集成的大型商业应用。这些应用是:生产计划(PPProduction Planning
    • 物料管理(MMMaterials Management
    • 销售和配送(SDSales and Distribution
    • 财务会计(FIFinancial Accounting
    • 控制(COControlling
    • 固定资产管理(AMFixed Assets Management
    • 项目管理(PSProject System
    • 工作流(WFWorkflow
    • ISISIndustry Solutions
    • 人力资源(HRHuman Resources
    • 工厂维护(PMPlant Maintenance
    • 质量管理(QMQuality Management
    这些应用程序有时被称为R/3的功能模块。
    传统上我们是对单个模块进行评估,从多个软件供应商购买这些单独的模块,组装在一起成为数据处理应用。这样在这些单独的模块之间就需要接口。例如,物料管理需要与销售和财务联系,工作流需要从人力资源获得信息。在实施和维护这些接口时花费了大量的时间和金钱。
    R/3预置了大多数大公司需要的核心商业应用。这些应用在同一个环境下共存。它们使用的是单个数据库和一组数据表。数据库的大小在12G到接近3T之间。标准的R/3配置有大约8000个数据表。
    为什么我们需要知道这些功能模块?
    作为一个ABAP/4程序员,知道这些功能模块是重要的。这是因为这些功能模块都是完全用ABAP/4编写的。要想成为一个熟练的R/3开发者,就必须了解这些功能模块。
    例如,假定你已熟悉ABAP/4,要求你编写一个财务报表,对企业的每个供应商的年度借贷进行汇总。你或许知道如何编写ABAP代码,你知道如何才能满足这个需求吗?
    又或者你的工作是承担了用ABAP/4开发新的应用程序。要求你设计一个系统,向潜在的客户提供股票行情。如果你不了解财务和销售系统,你就不知道你将创建的东西是否在R/3中已经存在了。你也不知道是否已经有了R/3数据表,包含了与你要存储的数据有类似甚至相同类型的数据。这些功能模块是高度集成的。“我要建立自己的数据表,保存自己的数据拷贝”,抱有这样想法的开发者很快就会发现他的数据是多余的,必须与数据库的已有数据同步。这样建立的应用程序没有充分利用R/3环境的高度集成的特性。
    我指出这一点是因为许多希望成为独立的咨询顾问的开发者认为,只需学习ABAP/4就可以开发R/3应用。学习ABAP/4当然是一个很好的开始,但仅仅是一个开始。那些有兴趣成为ABAP/4咨询顾问的人常常忽视了在功能模块知识训练的重要性。虽然功能模块知识可以在实际的工作中学习,但是我希望表明的是,学习ABAP/4语言只是迈向SAP万里长征的第一步。如果你希望成为一个成功的独立咨询顾问,你就需要掌握功能模块知识。
    了解Basis
    Basis就象是R/3的操作系统,它介于ABAP/4代码和计算机操作系统之间。因此,SAP喜欢称之为中间件。
    ABAP/4程序不能直接在操作系统上运行,需要一组程序(这组程序就是Basis)对其输入输出进行装载、解释和缓冲。
    Basis在某些方面有点像Windows环境。Windows启动后为Windows程序提供了运行环境。没有Windows,为Windows环境编写的程序就不能运行。
    Basis对于ABAP/4来说就象Windows对于Windows程序一样。BasisABAP/4
    程序提供了运行环境。没有BasisABAP/4程序就不能运行。当你启动R/3时,你可以认为启动了BasisBasis是一组带有接口的R/3系统程序,利用这些接口,用户就可以启动ABAP/4程序。
    为了安装Basis,安装者在操作系统的命令提示符下运行r3inst程序。像大多数安装过程一样,这将产生一个目录结构,并将一组可执行文件拷贝到这个目录结构。这些可执行文件作为一个整体就形成了Basis
    为了启动R/3系统,只需输入命令startsapBasis就被启动,处于运行状态,接受用户请求,运行ABAP/4程序。
    ABAP/4程序运行在保护性的Basis环境,它们不能在操作系统环境下运行。Basis读取ABAP/4代码,并向操作系统指令解释ABAP/4代码。

    ultraluck 发表于:2007.11.12 16:28 ::分类: ( SAP ABAP ) ::阅读:(77次) :: Permanent link :: 引用 (0)

    ABAP/4开发环境2[转贴]

    ABAP/4开发环境2[转贴]

    ABAP/4程序不能直接访问操作系统的功能,而是利用Basis功能进行文件I/O和在窗口中显示数据。与操作系统的分离使得ABAP/4程序不用修改就可运行在任何支持R/3的系统上。能运行R/3的平台如下:

    1.1 R/3支持的平台和数据库

    操作系统

    支持的硬件

    支持的前端

    支持的数据库

    AIX SINIX

    IBM SNI SUN

    Win 3.1/95/NT

    DB2 for AIX

    SOLARIS HP-UX

    Digital HP

    OSF/Motif

    Informix-Online

    Digital-UNIX

    Bull

    OS/2

    Oracle 7.1

    Macintosh

    ADABAS D

    Windows NT

    AT&T Compaq

    Win 3.1/95/NT

    Oracle 7.1

    Bull/Zenith

    OSF/Motif

    SQL Server 6.0

    HP (Intel) SNI

    OS/2

    ADABAS D

    IBM (Intel)

    Macintosh

    Digital (Intel)

    Data-General

    OS/400

    AS/400

    Win95 OS/2

    DB2/400

    SAP提供了一组工具管理Basis系统。
    Basis支持客户机/服务器模式。R/3是三层客户机/服务器模式,这三层是:
    表示层服务器:实际上是一个程序sapgui.exe,提供用户界面。
    应用服务器:一组可执行文件,它们解释ABAP/4程序,管理输入/输出。配置文件application server profile定义了应用服务器启动时启动的程序。
    数据库服务器
    这三层可以位于一台电脑上,也可以位于两台电脑上,实际使用时一般是位于三台电脑上。
    client有关的数据表和与client无关的数据表
    R/3的数据表分为两类:与client有关的数据表和与client无关的数据表。一个数据表是与client有关的,如果它的第一个字段类型是CLNT。这种类型的字段长度总是3,约定它的名称是mandt
    R/3有三个系统:开发、测试和产品。缺省地,每个系统有三个client000001066。开发和测试系统一般有3-6client。产品系统一般只有一个client
    SAP Open SQL
    Open SQLANSI SQL的子集。ABAP/4程序中使用Open SQL使得代码不用修改就可在不同的数据库环境运行。

    ultraluck 发表于:2007.11.12 16:23 ::分类: ( SAP ABAP ) ::阅读:(70次) :: Permanent link :: 引用 (0)

    ABAP/4开发环境3[转贴]

    ABAP/4开发环境3[转贴]

    初识ABAP/4
    开发对象包括programs, screens, tables, views, structures, data models, messages, includes
    ABAP/4程序主要有两种类型:
    • reports
    • dialog programs
    report的目的就是从数据库中读数据,以及输出数据。它仅由两个屏幕组成:selection screenoutput screen
    selection screen:主要包含输入字段,允许用户输入产生报告的条件。
    output screen:最终的报告。
    selection screen是可选的。
    Dialog Programreport更灵活也更复杂。它可以包含任意数量的screenScreen sequence可以在运行时动态改变。在每一个screen中,可以有input fields, output fields, pushbuttons, 和多个scrollable area
    所有的开发对象及其组件都是存储在R/3数据库中,例如,report的源代码就是存储在数据表dd010s中。
    程序名由2-8个字符组成,用户程序名要以yz开头。A~X开头的程序是系统程序。
    选择三个字符作为你的程序名称的前缀,例如,zkg。在后面的叙述中,“输入程序名称abc”,你应该输入zkgabc
    示例程序命名为ztxccnncc是章号,nn是序号。练习中用到的程序命名为ztyccnn,答案中的程序命名为ztzccnn。实用程序命名为y—xxxxx
    系统变量以sy开头,所以datum表示当前系统日期,sy-uzeit表示当前系统时间。所有的系统变量都在DDIC structure syst。在select语句中,常用到两个系统变量sy-subrcsy-dbcnt。找到了记录时,Sy-subrc0;否则为4Sy-dbcnt表示找到的记录的序号,第一条记录为1,第二条记录为2,最后一条记录的序号也是记录数。
    使用chain operator
    冒号(:)成为chain operator,例如要定义两个表,可以用如下代码:
    tables ztxlfa1.
    tables ztxlfb1.
    也可以用如下代码:
    tables: ztxlfa1, ztxlfb1.
    Select有两种形式。
    第一种形式是:
    select * from t1 [into wa] [where f1 op v1 and/or f2 op v2 ...]
    [order by f1].
    (other abap/4 statements)
    endselect.
    第二种形式是:
    select * from t1 [into wa] [where f1 op v1 and/or f2 op v2 ...].
    第一种形式可以提取多条记录,按主键查找,可以使用第二种形式,第二种形式只能提取一条记录,第二种形式比第一种形式更快。
    注释行用星号(*)和双引号(,如下所示:
    * This is a comment
    tables ztxlfa1. " This is also a comment
    ABAP/4程序的语句以英文句号结尾。
    浏览数据表数据的事务有四个SE16SE17SM30SM31

    ultraluck 发表于:2007.11.12 16:14 ::分类: ( SAP ABAP ) ::阅读:(59次) :: Permanent link :: 引用 (0)

    ABAP/4开发环境4[转贴]

    数据字典
    大多数ABAP/4程序都用到了数据字典(DDIC)对象。ABAP/4程序和DDIC对象的互锁机制使得深入了解R/3数据字典是基本的编程技巧。因此,从现在开始,我们将学习如何创建DDIC对象,例如table,data elementdomain
    Table的类型
    R/3中,有三种类型的tabletransparent tablepooled table,和 cluster table
    transparent table与数据库中的table有一对一的关系。他们有相同的名称,相同数量的字段,字段名也相同。transparent table用来存储应用数据,而pooled tablecluster table用来存储系统数据。
    pooled tablecluster table与数据库中的table有多对一的关系。他们可以有不同的名称,不同数量的字段,字段名也可以不同。
    Table Pool Pooled Table
    Table Pool是数据库中的一个table,它存储的是pooled tableR/3table pool存储大量的(数十到数千个)小table(每个只有10-100)Table pool减少了同时打开多个小table所需要的数据库资源。Pooled tableSAP主要用于存储定制数据。
    当安装一个大系统时,通常需要定制以便满足公司的特定需要。在R/3中,这是通过定制table实现的。定制table包含了编码、字段验证、数值范围以及R/3应用的参数。例如,定制table中包含了这样一些数据,国家编码、地区代码、汇率、折价方法等。
    系统初始实现时,功能分析员设置定制table中的数据。
    Table cluster cluster table
    Cluster table类似于pooled table。它们用来存储少数几个(大约2-10个)非常大的table。这几个表有相同的主键,需要同时访问它们。
    Table Cluster包含的tabletable pool少的多。与table pool不同,table cluster中的每个table有相同的主键,多个不同的table中有相同主键的行组成table cluster中的一行。Cluster table减少了读数据库的次数,从而提高了性能。
    Tablefield组成,创建field需要data elementData element包含了field标签和在线文档(也称为F1 help),field标签是field的文字说明,在屏幕上通常显示在field的左边,当光标在field输入栏时按F1键就显示F1 help
    Data element的定义要求domainDomain包含了field的技术特性,即字段长度和数据类型。
    Domaindata element是可重用的。一个Domain可以用于多个data element,一个data element可以用于多个field和多个table R/3预置了13000多个domain

    3.1 Table, Field, Data Element, Domain命名约定

    Object Type

    Max Name Length

    Allowed First Character

    Table

    10

    y, z

    Data element

    10

    y, z

    Domain

    10

    y, z

    Field

    10

    Any character

    Field可以用除了保留字以外的任何字符开头,DDIC table trese包含了这些保留字。
    创建的对象必须激活(activate)才能使用,对象修改后必须重新激活变更才有效。

    ultraluck 发表于:2007.11.12 16:09 ::分类: ( SAP ABAP ) ::阅读:(108次) :: Permanent link :: 引用 (0)

    2007 年 09 月 28日, 星期五

    转换程序 Conversion

    发个帖---转换程序

    今天遇到一个问题,在定义cost center的时候,输入的编号是1234,可是table里存储的是‘0000001234’,很是纳闷;
    于是乎查看了一下Field:KOSTL的定义,domain也是KOSTL,domain定义的 其中一项 Convers. routine定义的是: ALPHA,这是啥咚咚,F1查看,如下:
    Conversion routine
    Conversion takes place when converting the contents of a screen field from display format to SAP-internal format and vice versa and when outputting with the ABAP statement WRITE, depending on the data type of the field.

    If standard conversion is not suitable, it can be overridden by specifying a conversion routine in the underlying domain.

    A conversion routine is identified by its five-place name and is stored as a group of two function modules. The function modules have a fixed naming convention. The following function modules are assigned to conversion routine xxxxx:

    CONVERSION_EXIT_xxxxx_INPUT
    CONVERSION_EXIT_xxxxx_OUTPUT
    The INPUT module performs the conversion from display format to internal format. The OUTPUT module performs the conversion from internal format to display format.

    If a screen field refers to a domain with a conversion routine, this conversion routine is executed automatically each time an entry is made in this screen field or when values are displayed with this screen field.
    原来是定义的转换程序,在Screen中输入1234之后,调用了
    CONVERSION_EXIT_ALPHA_INPUT 将 1234 转换成了0000001234,存贮到table中,而在从table读出的时候,相反调用
    CONVERSION_EXIT_ALPHA_OUTPUT 将 0000001234 转换成1234 Dispay。。。。
    呵呵,为什么这样呢,有啥好处?

    为了排序~~~
    比如:
    1,
    2,
    3,
    11,
    12,
    如果按原有长度存贮,排序出来后会是这样:
    1,
    11,
    12,
    2,
    3,
    在前面加了定长0,就不会出现这个问题了


    ultraluck 发表于:2007.09.28 11:01 ::分类: ( SAP ABAP ) ::阅读:(70次) :: Permanent link :: 引用 (0)

    2007 年 09 月 22日, 星期六

    sap Program DEMO info

    BALVBT01 Example SAP program for displying multiple ALV reports on one page BCALV_GRID_DEMO ALV Dialog grid demo (4.6) SHOW_COLO Displays all colours available SHOW_ICON Displays all icon available RGUGBR00 Substitution/Validation and rules utility RKCTSEAR Search source code of various programs for up to two strings. Also see RPR_ABAP_SOURCE_SCAN or use search in source functionality via SE80 RPCIFU01 Display File RPCIFU03 Download Unix File to PC RPCIFU04 Upload PC File to Unix File RPR_ABAP_SOURCE_SCAN Search ABAP code for a string. Much more flexible than RSRSCAN1 or RKCTSEAR RSBDCBTC Submit a BDC job with an internal batch number and wait for the end of the batch input session RSBDCDRU Prints the contents of a Batch Input session. No options for error transactions only RSBDCOS0 Execute OS Command (Logged in SYSLOG and Trace Files) RSBDCSUB Process batch input sessions automatically RSBTCDEL Delete batch jobs RSCONN01 SAPconnect: Start Email Send Process RSCSAUTH Maintain/Restore Authorization Groups RSINCL00 Extended ABAP Program Reference List RSMODRES Restore enhancement projects after upgarde RSORAREL Check Oracle Version RSPARAM Display all instance parameters RSPO0041 Delete Old Spool Requests RSSNAPDL Reorganization Program for Table SNAP of Short Dumps RSTRANSP Transport Report Variants RSTXFCON SAPscript: Conversion of Page Format for Forms RSTXPDFT4 Convert spool request to PDF document RSTXPDFT5 GUI download of a spool request RSTXSCRP SAPscript Export to Dataset / SAPscript Import from Dataset (Upload and download SAPScript layout sets) RSTXTRAN Transfer of SAPscript Texts(standard texts) to a transport RSUSR003 Check the Passwords of Users SAP* and DDIC in All Clients RSUSR006 List of Users with Incorrect Logons RSVARFIT Adjust Variants to Modified Selections RSVTPROT Evaluation of change logs RSWBO052 Change Object Directory Entries RSWBO060 Include Objects in a Transport Request SAPMSUU0 Program for user maintenance(SU01), Maybe useful if you do not have access to the actual SU01 transaction code.
    ultraluck 发表于:2007.09.22 22:30 ::分类: ( SAP ABAP ) ::阅读:(122次) :: Permanent link :: 引用 (0)

    一些优秀的sap网站

    著名的SAP论坛:(人气比较旺,可以找到很多问题的回答) http://www.sapfans.com/ 著名的It专业网站的SAP部分:(查找部分资料) http://sap.ittoolbox.com/ SAP门户:(什么都有,什么都不深入) http://www.sapgenie.com/ http://www.sap-directory.com/ http://www.planetsap.com/ SAP的Basis与ABAP网站:(对其他模块也有相当价值,推荐初学者) http://www.sap-basis-abap.com/ http://www.planetsap.com/ SAP的IMG网站:(适合初学者) http://www.sap-img.com/ 专门研究SAP的网站 http://www.searchsap.com http://www.100easy.com/
    ultraluck 发表于:2007.09.22 18:20 ::分类: ( SAP ABAP ) ::阅读:(76次) :: Permanent link :: 引用 (0)

    SAP Dialog From Program [转]

    Step 1: Create A Program: ZZW_DIALOG_FORM_LUW
    Step 2: Data Define Section.
    There you must Define:
    Data ok_code TYPE Sy-Ucomm.

    Step 3: Call SCREEN SCREEN_NUMBER.
    e.g: Call Screen 100.

    Setp 4: Double Click Screen_Number.
    e.g: Double Click 100.

    -Screen Painter
    1) Element List.
    Name Type
    OK_CODE OK



    -Flow Logic
    Write PBO / PAI Process Section.
    In Flow Logic Are All Module Define.

    e.g:
    Process Before OutPut.
    Module Init.

    Process After Input.
    Module exit at exit-command.
    ...
    Module Select.

    At There ,You Can Double Click Module and Go To The Program to Write Module.

    Module Implementation.
    e.g :
    Module exit input.
    Leave Program.
    EndModule.

    2)Screen Painter - Design Screen.
    Click - Layout or Point GO TO -> Layout.

    Step 5: Implementation PBO Module Section.
    e.g :
    Module Init OutPut.
    Set PF-STATS 'BASIC'.
    Sflight-Carrid = 'LH'.
    Sflight-Connid = '400'.
    Sflight-fldate = Sy-datum.
    EndModule.

    Set PF-Stats is Initialization Screen Menu.
    e.g: Set PF-Stats 'BASIC'.
    'BASIC' is Screen Menu Name. Inclue [ Menu Bar ] , [Application

    Toolbar],[Function Keys]


    ------
    Dialog From Complete Program: ZZW_DIALOG_FORM_LUW

    *-----------------------------------------------------------------------
    *
    * Company ASAT Company Limited
    *
    * ProgrameName: ZZW_DIALOG_FORM_LUW
    *
    * Author: Wei_Zhu
    *
    * Date: 05/12/2006
    *
    * Description: Study SAP Dialog Form Program and LUW(SAP Lock Databse
    * Objec.)
    *
    *-----------------------------------------------------------------------
    REPORT ZZW_DIALOG_FORM_LUW MESSAGE-ID sabapdocu. .

    TABLES sflight.

    DATA text(8) TYPE c.

    DATA ok_code TYPE sy-ucomm.

    CALL SCREEN 100.

    *&---------------------------------------------------------------------*
    *& Module init OUTPUT
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    module init output.
    SET PF-STATUS 'BASIC'.
    sflight-carrid = 'LH'.
    Sflight-connid = '400'.
    * sflight-fldate = sy-datum.
    endmodule. " init OUTPUT
    *&---------------------------------------------------------------------*
    *& Module exit INPUT
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    module exit input.
    LEAVE PROGRAM.
    endmodule. " exit INPUT
    *&---------------------------------------------------------------------*
    *& Module Enqueue INPUT
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    module Enqueue input.
    Case ok_code.
    when 'ENQUEUE'.
    CALL FUNCTION 'ENQUEUE_EDEMOFLHT'
    Exporting
    mode_sflight = 'X'
    carrid = sflight-carrid
    connid = sflight-connid
    fldate = sflight-fldate
    Exceptions
    foreign_lock = 1
    system_failure = 2
    Others = 3.

    CASE sy-subrc.
    WHEN 0.
    MESSAGE i888 WITH 'Enqueue successful'(001).
    WHEN 1.
    text = sy-msgv1.
    MESSAGE e888 WITH 'Record already'(002) 'locked by'(003)
    text.
    CALL TRANSACTION 'SM12'.
    WHEN 2 OR 3.
    MESSAGE e888 WITH 'Error in enqueue!'(004)
    'SY-SUBRC:' sy-subrc.
    ENDCASE.
    WHEN 'DEQUEUE'.
    CALL FUNCTION 'DEQUEUE_EDEMOFLHT'
    EXPORTING
    mode_sflight = 'X'
    carrid = sflight-carrid
    connid = sflight-connid
    fldate = sflight-fldate
    EXCEPTIONS
    OTHERS = 1.
    CASE sy-subrc.
    WHEN 0.
    MESSAGE i888 WITH 'Dequeue successful'(005).
    WHEN 1.
    MESSAGE e888 WITH 'Error in dequeue!'(006).
    ENDCASE.
    WHEN 'SM12'.
    call transaction 'SM12'.
    WHEN 'SELECT'.
    MESSAGE i888 WITH 'SY-SUBRC:' sy-subrc.
    ENDCASE.
    endmodule. " Enqueue INPUT
    *&---------------------------------------------------------------------*
    *& Module select INPUT
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    module select input.
    * case ok_code.
    * WHEN 'SELECT'.
    * SELECT * FROM sflight WHERE carrid = sflight-carrid
    * AND connid = sflight-connid
    * AND fldate = sflight-fldate.
    * ENDSELECT.
    MESSAGE i888 WITH 'xxxxxxx'.
    * ENDCASE.
    endmodule. " select INPUT


    ultraluck 发表于:2007.09.22 12:34 ::分类: ( SAP ABAP ) ::阅读:(115次) :: Permanent link :: 引用 (0)

    2007 年 09 月 19日, 星期三

    什么是增强?

    做你自己想要做的而SAP标准功能有没提供的.

    用户增强: 所有的Enhancement在表MODSAP,用户增强大概有三类

    MODSAPEnhancement, TFDIR是看是否此enhancement被激活,就看字段MAND是否是C而已

    1. E Enhancement exits :就是常说的写User_exit ,经常使用

    2. C GUI codes 没用过

    3. 3. S Subscreens 屏幕增强

     查看全文

    ultraluck 发表于:2007.09.19 16:05 ::分类: ( SAP ABAP ) ::阅读:(121次) :: 评论 (0) :: 引用 (0)

    2007 年 09 月 18日, 星期二

    如何查找事务代码所在程序的用户出口

    如何查找事务代码所在程序的用户出口  查看全文
    ultraluck 发表于:2007.09.18 16:29 ::分类: ( SAP ABAP ) ::阅读:(87次) :: 评论 (0) :: 引用 (0)

    SD相关的BADI

    HU_BADIBusiness Add-Ins for Handling Units
    LE_SHP_BADIBusiness Add-Ins in Shipping
    LE_TRA_BADIBusiness Add-Ins in Transportation
    LE_WM_BADIBusiness Add-Ins in Warehouse Management
    MRM_BADIBusiness Add-Ins in Invoice Verification
    PL_PACKINST_BADIBusiness Add-In in the Packing Instruction
    S_BADI_FORMULA_BUILDERBADI Implementation with Formula Builder
    VA_BADIBADIs R/3 Sales
    VF_BADIBAdIs for Billing
     查看全文
    ultraluck 发表于:2007.09.18 15:06 ::分类: ( SAP ABAP ) ::阅读:(73次) :: 评论 (0) :: 引用 (0)

    如何从SAP中查找BADI

    BADI作为SAP的第三代用户出口,他的应用也越来越广泛,但如何找到合适的badi是许多abap程序员的困惑。我这里就介绍一下我个人的应用的经验,供大家参考。

    1、badi对象的信息存储在SXS_INTER, SXC_EXIT, SXC_CLASS 和SXC_ATTR 这四个表中(参见SECE包);

    2、sap程序都会调用cl_exithandler=>get_instance来判断对象是否存在,并返回实例;其实get_instance就是对上述几个表和他们的视图(V_EXT_IMP 和 V_EXT_ACT)进行查询和搜索。

    3、基于这个机理,我查用ST05来监控一个TCODE来跟踪,然后选择查找有关上述几个表和视图的操作,就可获得相关BADI。

    4、se18 查找接口,se19 实现接口就可以实现用户增强。
    示例:用LE_SHP_DELIVERY_PROC控制跨月Cancel

    METHOD IF_EX_LE_SHP_DELIVERY_PROC~CHANGE_DELIVERY_HEADER .
    data : thismonth(2) type c.
    data : wa_likp type line of SHP_LIKP_T.
    data : wa_log type line of SHP_BADI_ERROR_LOG_T.
    clear ct_log[],thismonth.
    thismonth = sy-datum+4(2). "----->這一個月的月份
    loop at it_xlikp into wa_likp.
    check IS_V50AGL-WARENAUSG_STORNO ='X'."--->代表作GI cancel
    if wa_likp-WADAT_IST+4(2) < thismonth.
    wa_log-VBELN = cs_likp-vbeln.
    wa_log-MSGTY = 'E'. "錯誤訊息
    wa_log-MSGID = 'ZDN_ERROR'. "這一個class要自己建
    wa_log-MSGNO = '001'.
    append wa_log to ct_log. "Error log寫入
    endif.
    endloop.
    ENDMETHOD.

     查看全文
    ultraluck 发表于:2007.09.18 15:02 ::分类: ( SAP ABAP ) ::阅读:(110次) :: 评论 (0) :: 引用 (0)

    SAP用户出口的类型

    sap的用户出口总共有三代:

    1、第一代
    sap提供一个空代码的子过程,在这个子过程中用户可以添加自己的代码,控制自己的需求。这类增强都需要修改sap的标准代码。
    示例:USEREXIT.. in SAPMV45A

    2、第二代
    sap提供的是CUSTOMER-FUNCTION,它是通过SMOD和CMOD完成实现。参见我的http://blog.csdn.net/CompassButton/archive/2006/08/31/1150258.aspx

    3、第三代
    sap提供的第三代的用户出口就是BADI,他的调用方式是CALL METHOD (instance),(相关的TCODE是SE18和SE19),你可以通过EXIT_HANDLER这个单词查找BADI。

     查看全文
    ultraluck 发表于:2007.09.18 14:57 ::分类: ( SAP ABAP ) ::阅读:(76次) :: 评论 (0) :: 引用 (0)

    SAP用户出口

    一、User EXIT
    这种出口据说是第一代的用户出口,它们include在SAP标准程序的源代码里,可以说他们是源代码的一部分,你改了这种出口就相当于改了SAP标准程序,是需要申请access key才能更改的,不需要建立PROJECT。很多标准程序里心ZZ或者Z结尾的包括程序里都有以user_exit_开始的子程序,例如上面mv50afz1里的user_exit_save_document.我做绝大部分SD的出口里,都是这种形式的。
    二、Customer exit
    可以把这种出口看成第二代的的出口,好像增强(ehancement)就是指这类,不知道我有没有理解正确,这种出口又包括了六种不同的类型.
    1)function exit,2)menu exit,3)table exit,4)field exit,5)screen exit,6)keyword exit,但我的好像只做过第一种,就是function exit.这种出口是以FM的形式存在的,其开发的方式,就像Herman_wenzhenzh所说的那样,找到相关的增强后,建立PROJECT,然后在componemt里有FM,在FM里有以Z开始INCLUDE程序,双击这个INCLUDE程序进入后就可以根据FM里IMPORT/EXPORT/CHANGING/TABLE等来开发你们的需求。这些增强是不需要申请ACCESS KEY的,因为他们不属于SAP标准程序里的一部分。这种增强FM的命名方式是EXIT_programname_NNN,NNN是3个数字的序号,实际上在SAP的标准程序里,会用到下面的方式调用该增强的逻辑:call customer-function 'NNN',从而来达到用户的需求。SD好像也有这种形式的增强,但是我没有怎么做过,不太好说那一个能实现楼主的需求。我做的MM里很多都是这种形式的。其他的例如menu exit/screen exit我就没有怎么做过,不好说什么。
    三、BADI
    这是基于面向对像的第三代增强。自己也只做过两次,特别是自己对SAP的面向对像还搞不清楚,寒~~`一时之间说不出个所以。前面介绍的两种出口增强,都是SAP提供固定的点给用户进行开发,而BADI这种增强,则让顾问们很自由地定义需要增强的地方,据说SAP很多的行业方案就是用这种形式来扩展的。
    如果你需要找某一个出口/增强,还是回去看SPRO,每一个模块里都基本有system modificatio或者BADI的说明,这样能更快找到相关的东西。

    ultraluck 发表于:2007.09.18 14:49 ::分类: ( SAP ABAP ) ::阅读:(151次) :: 评论 (0) :: 引用 (0)

    2007 年 09 月 08日, 星期六


    ultraluck 发表于:2007.09.08 17:34 ::分类: ( SAP ABAP ) ::阅读:(43次) :: 评论 (0) :: 引用 (0)

    2007 年 09 月 06日, 星期四

    基础知识1

    基础知识1

    ABAP/4是英文Advanced Business Application Programming的缩写,是SAP R/3商用系统的应用程序开发工具

    ABAP/4是所有SAP R/3应用的基础,也是进行SAP R/3二次开发的最主要的工具,是我们对SAP R/3系统进行应用分析、二次开发的主要工具、

    必由之路

    I.首先必须了解ABAP/4的处理对象

    基本对象
    vABAP/4 Dictionary
    vReport
    vBatch Input
    vDialog
    vSAPScript
    vFunction
    vQuery

    高级对象
    vBAPI
    vModule
    vSmartform
    vEvent
    v……

    II.了解SAP的ABAP/4培训课程结构

    Level 1
    Schedule 1 BC400 ─ ABAP Workbench: Concepts and Tools 3 Days
    Level 2
    Schedule 1 BC402 ─ ABAP Programming Techniques 2 Days
    Schedule 2 BC430 ─ ABAP Dictionary 2 Days
    Schedule 3 BC405 ─ Techniques of List Processing and SAP Query 3 Days
    Schedule 4 BC420 ─ Data Transfer 5 Days
    Schedule 5 BC410 ─ Programming User Dialogs 5 Days
    Schedule 6 BC460 ─ SAP scrip: Forms Design and Text Management 3 Days
    Level 3
    Schedule 1 BC404 ─ ABAP Objects: Object Oriented Programming in R/3 3 Days
    Schedule 2 CA610 ─ CATT: Test Workbench and Computer Aided Test Tool 2 Days
    Schedule 3 BC414 ─ Programming Database Updates 2 Days
    Schedule 4 BC415 ─ Communication Interfaces in ABAP 2 Days
    Schedule 5 BC490 ─ ABAP Performance Tuning 3 Days
    Level 4
    MySAP.com Partner Academic

    III.SAP对ABAP/4程序员的要求

    Junior programmer: Attend course - Level 1 and partial Level 2 (BC402, BC430, BC405)
    Skills – 1. ABAP commands syntax
    2. Create dictionary objects (Table, view…)
    3. Create SAP Query list 、Report list and Logic-Database
    Advance programmer: Attend course - Level 1 and Level 2
    Skills – 1. Extend junior programmer’s skills
    2. Create Data conversion programs (Batch-input)
    3. Create user dialog programs (On-line)
    4. Create Forms (Layout-set)
    Senior programmer: Attend course - Level 1 , Level 2 and Level 3
    Skills – 1. Extend junior and advance programmer’s skills
    2. Using ABAP object and BAPIs in ABAP programs
    3. Tuning ABAP program performance and adjust frame of program
    4. Future ABAP programming
    ABAP consultant: Attend course - All Levels
    Skills – ABAP certificate consultant

    IV.我们的基础目标

    v创建、维护ABAP/4 Dictionary对象
    vReport程序设计
    vBatch Input程序设计
    vDialog程序设计
    vSAPScript Layout Set和处理程序设计

    V.我们希望的进一步目标

    vBAPI程序设计
    vFunction程序设计
    vSmartform程序设计


    ultraluck 发表于:2007.09.06 08:30 ::分类: ( SAP ABAP ) ::阅读:(111次) :: 评论 (0) :: 引用 (0)

    2007 年 08 月 24日, 星期五

    内表(Internal Table)之sy-tfill的用法

    内表(Internal Table)之sy-tfill的用法 查看全文
    ultraluck 发表于:2007.08.24 17:26 ::分类: ( SAP ABAP ) ::阅读:(116次) :: 评论 (0) :: 引用 (0)

    内表(Internal Table)之带Where条件(Clause)的Loop at - []


    内表(Internal Table)之带Where条件(Clause)的Loop at - []

     查看全文
    ultraluck 发表于:2007.08.24 17:24 ::分类: ( SAP ABAP ) ::阅读:(77次) :: 评论 (0) :: 引用 (0)

    2007 年 08 月 09日, 星期四

    FOR ALL ENTRIES IN itab WHERE cond使用注意事项

    FOR ALL ENTRIES IN itab WHERE cond使用注意事项:

    * Suppost FTAB is filled as follows:
    *
    * CARRID CONNID
    * --------------
    * LH 2415
    * SQ 0026
    * LH 0400

    1.SELECT CARRID CONNID PRICE

    FROM SFLIGHT

    INTO TABLE IT_PRICE

    FOR ALL ENTRIES IN IT_SFLIGHT

    WHERE CARRID = IT_SFLIGHT-CARRID

    AND CONNID = IT_SFLIGHT-CONNID'.

    在 WHERE 条件中,IT_SFLIGHT-CARRID和IT_SFLIGHT-CONNID这些列将用作占位符。
    该 SELECT 语句的结果集是 SELECT 语句的所有结果集的联合,这些结果集是用内部表 IT_SFLIGHT 中的相应值在每一行上替换占位符的结果。实际上该WHERE子句的特殊变式就是下面WHERE基本语句的简略写法。

    SELECT DISTINCT CARRID CONNID PRICE

    FROM SFLIGHT

    INTO TABLE IT_PRICE

    WHERE ( CARRID = 'LH' AND CONNID = '2415' ) OR

    ( CARRID = 'SQ' AND CONNID = '0026' ) OR

    ( CARRID = 'LH' AND CONNID = '0400' ) .


    2.使用该语句,对于最后得出的结果集系统会自动删除重复行。
    因此如果你要保留重复行记录时,记得在SELECT语句中添加足够键值项目
    (有必要时,增加全部键值项目),
    以保证结果集中所需重复项目不会被删除。
    (例如选取支付金额时,支付事件可能不同,但金额可能相同,
    此时一定要注意,以避免错误删除结果记录。)

    3.FOR ALL ENTRIES IN后面使用的内部表itab如果为空,系统将视为无条件选取,
    将当前CLIENT下所有记录选出。因此为避免无意义的全件检索,
    在使用该语句前一定要判断内部表itab是否为空,为空时不执行包含该语句的数据库检索处理。

    4.由于itab-f实际上是作为占位符被替换,所以内部表itab中不要包含HEADER行(项目标识名称行),以免造成混淆,检索出错。

    5.内部表itab中作为条件替换用项目的类型和长度,
    一定要和检索数据库中对应的项目相同,否则编译不能通过。

    6.对于内部表itab中作为条件替换用项目,不能使用LIKE,BETWEEN,IN比较操作符。
    因为这些比较操作符都是不确定比较操作符(将选择条件设定在一个范围内),
    而FOR ALL ENTRIES IN语句的作用相当于将选择条件块全部并列开来,用OR连接,
    如果每个OR分支中又是不确定的范围,那么系统性能将大大降低,
    因此R/3系统在使用该语句时禁止使用不确定比较操作符。

    7.使用该语句时,ORDER BY语句和HAVING语句将不能使用。

    8.使用该语句时,除COUNT( * )以外的所有合计函数(MAX,MIN,AVG,SUM)都不能使用。

    1. Duplicates are automatically removed from the resulting data set. Hence care should be taken that the unique key of the detail line items should be given in the select statement.
    2. If the table on which the For All Entries IN clause is based is empty, all rows are selected into the destination table. Hence it is advisable to check before-hand that the first table is not empty.
    3. If the table on which the For All Entries IN clause is based is very large, the performance will go down instead of improving. Hence attempt should be made to keep the table size to a moderate level.


    ultraluck 发表于:2007.08.09 14:11 ::分类: ( SAP ABAP ) ::阅读:(155次) :: 评论 (0) :: 引用 (0)

    提高[FOR ALL ENTRIES]查询的效率

    代码实例:
    DATA: it_mara TYPE STANDARD TABLE OF mara,
    wa_mara TYPE mara,
    it_makt TYPE STANDARD TABLE OF makt,
    wa_makt TYPE makt,
    it_temp_mara TYPE STANDARD TABLE OF mara,
    wa_temp_mara TYPE mara.
    * Get all the records from MARA
    SELECT *
    FROM mara
    INTO TABLE it_temp_mara.
    IF sy-subrc = 0.
    IF NOT it_temp_mara[] IS INITIAL.
    * 具有重复数据的内表
    DO 100 TIMES.
    APPEND LINES OF it_temp_mara TO it_mara.
    ENDDO.
    IF NOT it_mara[] IS INITIAL.
    * Select MAKT
    PERFORM select_makt.
    * 排过序的内表
    SORT it_mara BY matnr.
    PERFORM select_makt.
    * 删除了重复数据的内表
    DELETE ADJACENT DUPLICATES FROM it_mara COMPARING matnr.
    PERFORM select_makt.
    ENDIF.
    ENDIF.
    ENDIF.
    *&---------------------------------------------------------------------*
    *& Form select_makt
    *&---------------------------------------------------------------------*
    * Select data friom MAKT
    *----------------------------------------------------------------------*
    FORM select_makt .
    DATA: t1 TYPE i,
    t2 TYPE i,
    tmin TYPE i.
    REFRESH it_makt[].
    GET RUN TIME FIELD t1.
    SELECT *
    FROM makt
    INTO TABLE it_makt
    FOR ALL ENTRIES IN it_mara
    WHERE matnr = it_mara-matnr.
    GET RUN TIME FIELD t2.
    tmin = t2 - t1.
    tmin = tmin .
    WRITE:/ ' Time(ms) = ', tmin.
    ENDFORM.
    *----------------------------------------------------------------------*

    2007/03/22 Program ZTEST00100 1

    Time(ms) = 1,087,713 "具有重复数据的内表
    Time(ms) = 1,077,911 "排过序的内表
    Time(ms) = 11,610 "删除了重复数据的内表

    由上边的执行时间分析,可以得出以下结论:

    ·使用FOR ALL ENTRIES 时内表中不要有重复的数据

    ·对内表进行排序


    ultraluck 发表于:2007.08.09 14:01 ::分类: ( SAP ABAP ) ::阅读:(104次) :: 评论 (0) :: 引用 (0)

    2007 年 07 月 28日, 星期六

    FUNCTION ALV中加按钮.doc

    Add Button to ALV Toolbar with REUSE_ALV_LIST_DISPLAY

    How to add button to ALV toolbar using REUSE_ALV_LIST_DISPLAY?

    In the program which calls ALV using REUSE_ALV_LIST_DISPLAY,
    I have to add a new button.
    I saw the demo program BCALV_GRID_08, which is written using ABAP-Controls.
    In that example, the button is added using TOOLBAR event of cl_gui_alv_grid.
    Could you help me to implement the same logic using REUSE_ALV_LIST_DISPLAY parameters.

    you should copy the 'STANDARD' GUI status from program SAPLKKBL using transaction SE90 -->Programming SubObjects--> Gui Status.

    Execute this transaction to get to next screen. select status using checkbox. click on GUI Status --> Copy.

    Enter your Z program name and the name you what for this status - you can keep it as 'STANDARD' to be simple.

    Then you can edit the new status to add or delete buttons. This will also bring in the standard SAP ALV functionality such as sorting/subtotaling etc...

    When you call 'REUSE_ALV_GRID_DISPLAY' make sure you pass it the new status name.

    an example of one of mine:
    call function 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    i_callback_program = 'ZSDBOLST_REPORT'
    i_callback_pf_status_set = 'STANDARD' <---------
    i_callback_user_command = 'USER_COMMAND'
    i_structure_name = 'I_BOLACT'
    i_grid_title = 'BOL Action Report'(031)
    is_layout = gs_layout
    it_fieldcat = gt_fieldcat[]
    i_save = 'A'
    is_variant = v_variant
    TABLES
    t_outtab = i_bolact
    EXCEPTIONS
    program_error = 1
    others = 2.

    I just tried the same procedure ,but my entire application toolbar disappeared and a lock icon appears next to the application toolbar in my copied pf-status.
    Could you advice what might have gone wrong ?

    As identified with the FM's help you can do the following.

    1). Using SE80 (I think) you can copy a GUI status from one program to another. It mentions which one in the FM's help.
    2). Create a form named like so:

    Code:
    *****************************************************************
    * Form Set_pf_status
    * Notes: Called by FM REUSE_ALV_GRID_DISPLAY
    *****************************************************************
    FORM set_pf_status USING rt_extab TYPE slis_t_extab.
    SET PF-STATUS 'ZSTANDARD'.
    ENDFORM. "Set_pf_status

    In the above case the GUI status copied was named ZSTANDARD and adjusted accordingly, adding and removing the desired buttons. A button was added called '%DELETE'.

    3). Create the following report:
    Code:
    *****************************************************************
    * Form User_command
    * Notes: Called by FM REUSE_ALV_GRID_DISPLAY
    * Detects whether the icon/button for
    * 'Return Tag Deletion' has been pressed. If it has then
    * detect whether any rows have been highlighted and then
    * set the delete flag.
    *****************************************************************
    FORM user_command USING r_ucomm LIKE sy-ucomm
    rs_selfield TYPE slis_selfield.
    DATA: li_count TYPE I.
    IF r_ucomm EQ '%DELETE'.
    LOOP AT %g00 WHERE mark EQ 'X'.
    ADD 1 TO li_count.
    ENDLOOP.
    IF li_count GT 0.
    gc_delete_flag = 'X'.
    r_ucomm = '&F03'. "Back arraow
    ELSE.
    MESSAGE W000 WITH 'Please highlight the rows to be deleted!'.
    ENDIF.
    ENDIF.
    ENDFORM. "User_command

    As I've added an extra button to indicate which records should be deleted I need to identify a form to be called to process when this button is chosen.

    Then when you call the ALV function you to specify the following extra details:

    Code:
    call function 'REUSE_ALV_GRID_DISPLAY'
    exporting i_callback_program = gc_repid
    I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
    I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
    i_grid_title = lc_grid_title
    is_layout = lc_layout
    it_fieldcat = gt_fieldcat
    it_sort = sort
    i_save = l_save
    is_reprep_id = l_bbs_id
    is_variant = l_variant
    tables t_outtab = %g00
    exceptions program_error = 1
    others = 2.

    The parameters in capitals are the extra ones that need to be added.


    ultraluck 发表于:2007.07.28 17:05 ::分类: ( SAP ABAP ) ::阅读:(180次) :: 评论 (0) :: 引用 (0)

    基本的ALV例子

    参照程序:zsd_return_rate

    ***************************************************************
    ** about alv **
    ***************************************************************
    DEFINE add_field.
    wa_field-fieldname = &1.
    wa_field-reptext_ddic = &2.
    append wa_field to it_field.
    END-OF-DEFINITION.

    TYPE-POOLS slis.
    DATA: gs_layout TYPE slis_layout_alv.
    DATA: g_repid TYPE sy-repid.
    DATA: it_field TYPE slis_t_fieldcat_alv.
    DATA: wa_field TYPE slis_fieldcat_alv.
    g_repid = sy-repid.
    gs_layout-colwidth_optimize = 'X'.
    gs_layout-box_fieldname = 'SEL'.

    *add_field 'BSTKD' '订单编号'. "bstkd一定要大写
    add_field 'VBELN' '订单编号'.
    add_field 'BSTKD' '采购订单编号'.
    add_field 'ERDAT' '订单创建日期'.
    add_field 'AUART' '销售订单类型'.
    add_field 'KUNNR' '售达方'.
    add_field 'NAME1' '售达方描述'.
    add_field 'POSNR' '行项目'.
    add_field 'MATNR' '物料编码'.
    add_field 'KWMENG' '订单数量'.
    add_field 'ARKTX' '物料描述'.
    add_field 'MATKL' '物料组'.
    add_field 'WGBEZ' '物料组描述'.
    add_field 'STPRS' '物料标准价格'.
    DATA: it_sort TYPE slis_t_sortinfo_alv,
    ls_sort TYPE slis_sortinfo_alv.
    ls_sort-fieldname = 'VBELN'.
    ls_sort-spos = 1.
    ls_sort-up = 'X'.
    ls_sort-subtot = 'X'.
    APPEND ls_sort TO it_sort.
    *it_sort-fieldname = 'VBELN'.
    *it_sort-up = 'X'.
    *append it_sort.


    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' "输出退换货清单
    EXPORTING
    i_callback_program = g_repid
    it_fieldcat = it_field
    is_layout = gs_layout
    it_sort = it_sort
    i_save = 'A'
    TABLES
    t_outtab = itab1.


    ultraluck 发表于:2007.07.28 17:04 ::分类: ( SAP ABAP ) ::阅读:(118次) :: 评论 (0) :: 引用 (0)

    ALV输出,双击调用事务***

    report zsd_soposto no standard page heading message-id zsd.
    type-pools: slis.
    tables:vbak,vbkd,vbap,kna1,vbfa,vbpa,ekko,ekpo,ekbe,afko,afpo.
    types: begin of strc,
    bstkd like vbkd-bstkd, "合同号@项目名称
    name1 like kna1-name1, "付款方
    netwr like vbak-netwr, "工程价格
    vbeln like vbap-vbeln, "销售订单号
    posnr like vbap-posnr, "销售订单项目
    matnr like vbap-matnr, "行项目物料号
    kwmeng like vbap-kwmeng, "屏体数量
    aufnr like afpo-aufnr, "生产订单号
    strmp like afpo-strmp, "生产订单开始日期
    vbeln1 like lips-vbeln, "工程交货单号
    erdat1 like lips-erdat, "工程交货单创建日期
    ebeln like ekko-ebeln, "对应移库单号
    aedat like ekko-aedat, "移库单创建日期
    vbeln2 like lips-vbeln, "移库单交货单号
    erdat2 like lips-erdat, "移库单交货单创建日期
    contract(20) type c, "合同号
    project(40) type c, "工程名称
    end of strc.
    data: itab1 type strc occurs 0 with header line,
    temp_tab like table of ekbe with header line.

    *"Variants
    data: temp_con like vbkd-bstkd,
    temp_con1 like vbkd-bstkd,
    temp_con2 like vbkd-bstkd,
    temp_con3 like vbkd-bstkd,
    temp_pro3 like vbkd-bstkd,
    temp_bstkd like vbkd-bstkd.

    ****about alv
    data: it_fieldcat type slis_t_fieldcat_alv,
    wa_fieldcat type slis_fieldcat_alv,
    myindex like sy-tabix,
    gs_layout type slis_layout_alv,
    g_exit_caused_by_caller,
    gs_exit_caused_by_user type slis_exit_by_user,
    fieldcat type slis_t_fieldcat_alv,
    fieldcat_ln like line of fieldcat,
    g_repid like sy-repid,
    gs_variant like disvariant,
    g_save.
    data:
    gt_events type slis_t_event,
    gt_list_top_of_page type slis_t_listheader,
    g_status_set type slis_formname value 'PF_STATUS_SET',
    g_user_command type slis_formname value 'USER_COMMAND',
    g_top_of_page type slis_formname value 'TOP_OF_PAGE',
    g_top_of_list type slis_formname value 'TOP_OF_LIST',
    g_end_of_list type slis_formname value 'END_OF_LIST'.
    g_repid = sy-repid.
    define add_field.
    wa_fieldcat-tabname = 'ITAB1'.
    wa_fieldcat-fieldname = &1.
    wa_fieldcat-seltext_m = &2.
    wa_fieldcat-outputlen = &3.
    append wa_fieldcat to it_fieldcat.
    end-of-definition.

    selection-screen: skip 1.
    selection-screen: begin of block input with frame title text-001,
    skip 1.
    selection-screen: begin of block so with frame title text-002.
    parameters: so_con(20) type c, "合同号
    so_pro(40) type c. "工程名称
    select-options: so_auart for vbak-auart, "销售单据类型
    so_vkbur for vbak-vkbur, "销售办公室
    so_vkgrp for vbak-vkgrp, "销售组
    so_vbeln for vbak-vbeln, "销售订单号
    so_erdat for vbak-erdat, "销售订单创建日期
    so_kunnr for vbpa-kunnr, "付款方
    so_matnr for vbap-matnr, "物料编码
    so_werks for vbap-werks. "工厂
    selection-screen: end of block so.
    selection-screen: skip 1.
    selection-screen: begin of block sto with frame title text-003.
    select-options: so_ebeln for ekko-ebeln, "移库单编号
    so_aedat for ekko-aedat. "移库单创建日期
    selection-screen: end of block sto.
    selection-screen: skip 1.
    selection-screen: begin of block po with frame title text-004.
    select-options: so_aufnr for afpo-aufnr, "生产订单号
    so_strmp for afpo-strmp. "生产订单基本开始日期
    selection-screen: end of block po.
    selection-screen: end of block input.
    selection-screen: skip 1.
    selection-screen: begin of block output with frame title text-005.
    parameters: so as checkbox default 'X',
    solf as checkbox default 'X',
    sto as checkbox default 'X',
    stolf as checkbox default 'X',
    po as checkbox default 'X'.
    selection-screen: end of block output.

    ****main program
    if so_aufnr[] is initial and so_strmp[] is initial .
    perform so_search.
    *ELSEIF so_ebeln IS INITIAL OR so_aedat IS INITIAL.
    * MESSAGE i001.
    * PERFORM sto_search.
    else.
    perform po_search.
    write: 'PO'.
    endif.
    perform output.
    ****end main program

    *---------------------------------------------------------------------*
    * FORM so_search *
    *---------------------------------------------------------------------*
    * search by so *
    *---------------------------------------------------------------------*
    form so_search.
    **********get so data
    concatenate '%' so_con '%' into temp_con3. "模糊合同号
    concatenate '%' so_pro '%' into temp_pro3. "模糊工程名称
    select vbkd~bstkd kna1~name1 vbak~netwr vbap~vbeln vbap~posnr vbap~matnr
    vbap~kwmeng into table itab1
    from vbak inner join vbpa
    on vbak~vbeln = vbpa~vbeln
    inner join kna1
    on vbpa~kunnr = kna1~kunnr
    inner join vbkd
    on vbak~vbeln = vbkd~vbeln
    inner join vbap
    on vbak~vbeln = vbap~vbeln
    where vbkd~posnr = '000000'
    and vbpa~posnr = '000000'
    and vbap~abgru = space "行项目未被拒绝
    and vbak~auart in so_auart "销售单据类型
    and vbak~vbeln in so_vbeln "销售订单号
    and vbak~vkbur in so_vkbur "销售办公室
    and vbak~vkgrp in so_vkgrp "销售组
    and vbak~erdat in so_erdat "销售订单创建日期
    and vbpa~kunnr in so_kunnr "付款方
    and vbpa~parvw = 'RG'
    and vbap~matnr in so_matnr "物料编码
    and vbap~werks in so_werks "工厂
    * and vbke~bstkd cn ''.
    and vbkd~bstkd like temp_pro3 "合同号@项目名称
    and vbkd~bstkd like temp_con3. "合同号@项目名称
    loop at itab1.
    split itab1-bstkd at '@' into itab1-contract itab1-project.
    itab1-netwr = itab1-netwr * '1.17'.
    modify itab1.
    endloop.
    **********get sto data
    if sto ne space.
    loop at itab1.
    ****delete contract's '('and ')'
    temp_con = itab1-contract.
    * CHECK itab1-contract NE space.
    if itab1-contract = space and so_ebeln[] is initial and so_aedat[]
    is initial.
    continue.
    endif.
    split temp_con at '(' into temp_con1 temp_con2.
    concatenate temp_con1 temp_con2 into temp_con.
    split temp_con at ')' into temp_con1 temp_con2.
    concatenate temp_con1 temp_con2 into temp_con.
    temp_con1 = temp_con.
    temp_con2 = temp_con.
    translate temp_con1 to upper case.
    translate temp_con2 to lower case.
    select distinct ebeln from ekpo into itab1-ebeln
    where ebeln in so_ebeln and ( bednr =
    temp_con1 or bednr = temp_con2 ).
    select single aedat from ekko into itab1-aedat
    where ebeln = itab1-ebeln and aedat in so_aedat.
    check sy-subrc = 0.
    modify itab1.
    endselect.
    if itab1-ebeln = space.
    if not ( so_ebeln[] is initial )
    or not ( so_aedat[] is initial ).
    delete itab1.
    endif.
    endif.
    endloop.
    endif.
    **********get po data
    if po ne space.
    loop at itab1.
    select single aufnr strmp from afpo into (itab1-aufnr,itab1-strmp)
    where kdauf = itab1-vbeln and kdpos = itab1-posnr and aufnr in so_aufnr
    and strmp in so_strmp.
    check sy-subrc = 0.
    modify itab1.
    endloop.
    endif.
    **********get so's lf data
    if solf ne space.
    loop at itab1.
    select single vbeln erdat from vbfa into (itab1-vbeln1,itab1-erdat1)
    where vbelv = itab1-vbeln and posnv = itab1-posnr and vbtyp_n = 'J'.
    check sy-subrc = 0.
    modify itab1.
    endloop.
    endif.
    **********get sto's lf data
    if stolf ne space.
    loop at itab1.
    select distinct belnr budat from ekbe into (itab1-vbeln2,
    itab1-erdat2) where ebeln = itab1-ebeln and bewtp = 'L'.
    endselect.
    * ORDER BY budat DESCENDING.
    check sy-subrc = 0.
    modify itab1.
    endloop.
    endif.
    endform.

    *---------------------------------------------------------------------*
    * FORM po_search *
    *---------------------------------------------------------------------*
    * search by po *
    *---------------------------------------------------------------------*
    form po_search.
    concatenate '%' so_con '%' into temp_con3. "模糊合同号
    concatenate '%' so_pro '%' into temp_pro3. "模糊工程名称
    **********get so & po data
    select vbkd~bstkd kna1~name1 vbak~netwr vbap~vbeln vbap~posnr vbap~matnr
    vbap~kwmeng afpo~aufnr afpo~strmp into table itab1
    from vbak inner join vbpa
    on vbak~vbeln = vbpa~vbeln
    inner join kna1
    on vbpa~kunnr = kna1~kunnr
    inner join vbkd
    on vbak~vbeln = vbkd~vbeln
    inner join vbap
    on vbak~vbeln = vbap~vbeln
    inner join afpo
    on afpo~kdauf = vbak~vbeln
    and afpo~kdpos = vbap~posnr
    where vbkd~posnr = '000000'
    and vbpa~posnr = '000000'
    and vbap~abgru = space "行项目未被拒绝
    and vbak~auart in so_auart "销售单据类型
    and vbak~vbeln in so_vbeln "销售订单号
    and vbak~vkbur in so_vkbur "销售办公室
    and vbak~vkgrp in so_vkgrp "销售组
    and vbak~erdat in so_erdat "销售订单创建日期
    and vbpa~kunnr in so_kunnr "付款方
    and vbpa~parvw = 'RG'
    and vbap~matnr in so_matnr "物料编码
    and vbap~werks in so_werks "工厂
    * and vbke~bstkd cn ''.
    and vbkd~bstkd like temp_pro3 "合同号@项目名称
    and vbkd~bstkd like temp_con3 "合同号@项目名称
    and afpo~aufnr in so_aufnr "生产订单号
    and afpo~strmp in so_strmp. "订单开始日期
    loop at itab1.
    split itab1-bstkd at '@' into itab1-contract itab1-project.
    itab1-netwr = itab1-netwr * '1.17'.
    modify itab1.
    endloop.
    **********get so's lf data
    if solf ne space.
    loop at itab1.
    select single vbeln erdat from vbfa into (itab1-vbeln1,itab1-erdat1)
    where vbelv = itab1-vbeln and posnv = itab1-posnr and vbtyp_n = 'J'.
    check sy-subrc = 0.
    modify itab1.
    endloop.
    endif.
    **********get sto data
    if sto ne space.
    loop at itab1.
    ****delete contract's '('and ')'
    temp_con = itab1-contract.
    * CHECK itab1-contract NE space.
    if itab1-contract = space and so_ebeln[] is initial and
    so_aedat[] is initial.
    continue.
    endif.
    split temp_con at '(' into temp_con1 temp_con2.
    concatenate temp_con1 temp_con2 into temp_con.
    split temp_con at ')' into temp_con1 temp_con2.
    concatenate temp_con1 temp_con2 into temp_con.
    temp_con1 = temp_con.
    temp_con2 = temp_con.
    translate temp_con1 to upper case.
    translate temp_con2 to lower case.
    select distinct ebeln from ekpo into itab1-ebeln
    where ebeln in so_ebeln and ( bednr =
    temp_con1 or bednr = temp_con2 ).
    select single aedat from ekko into itab1-aedat
    where ebeln = itab1-ebeln and aedat in so_aedat.
    endselect.
    check sy-subrc = 0.
    modify itab1.
    endloop.
    endif.
    **********get sto's lf data
    if stolf ne space.
    loop at itab1.
    select distinct belnr budat from ekbe into (itab1-vbeln2,
    itab1-erdat2) where ebeln = itab1-ebeln and bewtp = 'L'.
    endselect.
    check sy-subrc = 0.
    modify itab1.
    endloop.
    endif.
    endform.
    *---------------------------------------------------------------------*
    * FORM output *
    *---------------------------------------------------------------------*
    * ........ *
    *---------------------------------------------------------------------*
    form output.
    ********output
    * add_field 'CONTRACT' '合同号' '20'.
    add_field 'CONTRACT' text-060 '20'.
    add_field 'PROJECT' '工程名称' '40'.
    *add_field 'BSTKD' '合同号@项目名称' '35'.
    add_field 'NAME1' '付款方' '35'.
    add_field 'VBELN' '销售订单号' '10'.
    add_field 'MATNR' '行项目物料号' '12'.
    add_field 'KWMENG' '屏体数量' '15'.
    if po ne space.
    add_field 'AUFNR' '生产订单号' '12'.
    add_field 'STRMP' '生产订单开始日期' '16'.
    endif.
    if solf ne space.
    add_field 'VBELN1' '工程交货单号' '12'.
    add_field 'ERDAT1' '工程交货单创建日期' '18'.
    endif.
    if sto ne space.
    add_field 'EBELN' '最近移库单号' '12'.
    add_field 'AEDAT' '移库单创建日期' '14'.
    endif.
    if stolf ne space.
    add_field 'VBELN2' '移库单最近交货单号' '18'.
    add_field 'ERDAT2' '移库单交货单创建日期' '20'.
    endif.
    add_field 'NETWR' '工程价格' '15'.


    call function 'REUSE_ALV_LIST_DISPLAY'
    exporting
    i_buffer_active = 'X'
    i_callback_program = g_repid
    it_fieldcat = it_fieldcat
    is_layout = gs_layout
    i_callback_user_command = g_user_command
    i_save = g_save
    is_variant = gs_variant
    it_events = gt_events[]
    tables
    t_outtab = itab1
    exceptions
    program_error = 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.
    endform.
    *---------------------------------------------------------------------*
    * FORM user_command *
    *---------------------------------------------------------------------*
    * ........ *
    *---------------------------------------------------------------------*
    * --> R_UCOMM *
    * --> RS_SELFIELD *
    *---------------------------------------------------------------------*
    form user_command using r_ucomm like sy-ucomm
    rs_selfield type slis_selfield.
    case r_ucomm.
    when '&IC1'. " SAP standard code for double-clicking
    if rs_selfield-sel_tab_field = 'ITAB1-VBELN'.
    set parameter id 'AUN' field rs_selfield-value.
    call transaction 'VA03' and skip first screen.
    endif.
    if rs_selfield-sel_tab_field = 'ITAB1-AUFNR'.
    set parameter id 'ANR' field rs_selfield-value.
    call transaction 'CO03' and skip first screen.
    endif.
    if rs_selfield-sel_tab_field = 'ITAB1-MATNR'.
    set parameter id 'MAT' field rs_selfield-value.
    call transaction 'MM03' and skip first screen.
    endif.
    if rs_selfield-sel_tab_field = 'ITAB1-VBELN1' or
    rs_selfield-sel_tab_field = 'ITAB1-VBELN2'.
    set parameter id 'VL' field rs_selfield-value.
    call transaction 'VL03N' and skip first screen.
    endif.
    if rs_selfield-sel_tab_field = 'ITAB1-EBELN'.
    set parameter id 'BES' field rs_selfield-value.
    call transaction 'ME23N'.
    endif.
    endcase.
    endform.
    *&--------------------------------------------------------------------*
    *& Form LAYOUT_INIT
    *&--------------------------------------------------------------------*
    * text
    *---------------------------------------------------------------------*
    * -->RS_LAYOUT text
    *---------------------------------------------------------------------*
    form layout_init using rs_layout type slis_layout_alv.
    *"Build layout for list display
    rs_layout-detail_popup = 'X'.
    rs_layout-colwidth_optimize = 'X'.
    endform. "LAYOUT_INIT

    *&--------------------------------------------------------------------*
    *& Form EVENTTAB_BUILD
    *&--------------------------------------------------------------------*
    * text
    *---------------------------------------------------------------------*
    * -->RT_EVENTS text
    *---------------------------------------------------------------------*
    form eventtab_build using rt_events type slis_t_event.
    *"Registration of events to happen during list display
    data: ls_event type slis_alv_event.
    *
    call function 'REUSE_ALV_EVENTS_GET'
    exporting
    i_list_type = 0
    importing
    et_events = rt_events.
    read table rt_events with key name = slis_ev_top_of_page
    into ls_event.
    if sy-subrc = 0.
    move g_top_of_page to ls_event-form.
    append ls_event to rt_events.
    endif.
    endform. "EVENTTAB_BUILD
    "
    *&--------------------------------------------------------------------*
    *& Form TOP_OF_PAGE
    *&--------------------------------------------------------------------*
    * text
    *---------------------------------------------------------------------*
    form top_of_page.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    i_logo = 'LOGO_YH01'
    it_list_commentary = gt_list_top_of_page.
    endform. "TOP_OF_PAGE
    "
    *&--------------------------------------------------------------------*
    *& Form COMMENT_BUILD
    *&--------------------------------------------------------------------*
    * text
    *---------------------------------------------------------------------*
    * -->LT_TOP_OF_Ptext
    *---------------------------------------------------------------------*
    form comment_build using lt_top_of_page type
    slis_t_listheader.
    data: ls_line type slis_listheader.
    clear ls_line.
    ls_line-typ = 'H'.
    ls_line-info = text-100.
    append ls_line to lt_top_of_page.
    endform. "COMMENT_BUILD


    ultraluck 发表于:2007.07.28 17:01 ::分类: ( SAP ABAP ) ::阅读:(121次) :: 评论 (0) :: 引用 (0)

    2007 年 04 月 11日, 星期三

    TextEdit Control

    TextEdit Control 查看全文
    ultraluck 发表于:2007.04.11 12:57 ::分类: ( SAP ABAP ) ::阅读:(289次) :: 评论 (0) :: 引用 (0)

    ALVGrid Control

    ALVGrid Control 查看全文
    ultraluck 发表于:2007.04.11 12:47 ::分类: ( SAP ABAP ) ::阅读:(340次) :: 评论 (0) :: 引用 (0)

    Controls Framework

    Controls Framework 查看全文
    ultraluck 发表于:2007.04.11 12:31 ::分类: ( SAP ABAP ) ::阅读:(244次) :: 评论 (0) :: 引用 (0)

    Business Object Repository

    Business Object Repository 查看全文
    ultraluck 发表于:2007.04.11 12:13 ::分类: ( SAP ABAP ) ::阅读:(193次) :: 评论 (0) :: 引用 (0)

    Business Object Repository

    Business Object Repository 查看全文
    ultraluck 发表于:2007.04.11 12:13 ::分类: ( SAP ABAP ) ::阅读:(158次) :: 评论 (0) :: 引用 (0)

    BAPI

    BAPI 查看全文
    ultraluck 发表于:2007.04.11 10:14 ::分类: ( SAP ABAP ) ::阅读:(209次) :: 评论 (0) :: 引用 (0)

    Business Object Repository

    Business Object Repository 查看全文
    ultraluck 发表于:2007.04.11 09:36 ::分类: ( SAP ABAP ) ::阅读:(154次) :: 评论 (0) :: 引用 (0)

    Business Object Repository

    Business Object Repository 查看全文
    ultraluck 发表于:2007.04.11 09:36 ::分类: ( SAP ABAP ) ::阅读:(116次) :: 评论 (0) :: 引用 (0)

    Sub screen Creation in ABAP

    Sub screen Creation in ABAP 查看全文
    ultraluck 发表于:2007.04.11 09:32 ::分类: ( SAP ABAP ) ::阅读:(175次) :: 评论 (0) :: 引用 (0)

    Drill Down Reports

    Drill Down Reports 查看全文
    ultraluck 发表于:2007.04.11 09:21 ::分类: ( SAP ABAP ) ::阅读:(195次) :: 评论 (0) :: 引用 (0)

    Interactive ABAP Reports

    Interactive ABAP Reports 查看全文
    ultraluck 发表于:2007.04.11 09:02 ::分类: ( SAP ABAP ) ::阅读:(190次) :: 评论 (0) :: 引用 (0)

    ABAP Reports

    ABAP Reports 查看全文
    ultraluck 发表于:2007.04.11 08:48 ::分类: ( SAP ABAP ) ::阅读:(246次) :: 评论 (0) :: 引用 (0)

    Transactions

    Transactions

     查看全文
    ultraluck 发表于:2007.04.11 08:37 ::分类: ( SAP ABAP ) ::阅读:(353次) :: 评论 (0) :: 引用 (0)

    Transactions

    Transactions

     查看全文
    ultraluck 发表于:2007.04.11 08:37 ::分类: ( SAP ABAP ) ::阅读:(2997次) :: 评论 (7) :: 引用 (0)

    2007 年 04 月 10日, 星期二

    OK Code Values

    OK Code Values 查看全文
    ultraluck 发表于:2007.04.10 18:01 ::分类: ( SAP ABAP ) ::阅读:(143次) :: 评论 (0) :: 引用 (0)

    ABAP Function Modules

    ABAP Function Modules

     查看全文

    ultraluck 发表于:2007.04.10 17:57 ::分类: ( SAP ABAP ) ::阅读:(2038次) :: 评论 (1) :: 引用 (0)

    SD Tables

    SD Tables 查看全文
    ultraluck 发表于:2007.04.10 17:31 ::分类: ( SAP ABAP ) ::阅读:(203次) :: 评论 (0) :: 引用 (0)

    Find tables in particular Module

    If table starts with following name B----------- -------- FI/CO P----------- -------HR M----------- --------- -MM V----------- ------SD T----------- --------ADMINIST RATION RELATION K----------- ------CUSTOMER TABLE L----------- ------VENDOR E----------- --------PURCHASI NG ORDERS
    ultraluck 发表于:2007.04.10 16:30 ::分类: ( SAP ABAP ) ::阅读:(130次) :: 评论 (0) :: 引用 (0)

    计算日期时间差 Abap Date Differance

    use the following function module to calculate days bet two dates, DAYS_BETWEEN_ TWO_DATES.
    ultraluck 发表于:2007.04.10 16:04 ::分类: ( SAP ABAP ) ::阅读:(155次) :: 评论 (0) :: 引用 (0)

    2007 年 01 月 16日, 星期二

    写代码做下拉框,按F4的功能

    写代码做下拉框,按F4的功能 查看全文
    ultraluck 发表于:2007.01.16 12:48 ::分类: ( SAP ABAP ) ::阅读:(209次) :: 评论 (0) :: 引用 (0)