Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SY-DBCNT QUESTION ?

Former Member
0 Likes
3,046

CAN ANYONE TELL ME HOW TO USE SY-DBCNT AFTER THE SELECT STATEMENT ? I NEED THIS TO KNOW HOW MY RECORDS MY SELECT QUERY IS RETURNING ? THKS!

select * from ekbe into ekbe where

ebeln = it_out-ebeln

and ebelp = it_out-ebelp

and ebeln = it_out-ebeln_ekpo

and ebelp = it_out-ebelp_ekpo

  • and buzei = it_out-buzei

and lfbnr = it_out-lfbnr

and lfpos = it_out-lfpos

and menge = it_out-menge

and bewtp = 'E'

and bwart = 101.

AFTER THIS ?

1 ACCEPTED SOLUTION
Read only

former_member194669
Active Contributor
0 Likes
2,166

Hi,



select * from ekbe into table i_ekbe where
ebeln = it_out-ebeln
and ebelp = it_out-ebelp
and ebeln = it_out-ebeln_ekpo
and ebelp = it_out-ebelp_ekpo
* and buzei = it_out-buzei
and lfbnr = it_out-lfbnr
and lfpos = it_out-lfpos
and menge = it_out-menge
and bewtp = 'E'
and bwart = 101.

DESCRIBE TABLE i_ekbe LINES l_count.

in l_count u will get the no of lines,

aRs

CAN ANYONE TELL ME HOW TO USE SY-DBCNT AFTER THE SELECT STATEMENT ? I NEED THIS TO KNOW HOW MY RECORDS MY SELECT QUERY IS RETURNING ? THKS!

select * from ekbe into ekbe where

ebeln = it_out-ebeln

and ebelp = it_out-ebelp

and ebeln = it_out-ebeln_ekpo

and ebelp = it_out-ebelp_ekpo

  • and buzei = it_out-buzei

and lfbnr = it_out-lfbnr

and lfpos = it_out-lfpos

and menge = it_out-menge

and bewtp = 'E'

and bwart = 101.

AFTER THIS ?

12 REPLIES 12
Read only

gopi_narendra
Active Contributor
0 Likes
2,166

select * from ekbe
         into table it_ekbe 
         where ebeln = it_out-ebeln
           and ebelp = it_out-ebelp
           and ebeln = it_out-ebeln_ekpo
           and ebelp = it_out-ebelp_ekpo
           * and buzei = it_out-buzei
           and lfbnr = it_out-lfbnr
           and lfpos = it_out-lfpos
           and menge = it_out-menge
           and bewtp = 'E'
           and bwart = 101.
    " after this use the describe statement like this
    data : N type I.
    describe table it_ekbe lines N.
    " N is the number of records in your internal table

Regards

Gopi

Read only

Former Member
0 Likes
2,166

Hi,

The system field sy-dbcnt is always set to the number of rows that were actually selected.

After SELECT statement you can use it.

select....

endselect.

if sy-dbcnt = 0.

No rows selected.

endif.

Reward if useful!

Read only

Former Member
0 Likes
2,166

after select query use this,

check sy-subrc eq 0.

l_count = sy-dbcnt.

Regards,

Niyaz

Read only

former_member194669
Active Contributor
0 Likes
2,167

Hi,



select * from ekbe into table i_ekbe where
ebeln = it_out-ebeln
and ebelp = it_out-ebelp
and ebeln = it_out-ebeln_ekpo
and ebelp = it_out-ebelp_ekpo
* and buzei = it_out-buzei
and lfbnr = it_out-lfbnr
and lfpos = it_out-lfpos
and menge = it_out-menge
and bewtp = 'E'
and bwart = 101.

DESCRIBE TABLE i_ekbe LINES l_count.

in l_count u will get the no of lines,

aRs

Read only

Former Member
0 Likes
2,166

u can just read the system field sy-dbcnt to check how many lines it contains.

the system automatically sets this field after the select statement

reward points plz

Read only

former_member404244
Active Contributor
0 Likes
2,166

Hi,

It will return the number of records that satisfy ur where clause.So in SE11 give the table name as EKBE and then specify the values in se11 and check the entries.

Regards,

nagaraj

Read only

Former Member
0 Likes
2,166

Hi,

Refer code below and u will get idea:

data : begin of itab occurs 0,
         DMBTR like BSEG-DMBTR,
         End of itab.
  data : v_count type i.
  data : total type i.
  
  select DMBTR
   from BSEG
   into TABLE itab
   .
*Now Sy-dbcnt gives the number of records retrieved.
   v_count = sy-dbcnt.
   loop at itab.
   AT LAST. 
*All the numeric fields are added at last
    SUM.
    total = itab-DMBTR.
   ENDAT.
   Endloop.

