Showing posts with label Classical Report. Show all posts
Showing posts with label Classical Report. Show all posts

Thursday, July 23, 2020

Send Mail Excel attachment program in SAP ABAP

Send Mail Excel attachment program in SAP ABAP.




DATA: lt_mailrecipients  TYPE STANDARD TABLE OF somlrec90 WITH HEADER LINE,

      lt_mailtxt         TYPE STANDARD TABLE OF soli      WITH HEADER LINE,

      lt_attachment      TYPE STANDARD TABLE OF solisti1  WITH HEADER LINE,

      lt_mailsubject     TYPE sodocchgi1,

      lt_packing_list    TYPE STANDARD TABLE OF sopcklsti1 WITH HEADER LINE,

      gv_cnt             TYPE i.


Add Recipients


lt_mailrecipients-rec_type  = 'U'.

lt_mailrecipients-com_type  = 'INT'.

lt_mailrecipients-RECEIVER  = 'someone@erpdb.info'.

APPEND lt_mailrecipients .

CLEAR lt_mailrecipients .


Put in the Mail Contents


lt_mailtxt = 'Hi How are you'.      APPEND lt_mailtxt. CLEAR lt_mailtxt.

lt_mailtxt = 'Here is a test mail'. APPEND lt_mailtxt. CLEAR lt_mailtxt.

lt_mailtxt = 'Thanks'.              APPEND lt_mailtxt. CLEAR lt_mailtxt.


Create the attachment


  DATA: BEGIN OF lt_po_data_cons OCCURS 0,

         ebeln LIKE ekpo-ebeln,

         ebelp LIKE ekpo-ebelp,

        END OF lt_po_data_cons.


  SELECT ebeln ebelp INTO TABLE lt_po_data_cons

  UP TO 10 ROWS

  FROM ekpo. 


  CLASS cl_abap_char_utilities DEFINITION LOAD.

  CONCATENATE 'PO' 'PO Line'

              INTO lt_attachment SEPARATED BY

              cl_abap_char_utilities=>horizontal_tab.

  APPEND lt_attachment. CLEAR lt_attachment.


  LOOP AT lt_po_data_cons.

  CONCATENATE lt_po_data_cons-ebeln lt_po_data_cons-ebelp

              INTO lt_attachment SEPARATED BY

              cl_abap_char_utilities=>horizontal_tab.


  CONCATENATE cl_abap_char_utilities=>newline lt_attachment

              INTO lt_attachment.


  APPEND lt_attachment. CLEAR lt_attachment.

 ENDLOOP.

Pack the mail contents and attachment

 lt_packing_list-transf_bin  = SPACE.

  lt_packing_list-head_start  = 1.

  lt_packing_list-head_num    = 0.

  lt_packing_list-body_start  = 1.

  lt_packing_list-body_num    = LINES( lt_mailtxt ).

  lt_packing_list-doc_type    = 'RAW'.

  APPEND lt_packing_list. CLEAR lt_packing_list.


  lt_packing_list-transf_bin  = 'X'.

  lt_packing_list-head_start  = 1.

  lt_packing_list-head_num    = 1.

  lt_packing_list-body_start  = 1.

  lt_packing_list-body_num    = LINES( lt_attachment ).

  lt_packing_list-doc_type    = 'XLS'. " You can give RAW incase if you want just a txt file.

  lt_packing_list-obj_name    = 'data.xls'.

  lt_packing_list-obj_descr   = 'data.xls'.

  lt_packing_list-doc_size    = lt_packing_list-body_num * 255.

  APPEND lt_packing_list. CLEAR lt_packing_list.


  lt_mailsubject-obj_name     = 'MAILATTCH'.

  lt_mailsubject-obj_langu    = sy-langu.

  lt_mailsubject-obj_descr    = 'You have got mail'.

  lt_mailsubject-sensitivty   = 'F'.

  gv_cnt = LINES( lt_attachment ).

  lt_mailsubject-doc_size     = ( gv_cnt - 1 ) * 255 + STRLEN(

  lt_attachment ).

