Skip to Content
0
Jul 12, 2019 at 01:02 PM

Issue facing with SUM in control break statements.

138 Views

Hi All,

I just started learning ABAP. I am facing issue with SUM in control break statements.

I uploaded a file using FM GUI_UPLOAD, and tried to calculate sum using control break statements but its not working.Should we need to declare any other variable to store the value? Could you please help me with this?

Uploaded images of input and output as well.

Thanks in advance.

types: begin of ty_cont,
        name type string,
        module type string,
        num type string,
      end of ty_cont.

data: it_cont TYPE TABLE OF ty_cont,
      wa_cont TYPE ty_cont,
      v_flag type c.

CALL FUNCTION 'GUI_UPLOAD'

  EXPORTING
    FILENAME                = 'C:\Users\1210261\Desktop\notepad.txt'
    FILETYPE                = 'ASC'
    HAS_FIELD_SEPARATOR     = 'X'

  TABLES
    DATA_TAB                = it_cont
  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
    OTHERS                  = 17.

IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

IF SY-SUBRC = 0.
  SORT IT_CONT.
  loop at it_cont INTO wa_cont.

    AT FIRST.
      write: / 'name',
           12 'module',
           24 'num'.
    ENDAT.

    AT NEW name.
      v_flag = 'X'.
    ENDAT.
   
 if v_flag = 'X'.
      write: / wa_cont-name,
               12 wa_cont-module,
               24 wa_cont-num.
    else.

     write: /12 wa_cont-module,
            24 wa_cont-num.
    ENDIF.

    AT END OF NAME.
      SUM.
        WRITE: / 'the sub total is:', wa_CONT-NUM.
      SUM.
    ENDAT.

    AT LAST.
      SUM.
        WRITE: / 'the grand total is:', wa_CONT-NUM.
      SUM.
    ENDAT.

clear: wa_CONT, v_flag.
  ENDLOOP.
 ENDIF.

Attachments

input.png (5.0 kB)
output.png (7.0 kB)