λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
SAP/ABAP

[ABAP] SMW0 μ΄μš©ν•΄μ„œ ν…œν”Œλ › λ‹€μš΄λ‘œλ“œ

by applemango2021 2021. 1. 8.

λŒ€λŸ‰ 데이터λ₯Ό μ—…λ‘œλ“œ ν•΄μ•Ό ν•˜λŠ” 경우, μš°μ„  μ‚¬μš©μžκ°€ μ—‘μ…€ νŒŒμΌμ— 데이터λ₯Ό μž…λ ₯ν•˜κ²Œ ν•œ λ‹€μŒμ—, κ·Έ 데이터λ₯Ό λ°›μ•„μ„œ BDCλ‚˜ BAPI둜 μ²˜λ¦¬ν•œλ‹€. μ΄λ•Œ μ—…λ‘œλ“œ 양식을 λͺ¨λ“  μ‚¬μš©μžλ“€μ—κ²Œ μΌκ΄€λ˜κ²Œ μ œκ³΅ν•΄μ•Ό ν•˜κΈ° λ•Œλ¬Έμ—, μ—…λ‘œλ“œ ν”„λ‘œκ·Έλž¨μ—μ„œ ν…œν”Œλ › 양식도 μ œκ³΅ν•œλ‹€. 

 

μ—¬λŸ¬ 방법이 μžˆμ„ μˆ˜λ„ μžˆκ² μ§€λ§Œ, Web Repository(T-code SMW0)λ₯Ό 많이 μ΄μš©ν•œλ‹€. 

 

1. Web Repository(T-code SMW0)에 ν…œν”Œλ › μ—…λ‘œλ“œ

 - μ €μž₯ 파일λͺ… : ZTESTFILE

 

2. Application Bar에 μ—…λ‘œλ“œ λ²„νŠΌ 생성

 

3. PAI λͺ¨λ“ˆμ— PERFORM TEMPLATE_DOWNLOAD 생성

PROCESS AFTER INPUT.
	MODULE EXIT_0100 AT EXIT-COMMAND.
    MODULE USER_COMMAND_0100.
MODULE USER_COMMAND_0100 INPUT.
  CLEAR GV_UCOMM.
  GV_UCOMM = GV_OKCODE.
  CLEAR GV_OKCODE.

  CASE GV_UCOMM.
    WHEN 'TEMP'.   "GUI Status에 λ“±λ‘ν•œ Function Code
      PERFORM TEMPLATE_DOWNLOAD.
  ENDCASE.
ENDMODULE.

4. PERFORM TEMPLATE_DOWNLOAD 둜직 κ΅¬ν˜„

FORM TEMPLATE_DOWNLOAD.
    DATA LV_SAVEPATH TYPE STRING.
    
    "4-1. μ €μž₯μœ„μΉ˜ 선택
    PERFORM SET_SAVE_PATH CHANGING LV_SAVEPATH.
    
    "4-2. Web Repositoryμ—μ„œ 파일 선택 및 μ €μž₯ 
    PERFORM SAVE_TEMPLATE USING LV_SAVEPATH.
ENDFORM.

   4-1. μ €μž₯ μœ„μΉ˜ 선택

