Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7202761
  • 博文数量: 655
  • 博客积分: 10264
  • 博客等级: 上将
  • 技术积分: 8278
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-04 17:47
个人简介

ABAP顾问

文章分类

全部博文(655)

文章存档

2017年(2)

2014年(8)

2013年(3)

2012年(2)

2011年(18)

2010年(102)

2009年(137)

2008年(274)

2007年(134)

分类:

2007-11-06 21:49:56

REPORT z_barry_01 NO STANDARD PAGE HEADING MESSAGE-ID 00.

TABLES : malg, mean .

DATA: layout_module LIKE bapie1twml,
      return LIKE bapiret2,
      descriptions LIKE TABLE OF  twmlt WITH HEADER LINE,
      descriptions2 LIKE TABLE OF  twmlt WITH HEADER LINE,
      items TYPE TABLE OF bapie1malg WITH HEADER LINE ,
      item2 TYPE TABLE OF bapie1malg WITH HEADER LINE ,
      wa_items LIKE LINE OF items.
DATA: i_malg TYPE malg,
      i_twml TYPE twml.

DATA: BEGIN OF it_twml_new OCCURS 0,
        laygr(10) TYPE c ,
      END OF it_twml_new.
DATA: BEGIN OF it_twml_exist OCCURS 0,
        laygr(10) TYPE c ,
      END OF it_twml_exist .
DATA: BEGIN OF it_twml_add OCCURS 0,
        laygr(10) TYPE c ,
      END OF it_twml_add .
DATA: BEGIN OF it_upc OCCURS 0,
        upc(18) TYPE c,
      END OF it_upc.

DATA: BEGIN OF it_upload OCCURS 0 ,
        upc LIKE mean-ean11 ,                "18
        layout_mod LIKE items-layout_mod ,
        nameofstate(40) TYPE c ,
        sort_seq LIKE items-sort_seq ,
        shelf_quantity_max(13) TYPE c ,
        shelf_quantity_opt(13) TYPE c ,
        facing(13) TYPE c ,
        front(13) TYPE c ,
        exclusion LIKE items-exclusion  ,
      END OF it_upload .
DATA wa LIKE LINE OF it_upload.
DATA initialflag .
PARAMETERS:
     con_name LIKE dbcon-con_name DEFAULT 'PROSPACE_SAP' LOWER CASE.

START-OF-SELECTION.
  PERFORM connectdb.
  PERFORM fillitab USING initialflag .
  IF initialflag = 'N' .
    MESSAGE i398(00) WITH 'SQL Server没有需要更新的数据!'.
    LEAVE PROGRAM.
  ENDIF.
  IF sy-batch <> 'X'.
    PERFORM check USING 'I'.
  ELSE.
    PERFORM check USING 'E'.
  ENDIF.
  PERFORM getitems.
  PERFORM runbapi.
  PERFORM discondb.
  LEAVE PROGRAM.


*&---------------------------------------------------------------------*
*&      Form  fillitab
*&---------------------------------------------------------------------*
FORM fillitab USING flag .
  EXEC SQL PERFORMING appenditab.
    SELECT * INTO :wa  FROM z_trig_data
  ENDEXEC.

  LOOP AT it_upload.
    TRANSLATE it_upload-layout_mod TO UPPER CASE .
    MODIFY it_upload.
  ENDLOOP.

  READ TABLE it_upload INDEX 1.
  IF it_upload IS INITIAL .
    flag = 'N' .
  ENDIF.
ENDFORM.                    " fillitab

*&---------------------------------------------------------------------*
*&      Form  appenditab
*&---------------------------------------------------------------------*
FORM appenditab.
  APPEND wa TO it_upload.
ENDFORM.                    " appenditab

