ZTEST004FORM

Posted wangxiaowen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ZTEST004FORM相关的知识,希望对你有一定的参考价值。

*&---------------------------------------------------------------------*
*&  Include           ZTEST004FORM
*&---------------------------------------------------------------------*

*--------------------------------------------------------------------*
*      Form  GET_DATA
*--------------------------------------------------------------------*
FORM GET_DATA .

  DATA: LO_CSV        TYPE REF TO CL_RSDA_CSV_CONVERTER,
        LV_CPCODEPAGE TYPE CPCODEPAGE,
        LV_CSV        TYPE STRING.
  DATA: LV_PATH TYPE STRING,
        LV_DATA TYPE STRING.

  CALL METHOD CL_RSDA_CSV_CONVERTER=>CREATE
*   EXPORTING
*     i_delimiter = C_DEFAULT_DELIMITER
*     i_separator = C_DEFAULT_SEPARATOR
    RECEIVING
      R_R_CONV    = LO_CSV
      .

  IF P_CKUBUN = CNS_KEY_L.

    LV_PATH = P_LFILE.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
      EXPORTING
        FILENAME                = LV_PATH
        FILETYPE                = ASC
        HAS_FIELD_SEPARATOR     = ABAP_TRUE
      CHANGING
        DATA_TAB                = IT_TEMP
      EXCEPTIONS
        FILE_OPEN_ERROR         = 1
        FILE_READ_ERROR         = 2
        NO_BATCH                = 3
        GUI_REFUSE_FILETRANSFER = 4
        INVALID_TYPE            = 5
        NO_AUTHORITY            = 6
        UNKNOWN_ERROR           = 7
        BAD_DATA_FORMAT         = 8
        HEADER_NOT_ALLOWED      = 9
        SEPARATOR_NOT_ALLOWED   = 10
        HEADER_TOO_LONG         = 11
        UNKNOWN_DP_ERROR        = 12
        ACCESS_DENIED           = 13
        DP_OUT_OF_MEMORY        = 14
        DISK_FULL               = 15
        DP_TIMEOUT              = 16
        NOT_SUPPORTED_BY_GUI    = 17
        ERROR_NO_GUI            = 18
        OTHERS                  = 19.

    IF SY-SUBRC <> 0.
      LEAVE LIST-PROCESSING.
    ENDIF.

    LOOP AT IT_TEMP INTO WA_TEMP.
      LV_DATA = WA_TEMP-TEXTLINE.
      CALL METHOD LO_CSV->CSV_TO_STRUCTURE
        EXPORTING
          I_DATA   = LV_DATA
        IMPORTING
          E_S_DATA = WA_WULIAO.
      APPEND WA_WULIAO TO IT_WULIAO.

    ENDLOOP.

  ELSE.

    OPEN DATASET P_SFILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
    IF SY-SUBRC = 0.
      DO.
        READ DATASET P_SFILE INTO LV_CSV.
        IF SY-SUBRC = 0.

          CLEAR WA_WULIAO.
          CALL METHOD LO_CSV->CSV_TO_STRUCTURE
            EXPORTING
              I_DATA   = LV_CSV
            IMPORTING
              E_S_DATA = WA_WULIAO.
          APPEND WA_WULIAO TO IT_WULIAO.
        ELSE.
          EXIT.
        ENDIF.
      ENDDO.
      CLOSE DATASET P_SFILE.
    ELSE.
      MESSAGE Cannot open file! TYPE E .
    ENDIF.

  ENDIF.

ENDFORM.                    " GET_DATA
*---------------------------------------------------------------------*
*      Form  APPEND_BDCDATA
*---------------------------------------------------------------------*
FORM APPEND_BDCDATA .
  DATA LV_MESSAGE TYPE C LENGTH 200.