Finally, send the mail out.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

      document_data              = lt_mailsubject

    TABLES

      packing_list               = lt_packing_list

      contents_bin               = lt_attachment

      contents_txt               = lt_mailtxt

      receivers                  = lt_mailrecipients

    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 EQ 0.

    COMMIT WORK.

    SUBMIT rsconn01 WITH MODE = 'INT' AND RETURN.

  ENDIF.

Wednesday, February 27, 2019

Delivery report In SAP ABAP.

SAP ABAP DELIVERY REPORT.

READ MORE BDC DETAILS

REPORT  ZSW_DEL_1 NO STANDARD PAGE HEADING LINE-COUNT 37(3).

TABLES VBAK,VBAP,VBFA,LIKP,LIPS.

TYPESBEGIN OF TY_VBAK,
        VBELN TYPE VBAK-VBELN,
        VKORG TYPE VBAK-VKORG,
        VTWEG TYPE VBAK-VTWEG,
        SPART TYPE VBAK-SPART,
      END OF TY_VBAK.
TYPESBEGIN OF TY_VBAP,
        VBELN TYPE VBAP-VBELN,
        POSNR TYPE VBAP-POSNR,
        MATNR TYPE VBAP-MATNR,
        ZMENG TYPE VBAP-ZMENG,
        NETPR TYPE VBAP-NETPR,
      END OF TY_VBAP.
TYPESBEGIN OF TY_LIKP,
        VBELN TYPE LIKP-VBELN,
      END OF TY_LIKP.
TYPESBEGIN OF TY_LIPS,
        VBELN TYPE LIPS-VBELN,
        POSNR TYPE LIPS-POSNR,
        LFIMG TYPE LIPS-LFIMG,
        NETPR TYPE LIPS-NETPR,
      END OF TY_LIPS.
TYPESBEGIN OF TY_VBFA,
        VBELV TYPE VBFA-VBELV,
        POSNV TYPE VBFA-POSNV,
        VBELN TYPE VBFA-VBELN,
        POSNN TYPE VBFA-POSNN,
        VBTYP_N TYPE VBFA-VBTYP_N,
      END OF TY_VBFA.
TYPESBEGIN OF TY_FINAL,
        VBELN TYPE VBAP-VBELN,
        POSNR TYPE VBAP-POSNR,
        MATNR TYPE VBAP-MATNR,
        ZMENG TYPE VBAP-ZMENG,
        NETPR TYPE VBAP-NETPR,
        VBELN1 TYPE LIPS-VBELN,
        POSNR1 TYPE LIPS-POSNR,
        LFIMG TYPE LIPS-LFIMG,
        NETPR1 TYPE LIPS-NETPR,
      END OF TY_FINAL.

DATA IT_VBAK TYPE TABLE OF TY_VBAK,
       WA_VBAK TYPE TY_VBAK.
DATA IT_VBAP TYPE TABLE OF TY_VBAP,
       WA_VBAP TYPE TY_VBAP.
DATA IT_LIKP TYPE TABLE OF TY_LIKP,
       WA_LIKP TYPE TY_LIKP.
DATA IT_LIPS TYPE TABLE OF TY_LIPS,
       WA_LIPS TYPE TY_LIPS.
DATA IT_VBFA TYPE TABLE OF TY_VBFA,
       WA_VBFA TYPE TY_VBFA.
DATA IT_FINAL TYPE TABLE OF TY_FINAL,
       WA_FINAL TYPE TY_FINAL.

DATA V_TITLE TYPE STRING.
DATA V_FNAME TYPE STRING.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS S_VBELN FOR VBAK-VBELN NO-EXTENSION.
SELECT-OPTIONS S_VKORG FOR VBAK-VKORG NO INTERVALS NO-EXTENSION.
SELECT-OPTIONS S_VTWEG FOR VBAK-VTWEG NO INTERVALS NO-EXTENSION.
SELECT-OPTIONS S_SPART FOR VBAK-SPART NO INTERVALS NO-EXTENSION.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN SKIP.

PARAMETERS P_FILE TYPE RLGRAP-FILENAME.
PARAMETERS DOWNLOAD AS CHECKBOX.

