ABAP Select data from SAP table /ACCGO/CAS_S_CAH_DB_INT 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 /ACCGO/CAS_S_CAH_DB_INT 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 /ACCGO/CAS_S_CAH_DB_INT. 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 /ACCGO/CAS_S_CAH_DB_INT 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_/ACCGO/CAS_S_CAH_DB_INT TYPE STANDARD TABLE OF /ACCGO/CAS_S_CAH_DB_INT,
      WA_/ACCGO/CAS_S_CAH_DB_INT TYPE /ACCGO/CAS_S_CAH_DB_INT,
      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: </ACCGO/CAS_S_CAH_DB_INT> TYPE /ACCGO/CAS_S_CAH_DB_INT.

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

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM /ACCGO/CAS_S_CAH_DB_INT
  INTO TABLE IT_/ACCGO/CAS_S_CAH_DB_INT.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /ACCGO/CAS_S_CAH_DB_INT
*  INTO TABLE @DATA(IT_/ACCGO/CAS_S_CAH_DB_INT2).
*--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_/ACCGO/CAS_S_CAH_DB_INT INDEX 1 INTO DATA(WA_/ACCGO/CAS_S_CAH_DB_INT2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/ACCGO/CAS_S_CAH_DB_INT ASSIGNING </ACCGO/CAS_S_CAH_DB_INT>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</ACCGO/CAS_S_CAH_DB_INT>-MANDT = 1.
</ACCGO/CAS_S_CAH_DB_INT>-APPLDOC = 1.
</ACCGO/CAS_S_CAH_DB_INT>-HDR_GUID = 1.
</ACCGO/CAS_S_CAH_DB_INT>-DOC_TYPE = 1.
</ACCGO/CAS_S_CAH_DB_INT>-ADTYP = 1.
ENDLOOP.

LOOP AT IT_/ACCGO/CAS_S_CAH_DB_INT INTO WA_/ACCGO/CAS_S_CAH_DB_INT.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/ACCGO/CAS_S_CAH_DB_INT-BLDAT, sy-vline,
WA_/ACCGO/CAS_S_CAH_DB_INT-BUDAT, sy-vline,
WA_/ACCGO/CAS_S_CAH_DB_INT-PODAT, sy-vline,
WA_/ACCGO/CAS_S_CAH_DB_INT-POTIM, sy-vline,
WA_/ACCGO/CAS_S_CAH_DB_INT-REF_DOC_TYPE, sy-vline,
WA_/ACCGO/CAS_S_CAH_DB_INT-REF_DOC, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/ACCGO/CAS_S_CAH_DB_INT 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_/ACCGO/CAS_S_CAH_DB_INT 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_/ACCGO/CAS_S_CAH_DB_INT INTO WA_/ACCGO/CAS_S_CAH_DB_INT. *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 ALPHA, internal->external for field APPLDOC CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/ACCGO/CAS_S_CAH_DB_INT-APPLDOC IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ACCGO/CAS_S_CAH_DB_INT-APPLDOC.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit GJAHR, internal->external for field MJAHR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_/ACCGO/CAS_S_CAH_DB_INT-MJAHR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ACCGO/CAS_S_CAH_DB_INT-MJAHR.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit GJAHR, internal->external for field GJAHR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_/ACCGO/CAS_S_CAH_DB_INT-GJAHR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ACCGO/CAS_S_CAH_DB_INT-GJAHR.
WRITE:/ 'New Value:', ld_input.

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

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

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

*Conversion exit TSTLC, internal->external for field CREATED_ON CALL FUNCTION 'CONVERSION_EXIT_TSTLC_OUTPUT' EXPORTING input = WA_/ACCGO/CAS_S_CAH_DB_INT-CREATED_ON IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ACCGO/CAS_S_CAH_DB_INT-CREATED_ON.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTLC, internal->external for field CHANGED_ON CALL FUNCTION 'CONVERSION_EXIT_TSTLC_OUTPUT' EXPORTING input = WA_/ACCGO/CAS_S_CAH_DB_INT-CHANGED_ON IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ACCGO/CAS_S_CAH_DB_INT-CHANGED_ON.
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_/ACCGO/CAS_S_CAH_DB_INT_STR,
MANDT TYPE STRING,
APPLDOC TYPE STRING,
HDR_GUID TYPE STRING,
DOC_TYPE TYPE STRING,
ADTYP TYPE STRING,
BLDAT TYPE STRING,
BUDAT TYPE STRING,
PODAT TYPE STRING,
POTIM TYPE STRING,
REF_DOC_TYPE TYPE STRING,
REF_DOC TYPE STRING,
MJAHR TYPE STRING,
REF_APP_DOC TYPE STRING,
REF_APP_DOC_TYP TYPE STRING,
REF_ADTYP TYPE STRING,
STRING_CIRCLE TYPE STRING,
STATUS TYPE STRING,
NO_PH_REC TYPE STRING,
NFNUM TYPE STRING,
NFVALID TYPE STRING,
STKZN TYPE STRING,
LFSNR TYPE STRING,
TROP TYPE STRING,
SPLIT TYPE STRING,
NFFRE TYPE STRING,
FUTURE TYPE STRING,
TROP_EARLY_INVOICE TYPE STRING,
BELNR TYPE STRING,
GJAHR TYPE STRING,
COMMINGLED TYPE STRING,
DNTOT TYPE STRING,
NFR_CURR TYPE STRING,
DNQTY TYPE STRING,
DNUOM TYPE STRING,
J_1BEXBASE TYPE STRING,
BASE_CURR TYPE STRING,
MWSKZ TYPE STRING,
REF_TC TYPE STRING,
REF_IT TYPE STRING,
EBELN TYPE STRING,
EBELP TYPE STRING,
DELIVERY_NFVALID TYPE STRING,
CREATED_BY TYPE STRING,
CREATED_ON TYPE STRING,
CHANGED_BY TYPE STRING,
CHANGED_ON TYPE STRING,
SUCC_ARCH TYPE STRING,END OF T_EKKO_STR. DATA: WA_/ACCGO/CAS_S_CAH_DB_INT_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_/ACCGO/CAS_S_CAH_DB_INT_STR-MANDT sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-APPLDOC sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-HDR_GUID sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-DOC_TYPE sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-ADTYP sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-BLDAT sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-BUDAT sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-PODAT sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-POTIM sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-REF_DOC_TYPE sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-REF_DOC sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-MJAHR sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-REF_APP_DOC sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-REF_APP_DOC_TYP sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-REF_ADTYP sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-STRING_CIRCLE sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-STATUS sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-NO_PH_REC sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-NFNUM sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-NFVALID sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-STKZN sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-LFSNR sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-TROP sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-SPLIT sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-NFFRE sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-FUTURE sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-TROP_EARLY_INVOICE sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-BELNR sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-GJAHR sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-COMMINGLED sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-DNTOT sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-NFR_CURR sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-DNQTY sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-DNUOM sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-J_1BEXBASE sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-BASE_CURR sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-MWSKZ sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-REF_TC sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-REF_IT sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-EBELN sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-EBELP sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-DELIVERY_NFVALID sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-CREATED_BY sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-CREATED_ON sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-CHANGED_BY sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-CHANGED_ON sy-vline
WA_/ACCGO/CAS_S_CAH_DB_INT_STR-SUCC_ARCH sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.