*&---------------------------------------------------------------------*
*&      Form  checklayoutmodule
*&---------------------------------------------------------------------*
FORM checklayoutmodule.
  DATA: n(8) ,
        out TYPE c ,
        msgtext(70).
  DESCRIBE TABLE it_twml_add LINES n .
  IF n <> 0 .
    CONCATENATE 'Layout module 有(' n '条)记录不存在' INTO msgtext .
    CALL FUNCTION 'POPUP_TO_CONFIRM'
         EXPORTING
              titlebar       = msgtext
              text_question  = '要看详细错误信息么?'
         IMPORTING
              answer         = out                          "1、 2、 A
         EXCEPTIONS
              text_not_found = 1
              OTHERS         = 2.

    IF out = '1' .
      CALL FUNCTION 'G_DISPLAY_SELECTION_DYNPRO'
           EXPORTING
                dynp_title        = msgtext
                show_also_1       = 'X'
                start_column      = 5
                without_selection = 'X'
           TABLES
                sel_table         = it_twml_add
           EXCEPTIONS
                no_lines          = 1
                no_line_picked    = 2
                OTHERS            = 3.
    ENDIF.
    CALL FUNCTION 'POPUP_TO_CONFIRM'
         EXPORTING
              titlebar       = 'New Layout Module'
              text_question  = 'Add New Layout Module?'
         IMPORTING
              answer         = out                          "1、 2、 A
         EXCEPTIONS
              text_not_found = 1
              OTHERS         = 2.
    IF out = 1.
      PERFORM newlayoutmodule.
    ELSE.
      MESSAGE e398(00) WITH 'Layout Module Error!' .
    ENDIF.
  ENDIF.

ENDFORM.                    " checklayoutmodule

*---------------------------------------------------------------------*
*       FORM checkarticle                                             *
*---------------------------------------------------------------------*
FORM check USING mestype.
  DATA error.
  LOOP AT it_upload  .
    SELECT SINGLE * FROM mean
      WHERE ean11 = it_upload-upc .
    IF sy-subrc <> 0 .
      it_upc-upc = it_upload-upc.
      APPEND it_upc.
    ENDIF.
  ENDLOOP.

  LOOP AT it_upload .
    it_twml_new-laygr = it_upload-layout_mod.
    APPEND it_twml_new.
  ENDLOOP .

  SORT it_twml_new BY laygr .
  DELETE ADJACENT DUPLICATES
    FROM it_twml_new COMPARING laygr .

  SELECT laygr INTO TABLE it_twml_exist
    FROM twml
    FOR ALL ENTRIES IN it_twml_new
    WHERE laygr = it_twml_new-laygr .

  CALL FUNCTION 'CTVB_COMPARE_TABLES'
       EXPORTING
            table_old  = it_twml_exist[]
            table_new  = it_twml_new[]
            key_length = 10
       IMPORTING
            table_add  = it_twml_add[].

  READ TABLE it_upc INDEX 1.
  IF NOT it_upc IS INITIAL.
    error = 1 .
    WRITE / 'Artical Not Found, UPC:'.
    LOOP AT it_upc.
      WRITE / it_upc-upc.
    ENDLOOP.
  ENDIF.

  READ TABLE it_twml_add INDEX 1.
  IF NOT it_twml_add IS INITIAL.
    error = 1.
    WRITE /'LayoutModule Not Found:'.
    LOOP AT it_twml_add.
      WRITE / it_twml_add-laygr.
    ENDLOOP.
  ENDIF.
  IF error = 1 .
    MESSAGE ID '00' TYPE mestype NUMBER 398 WITH 'Error occured!' .
    STOP.
  ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM newlayoutmodule                                          *
*---------------------------------------------------------------------*
FORM newlayoutmodule.
*  LOOP AT it_twml_add.
*    layout_module-layout_mod = it_twml_add-laygr .
*    layout_module-function   = '009'.
*    layout_module-CHANGE     = 1.
*    CALL FUNCTION 'BAPI_LAYMOD_SAVEREPLICA'
*         EXPORTING
*              layout_module = layout_module.
*  ENDLOOP.

  DATA it_twml LIKE TABLE OF  twml WITH HEADER LINE.
  LOOP AT it_twml_add.
    it_twml-laygr = it_twml_add.
    APPEND it_twml.
  ENDLOOP.
  INSERT twml FROM TABLE it_twml[] .
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  getitems
*&---------------------------------------------------------------------*
FORM getitems.
  LOOP AT it_upload  .
    SELECT SINGLE * FROM mean
      WHERE ean11 = it_upload-upc .
    IF sy-subrc = 0 .
      items-material = mean-matnr .
      items-unit     = mean-meinh .
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
           EXPORTING
                input  = items-material
           IMPORTING
                output = items-material.

      MOVE-CORRESPONDING it_upload TO items.
*    items-layout_mod = it_upload-layout_mod .
      APPEND items.
    ELSE.
      MESSAGE e398(00) WITH  'Article Not Found!  UPC:' it_upload-upc.
    ENDIF.
  ENDLOOP.
ENDFORM.                    " getitems