I am not going to change ur code so that u may get a practice for urself using above code.

Pls reward points.

Regards,

Ameet

Read only

Former Member
0 Likes
2,166

HI

Check this sample code

data: idoc_control like EDIDC,
      NUMBER_OF_DATA_RECORDS like sy-dbcnt,
      NUMBER_OF_STATUS_RECORDS like sy-dbcnt,
      INT_EDIDS like edids occurs 0 with header line,
      INT_EDIDD like edidd occurs 0 with header line.

TYPE-POOLS :  LEDID.

data: STRUCT_TYPE TYPE  LEDID_STRUCT_TYPE ,
      IDOC_STRUCT TYPE  LEDID_T_IDOC_STRUCT,
      SEGMENTS TYPE  LEDID_T_SEGMENT,
      SEGMENT_STRUCT TYPE  LEDID_T_SEGMENT_STRUCT,
      excel_tab(2000) occurs 0 with header line.



parameter: DOCNUM like edidc-docnum obligatory, ""Idoc Number
           sap_rel like SY-SAPRL default SY-SAPRL obligatory,
           pi_ver like EDI_VERREC-VERSION default '3' obligatory,
           d_excel as checkbox default 'X'. ""Download ?

start-of-selection.
  perform read_idoc.
  perform process_idoc.
  if d_excel = 'X'.
    perform download_to_excel.
  endif.

end-of-selection.

FORM read_idoc.
  CALL FUNCTION 'IDOC_READ_COMPLETELY'
       EXPORTING
            DOCUMENT_NUMBER          = docnum
       IMPORTING
            IDOC_CONTROL             = idoc_control
            NUMBER_OF_DATA_RECORDS   = NUMBER_OF_DATA_RECORDS
            NUMBER_OF_STATUS_RECORDS = NUMBER_OF_STATUS_RECORDS
       TABLES
            INT_EDIDS                = INT_EDIDS
            INT_EDIDD                = INT_EDIDD
       EXCEPTIONS
            DOCUMENT_NOT_EXIST       = 1
            DOCUMENT_NUMBER_INVALID  = 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.

ENDFORM.                    "" read_idoc

FORM process_idoc.
  perform read_idoc_structure.
  perform display_data_records.
ENDFORM.                    "" process_idoc