*  DATA LV_GROUP   TYPE APQI-GROUPID VALUE ‘ZTEST004_BDC_GROUP‘.
*  CALL FUNCTION ‘BDC_OPEN_GROUP‘
*   EXPORTING
**     CLIENT                    = SY-MANDT
**     DEST                      = FILLER8
*     GROUP                     = LV_GROUP
**     HOLDDATE                  = FILLER8
*     KEEP                      = ‘X‘
*     USER                      = SY-UNAME
**     RECORD                    = FILLER1
**     PROG                      = SY-CPROG
**     DCPFM                     = ‘%‘
**     DATFM                     = ‘%‘
**   IMPORTING
**     QID                       =
*   EXCEPTIONS
*     CLIENT_INVALID            = 1
*     DESTINATION_INVALID       = 2
*     GROUP_INVALID             = 3
*     GROUP_IS_LOCKED           = 4
*     HOLDDATE_INVALID          = 5
*     INTERNAL_ERROR            = 6
*     QUEUE_ERROR               = 7
*     RUNNING                   = 8
*     SYSTEM_LOCK_ERROR         = 9
*     USER_INVALID              = 10
*     OTHERS                    = 11
*            .
*  IF SY-SUBRC <> 0.
*    EXIT.
*  ENDIF.

  LOOP AT IT_WULIAO INTO WA_WULIAO .
    CLEAR: BDCDATA, BDCDATA[],
           MESSTAB, MESSTAB[].
    PERFORM BDC_DYNPRO USING SAPLMGMM 0060.
    PERFORM BDC_FIELD USING BDC_CURSOR RMMG1-MATNR.
    PERFORM BDC_FIELD USING BDC_OKCODE =ENTR.
    PERFORM BDC_FIELD USING RMMG1-MATNR WA_WULIAO-MATNR.

    PERFORM BDC_DYNPRO USING SAPLMGMM 0070.
    PERFORM BDC_FIELD USING BDC_CURSOR MSICHTAUSW-DYTXT(01).
    PERFORM BDC_FIELD USING BDC_OKCODE =ENTR.
    PERFORM BDC_FIELD USING MSICHTAUSW-KZSEL(01)R X.

    PERFORM BDC_DYNPRO USING SAPLMGMM 4004.
    PERFORM BDC_FIELD USING BDC_OKCODE =BU.
    PERFORM BDC_FIELD USING MAKT-MAKTX WA_WULIAO-MAKTX.
    PERFORM BDC_FIELD USING BDC_CURSOR MARA-GEWEI.
    PERFORM BDC_FIELD USING MARA-BRGEW WA_WULIAO-BRGEW.
    PERFORM BDC_FIELD USING MARA-GEWEI WA_WULIAO-GEWET.
    PERFORM BDC_FIELD USING MARA-NTGEW WA_WULIAO-NTGEW.

    CALL TRANSACTION MM02 USING BDCDATA
                            UPDATE P_UPDATE   "更新模式 S同步,A异步
                            MODE   P_MODE     "显示模式  A前台, N后台,E只显示错误
                            MESSAGES INTO MESSTAB.

    LOOP AT  MESSTAB .
      PERFORM MSG_SET USING MESSTAB-MSGID
                              MESSTAB-MSGTYP
                              MESSTAB-MSGNR
                              MESSTAB-MSGV1
                              MESSTAB-MSGV2
                              MESSTAB-MSGV3
                              MESSTAB-MSGV4
                              .
    ENDLOOP.

*    CALL FUNCTION ‘BDC_INSERT‘
*     EXPORTING
*       TCODE                  = ‘MM02‘
**       POST_LOCAL             = NOVBLOCAL
**       PRINTING               = NOPRINT
**       SIMUBATCH              = ‘ ‘
**       CTUPARAMS              = ‘ ‘
*      TABLES
*        DYNPROTAB              = BDCDATA
*     EXCEPTIONS
*       INTERNAL_ERROR         = 1
*       NOT_OPEN               = 2
*       QUEUE_ERROR            = 3
*       TCODE_INVALID          = 4
*       PRINTING_INVALID       = 5
*       POSTING_INVALID        = 6
*       OTHERS                 = 7
*              .
*    IF SY-SUBRC <> 0.
*      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*    ENDIF.