*---------------------------------------------------------------------*
*       FORM runbapi                                                  *
*---------------------------------------------------------------------*
FORM runbapi.
  LOOP AT items.
    item2-function = '003'.
    item2-material = items-material.
    item2-unit     = items-unit.
    item2-layout_mod = items-layout_mod.
    item2-change   = '0'.
    APPEND item2.
    IF items-exclusion <> 'D' AND items-exclusion <> 'd'.
      items-exclusion = ''.
    ENDIF.
    MODIFY items.
  ENDLOOP.

  DELETE items WHERE exclusion = 'D' OR exclusion = 'd'.

  DELETE it_upload WHERE exclusion = 'D' OR exclusion = 'd'.
  LOOP AT it_upload.
    descriptions-laygr   = it_upload-layout_mod.
    descriptions-ltext   = it_upload-nameofstate.
    descriptions-zzlaygr_text = it_upload-nameofstate.
    descriptions-spras   = 'EN'.
    APPEND descriptions.
    descriptions-laygr   = it_upload-layout_mod.
    descriptions-ltext   = it_upload-nameofstate.
    descriptions-zzlaygr_text = it_upload-nameofstate.
    descriptions-spras    = 1.
    APPEND descriptions.
  ENDLOOP.
  SORT descriptions BY laygr spras .
  DELETE ADJACENT DUPLICATES
    FROM descriptions COMPARING laygr spras .
  MODIFY twmlt FROM TABLE descriptions .

  LOOP AT item2 .
    SELECT SINGLE * FROM malg
      WHERE matnr = item2-material AND
            meinh = item2-unit      AND
            laygr = item2-layout_mod .
    IF sy-subrc = 0 .
      UPDATE malg SET sorf1 = ''
        WHERE matnr = item2-material AND
              meinh = item2-unit     AND
              laygr = item2-layout_mod .
*      COMMIT WORK AND WAIT.
    ELSE.
      DELETE item2.
    ENDIF.
  ENDLOOP .

  CALL FUNCTION 'BAPI_LAYMOD_SAVEREPLICA'
       EXPORTING
            layout_module = layout_module
       IMPORTING
            return        = return
       TABLES
            items         = item2.

  IF return-type = 'E'.
    MESSAGE ID     return-id
            TYPE   return-type
            NUMBER return-number
            WITH   return-message_v1
                   return-message_v2
                   return-message_v3
                   return-message_v4.
    ROLLBACK WORK.
  ELSE.
*    COMMIT WORK AND WAIT.
  ENDIF.

  CALL FUNCTION 'BAPI_LAYMOD_SAVEREPLICA'
       EXPORTING
            layout_module = layout_module
       IMPORTING
            return        = return
       TABLES
*            descriptions  = descriptions
            items         = items.

  IF return-type = 'E'.
    MESSAGE ID     return-id
            TYPE   return-type
            NUMBER return-number
            WITH   return-message_v1
                   return-message_v2
                   return-message_v3
                   return-message_v4.
    ROLLBACK WORK.
  ELSE.
    COMMIT WORK.
  ENDIF.

  EXEC SQL.
    delete from z_trig_data
  ENDEXEC.
  MESSAGE s398(00) WITH 'Success!'.
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  connectdb
*&---------------------------------------------------------------------*
FORM connectdb.
  EXEC SQL.
    CONNECT TO :con_name
  ENDEXEC.
  IF sy-subrc <> 0.
    RAISE connect_fail.
  ENDIF.

  EXEC SQL.
    SET CONNECTION :con_name
  ENDEXEC.
  IF sy-subrc <> 0.
    RAISE set_connection_fail.
  ENDIF.
ENDFORM.                    " connectdb
*&---------------------------------------------------------------------*
*&      Form  discondb
*&---------------------------------------------------------------------*
FORM discondb.
  EXEC SQL.
    DISCONNECT :con_name
  ENDEXEC.

  EXEC SQL.
    SET CONNECTION DEFAULT
  ENDEXEC.
ENDFORM.                    " discondb

 
阅读(4695) | 评论(2) | 转发(0) |
0

上一篇:HTML viewer

下一篇:ACCESS文件密码破解

给主人留下些什么吧!~~

chinaunix网友2010-02-09 13:06:39

这么清晰的程序结构,还需要注释么?

chinaunix网友2010-02-09 11:09:04

老白你太赖了 什么注释都没有啊