FORM display_data_records.

  data: PE_seg_HEADER like EDI_SAPI01,
        segname like EDI_IAPI12-SEGMENTTYP,
        prev_segname like EDI_IAPI12-SEGMENTTYP value ' ',
        pt_fields2 like EDI_IAPI12 occurs 0 with header line,
        PT_FVALUES2 like EDI_IAPI14 occurs 0 with header line,
        byte_first type i,
        byte_last type i,
        field_val(50),
        tmp_str(15),
        tmp_str3(15),
        seg_repeats type i value 0,
        tmp_str2(15),
        tab_cr(1) type x value '09',
        tot_ctr type i value 0,
        ctr type i value 0,
        msg(40) type c.

  data: IDOC_STRUCT_wa TYPE  LEDID_IDOC_STRUCT.

  sort int_edidd by segnum.
  describe table int_edidd lines tot_ctr.
  loop at int_edidd.
    move int_edidd-segnam to segname.
    clear msg.
    concatenate 'Reading segment ' segname
                into msg separated by space.
    if tot_ctr <> 0.
      ctr = ( 100 * sy-tabix ) / tot_ctr.
    endif.
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = ctr
              TEXT       = msg.
    add 1 to seg_repeats.
    clear tmp_str2.
    if int_edidd-segnam <> prev_segname.
      seg_repeats = 1.
      clear: pe_seg_header, pt_fields2, pt_fvalues2.
      refresh: pt_fields2, pt_fvalues2.
      CALL FUNCTION 'SEGMENT_READ_COMPLETE'
           EXPORTING
                PI_SEGTYP                 = segname
                PI_RELEASE                = sap_rel
                PI_VERSION                = pi_ver
           IMPORTING
                PE_HEADER                 = pe_seg_header
           TABLES
                PT_FIELDS                 = pt_fields2
                PT_FVALUES                = pt_fvalues2
           EXCEPTIONS
                SEGMENT_UNKNOWN           = 1
                SEGMENT_STRUCTURE_UNKNOWN = 2
                OTHERS                    = 3.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      prev_segname = int_edidd-segnam.
    endif.
    read table idoc_struct into idoc_struct_wa with key
                           segment_type = int_edidd-segnam.
    if sy-subrc = 0.
      IF IDOC_STRUCT_WA-SYNTAX_ATTRIB-MUSTFL = 'X'.
        TMP_STR = 'Mandatory'.                  ""Mandatory
      ELSE.
        TMP_STR = 'Optional'.                  ""Optional
      ENDIF.
      if IDOC_STRUCT_wa-SEGMENT_TYPE_ATTRIB-QUALIFIER = 'X'.
        tmp_str3 = 'Qualified'.
      else.
        tmp_str3 = 'Non-Qualified'.
      endif.
      shift IDOC_STRUCT_wa-SYNTAX_ATTRIB-OCCMAX
                                 left deleting leading '0'.
      move seg_repeats to tmp_str2.
      condense: IDOC_STRUCT_wa-SYNTAX_ATTRIB-OCCMAX, tmp_str2.
      concatenate tmp_str2 'of'  IDOC_STRUCT_wa-SYNTAX_ATTRIB-OCCMAX
          into tmp_str2 separated by space.

      write :/ IDOC_STRUCT_wa-SEGMENT_TYPE,
           tmp_str,
           TMP_STR3,
           tmp_str2,
           IDOC_STRUCT_wa-SYNTAX_ATTRIB-HLEVEL,
           IDOC_STRUCT_wa-SEGMENT_TYPE_ATTRIB-plast,
           IDOC_STRUCT_wa-SEGMENT_TYPE_ATTRIB-DESCRP.
      if d_excel = 'X'.
        concatenate 'Segment Name' tab_cr
                    'Mand / Opt ' tab_cr
                    'Qual / non-Qual' tab_cr
                    'Seq of Max' tab_cr
                    'Level' tab_cr
                    'Owner' tab_cr
                    'Description'
                    into excel_tab.
        append excel_tab.
        concatenate IDOC_STRUCT_wa-SEGMENT_TYPE tab_cr
              tmp_str tab_cr
              TMP_STR3 tab_cr
              tmp_str2 tab_cr
              IDOC_STRUCT_wa-SYNTAX_ATTRIB-HLEVEL tab_cr
              IDOC_STRUCT_wa-SEGMENT_TYPE_ATTRIB-plast tab_cr
              IDOC_STRUCT_wa-SEGMENT_TYPE_ATTRIB-DESCRP
              into excel_tab.
        append excel_tab.
        concatenate tab_cr
                    'Field Nma' tab_cr
                    'Type' tab_cr
                    'Length' tab_cr
                    'Byte From' tab_cr
                    'Byte To' tab_cr
                    'Description' tab_cr
                    'Value' tab_cr
                    'Qualifier Meaning'
                    into excel_tab.
        append excel_tab.
      endif.
    endif.
    sort pt_fields2 by field_pos.
    byte_first = 0.
    loop at pt_fields2.
      clear: field_val.
      byte_last = pt_fields2-EXTLEN.
      write int_edidd-sdata+byte_first(byte_last) to
            field_val left-justified.
      shift pt_fields2-EXTLEN left deleting leading '0'.
      shift pt_fields2-byte_first left deleting leading '0'.
      shift pt_fields2-byte_last left deleting leading '0'.
      write:/ '   ', pt_fields2-fieldname,
              pt_fields2-datatype,
              pt_fields2-EXTLEN,
              pt_fields2-byte_first ,
              pt_fields2-byte_last,
              pt_fields2-descrp,
              field_val.
      read table pt_fvalues2 with key fieldname = pt_fields2-fieldname
                    fldvalue_l = field_val.
      add byte_last to byte_first.
      if sy-subrc = 0.
        write : pt_fvalues2-descrp.
      else.
        clear pt_fvalues2-descrp.
      endif.
      if d_excel = 'X'.
        concatenate tab_cr pt_fields2-fieldname tab_cr
                pt_fields2-datatype tab_cr
                pt_fields2-EXTLEN tab_cr
                pt_fields2-byte_first tab_cr
                pt_fields2-byte_last tab_cr
                pt_fields2-descrp tab_cr
                field_val tab_cr
                pt_fvalues2-descrp
                into excel_tab.
        append excel_tab.
      endif.
    endloop.
  endloop.
ENDFORM.                    "" display_data_records

FORM read_idoc_structure.
  data: idoctype type LEDID_IDOCTYPE.

  if not idoc_control-cimtyp is initial.
    STRUCT_TYPE = 'E'. ""Extended
    idoctype = idoc_control-cimtyp.
  else.
    STRUCT_TYPE = 'B'. ""Basic
    idoctype = idoc_control-idoctp.
  endif.

  CALL FUNCTION 'IDOC_TYPE_COMPLETE_READ'
       EXPORTING
            RELEASE              = sap_rel
            STRUCT_TYPE          = STRUCT_TYPE
            IDOCTYPE             = idoctype
            VERSION              = pi_ver