*    READ TABLE MESSTAB WITH KEY MSGID = ‘M3‘
*                                             MSGNR = ‘801‘.
*    IF SY-SUBRC = 0.
*      WRITE:/ ‘物料‘, WA_WULIAO-MATNR ,‘修改成功!‘.
*    ELSE.
*
*      READ TABLE MESSTAB INTO MESSTAB WITH KEY MSGID = ‘M3‘
*                                               MSGNR = ‘810‘.
*      IF SY-SUBRC = 0.
*        WRITE:/ ‘物料‘, WA_WULIAO-MATNR ,‘修改成功!‘.
*      ELSE.
*
*        LOOP AT  MESSTAB WHERE MSGTYP = ‘E‘ .
*          CALL FUNCTION ‘MESSAGE_TEXT_BUILD‘
*            EXPORTING
*              MSGID               = MESSTAB-MSGID
*              MSGNR               = MESSTAB-MSGNR
*              MSGV1               = MESSTAB-MSGV1
*              MSGV2               = MESSTAB-MSGV2
*              MSGV3               = MESSTAB-MSGV3
*              MSGV4               = MESSTAB-MSGV4
*            IMPORTING
*              MESSAGE_TEXT_OUTPUT = LV_MESSAGE.
*          WRITE:/ ‘物料修改失败原因:‘,
*                  LV_MESSAGE.
*
*        ENDLOOP.
*      ENDIF.
*
*    ENDIF.

  ENDLOOP.
  IF IT_LOG IS NOT INITIAL.
    PERFORM LOG_WRITE.
  ENDIF.

*  CALL FUNCTION ‘BDC_CLOSE_GROUP‘
*    EXCEPTIONS
*      NOT_OPEN    = 1
*      QUEUE_ERROR = 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.
*
*  SUBMIT RSBDCSUB WITH MAPPE EQ LV_GROUP
*               WITH VON EQ SY-DATUM
*               WITH BIS EQ SY-DATUM
*               WITH FEHLER EQ ‘.‘
*               EXPORTING LIST TO MEMORY
*               AND RETURN.
*
*  WAIT UP TO 10 SECONDS .
ENDFORM.                    " APPEND_BDCDATA
*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
  CLEAR BDCDATA.
  BDCDATA-PROGRAM  = PROGRAM.
  BDCDATA-DYNPRO   = DYNPRO.
  BDCDATA-DYNBEGIN = X.
  APPEND BDCDATA.
ENDFORM.                    "BDC_DYNPRO

*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
  CLEAR BDCDATA.
  BDCDATA-FNAM = FNAM.
  BDCDATA-FVAL = FVAL.
  APPEND BDCDATA.
ENDFORM.                    "BDC_FIELD
*---------------------------------------------------------------------*
*      Form  GET_FILENAME
*---------------------------------------------------------------------*

FORM GET_FILENAME .

  DATA: LIT_FILE_NAMES TYPE FILETABLE,
        LWA_FILE_NAME  LIKE LINE OF LIT_FILE_NAMES,
        LV_COUNT       TYPE I.

  IF P_CKUBUN = CNS_KEY_L.
*   ファイルを開くダイアログを表示FM
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
      EXPORTING
        WINDOW_TITLE            = ファイル選択                "ファイルを開くダイアログの表題
        FILE_FILTER             = Excel Files (*.CSV)|*.CSV|Text File(*.txt)|*.txt   "ファイル拡張フィルタストリング
        INITIAL_DIRECTORY       = C:                          "第一ディレクトリ
        MULTISELECTION          = SPACE                         "複数選択可能 (X複数可能)
      CHANGING
        FILE_TABLE              = LIT_FILE_NAMES                "選択したファイルを維持するテーブル
        RC                      = LV_COUNT                      "打开文件的数量 (ファイル数かエラーの場合は -1)
      EXCEPTIONS
        FILE_OPEN_DIALOG_FAILED = 1
        CNTL_ERROR              = 2
        ERROR_NO_GUI            = 3
        NOT_SUPPORTED_BY_GUI    = 4
        OTHERS                  = 5.

    READ TABLE LIT_FILE_NAMES INTO LWA_FILE_NAME INDEX 1.
    IF SY-SUBRC = 0.
      P_LFILE = LWA_FILE_NAME-FILENAME.
    ELSE.
      MESSAGE ファイルを選択してください TYPE E.
      EXIT.
    ENDIF.
  ELSE.
    CONCATENATE P_SFILE CSV_TEST.CSV INTO P_SFILE.
  ENDIF.
ENDFORM.                    " F4_GET_FILENAME
*---------------------------------------------------------------------*
*      Form  SELECTION_SCREEN_PAI.
*---------------------------------------------------------------------*
FORM  SELECTION_SCREEN_PAI.

  IF SSCRFIELDS-UCOMM = FC01.
    PERFORM FILE_DOWNLOAD.
  ENDIF.