INITIALIZATION.
  V_TITLE 'THIS IS SALES DOCUMENT:ITEM DATA AND DELIVERY DETAILS'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
  PERFORM GET_FILE_PATH.

AT SELECTION-SCREEN ON HELP-REQUEST FOR P_FILE.
  PERFORM GET_HELP_FOR_FILE_PATH.

AT SELECTION-SCREEN.
  PERFORM VALIDATE_SALESDOCUMENT.
  PERFORM VALIDATE_SALESORGANIZATION.
  PERFORM VALIDATE_DISTRIBUTIONCHANNEL.
  PERFORM VALIDATE_DIVISION.

START-OF-SELECTION.
  PERFORM GET_DATA.
  PERFORM DISPLAY_DATA.
  PERFORM DOWNLOAD_DATA.

END-OF-SELECTION.

TOP-OF-PAGE.
  PERFORM DISPLAY_HEADING.

END-OF-PAGE.
  PERFORM DISPLAY_FOOTER.


FORM GET_FILE_PATH .
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      PROGRAM_NAME  SYST-REPID
      DYNPRO_NUMBER SYST-DYNNR
      FIELD_NAME    P_FILE
    CHANGING
      FILE_NAME     P_FILE.
ENDFORM.                    " GET_FILE_PATH

FORM GET_HELP_FOR_FILE_PATH .
  MESSAGE 'PLEASE SELECT THE FILE PATH' TYPE 'I'.
ENDFORM.                    " GET_HELP_FOR_FILE_PATH

FORM VALIDATE_SALESDOCUMENT .
  SELECT SINGLE VBELN
         FROM VBAK
         INTO WA_VBAK
         WHERE VBELN IN S_VBELN.
  IF SY-SUBRC <> 0.
    MESSAGE 'THIS IS INVALID SALES DOCUMENT NO' TYPE 'I'.
  ENDIF.
ENDFORM.                    " VALIDATE_SALESDOCUMENT

FORM VALIDATE_SALESORGANIZATION .
  SELECT VKORG
    FROM VBAK
    INTO WA_VBAK
    UP TO ROWS
    WHERE VKORG IN S_VKORG.
  ENDSELECT.
  IF SY-SUBRC <> 0.
    MESSAGE 'THIS IS INVALID SALES ORGANIZATION' TYPE 'I'.
  ENDIF.
ENDFORM.                    " VALIDATE_SALESORGANIZATION

FORM VALIDATE_DISTRIBUTIONCHANNEL.
  SELECT VTWEG
    FROM VBAK
    INTO WA_VBAK
    UP TO ROWS
    WHERE VTWEG IN S_VTWEG.
  ENDSELECT.
  IF SY-SUBRC <> 0.
    MESSAGE 'THIS IS INVALID DISTRIBUTION CHANNEL' TYPE 'I'.
  ENDIF.
ENDFORM.                    " VALIDATE_DISTRIBUTIONCHANNEL

FORM VALIDATE_DIVISION .
  SELECT SPART
    FROM VBAK
    INTO WA_VBAK
    UP TO ROWS
    WHERE SPART IN S_SPART.
  ENDSELECT.
  IF SY-SUBRC <> 0.
    MESSAGE 'THIS IS INVALID DIVISION' TYPE 'I'.
  ENDIF.
ENDFORM.                    " VALIDATE_DIVISION

***********************************
READ MORE BDC DETAILS  *
***********************************