*       IMPORTING
*            IDOC_TYPE            = idoctype
       TABLES
            IDOC_STRUCT          = idoc_struct
            SEGMENTS             = segments
            SEGMENT_STRUCT       = segment_struct
       EXCEPTIONS
            IDOCTYPE_UNKNOWN     = 1
            IDOCSTRUCT_UNKNOWN   = 2
            SEGMENT_DATA_MISSING = 3
            ILLEGAL_STRUCT_TYPE  = 4
            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.                    "" read_idoc_structure

FORM download_to_excel.
  data: name like RLGRAP-FILENAME.

  shift docnum left deleting leading '0'.
  concatenate docnum '-' idoc_control-idoctp '.xls'
              into name.



  CALL FUNCTION 'RH_START_EXCEL_WITH_DATA'
   EXPORTING
     DATA_NAME                 = name
     DATA_TYPE                 = 'ASC'
     WAIT                      = ' '
   TABLES
     DATA_TAB                  = excel_tab
   EXCEPTIONS
     NO_BATCH                  = 1
     EXCEL_NOT_INSTALLED       = 2
     WRONG_VERSION             = 3
     INTERNAL_ERROR            = 4
     INVALID_TYPE              = 5
     CANCELLED                 = 6
     DOWNLOAD_ERROR            = 7
     OTHERS                    = 8
            .
  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.                    "" download_to_excel

Reward all helpfull answers

Regards

Pavan

Read only

Former Member
0 Likes
2,166

<b>SY-DBCNT describes Number of processed table rows</b>

Check this sample code...

REPORT ZBCTCB92.

TABLES: T000.

DATA: BEGIN OF T OCCURS 0,

FIELD(10),

END OF T.

DATA: NUM TYPE N.

DETAIL.

  • sy-linct and sy-linsz describes a page of the list

WRITE: / 'Example of sy-linct and sy-linsz'.

SKIP.

WRITE: / SY-LINCT, 'line and', (3) SY-LINSZ, 'column is a page'.

  • sy-index works in do-enddo and while-endwhile loops.

  • it contains the number of loop passes.

WRITE: /'Example of sy-index'.

SKIP.

DO 5 TIMES.

WRITE: SY-INDEX.

ENDDO.

  • sy-tabix is the index number of the currently processed row

  • for an internal table

SKIP.

WRITE: /'Example of sy-tabix'.

SKIP.

T-FIELD = 'One'. APPEND T.

T-FIELD = 'Two'. APPEND T.

T-FIELD = 'Three'. APPEND T.

T-FIELD = 'Four'. APPEND T.

T-FIELD = 'Five'. APPEND T.

WRITE: /'Example of sy-tabix I'.

SKIP.

LOOP AT T.

WRITE: / SY-TABIX, T-FIELD.

ENDLOOP.

*sy-fdpos contains off-set after string comparison and search operations

SKIP.

WRITE: /'Example of sy-fdpos'.

SKIP.

CLEAR T.

SEARCH T FOR 're'.

READ TABLE T INDEX SY-TABIX.

WRITE: / SY-TABIX, T-FIELD.

SKIP.

WRITE: /9 'At the example of sy-tabix, Row', (3) SY-TABIX, ',' ,

'keyword ''re'' found at off-set position:', (3) SY-FDPOS.

SKIP.

  • sy-dbcnt contains the number of selected records.

  • sy-subrc is 0 if an operation was successful.

WRITE: /'Example of sy-dbcnt and sy-subrc I'.

SKIP.

SELECT * FROM T000 WHERE MANDT BETWEEN '000' AND '066'.

WRITE: /10 'Mandant:', T000-MANDT.

ENDSELECT.

WRITE: /12 'Number of selected records:', SY-DBCNT CENTERED.

WRITE: /12 'Return code: ' RIGHT-JUSTIFIED, SY-SUBRC .

SKIP.

WRITE: /'Example of sy-dbcnt and sy-subrc II: don't find records'.

SKIP.

SELECT * FROM T000 WHERE MANDT EQ -1.

ENDSELECT.

WRITE: /12 'Number of selected records:', SY-DBCNT CENTERED.

WRITE: /12 'Return code: ' RIGHT-JUSTIFIED, SY-SUBRC.

Regards,

Pavan

Read only

Former Member
0 Likes
2,166

THANKS A LOT GUYS! THIS WILL HELP.

Read only

0 Likes
2,166

Hi,

I think that u required code for sy-dbcnt then why u require alternative for the same.

Pls be clear when mentioning subject frm next time.

I think that was not good as regards to points for our effort.

Regards,

Ameet

Read only

0 Likes
2,166

Hi,

Was looking for sy-dbcnt code, but then got a better way in this thread. Sorry in case any confusion caused - this being my first post. Very much appreciate your answer and help.

Thanks!