ABAP Select data from SAP table BAPITCCONDOC into internal table

Get Example source ABAP code based on a different SAP table
  

Below is a number of ABAP code snippets to demonstrate how to select data from SAP BAPITCCONDOC table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to BAPITCCONDOC. See here for more generic Select statement tips.

Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.

There is also a full declaration of the BAPITCCONDOC table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.

DATA: IT_BAPITCCONDOC TYPE STANDARD TABLE OF BAPITCCONDOC,
      WA_BAPITCCONDOC TYPE BAPITCCONDOC,
      GD_STR TYPE STRING.

DATA: lo_typedescr type REF TO cl_abap_typedescr.
DATA: lv_fieldname type fieldname.

FIELD-SYMBOLS: <FIELD> TYPE any.
FIELD-SYMBOLS: <BAPITCCONDOC> TYPE BAPITCCONDOC.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_BAPITCCONDOC.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM BAPITCCONDOC
  INTO TABLE IT_BAPITCCONDOC.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM BAPITCCONDOC
*  INTO TABLE @DATA(IT_BAPITCCONDOC2).
*--Further methods of using ABAP code to  select data from SAP database tables

*You can also declare the header/work area using the in-line DATA declaration method
READ TABLE IT_BAPITCCONDOC INDEX 1 INTO DATA(WA_BAPITCCONDOC2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_BAPITCCONDOC ASSIGNING <BAPITCCONDOC>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPITCCONDOC>-TRCONT_ITEM = 1.
<BAPITCCONDOC>-COND_ST_NO = 1.
<BAPITCCONDOC>-COND_COUNT = 1.
<BAPITCCONDOC>-APPLICATIO = 1.
<BAPITCCONDOC>-COND_TYPE = 1.
ENDLOOP.

LOOP AT IT_BAPITCCONDOC INTO WA_BAPITCCONDOC.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_BAPITCCONDOC-CONPRICDAT, sy-vline,
WA_BAPITCCONDOC-CALCTYPCON, sy-vline,
WA_BAPITCCONDOC-CONBASEVAL, sy-vline,
WA_BAPITCCONDOC-SOCURRENCY, sy-vline,
WA_BAPITCCONDOC-SOCURR_ISO, sy-vline,
WA_BAPITCCONDOC-COND_VALUE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPITCCONDOC you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_BAPITCCONDOC TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_BAPITCCONDOC INTO WA_BAPITCCONDOC. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.

*Conversion exit CUNIT, internal->external for field COND_D_UNT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPITCCONDOC-COND_D_UNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPITCCONDOC-COND_D_UNT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field GL_ACCOUNT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPITCCONDOC-GL_ACCOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPITCCONDOC-GL_ACCOUNT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field GLACCOUNT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPITCCONDOC-GLACCOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPITCCONDOC-GLACCOUNT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field VENDOR_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPITCCONDOC-VENDOR_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPITCCONDOC-VENDOR_NO.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field CUSTNO_RR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPITCCONDOC-CUSTNO_RR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPITCCONDOC-CUSTNO_RR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field UNITMEASUR CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_BAPITCCONDOC-UNITMEASUR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPITCCONDOC-UNITMEASUR.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_BAPITCCONDOC_STR,
TRCONT_ITEM TYPE STRING,
COND_ST_NO TYPE STRING,
COND_COUNT TYPE STRING,
APPLICATIO TYPE STRING,
COND_TYPE TYPE STRING,
CONPRICDAT TYPE STRING,
CALCTYPCON TYPE STRING,
CONBASEVAL TYPE STRING,
SOCURRENCY TYPE STRING,
SOCURR_ISO TYPE STRING,
COND_VALUE TYPE STRING,
CURRENCY TYPE STRING,
CURRENCISO TYPE STRING,
CONEXCHRAT TYPE STRING,
CONEXCHRAT_V TYPE STRING,
COND_P_UNT TYPE STRING,
COND_D_UNT TYPE STRING,
T_UNIT_ISO TYPE STRING,
NUMCONVERT TYPE STRING,
DENOMINATO TYPE STRING,
CONDTYPE TYPE STRING,
STAT_CON TYPE STRING,
SCALETYPE TYPE STRING,
ACCRUALS TYPE STRING,
CONINVOLST TYPE STRING,
CONDORIGIN TYPE STRING,
GROUPCOND TYPE STRING,
COND_UPDAT TYPE STRING,
ACCESS_SEQ TYPE STRING,
COND_NO TYPE STRING,
CONDCOUNT TYPE STRING,
ACCOUNTKEY TYPE STRING,
GL_ACCOUNT TYPE STRING,
TAX_CODE TYPE STRING,
ACCOUNT_KE TYPE STRING,
GLACCOUNT TYPE STRING,
WITHTAXCOD TYPE STRING,
VENDOR_NO TYPE STRING,
CUSTNO_RR TYPE STRING,
ROUNDOFFDI TYPE STRING,
CONDVALUE TYPE STRING,
CONDCNTRL TYPE STRING,
CONDISACTI TYPE STRING,
CONDCLASS TYPE STRING,
CONDCOINHD TYPE STRING,
INDIBASVAL TYPE STRING,
INDICONVAL TYPE STRING,
FACTBASVAL TYPE STRING,
STRUCTCOND TYPE STRING,
FACTCONBAS TYPE STRING,
SCALEBASIN TYPE STRING,
SCALBASVAL TYPE STRING,
UNITMEASUR TYPE STRING,
TUNITISO TYPE STRING,
CURRENCY_SCALE TYPE STRING,
CURR_ISO_SCALE TYPE STRING,
CONBASEVAL_K TYPE STRING,
CONDCURRENCY TYPE STRING,
COND_CURR_ISO TYPE STRING,
CONDVALUE_K TYPE STRING,
CONDINCOMP TYPE STRING,
CONDCONFIG TYPE STRING,
CONDCHAMAN TYPE STRING,
PRICESOURC TYPE STRING,
VARIANCOND TYPE STRING,
LEVEL_BOM TYPE STRING,
PATH_BOM TYPE STRING,
RELACCASSI TYPE STRING,
INDIMATMAI TYPE STRING,
TAXJURISDI TYPE STRING,
ACCESS_SEQ_LONG TYPE STRING,
COND_COUNT_LONG TYPE STRING,
CONDCOINHD_LONG TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPITCCONDOC_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_BAPITCCONDOC_STR-TRCONT_ITEM sy-vline
WA_BAPITCCONDOC_STR-COND_ST_NO sy-vline
WA_BAPITCCONDOC_STR-COND_COUNT sy-vline
WA_BAPITCCONDOC_STR-APPLICATIO sy-vline
WA_BAPITCCONDOC_STR-COND_TYPE sy-vline
WA_BAPITCCONDOC_STR-CONPRICDAT sy-vline
WA_BAPITCCONDOC_STR-CALCTYPCON sy-vline
WA_BAPITCCONDOC_STR-CONBASEVAL sy-vline
WA_BAPITCCONDOC_STR-SOCURRENCY sy-vline
WA_BAPITCCONDOC_STR-SOCURR_ISO sy-vline
WA_BAPITCCONDOC_STR-COND_VALUE sy-vline
WA_BAPITCCONDOC_STR-CURRENCY sy-vline
WA_BAPITCCONDOC_STR-CURRENCISO sy-vline
WA_BAPITCCONDOC_STR-CONEXCHRAT sy-vline
WA_BAPITCCONDOC_STR-CONEXCHRAT_V sy-vline
WA_BAPITCCONDOC_STR-COND_P_UNT sy-vline
WA_BAPITCCONDOC_STR-COND_D_UNT sy-vline
WA_BAPITCCONDOC_STR-T_UNIT_ISO sy-vline
WA_BAPITCCONDOC_STR-NUMCONVERT sy-vline
WA_BAPITCCONDOC_STR-DENOMINATO sy-vline
WA_BAPITCCONDOC_STR-CONDTYPE sy-vline
WA_BAPITCCONDOC_STR-STAT_CON sy-vline
WA_BAPITCCONDOC_STR-SCALETYPE sy-vline
WA_BAPITCCONDOC_STR-ACCRUALS sy-vline
WA_BAPITCCONDOC_STR-CONINVOLST sy-vline
WA_BAPITCCONDOC_STR-CONDORIGIN sy-vline
WA_BAPITCCONDOC_STR-GROUPCOND sy-vline
WA_BAPITCCONDOC_STR-COND_UPDAT sy-vline
WA_BAPITCCONDOC_STR-ACCESS_SEQ sy-vline
WA_BAPITCCONDOC_STR-COND_NO sy-vline
WA_BAPITCCONDOC_STR-CONDCOUNT sy-vline
WA_BAPITCCONDOC_STR-ACCOUNTKEY sy-vline
WA_BAPITCCONDOC_STR-GL_ACCOUNT sy-vline
WA_BAPITCCONDOC_STR-TAX_CODE sy-vline
WA_BAPITCCONDOC_STR-ACCOUNT_KE sy-vline
WA_BAPITCCONDOC_STR-GLACCOUNT sy-vline
WA_BAPITCCONDOC_STR-WITHTAXCOD sy-vline
WA_BAPITCCONDOC_STR-VENDOR_NO sy-vline
WA_BAPITCCONDOC_STR-CUSTNO_RR sy-vline
WA_BAPITCCONDOC_STR-ROUNDOFFDI sy-vline
WA_BAPITCCONDOC_STR-CONDVALUE sy-vline
WA_BAPITCCONDOC_STR-CONDCNTRL sy-vline
WA_BAPITCCONDOC_STR-CONDISACTI sy-vline
WA_BAPITCCONDOC_STR-CONDCLASS sy-vline
WA_BAPITCCONDOC_STR-CONDCOINHD sy-vline
WA_BAPITCCONDOC_STR-INDIBASVAL sy-vline
WA_BAPITCCONDOC_STR-INDICONVAL sy-vline
WA_BAPITCCONDOC_STR-FACTBASVAL sy-vline
WA_BAPITCCONDOC_STR-STRUCTCOND sy-vline
WA_BAPITCCONDOC_STR-FACTCONBAS sy-vline
WA_BAPITCCONDOC_STR-SCALEBASIN sy-vline
WA_BAPITCCONDOC_STR-SCALBASVAL sy-vline
WA_BAPITCCONDOC_STR-UNITMEASUR sy-vline
WA_BAPITCCONDOC_STR-TUNITISO sy-vline
WA_BAPITCCONDOC_STR-CURRENCY_SCALE sy-vline
WA_BAPITCCONDOC_STR-CURR_ISO_SCALE sy-vline
WA_BAPITCCONDOC_STR-CONBASEVAL_K sy-vline
WA_BAPITCCONDOC_STR-CONDCURRENCY sy-vline
WA_BAPITCCONDOC_STR-COND_CURR_ISO sy-vline
WA_BAPITCCONDOC_STR-CONDVALUE_K sy-vline
WA_BAPITCCONDOC_STR-CONDINCOMP sy-vline
WA_BAPITCCONDOC_STR-CONDCONFIG sy-vline
WA_BAPITCCONDOC_STR-CONDCHAMAN sy-vline
WA_BAPITCCONDOC_STR-PRICESOURC sy-vline
WA_BAPITCCONDOC_STR-VARIANCOND sy-vline
WA_BAPITCCONDOC_STR-LEVEL_BOM sy-vline
WA_BAPITCCONDOC_STR-PATH_BOM sy-vline
WA_BAPITCCONDOC_STR-RELACCASSI sy-vline
WA_BAPITCCONDOC_STR-INDIMATMAI sy-vline
WA_BAPITCCONDOC_STR-TAXJURISDI sy-vline
WA_BAPITCCONDOC_STR-ACCESS_SEQ_LONG sy-vline
WA_BAPITCCONDOC_STR-COND_COUNT_LONG sy-vline
WA_BAPITCCONDOC_STR-CONDCOINHD_LONG sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.