FORM GET_DATA .
  SELECT VBELN
         VKORG
         VTWEG
         SPART
    FROM VBAK
    INTO TABLE IT_VBAK
    WHERE VBELN IN S_VBELN
    AND VKORG IN S_VKORG
    AND VTWEG IN S_VTWEG
    AND SPART IN S_SPART.
  IF IT_VBAK IS NOT INITIAL.

    SELECT VBELN
           POSNR
           MATNR
           ZMENG
           NETPR
      FROM VBAP
      INTO TABLE IT_VBAP
      FOR ALL ENTRIES IN IT_VBAK
      WHERE VBELN IT_VBAK-VBELN.

    SELECT VBELV
           POSNV
           VBELN
           POSNN
           VBTYP_N
      FROM VBFA
      INTO TABLE IT_VBFA
      FOR ALL ENTRIES IN IT_VBAP
      WHERE VBELV IT_VBAP-VBELN
        AND VBTYP_N 'J'.

    SELECT VBELN
      FROM LIKP
      INTO TABLE IT_LIKP
      FOR ALL ENTRIES IN IT_VBFA
      WHERE VBELN IT_VBFA-VBELN.

    SELECT VBELN
           POSNR
           LFIMG
           NETPR
      FROM LIPS
      INTO TABLE IT_LIPS
      FOR ALL ENTRIES IN IT_LIKP
      WHERE VBELN IT_LIKP-VBELN.

    SORT IT_VBAP.
    SORT IT_LIPS.

    LOOP AT IT_VBFA INTO WA_VBFA.
      READ TABLE IT_LIPS INTO WA_LIPS WITH KEY VBELN WA_VBFA-VBELN
                                               POSNR WA_VBFA-POSNN
                                               BINARY SEARCH.
      READ TABLE IT_VBAP INTO WA_VBAP WITH KEY VBELN WA_VBFA-VBELV
                                               POSNR WA_VBFA-POSNV
                                               BINARY SEARCH.
      WA_FINAL-VBELN  WA_VBAP-VBELN.
      WA_FINAL-POSNR  WA_VBAP-POSNR.
      WA_FINAL-MATNR  WA_VBAP-MATNR.
      WA_FINAL-ZMENG  WA_VBAP-ZMENG.
      WA_FINAL-NETPR  WA_VBAP-NETPR.
      WA_FINAL-VBELN1 WA_LIPS-VBELN.
      WA_FINAL-POSNR1 WA_LIPS-POSNR.
      WA_FINAL-LFIMG  WA_LIPS-LFIMG.
      WA_FINAL-NETPR1 WA_LIPS-NETPR.
      APPEND WA_FINAL TO IT_FINAL.
      CLEAR WA_FINAL.
    ENDLOOP.
  ENDIF.
ENDFORM.                    " GET_DATA

FORM DISPLAY_DATA .
  LOOP AT IT_FINAL INTO WA_FINAL.
    WRITE / WA_FINAL-VBELN,
              WA_FINAL-POSNR,
              WA_FINAL-MATNR,
              WA_FINAL-ZMENG,
              WA_FINAL-NETPR,
              WA_FINAL-VBELN1,
              WA_FINAL-POSNR1,
              WA_FINAL-LFIMG,
              WA_FINAL-NETPR.
  ENDLOOP.
ENDFORM.                    " DISPLAY_DATA

FORM DOWNLOAD_DATA .
  IF DOWNLOAD 'X'.
    V_FNAME P_FILE.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        FILENAME              V_FNAME
        FILETYPE              'ASC'
        WRITE_FIELD_SEPARATOR 'X'
      TABLES
        DATA_TAB              IT_FINAL.
    IF SY-SUBRC 0.
      MESSAGE 'SUCCESSFULLY DOWNLOADED' TYPE 'I'.
    ENDIF.
  ENDIF.
ENDFORM.                    " DOWNLOAD_DATA

FORM DISPLAY_HEADING .
  WRITESY-ULINE.
  WRITE :/45 V_TITLE.
  WRITESY-ULINE.
ENDFORM.                    " DISPLAY_HEADING

FORM DISPLAY_FOOTER .
  WRITESY-ULINE.
  WRITE :/45 'IBM'.
  WRITESY-ULINE.
ENDFORM.                    " DISPLAY_FOOTER


READ MORE BDC DETAILS.........

Tuesday, February 26, 2019

Interview Questions & Answers report related in SAP ABAP.



Interview Questions & Answers report related in SAP ABAP.

REPORT GENERATION – FORMATTING

1.The alignment of a type ‘c’ field in a report is left Aligned.

2. In the statement Write:/15(10) Ofal-lifnr. what do the number 15 and 10 stand for
15 stand for the offset on the screen and 10 stands for the field length displayed.