ENDFORM.                    "SELECTION_SCREEN_PAI
*---------------------------------------------------------------------*
*      Form  FILE_DOWNLOAD.
*---------------------------------------------------------------------*
FORM FILE_DOWNLOAD.

  DATA LV_FILE TYPE STRING.
  REFRESH IT_WULIAOTMP.
  APPEND  IT_WULIAOTMP.


* 1.获取文件路径
  CALL FUNCTION WS_FILENAME_GET
   EXPORTING
*    DEF_FILENAME           = ‘ ‘
*    DEF_PATH               = ‘ ‘
     MASK                   = ,EXCEL.xls,*.xls.
     MODE                   = O" O保存,S打开
     TITLE                  = 选择保存文件路径"窗口的显示标题
   IMPORTING
     FILENAME               = LV_FILE
*    RC                     =
   EXCEPTIONS
     INV_WINSYS             = 1
     NO_BATCH               = 2
     SELECTION_CANCEL       = 3
     SELECTION_ERROR        = 4
     OTHERS                 = 5
            .
  IF SY-SUBRC <> 0.
    EXIT.
  ENDIF.

  CHECK LV_FILE IS NOT INITIAL.
* 2. 下载文件保存到指定路径文件中
  CHECK LV_FILE IS NOT INITIAL.
  CALL FUNCTION GUI_DOWNLOAD
    EXPORTING
*     BIN_FILESIZE                    =
      FILENAME                        = LV_FILE
*     FILETYPE                        = ‘ASC‘
*     APPEND                          = ‘X‘
*     WRITE_FIELD_SEPARATOR           = ‘X‘
*     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                      = ‘ ‘
*   IMPORTING
*     FILELENGTH                      =
    TABLES
      DATA_TAB                        = IT_WULIAO
*     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.

ENDFORM.                    "FILE_DOWNLOAD
*&---------------------------------------------------------------------*
*&      Form  fill_data_to_auart
*&---------------------------------------------------------------------*
FORM DATA_SETTO_LISTBOX .
  DATA: NAME  TYPE VRM_ID,        " list box的名称
        LIST  TYPE VRM_VALUES,    " list box的值
        VALUE LIKE LINE OF LIST ." list box的结构

  REFRESH LIST .
  VALUE-KEY  = CNS_KEY_L.
  VALUE-TEXT = CNS_TEXT_L.
  APPEND VALUE TO LIST.

  VALUE-KEY  = CNS_KEY_S.
  VALUE-TEXT = CNS_TEXT_S.
  APPEND VALUE TO LIST.

  "---〉调用函数显示listbox里面的值
  CALL FUNCTION VRM_SET_VALUES
    EXPORTING
      ID     = P_CKUBUN  " PARAMETERS‘s Name
      VALUES = LIST.
ENDFORM.                    " fill_data_to_auart
*&---------------------------------------------------------------------*
*&      Form  LFILE_SFILE_DISPLAY
*&---------------------------------------------------------------------*
FORM SCREEN_DISPLAY.

  LOOP AT SCREEN.

    IF SCREEN-NAME = P_LFILE .
      SCREEN-INPUT = 0.  "不可输入
    ENDIF.
    IF SCREEN-NAME = P_SFILE .
      IF P_CKUBUN = CNS_KEY_S.
        SCREEN-INPUT = 1.  "可输入
      ELSE.
        SCREEN-INPUT = 0.  "不可输入
      ENDIF.
    ENDIF.
    IF SCREEN-NAME = P_SLOG .
      IF P_CKUBUN = CNS_KEY_S.
        SCREEN-INPUT = 1.  "可输入
      ELSE.
        SCREEN-INPUT = 0.  "不可输入
      ENDIF.
    ENDIF.
    MODIFY SCREEN.

  ENDLOOP.

