ABAP Select data from SAP table EECRM_CRMCONTRACTPOS_22 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 EECRM_CRMCONTRACTPOS_22 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 EECRM_CRMCONTRACTPOS_22. 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 EECRM_CRMCONTRACTPOS_22 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_EECRM_CRMCONTRACTPOS_22 TYPE STANDARD TABLE OF EECRM_CRMCONTRACTPOS_22,
      WA_EECRM_CRMCONTRACTPOS_22 TYPE EECRM_CRMCONTRACTPOS_22,
      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: <EECRM_CRMCONTRACTPOS_22> TYPE EECRM_CRMCONTRACTPOS_22.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM EECRM_CRMCONTRACTPOS_22
*  INTO TABLE @DATA(IT_EECRM_CRMCONTRACTPOS_222).
*--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_EECRM_CRMCONTRACTPOS_22 INDEX 1 INTO DATA(WA_EECRM_CRMCONTRACTPOS_222).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_EECRM_CRMCONTRACTPOS_22 ASSIGNING <EECRM_CRMCONTRACTPOS_22>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<EECRM_CRMCONTRACTPOS_22>-GUID_H = 1.
<EECRM_CRMCONTRACTPOS_22>-GUID_I = 1.
<EECRM_CRMCONTRACTPOS_22>-BU_PARTNER_GUID = 1.
<EECRM_CRMCONTRACTPOS_22>-BUAG_GUID = 1.
<EECRM_CRMCONTRACTPOS_22>-BUPA_NR = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_EECRM_CRMCONTRACTPOS_22-ISUVERTRAG, sy-vline,
WA_EECRM_CRMCONTRACTPOS_22-ISUVERTRAG_LOGSYS, sy-vline,
WA_EECRM_CRMCONTRACTPOS_22-OBJECT_ID, sy-vline,
WA_EECRM_CRMCONTRACTPOS_22-NUMBER_INT, sy-vline,
WA_EECRM_CRMCONTRACTPOS_22-ORDERED_PROD, sy-vline,
WA_EECRM_CRMCONTRACTPOS_22-PRODUCT_GUID, sy-vline.
ENDLOOP. *Add any further fields from structure WA_EECRM_CRMCONTRACTPOS_22 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_EECRM_CRMCONTRACTPOS_22 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_EECRM_CRMCONTRACTPOS_22 INTO WA_EECRM_CRMCONTRACTPOS_22. *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 BUPA_NR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_EECRM_CRMCONTRACTPOS_22-BUPA_NR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EECRM_CRMCONTRACTPOS_22-BUPA_NR.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit TPLNR, internal->external for field TPLNR CALL FUNCTION 'CONVERSION_EXIT_TPLNR_OUTPUT' EXPORTING input = WA_EECRM_CRMCONTRACTPOS_22-TPLNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_EECRM_CRMCONTRACTPOS_22-TPLNR.
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_EECRM_CRMCONTRACTPOS_22_STR,
GUID_H TYPE STRING,
GUID_I TYPE STRING,
BU_PARTNER_GUID TYPE STRING,
BUAG_GUID TYPE STRING,
BUPA_NR TYPE STRING,
ISUVERTRAG TYPE STRING,
ISUVERTRAG_LOGSYS TYPE STRING,
OBJECT_ID TYPE STRING,
NUMBER_INT TYPE STRING,
ORDERED_PROD TYPE STRING,
PRODUCT_GUID TYPE STRING,
POD_GUID TYPE STRING,
CONTSTART TYPE STRING,
CONTEND TYPE STRING,
INST_DATE TYPE STRING,
CON_SI_DAT TYPE STRING,
CANC_PROC TYPE STRING,
CANC_R_DAT TYPE STRING,
R_CANC_DAT TYPE STRING,
VAL_PER TYPE STRING,
VAL_PER_UN TYPE STRING,
VAL_PER_CA TYPE STRING,
CAMPAIGN TYPE STRING,
CAMPAIGN_TO_DATE TYPE STRING,
SALES_ORG_RESP TYPE STRING,
SALES_ORG TYPE STRING,
DISTRIBUTION_CHANNEL TYPE STRING,
SALES_OFFICE TYPE STRING,
SALES_GROUP TYPE STRING,
SERVICE_ORG_RESP TYPE STRING,
SERVICE_ORG TYPE STRING,
PROCESS_TYPE TYPE STRING,
RELTOPREV TYPE STRING,
RELTONEXT TYPE STRING,
PREV_TS_GUID TYPE STRING,
NEXT_TS_GUID TYPE STRING,
TPLNR TYPE STRING,
CANC_PARTY TYPE STRING,
CANCREASON TYPE STRING,
OUCONT TYPE STRING,
OUCONTRACT_I TYPE STRING,
CHANGE_TICKET1 TYPE STRING,
BUNDLE_CONTRACT TYPE STRING,
BUNDLE_STARTDATE TYPE STRING,
BUNDLE_ENDDATE TYPE STRING,
BUNDLE_SCORE TYPE STRING,
EXT_REF TYPE STRING,
OR1_BORTYPE TYPE STRING,
OR1_BORKEY TYPE STRING,
OR1_RELTYPE TYPE STRING,
OR1_ACTION TYPE STRING,
CONTSTART_KEEPRULE TYPE STRING,
CONTEND_KEEPRULE TYPE STRING,
COPY_PREMISE_ADDR TYPE STRING,
RESPONSE_NEEDED TYPE STRING,
SWITCHNUM1 TYPE STRING,
SWITCHNUM2 TYPE STRING,
SW1_ACTION TYPE STRING,
SW2_ACTION TYPE STRING,
CANCELLED TYPE STRING,END OF T_EKKO_STR. DATA: WA_EECRM_CRMCONTRACTPOS_22_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_EECRM_CRMCONTRACTPOS_22_STR-GUID_H sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-GUID_I sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-BU_PARTNER_GUID sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-BUAG_GUID sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-BUPA_NR sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-ISUVERTRAG sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-ISUVERTRAG_LOGSYS sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-OBJECT_ID sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-NUMBER_INT sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-ORDERED_PROD sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-PRODUCT_GUID sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-POD_GUID sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-CONTSTART sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-CONTEND sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-INST_DATE sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-CON_SI_DAT sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-CANC_PROC sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-CANC_R_DAT sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-R_CANC_DAT sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-VAL_PER sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-VAL_PER_UN sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-VAL_PER_CA sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-CAMPAIGN sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-CAMPAIGN_TO_DATE sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-SALES_ORG_RESP sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-SALES_ORG sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-DISTRIBUTION_CHANNEL sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-SALES_OFFICE sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-SALES_GROUP sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-SERVICE_ORG_RESP sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-SERVICE_ORG sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-PROCESS_TYPE sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-RELTOPREV sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-RELTONEXT sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-PREV_TS_GUID sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-NEXT_TS_GUID sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-TPLNR sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-CANC_PARTY sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-CANCREASON sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-OUCONT sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-OUCONTRACT_I sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-CHANGE_TICKET1 sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-BUNDLE_CONTRACT sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-BUNDLE_STARTDATE sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-BUNDLE_ENDDATE sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-BUNDLE_SCORE sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-EXT_REF sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-OR1_BORTYPE sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-OR1_BORKEY sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-OR1_RELTYPE sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-OR1_ACTION sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-CONTSTART_KEEPRULE sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-CONTEND_KEEPRULE sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-COPY_PREMISE_ADDR sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-RESPONSE_NEEDED sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-SWITCHNUM1 sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-SWITCHNUM2 sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-SW1_ACTION sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-SW2_ACTION sy-vline
WA_EECRM_CRMCONTRACTPOS_22_STR-CANCELLED sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.