3.Specify the default alignment for the following field types:‘D’ – Left, ‘F’-Right, ‘N’-Left, ‘I’-Right, ‘T’-Left.

4. If s_time has the value ‘123456’ how would you get an output of 12:34:56 with a single ‘Write:’ statement.
Write:s_time using edit mask’--:--:--‘.

5. In order to suppress the leading zeroes of a number field the keywords used are NO-ZERO.

6. The total no of date formats that can be used to display a date during output is MM/DD/YY, DD/MM/YY, DD/MM/YYYY, MM/DD/YYYY, MMDDYY, DDMMYY, YYMMDD.

7. The UNDER Command allows for vertical alignment of fields one below the other.

8. In order to concatenate strings only for output purposes the command NO-GAP can be used in conjunction with the ‘Write’ statement.

9. The no of decimal places for output can be defines within a write statement. (T/F).
TRUE.  Write:/<F> decimals 2.

10.  Data can be moved from one field to another using a ‘Write:’ Statement and stored in the desired format. (T/F).
TRUE. Write: Date_1 to Date_2 format DD/MM/YY.

11.  In the statement Write:/15(10) lfa1-lifnr. The values 15 and 11 can also be defined by variables (T/F). False.

12. Differentiate between the following two statements if any.
ULINE.
Write: sy-uline.
No-difference.  Except that uline is used outside the ‘Write’ Statement.

13. In order to skip a single line the number of lines need not be given as an assignment (T/F)
TRUE.

14. The “SKIP TO LINE line number” is dependent on the LINE-COUNT  statement included in the report statement of the program.

15. In order to skip columns the command used is POSITION <n>.
   
16.  In order to have boldfaced text as output the command used is Write:<f>INTENSIFIED.
   
17.  Background and foreground colors can be interchanged using the command Format Inverse.
  
18.  In order to restore the system defaults for all changes made with the format statement is Format Reset.

     19.   Like ULINE the statement VLINE is used to insert vertical lines. (T/F).
False.
20. Suppressing the number signs (+/-) is carried out using the addition NO-SIGNS to the Write statement. (T/F).    False.

21.  If SY-UZEIT has the value 6:34:45 it can be displayed as 063445 using No Edit Mask.

22.  If the variable “Text” has the value ‘ABCDEF’ the output for the statement “Write:/Text+2(3)” will be “CDE” 

23.  The fields specified by select-options and parameters statement cannot be grouped together in the selection screen. (T/F).  False.

24.  When calling an external report the parameters or select-options specified in the external report cannot be called. (T/F)
FALSE.

25.  Selection Texts  in the text elements of the program helps in changing the displayed names of variables in the parameters statement.

26.  Type F  datatype cannot be used to define parameters.
27. Rounding off of values can be carried out using the write statement. (T/F). TRUE

28.  How would you define the exponents for a type ‘f’ field?
Exponent <e>.

29.  How would you format the output as left, centered or right-justified using the write statement.
Left-justified, Centered, Right-justified.

30.  If the same formatting options were used for a WRITE statement that follows the FORMAT statement, which settings would take precedence.
The settings in the Write Statement.

31.  For each new event, the system resets all formatting options to their default values (T/F)
TRUE.

32.  All formatting options have the default value OFF. (T/F).
TRUE.

33.  How would you set the formatting options statically and dynamically within a report? Statically: FORMAT <option1>[ON|OFF]….
Dynamically: FORMAT <option1> = <var1><option2>=<var2>….

34.  The page footer is defined using the statement END-OF-PAGE.

35.  The processing block following END-OF-PAGE is processed only if you reserve lines for the footer in the LINE-COUNT option of the REPORT statement. (T/F)
TRUE.

36.  To execute a page break under the condition that less than a certain number of lines is left on a page is achieved by RESERVE n lines.

37.  The RESERVE statement only takes effect if output is written to the subsequent page.  No blank pages are created and it defines a block of lines that must be output as a whole. (T/F). TRUE.

38.  To set the next output line to the first line of a block of lines defined with the RESERVE statement the statement BACK  is used.