FORM SET_SAVE_PATH CHANGING PV_SAVEPATH.
  DATA : LV_PATH          TYPE STRING,
         LV_SAVE_FILENAME TYPE STRING.
  DATA(LV_FILENAME) = |Template_| & |{ SY-DATUM }| & |.xlsx|.

  CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG(
    EXPORTING
      DEFAULT_FILE_NAME         = LV_FILENAME
      FILE_FILTER               = 'Excel files (*.XLS;*.XLSX)|*.XLSX'
      INITIAL_DIRECTORY         = 'D:\'
    CHANGING
      FILENAME                  = LV_SAVE_FILENAME
      PATH                      = LV_PATH
      FULLPATH                  = PV_SAVEPATH
    EXCEPTIONS
      CNTL_ERROR                = 1                " Control error
      ERROR_NO_GUI              = 2                " No GUI available
      NOT_SUPPORTED_BY_GUI      = 3                " GUI does not support this
      INVALID_DEFAULT_FILE_NAME = 4                " Invalid default file name
      OTHERS                    = 5
  ).
  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.

   4-2. Web Repositoryμ—μ„œ 파일 선택 및 둜컬 PC에 μ €μž₯

    - FUNCTION 'WWWDATA_IMPORT'λž‘ FUNCTION 'WWWPARAMS_READ'λ₯Ό μ΄μš©ν•΄μ„œ MIME νƒ€μž…μœΌλ‘œ 데이터λ₯Ό κ°€μ Έμ˜¨ λ‹€μŒμ—, PERFORM 'GUI_DOWNLOAD'λ₯Ό μ΄μš©ν•˜λŠ” 방법도 μžˆλ‹€.

    - μ–΄μ°¨ν”Ό FUNCTION 'DOWNLOAD_WEB_OBJECT'μ•ˆμ—μ„œ μœ„ 3개의 ν•¨μˆ˜λ₯Ό μ΄μš©ν•˜κ³  μžˆλ‹€

FORM SAVE_TEMPLATE USING PV_SAVEPATH.

 DATA : 	LS_WWWDATA 	TYPE WWWDATATAB,
    		LV_FILE 	TYPE RLGRAP-FILENAME.
            
 SELECT SINGLE * INTO CORRESPONDING FIELDS OF LS_WWWDATA
   FROM WWWDATA
   WHERE OBJID = 'ZTESTFILE'.	"1λ²ˆμ—μ„œ μ €μž₯ν•œ 파일λͺ…
   
 CHECK PV_SAVEPATH IS NOT INITIAL.
 "PV_SAVEPATH의 νƒ€μž…μ€ STRING이고, ν•¨μˆ˜μ— λ„˜κ²¨μ£ΌλŠ” λ³€μˆ˜νƒ€μž…μ€ RLGRAP-FILENAME이기 λ•Œλ¬Έμ—
 "νƒ€μž… λ³€ν™˜μ„ μœ„ν•΄ μ•„λž˜μ™€ 같이 값을 전달해쀀닀.
 LV_FILE = PV_SAVEPATH.  

 CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
    EXPORTING
      KEY          = WWWDATA_ITEM
      DESTINATION  = LV_FILE.
  
  " λ‹€μš΄λ‘œλ“œ 받은 뒀에 λ°”λ‘œ νŒŒμΌμ„ μ‹€ν–‰μ‹œν‚€κ³  μ‹Άλ‹€λ©΄ μ•„λž˜ ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•œλ‹€. 
  " μ΄λ•Œ, DOCUMENT νŒŒλΌλ―Έν„°λŠ” STRING νƒ€μž…μ΄κΈ° λ•Œλ¬Έμ— LV_FILE이 μ•„λ‹Œ PV_SAVEPATHλ₯Ό μ΄μš©ν•œλ‹€.
  IF SY-SUBRC = 0.
    CL_GUI_FRONTEND_SERVICES=>EXECUTE(
      EXPORTING
        DOCUMENT               = PV_SAVEPATH      " Path+Name to Document
        OPERATION              = 'OPEN'           " Reserved: Verb for ShellExecute
      EXCEPTIONS
        CNTL_ERROR             = 1       " Control error
        ERROR_NO_GUI           = 2       " No GUI available
        BAD_PARAMETER          = 3       " Incorrect parameter combination
        FILE_NOT_FOUND         = 4       " File not found
        PATH_NOT_FOUND         = 5       " Path not found
        FILE_EXTENSION_UNKNOWN = 6       " Could not find application for specified extension
        ERROR_EXECUTE_FAILED   = 7       " Could not execute application or document
        SYNCHRONOUS_FAILED     = 8       " Cannot Call Application Synchronously
        NOT_SUPPORTED_BY_GUI   = 9       " GUI does not support this
        OTHERS                 = 10
    ).
  ENDIF.
         
ENDFORM.

'SAP > ABAP' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

ALV Display ↔ Change ν† κΈ€ λ²„νŠΌ  (1) 2020.12.23
[ABAP] κΈˆμ•‘ λ³€ν™˜ - WRITE TO CURRENCY  (0) 2020.12.17