ENDFORM.                    "LFILE_SFILE_DISPLAY
*&---------------------------------------------------------------------*
*&      Form  remove_cr_lf
*&---------------------------------------------------------------------*
FORM REMOVE_CR_LF  CHANGING  P_STR.
  DATA: TCODEPAGE TYPE CPCODEPAGE.
  CALL FUNCTION NLS_GET_FRONTEND_CP
    EXPORTING
      LANGU                 = SY-LANGU
      FETYPE                = MS
    IMPORTING
      FRONTEND_CODEPAGE     = TCODEPAGE
    EXCEPTIONS
      ILLEGAL_SYST_CODEPAGE = 1
      NO_FRONTEND_CP_FOUND  = 2
      INTERNAL_OR_DB_ERROR  = 3
      OTHERS                = 4.

  CALL FUNCTION SCP_REPLACE_STRANGE_CHARS
    EXPORTING
      INTEXT            = P_STR
      INTER_CP          = TCODEPAGE
      REPLACEMENT       = 32     " 等于space, ASC
    IMPORTING
      OUTTEXT           = P_STR
    EXCEPTIONS
      INVALID_CODEPAGE  = 1
      CODEPAGE_MISMATCH = 2
      INTERNAL_ERROR    = 3
      CANNOT_CONVERT    = 4
      FIELDS_NOT_TYPE_C = 5
      OTHERS            = 6.
ENDFORM.                    " REMOVE_CR_LF

*&---------------------------------------------------------------------*
*&      Form  MSG_SET
*&---------------------------------------------------------------------*
FORM MSG_SET USING    P_MSGID P_MSGTY
                      P_MSGNR P_MSGV1
                      P_MSGV2 P_MSGV3
                              P_MSGV4.

  DATA: LV_MESSAGE TYPE C LENGTH 200.

*  CLEAR WA_LOG.
  CALL FUNCTION MESSAGE_TEXT_BUILD
    EXPORTING
      MSGID               = P_MSGID
      MSGNR               = P_MSGNR
      MSGV1               = P_MSGV1
      MSGV2               = P_MSGV2
      MSGV3               = P_MSGV3
      MSGV4               = P_MSGV4
    IMPORTING
      MESSAGE_TEXT_OUTPUT = LV_MESSAGE.

  WA_LOG-OUTDATE =  SY-DATUM.
  WA_LOG-MSGTYPE =  P_MSGTY.
  WA_LOG-MSGTEXT =  LV_MESSAGE.

  APPEND WA_LOG TO IT_LOG.
ENDFORM.                    "MSG_SET
*&---------------------------------------------------------------------*
*&      Form  CHECK_LOGFILE
*&---------------------------------------------------------------------*
FORM CHECK_LOGFILE.

  CONCATENATE P_LOG SY-REPID _ SY-DATUM .txt INTO G_LOGFILE.

  OPEN DATASET G_LOGFILE FOR APPENDING IN TEXT MODE  ENCODING DEFAULT .  "打开文件
  IF SY-SUBRC <> 0.
    MESSAGE OPEN ERROR!! TYPE E.
  ELSE.
    CLOSE DATASET G_LOGFILE.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  LOG_WRITE
*&---------------------------------------------------------------------*
FORM LOG_WRITE.
  DATA: LV_OUTPUT  TYPE C LENGTH 256.
  OPEN DATASET G_LOGFILE FOR APPENDING  IN TEXT MODE  ENCODING DEFAULT .  "打开文件
  IF SY-SUBRC = 0.
    LOOP AT IT_LOG INTO WA_LOG.
      CONCATENATE WA_LOG-OUTDATE
                  WA_LOG-MSGTYPE
                  WA_LOG-MSGTEXT
             INTO LV_OUTPUT  SEPARATED BY space.
      TRANSFER LV_OUTPUT TO G_LOGFILE .
    ENDLOOP.
    CLOSE DATASET G_LOGFILE.
    CLEAR: IT_LOG,WA_LOG.
  ELSE.
    MESSAGE OPEN ERROR!! TYPE E.
  ENDIF.

ENDFORM.                    "LOG_WRITE

 

以上是关于ZTEST004FORM的主要内容,如果未能解决你的问题,请参考以下文章

ZTEST004TOP

Zephyr单元测试框架:ztest/twister的使用和介绍

Zephyr单元测试框架:ztest/twister的使用和介绍

Zephyr单元测试框架:ztest/twister的使用和介绍

SpringBoot中表单提交报错“Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“(代码片段

[UnityShader]点染队列ZWrite和ZTest