39.  What is the limit for the length of a page if the page length is not specified in the report statement. 60,000 lines.

40.  How would you start the printing process from within the program while creating a list?
NEW-PAGE PRINT ON.

41.  You can change the width of pages within list levels triggered by page breaks. (T/F).
FALSE.

42.  Hotspots are special areas of an output list used to trigger events. (T/F) TRUE.

43.  To designate fields as hotspots at runtime, use FORMAT HOTSPOT = <h>.

44.  Horizontal lines created with ULINE and blank lines created with SKIP can be formatted as hotspots. (T/F). FALSE.

45.  How would you suppress the display of a parameter on the selection screen?
Parameters <p> ………..No-Display.

46.  Can you assign a matchcode object to a parameter? If so how?
Yes.  PARAMETERS <p>……..MATCHCODE OBJECT <obj>……..

47.  For each SELECT-OPTIONS statement, the system creates a selection table. (T/F)
TRUE.

48.  To position a set of parameters or comments on a single line on the selection screen, you must declare the elements in a block enclosed by
SELECTION-SCREEN BEGIN OF LINE.
……..
SELECTION-SCREEN END OF LINE.

49.  How can Symbols or R/3 icons be output on the screen?
     WRITE <symbol-name>AS SYMBOL.
     WRITE <icon-name> AS ICON.

50.  In the standard setting, you cannot create empty lines with the WRITE statement alone. (T/F).  TRUE.

Wednesday, December 26, 2018

Upload program in z-table in SAP ABAP.


Upload program in ztable.
This is Table

FILE FORMAT IN (xlsx).
ID
NAME
EMPDES
EMPPHONE
53
Alex
9874563215
54
Ponting
8745632103

*&---------------------------------------------------------------------*
*& Report  ZSW_UPLOAD_TABLE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZSW_UPLOAD_TABLE.

TYPE-POOLS truxs.
TABLES ZEMP03.
PARAMETER p_file TYPE rlgrap-filename DEFAULT 'C:\Users\swadesh\Desktop\Book1_1.xlsx'.

TYPES:BEGIN OF t_tab,
         EMPID 
TYPE ZEMP03-EMPID,
         EMPNAME 
TYPE ZEMP03-EMPNAME,
         EMPDES 
TYPE ZEMP03-EMPDES,
         EMPPHONE 
TYPE ZEMP03-EMPPHONE,
      
END OF t_tab.

DATA :t_upload TYPE STANDARD TABLE OF t_tab,
      wa_upload 
TYPE t_tab,
      it_type 
TYPE truxs_t_text_data.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  
CALL FUNCTION 'F4_FILENAME'
    
EXPORTING
      PROGRAM_NAME  
SYST-CPROG
      DYNPRO_NUMBER 
SYST-DYNNR
      field_name    
'P_FILE'
    
IMPORTING
      file_name     
p_file.

START-OF-SELECTION.

*  Uploading the data in the file into internal table

  
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    
EXPORTING
*     I_FIELD_SEPERATOR    =
      I_LINE_HEADER        
'X'
      i_tab_raw_data       
it_type
      i_filename           
p_file
    
TABLES
      i_tab_converted_data 
t_upload[]
    
EXCEPTIONS
      conversion_failed    
1
      
OTHERS               2.

  
IF sy-subrc NE 0.
    
MESSAGE ID sy-msgid
    
TYPE sy-msgty
    
NUMBER sy-msgno
    
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  
else.
    
MESSAGE 'Dada Upload sucessfull' TYPE 'I'.
  
endif.

END-OF-SELECTION.

*  Uploading the data into the database table

  
LOOP AT T_UPLOAD INTO WA_UPLOAD.
    ZEMP03
-EMPID    WA_UPLOAD-EMPID.
    ZEMP03
-EMPNAME  WA_UPLOAD-EMPNAME.
    ZEMP03
-EMPDES   WA_UPLOAD-EMPDES.
    ZEMP03
-EMPPHONE WA_UPLOAD-EMPPHONE.
    
MODIFY ZEMP03.
  
ENDLOOP.



After Updating Result.